PhysicsBodyUnrecPtr buildBox(const Pnt3f& Position, const Vec3f& Dimensions, const Color3f& Color, Node* const spaceGroupNode, PhysicsWorld* const physicsWorld, PhysicsHashSpace* const physicsSpace) { Matrix m; //create OpenSG mesh GeometryUnrecPtr box; NodeUnrecPtr boxNode = makeBox(Dimensions.x(), Dimensions.y(), Dimensions.z(), 1, 1, 1); box = dynamic_cast<Geometry*>(boxNode->getCore()); SimpleMaterialUnrecPtr box_mat = SimpleMaterial::create(); box_mat->setAmbient(Color3f(0.0,0.0,0.0)); box_mat->setDiffuse(Color); box->setMaterial(box_mat); TransformUnrecPtr boxTrans; NodeUnrecPtr boxTransNode = makeCoredNode<Transform>(&boxTrans); m.setIdentity(); m.setTranslate(Position); boxTrans->setMatrix(m); //create ODE data PhysicsBodyUnrecPtr boxBody = PhysicsBody::create(physicsWorld); boxBody->setPosition(Vec3f(Position)); boxBody->setBoxMass(1.0,Dimensions.x(), Dimensions.y(), Dimensions.z()); boxBody->setLinearDamping(0.0001); boxBody->setAngularDamping(0.0001); PhysicsBoxGeomUnrecPtr boxGeom = PhysicsBoxGeom::create(); boxGeom->setBody(boxBody); boxGeom->setSpace(physicsSpace); boxGeom->setLengths(Dimensions); //add attachments boxNode->addAttachment(boxGeom); boxTransNode->addAttachment(boxBody); boxTransNode->addChild(boxNode); //add to SceneGraph spaceGroupNode->addChild(boxTransNode); return boxBody; }
////////////////////////////////////////////////////////////////////////// //! build a sphere ////////////////////////////////////////////////////////////////////////// PhysicsBodyUnrecPtr buildSphere(void) { Real32 Radius((Real32)(rand()%2)*0.5+0.5); Matrix m; //create OpenSG mesh GeometryUnrecPtr sphere; NodeUnrecPtr sphereNode = makeSphere(2, Radius); sphere = dynamic_cast<Geometry*>(sphereNode->getCore()); SimpleMaterialUnrecPtr sphere_mat = SimpleMaterial::create(); sphere_mat->setAmbient(Color3f(0.0,0.0,0.0)); sphere_mat->setDiffuse(Color3f(0.0,0.0,1.0)); sphere->setMaterial(sphere_mat); TransformUnrecPtr sphereTrans; NodeUnrecPtr sphereTransNode = makeCoredNode<Transform>(&sphereTrans); m.setIdentity(); Real32 randX = (Real32)(rand()%10)-5.0; Real32 randY = (Real32)(rand()%10)-5.0; m.setTranslate(randX, randY, 10.0); sphereTrans->setMatrix(m); //create ODE data PhysicsBodyUnrecPtr sphereBody = PhysicsBody::create(physicsWorld); sphereBody->setPosition(Vec3f(randX, randY, 10.0)); sphereBody->setLinearDamping(0.0001); sphereBody->setAngularDamping(0.0001); sphereBody->setSphereMass(1.0,Radius); PhysicsSphereGeomUnrecPtr sphereGeom = PhysicsSphereGeom::create(); sphereGeom->setBody(sphereBody); sphereGeom->setSpace(physicsSpace); sphereGeom->setRadius(Radius); //add attachments sphereNode->addAttachment(sphereGeom); sphereTransNode->addAttachment(sphereBody); sphereTransNode->addChild(sphereNode); //add to SceneGraph spaceGroupNode->addChild(sphereTransNode); commitChanges(); return sphereBody; }