PDA

View Full Version : Spherical : Billboarding



Erakis
01-03-2002, 12:11 AM
Hello.
I've implemented a camera engine that use gluLookAt (Free camera).
My camera can provide these informations :

Camera.Pos (Space coord x,y,z)
Camera.LookAt (Direciton Vector)
Camera.UpVector (UP vector http://www.opengl.org/discussion_boards/ubb/smile.gif)
Camera.RightVector (RIGHT vector http://www.opengl.org/discussion_boards/ubb/smile.gif )

And I set my camera like this :


gluLookAt( Camera.Pos.x,
Camera.Pos.y,
Camera.Pos.z,

Camera.Pos.x + Camera.LookAt.x,
Camera.Pos.y + Camera.LooAt.y,
Camera.Pos.z + Camera.LooAt.z,

Camera.UpVector.x,
Camera.UpVector.y,
Camera.UpVector.z
);



Now I'm able to realize a cylindrical billboard (quads building)
but I don't understand what to do to realize a spherical billboarding.
The billboard should be spherical cause the camera will move around a
particles foutain and as it's free(camera) then it can pass above the fountain.


To draw the quads(Particles), I proceed like that :




RightVector = Camera.GetRightVector;
RightVector.x = RightVector.x * Quad_Half_Width;
RightVector.y = RightVector.y * Quad_Half_Width;
RightVector.z = RightVector.z * Quad_Half_Width;

UpVector = Camera.GetUpVector;
UpVector.x = UpVector.x * Quad_Half_Height;
UpVector.y = UpVector.y * Quad_Half_Height;
UpVector.z = UpVector.z * Quad_Half_Height;

glBegin( GL_QUADS );
glVertex3f( ObjectPosX - (RightVector.x + UpVector.x),
ObjectPosY - (RightVector.y + UpVector.y),
ObjectPosZ - (RightVector.z + UpVector.z) );

glVertex3f( ObjectPosX + (RightVector.x - UpVector.x),
ObjectPosY + (RightVector.y - UpVector.y),
ObjectPosZ + (RightVector.z - UpVector.z) );

glVertex3f( ObjectPosX + (RightVector.x + UpVector.x),
ObjectPosY + (RightVector.y + UpVector.y),
ObjectPosZ + (RightVector.z + UpVector.z) );

glVertex3f( ObjectPosX - (RightVector.x - UpVector.x),
ObjectPosY - (RightVector.y - UpVector.y),
ObjectPosZ - (RightVector.z - UpVector.z));
glEnd();


ObjectPos is where the Billboard quads(Particles) will be drawn.


When the camera goes forward, backward, rotate left/right or strafing right/left,
the quads are well facing the camera but when I raise the camera and I look
down (CamLook), the Quads do not facing the camera.
Consequently, they(quads) should undergo a rotation around the RIGHT vector but ???


PS :Perhaps the error cames from me cause when I raise the eye(lookAt) of the camera
I modify the LookAt vector but I don't modify the UP vector.




CamLook.y = Sin(Eye_Elevation_Degres);



I think the UP vector have to be modify cause pretend I raise my eye to the sky,
the UP vector of my head(Camera) will move backwards...
But, how modify it and, could the error come from this ?


I thank you in advance.
Martin


PS :Excuse these many confusions and this long annoying question
but I'm tired to seek informations on Billboarding (Without use the ModelView matrix).

Evil-Dog
01-03-2002, 06:16 AM
I'm not sure I understand your question....
Why don't you make your particles to always be facing the camera with mathematical calculation.
I don't know if that is a suitable solution to you problem...

here's some code

void CBillboard::Render(const C3DVector& vOrientation)
{
glPushMatrix();

//Translate the object at his position
glTranslatef(m_vPosition.x, m_vPosition.y, m_vPosition.z);
//Find the angle between the (1,0,0) vector and the oriention vector
//and rotate with that angle
C3DVector vXAxis(1.0f, 0.0f, 0.0f);
C3DVector vNewOrientation(vOrientation.x - m_vPosition.x, 0.0f, vOrientation.z - m_vPosition.z);
float fAngle = 180.0f/3.1416f * acos((vXAxis * vNewOrientation) / (vXAxis.GetLength() * vNewOrientation.GetLength()));
if(m_vPosition.z >= vOrientation.z)
glRotatef(fAngle, 0.0f, 1.0f, 0.0f);
else
glRotatef(-fAngle, 0.0f, 1.0f, 0.0f);
//glScalef(m_vDimension.x, m_vDimension.y, 1.0f);

glBindTexture(GL_TEXTURE_2D, m_iTextureID);

//glColor4f(1.0f, 1.0f, 1.0f, 1.0f);

glBegin(GL_QUADS);
glTexCoord2f(1.0f, 0.0f);
glVertex3f(0.0f, 0.0f, m_vDimension.x / -2.0f);

glTexCoord2f(1.0f, 1.0f);
glVertex3f(0.0f, m_vDimension.y, m_vDimension.x / -2.0f);

glTexCoord2f(0.0f, 1.0f);
glVertex3f(0.0f, m_vDimension.y, m_vDimension.x / 2.0f);

glTexCoord2f(0.0f, 0.0f);
glVertex3f(0.0f, 0.0f, m_vDimension.x / 2.0f);
glEnd();

glPopMatrix();
}