PDA

View Full Version : drawing 2 vectors ...



romb
08-05-2002, 02:11 AM
I have a problem (really ?!) : the foloowing code sould draw two vector with the same orientation... but it doesn't work. I try to draw a vector in spherical coordonates ( the base is (1,angle[1],angle[0]) and sorry for the english ...) with 2 rotations and with this cartesian composantes.
/-------------------------------------------------------------------------------------------
angle[2]={40,60};
anglerd[0]=angle[0]*PI/180;anglerd[1]=angle[1]*PI/180;
dir[0]=sin(anglerd[1])*cos(anglerd[0]);dir[1]=sin(anglerd[0])*sin(anglerd[1]);dir[2]=cos(anglerd[1]);

glColor3f(1,0,0);
glBegin(GL_LINES);
glVertex3f(0,0,0);glVertex3d(3*dir[0],3*dir[1],3* dir[2]); //vecteur directeur
glEnd();

//retrouver le vecteur directeur

glPushMatrix();
glRotated(angle[1]-90,0,1,0);
glRotatef(angle[0],0,0,1);
glColor3f(0,1,0);
glBegin(GL_LINES);
glVertex3f(0,0,0);glVertex3f(4,0,0);
glEnd();
glPopMatrix();
/------------------------------------------------------------------------------------------------
I hope my english is not so bad that it cannot be understand....

knackered
08-05-2002, 04:00 AM
dir[0]=sin(anglerd[1])*cos(anglerd[0]);
dir[1]=sin(anglerd[0])*sin(anglerd[1]);
dir[2]=cos(anglerd[1]);


Shouldn't it be something like this?:-



dir[0]=cos(anglerd[0])*sin(anglerd[1]);
dir[1]=sin(anglerd[0])*sin(anglerd[1]);
dir[2]=cos(anglerd[1]);

Michael Steinberg
08-05-2002, 04:30 AM
Am i possibly too blind to see the difference? http://www.opengl.org/discussion_boards/ubb/smile.gif

Bob
08-05-2002, 05:09 AM
Yes, you must be blind. He changed the order of multiplication for dir[0]. Didn't you see that? http://www.opengl.org/discussion_boards/ubb/biggrin.gif

romb
08-05-2002, 05:30 AM
i have tested the code for no results. http://www.opengl.org/discussion_boards/ubb/frown.gif
I sould explain the goal of this code :
I try to draw a ship that follows a terrain, so i succeed in calculate the altitude and the normal at (x,y) : the ship follows the terrain.
But now i want it also follows the angle of the terrain : so i use the normal, calculate its theta and phi coordonates (spherical base) and draw the ship :
(the ship follows the normal)
glPushMatrix();
glRotatef(theta,...);
glRotatef(phi,...);
glTranslatef(x,y,z);
DrawShip();
glPopMatrix();

It sould work ?

J P
08-05-2002, 01:23 PM
There are 3 tutorials that are basically about aligning an object along a vector that maybe helpful to you.
http://www.mfcogl.com/OpenGL%20Topics.htm

They also draw and rotate lots of vectors (coordinate axes.) The MFC is is used to setup the OpenGL window but the OpenGL code is valid for any system.

knackered
08-05-2002, 02:04 PM
How did you know I was blind?
It's cruel to mock the afflicted... http://www.opengl.org/discussion_boards/ubb/wink.gif

romb
08-06-2002, 03:25 AM
thanks a lot for your answers it works perfectly now http://www.opengl.org/discussion_boards/ubb/smile.gif)))))))))))))))))