29 #include "../idlib/precompiled.h"
42 #define ARTICULATED_FIGURE_ANIM "af_pose"
43 #define POSE_BOUNDS_EXPANSION 5.0f
95 savefile->
ReadObject( reinterpret_cast<idClass *&>(
self ) );
139 idVec3 origin, renderOrigin, bodyOrigin;
140 idMat3 axis, renderAxis, bodyAxis;
151 renderEntity =
self->GetRenderEntity();
152 if ( !renderEntity ) {
167 renderOrigin = origin -
baseOrigin * renderAxis;
171 for ( i = 0; i <
jointMods.Num(); i++ ) {
179 origin = ( bodyOrigin -
jointMods[
i].jointBodyOrigin * axis - renderOrigin ) * renderAxis.Transpose();
198 idVec3 origin, entityOrigin;
209 entityOrigin = origin -
baseOrigin * entityAxis;
212 for ( i = 0; i <
jointMods.Num(); i++ ) {
214 origin = ( body->
GetWorldOrigin() - entityOrigin ) * entityAxis.Transpose();
244 if ( !animatorPtr ) {
249 if ( !renderEntity ) {
264 for ( i = 0; i <
jointMods.Num(); i++ ) {
288 idVec3 origin, lastOrigin;
298 if ( !animatorPtr ) {
303 if ( !renderEntity ) {
319 for ( i = 0; i <
jointMods.Num(); i++ ) {
337 int i,
j, numClipModels;
350 for ( i = 0; i <
jointMods.Num(); i++ ) {
353 for ( j = 0; j < numClipModels; j++ ) {
369 touchList[ numTouching ].touchedByBody = body;
370 touchList[ numTouching ].touchedClipModel = cm;
371 touchList[ numTouching ].touchedEnt = cm->
GetEntity();
373 clipModels[
j] =
NULL;
454 gameLocal.
Error(
"idAF for entity '%s' at (%s) modifies unknown joint '%s'",
self->
name.
c_str(),
self->GetPhysics()->GetOrigin().ToString(0), jointName );
457 assert( handle < animator->NumJoints() );
458 origin = joints[ handle ].
ToVec3();
459 axis = joints[ handle ].
ToMat3();
495 idMat3 axis, inertiaTensor;
496 idVec3 centerOfMass, origin;
524 bounds[0].z -= bounds[1].z;
532 length = axis[2].Normalize();
534 axis[2].NormalVectors( axis[0], axis[1] );
546 origin += centerOfMass * axis;
604 for( i = 0; i < jointList.
Num(); i++ ) {
605 if (
jointBody[ jointList[ i ] ] != -1 ) {
656 switch( fc->
limit ) {
689 switch( fc->
limit ) {
722 switch( fc->
limit ) {
724 idVec3 left, up, axis, shaft;
777 static bool GetJointTransform(
void *model,
const idJointMat *frame,
const char *jointName,
idVec3 &origin,
idMat3 &axis ) {
780 joint =
reinterpret_cast<idAnimator *
>(model)->GetJointHandle( jointName );
781 if ( ( joint >= 0 ) && ( joint < reinterpret_cast<idAnimator *>(model)->NumJoints() ) ) {
782 origin = frame[ joint ].
ToVec3();
783 axis = frame[ joint ].
ToMat3();
814 name.StripFileExtension();
822 if ( file->
bodies.
Num() == 0 || file->
bodies[0]->jointName !=
"origin" ) {
823 gameLocal.
Warning(
"idAF::Load: articulated figure '%s' for entity '%s' at (%s) has no body which modifies the origin joint.",
830 gameLocal.
Warning(
"idAF::Load: articulated figure '%s' for entity '%s' at (%s) has no or defaulted modelDef '%s'",
837 gameLocal.
Warning(
"idAF::Load: articulated figure '%s' for entity '%s' at (%s) has no or defaulted model '%s'",
845 gameLocal.
Warning(
"idAF::Load: articulated figure '%s' for entity '%s' at (%s) has no modified animation '%s'",
852 joints = (
idJointMat * )_alloca16( numJoints *
sizeof( joints[0] ) );
879 for ( j = 0; j < file->
bodies.
Num(); j++ ) {
906 for ( i = 0; i < file->
bodies.
Num(); i++ ) {
920 gameLocal.
Warning(
"idAF::Load: articulated figure '%s' for entity '%s' at (%s) joint '%s' is not contained by a body",
1006 if ( inheritVelocityTime > 0 ) {
1031 self->UpdateModel();
1069 if ( !constraint ) {
1075 gameLocal.
Warning(
"constraint '%s' does not bind to another entity", name );
1079 switch( constraint->
GetType() ) {
1112 for ( i = 0; i <
jointMods.Num(); i++ ) {
1115 key =
"body " + body->
GetName();
1119 args.
Set( key, value );
1139 name.
Strip(
"body " );
1142 sscanf( kv->
GetValue(),
"%f %f %f %f %f %f", &origin.
x, &origin.
y, &origin.
z, &angles.
pitch, &angles.
yaw, &angles.
roll );
1166 idVec3 origin, renderOrigin;
1173 const idDict &args =
self->spawnArgs;
1179 renderOrigin = origin -
baseOrigin * renderAxis;
1184 name.
Strip(
"bindConstraint " );
1192 gameLocal.
Warning(
"idAF::AddBindConstraints: body '%s' not found on entity '%s'", bodyName.
c_str(),
self->name.c_str() );
1197 if ( type.
Icmp(
"fixed" ) == 0 ) {
1203 else if ( type.
Icmp(
"ballAndSocket" ) == 0 ) {
1216 c->
SetAnchor( renderOrigin + origin * renderAxis );
1218 else if ( type.
Icmp(
"universal" ) == 0 ) {
1230 c->
SetAnchor( renderOrigin + origin * renderAxis );
1234 gameLocal.
Warning(
"idAF::AddBindConstraints: unknown constraint type '%s' on entity '%s'", type.
c_str(),
self->name.c_str() );
1255 const idDict &args =
self->spawnArgs;
1261 name.
Strip(
"bindConstraint " );
void AddForce(const int id, const idVec3 &point, const idVec3 &force)
virtual const idVec3 & GetOrigin(int id=0) const =0
void SetupPose(idEntity *ent, int time)
void SetSelfCollision(const bool enable)
int ClipModelsTouchingBounds(const idBounds &bounds, int contentMask, idClipModel **clipModelList, int maxCount) const
idEntity * GetEntity(void) const
void GetImpactInfo(const int id, const idVec3 &point, impactInfo_t *info) const
idAFVector contactMotorDirection
void ForceBodyId(idAFBody *body, int newId)
idList< idDeclAF_Constraint * > constraints
float defaultLinearFriction
bool GetJointTransform(jointHandle_t jointHandle, int currenttime, idVec3 &offset, idMat3 &axis)
GLsizei const GLfloat * value
void WriteString(const char *string)
void SetAnchor(const idVec3 &worldPosition)
void SetPyramidLimit(const idVec3 &pyramidAxis, const idVec3 &baseAxis, const float angle1, const float angle2, const idVec3 &body1Axis)
int AddBody(idAFBody *body)
#define POSE_BOUNDS_EXPANSION
assert(prefInfo.fullscreenBtn)
int GetNumConstraints(void) const
#define CLIPMODEL_ID_TO_JOINT_HANDLE(id)
jointHandle_t GetFirstChild(jointHandle_t jointnum) const
idAFBody * GetBody2(void) const
void SetDefaultFriction(float linear, float angular, float contact)
void FinishAFPose(int animnum, const idBounds &bounds, const int time)
idMat3 mat3_identity(idVec3(1, 0, 0), idVec3(0, 1, 0), idVec3(0, 0, 1))
virtual idAnimator * GetAnimator(void)
virtual void SetBody2(idAFBody *body)
void ApplyImpulse(const int id, const idVec3 &point, const idVec3 &impulse)
void WriteObject(const idClass *obj)
declAFConstraintType_t type
int GetNumBodies(void) const
idAFConstraint * GetConstraint(const char *constraintName) const
virtual void Translate(const idVec3 &translation)
void SetContents(int newContents)
virtual void Finish(const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model) const
void SetDensity(float density, const idMat3 &inertiaScale=mat3_identity)
void ChangePose(idEntity *ent, int time)
void LoadState(const idDict &args)
void SetContactMotorDirection(const idVec3 &dir)
void SetupBox(const idBounds &boxBounds)
const idStr & GetKey(void) const
void SetWorldOrigin(const idVec3 &origin)
idBounds GetBounds(void) const
bool UpdateAnimation(void)
const char * ToString(int precision=2) const
idMat3 Transpose(void) const
void void void void void Error(const char *fmt,...) const id_attribute((format(printf
int NumJoints(void) const
void AssureSize(int newSize)
idAFBody * GetBody(const char *bodyName) const
const idMat3 & GetWorldAxis(void) const
const idMat3 & GetAxis(void) const
virtual void Translate(const idVec3 &translation)
const idKeyValue * MatchPrefix(const char *prefix, const idKeyValue *lastMatch=NULL) const
int BodyForClipModelId(int id) const
void SetShafts(const idVec3 &cardanShaft1, const idVec3 &cardanShaft2)
void SetupCylinder(const idBounds &cylBounds, const int numSides)
void AddBindConstraints(void)
jointHandle_t GetJointHandle(const char *name) const
void void void void DWarning(const char *fmt,...) const id_attribute((format(printf
const char * GetName(void) const
void ReadBool(bool &value)
void SetFriction(const float f)
GLint GLint GLsizei GLsizei GLsizei depth
void WriteStaticObject(const idClass &obj)
idPhysics_AF * GetPhysics(void)
virtual const char * Name() const =0
const idVec3 & GetOrigin(void) const
GLuint GLuint GLsizei GLenum type
idAFVector frictionDirection
void Set(const char *key, const char *value)
void GetMassProperties(const float density, float &mass, idVec3 ¢erOfMass, idMat3 &inertiaTensor) const
idClipModel * GetClipModel(void) const
void OrthogonalBasis(idVec3 &left, idVec3 &up) const
void SetAnimator(idAnimator *a)
void WriteVec3(const idVec3 &vec)
const idMat3 & GetAxis(int id=0) const
virtual void ANIM_CreateAnimFrame(const idRenderModel *model, const idMD5Anim *anim, int numJoints, idJointMat *frame, int time, const idVec3 &offset, bool remove_origin_offset)
void SetAxis(const idVec3 &ax)
int Icmp(const char *text) const
declAFJointMod_t jointMod
void RemoveBindConstraints(void)
int GetClipMask(void) const
void Restore(idRestoreGame *savefile)
bool Load(idEntity *ent, const char *fileName)
void SetFriction(float linear, float angular, float contact)
void WriteBool(const bool value)
virtual void Translate(const idVec3 &translation)
void void void Warning(const char *fmt,...) const id_attribute((format(printf
void SetConeLimit(const idVec3 &coneAxis, const float coneAngle)
void DeleteBody(const char *bodyName)
void SetClipMask(const int mask)
void SetAnchor(const idVec3 &worldPosition)
void GetPhysicsToVisualTransform(idVec3 &origin, idMat3 &axis) const
const idBounds & GetAbsBounds(int id=-1) const
void AddForce(idEntity *ent, int id, const idVec3 &point, const idVec3 &force)
void Translate(const idVec3 &translation)
void ClearAllJoints(void)
void SetLimit(const float minLength, const float maxLength)
void SetWorldAxis(const idMat3 &axis)
void SetSelf(idEntity *e)
void SetFrictionDirection(const idVec3 &dir)
idVec3 GetAnchor(void) const
idVec3 GetAnchor(void) const
void SetupBone(const float length, const float width)
idPhysics * GetPhysics(void) const
idList< jointConversion_t > jointMods
idAngles ToAngles(void) const
const idVec3 & ToVec3(void) const
void SetMass(float mass, int id=-1)
void SetAnchor(const idVec3 &worldAnchor1, const idVec3 &worldAnchor2)
bool TestSolid(void) const
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
void GetImpactInfo(idEntity *ent, int id, const idVec3 &point, impactInfo_t *info)
virtual renderEntity_t * GetRenderEntity(void)
idVec3 GetAnchor(void) const
int EntitiesTouchingAF(afTouch_t touchList[MAX_GENTITIES]) const
void SetConstraintPosition(const char *name, const idVec3 &pos)
void SetBase(idAFBody *body, const idJointMat *joints)
idVec3 ToVec3(void) const
static float Fabs(float f)
cmHandle_t Handle(void) const
void SetupOctahedron(const idBounds &octBounds)
void ClearAllAnims(int currentTime, int cleartime)
const idMD5Anim * MD5Anim(int num) const
const idBounds & GetBounds(void) const
void SetupCone(const idBounds &coneBounds, const int numSides)
virtual const idDecl * FindType(declType_t type, const char *name, bool makeDefault=true)=0
void SetFriction(const float f)
float defaultContactFriction
const idAnim * GetAnim(int index) const
void SetSuspendSpeed(const idVec2 &velocity, const idVec2 &acceleration)
void SetClipModel(idClipModel *clipModel)
const idVec3 & GetGravity(void) const
bool IsTraceModel(void) const
void GetJointList(const char *jointnames, idList< jointHandle_t > &jointList) const
bool IsAtRest(void) const
const idStr & GetValue(void) const
bool IsEqual(const idTraceModel &trm) const
const idDeclModelDef * ModelDef(void) const
void FromTransformedBounds(const idBounds &bounds, const idVec3 &origin, const idMat3 &axis)
void SetSelfCollision(const bool enable)
void SetLinearVelocity(const idVec3 &linear) const
void SetAnchor(const idVec3 &worldPosition)
const idVec3 & GetVisualOffset(void) const
void SetLimit(const idVec3 &axis, const float angle, const idVec3 &body1Axis)
int LoadMemory(const char *ptr, int length, const char *name, int startLine=1)
#define ARTICULATED_FIGURE_ANIM
const char * ToString(int precision=2) const
void WriteInt(const int value)
idDeclManager * declManager
void WriteMat3(const idMat3 &mat)
void SetAxis(const idVec3 &axis)
int GetBodyId(idAFBody *body) const
void ReadMat3(idMat3 &mat)
bool IsLoaded(void) const
idMat3 ToMat3(void) const
void ReadStaticObject(idClass &obj)
void SetSuspendTolerance(const float noMoveTime, const float translationTolerance, const float rotationTolerance)
void UpdateClipModels(void)
void AddConstraint(idAFConstraint *constraint)
bool LoadConstraint(const idDeclAF_Constraint *fc)
void StartFromCurrentPose(int inheritVelocityTime)
virtual bool IsDefaultModel() const =0
void SetClipMask(int mask, int id=-1)
void SetConeLimit(const idVec3 &coneAxis, const float coneAngle, const idVec3 &body1Axis)
const idVec3 & GetWorldOrigin(void) const
idVec2 suspendAcceleration
idList< idDeclAF_Body * > bodies
idMat3 ToMat3(void) const
declState_t GetState(void) const
virtual void SetBody1(idAFBody *body)
enum idDeclAF_Constraint::@49 limit
bool IntersectsBounds(const idBounds &a) const
void Save(idSaveGame *savefile) const
idCVar af_testSolid("af_testSolid","1", CVAR_GAME|CVAR_BOOL,"test for bodies initially stuck in solid")
void DeleteConstraint(const char *constraintName)
int ContentsModel(const idVec3 &start, const idClipModel *mdl, const idMat3 &trmAxis, int contentMask, cmHandle_t model, const idVec3 &modelOrigin, const idMat3 &modelAxis)
GLsizei const GLcharARB const GLint * length
void SetSpring(const float stretch, const float compress, const float damping, const float restLength)
void SetSuspendTime(const float minTime, const float maxTime)
void ReadVec3(idVec3 &vec)
const char * c_str(void) const
void SetAFPoseBlendWeight(float blendWeight)
void ApplyImpulse(idEntity *ent, int id, const idVec3 &point, const idVec3 &impulse)
const char * GetJointName(jointHandle_t handle) const
idAngles ToAngles(void) const
constraintType_t GetType(void) const
const idBounds & GetAbsBounds(void) const
void SetPyramidLimit(const idVec3 &pyramidAxis, const idVec3 &baseAxis, const float angle1, const float angle2)
virtual void SetBody1(idAFBody *body)
idRenderModel * ModelHandle(void) const
const idStr & GetName(void) const
void SetupDodecahedron(const idBounds &dodBounds)
void SetGravity(const idVec3 &newGravity)
void SetFriction(const float f)
void SaveState(idDict &args) const
float defaultAngularFriction
bool Translation(trace_t &results, const idVec3 &start, const idVec3 &end, const idClipModel *mdl, const idMat3 &trmAxis, int contentMask, const idEntity *passEntity)
const char * GetName(void) const
bool IsActive(void) const
void SetAFPoseJointMod(const jointHandle_t jointNum, const AFJointModType_t mod, const idMat3 &axis, const idVec3 &origin)
void ReadString(idStr &string)
int ReadToken(idToken *token)
int GetRestStartTime(void) const
void AddBody(idAFBody *body, const idJointMat *joints, const char *jointName, const AFJointModType_t mod)
bool LoadBody(const idDeclAF_Body *fb, const idJointMat *joints)
const idVec3 & GetOrigin(int id=0) const
void ReadObject(idClass *&obj)
const idStr & GetName(void) const
virtual void SetBody2(idAFBody *body)
bool RemoveOrigin(void) const