PDA

View Full Version : conversion between polar cordinate and normal 3D cordinate?


Nappe1
25-May-2004, 14:24
I have 3D space with following cordinate system:

unit up vector: 0.0, 0.0, 1.0
unit right vector: 1.0, 0.0, 0.0
unit depth vector: 0.0, 1.0, 0.0

cordinates are floats.

I also have a definition for Light (sun in this case.) as in polar cordinates:
Yaw Angle in radian system
Pitch Angle in radian system

How do I convert Light direction to unit vector in the mentioned 3D cordinate system? I know it is just all about Pythagora's triangle geometry, but while I did a one, I got very badly mixed up because I usually use 3D space where Y -axle points up, not Z.

what for I am doing this? well, I have done a tracer for recalculating vertex shadow information in NFS4 tracks... and it is a bit pointless even test run it if you can't figure out where the light should be. :)

all help is greatly appriciated.

gokickrocks
25-May-2004, 19:24
are you referring to spherical coordinates?
ie: x=rsin(phi)cos(theta), y=rsin(phi)sin(theta), z=rcos(phi), r=sqrt(x*x+y*y+z*z)...but in your case y and z would be switched, yaw = phi, pitch = theta

or am i just completely way off...

Nappe1
25-May-2004, 19:45
are you referring to spherical coordinates?
ie: x=rsin(phi)cos(theta), y=rsin(phi)sin(theta), z=rcos(phi), r=sqrt(x*x+y*y+z*z)...but in your case y and z would be switched, yaw = phi, pitch = theta

or am i just completely way off...

most likely you just hit the nail on the head in there. :)
need to check few things on my code...

thanks. I'll let you know if it seems to be correct...

akira888
27-May-2004, 01:59
http://mathworld.wolfram.com/SphericalCoordinates.html

Chalnoth
08-Jun-2004, 02:52
Yeah, that's definitely right. But just remember the light vector is assumed to be normalized, so r=1, giving:
x=cos(phi)*sin(theta)
y=sin(phi)*sin(theta)
z=cos(theta)

...with the phi/theta definitions gokickrocks gave.

And, of course, remember:
x=right
y=depth
z=up

Nappe1
28-Oct-2004, 23:31
bringing this back up, as the subject has become problematic again. :lol:
well, first I didn't have time to test my tracer, and when I did, I found so much problems that I decided to make tracer work by testing ray-triangle collision with two known global coordinates.

well, now it works that way, BUT when I started to work with the Sun again (that has only 2 radian values) I found out that EA used different 3D space for the sun. :) while polygon mesh use X=Right,Y=Depth,Z=UP Space, Sun seems to use X=Depth, -Y=Right, Z=UP Space. (when theta is set to 0.00, sun is in Infinitum on positive X-axis direction. other value is named as Rho, and 0.00 sets the sun in Zenite, while ~0.30 sets it to close to horizon.)

so, what I need is a more help. :D I know this being a simple, but I have been thinking and trying these way too many times and only got my head spin (and pretty good headache as well.) :)

EDIT: and as a note, Theta value rotates the sun Counter-clockwise (setting theta = 0.5*pi makes the sun appear to direction of positive Y-axis and 1.5*pi again direction of negative Y-axis.)

Nappe1
14-Dec-2004, 13:23
Got it working, thanks everyone. :)

some screenshots coming whenever find to time to take them.

any suggestions to make fast texel sampler? I need it to check transparency / alpha information.

textures are tiled and primitive is Quad. (only one texture per quad.)
textures are stored in 32 bit BITMAP array. (during editor run time, game uses several different formats.)