PDA

View Full Version : bullet(well... paintball) physics?



c_olin
05-14-2003, 11:00 AM
for the fps im making i am doing bullet physics... here is my code so far



class paint
{
public:
GLfloat heading;
GLfloat xpos;
GLfloat zpos;
GLfloat ypos;
int go;
void newPaint(GLfloat heading1, GLfloat xpos1, GLfloat ypos1, GLfloat zpos1);
void updatePaint();
void drawPaint();
};

void paint::newPaint(GLfloat heading1, GLfloat xpos1, GLfloat ypos1, GLfloat zpos1)
{
xpos = xpos1;
ypos = ypos1;
zpos = zpos1;
heading = heading1;
go = 1;
}

void paint::updatePaint()
{
xpos += (float)sin(heading*piover180) * 0.5f * speed;
zpos += (float)cos(heading*piover180) * 0.5f * speed;
}

void paint::drawPaint()
{

glTranslatef(xpos, 5.5f, zpos);
ballmesh.Render(1.0f, 0.0f, 0.0f);
}
paint ball[100];
for(int i = 0; i < 100; i++)
{
if(ball[i].go == 1) ball[i].updatePaint();
}
for(int j = 0; j < 100; j++)
{
if(j > 1) glTranslatef(ball[j - 1].xpos, -5.5f, ball[j - 1].zpos);
if(ball[j].go == 1) ball[j].drawPaint();

}
id(mouseclick)
{
ball[ballcount].newPaint(mcamera.heading , mcamera.xpos, 5.5f, mcamera.zpos);
ballcount++;

}



it works fine for the first ball, but all the balls after that get a weird heading!

please hlep

[This message has been edited by c_olin (edited 05-14-2003).]

Relic
05-15-2003, 12:50 AM
Try this:

void paint::drawPaint()
{
glPushMatrix();
glTranslatef(xpos, 5.5f, zpos);
ballmesh.Render(1.0f, 0.0f, 0.0f);
glPopMatrix();
}

for(int j = 0; j < 100; j++)
{
/* if(j > 1)
glTranslatef(ball[j - 1].xpos, -5.5f, ball[j - 1].zpos);
*/
if(ball[j].go == 1)
ball[j].drawPaint();
}


[This message has been edited by Relic (edited 05-15-2003).]

c_olin
05-15-2003, 07:35 AM
thanks!

what does the pushmatrix and popmatrix do to the heading?

Relic
05-15-2003, 07:51 AM
RTFM http://www.opengl.org/discussion_boards/ubb/biggrin.gif (Couldn't resist) http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc03_246w .asp (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/opengl/glfunc03_246w.asp)

In your case it prohibits that your glTranslatef calls accumulate in the modelview matrix by saving and restoring the current matrix so that your drawPaint doesn't change it.
You tried to do that same by resetting the translate of the previous ball but forgot to negate the x and z values.
But your code would have broken if one previous ball has go=0 (in case it has hit something and is taken out of the list).

[This message has been edited by Relic (edited 05-15-2003).]