int main(int argc,char** argv) { raytracePicture = new RenderTexture(screenWidth,screenHeight); myBox.SetMargin(0.02f); myCone.SetMargin(0.2f); simplex.SetSimplexSolver(&simplexSolver); simplex.AddVertex(SimdPoint3(-1,0,-1)); simplex.AddVertex(SimdPoint3(1,0,-1)); simplex.AddVertex(SimdPoint3(0,0,1)); simplex.AddVertex(SimdPoint3(0,1,0)); /// convex hull of 5 spheres #define NUM_SPHERES 5 SimdVector3 inertiaHalfExtents(10.f,10.f,10.f); SimdVector3 positions[NUM_SPHERES] = { SimdVector3(-1.2f, -0.3f, 0.f), SimdVector3(0.8f, -0.3f, 0.f), SimdVector3(0.5f, 0.6f, 0.f), SimdVector3(-0.5f, 0.6f, 0.f), SimdVector3(0.f, 0.f, 0.f) }; SimdScalar radi[NUM_SPHERES] = { 0.35f,0.35f,0.45f,0.40f,0.40f }; MultiSphereShape multiSphereShape(inertiaHalfExtents,positions,radi,NUM_SPHERES); ConvexHullShape convexHullShape(positions,3); //choose shape shapePtr[0] = &myCone; shapePtr[1] =&simplex; shapePtr[2] =&convexHullShape; shapePtr[3] =&myMink;//myBox; simplex.SetMargin(0.3f); setCameraDistance(6.f); return glutmain(argc, argv,screenWidth,screenHeight,"Minkowski-Sum Raytracer Demo"); }
void Raytracer::initPhysics() { raytracePicture = new RenderTexture(screenWidth,screenHeight); myBox.SetMargin(0.02f); myCone.SetMargin(0.2f); simplex.SetSimplexSolver(&simplexSolver); simplex.AddVertex(SimdPoint3(-1,0,-1)); simplex.AddVertex(SimdPoint3(1,0,-1)); simplex.AddVertex(SimdPoint3(0,0,1)); simplex.AddVertex(SimdPoint3(0,1,0)); /// convex hull of 5 spheres #define NUM_SPHERES 5 SimdVector3 inertiaHalfExtents(10.f,10.f,10.f); SimdVector3 positions[NUM_SPHERES] = { SimdVector3(-1.2f, -0.3f, 0.f), SimdVector3(0.8f, -0.3f, 0.f), SimdVector3(0.5f, 0.6f, 0.f), SimdVector3(-0.5f, 0.6f, 0.f), SimdVector3(0.f, 0.f, 0.f) }; // MultiSphereShape* multiSphereShape = new MultiSphereShape(inertiaHalfExtents,positions,radi,NUM_SPHERES); ConvexHullShape* convexHullShape = new ConvexHullShape(positions,3); //choose shape shapePtr[0] = &myCone; shapePtr[1] =&simplex; shapePtr[2] =convexHullShape; shapePtr[3] =&myMink;//myBox;//multiSphereShape simplex.SetMargin(0.3f); }
void clientDisplay(void) { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); glDisable(GL_LIGHTING); //GL_ShapeDrawer::DrawCoordSystem(); float m[16]; int i; GjkPairDetector convexConvex(shapePtr[0],shapePtr[1],&sGjkSimplexSolver,0); SimdVector3 seperatingAxis(0.00000000f,0.059727669f,0.29259586f); convexConvex.SetCachedSeperatingAxis(seperatingAxis); PointCollector gjkOutput; GjkPairDetector::ClosestPointInput input; input.m_transformA = tr[0]; input.m_transformB = tr[1]; convexConvex.GetClosestPoints(input ,gjkOutput,0); if (gjkOutput.m_hasResult) { SimdVector3 endPt = gjkOutput.m_pointInWorld + gjkOutput.m_normalOnBInWorld*gjkOutput.m_distance; glBegin(GL_LINES); glColor3f(1, 0, 0); glVertex3d(gjkOutput.m_pointInWorld.x(), gjkOutput.m_pointInWorld.y(),gjkOutput.m_pointInWorld.z()); glVertex3d(endPt.x(),endPt.y(),endPt.z()); //glVertex3d(gjkOutputm_pointInWorld.x(), gjkOutputm_pointInWorld.y(),gjkOutputm_pointInWorld.z()); //glVertex3d(gjkOutputm_pointInWorld.x(), gjkOutputm_pointInWorld.y(),gjkOutputm_pointInWorld.z()); glEnd(); } for (i=0; i<numObjects; i++) { tr[i].getOpenGLMatrix( m ); GL_ShapeDrawer::DrawOpenGL(m,shapePtr[i],SimdVector3(1,1,1),getDebugMode()); } simplex.SetSimplexSolver(&sGjkSimplexSolver); SimdPoint3 ybuf[4],pbuf[4],qbuf[4]; int numpoints = sGjkSimplexSolver.getSimplex(pbuf,qbuf,ybuf); simplex.Reset(); for (i=0; i<numpoints; i++) simplex.AddVertex(ybuf[i]); SimdTransform ident; ident.setIdentity(); ident.getOpenGLMatrix(m); GL_ShapeDrawer::DrawOpenGL(m,&simplex,SimdVector3(1,1,1),getDebugMode()); SimdQuaternion orn; orn.setEuler(yaw,pitch,roll); tr[0].setRotation(orn); // pitch += 0.005f; // yaw += 0.01f; glFlush(); glutSwapBuffers(); }