Advertisement

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

Started by September 21, 2014 09:25 PM
3 comments, last by _WeirdCat_ 10 years, 5 months ago

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)

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

Did you try adding another button?

Mobile Developer at PawPrint Games ltd.

(Not "mobile" as in I move around a lot, but as in phones, mobile phone developer)

(Although I am mobile. no, not as in a babies mobile, I move from place to place)

(Not "place" as in fish, but location.)

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.

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));

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 ;]

This topic is closed to new replies.

Advertisement