• Advertisement
Sign in to follow this  

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

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

If you intended to correct an error in the post then please contact us.

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 this post


Link to post
Share on other sites
Advertisement
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 this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Quote:
Original post by Mayrel
But 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 this post


Link to post
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).

Share this post


Link to post
Share on other sites
Quote:
Original post by Monder
Well two values aren't sufficient to store all rotation in 3D space. You can use three values to describe any rotation.

Actually, that's not true. It takes N-1 number of rotations to get a direction in N dimenions. For 3 dimensions, you technically only need 2 rotations (yes, you can represent any direction in 3D space with 2 rotations about different axes). A simpler example is with 2 dimensions. In a 2D plane, you only need one angle to store direction.

Share this post


Link to post
Share on other sites
Quote:
For 3 dimensions, you technically only need 2 rotations (yes, you can represent any direction in 3D space with 2 rotations about different axes).


Hmm I wasn't aware of that, would using such a representation be practical though?

Share this post


Link to post
Share on other sites
Quote:
Original post by Monder
Hmm I wasn't aware of that, would using such a representation be practical though?
Yes. You'd just end up needing an Nth value for the displacement along that direction. Take 2D rotation again: θ gives us the rotation from a reference axis, but where's our point? The rotation defines a line; we need a linear displacement to locate a specific point - the radius in polar coordinate systems (r, θ).

To locate a point in N-space, you need N coordinates. Note that these coordinates may be displacements or rotations about an axis, with the constraint of at least one displacement. Thus cartesian, cylindrical and spherical 3-D coordinates.

Share this post


Link to post
Share on other sites
Quote:
Original post by Monder
Quote:
For 3 dimensions, you technically only need 2 rotations (yes, you can represent any direction in 3D space with 2 rotations about different axes).


Hmm I wasn't aware of that, would using such a representation be practical though?

Generally not for most games because of the manner in which orientations change. Often times, direction can change by a rotation along any of the three axes by user input, which makes raw, pitch, and roll much better suited, using three rotations. However, one place it would be useful to store just two rotations is a flying game where you can rotate left and right or up and down, yet not roll. Such restrictions let you look in any direction, but limit you to valid movements of your plane.

Other times it is useful to store just two values are when size is what matters most, such as with saving to a file or for sending directional information over a network.

Share this post


Link to post
Share on other sites
Aha, that's why people use 3 values for rotation and another one for the point, OK, it seems quite logical now to use 3 for directions if you want a fully functional 3d engine.
Thanks alot!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement