mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-16 09:04:38 +00:00
rev 1 refactor for fitting rigidshape into the vehicle hierarchy.
cleaned a few, but by no means all redundancies.
DO NOTE THE FOLLOWING:
ShapeBase::processTick(move);
ShapeBase::interpolateTick(dt);
to avoid side effects for now. properly those would be retooled down the line to be more inheritance-friendly.
This commit is contained in:
parent
45a19453ee
commit
d6b6f36b0a
4 changed files with 39 additions and 81 deletions
|
|
@ -1210,44 +1210,39 @@ on standard collision resolution formulas.
|
||||||
bool RigidShape::resolveCollision(Rigid& ns,CollisionList& cList)
|
bool RigidShape::resolveCollision(Rigid& ns,CollisionList& cList)
|
||||||
{
|
{
|
||||||
// Apply impulses to resolve collision
|
// Apply impulses to resolve collision
|
||||||
bool colliding, collided = false;
|
bool collided = false;
|
||||||
|
for (S32 i = 0; i < cList.getCount(); i++)
|
||||||
do
|
|
||||||
{
|
{
|
||||||
colliding = false;
|
Collision& c = cList[i];
|
||||||
for (S32 i = 0; i < cList.getCount(); i++)
|
if (c.distance < mDataBlock->collisionTol)
|
||||||
{
|
{
|
||||||
Collision& c = cList[i];
|
// Velocity into surface
|
||||||
if (c.distance < mDataBlock->collisionTol)
|
Point3F v, r;
|
||||||
|
ns.getOriginVector(c.point, &r);
|
||||||
|
ns.getVelocity(r, &v);
|
||||||
|
F32 vn = mDot(v, c.normal);
|
||||||
|
|
||||||
|
// Only interested in velocities greater than sContactTol,
|
||||||
|
// velocities less than that will be dealt with as contacts
|
||||||
|
// "constraints".
|
||||||
|
if (vn < -mDataBlock->contactTol)
|
||||||
{
|
{
|
||||||
// Velocity into surface
|
|
||||||
Point3F v,r;
|
|
||||||
ns.getOriginVector(c.point,&r);
|
|
||||||
ns.getVelocity(r,&v);
|
|
||||||
F32 vn = mDot(v,c.normal);
|
|
||||||
|
|
||||||
// Only interested in velocities greater than sContactTol,
|
// Apply impulses to the rigid body to keep it from
|
||||||
// velocities less than that will be dealt with as contacts
|
// penetrating the surface.
|
||||||
// "constraints".
|
ns.resolveCollision(cList[i].point,
|
||||||
if (vn < -mDataBlock->contactTol)
|
cList[i].normal);
|
||||||
|
collided = true;
|
||||||
|
|
||||||
|
// Keep track of objects we collide with
|
||||||
|
if (!isGhost() && c.object->getTypeMask() & ShapeBaseObjectType)
|
||||||
{
|
{
|
||||||
|
ShapeBase* col = static_cast<ShapeBase*>(c.object);
|
||||||
// Apply impulses to the rigid body to keep it from
|
queueCollision(col, v - col->getVelocity());
|
||||||
// penetrating the surface.
|
|
||||||
ns.resolveCollision(cList[i].point,
|
|
||||||
cList[i].normal);
|
|
||||||
colliding = collided = true;
|
|
||||||
|
|
||||||
// Keep track of objects we collide with
|
|
||||||
if (!isGhost() && c.object->getTypeMask() & ShapeBaseObjectType)
|
|
||||||
{
|
|
||||||
ShapeBase* col = static_cast<ShapeBase*>(c.object);
|
|
||||||
queueCollision(col,v - col->getVelocity());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (colliding);
|
}
|
||||||
|
|
||||||
return collided;
|
return collided;
|
||||||
}
|
}
|
||||||
|
|
@ -1264,7 +1259,7 @@ bool RigidShape::resolveContacts(Rigid& ns,CollisionList& cList,F32 dt)
|
||||||
Point3F t,p(0,0,0),l(0,0,0);
|
Point3F t,p(0,0,0),l(0,0,0);
|
||||||
for (S32 i = 0; i < cList.getCount(); i++)
|
for (S32 i = 0; i < cList.getCount(); i++)
|
||||||
{
|
{
|
||||||
Collision& c = cList[i];
|
const Collision& c = cList[i];
|
||||||
if (c.distance < mDataBlock->collisionTol)
|
if (c.distance < mDataBlock->collisionTol)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -146,11 +146,6 @@ class RigidShape: public ShapeBase
|
||||||
SimObjectPtr<ParticleEmitter> mDustTrailEmitter;
|
SimObjectPtr<ParticleEmitter> mDustTrailEmitter;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum CollisionFaceFlags
|
|
||||||
{
|
|
||||||
BodyCollision = BIT(0),
|
|
||||||
WheelCollision = BIT(1),
|
|
||||||
};
|
|
||||||
enum MaskBits {
|
enum MaskBits {
|
||||||
PositionMask = Parent::NextFreeMask << 0,
|
PositionMask = Parent::NextFreeMask << 0,
|
||||||
EnergyMask = Parent::NextFreeMask << 1,
|
EnergyMask = Parent::NextFreeMask << 1,
|
||||||
|
|
|
||||||
|
|
@ -782,14 +782,6 @@ bool Vehicle::onAdd()
|
||||||
void Vehicle::onRemove()
|
void Vehicle::onRemove()
|
||||||
{
|
{
|
||||||
U32 i=0;
|
U32 i=0;
|
||||||
for( i=0; i<VehicleData::VC_NUM_DUST_EMITTERS; i++ )
|
|
||||||
{
|
|
||||||
if( mDustEmitterList[i] )
|
|
||||||
{
|
|
||||||
mDustEmitterList[i]->deleteWhenEmpty();
|
|
||||||
mDustEmitterList[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for( i=0; i<VehicleData::VC_NUM_DAMAGE_EMITTERS; i++ )
|
for( i=0; i<VehicleData::VC_NUM_DAMAGE_EMITTERS; i++ )
|
||||||
{
|
{
|
||||||
|
|
@ -800,15 +792,6 @@ void Vehicle::onRemove()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for( i=0; i<VehicleData::VC_NUM_SPLASH_EMITTERS; i++ )
|
|
||||||
{
|
|
||||||
if( mSplashEmitterList[i] )
|
|
||||||
{
|
|
||||||
mSplashEmitterList[i]->deleteWhenEmpty();
|
|
||||||
mSplashEmitterList[i] = NULL;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
mWorkingQueryBox.minExtents.set(-1e9f, -1e9f, -1e9f);
|
mWorkingQueryBox.minExtents.set(-1e9f, -1e9f, -1e9f);
|
||||||
mWorkingQueryBox.maxExtents.set(-1e9f, -1e9f, -1e9f);
|
mWorkingQueryBox.maxExtents.set(-1e9f, -1e9f, -1e9f);
|
||||||
|
|
||||||
|
|
@ -822,7 +805,7 @@ void Vehicle::processTick(const Move* move)
|
||||||
{
|
{
|
||||||
PROFILE_SCOPE( Vehicle_ProcessTick );
|
PROFILE_SCOPE( Vehicle_ProcessTick );
|
||||||
|
|
||||||
Parent::processTick(move);
|
ShapeBase::processTick(move);
|
||||||
|
|
||||||
// Warp to catch up to server
|
// Warp to catch up to server
|
||||||
if (mDelta.warpCount < mDelta.warpTicks)
|
if (mDelta.warpCount < mDelta.warpTicks)
|
||||||
|
|
@ -867,7 +850,9 @@ void Vehicle::processTick(const Move* move)
|
||||||
// Update the physics based on the integration rate
|
// Update the physics based on the integration rate
|
||||||
S32 count = mDataBlock->integration;
|
S32 count = mDataBlock->integration;
|
||||||
--mWorkingQueryBoxCountDown;
|
--mWorkingQueryBoxCountDown;
|
||||||
updateWorkingCollisionSet(getCollisionMask());
|
|
||||||
|
if (!mDisableMove)
|
||||||
|
updateWorkingCollisionSet(getCollisionMask());
|
||||||
for (U32 i = 0; i < count; i++)
|
for (U32 i = 0; i < count; i++)
|
||||||
updatePos(TickSec / count);
|
updatePos(TickSec / count);
|
||||||
|
|
||||||
|
|
@ -887,7 +872,7 @@ void Vehicle::interpolateTick(F32 dt)
|
||||||
{
|
{
|
||||||
PROFILE_SCOPE( Vehicle_InterpolateTick );
|
PROFILE_SCOPE( Vehicle_InterpolateTick );
|
||||||
|
|
||||||
Parent::interpolateTick(dt);
|
ShapeBase::interpolateTick(dt);
|
||||||
|
|
||||||
if(dt == 0.0f)
|
if(dt == 0.0f)
|
||||||
setRenderPosition(mDelta.pos, mDelta.rot[1]);
|
setRenderPosition(mDelta.pos, mDelta.rot[1]);
|
||||||
|
|
@ -909,13 +894,6 @@ void Vehicle::advanceTime(F32 dt)
|
||||||
|
|
||||||
updateLiftoffDust( dt );
|
updateLiftoffDust( dt );
|
||||||
updateDamageSmoke( dt );
|
updateDamageSmoke( dt );
|
||||||
updateFroth(dt);
|
|
||||||
|
|
||||||
// Update 3rd person camera offset. Camera update is done
|
|
||||||
// here as it's a client side only animation.
|
|
||||||
mCameraOffset -=
|
|
||||||
(mCameraOffset * mDataBlock->cameraDecay +
|
|
||||||
mRigid.linVelocity * mDataBlock->cameraLag) * dt;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -1199,7 +1177,8 @@ void Vehicle::updatePos(F32 dt)
|
||||||
|
|
||||||
// Update collision information based on our current pos.
|
// Update collision information based on our current pos.
|
||||||
bool collided = false;
|
bool collided = false;
|
||||||
if (!mRigid.atRest) {
|
if (!mRigid.atRest && !mDisableMove)
|
||||||
|
{
|
||||||
collided = updateCollision(dt);
|
collided = updateCollision(dt);
|
||||||
|
|
||||||
// Now that all the forces have been processed, lets
|
// Now that all the forces have been processed, lets
|
||||||
|
|
@ -1220,7 +1199,7 @@ void Vehicle::updatePos(F32 dt)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Integrate forward
|
// Integrate forward
|
||||||
if (!mRigid.atRest)
|
if (!mRigid.atRest && !mDisableMove)
|
||||||
mRigid.integrate(dt);
|
mRigid.integrate(dt);
|
||||||
|
|
||||||
// Deal with client and server scripting, sounds, etc.
|
// Deal with client and server scripting, sounds, etc.
|
||||||
|
|
|
||||||
|
|
@ -24,13 +24,7 @@
|
||||||
#define _VEHICLE_H_
|
#define _VEHICLE_H_
|
||||||
|
|
||||||
#ifndef _SHAPEBASE_H_
|
#ifndef _SHAPEBASE_H_
|
||||||
#include "T3D/shapeBase.h"
|
#include "T3D/rigidShape.h"
|
||||||
#endif
|
|
||||||
#ifndef _RIGID_H_
|
|
||||||
#include "T3D/rigid.h"
|
|
||||||
#endif
|
|
||||||
#ifndef _BOXCONVEX_H_
|
|
||||||
#include "collision/boxConvex.h"
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
class ParticleEmitter;
|
class ParticleEmitter;
|
||||||
|
|
@ -41,9 +35,9 @@ class Vehicle;
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
struct VehicleData: public ShapeBaseData
|
struct VehicleData : public RigidShapeData
|
||||||
{
|
{
|
||||||
typedef ShapeBaseData Parent;
|
typedef RigidShapeData Parent;
|
||||||
|
|
||||||
struct Body {
|
struct Body {
|
||||||
enum Sounds {
|
enum Sounds {
|
||||||
|
|
@ -143,20 +137,15 @@ struct VehicleData: public ShapeBaseData
|
||||||
|
|
||||||
//----------------------------------------------------------------------------
|
//----------------------------------------------------------------------------
|
||||||
|
|
||||||
class Vehicle: public ShapeBase
|
class Vehicle : public RigidShape
|
||||||
{
|
{
|
||||||
typedef ShapeBase Parent;
|
typedef RigidShape Parent;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
enum CollisionFaceFlags {
|
enum CollisionFaceFlags {
|
||||||
BodyCollision = 0x1,
|
BodyCollision = 0x1,
|
||||||
WheelCollision = 0x2,
|
WheelCollision = 0x2,
|
||||||
};
|
};
|
||||||
enum MaskBits {
|
|
||||||
PositionMask = Parent::NextFreeMask << 0,
|
|
||||||
EnergyMask = Parent::NextFreeMask << 1,
|
|
||||||
NextFreeMask = Parent::NextFreeMask << 2
|
|
||||||
};
|
|
||||||
|
|
||||||
struct StateDelta {
|
struct StateDelta {
|
||||||
Move move; ///< Last move from server
|
Move move; ///< Last move from server
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue