int InitGLObjects()										// Initialize Objects
{
	if (!ReadObject("Data/Object2.txt", &obj))			// Read Object2 Into obj
	{
		return FALSE;									// If Failed Return False
	}

	SetConnectivity(&obj);								// Set Face To Face Connectivity

	for (unsigned int i=0;i<obj.nPlanes;i++)			// Loop Through All Object Planes
		CalcPlane(obj, &(obj.planes[i]));				// Compute Plane Equations For All Faces

	return TRUE;										// Return True
}
Exemple #2
0
Object *InitObject(char *objfile)
{
	int nf;
	Object *obj;
		
	if((obj = LoadObject(objfile)) != NULL){
		SetConnectivity(obj);

		for(nf=0; nf < obj->nFaces; nf++)
			CalculatePlane(obj, nf);
	}

	return obj;
}
Exemple #3
0
bool SHADOW_MODEL::GenerateTorus(float innerRadius, float outerRadius)
{
	int torusPrecision=24;

	numVertices=(torusPrecision+1)*(torusPrecision+1);
	numIndices=2*torusPrecision*torusPrecision*3;
	numTriangles=numIndices/3;

	vertices=new SHADOW_MODEL_VERTEX[numVertices];
	if(!vertices)
	{
		errorLog.OutputError("Unable to allocate memory for torus vertices");
		return false;
	}

	indices=new unsigned int[numIndices];
	if(!indices)
	{
		errorLog.OutputError("Unable to allocate memory for torus indices");
		return false;
	}
	
	//calculate the first ring - inner radius 4, outer radius 1.5
	for(int i=0; i<torusPrecision+1; i++)
	{
		vertices[i].position=VECTOR3D(innerRadius, 0.0f, 0.0f).GetRotatedZ(i*360.0f/torusPrecision)+
									VECTOR3D(outerRadius, 0.0f, 0.0f);
		
		vertices[i].normal=VECTOR3D(0.0f, 0.0f, 1.0f).
							CrossProduct(VECTOR3D(0.0f, -1.0f, 0.0f).GetRotatedZ(i*360.0f/torusPrecision));
	}

	//rotate this to get other rings
	for(int ring=1; ring<torusPrecision+1; ring++)
	{
		for(int i=0; i<torusPrecision+1; i++)
		{
			vertices[ring*(torusPrecision+1)+i].position=vertices[i].position.GetRotatedY(ring*360.0f/torusPrecision);
			
			vertices[ring*(torusPrecision+1)+i].normal=vertices[i].normal.GetRotatedY(ring*360.0f/torusPrecision);
		}
	}

	//calculate the indices
	for(int ring=0; ring<torusPrecision; ring++)
	{
		for(int i=0; i<torusPrecision; i++)
		{
			indices[((ring*torusPrecision+i)*2)*3+0]=ring*(torusPrecision+1)+i;
			indices[((ring*torusPrecision+i)*2)*3+1]=(ring+1)*(torusPrecision+1)+i;
			indices[((ring*torusPrecision+i)*2)*3+2]=ring*(torusPrecision+1)+i+1;
			indices[((ring*torusPrecision+i)*2+1)*3+0]=ring*(torusPrecision+1)+i+1;
			indices[((ring*torusPrecision+i)*2+1)*3+1]=(ring+1)*(torusPrecision+1)+i;
			indices[((ring*torusPrecision+i)*2+1)*3+2]=(ring+1)*(torusPrecision+1)+i+1;
		}
	}


	//Calculate the plane equation for each face
	planeEquations=new PLANE[numTriangles];
	if(!planeEquations)
	{
		errorLog.OutputError("Unable to allocate memory for %d planes", numTriangles);
		return false;
	}

	for(unsigned int j=0; j<numTriangles; ++j)
	{
		planeEquations[j].SetFromPoints(vertices[indices[j*3+0]].position,
										vertices[indices[j*3+1]].position,
										vertices[indices[j*3+2]].position);
	}

	//Create space for the "is facing light" booleans
	isFacingLight=new bool[numTriangles];
	if(!isFacingLight)
	{
		errorLog.OutputError("Unable to allocate memory for %d booleans", numTriangles);
		return false;
	}

	//Create space for connectivity data
	neighbourIndices=new GLint[numTriangles*3];
	if(!neighbourIndices)
	{
		errorLog.OutputError("Unable to allocate memory for %d neighbour indices", numTriangles*3);
		return false;
	}

	//Create space for "is silhouette edge" booleans
	isSilhouetteEdge=new bool[numTriangles*3];
	if(!isSilhouetteEdge)
	{
		errorLog.OutputError("Unable to allocate memory for %d booleans", numTriangles*3);
		return false;
	}

	//Calculate the neighbours
	SetConnectivity();

	return true;
}