gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Graphics > Mapping points in perspective

#11766 - Datch - Sat Oct 18, 2003 5:11 pm

Not really limited to GBA but anyway...

I would like to know how to calculate the new x,y of a point when drawn in pespective.

Here's a sample :

[Images not permitted - Click here to view it]
A(6,2) => A'(6,5)
B(6,4) => B'(6,8)
C(6,8) => C'(6,12)
D(6,12) => D'(6,14.5)

It's easy to figure out this way that to every single point in the first rectangle there is a corresponding point in the perspective trapeze. I just would like to know how to figure out the new coordinates of the points.

I've made a lot of searches on Google but I can't figure out a combination of key words that will bring me a page with the answer. So in a last attempt I'm asking you. Any hint will be appreciated!
_________________
Visit SR-388 now and get a 40% discount!


Last edited by Datch on Sat Oct 18, 2003 6:26 pm; edited 1 time in total

#11768 - poslundc - Sat Oct 18, 2003 5:57 pm

Datch wrote:
Not really limited to GBA but anyway...

I would like to know how to calculate the new x,y of a point when drawn in pespective.


This largely depends on what variables you are using to define perspective (angle, coordinates, etc.). Your image link is broken, and since your transformation function appears to be non-linear, it's hard to understand what you are trying to accomplish.

There is a good raycasting tutorial that explains many of the mathematics behind calculating perspective, and although it is primarily geared to developing a Wolfenstein-style wall-mapper I still found it quite useful when developing my terrain engine.

Dan.

#11769 - Datch - Sat Oct 18, 2003 6:10 pm

Hmm.. The image was fine in the preview. Anyway, here's the link to it :

[url]
http://www.geocities.com/datch78/pointmapping.gif
[/url]

There is no 3d involved. It's only mapping 2d points to a 2d plane to give a perspective illusion.
_________________
Visit SR-388 now and get a 40% discount!

#11773 - Datch - Sat Oct 18, 2003 6:27 pm

Image linking doesn't work on Geocities/Yahoo due to some kind of protection.

I've uploaded the image somewhere else and it should be visible in the first message.
_________________
Visit SR-388 now and get a 40% discount!

#11774 - DekuTree64 - Sat Oct 18, 2003 6:32 pm

The image does work, you just have to copy the URL without the http:// and paste it into a new window. Otherwise Geocities will know it's being linked from another site and they're mean about that.
Unfortunately I can't really tell what the image is getting at. How exactly do you project 2D onto 2D? I know for 3D an easy way to project is to multiply your x and y by some value and divide by z. You can control the aspect ration by changing your scale values and adding to z before dividing by it. I'm no 3D expert, but I think this would change the size and distance of the projection plane.
But what exactly are you trying to do? What sort of program is it?
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku

#11783 - Datch - Sat Oct 18, 2003 9:39 pm

Hi deku. First thanks for your reply. I'll try to explain what I want more clearly.

If you look at the picture, you can see that point C is centered in the first rectangle. You can tell it is centered by drawing the two diagonales and you'll see the C point is at the intersection of the two diagonales. So if I draw a rectangle in pespective, which gives a trapeze like in the second rectangle, I can find the exact position of the point C by drawing the two diagonales again and by putting the C' point at the intersection again. Tada! The point is plotted. I can procede the same way to plot the other points and find the new positions of A', B' and D'. By plotting many points from a rectangle to a trapeze this way you'll get a nice perspective effect.

It's more image distortion than 3d. It's exactly like the Photoshop distortion tool, if you've seen it before. I just want to be able to do that! :)
_________________
Visit SR-388 now and get a 40% discount!

#11786 - DekuTree64 - Sat Oct 18, 2003 10:20 pm

Oh, ok. I think this is what you want: http://freespace.virgin.net/hugo.elias/graphics/x_persp.htm
_________________
___________
The best optimization is to do nothing at all.
Therefore a fully optimized program doesn't exist.
-Deku