PDA

View Full Version : GluLookAt w/ particles



Kent767
08-18-2002, 01:21 AM
ok i'll try to describe this as best as possible (this is my first opengl project, and im learning new stuff all the time)

I have a routine AddObject which takes in an ObjectID, xpos,ypos,zpos,xrot,yrot,and zrot... i have this working fine by just pushing the models on the matrix doing whatever.

Then I use gluLookAt to view the Objects from wherever (im too lazy to implement my own translate/rotate routines) and for all intents and purposes, this works fine.

The trouble comes in when i try to add my particles, they need to be able to be placed explicitly like the Objects, but always rotate to face the origin from gluLookAt... I can get them to face the camera at all times, but then translating the particles doesn't really work out, (im guessing because its using the gluLookAt's matrix) if i treat it like a regular Object it will not rotate to face the camera.. (i imagine there is a nasty algorithm to rotate to the xyz origin locations of my camera... but thats entirely too slow.. and i'd prefer that it be done right on the matrix if possible.

I could be going about this completely the wrong way (again its my first opengl project).. any advice would be life saving..
thanks,
Kent

Robbo
08-18-2002, 01:37 AM
Show some source code - either the order of your transforms is incorrect, or you aren't pushing\popping matrices in the right places.

Kent767
08-18-2002, 01:56 AM
ok umm i'll try to make it as upfront as i can.. (i really hope the formatting comes out ok.. otherwise i'll post again)
the main program basically runs this:

for (int x=-100;x<=100;x+=100)
for (int y=-100;y<=100;y+=100)
for (int z=-100;z<=100;z+=100){
gfx.AddObject(1,x,y,z,0,0,0,0);
gfx.Particle(1,x/2,y/2,z/2);
}

rot+=0.3f;

gfx.Fog(keys[VK_F1]); //if f1 is pressed display fog
gfx.RenderObjects();
gfx.SetCamera(xcampos,ycampos,zcampos,0,0,0);


ok, these are the gfx routines to handle what the main has called..

void GFX::AddObject(int ObjectID,GLfloat xpos,GLfloat ypos,GLfloat zpos, GLfloat angle, GLfloat xrot,GLfloat yrot,GLfloat zrot)
{
glPushMatrix();
glTranslatef(xpos,ypos,zpos);
glRotatef(angle,xrot,yrot,zrot);
glScalef(Objects[ObjectID].scale,Objects[ObjectID].scale,Objects[ObjectID].scale);
glCallList(ObjectID);
glPopMatrix();
}

void GFX::SetCamera(GLfloat ox, GLfloat oy, GLfloat oz, GLfloat tx,GLfloat ty, GLfloat tz)
{
gluLookAt(ox,oy,oz,tx,ty,tz,0,1,0);
}

void GFX::RenderObjects()
{
glLoadIdentity();
SwapBuffers(g_hDC);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
}


and the particle code i know is messed up (so i'm posting it in the same manner as i would an object... because everything else i have tried has failed)

void GFX::Particle(int ParticleID,GLfloat xpos,GLfloat ypos,GLfloat zpos)
{

glPushMatrix();
glBindTexture(GL_TEXTURE_2D, PartTextures[ParticleID]);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTE R,GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTE R,GL_LINEAR);
glBegin(GL_QUADS);
glTexCoord2f(0.0f,0.0f); glVertex3f(xpos-0.5f,ypos-0.5f,zpos-3);
glTexCoord2f(1.0f,0.0f); glVertex3f(xpos+0.5f,ypos-0.5f,zpos-3);
glTexCoord2f(1.0f,1.0f); glVertex3f(xpos+0.5f,ypos+0.5f,zpos-3);
glTexCoord2f(0.0f,1.0f); glVertex3f(xpos-0.5f,ypos+0.5f,zpos-3);
glEnd();
glPopMatrix();