Sign in to follow this  
SeCrEt-CoDe

Help with collision please

Recommended Posts

Hello

I was working on a project which consists of walls and each wall consists of many cubes and here is the function to draw the cube


void drawunitcube(float posx,float posy,float posz,float sizex,float sizey,float sizez,float rotangle,float rotx,float roty,float rotz)
{
glColor3f(1.0,1.0,1.0);

glTranslatef (posx,posy,posz);

glRotatef (rotangle,rotx,roty,rotz);

glBindTexture(GL_TEXTURE_2D, texture[0]);

glBegin(GL_QUADS);

//bottom face
//glColor3f(1.0,0.0,0.0);
glTexCoord2f(0.0f, 0.0f); glVertex3f (-0.5,-0.5,-0.5);
glTexCoord2f(1.0f, 0.0f); glVertex3f (-0.5 + sizex,-0.5,-0.5);
glTexCoord2f(1.0f, 1.0f); glVertex3f (-0.5 + sizex,-0.5,-0.5 + sizez);
glTexCoord2f(0.0f, 1.0f); glVertex3f (-0.5,-0.5,-0.5 + sizez);

//Top face
//glColor3f(1.0,0.0,0.0);
glTexCoord2f(0.0f, 0.0f); glVertex3f (-0.5,-0.5+sizey,-0.5);
glTexCoord2f(1.0f, 0.0f); glVertex3f (-0.5 + sizex,-0.5+sizey,-0.5);
glTexCoord2f(1.0f, 1.0f); glVertex3f (-0.5+sizex,-0.5+sizey,-0.5+sizez);
glTexCoord2f(0.0f, 1.0f); glVertex3f (-0.5,-0.5+sizey,-0.5+sizez);

//Right face
//glColor3f(0.0,1.0,0.0);
glTexCoord2f(0.0f, 0.0f); glVertex3f (-0.5 + sizex,-0.5,-0.5);
glTexCoord2f(1.0f, 0.0f); glVertex3f (-0.5 + sizex,-0.5,-0.5 + sizez);
glTexCoord2f(1.0f, 1.0f); glVertex3f (-0.5+sizex,-0.5+sizey,-0.5+sizez);
glTexCoord2f(0.0f, 1.0f); glVertex3f (-0.5 + sizex,-0.5+sizey,-0.5);

//Left face
//glColor3f(0.0,0.0,1.0);
glTexCoord2f(0.0f, 0.0f); glVertex3f (-0.5,-0.5,-0.5 + sizez);
glTexCoord2f(1.0f, 0.0f); glVertex3f (-0.5,-0.5,-0.5);
glTexCoord2f(1.0f, 1.0f); glVertex3f (-0.5,-0.5+sizey,-0.5);
glTexCoord2f(0.0f, 1.0f); glVertex3f (-0.5,-0.5+sizey,-0.5+sizez);

//Back face
//glColor3f(0.5,0.5,0.5);
glTexCoord2f(0.0f, 0.0f); glVertex3f (-0.5 + sizex,-0.5,-0.5 + sizez);
glTexCoord2f(1.0f, 0.0f); glVertex3f (-0.5,-0.5,-0.5 + sizez);
glTexCoord2f(1.0f, 1.0f); glVertex3f (-0.5,-0.5+sizey,-0.5+sizez);
glTexCoord2f(0.0f, 1.0f); glVertex3f (-0.5+sizex,-0.5+sizey,-0.5+sizez);

//Front face
//glColor3f(0.5,0.5,0.5);
glTexCoord2f(0.0f, 0.0f); glVertex3f (-0.5,-0.5,-0.5);
glTexCoord2f(1.0f, 0.0f); glVertex3f (-0.5 + sizex,-0.5,-0.5);
glTexCoord2f(1.0f, 1.0f); glVertex3f (-0.5 + sizex,-0.5+sizey,-0.5);
glTexCoord2f(0.0f, 1.0f); glVertex3f (-0.5,-0.5+sizey,-0.5);

glEnd();


}



and I constructed a maze using these cubes (walls) which is drawn using matrix of 1's and 0's

and I have a sphere to navigate through the maze


void display(void)
{
glClear (GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

glPushMatrix();

glColor3f (1.0,0.0,0.0);

glutSolidSphere(0.25,100,100);

glPopMatrix();
}



assuming that the maze and sphere is drawn ...
how can I make collision with the inner faces of cubes and the sphere ??
the problem is I can't keep track of position of the sphere and the cubes

Thanks alot in advance

Share this post


Link to post
Share on other sites
Note that the calls to glPushMatrix() and glPopMatrix() in your display() function don't have any effect, and can be taken out.
Quote:
the problem is I can't keep track of position of the sphere and the cubes
Sure you can. Why don't you think that you can?

Share this post


Link to post
Share on other sites
Thanks alot ...

I have the positions of the walls .. but when moving the sphere I'm not moving it on the 0's of the matrix ... when that matrix is drawn I don't use it again
cuz the scale is different from the scene ...
any way to match the moving poisitions of sphere with the walls matrix ??

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this