3d perspective math

Started by
3 comments, last by ironfroggy 22 years, 2 months ago
I''m trying to do a new AVS plugin for Winamp. I have a galaxy rendered, but I want to to be viewed in perspective. I can''t get the math just right... incase you don''t know how it works, i can create a list of operations to be performed for each pixel. i am working on the pixels'' x and y variables. What I am doing now is this: p=0.5; x=x*(p-y); y=y/p It doesn''t quite work... anyone have ideas on how i could do this? I have most common and some uncommon math functions at my disposal. (http://www.ironfroggy.com/) (http://www.ironfroggy.com/pinch)
(http://www.ironfroggy.com/)(http://www.ironfroggy.com/pinch)
Advertisement
hi ironfroggy,

I have never rendered a galaxy, but would like to know how. Infact I tried even looking in astrophysics books and came up with nothing

But I have some experiences with my own 3d routs. I just do some very simple stuff. I hope this is what you mean:

I asume a 3d point has (x,y,z) coords.. cam_length is just some trick to avoid div by 0. (X,Y) is the 2d rendered pixel.

X=x/(z+cam_length);
Y=y/(z+cam_length);

This works for me.

If you can give me some hints on howto generate sucha nice galaxy shape you have my eternal grattitude.

Pieter (earx)
Take a look at how glFrustum() works (either in the MSDN help files or the OpenGL Blue Book). It shows you how to generate the projection matrix based on the near and far clipping planes and the left, right, top, and bottom coordinates of the near clipping plane. Then, from glViewport(), you take the results of multiplying by that matrix and multiply the x-coordinate by the width of the viewport and add half the viewport width, and multiply the y-coordinate by the height of the viewport and then add half the viewport height. That should work.
unfortunitly, what i have to work with is far more limited than this. there is NO 3d support at all, and its too slow to do real 3d. What I want to do is simply to stretch one image in such a way that it appears viewed at a 3d perspective. I''ve gotten close, using this:

p=.5;
x=(x/(p+y));
y=(y/.2);

where p is my perspective ratio im using (made up value), x and y are the locations of the pixel and what im chaging them too(range -1 to 1).

the only major problem, is that even tho the image seems almost to perspective, its just shrunk on the y axis. i need all pixels to have y values closer to 0, but the lower the original values are, the closer to 0 they should be. understand?

(http://www.ironfroggy.com/)
(http://www.ironfroggy.com/pinch)
(http://www.ironfroggy.com/)(http://www.ironfroggy.com/pinch)
if you just want scaling:

p=1/(z+l)
x=x*p
y=y*p

so: 1 add, 1 div and 2 muls per point. not bad. ofcos you can make multiply tables for limited ranges..

What kind of machine are you working on?

This topic is closed to new replies.

Advertisement