PDA

View Full Version : Geometry problem

Alessandro_dup1
11-29-2003, 04:51 AM
I'd like to draw an object which always face the camera. Because my english is not so good, i attached three shots of what i'd like to achieve. As you can see i'd like to render an object (also a simple quad, represented by the orange box) which has the position and orientation shown in the shots.
Billboarding wouldn't do, because i lose one axis.
http://www.web-discovery.net/temp/1.jpg http://www.web-discovery.net/temp/2.jpg http://www.web-discovery.net/temp/3.jpg

Adrian
11-29-2003, 06:38 AM
Just do an additional negative rotate on your modelview matrix after the translation e.g.

glMatrixMode(GL_MODELVIEW);
glRotatef(Viewangle,ViewX,ViewY,ViewZ);
glTranslatef(PosX,PosY,PosZ);
glRotatef(-Viewangle,ViewX,ViewY,ViewZ);

//Draw quad

tellaman
11-29-2003, 08:39 AM
multiply by the inverse for the rotational part (upper 3x3) of your lookat matrix:

gluLookAt(...);
glTranslate(quadposition);
glMultMatrixd(lookatmat.invrot);
drawquad();

[This message has been edited by tellaman (edited 11-29-2003).]

Alessandro_dup1
11-29-2003, 08:43 AM
hi tellaman, i suppose i should use the glMultMatrix function ? could you make an example please ?

Alessandro_dup1
11-30-2003, 03:11 AM
Hi, i've been trying all the evening and finally i get the quad always facing the camera. The last problem is that i'd like to position the quad near the tail of the aircraft (while now is centered in the middle of it). I've been trying to move it along the z axis, but i am not able to do it, it always remain centered in the middle of the aircraft. Here is my code:

glLoadIdentity();
glTranslatef(x,y,z); // this has no effect, doesn't move the quad
glRotatef(cameraz_pov, 0.0, 0.0, 1.0);
glRotatef(camerax_pov, 1.0, 0.0, 0.0);
glRotatef(cameray_pov, 0.0, -1.0, 0.0);
glGetDoublev(GL_MODELVIEW_MATRIX,m_mt) ; // get current matrix

// start calculate inverse matrix
result_mt[0]=m_mt[0];
result_mt[1]=m_mt[4];
result_mt[2]=m_mt[8];
result_mt[3]=0.0f;
result_mt[4]=m_mt[1];
result_mt[5]=m_mt[5];
result_mt[6]=m_mt[9];
result_mt[7]=0.0f;
result_mt[8]=m_mt[2];
result_mt[9]=m_mt[6];
result_mt[10]=m_mt[10];
result_mt[11]=0.0f;
result_mt[12]=-(m_mt[12]*m_mt[0])-(m_mt[13]*m_mt[1])-(m_mt[14]*m_mt[2]);
result_mt[13]=-(m_mt[12]*m_mt[4])-(m_mt[13]*m_mt[5])-(m_mt[14]*m_mt[6]);
result_mt[14]=-(m_mt[12]*m_mt[8])-(m_mt[13]*m_mt[9])-(m_mt[14]*m_mt[10]);
result_mt[15]=1.0f;
// end calculate inverse matrix

glMultMatrixd((GLdouble *)result_mt); // multiply matrix

Draw_Quad();

tellaman
11-30-2003, 05:54 AM
xlation has no effect since you are calculating the inverse of the whole mv matrix
you only need to invert the rotational part, ie transpose of upper 3x3 part
4th row and column are (0,0,0,1)