best way to get coordinates out of a 3D direction?

Started by
18 comments, last by the_cyberlord 19 years, 5 months ago
and how does it work with another direction? (_direction.c)
Advertisement
Quote:Original post by the_cyberlord
and how does it work with another direction? (_direction.c)

.c may be needed for for orientation. For 3d direction, a and b is enough, no need for c . You may also store distance together with direction, but don't name it c because it will be confusing.


Direction is usually storen as 3 numbers x,y,z for speed-up.
Because, for given points O and P it's fast to find x,y,z direction from O to P. No need to do asin and acos, then do sin and cos. Also stepping along direction in x,y,z is fast and simple, as in my first code.
read my previous thread, and you'll know why I want three direction values and a speed value, and I don't care if I call them a,b,c or x,y,z , I use classes in a good manner so I don't have to care about them.
Quote:Original post by the_cyberlord
read my previous thread, and you'll know why I want three direction values and a speed value, and I don't care if I call them a,b,c or x,y,z , I use

no i dont.
you want tree directions because
Quote:
but I see all those 3D modelers store it in 3 values, how does that work?

?
If so, xyz direction is probably what you need. Unless you're asking about orientations without knowing what you're asking for.

Anw, why abc and not xyz and why care even if you "use classes in a good manner":
because of confusion like in that and previous thread. So people will not mix Euler angles or something with vectors. See, that xyz direction is nothing like a,b direction.
Quote:Original post by Eelco
Quote:Original post by the_cyberlord
read my previous thread, and you'll know why I want three direction values and a speed value, and I don't care if I call them a,b,c or x,y,z , I use

no i dont.

seconded.
It's just pure because of logic, for example in a plane game: you can turn around the z axis (rolling), the x axis (nose up/down), and the y axis (rudder turning). Of course you can all represent these directions with just 2 rotations, but that's not very logical when your programming your plane game.
It seems you guys don't really want to help...
can you just error check this code then?
GLvoid direction_apply(point angle, GLfloat distance, point &_position) {	if (angle.x<= 90) { position.z = (cos(angle)*distance); position.y = (sin(angle)*distance); }else	if (angle.x<= 180) { position.z = -(cos(angle)*distance); position.y = (sin(angle)*distance); }else	if (angle.x<= 270) { position.z = -(cos(angle)*distance); position.y = -(sin(angle)*distance); }else	if (angle.x<= 360) { position.z = (cos(angle)*distance); position.y = -(sin(angle)*distance); }	if (angle.y<= 90) { position.x = (cos(angle)*distance); position.z = (sin(angle)*distance); }else	if (angle.y<= 180) { position.x = -(cos(angle)*distance); position.z = (sin(angle)*distance); }else	if (angle.y<= 270) { position.x = -(cos(angle)*distance); position.z = -(sin(angle)*distance); }else	if (angle.y<= 360) { position.x = (cos(angle)*distance); position.z = -(sin(angle)*distance); }	if (angle.z<= 90) { position.y = (cos(angle)*distance); position.x = (sin(angle)*distance); }else	if (angle.z<= 180) { position.y = -(cos(angle)*distance); position.x = (sin(angle)*distance); }else	if (angle.z<= 270) { position.y = -(cos(angle)*distance); position.x = -(sin(angle)*distance); }else	if (angle.z<= 360) { position.y = (cos(angle)*distance); position.x = -(sin(angle)*distance); } }
Okay. Seems that by helpful replies, orientation and direction is completely mixed up in that and prev. threads to great extent.

Anyway.
As about your code,
0:it makes no sense because you work like angle is float or double "sin(angle)" and declare it as "point angle".
1: you don't need all those ifs as hplus0603 said
2: you have tonns of unnecessary code, becoz you owerwrite every cooedinate of position 2 times.
3: i *guess* it will work not in way you expect even if you'll fix 0,1,and 2

...and as about helpfullness.... if someone don't understand something, yes, it's gives no help, therefore, it's not helpful, that's logic. But if someone gives reply that is misundestood.... it's unhelpful.
go there
Read this
and
this
,get confused, then get somme book about linear algebra(in school library), and everything will be fine. It's really a suggestion, potentially helpful suggestion, not a sarcasm or something.
Well, just to ask, can you rewrite the code so all time waiste is gone?
I corrected some things (like value overwrite, but I'm still not shure if it'll work.)
And about the if's, do sin and cos produce negative values as well??
Oh yeah of course, I forgot angle.x, angle.y, angle.z, Fixed now.
And are all the other two axises for every rotation axis in the right order?
GLvoid direction_apply(coords angle, GLfloat distance, point &_position) {		if (angle.x<= 90) { _position.z = (cos(angle.x)*distance); _position.y = (sin(angle.x)*distance); }else	if (angle.x<= 180) { _position.z = -(cos(angle.x)*distance); _position.y = (sin(angle.x)*distance); }else	if (angle.x<= 270) { _position.z = -(cos(angle.x)*distance); _position.y = -(sin(angle.x)*distance); }else	if (angle.x<= 360) { _position.z = (cos(angle.x)*distance); _position.y = -(sin(angle.x)*distance); }	if (angle.y<= 90) { _position.x = (cos(angle.y)*distance); _position.z += (sin(angle.y)*distance); }else	if (angle.y<= 180) { _position.x = -(cos(angle.y)*distance); _position.z += (sin(angle.y)*distance); }else	if (angle.y<= 270) { _position.x = -(cos(angle.y)*distance); _position.z += -(sin(angle.y)*distance); }else	if (angle.y<= 360) { _position.x = (cos(angle.y)*distance); _position.z += -(sin(angle.y)*distance); }	if (angle.z<= 90) { _position.y += (cos(angle.z)*distance); _position.x += (sin(angle.z)*distance); }else	if (angle.z<= 180) { _position.y += -(cos(angle.z)*distance); _position.x += (sin(angle.z)*distance); }else	if (angle.z<= 270) { _position.y += -(cos(angle.z)*distance); _position.x += -(sin(angle.z)*distance); }else	if (angle.z<= 360) { _position.y += (cos(angle.z)*distance); _position.x += -(sin(angle.z)*distance); } }

This topic is closed to new replies.

Advertisement