(topic reuse) best way to get coordinates out of a 3D direction?

This topic is 5206 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

Recommended Posts

what is the best way to store 3D directions? TOPIC REUSE: what is the best way to get coordinates out of a 3D direction? before I used only 2 directions for my rotations (x,y) but now I have 3 of them (x,y,z) so I don't really know how to fix this code, or even if it's the best way to do it. Just changed the code because of my code redesign>> angle has now x,y,z. So this code now only applies to angle.y
GLvoid camera::change_dir(point &position, GLfloat angle, GLfloat distance) {
if (angle<= 90) { position.x = (cos(angle)*distance); position.z = (sin(angle)*distance); }else
if (angle<= 180) { position.x = -(cos(angle)*distance); position.z = (sin(angle)*distance); }else
if (angle<= 270) { position.x = -(cos(angle)*distance); position.z = -(sin(angle)*distance); }else
if (angle<= 360) { position.x = (cos(angle)*distance); position.z = -(sin(angle)*distance); } }


[Edited by - the_cyberlord on October 23, 2004 10:34:47 AM]

Share on other sites
Vectors are what you want.

Share on other sites
OK, yeah, I know that, but I want to store directions in degrees too... so you could have an x and an y direction to store your 3D direction, but I see all those 3D modelers store it in 3 values, how does that work?

Share on other sites
Well two values aren't sufficient to store all rotation in 3D space. You can use three values to describe any rotation. The three values are basically how much it is rotated around an axis i.e. you'd have the rotation around the X, Y and Z axes stored using 3 values.

Share on other sites
Quote:
 Original post by MonderVectors are what you want.

i thought matrices were best?
oh well....

Share on other sites
But if you want to store an orientation rather than just a direction, you may find that quaternions have a few technical benefits.

Share on other sites
I know about rotateing around an axis, but I don't really see why you need three values...

Share on other sites
Quote:
 Original post by MayrelBut if you want to store an orientation rather than just a direction, you may find that quaternions have a few technical benefits.

the difference between orientation and direction, in relation to this thread?

Share on other sites
Well yeah, I'll just use three in my code... maybe I'll understand later on

Share on other sites
Quote:
 i thought matrices were best?oh well....

Matrices are used when you need to apply a transformation (such as a rotation) to a point or a vector. You could store a rotation matrix to describe a rotation but whether this would be suitable or not depends on what you're actually trying to do.

Quote:
 I know about rotateing around an axis, but I don't really see why you need three values...

There are three axes in a 3D system and thus you need 3 angles (i.e. 3 values).

• What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

• 11
• 11
• 15
• 11
• 11
• Forum Statistics

• Total Topics
634149
• Total Posts
3015834
×