Beispiel #1
0
void AseFile::AddCollisionFaces(vector<z_face> *faces, const vec center, float radius)
{
	z_face f;
	if(!SphereInBox( center, radius, min, max))return;
	for(int i=0; i<objects.size(); i++)
	{
		zASE_Object *obj = &objects[i];
		if(!SphereInBox( center, radius, obj->min, obj->max))continue;
		for( int j=0; j<obj->numOfFaces; j++)
		{
			zASE_Face *ind = &obj->pFaces[j];
			if( SpherePolygonCollision( center, radius, obj->pVerts[ind->index[0]], obj->pVerts[ind->index[1]], obj->pVerts[ind->index[2]], obj->pFaceNormals[j] ) )
			{
				f.a = obj->pVerts[ind->index[0]];
				f.b = obj->pVerts[ind->index[1]];
				f.c = obj->pVerts[ind->index[2]];
				f.normal = obj->pFaceNormals[j];
				faces->push_back(f);
			}
		}
	}
}
Beispiel #2
0
void RenderScene() 
{
    int i=0;    

    glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); // Clear The Screen And The Depth Buffer
    glLoadIdentity();                                   // Reset The matrix


/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *

    // Set our camera to the left a bit for a nice side view of the left hand side

        //      Position          View       Up Vector
    gluLookAt(-2.5f, 0.5, -0.1,  0, 0.5f, 0,   0, 1, 0); // This determines where the camera's position and view is

    // Rotate the camera around our world for a 360 degree view of what is going on.
    // Yes I know... we are actually rotating the whole world, not the camera :)
    glRotatef(g_rotateY, 0, 1, 0);

    // We need a radius for our sphere, so let's create it here with 0.1
    float radius = 0.1f;
    
    // Draw the polygon

    glBegin (GL_TRIANGLES);                             // This is our BEGIN to draw

        glColor3ub(255, 0, 0);                          // Make the Left vertex RED
        glVertex3f(g_vTriangle[0].x, g_vTriangle[0].y, g_vTriangle[0].z);

        glColor3ub(0, 255, 0);                          // Make the Right vertex GREEN
        glVertex3f(g_vTriangle[1].x, g_vTriangle[1].y, g_vTriangle[1].z);

        glColor3ub(0, 0, 255);                          // Make the Top vertex BLUE
        glVertex3f(g_vTriangle[2].x, g_vTriangle[2].y, g_vTriangle[2].z);
    glEnd();                                            // This is the END of drawing

    // Instead of calculating the sphere ourselves, we are going to use quadrics.
    // Check out the tutorial on quadrics if this is confusing for you.

    // Allocate a quadric object to use as a sphere
    GLUquadricObj *pObj = gluNewQuadric();              // Get a Quadric off the stack

    // To make it easier to see, we want the sphere to be in wire frame
    gluQuadricDrawStyle(pObj, GLU_LINE);                // Draw the sphere normally

    // Move the sphere to it's center position
    glTranslatef(g_vPosition.x, g_vPosition.y, g_vPosition.z);

    // Now we get to the wonderful function that does it all for us.  All we
    // need to do is pass in the array of vertices for the triangle, the center
    // of the sphere and it's radius.  This will return a true or false, depending
    // on if we collided or not.  True = The Sphere Collided
    bool bCollided = SpherePolygonCollision(g_vTriangle, g_vPosition, 3, radius);   
    
    // If we collided we want the sphere to be green, otherwise it should be purple
    if(bCollided)
        glColor3ub(0, 255, 0);                          // Make the sphere green
    else        
        glColor3ub(255, 0, 255);                        // Make the sphere purple
        
    // Draw the quadric as a sphere with the radius of .1 and a 15 by 15 detail.
    // To increase the detail of the sphere, just increase the 2 last parameters.
    gluSphere(pObj, radius, 15, 15);

    gluDeleteQuadric(pObj);                             // Free the Quadric

/////// * /////////// * /////////// * NEW * /////// * /////////// * /////////// *


    SDL_GL_SwapBuffers();                                   // Swap the backbuffers to the foreground
}