Jun 20, 2014 at 6:58pm UTC
Hi Everyone,
I would like to understand how to rotate a 3D Object around it's Center, by modifying it's Vertex Coordinates.
Not by using glRotatef...
The reason is that I need to keep track of the new coordinates because of my collision system, which is based on Vertex Coords.
Here is the Code for an Object Thanks Guys!
void DrawHouse(GLfloat x1, GLfloat x2, GLfloat y1, GLfloat y2, GLfloat z1,GLfloat z2, GLfloat u1, GLfloat u2, GLfloat v1, GLfloat v2, GLuint textid)
{
glBindTexture(GL_TEXTURE_2D, textid);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(u1,v1); glVertex3f(x1,y1,z2);
glTexCoord2f(u2,v1); glVertex3f(x2,y1,z2);
glTexCoord2f(u2,v2); glVertex3f(x2,y2,z2);
glEnd();
glBindTexture(GL_TEXTURE_2D, textid);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(u2,v2); glVertex3f(x2,y2,z2);
glTexCoord2f(u1,v2); glVertex3f(x1,y2,z2);
glTexCoord2f(u1,v1); glVertex3f(x1,y1,z2);
glEnd();
glBindTexture(GL_TEXTURE_2D, textid);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(u1,v1); glVertex3f(x1,y1,z1);
glTexCoord2f(u2,v1); glVertex3f(x2,y1,z1);
glTexCoord2f(u2,v2); glVertex3f(x2,y2,z1);
glEnd();
glBindTexture(GL_TEXTURE_2D, textid);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(u2,v2); glVertex3f(x2,y2,z1);
glTexCoord2f(u1,v2); glVertex3f(x1,y2,z1);
glTexCoord2f(u1,v1); glVertex3f(x1,y1,z1);
glEnd();
glBindTexture(GL_TEXTURE_2D, textid);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(u1,v1); glVertex3f(x2,y1,z2);
glTexCoord2f(u2,v1); glVertex3f(x2,y1,z1);
glTexCoord2f(u2,v2); glVertex3f(x2,y2,z1);
glEnd();
glBindTexture(GL_TEXTURE_2D, textid);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(u2,v2); glVertex3f(x2,y2,z1);
glTexCoord2f(u1,v2); glVertex3f(x2,y2,z2);
glTexCoord2f(u1,v1); glVertex3f(x2,y1,z2);
glEnd();
glBindTexture(GL_TEXTURE_2D, textid);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(u1,v1); glVertex3f(x1,y1,z2);
glTexCoord2f(u2,v1); glVertex3f(x1,y1,z1);
glTexCoord2f(u2,v2); glVertex3f(x1,y2,z1);
glEnd();
glBindTexture(GL_TEXTURE_2D, textid);
glBegin(GL_TRIANGLES);
glNormal3f( 0.0f, 0.0f, 1.0f);
glTexCoord2f(u2,v2); glVertex3f(x1,y2,z1);
glTexCoord2f(u1,v2); glVertex3f(x1,y2,z2);
glTexCoord2f(u1,v1); glVertex3f(x1,y1,z2);
glEnd();
//COLLISION WITH CHARACTER
if(xtrans <= -(x1-0.2) && xtrans >= -(x2+0.2) && ztrans <= -(z1-0.2) && ztrans >= -(z2+0.2))
{
if(MoveForward)
{
xpos += 2*(float)sin(heading*piover180) * 0.0005f;
zpos += 2*(float)cos(heading*piover180) * 0.0005f;
}
if(MoveBackward)
{
xpos -= 2*(float)sin(heading*piover180) * 0.0005f;
zpos -= 2*(float)cos(heading*piover180) * 0.0005f;
}
}
DrawDoor(x2, x2 + 0.1, 0.0 , 0.5, z2 - (z2-z1)/2 + 0.25, z2 - (z2-z1)/2 - 0.25, 0.0, 1.0, 0.0, 1.0, texture[1], texture[3]);
}