u32 wsScene::addModel(wsModel* myModel) { u32 modelHash = wsHash(myModel->getName()); if (models->insert(modelHash, myModel) == WS_SUCCESS) { #if WS_PHYSICS_BACKEND == WS_BACKEND_BULLET const vec4 dimensions = myModel->getBounds(); btCollisionShape* boundsShape; if (myModel->getCollisionShape() == WS_NULL) { boundsShape = wsNew(btBoxShape, btBoxShape(btVector3(dimensions.x, dimensions.y, dimensions.z))); } else { wsCollisionShape* shape = myModel->getCollisionShape(); switch (shape->getType()) { default: boundsShape = wsNew(btBoxShape, btBoxShape(btVector3(dimensions.x, dimensions.y, dimensions.z))); break; case WS_SHAPE_CAPSULE: boundsShape = wsNew(btCapsuleShape, btCapsuleShape(shape->getDim0(), shape->getDim1())); break; case WS_SHAPE_CUBE: boundsShape = wsNew(btBoxShape, btBoxShape(btVector3(shape->getDim0(), shape->getDim1(), shape->getDim2()))); break; case WS_SHAPE_CYLINDER: boundsShape = wsNew(btCylinderShape, btCylinderShape(btVector3(shape->getDim0(), shape->getDim1()/2.0f, shape->getDim0()))); break; case WS_SHAPE_SPHERE: boundsShape = wsNew(btSphereShape, btSphereShape(shape->getDim0())); break; } } f32 mass = myModel->getMass(); btVector3 myInertia(0.0f, 0.0f, 0.0f); boundsShape->calculateLocalInertia(mass, myInertia); btRigidBody::btRigidBodyConstructionInfo modelRigidBodyCI(mass, myModel->getTransformp(), boundsShape, myInertia); btRigidBody* modelRigidBody = wsNew(btRigidBody, btRigidBody(modelRigidBodyCI)); if (myModel->getProperties() & WS_MODEL_LOCK_HORIZ_ROTATIONS) { modelRigidBody->setAngularFactor(btVector3(0.0f, 0.0f, 0.0f)); } modelRigidBody->setActivationState(DISABLE_DEACTIVATION); rigidBodies->insert(modelHash, modelRigidBody); physicsWorld->addRigidBody(modelRigidBody, myModel->getCollisionClass(), collisionClasses[(u32)wsLog2(myModel->getCollisionClass())]); #endif return modelHash; } return WS_NULL; }// End addModel(wsModel*) method
void wsScene::addAnimation(wsAnimation* myAnim, const char* modelName) { wsModel* myModel = models->retrieve(wsHash(modelName)); myModel->addAnimation(myAnim); #if WS_PHYSICS_BACKEND == WS_BACKEND_BULLET char animName[512]; strcpy(animName, modelName); strcat(animName, myAnim->getName()); u32 boundsHash = wsHash(animName); const vec4 dimensions = myAnim->getBounds(); btCollisionShape* boundsShape; if (myModel->getCollisionShape() == WS_NULL) { boundsShape = wsNew(btBoxShape, btBoxShape(btVector3(dimensions.x, dimensions.y, dimensions.z))); } else { wsCollisionShape* shape = myModel->getCollisionShape(); switch (shape->getType()) { default: boundsShape = wsNew(btBoxShape, btBoxShape(btVector3(dimensions.x, dimensions.y, dimensions.z))); break; case WS_SHAPE_CAPSULE: boundsShape = wsNew(btCapsuleShape, btCapsuleShape(shape->getDim0(), shape->getDim1())); break; case WS_SHAPE_CUBE: boundsShape = wsNew(btBoxShape, btBoxShape(btVector3(shape->getDim0(), shape->getDim1(), shape->getDim2()))); break; case WS_SHAPE_CYLINDER: boundsShape = wsNew(btCylinderShape, btCylinderShape(btVector3(shape->getDim0(), shape->getDim1()/2.0f, shape->getDim0()))); break; case WS_SHAPE_SPHERE: boundsShape = wsNew(btSphereShape, btSphereShape(shape->getDim0())); break; } } f32 mass = myModel->getMass(); btVector3 myInertia(0.0f, 0.0f, 0.0f); boundsShape->calculateLocalInertia(mass, myInertia); btRigidBody::btRigidBodyConstructionInfo animRigidBodyCI(mass, myModel->getTransformp(), boundsShape, myInertia); btRigidBody* animRigidBody = wsNew(btRigidBody, btRigidBody(animRigidBodyCI)); if (myModel->getProperties() & WS_MODEL_LOCK_HORIZ_ROTATIONS) { animRigidBody->setAngularFactor(btVector3(0.0f, 0.0f, 0.0f)); } rigidBodies->insert(boundsHash, animRigidBody); #endif }// End addAnimation method
void PhysicsSphereShape::create( float radius ) { m_shape = btSphereShape( radius * 0.5f ); }