void RaceCircuit::create() { setMargin(2.f); const float scaling = PhysicsState::engine->simulateScale(); btVector3 * pos = createVertexPos(sNumVertices); int i; for(i = 0; i < sNumVertices; i++) { Vector3F q(sMeshVertices[i * 3] - sMeshNormals[i * 3] * margin(), sMeshVertices[i * 3 + 1] - sMeshNormals[i * 3 + 1] * margin(), sMeshVertices[i * 3 + 2] - sMeshNormals[i * 3 + 2] * margin()); q *= scaling; pos[i] = btVector3(q.x, q.y, q.z); } int * idx = createTriangles(sNumTriangleIndices / 3); for(i = 0; i < sNumTriangleIndices; i++) { idx[i] = sMeshTriangleIndices[i]; } btBvhTriangleMeshShape* shp = createCollisionShape(); Matrix44F trans; btRigidBody * bd = PhysicsState::engine->createRigidBody(shp, trans, 0.f); bd->setFriction(.768f); }
void render() { if (initialized == false) { createTriangles(); initialized = true; } glClear(GL_COLOR_BUFFER_BIT); renderTriangles(); }
/** \brief triangulate the scrap data */ void cwTriangulateTask::triangulateScrap(int index) { cwTriangulateInData& scrapData = Scraps[index]; QRectF bounds = scrapData.outline().boundingRect(); cwImage croppedImage = TriangulatedScraps[index].croppedImage(); //Create the regualar mesh that covers the croppedImage PointGrid pointGrid = createPointGrid(bounds, scrapData); //Find all the points in the regualar mesh that are in the scrap's polygon QSet<int> gridPointsInScrap = pointsInPolygon(pointGrid, scrapData.outline()); //Creates list of quads that are on the edges or in the scrap QuadDatabase quads = createQuads(pointGrid, scrapData.outline()); //Triangulate the quads (this will update the outputs data) cwTriangulatedData triangleData = createTriangles(pointGrid, gridPointsInScrap, quads, scrapData); //Create the matrix that converts the normalized coords to the normalized coords QMatrix4x4 toLocal = localNormalizedCoordinates(bounds); //Convert the normalized points to local note points QVector<QVector3D> localNotePoints = mapToLocalNoteCoordinates(toLocal, triangleData.points()); //Create the texture coordinates QVector<QVector2D> texCoords = mapTexCoordinates(localNotePoints); //Morph the points for the scrap QVector<QVector3D> points = morphPoints(triangleData.points(), scrapData, toLocal, croppedImage); //Morph the lead points for the scrap QVector<QVector3D> leadPoints = morphPoints(leadPositionToVector3D(scrapData.leads()), scrapData, toLocal, croppedImage); //For testing cwTriangulatedData& outScrapData = TriangulatedScraps[index]; outScrapData.setIndices(triangleData.indices()); outScrapData.setPoints(points); outScrapData.setTexCoords(texCoords); outScrapData.setLeadPoints(leadPoints); }