Merge branch 'Physics' of https://github.com/dean11/Danbias into GameServer

This commit is contained in:
dean11 2014-02-27 13:51:05 +01:00
commit 4920bfe9f3
3 changed files with 46 additions and 34 deletions

View File

@ -93,6 +93,8 @@ ICustomBody* API_Impl::AddCollisionSphere(float radius, ::Oyster::Math::Float4 r
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
dynamic_cast<btSphereShape*>(collisionShape)->setMargin(0.2f);
state.centerPos = position; state.centerPos = position;
state.reach = Float3(radius, radius, radius); state.reach = Float3(radius, radius, radius);
state.dynamicFrictionCoeff = dynamicFriction; state.dynamicFrictionCoeff = dynamicFriction;
@ -132,6 +134,8 @@ ICustomBody* API_Impl::AddCollisionBox(Float3 halfSize, ::Oyster::Math::Float4 r
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
dynamic_cast<btBoxShape*>(collisionShape)->setMargin(0.2f);
state.centerPos = position; state.centerPos = position;
state.reach = halfSize; state.reach = halfSize;
state.dynamicFrictionCoeff = dynamicFriction; state.dynamicFrictionCoeff = dynamicFriction;
@ -171,6 +175,8 @@ ICustomBody* API_Impl::AddCollisionCylinder(::Oyster::Math::Float3 halfSize, ::O
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
dynamic_cast<btCylinderShape*>(collisionShape)->setMargin(0.2f);
state.centerPos = position; state.centerPos = position;
state.reach = halfSize; state.reach = halfSize;
state.dynamicFrictionCoeff = dynamicFriction; state.dynamicFrictionCoeff = dynamicFriction;
@ -212,6 +218,8 @@ ICustomBody* API_Impl::AddCharacter(::Oyster::Math::Float height, ::Oyster::Math
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
dynamic_cast<btCapsuleShape*>(collisionShape)->setMargin(0.2f);
state.centerPos = position; state.centerPos = position;
state.reach = Float3(radius, height, radius); state.reach = Float3(radius, height, radius);
state.dynamicFrictionCoeff = dynamicFriction; state.dynamicFrictionCoeff = dynamicFriction;
@ -245,9 +253,11 @@ ICustomBody* API_Impl::AddTriangleMesh(const std::wstring fileName, ::Oyster::Ma
btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w),btVector3(position.x, position.y, position.z))); btDefaultMotionState* motionState = new btDefaultMotionState(btTransform(btQuaternion(rotation.x, rotation.y, rotation.z, rotation.w),btVector3(position.x, position.y, position.z)));
body->SetMotionState(motionState); body->SetMotionState(motionState);
// Add rigid body // Add rigid body
btVector3 fallInertia(0, 0, 0); btVector3 fallInertia(0, 0, 0);
//collisionShape->calculateLocalInertia(mass, fallInertia); //collisionShape->calcu%lateLocalInertia(mass, fallInertia);
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(0, motionState, collisionShape, fallInertia); btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(0, motionState, collisionShape, fallInertia);
btRigidBody* rigidBody = new btRigidBody(rigidBodyCI); btRigidBody* rigidBody = new btRigidBody(rigidBodyCI);
rigidBody->setFriction(staticFriction); rigidBody->setFriction(staticFriction);
@ -259,6 +269,8 @@ ICustomBody* API_Impl::AddTriangleMesh(const std::wstring fileName, ::Oyster::Ma
this->dynamicsWorld->addRigidBody(rigidBody); this->dynamicsWorld->addRigidBody(rigidBody);
this->customBodies.push_back(body); this->customBodies.push_back(body);
dynamic_cast<btBvhTriangleMeshShape*>(collisionShape)->setMargin(0.5);
state.centerPos = position; state.centerPos = position;
state.reach = Float3(0, 0, 0); state.reach = Float3(0, 0, 0);
state.dynamicFrictionCoeff = dynamicFriction; state.dynamicFrictionCoeff = dynamicFriction;
@ -284,10 +296,7 @@ void API_Impl::UpdateWorld()
this->customBodies[i]->SetGravity(-(this->customBodies[i]->GetState().centerPos - this->gravityPoint).GetNormalized()*this->gravity); this->customBodies[i]->SetGravity(-(this->customBodies[i]->GetState().centerPos - this->gravityPoint).GetNormalized()*this->gravity);
simpleBody->PreStep(this->dynamicsWorld); simpleBody->PreStep(this->dynamicsWorld);
if(simpleBody->GetRigidBody()->getActivationState() == ACTIVE_TAG)
{
this->customBodies[i]->CallSubscription_Move();
}
simpleBody->SetPreviousVelocity(simpleBody->GetLinearVelocity()); simpleBody->SetPreviousVelocity(simpleBody->GetLinearVelocity());
} }
@ -301,7 +310,12 @@ void API_Impl::UpdateWorld()
btTransform trans; btTransform trans;
trans = simpleBody->GetRigidBody()->getWorldTransform(); trans = simpleBody->GetRigidBody()->getWorldTransform();
this->customBodies[i]->SetPosition(Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z())); this->customBodies[i]->SetPosition(Float3(trans.getOrigin().x(), trans.getOrigin().y(), trans.getOrigin().z()));
this->customBodies[i]->SetRotation(Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w())); this->customBodies[i]->SetRotation(Quaternion(Float3(trans.getRotation().x(), trans.getRotation().y(), trans.getRotation().z()), trans.getRotation().w()));
if(simpleBody->GetRigidBody()->getActivationState() == ACTIVE_TAG)
{
this->customBodies[i]->CallSubscription_Move();
}
} }
int numManifolds = this->dynamicsWorld->getDispatcher()->getNumManifolds(); int numManifolds = this->dynamicsWorld->getDispatcher()->getNumManifolds();
@ -362,11 +376,6 @@ void API_Impl::ReleaseFromLimbo( const ICustomBody* objRef )
void API_Impl::ApplyEffect(Oyster::Collision3D::ICollideable* collideable, void* args, EventAction_ApplyEffect effect) void API_Impl::ApplyEffect(Oyster::Collision3D::ICollideable* collideable, void* args, EventAction_ApplyEffect effect)
{ {
btRigidBody* body;
btCollisionShape* shape;
btMotionState* state;
btRigidBody::btRigidBodyConstructionInfo rigidBodyCI(0, NULL, NULL);
Sphere* sphere; Sphere* sphere;
Box* box; Box* box;
Cone* cone; Cone* cone;
@ -374,59 +383,61 @@ void API_Impl::ApplyEffect(Oyster::Collision3D::ICollideable* collideable, void*
switch(collideable->type) switch(collideable->type)
{ {
case ICollideable::Type::Type_sphere: case ICollideable::Type::Type_sphere:
{
sphere = dynamic_cast<Sphere*>(collideable); sphere = dynamic_cast<Sphere*>(collideable);
// Add collision shape // Add collision shape
shape = new btSphereShape(sphere->radius); btSphereShape btSphere(sphere->radius);
// Add motion state // Add motion state
state = new btDefaultMotionState(btTransform(btQuaternion(0.0f, 0.0f, 0.0f, 1.0f),btVector3(sphere->center.x, sphere->center.y, sphere->center.z))); btDefaultMotionState state = btDefaultMotionState(btTransform(btQuaternion(0.0f, 0.0f, 0.0f, 1.0f),btVector3(sphere->center.x, sphere->center.y, sphere->center.z)));
// Add rigid body // Add rigid body
rigidBodyCI = btRigidBody::btRigidBodyConstructionInfo(0, state, shape); btRigidBody::btRigidBodyConstructionInfo rigidBodyCI = btRigidBody::btRigidBodyConstructionInfo(0, &state, &btSphere);
body = new btRigidBody(rigidBodyCI); btRigidBody body = btRigidBody(rigidBodyCI);
ContactSensorCallback callback(body, effect, args);
this->dynamicsWorld->contactTest(&body, callback);
}
break; break;
case ICollideable::Type::Type_box: case ICollideable::Type::Type_box:
{
box = dynamic_cast<Box*>(collideable); box = dynamic_cast<Box*>(collideable);
// Add collision shape // Add collision shape
shape = new btBoxShape(btVector3(box->boundingOffset.x, box->boundingOffset.y, box->boundingOffset.z)); btBoxShape btBox = btBoxShape(btVector3(box->boundingOffset.x, box->boundingOffset.y, box->boundingOffset.z));
// Add motion state // Add motion state
state = new btDefaultMotionState(btTransform(btQuaternion(0.0f, 0.0f, 0.0f, 1.0f),btVector3(box->center.x, box->center.y, box->center.z))); btDefaultMotionState state = btDefaultMotionState(btTransform(btQuaternion(0.0f, 0.0f, 0.0f, 1.0f),btVector3(box->center.x, box->center.y, box->center.z)));
// Add rigid body // Add rigid body
rigidBodyCI = btRigidBody::btRigidBodyConstructionInfo(0, state, shape); btRigidBody::btRigidBodyConstructionInfo rigidBodyCI = btRigidBody::btRigidBodyConstructionInfo(0, &state, &btBox);
body = new btRigidBody(rigidBodyCI); btRigidBody body = btRigidBody(rigidBodyCI);
ContactSensorCallback callback(body, effect, args);
this->dynamicsWorld->contactTest(&body, callback);
}
break; break;
case ICollideable::Type::Type_cone: case ICollideable::Type::Type_cone:
{
cone = dynamic_cast<Cone*>(collideable); cone = dynamic_cast<Cone*>(collideable);
// Add collision shape // Add collision shape
shape = new btConeShapeZ(cone->radius, cone->length); btConeShapeZ coneShape = btConeShapeZ(cone->radius, cone->length);
// Add motion state // Add motion state
state = new btDefaultMotionState(btTransform(btQuaternion(cone->quaternion.x, cone->quaternion.y, cone->quaternion.z, cone->quaternion.w),btVector3(cone->center.x, cone->center.y, cone->center.z))); btDefaultMotionState state = btDefaultMotionState(btTransform(btQuaternion(cone->quaternion.x, cone->quaternion.y, cone->quaternion.z, cone->quaternion.w)*btQuaternion(0, 1, 0, 0),btVector3(cone->center.x, cone->center.y, cone->center.z)));
// Add rigid body // Add rigid body
rigidBodyCI = btRigidBody::btRigidBodyConstructionInfo (0, state, shape); btRigidBody::btRigidBodyConstructionInfo rigidBodyCI = btRigidBody::btRigidBodyConstructionInfo (0, &state, &coneShape);
body = new btRigidBody(rigidBodyCI); btRigidBody body = btRigidBody(rigidBodyCI);
ContactSensorCallback callback(body, effect, args);
this->dynamicsWorld->contactTest(&body, callback);
}
break; break;
default: default:
return; return;
} }
ContactSensorCallback callback(*body, effect, args);
this->dynamicsWorld->contactTest(body, callback);
delete state;
state = NULL;
delete shape;
shape = NULL;
delete body;
body = NULL;
} }
namespace Oyster namespace Oyster

View File

@ -73,6 +73,7 @@ void SimpleRigidBody::SetState( const SimpleRigidBody::State &state )
void SimpleRigidBody::ApplyImpulse(Float3 impulse) void SimpleRigidBody::ApplyImpulse(Float3 impulse)
{ {
this->rigidBody->applyCentralImpulse(btVector3(impulse.x, impulse.y, impulse.z)); this->rigidBody->applyCentralImpulse(btVector3(impulse.x, impulse.y, impulse.z));
this->rigidBody->setActivationState(ACTIVE_TAG);
} }
void SimpleRigidBody::SetCollisionShape(btCollisionShape* shape) void SimpleRigidBody::SetCollisionShape(btCollisionShape* shape)