mirror of
https://github.com/alliedmodders/hl2sdk.git
synced 2025-09-19 03:56:10 +08:00
First version of the SOurce SDK 2013
This commit is contained in:
20
public/vphysics/collision_set.h
Normal file
20
public/vphysics/collision_set.h
Normal file
@ -0,0 +1,20 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
// A set of collision rules
|
||||
// NOTE: Defaults to all indices disabled
|
||||
class IPhysicsCollisionSet
|
||||
{
|
||||
public:
|
||||
~IPhysicsCollisionSet() {}
|
||||
|
||||
virtual void EnableCollisions( int index0, int index1 ) = 0;
|
||||
virtual void DisableCollisions( int index0, int index1 ) = 0;
|
||||
|
||||
virtual bool ShouldCollide( int index0, int index1 ) = 0;
|
||||
};
|
345
public/vphysics/constraints.h
Normal file
345
public/vphysics/constraints.h
Normal file
@ -0,0 +1,345 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef CONSTRAINTS_H
|
||||
#define CONSTRAINTS_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "vphysics_interface.h"
|
||||
#include "mathlib/mathlib.h"
|
||||
|
||||
// constraint groups
|
||||
struct constraint_groupparams_t
|
||||
{
|
||||
int additionalIterations; // additional solver iterations make the constraint system more stable
|
||||
int minErrorTicks; // minimum number of ticks with an error before it's reported
|
||||
float errorTolerance; // error tolerance in HL units
|
||||
|
||||
inline void Defaults()
|
||||
{
|
||||
additionalIterations = 0;
|
||||
minErrorTicks = 15;
|
||||
errorTolerance = 3.0f;
|
||||
}
|
||||
};
|
||||
|
||||
// Breakable constraints;
|
||||
//
|
||||
// forceLimit - kg * in / s limit (N * conversion(in/m))
|
||||
// torqueLimit - kg * in^2 / s (Nm * conversion(in^2/m^2))
|
||||
|
||||
//
|
||||
// strength 0 - 1
|
||||
struct constraint_breakableparams_t
|
||||
{
|
||||
float strength; // strength of the constraint 0.0 - 1.0
|
||||
float forceLimit; // constraint force limit to break (0 means never break)
|
||||
float torqueLimit; // constraint torque limit to break (0 means never break)
|
||||
float bodyMassScale[2]; // scale applied to mass of reference/attached object before solving constriant
|
||||
bool isActive;
|
||||
|
||||
inline void Defaults()
|
||||
{
|
||||
forceLimit = 0.0f;
|
||||
torqueLimit = 0.0f;
|
||||
strength = 1.0f;
|
||||
bodyMassScale[0] = 1.0f;
|
||||
bodyMassScale[1] = 1.0f;
|
||||
isActive = true;
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: constraint limit on a single rotation axis
|
||||
//-----------------------------------------------------------------------------
|
||||
struct constraint_axislimit_t
|
||||
{
|
||||
float minRotation;
|
||||
float maxRotation;
|
||||
float angularVelocity; // desired angular velocity around hinge
|
||||
float torque; // torque to achieve angular velocity (use 0, torque for "friction")
|
||||
|
||||
inline void SetAxisFriction( float rmin, float rmax, float friction )
|
||||
{
|
||||
minRotation = rmin;
|
||||
maxRotation = rmax;
|
||||
angularVelocity = 0;
|
||||
torque = friction;
|
||||
}
|
||||
inline void Defaults()
|
||||
{
|
||||
SetAxisFriction(0,0,0);
|
||||
}
|
||||
};
|
||||
|
||||
// Builds a transform which maps points in the input object's local space
|
||||
// to the output object's local space
|
||||
inline void BuildObjectRelativeXform( IPhysicsObject *pOutputSpace, IPhysicsObject *pInputSpace, matrix3x4_t &xformInToOut )
|
||||
{
|
||||
matrix3x4_t outInv, tmp, input;
|
||||
pOutputSpace->GetPositionMatrix( &tmp );
|
||||
MatrixInvert( tmp, outInv );
|
||||
pInputSpace->GetPositionMatrix( &input );
|
||||
ConcatTransforms( outInv, input, xformInToOut );
|
||||
}
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: special limited ballsocket constraint for ragdolls.
|
||||
// Has axis limits for all 3 axes.
|
||||
//-----------------------------------------------------------------------------
|
||||
struct constraint_ragdollparams_t
|
||||
{
|
||||
constraint_breakableparams_t constraint;
|
||||
matrix3x4_t constraintToReference;// xform constraint space to refobject space
|
||||
matrix3x4_t constraintToAttached; // xform constraint space to attached object space
|
||||
int parentIndex; // NOTE: only used for parsing. NEED NOT BE SET for create
|
||||
int childIndex; // NOTE: only used for parsing. NEED NOT BE SET for create
|
||||
|
||||
constraint_axislimit_t axes[3];
|
||||
bool onlyAngularLimits; // only angular limits (not translation as well?)
|
||||
bool isActive;
|
||||
bool useClockwiseRotations; // HACKHACK: Did this wrong in version one. Fix in the future.
|
||||
|
||||
inline void Defaults()
|
||||
{
|
||||
constraint.Defaults();
|
||||
isActive = true;
|
||||
SetIdentityMatrix( constraintToReference );
|
||||
SetIdentityMatrix( constraintToAttached );
|
||||
parentIndex = -1;
|
||||
childIndex = -1;
|
||||
axes[0].Defaults();
|
||||
axes[1].Defaults();
|
||||
axes[2].Defaults();
|
||||
onlyAngularLimits = false;
|
||||
useClockwiseRotations = false;
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Used to init a hinge restricting the relative position and orientation
|
||||
// of two objects to rotation around a single axis
|
||||
//-----------------------------------------------------------------------------
|
||||
struct constraint_hingeparams_t
|
||||
{
|
||||
Vector worldPosition; // position in world space on the hinge axis
|
||||
Vector worldAxisDirection; // unit direction vector of the hinge axis in world space
|
||||
constraint_axislimit_t hingeAxis;
|
||||
constraint_breakableparams_t constraint;
|
||||
|
||||
inline void Defaults()
|
||||
{
|
||||
worldPosition.Init();
|
||||
worldAxisDirection.Init();
|
||||
hingeAxis.Defaults();
|
||||
constraint.Defaults();
|
||||
}
|
||||
};
|
||||
|
||||
struct constraint_limitedhingeparams_t : public constraint_hingeparams_t
|
||||
{
|
||||
Vector referencePerpAxisDirection; // unit direction vector vector perpendicular to the hinge axis in world space
|
||||
Vector attachedPerpAxisDirection; // unit direction vector vector perpendicular to the hinge axis in world space
|
||||
|
||||
constraint_limitedhingeparams_t() {}
|
||||
constraint_limitedhingeparams_t( const constraint_hingeparams_t &hinge )
|
||||
{
|
||||
static_cast<constraint_hingeparams_t &>(*this) = hinge;
|
||||
referencePerpAxisDirection.Init();
|
||||
attachedPerpAxisDirection.Init();
|
||||
}
|
||||
|
||||
inline void Defaults()
|
||||
{
|
||||
this->constraint_hingeparams_t::Defaults();
|
||||
referencePerpAxisDirection.Init();
|
||||
attachedPerpAxisDirection.Init();
|
||||
}
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Used to init a constraint that fixes the position and orientation
|
||||
// of two objects relative to each other (like glue)
|
||||
//-----------------------------------------------------------------------------
|
||||
struct constraint_fixedparams_t
|
||||
{
|
||||
matrix3x4_t attachedRefXform; // xform attached object space to ref object space
|
||||
constraint_breakableparams_t constraint;
|
||||
|
||||
inline void InitWithCurrentObjectState( IPhysicsObject *pRef, IPhysicsObject *pAttached )
|
||||
{
|
||||
BuildObjectRelativeXform( pRef, pAttached, attachedRefXform );
|
||||
}
|
||||
|
||||
inline void Defaults()
|
||||
{
|
||||
SetIdentityMatrix( attachedRefXform );
|
||||
constraint.Defaults();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Purpose: Same parameters as fixed constraint, but torqueLimit has no effect
|
||||
//-----------------------------------------------------------------------------
|
||||
struct constraint_ballsocketparams_t
|
||||
{
|
||||
Vector constraintPosition[2]; // position of the constraint in each object's space
|
||||
constraint_breakableparams_t constraint;
|
||||
inline void Defaults()
|
||||
{
|
||||
constraint.Defaults();
|
||||
constraintPosition[0].Init();
|
||||
constraintPosition[1].Init();
|
||||
}
|
||||
|
||||
void InitWithCurrentObjectState( IPhysicsObject *pRef, IPhysicsObject *pAttached, const Vector &ballsocketOrigin )
|
||||
{
|
||||
pRef->WorldToLocal( &constraintPosition[0], ballsocketOrigin );
|
||||
pAttached->WorldToLocal( &constraintPosition[1], ballsocketOrigin );
|
||||
}
|
||||
};
|
||||
|
||||
struct constraint_slidingparams_t
|
||||
{
|
||||
matrix3x4_t attachedRefXform; // xform attached object space to ref object space
|
||||
Vector slideAxisRef; // unit direction vector of the slide axis in ref object space
|
||||
constraint_breakableparams_t constraint;
|
||||
// NOTE: if limitMin == limitMax there is NO limit set!
|
||||
float limitMin; // minimum limit coordinate refAxisDirection space
|
||||
float limitMax; // maximum limit coordinate refAxisDirection space
|
||||
float friction; // friction on sliding
|
||||
float velocity; // desired velocity
|
||||
|
||||
inline void Defaults()
|
||||
{
|
||||
SetIdentityMatrix( attachedRefXform );
|
||||
slideAxisRef.Init();
|
||||
limitMin = limitMax = 0;
|
||||
friction = 0;
|
||||
velocity = 0;
|
||||
constraint.Defaults();
|
||||
}
|
||||
|
||||
inline void SetFriction( float inputFriction )
|
||||
{
|
||||
friction = inputFriction;
|
||||
velocity = 0;
|
||||
}
|
||||
|
||||
inline void SetLinearMotor( float inputVelocity, float maxForce )
|
||||
{
|
||||
friction = maxForce;
|
||||
velocity = inputVelocity;
|
||||
}
|
||||
|
||||
inline void InitWithCurrentObjectState( IPhysicsObject *pRef, IPhysicsObject *pAttached, const Vector &slideDirWorldspace )
|
||||
{
|
||||
BuildObjectRelativeXform( pRef, pAttached, attachedRefXform );
|
||||
matrix3x4_t tmp;
|
||||
pRef->GetPositionMatrix( &tmp );
|
||||
VectorIRotate( slideDirWorldspace, tmp, slideAxisRef );
|
||||
}
|
||||
};
|
||||
|
||||
struct constraint_pulleyparams_t
|
||||
{
|
||||
constraint_breakableparams_t constraint;
|
||||
Vector pulleyPosition[2]; // These are the pulley positions for the reference and attached objects in world space
|
||||
Vector objectPosition[2]; // local positions of attachments to the ref,att objects
|
||||
float totalLength; // total rope length (include gearing!)
|
||||
float gearRatio; // gearing affects attached object ALWAYS
|
||||
bool isRigid;
|
||||
|
||||
inline void Defaults()
|
||||
{
|
||||
constraint.Defaults();
|
||||
totalLength = 1.0;
|
||||
gearRatio = 1.0;
|
||||
pulleyPosition[0].Init();
|
||||
pulleyPosition[1].Init();
|
||||
objectPosition[0].Init();
|
||||
objectPosition[1].Init();
|
||||
isRigid = false;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
struct constraint_lengthparams_t
|
||||
{
|
||||
constraint_breakableparams_t constraint;
|
||||
Vector objectPosition[2]; // These are the positions for the reference and attached objects in local space
|
||||
float totalLength; // Length of rope/spring/constraint. Distance to maintain
|
||||
float minLength; // if rigid, objects are not allowed to move closer than totalLength either
|
||||
|
||||
void InitWorldspace( IPhysicsObject *pRef, IPhysicsObject *pAttached, const Vector &refPosition, const Vector &attachedPosition, bool rigid = false )
|
||||
{
|
||||
pRef->WorldToLocal( &objectPosition[0], refPosition );
|
||||
pAttached->WorldToLocal( &objectPosition[1], attachedPosition );
|
||||
totalLength = (refPosition - attachedPosition).Length();
|
||||
minLength = rigid ? totalLength : 0;
|
||||
}
|
||||
|
||||
inline void Defaults()
|
||||
{
|
||||
constraint.Defaults();
|
||||
objectPosition[0].Init();
|
||||
objectPosition[1].Init();
|
||||
totalLength = 1;
|
||||
minLength = 0;
|
||||
}
|
||||
};
|
||||
|
||||
class IPhysicsConstraint
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsConstraint( void ) {}
|
||||
|
||||
// NOTE: Constraints are active when created. You can temporarily enable/disable them with these functions
|
||||
virtual void Activate( void ) = 0;
|
||||
virtual void Deactivate( void ) = 0;
|
||||
|
||||
// set a pointer to the game object
|
||||
virtual void SetGameData( void *gameData ) = 0;
|
||||
|
||||
// get a pointer to the game object
|
||||
virtual void *GetGameData( void ) const = 0;
|
||||
|
||||
// Get the parent/referenced object
|
||||
virtual IPhysicsObject *GetReferenceObject( void ) const = 0;
|
||||
|
||||
// Get the attached object
|
||||
virtual IPhysicsObject *GetAttachedObject( void ) const = 0;
|
||||
|
||||
virtual void SetLinearMotor( float speed, float maxLinearImpulse ) = 0;
|
||||
virtual void SetAngularMotor( float rotSpeed, float maxAngularImpulse ) = 0;
|
||||
|
||||
virtual void UpdateRagdollTransforms( const matrix3x4_t &constraintToReference, const matrix3x4_t &constraintToAttached ) = 0;
|
||||
virtual bool GetConstraintTransform( matrix3x4_t *pConstraintToReference, matrix3x4_t *pConstraintToAttached ) const = 0;
|
||||
virtual bool GetConstraintParams( constraint_breakableparams_t *pParams ) const = 0;
|
||||
|
||||
virtual void OutputDebugInfo() = 0;
|
||||
};
|
||||
|
||||
|
||||
class IPhysicsConstraintGroup
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsConstraintGroup( void ) {}
|
||||
virtual void Activate() = 0;
|
||||
virtual bool IsInErrorState() = 0;
|
||||
virtual void ClearErrorState() = 0;
|
||||
virtual void GetErrorParams( constraint_groupparams_t *pParams ) = 0;
|
||||
virtual void SetErrorParams( const constraint_groupparams_t ¶ms ) = 0;
|
||||
virtual void SolvePenetration( IPhysicsObject *pObj0, IPhysicsObject *pObj1 ) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // CONSTRAINTS_H
|
51
public/vphysics/friction.h
Normal file
51
public/vphysics/friction.h
Normal file
@ -0,0 +1,51 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef FRICTION_H
|
||||
#define FRICTION_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
// NOTE: This is an iterator for the contact points on an object
|
||||
// NOTE: This should only be used temporarily. Holding one of these
|
||||
// NOTE: across collision callbacks or calls into simulation will cause errors!
|
||||
// NOTE: VPHYSICS may choose to make the data contained within this object invalid
|
||||
// NOTE: any time simulation is run.
|
||||
class IPhysicsFrictionSnapshot
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsFrictionSnapshot() {}
|
||||
|
||||
virtual bool IsValid() = 0;
|
||||
|
||||
// Object 0 is this object, Object 1 is the other object
|
||||
virtual IPhysicsObject *GetObject( int index ) = 0;
|
||||
virtual int GetMaterial( int index ) = 0;
|
||||
|
||||
virtual void GetContactPoint( Vector &out ) = 0;
|
||||
|
||||
// points away from source object
|
||||
virtual void GetSurfaceNormal( Vector &out ) = 0;
|
||||
virtual float GetNormalForce() = 0;
|
||||
virtual float GetEnergyAbsorbed() = 0;
|
||||
|
||||
// recompute friction (useful if dynamically altering materials/mass)
|
||||
virtual void RecomputeFriction() = 0;
|
||||
// clear all friction force at this contact point
|
||||
virtual void ClearFrictionForce() = 0;
|
||||
|
||||
virtual void MarkContactForDelete() = 0;
|
||||
virtual void DeleteAllMarkedContacts( bool wakeObjects ) = 0;
|
||||
|
||||
// Move to the next friction data for this object
|
||||
virtual void NextFrictionData() = 0;
|
||||
virtual float GetFrictionCoefficient() = 0;
|
||||
};
|
||||
|
||||
|
||||
|
||||
#endif // FRICTION_H
|
29
public/vphysics/object_hash.h
Normal file
29
public/vphysics/object_hash.h
Normal file
@ -0,0 +1,29 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef OBJECT_HASH_H
|
||||
#define OBJECT_HASH_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
class IPhysicsObjectPairHash
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsObjectPairHash() {}
|
||||
virtual void AddObjectPair( void *pObject0, void *pObject1 ) = 0;
|
||||
virtual void RemoveObjectPair( void *pObject0, void *pObject1 ) = 0;
|
||||
virtual bool IsObjectPairInHash( void *pObject0, void *pObject1 ) = 0;
|
||||
virtual void RemoveAllPairsForObject( void *pObject0 ) = 0;
|
||||
virtual bool IsObjectInHash( void *pObject0 ) = 0;
|
||||
|
||||
// Used to iterate over all pairs an object is part of
|
||||
virtual int GetPairCountForObject( void *pObject0 ) = 0;
|
||||
virtual int GetPairListForObject( void *pObject0, int nMaxCount, void **ppObjectList ) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif // OBJECT_HASH_H
|
44
public/vphysics/performance.h
Normal file
44
public/vphysics/performance.h
Normal file
@ -0,0 +1,44 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef PERFORMANCE_H
|
||||
#define PERFORMANCE_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
// Don't ever change these values, or face all kinds of subtle gameplay changes
|
||||
const float k_flMaxVelocity = 2000.0f;
|
||||
const float k_flMaxAngularVelocity = 360.0f * 10.0f;
|
||||
|
||||
const float DEFAULT_MIN_FRICTION_MASS = 10.0f;
|
||||
const float DEFAULT_MAX_FRICTION_MASS = 2500.0f;
|
||||
struct physics_performanceparams_t
|
||||
{
|
||||
int maxCollisionsPerObjectPerTimestep; // object will be frozen after this many collisions (visual hitching vs. CPU cost)
|
||||
int maxCollisionChecksPerTimestep; // objects may penetrate after this many collision checks (can be extended in AdditionalCollisionChecksThisTick)
|
||||
float maxVelocity; // limit world space linear velocity to this (in / s)
|
||||
float maxAngularVelocity; // limit world space angular velocity to this (degrees / s)
|
||||
float lookAheadTimeObjectsVsWorld; // predict collisions this far (seconds) into the future
|
||||
float lookAheadTimeObjectsVsObject; // predict collisions this far (seconds) into the future
|
||||
float minFrictionMass; // min mass for friction solves (constrains dynamic range of mass to improve stability)
|
||||
float maxFrictionMass; // mas mass for friction solves
|
||||
|
||||
void Defaults()
|
||||
{
|
||||
maxCollisionsPerObjectPerTimestep = 6;
|
||||
maxCollisionChecksPerTimestep = 250;
|
||||
maxVelocity = k_flMaxVelocity;
|
||||
maxAngularVelocity = k_flMaxAngularVelocity;
|
||||
lookAheadTimeObjectsVsWorld = 1.0f;
|
||||
lookAheadTimeObjectsVsObject = 0.5f;
|
||||
minFrictionMass = DEFAULT_MIN_FRICTION_MASS;
|
||||
maxFrictionMass = DEFAULT_MAX_FRICTION_MASS;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // PERFORMANCE_H
|
47
public/vphysics/player_controller.h
Normal file
47
public/vphysics/player_controller.h
Normal file
@ -0,0 +1,47 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef PLAYER_CONTROLLER_H
|
||||
#define PLAYER_CONTROLLER_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
class IPhysicsPlayerControllerEvent
|
||||
{
|
||||
public:
|
||||
virtual int ShouldMoveTo( IPhysicsObject *pObject, const Vector &position ) = 0;
|
||||
};
|
||||
|
||||
class IPhysicsPlayerController
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsPlayerController( void ) {}
|
||||
|
||||
virtual void Update( const Vector &position, const Vector &velocity, float secondsToArrival, bool onground, IPhysicsObject *ground ) = 0;
|
||||
virtual void SetEventHandler( IPhysicsPlayerControllerEvent *handler ) = 0;
|
||||
virtual bool IsInContact( void ) = 0;
|
||||
virtual void MaxSpeed( const Vector &maxVelocity ) = 0;
|
||||
|
||||
// allows game code to change collision models
|
||||
virtual void SetObject( IPhysicsObject *pObject ) = 0;
|
||||
// UNDONE: Refactor this and shadow controllers into a single class/interface through IPhysicsObject
|
||||
virtual int GetShadowPosition( Vector *position, QAngle *angles ) = 0;
|
||||
virtual void StepUp( float height ) = 0;
|
||||
virtual void Jump() = 0;
|
||||
virtual void GetShadowVelocity( Vector *velocity ) = 0;
|
||||
virtual IPhysicsObject *GetObject() = 0;
|
||||
virtual void GetLastImpulse( Vector *pOut ) = 0;
|
||||
|
||||
virtual void SetPushMassLimit( float maxPushMass ) = 0;
|
||||
virtual void SetPushSpeedLimit( float maxPushSpeed ) = 0;
|
||||
|
||||
virtual float GetPushMassLimit() = 0;
|
||||
virtual float GetPushSpeedLimit() = 0;
|
||||
virtual bool WasFrozen() = 0;
|
||||
};
|
||||
|
||||
#endif // PLAYER_CONTROLLER_H
|
40
public/vphysics/stats.h
Normal file
40
public/vphysics/stats.h
Normal file
@ -0,0 +1,40 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef STATS_H
|
||||
#define STATS_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
// internal counters to measure cost of physics simulation
|
||||
struct physics_stats_t
|
||||
{
|
||||
float maxRescueSpeed;
|
||||
float maxSpeedGain;
|
||||
|
||||
int impactSysNum;
|
||||
int impactCounter;
|
||||
int impactSumSys;
|
||||
int impactHardRescueCount;
|
||||
int impactRescueAfterCount;
|
||||
int impactDelayedCount;
|
||||
int impactCollisionChecks;
|
||||
int impactStaticCount;
|
||||
|
||||
double totalEnergyDestroyed;
|
||||
int collisionPairsTotal;
|
||||
int collisionPairsCreated;
|
||||
int collisionPairsDestroyed;
|
||||
|
||||
int potentialCollisionsObjectVsObject;
|
||||
int potentialCollisionsObjectVsWorld;
|
||||
|
||||
int frictionEventsProcessed;
|
||||
};
|
||||
|
||||
|
||||
#endif // STATS_H
|
250
public/vphysics/vehicles.h
Normal file
250
public/vphysics/vehicles.h
Normal file
@ -0,0 +1,250 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
// $NoKeywords: $
|
||||
//=============================================================================//
|
||||
|
||||
#ifndef VEHICLES_H
|
||||
#define VEHICLES_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
#include "datamap.h"
|
||||
|
||||
|
||||
#define VEHICLE_TYPE_CAR_WHEELS (1<<0)
|
||||
#define VEHICLE_TYPE_CAR_RAYCAST (1<<1)
|
||||
#define VEHICLE_TYPE_JETSKI_RAYCAST (1<<2)
|
||||
#define VEHICLE_TYPE_AIRBOAT_RAYCAST (1<<3)
|
||||
|
||||
#define VEHICLE_MAX_AXLE_COUNT 4
|
||||
#define VEHICLE_MAX_GEAR_COUNT 6
|
||||
#define VEHICLE_MAX_WHEEL_COUNT (2*VEHICLE_MAX_AXLE_COUNT)
|
||||
|
||||
#define VEHICLE_TIRE_NORMAL 0
|
||||
#define VEHICLE_TIRE_BRAKING 1
|
||||
#define VEHICLE_TIRE_POWERSLIDE 2
|
||||
|
||||
struct vehicle_controlparams_t
|
||||
{
|
||||
float throttle;
|
||||
float steering;
|
||||
float brake;
|
||||
float boost;
|
||||
bool handbrake;
|
||||
bool handbrakeLeft;
|
||||
bool handbrakeRight;
|
||||
bool brakepedal;
|
||||
bool bHasBrakePedal;
|
||||
bool bAnalogSteering;
|
||||
};
|
||||
|
||||
struct vehicle_operatingparams_t
|
||||
{
|
||||
DECLARE_SIMPLE_DATADESC();
|
||||
|
||||
float speed;
|
||||
float engineRPM;
|
||||
int gear;
|
||||
float boostDelay;
|
||||
int boostTimeLeft;
|
||||
float skidSpeed;
|
||||
int skidMaterial;
|
||||
float steeringAngle;
|
||||
int wheelsNotInContact;
|
||||
int wheelsInContact;
|
||||
bool isTorqueBoosting;
|
||||
};
|
||||
|
||||
// Debug!
|
||||
#define VEHICLE_DEBUGRENDERDATA_MAX_WHEELS 10
|
||||
#define VEHICLE_DEBUGRENDERDATA_MAX_AXLES 3
|
||||
|
||||
struct vehicle_debugcarsystem_t
|
||||
{
|
||||
Vector vecAxlePos[VEHICLE_DEBUGRENDERDATA_MAX_AXLES];
|
||||
|
||||
Vector vecWheelPos[VEHICLE_DEBUGRENDERDATA_MAX_WHEELS];
|
||||
Vector vecWheelRaycasts[VEHICLE_DEBUGRENDERDATA_MAX_WHEELS][2];
|
||||
Vector vecWheelRaycastImpacts[VEHICLE_DEBUGRENDERDATA_MAX_WHEELS];
|
||||
};
|
||||
|
||||
struct vehicleparams_t;
|
||||
|
||||
class IPhysicsVehicleController
|
||||
{
|
||||
public:
|
||||
virtual ~IPhysicsVehicleController() {}
|
||||
// call this from the game code with the control parameters
|
||||
virtual void Update( float dt, vehicle_controlparams_t &controls ) = 0;
|
||||
virtual const vehicle_operatingparams_t &GetOperatingParams() = 0;
|
||||
virtual const vehicleparams_t &GetVehicleParams() = 0;
|
||||
virtual vehicleparams_t &GetVehicleParamsForChange() = 0;
|
||||
virtual float UpdateBooster(float dt) = 0;
|
||||
virtual int GetWheelCount(void) = 0;
|
||||
virtual IPhysicsObject *GetWheel(int index) = 0;
|
||||
virtual bool GetWheelContactPoint( int index, Vector *pContactPoint, int *pSurfaceProps ) = 0;
|
||||
virtual void SetSpringLength(int wheelIndex, float length) = 0;
|
||||
virtual void SetWheelFriction(int wheelIndex, float friction) = 0;
|
||||
|
||||
virtual void OnVehicleEnter( void ) = 0;
|
||||
virtual void OnVehicleExit( void ) = 0;
|
||||
|
||||
virtual void SetEngineDisabled( bool bDisable ) = 0;
|
||||
virtual bool IsEngineDisabled( void ) = 0;
|
||||
|
||||
// Debug
|
||||
virtual void GetCarSystemDebugData( vehicle_debugcarsystem_t &debugCarSystem ) = 0;
|
||||
virtual void VehicleDataReload() = 0;
|
||||
};
|
||||
|
||||
|
||||
// parameters for the body object control of the vehicle
|
||||
struct vehicle_bodyparams_t
|
||||
{
|
||||
DECLARE_SIMPLE_DATADESC();
|
||||
|
||||
Vector massCenterOverride; // leave at vec3_origin for no override
|
||||
float massOverride; // leave at 0 for no override
|
||||
float addGravity; // keeps car down
|
||||
float tiltForce; // keeps car down when not on flat ground
|
||||
float tiltForceHeight; // where the tilt force pulls relative to center of mass
|
||||
float counterTorqueFactor;
|
||||
float keepUprightTorque;
|
||||
float maxAngularVelocity; // clamp the car angular velocity separately from other objects to keep stable
|
||||
};
|
||||
|
||||
// wheel objects are created by vphysics, these are the parameters for those objects
|
||||
// NOTE: They are paired, so only one set of parameters is necessary per axle
|
||||
struct vehicle_wheelparams_t
|
||||
{
|
||||
DECLARE_SIMPLE_DATADESC();
|
||||
|
||||
float radius;
|
||||
float mass;
|
||||
float inertia;
|
||||
float damping; // usually 0
|
||||
float rotdamping; // usually 0
|
||||
float frictionScale; // 1.5 front, 1.8 rear
|
||||
int materialIndex;
|
||||
int brakeMaterialIndex;
|
||||
int skidMaterialIndex;
|
||||
float springAdditionalLength; // 0 means the spring is at it's rest length
|
||||
};
|
||||
|
||||
struct vehicle_suspensionparams_t
|
||||
{
|
||||
DECLARE_SIMPLE_DATADESC();
|
||||
|
||||
float springConstant;
|
||||
float springDamping;
|
||||
float stabilizerConstant;
|
||||
float springDampingCompression;
|
||||
float maxBodyForce;
|
||||
};
|
||||
|
||||
// NOTE: both raytrace and wheel data here because jetski uses both.
|
||||
struct vehicle_axleparams_t
|
||||
{
|
||||
DECLARE_SIMPLE_DATADESC();
|
||||
|
||||
Vector offset; // center of this axle in vehicle object space
|
||||
Vector wheelOffset; // offset to wheel (assume other wheel is symmetric at -wheelOffset) from axle center
|
||||
Vector raytraceCenterOffset; // offset to center of axle for the raytrace data.
|
||||
Vector raytraceOffset; // offset to raytrace for non-wheel (some wheeled) vehicles
|
||||
vehicle_wheelparams_t wheels;
|
||||
vehicle_suspensionparams_t suspension;
|
||||
float torqueFactor; // normalized to 1 across all axles
|
||||
// e.g. 0,1 for rear wheel drive - 0.5,0.5 for 4 wheel drive
|
||||
float brakeFactor; // normalized to 1 across all axles
|
||||
};
|
||||
|
||||
struct vehicle_steeringparams_t
|
||||
{
|
||||
DECLARE_SIMPLE_DATADESC();
|
||||
|
||||
float degreesSlow; // angle in degrees of steering at slow speed
|
||||
float degreesFast; // angle in degrees of steering at fast speed
|
||||
float degreesBoost; // angle in degrees of steering at fast speed
|
||||
float steeringRateSlow; // this is the speed the wheels are steered when the vehicle is slow
|
||||
float steeringRateFast; // this is the speed the wheels are steered when the vehicle is "fast"
|
||||
float steeringRestRateSlow; // this is the speed at which the wheels move toward their resting state (straight ahead) at slow speed
|
||||
float steeringRestRateFast; // this is the speed at which the wheels move toward their resting state (straight ahead) at fast speed
|
||||
float speedSlow; // this is the max speed of "slow"
|
||||
float speedFast; // this is the min speed of "fast"
|
||||
float turnThrottleReduceSlow; // this is the amount of throttle reduction to apply at the maximum steering angle
|
||||
float turnThrottleReduceFast; // this is the amount of throttle reduction to apply at the maximum steering angle
|
||||
float brakeSteeringRateFactor; // this scales the steering rate when the brake/handbrake is down
|
||||
float throttleSteeringRestRateFactor; // this scales the steering rest rate when the throttle is down
|
||||
float powerSlideAccel; // scale of speed to acceleration
|
||||
float boostSteeringRestRateFactor; // this scales the steering rest rate when boosting
|
||||
float boostSteeringRateFactor; // this scales the steering rest rate when boosting
|
||||
float steeringExponent; // this makes the steering response non-linear. The steering function is linear, then raised to this power
|
||||
|
||||
bool isSkidAllowed; // true/false skid flag
|
||||
bool dustCloud; // flag for creating a dustcloud behind vehicle
|
||||
};
|
||||
|
||||
struct vehicle_engineparams_t
|
||||
{
|
||||
DECLARE_SIMPLE_DATADESC();
|
||||
|
||||
float horsepower;
|
||||
float maxSpeed;
|
||||
float maxRevSpeed;
|
||||
float maxRPM; // redline RPM limit
|
||||
float axleRatio; // ratio of engine rev to axle rev
|
||||
float throttleTime; // time to reach full throttle in seconds
|
||||
|
||||
// transmission
|
||||
int gearCount; // gear count - max 10
|
||||
float gearRatio[VEHICLE_MAX_GEAR_COUNT]; // ratio for each gear
|
||||
|
||||
// automatic transmission (simple auto-shifter - switches at fixed RPM limits)
|
||||
float shiftUpRPM; // max RPMs to switch to a higher gear
|
||||
float shiftDownRPM; // min RPMs to switch to a lower gear
|
||||
float boostForce;
|
||||
float boostDuration;
|
||||
float boostDelay;
|
||||
float boostMaxSpeed;
|
||||
float autobrakeSpeedGain;
|
||||
float autobrakeSpeedFactor;
|
||||
bool torqueBoost;
|
||||
bool isAutoTransmission; // true for auto, false for manual
|
||||
};
|
||||
|
||||
struct vehicleparams_t
|
||||
{
|
||||
DECLARE_SIMPLE_DATADESC();
|
||||
|
||||
int axleCount;
|
||||
int wheelsPerAxle;
|
||||
vehicle_bodyparams_t body;
|
||||
vehicle_axleparams_t axles[VEHICLE_MAX_AXLE_COUNT];
|
||||
vehicle_engineparams_t engine;
|
||||
vehicle_steeringparams_t steering;
|
||||
};
|
||||
|
||||
// Iterator for queries
|
||||
class CPassengerSeatTransition;
|
||||
typedef CUtlVector< CPassengerSeatTransition> PassengerSeatAnims_t;
|
||||
|
||||
// Seat query types
|
||||
enum VehicleSeatQuery_e
|
||||
{
|
||||
VEHICLE_SEAT_ANY, // Any available seat for our role
|
||||
VEHICLE_SEAT_NEAREST, // Seat closest to our starting point
|
||||
};
|
||||
|
||||
// Seat anim types for return
|
||||
enum PassengerSeatAnimType_t
|
||||
{
|
||||
PASSENGER_SEAT_ENTRY,
|
||||
PASSENGER_SEAT_EXIT
|
||||
};
|
||||
|
||||
#define VEHICLE_SEAT_INVALID -1 // An invalid seat
|
||||
|
||||
#endif // VEHICLES_H
|
46
public/vphysics/virtualmesh.h
Normal file
46
public/vphysics/virtualmesh.h
Normal file
@ -0,0 +1,46 @@
|
||||
//========= Copyright Valve Corporation, All rights reserved. ============//
|
||||
//
|
||||
// Purpose:
|
||||
//
|
||||
//=============================================================================
|
||||
|
||||
#ifndef VIRTUALMESH_H
|
||||
#define VIRTUALMESH_H
|
||||
#ifdef _WIN32
|
||||
#pragma once
|
||||
#endif
|
||||
|
||||
// NOTE: These are fixed length to make it easy to fill these out without memory allocation or storage
|
||||
const int MAX_VIRTUAL_TRIANGLES = 1024;
|
||||
struct virtualmeshlist_t
|
||||
{
|
||||
Vector *pVerts;
|
||||
int indexCount;
|
||||
int triangleCount;
|
||||
int vertexCount;
|
||||
int surfacePropsIndex;
|
||||
byte *pHull;
|
||||
unsigned short indices[MAX_VIRTUAL_TRIANGLES*3];
|
||||
};
|
||||
|
||||
struct virtualmeshtrianglelist_t
|
||||
{
|
||||
int triangleCount;
|
||||
unsigned short triangleIndices[MAX_VIRTUAL_TRIANGLES*3];
|
||||
};
|
||||
|
||||
class IVirtualMeshEvent
|
||||
{
|
||||
public:
|
||||
virtual void GetVirtualMesh( void *userData, virtualmeshlist_t *pList ) = 0;
|
||||
virtual void GetWorldspaceBounds( void *userData, Vector *pMins, Vector *pMaxs ) = 0;
|
||||
virtual void GetTrianglesInSphere( void *userData, const Vector ¢er, float radius, virtualmeshtrianglelist_t *pList ) = 0;
|
||||
};
|
||||
struct virtualmeshparams_t
|
||||
{
|
||||
IVirtualMeshEvent *pMeshEventHandler;
|
||||
void *userData;
|
||||
bool buildOuterHull;
|
||||
};
|
||||
|
||||
#endif // VIRTUALMESH_H
|
Reference in New Issue
Block a user