Jump to content
  • Advertisement
Sign in to follow this  
_WeirdCat_

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

This topic is 1429 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

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)

 

 

mads.jpg

 

 

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


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


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


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

Share this post


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

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!