|
@@ -46,6 +46,9 @@
|
|
#include "gfx/primBuilder.h"
|
|
#include "gfx/primBuilder.h"
|
|
#include "gfx/gfxDrawUtil.h"
|
|
#include "gfx/gfxDrawUtil.h"
|
|
#include "materials/materialDefinition.h"
|
|
#include "materials/materialDefinition.h"
|
|
|
|
+#include "T3D/physics/physicsPlugin.h"
|
|
|
|
+#include "T3D/physics/physicsBody.h"
|
|
|
|
+#include "T3D/physics/physicsCollision.h"
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
namespace {
|
|
@@ -203,7 +206,8 @@ VehicleData::VehicleData()
|
|
dMemset(waterSound, 0, sizeof(waterSound));
|
|
dMemset(waterSound, 0, sizeof(waterSound));
|
|
|
|
|
|
collDamageThresholdVel = 20;
|
|
collDamageThresholdVel = 20;
|
|
- collDamageMultiplier = 0.05f;
|
|
|
|
|
|
+ collDamageMultiplier = 0.05f;
|
|
|
|
+ enablePhysicsRep = true;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -315,6 +319,7 @@ void VehicleData::packData(BitStream* stream)
|
|
stream->write(softSplashSoundVel);
|
|
stream->write(softSplashSoundVel);
|
|
stream->write(medSplashSoundVel);
|
|
stream->write(medSplashSoundVel);
|
|
stream->write(hardSplashSoundVel);
|
|
stream->write(hardSplashSoundVel);
|
|
|
|
+ stream->write(enablePhysicsRep);
|
|
|
|
|
|
// write the water sound profiles
|
|
// write the water sound profiles
|
|
for(i = 0; i < MaxSounds; i++)
|
|
for(i = 0; i < MaxSounds; i++)
|
|
@@ -411,6 +416,7 @@ void VehicleData::unpackData(BitStream* stream)
|
|
stream->read(&softSplashSoundVel);
|
|
stream->read(&softSplashSoundVel);
|
|
stream->read(&medSplashSoundVel);
|
|
stream->read(&medSplashSoundVel);
|
|
stream->read(&hardSplashSoundVel);
|
|
stream->read(&hardSplashSoundVel);
|
|
|
|
+ stream->read(&enablePhysicsRep);
|
|
|
|
|
|
// write the water sound profiles
|
|
// write the water sound profiles
|
|
for(i = 0; i < MaxSounds; i++)
|
|
for(i = 0; i < MaxSounds; i++)
|
|
@@ -465,6 +471,11 @@ void VehicleData::unpackData(BitStream* stream)
|
|
|
|
|
|
void VehicleData::initPersistFields()
|
|
void VehicleData::initPersistFields()
|
|
{
|
|
{
|
|
|
|
+ addGroup("Physics");
|
|
|
|
+ addField("enablePhysicsRep", TypeBool, Offset(enablePhysicsRep, VehicleData),
|
|
|
|
+ "@brief Creates a representation of the object in the physics plugin.\n");
|
|
|
|
+ endGroup("Physics");
|
|
|
|
+
|
|
addField( "jetForce", TypeF32, Offset(jetForce, VehicleData),
|
|
addField( "jetForce", TypeF32, Offset(jetForce, VehicleData),
|
|
"@brief Additional force applied to the vehicle when it is jetting.\n\n"
|
|
"@brief Additional force applied to the vehicle when it is jetting.\n\n"
|
|
"For WheeledVehicles, the force is applied in the forward direction. For "
|
|
"For WheeledVehicles, the force is applied in the forward direction. For "
|
|
@@ -682,6 +693,8 @@ Vehicle::Vehicle()
|
|
mWorkingQueryBox.minExtents.set(-1e9f, -1e9f, -1e9f);
|
|
mWorkingQueryBox.minExtents.set(-1e9f, -1e9f, -1e9f);
|
|
mWorkingQueryBox.maxExtents.set(-1e9f, -1e9f, -1e9f);
|
|
mWorkingQueryBox.maxExtents.set(-1e9f, -1e9f, -1e9f);
|
|
mWorkingQueryBoxCountDown = sWorkingQueryBoxStaleThreshold;
|
|
mWorkingQueryBoxCountDown = sWorkingQueryBoxStaleThreshold;
|
|
|
|
+
|
|
|
|
+ mPhysicsRep = NULL;
|
|
}
|
|
}
|
|
|
|
|
|
U32 Vehicle::getCollisionMask()
|
|
U32 Vehicle::getCollisionMask()
|
|
@@ -695,6 +708,25 @@ Point3F Vehicle::getVelocity() const
|
|
return mRigid.linVelocity;
|
|
return mRigid.linVelocity;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void Vehicle::_createPhysics()
|
|
|
|
+{
|
|
|
|
+ SAFE_DELETE(mPhysicsRep);
|
|
|
|
+
|
|
|
|
+ if (!PHYSICSMGR || !mDataBlock->enablePhysicsRep)
|
|
|
|
+ return;
|
|
|
|
+
|
|
|
|
+ TSShape *shape = mShapeInstance->getShape();
|
|
|
|
+ PhysicsCollision *colShape = NULL;
|
|
|
|
+ colShape = shape->buildColShape(false, getScale());
|
|
|
|
+
|
|
|
|
+ if (colShape)
|
|
|
|
+ {
|
|
|
|
+ PhysicsWorld *world = PHYSICSMGR->getWorld(isServerObject() ? "server" : "client");
|
|
|
|
+ mPhysicsRep = PHYSICSMGR->createBody();
|
|
|
|
+ mPhysicsRep->init(colShape, 0, PhysicsBody::BF_KINEMATIC, this, world);
|
|
|
|
+ mPhysicsRep->setTransform(getTransform());
|
|
|
|
+ }
|
|
|
|
+}
|
|
//----------------------------------------------------------------------------
|
|
//----------------------------------------------------------------------------
|
|
|
|
|
|
bool Vehicle::onAdd()
|
|
bool Vehicle::onAdd()
|
|
@@ -776,11 +808,15 @@ bool Vehicle::onAdd()
|
|
mConvex.box.maxExtents.convolve(mObjScale);
|
|
mConvex.box.maxExtents.convolve(mObjScale);
|
|
mConvex.findNodeTransform();
|
|
mConvex.findNodeTransform();
|
|
|
|
|
|
|
|
+ _createPhysics();
|
|
|
|
+
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
void Vehicle::onRemove()
|
|
void Vehicle::onRemove()
|
|
{
|
|
{
|
|
|
|
+ SAFE_DELETE(mPhysicsRep);
|
|
|
|
+
|
|
U32 i=0;
|
|
U32 i=0;
|
|
for( i=0; i<VehicleData::VC_NUM_DUST_EMITTERS; i++ )
|
|
for( i=0; i<VehicleData::VC_NUM_DUST_EMITTERS; i++ )
|
|
{
|
|
{
|
|
@@ -880,6 +916,11 @@ void Vehicle::processTick(const Move* move)
|
|
setPosition(mRigid.linPosition, mRigid.angPosition);
|
|
setPosition(mRigid.linPosition, mRigid.angPosition);
|
|
setMaskBits(PositionMask);
|
|
setMaskBits(PositionMask);
|
|
updateContainer();
|
|
updateContainer();
|
|
|
|
+
|
|
|
|
+ //TODO: Only update when position has actually changed
|
|
|
|
+ //no need to check if mDataBlock->enablePhysicsRep is false as mPhysicsRep will be NULL if it is
|
|
|
|
+ if (mPhysicsRep)
|
|
|
|
+ mPhysicsRep->moveKinematicTo(getTransform());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|