# 3d vector total madness @#@#@!#!

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

## Recommended Posts

Hi

i need to make a 3d vector from point 0,0,0 to a specific point in space that is defined by pitch,yaw angles and distance.

somehow i manage to find proper yaw vector (green one) (see images below)

but i really really dont have an idea how to find make pitch vector and then how do i make a one vector

the thing is when pitch angle is greater than lets say 10 degrees lines are inaccurate (white and red ones)

oh and that white something that pretends to be a sphere is the point we want to face)

Y shows the pitch angle x shows yaw angle

100000000.0 is distance, imopi converts degrees to radians

kag.x = -100000000.0f*(sin(yawangle*imopi));
kag.z = -100000000.0f*(cos(yawangle*imopi));
kag.y = -100000000.0f*(sin(pitchangle*imopi));

glBegin(GL_LINES);

glColor3f(0,1,0);
glVertex3f(0,0,0);
glVertex3f(kag.x,0,kag.z);

glColor3f(1,0,0);
glVertex3f(0,0,0);
glVertex3f(kag.x*cos(pitchangle*imopi),kag.y,kag.z*cos(pitchangle*imopi));

glColor3f(1,1,1);
glVertex3f(0,0,0);
glVertex3f(kag.x,kag.y,kag.z);
glEnd();


yaw can be from 0 to 360

pitch is from 0..180 but i manage it differently (lets say it is -90..90)

##### Share on other sites

hmm, I don't think you have enough buttons on the screen.

Did you try adding another button?

##### Share on other sites
The x and z coordinates need to be multiplied by cos(pitch). For small pitch you don't see a problem because cos(something small) ~= 1.

##### Share on other sites

You need to include the pitch in your calculations for X and Z, as well as Y. Consider what happens when the pitch is 90 degrees: It should be pretty obvious that X and Z are both going to be zero, no matter what the yaw angle is. There are several ways to convert pitch and yaw to a vector depending on the order you want to do rotations, and how you've oriented your X, Y and Z axes. I believe in your case the correct formulas should be:

kag.x = -100000000.0f*(sin(yawangle*imopi))*(cos(pitchangle*imopi));
kag.z = -100000000.0f*(cos(yawangle*imopi))*(cos(pitchangle*imopi));
kag.y = -100000000.0f*(sin(pitchangle*imopi));

##### Share on other sites

you see i showed 2 ways of doing it, even with cos(pitch) for x and z see the red line it doesn't match the camera. (further i go to the sout/north pole) difference is greater.

UPDATE:

i have just ran the app it seems that red line follows (and was following it from the beggining) i just didint see that yesterday lol....

solved  - lets hope ;]

Edited by WiredCat

1. 1
2. 2
Rutin
19
3. 3
4. 4
5. 5

• 9
• 9
• 9
• 14
• 12
• ### Forum Statistics

• Total Topics
633300
• Total Posts
3011267
• ### Who's Online (See full list)

There are no registered users currently online

×