How do I map a 2D set of points to 3D-perspective correction

Get help using Construct 2

» Mon Nov 10, 2014 6:53 pm

I think we need a more precise approach. So instead we could use this equation:
Code: Select all
`screenx = x /(z/d - cz)`

cz is the z of the camera
and d is the distance from the screen which is the same as tan(fov_angle/2).

Then instead of finding the z of the back edge we'll assume it's 2 and solve for cz and d.
The math worked out to be:
screenx = x/((z-1)*(BottomWidth/TopWidth)+1)

Actually I had a -1 in there so some reason which was throwing it off until I removed it.

I updated my example in my first post. Click to switch between the old method and the new. The new matches the grid much better when the fov is different.
B
97
S
36
G
131
Posts: 5,513
Reputation: 83,464

» Tue Nov 11, 2014 6:28 am

@R0J0hound you can't resist a math challenge can you?

<3

Thanks for all the help, it's the first time I understand *all* of your math.

You're incredible.

Oh and here's a wip of the game you've helped
B
29
S
12
G
4
Posts: 193
Reputation: 4,606

» Tue Nov 11, 2014 6:19 pm

Looks fun.
B
97
S
36
G
131
Posts: 5,513
Reputation: 83,464

» Sun Dec 14, 2014 6:52 pm

@R0j0hound , R0j0 assuming the z of the back edge is "2" seems to have a strange effect: these pairs of rectangles now only work if they are the same relative size.

If I resize the perspective rectangle without resizing the top-down rectangle, the equations don't work at all.

If the top-down rect is 400x400, the perspective rect has to be 970x330. I don't know what this ratio means. Do you?

I don't mind working with this limitation, I just thought I'd make a note of it. Thanks again <3

https://dl.dropboxusercontent.com/u/28087823/Construct%20Examples/marioPinball/3DmappingR0j0.capx
B
29
S
12
G
4
Posts: 193
Reputation: 4,606

» Tue Dec 16, 2014 11:06 pm

@r0j0hound

Um. I've lost track of the math again, but your prototype only worked for a specific ratio.
I tried to change that ratio to something more useful. So, if the world width and the perspective rectangle bottom width are equal, the ratio comes out as 2.425
Did you use actual pixel dimensions when you made the assumption that Z=2 ?? Is that where this number comes from?

Anyhow, it works well for now and until I can go back and re-check your genius math. <3

[url]
https://dl.dropboxusercontent.com/u/280 ... ction.capx[/url]
B
29
S
12
G
4
Posts: 193
Reputation: 4,606

» Wed Dec 17, 2014 12:21 am

The front edge has a z of 1 and the back edge has a z of 2. The values were a bit arbitrary, you could pick a different value fro the back edge but then you'd need to rework the formulas. I did some fiddling with the example and stretched the perspective shapes around and actually found cases where the old method works better.

There may be a math error somewhere in my equation since it seems to need that correction for large values.
B
97
S
36
G
131
Posts: 5,513
Reputation: 83,464

» Wed Dec 17, 2014 12:29 am

It was fine if the rects were the size they were, but those weren't their 1:1 sizes, they were both resized at the time.

At their 1:1 sizes, dividing the world width by 2.425 gives a spectacularly accurate result, so there may be a math error somewhere, but all the other numbers are so elegant that I don't mind
B
29
S
12
G
4
Posts: 193
Reputation: 4,606

Previous