void MFCollision_DrawItem(MFCollisionItem *pItem) { // maybe reject it if its not in range.. MFVector colour = (pItem->flags & MFCIF_Disabled) ? MakeVector(1,0,0,1) : ((pItem->flags & MFCIF_Dynamic) ? MakeVector(0,0,1,1) : MakeVector(0,1,0,1)); MFMaterial_SetMaterial(MFMaterial_GetStockMaterial(MFMat_White)); switch(pItem->pTemplate->type) { case MFCT_Sphere: { MFCollisionSphere *pSphere = (MFCollisionSphere*)pItem->pTemplate->pCollisionTemplateData; MFPrimitive_DrawSphere(MFVector::zero, pSphere->radius, 8, 7, colour, pItem->worldPos, true); break; } case MFCT_Mesh: { MFCollisionMesh *pMesh = (MFCollisionMesh*)pItem->pTemplate->pCollisionTemplateData; int a; // draw each triangle MFPrimitive(PT_TriList); MFSetMatrix(pItem->worldPos); MFBegin(pMesh->numTris * 3); MFSetColour(1.0f, 1.0f, 1.0f, 0.5f); for(a=0; a<pMesh->numTris; a++) { if(pMesh->pTriangles[a].flags) MFSetColour(1.0f, 0.0f, 0.0f, 0.5f); MFSetPositionV(pMesh->pTriangles[a].verts[0]); MFSetPositionV(pMesh->pTriangles[a].verts[1]); MFSetPositionV(pMesh->pTriangles[a].verts[2]); if(pMesh->pTriangles[a].flags) { MFSetColour(1.0f, 1.0f, 1.0f, 0.5f); pMesh->pTriangles[a].flags = 0; } } MFEnd(); // draw each triangle outline MFPrimitive(PT_LineList); MFSetMatrix(pItem->worldPos); MFBegin(pMesh->numTris * 12); MFSetColourV(colour); for(a=0; a<pMesh->numTris; a++) { MFSetPositionV(pMesh->pTriangles[a].verts[0]); MFSetPositionV(pMesh->pTriangles[a].verts[1]); MFSetPositionV(pMesh->pTriangles[a].verts[1]); MFSetPositionV(pMesh->pTriangles[a].verts[2]); MFSetPositionV(pMesh->pTriangles[a].verts[2]); MFSetPositionV(pMesh->pTriangles[a].verts[0]); MFVector e1, e2, e3; e1 = (pMesh->pTriangles[a].verts[0] + pMesh->pTriangles[a].verts[1]) * 0.5f; e2 = (pMesh->pTriangles[a].verts[1] + pMesh->pTriangles[a].verts[2]) * 0.5f; e3 = (pMesh->pTriangles[a].verts[2] + pMesh->pTriangles[a].verts[0]) * 0.5f; MFSetPositionV(e1); MFSetPositionV(e1 + pMesh->pTriangles[a].edgePlanes[0] * 2.0f); MFSetPositionV(e2); MFSetPositionV(e2 + pMesh->pTriangles[a].edgePlanes[1] * 2.0f); MFSetPositionV(e3); MFSetPositionV(e3 + pMesh->pTriangles[a].edgePlanes[2] * 2.0f); // MFVector c = (pMesh->pTriangles[a].verts[0] + pMesh->pTriangles[a].verts[1] + pMesh->pTriangles[a].verts[2]) * (1.0f / 3.0f); // MFSetPosition(c); // MFSetPosition(c + pMesh->pTriangles[a].plane*3.0f); } MFEnd(); break; } case MFCT_Field: break; default: break; } }
void Game_Draw() { MFCALLSTACK; MFRenderer_SetClearColour(0.f, 0.f, 0.2f, 1.f); MFRenderer_ClearScreen(); // Set identity camera (no camera) MFView_Push(); MFView_SetAspectRatio(MFDisplay_GetNativeAspectRatio()); MFView_SetProjection(); MFMaterial_SetMaterial(MFMaterial_GetStockMaterial(MFMat_White)); // set the world matrix to identity MFMatrix world = MFMatrix::identity; // move the box into the scene (along the z axis) world.Translate(MakeVector(0, 0, 5)); // increment rotation static float rotation = 0.0f; rotation += MFSystem_TimeDelta(); // rotate the box world.RotateYPR(rotation, rotation * 2.0f, rotation * 0.5f); // begin rendering the box MFPrimitive(PT_TriList); MFSetMatrix(world); // begin rendering 12 triangles (12 * 3 vertices) MFBegin(3 * 12); // draw a bunch of triangles MFSetColour(1,0,0,1); MFSetPosition(-1,-1, -1); MFSetPosition(-1, 1, -1); MFSetPosition( 1, 1, -1); MFSetPosition(-1,-1, -1); MFSetPosition( 1, 1, -1); MFSetPosition( 1,-1, -1); MFSetColour(0,1,0,1); MFSetPosition(-1,-1,1); MFSetPosition( 1,-1,1); MFSetPosition( 1, 1,1); MFSetPosition(-1,-1,1); MFSetPosition( 1, 1,1); MFSetPosition(-1, 1,1); MFSetColour(0,0,1,1); MFSetPosition( 1,-1,1); MFSetPosition( 1,-1,-1); MFSetPosition( 1, 1,-1); MFSetPosition( 1,-1,1); MFSetPosition( 1, 1,-1); MFSetPosition( 1, 1,1); MFSetColour(1,0,1,1); MFSetPosition(-1,-1,1); MFSetPosition(-1, 1,1); MFSetPosition(-1, 1,-1); MFSetPosition(-1,-1,1); MFSetPosition(-1, 1,-1); MFSetPosition(-1,-1,-1); MFSetColour(1,1,0,1); MFSetPosition(-1, 1,1); MFSetPosition( 1, 1,1); MFSetPosition( 1, 1,-1); MFSetPosition(-1, 1,1); MFSetPosition( 1, 1,-1); MFSetPosition(-1, 1,-1); MFSetColour(0,1,1,1); MFSetPosition(-1,-1,1); MFSetPosition(-1,-1,-1); MFSetPosition( 1,-1,-1); MFSetPosition(-1,-1,1); MFSetPosition( 1,-1,-1); MFSetPosition( 1,-1,1); MFEnd(); MFRect disp; MFDisplay_GetDisplayRect(&disp); MFView_SetOrtho(&disp); pUI->Draw(); MFView_Pop(); }