int mainbak(int argc, char** argv) { object1.id = 1; object2.id = 2; vec3 boxMax1 = vec3(2, 2, 2); vec3 boxMax2 = vec3(1, 1, 1); DtShapeRef shape1 = dtBox(boxMax1.x * 2, boxMax1.y * 2, boxMax1.z * 2); DtShapeRef shape2 = dtBox(boxMax2.x * 2, boxMax2.y * 2, boxMax2.z * 2); boxobj1 = BoundingBox(-boxMax1, boxMax1); boxobj2 = BoundingBox(-boxMax2, boxMax2); dtCreateObject(&object1, shape1); dtCreateObject(&object2, shape2); dtDisableCaching(); dtSetDefaultResponse(collide1, DT_SIMPLE_RESPONSE, stdout); if(NO_DISPLAY) return 0; draw(argc, argv); return 0; }
void SimCarCollideInit(tTrack *track) { dtSetDefaultResponse(SimCarCollideResponse, DT_SMART_RESPONSE, NULL); // Hmm, why is caching disabled, are our objects too fast, so it does not work? // TODO: understand this and reconsider caching. dtDisableCaching(); dtSetTolerance(0.001); fixedid = 0; if (track != NULL) { tTrackSeg *firstleft = getFirstWallStart(track->seg, TR_SIDE_LFT); tTrackSeg *firstright = getFirstWallStart(track->seg, TR_SIDE_RGT); buildWalls(firstleft, TR_SIDE_LFT); buildWalls(firstright, TR_SIDE_RGT); unsigned int i; for (i = 0; i < fixedid; i++) { dtCreateObject(&fixedobjects[i], fixedobjects[i]); dtSetObjectResponse(&fixedobjects[i], SimCarWallCollideResponse, DT_SMART_RESPONSE, &fixedobjects[i]); } } }
void SimCarCollideConfig(tCar *car) { tCarElt *carElt; carElt = car->carElt; // The current car shape is a box... car->shape = dtBox(carElt->_dimension_x, carElt->_dimension_y, carElt->_dimension_z); dtCreateObject(car, car->shape); car->collisionAware = 1; }
void SimCarCollideConfig(tCar *car, tTrack *track) { tCarElt *carElt; // Create car collision objects. carElt = car->carElt; // The current car shape is a box... car->shape = dtBox(carElt->_dimension_x, carElt->_dimension_y, carElt->_dimension_z); dtCreateObject(car, car->shape); car->collisionAware = 1; // Create fixed track collision objects (just pit wall for now). // TODO: car body/curbs collision. // TODO: car body/flat wall collision (e.g. for pavement, sidewalk). // TODO: define static objects in XML file/tTrack, collide with them as well. }
int main(int argc, char** argv) { object1.id = 1; object2.id = 2; /*vec3 boxMax1 = vec3(2, 2, 2); vec3 boxMax2 = vec3(1, 1, 1); boxobj1 = BoundingBox(-boxMax1, boxMax1); boxobj2 = BoundingBox(-boxMax2, boxMax2); */ boxobj1 = BoundingBox(vec3(-0.9438, -0.4669, -0.61679), vec3(0.607788, 1.06996, 0.587146)); boxobj2 = BoundingBox(vec3(1.056195, -0.46690, -0.6167920), vec3(2.6077880000000002, 1.0699599999999998, 0.58714600000000006)); /* DtShapeRef shape1 = dtBox(boxMax1.x * 2, boxMax1.y * 2, boxMax1.z * 2); DtShapeRef shape2 = dtBox(boxMax2.x * 2, boxMax2.y * 2, boxMax2.z * 2); */ vector<Point> solid_points0; vector<CP_Vector3D> points0 = boxobj1.GetAABBVertices(); for(int i = 0; i < points0.size(); i++) solid_points0.push_back(Point(points0[i].x, points0[i].y, points0[i].z)); vector<DtIndex> solid_indices0; auto indices = boxobj1.GetAABBIndices(); for(auto it = indices.begin(); it != indices.end(); it++) solid_indices0.push_back(*it); DtShapeRef shape1 = dtNewComplexShape(); dtVertexBase(&solid_points0[0]); for(int i = 0; i < solid_indices0.size()/3; i++) { dtBegin(DT_SIMPLEX); dtVertexIndex(solid_indices0[i*3+0]); dtVertexIndex(solid_indices0[i*3+1]); dtVertexIndex(solid_indices0[i*3+2]); dtEnd(); } //dtVertexIndices(DT_POLYHEDRON, solid_indices0.size(), &solid_indices0[0]); dtEndComplexShape(); vector<Point> solid_points1; vector<CP_Vector3D> points1 = boxobj2.GetAABBVertices(); for(int i = 0; i < points1.size(); i++) solid_points1.push_back(Point(points1[i].x, points1[i].y, points1[i].z)); auto indices1 = boxobj2.GetAABBIndices(); vector<DtIndex> solid_indices1(indices1.begin(), indices1.end()); DtShapeRef shape2 = dtNewComplexShape(); dtVertexBase(&solid_points1[0]); for(int i = 0; i < solid_indices1.size()/3; i++) { dtBegin(DT_SIMPLEX); dtVertexIndex(solid_indices1[i*3+0]); dtVertexIndex(solid_indices1[i*3+1]); dtVertexIndex(solid_indices1[i*3+2]); dtEnd(); } //dtVertexIndices(DT_POLYHEDRON, solid_indices1.size(), &solid_indices1[0]); dtEndComplexShape(); dtCreateObject(&object1, shape1); dtCreateObject(&object2, shape2); dtDisableCaching(); dtSetDefaultResponse(collide1, DT_SIMPLE_RESPONSE, stdout); if(NO_DISPLAY) return 0; draw(argc, argv); return 0; }