29 #include "../idlib/precompiled.h"
82 else if ( token ==
"joint" ) {
89 else if ( token ==
"bonecenter" ) {
99 else if ( token ==
"bonedir" ) {
110 src.
Error(
"unknown token %s in vector", token.
c_str() );
131 if ( !GetJointTransform( model, frame,
joint1,
vec, axis ) ) {
138 if ( !GetJointTransform( model, frame,
joint1, start, axis ) ) {
142 if ( !GetJointTransform( model, frame,
joint2, end, axis ) ) {
150 if ( !GetJointTransform( model, frame,
joint1, start, axis ) ) {
154 if ( !GetJointTransform( model, frame,
joint2, end, axis ) ) {
218 sprintf( format,
"( %%.%df, %%.%df, %%.%df )", precision, precision, precision );
253 v1.ToVec3().x =
v1.ToVec3().y =
v1.ToVec3().z = -10.0f;
255 v2.ToVec3().x =
v2.ToVec3().y =
v2.ToVec3().z = 10.0f;
376 ic[0][0], ic[0][1], ic[0][2],
377 ic[1][0], ic[1][1], ic[1][2],
378 ic[2][0], ic[2][1], ic[2][2] );
607 "\tGenerated by the Articulated Figure Editor.\n"
608 "\tDo not edit directly but launch the game and type 'editAFs' on the console.\n"
660 if ( token.
Icmp(
"none" ) == 0 ) {
663 else if ( token.
Icmp(
"solid" ) == 0 ) {
666 else if ( token.
Icmp(
"body" ) == 0 ) {
669 else if ( token.
Icmp(
"corpse" ) == 0 ) {
672 else if ( token.
Icmp(
"playerclip" ) == 0 ) {
675 else if ( token.
Icmp(
"monsterclip" ) == 0 ) {
678 else if ( token ==
"," ) {
696 if ( str.
Length() ) str +=
", ";
700 if ( str.
Length() ) str +=
", ";
704 if ( str.
Length() ) str +=
", ";
708 if ( str.
Length() ) str +=
", ";
712 if ( str.
Length() ) str +=
", ";
713 str +=
"monsterclip";
715 if ( str[0] ==
'\0' ) {
747 return "orientation";
756 return "orientation";
794 bool hasJoint =
false;
810 src.
Error(
"a body may not be named \"origin\" or \"world\"" );
816 if ( !token.
Icmp(
"model" ) ) {
820 if ( !token.
Icmp(
"box" ) ) {
829 }
else if ( !token.
Icmp(
"octahedron" ) ) {
838 }
else if ( !token.
Icmp(
"dodecahedron" ) ) {
847 }
else if ( !token.
Icmp(
"cylinder" ) ) {
860 }
else if ( !token.
Icmp(
"cone" ) ) {
873 }
else if ( !token.
Icmp(
"bone" ) ) {
886 }
else if ( !token.
Icmp(
"custom" ) ) {
887 src.
Error(
"custom models not yet implemented" );
890 src.
Error(
"unkown model type %s", token.
c_str() );
893 }
else if ( !token.
Icmp(
"origin" ) ) {
897 }
else if ( !token.
Icmp(
"angles" ) ) {
898 if ( !angles.
Parse( src ) ) {
902 }
else if ( !token.
Icmp(
"joint" ) ) {
908 }
else if ( !token.
Icmp(
"mod" ) ) {
913 }
else if ( !token.
Icmp(
"density" ) ) {
915 }
else if ( !token.
Icmp(
"inertiaScale" ) ) {
917 }
else if ( !token.
Icmp(
"friction" ) ) {
923 }
else if ( !token.
Icmp(
"contents" ) ) {
925 }
else if ( !token.
Icmp(
"clipMask" ) ) {
927 }
else if ( !token.
Icmp(
"selfCollision" ) ) {
929 }
else if ( !token.
Icmp(
"containedjoints" ) ) {
934 }
else if ( !token.
Icmp(
"frictionDirection" ) ) {
938 }
else if ( !token.
Icmp(
"contactMotorDirection" ) ) {
942 }
else if ( token ==
"}" ) {
945 src.
Error(
"unknown token %s in body", token.
c_str() );
951 src.
Error(
"no model set for body" );
956 src.
Error(
"no joint set for body" );
983 constraint->
name = token;
987 if ( !token.
Icmp(
"body1" ) ) {
989 constraint->
body1 = token;
990 }
else if ( !token.
Icmp(
"body2" ) ) {
992 constraint->
body2 = token;
993 }
else if ( token ==
"}" ) {
996 src.
Error(
"unknown token %s in ball and socket joint", token.
c_str() );
1023 constraint->
name = token;
1030 if ( !token.
Icmp(
"body1" ) ) {
1032 constraint->
body1 = token;
1033 }
else if ( !token.
Icmp(
"body2" ) ) {
1035 constraint->
body2 = token;
1036 }
else if ( !token.
Icmp(
"anchor" ) ) {
1040 }
else if ( !token.
Icmp(
"conelimit" ) ) {
1051 }
else if ( !token.
Icmp(
"pyramidlimit" ) ) {
1070 }
else if ( !token.
Icmp(
"friction" ) ) {
1072 }
else if ( token ==
"}" ) {
1075 src.
Error(
"unknown token %s in ball and socket joint", token.
c_str() );
1102 constraint->
name = token;
1110 if ( !token.
Icmp(
"body1" ) ) {
1112 constraint->
body1 = token;
1113 }
else if ( !token.
Icmp(
"body2" ) ) {
1115 constraint->
body2 = token;
1116 }
else if ( !token.
Icmp(
"anchor" ) ) {
1120 }
else if ( !token.
Icmp(
"shafts" ) ) {
1126 }
else if ( !token.
Icmp(
"conelimit" ) ) {
1133 }
else if ( !token.
Icmp(
"pyramidlimit" ) ) {
1148 }
else if ( !token.
Icmp(
"friction" ) ) {
1150 }
else if ( token ==
"}" ) {
1153 src.
Error(
"unknown token %s in universal joint", token.
c_str() );
1180 constraint->
name = token;
1187 if ( !token.
Icmp(
"body1" ) ) {
1189 constraint->
body1 = token;
1190 }
else if ( !token.
Icmp(
"body2" ) ) {
1192 constraint->
body2 = token;
1193 }
else if ( !token.
Icmp(
"anchor" ) ) {
1197 }
else if ( !token.
Icmp(
"axis" ) ) {
1201 }
else if ( !token.
Icmp(
"limit" ) ) {
1212 }
else if ( !token.
Icmp(
"friction" ) ) {
1214 }
else if ( token ==
"}" ) {
1217 src.
Error(
"unknown token %s in hinge", token.
c_str() );
1244 constraint->
name = token;
1249 if ( !token.
Icmp(
"body1" ) ) {
1251 constraint->
body1 = token;
1252 }
else if ( !token.
Icmp(
"body2" ) ) {
1254 constraint->
body2 = token;
1255 }
else if ( !token.
Icmp(
"axis" ) ) {
1259 }
else if ( !token.
Icmp(
"friction" ) ) {
1261 }
else if ( token ==
"}" ) {
1264 src.
Error(
"unknown token %s in slider", token.
c_str() );
1291 constraint->
name = token;
1296 if ( !token.
Icmp(
"body1" ) ) {
1298 constraint->
body1 = token;
1299 }
else if ( !token.
Icmp(
"body2" ) ) {
1301 constraint->
body2 = token;
1302 }
else if ( !token.
Icmp(
"anchor1" ) ) {
1306 }
else if ( !token.
Icmp(
"anchor2" ) ) {
1310 }
else if ( !token.
Icmp(
"friction" ) ) {
1312 }
else if ( !token.
Icmp(
"stretch" ) ) {
1314 }
else if ( !token.
Icmp(
"compress" ) ) {
1316 }
else if ( !token.
Icmp(
"damping" ) ) {
1318 }
else if ( !token.
Icmp(
"restLength" ) ) {
1320 }
else if ( !token.
Icmp(
"minLength" ) ) {
1322 }
else if ( !token.
Icmp(
"maxLength" ) ) {
1324 }
else if ( token ==
"}" ) {
1327 src.
Error(
"unknown token %s in spring", token.
c_str() );
1349 if ( !token.
Icmp(
"mesh" ) ) {
1353 }
else if ( !token.
Icmp(
"anim" ) ) {
1357 }
else if ( !token.
Icmp(
"model" ) ) {
1362 }
else if ( !token.
Icmp(
"skin" ) ) {
1367 }
else if ( !token.
Icmp(
"friction" ) ) {
1381 }
else if ( !token.
Icmp(
"totalMass" ) ) {
1383 }
else if ( !token.
Icmp(
"suspendSpeed" ) ) {
1398 }
else if ( !token.
Icmp(
"noMoveTime" ) ) {
1400 }
else if ( !token.
Icmp(
"noMoveTranslation" ) ) {
1402 }
else if ( !token.
Icmp(
"noMoveRotation" ) ) {
1404 }
else if ( !token.
Icmp(
"minMoveTime" ) ) {
1406 }
else if ( !token.
Icmp(
"maxMoveTime" ) ) {
1408 }
else if ( !token.
Icmp(
"contents" ) ) {
1410 }
else if ( !token.
Icmp(
"clipMask" ) ) {
1412 }
else if ( !token.
Icmp(
"selfCollision" ) ) {
1414 }
else if ( token ==
"}" ) {
1417 src.
Error(
"unknown token %s in settings", token.
c_str() );
1441 if ( !token.
Icmp(
"settings" ) ) {
1445 }
else if ( !token.
Icmp(
"body" ) ) {
1449 }
else if ( !token.
Icmp(
"fixed" ) ) {
1453 }
else if ( !token.
Icmp(
"ballAndSocketJoint" ) ) {
1457 }
else if ( !token.
Icmp(
"universalJoint" ) ) {
1461 }
else if ( !token.
Icmp(
"hinge" ) ) {
1465 }
else if ( !token.
Icmp(
"slider" ) ) {
1469 }
else if ( !token.
Icmp(
"spring" ) ) {
1473 }
else if ( token ==
"}" ) {
1476 src.
Error(
"unknown keyword %s", token.
c_str() );
1483 for ( j = i+1; j <
bodies.
Num(); j++ ) {
1485 src.
Error(
"two bodies with the same name \"%s\"",
bodies[i]->
name.c_str() );
1508 if (
bodies[i]->jointName ==
"origin" ) {
1530 "\t\t" "model \"\"\n"
1531 "\t\t" "skin \"\"\n"
1532 "\t\t" "friction 0.01, 0.01, 0.8, 0.5\n"
1533 "\t\t" "suspendSpeed 20, 30, 40, 60\n"
1534 "\t\t" "noMoveTime 1\n"
1535 "\t\t" "noMoveTranslation 10\n"
1536 "\t\t" "noMoveRotation 10\n"
1537 "\t\t" "minMoveTime -1\n"
1538 "\t\t" "maxMoveTime -1\n"
1539 "\t\t" "totalMass -1\n"
1540 "\t\t" "contents corpse\n"
1541 "\t\t" "clipMask solid, corpse\n"
1542 "\t\t" "selfCollision 1\n"
1544 "\t" "body \"body\" {\n"
1545 "\t\t" "joint \"origin\"\n"
1546 "\t\t" "mod orientation\n"
1547 "\t\t" "model box( ( -10, -10, -10 ), ( 10, 10, 10 ) )\n"
1548 "\t\t" "origin ( 0, 0, 0 )\n"
1549 "\t\t" "density 0.2\n"
1550 "\t\t" "friction 0.01, 0.01, 0.8\n"
1551 "\t\t" "contents corpse\n"
1552 "\t\t" "clipMask solid, corpse\n"
1553 "\t\t" "selfCollision 1\n"
1554 "\t\t" "containedJoints \"*origin\"\n"
1596 body->
v1.
Finish( name, GetJointTransform, frame, model );
1597 body->
v2.
Finish( name, GetJointTransform, frame, model );
1598 body->
origin.
Finish( name, GetJointTransform, frame, model );
1604 constraint->
anchor.
Finish( name, GetJointTransform, frame, model );
1605 constraint->
anchor2.
Finish( name, GetJointTransform, frame, model );
1606 constraint->
shaft[0].
Finish( name, GetJointTransform, frame, model );
1607 constraint->
shaft[1].
Finish( name, GetJointTransform, frame, model );
1608 constraint->
axis.
Finish( name, GetJointTransform, frame, model );
1609 constraint->
limitAxis.
Finish( name, GetJointTransform, frame, model );
1639 if (
bodies[i]->
name.Icmp( oldName ) == 0 ) {
1645 if (
constraints[i]->body1.Icmp( oldName ) == 0 ) {
1647 }
else if (
constraints[i]->body2.Icmp( oldName ) == 0 ) {
1665 if (
bodies[i]->name.Icmp( name ) == 0 ) {
int GetLineNum(void) const
int CheckTokenString(const char *string)
idAFVector contactMotorDirection
bool Write(idFile *f) const
idList< idDeclAF_Constraint * > constraints
float defaultLinearFriction
void DeleteBody(const char *name)
bool ReplaceSourceFileText(void)
assert(prefInfo.fullscreenBtn)
idMat3 mat3_identity(idVec3(1, 0, 0), idVec3(0, 1, 0), idVec3(0, 0, 1))
bool ParseHinge(idLexer &src)
declAFConstraintType_t type
const char * GetFileName(void) const
const int DECL_LEXER_FLAGS
bool WriteBallAndSocketJoint(idFile *f, const idDeclAF_Constraint &c) const
virtual void Finish(const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model) const
static int ContentsFromString(const char *str)
bool ParseSettings(idLexer &src)
GLenum GLsizei GLenum format
void SetDefault(const idDeclAF *file)
void Set(const float x, const float y, const float z)
int Parse1DMatrix(int x, float *m)
virtual const char * DefaultDefinition(void) const
const char * GetName(void) const
idAngles ang_zero(0.0f, 0.0f, 0.0f)
bool ParseBody(idLexer &src)
virtual size_t Size(void) const
bool ParseUniversalJoint(idLexer &src)
GLuint GLuint GLsizei GLenum type
idAFVector frictionDirection
float ParseFloat(bool *errorFlag=NULL)
bool WriteSettings(idFile *f) const
void DeleteConstraint(const char *name)
int Icmp(const char *text) const
declAFJointMod_t jointMod
bool WriteHinge(idFile *f, const idDeclAF_Constraint &c) const
void NewConstraint(const char *name)
int ExpectAnyToken(idToken *token)
bool WriteFixed(idFile *f, const idDeclAF_Constraint &c) const
GLfloat GLfloat GLfloat v2
void Error(const char *str,...) id_attribute((format(printf
int ExpectTokenType(int type, int subtype, idToken *token)
const idVec3 & ToVec3(void) const
void NewBody(const char *name)
idVec3 vec3_origin(0.0f, 0.0f, 0.0f)
const char * GetDataPtr(void) const
virtual void FreeData(void)
bool WriteUniversalJoint(idFile *f, const idDeclAF_Constraint &c) const
static declAFJointMod_t JointModFromString(const char *str)
float defaultContactFriction
bool ParseBallAndSocketJoint(idLexer &src)
bool ParseSpring(idLexer &src)
void DeleteContents(bool clear)
static const char * ContentsToString(const int contents, idStr &str)
virtual int WriteFloatString(const char *fmt,...) id_attribute((format(printf
void RenameConstraint(const char *oldName, const char *newName)
int LoadMemory(const char *ptr, int length, const char *name, int startLine=1)
bool ParseFixed(idLexer &src)
void SetText(const char *text)
bool WriteSpring(idFile *f, const idDeclAF_Constraint &c) const
bool WriteBody(idFile *f, const idDeclAF_Body &body) const
bool ParseContents(idLexer &src, int &c) const
int ExpectTokenString(const char *string)
int Append(const type &obj)
float defaultConstraintFriction
bool WriteConstraint(idFile *f, const idDeclAF_Constraint &c) const
idVec2 suspendAcceleration
idList< idDeclAF_Body * > bodies
bool RemoveIndex(int index)
enum idDeclAF_Constraint::@49 limit
virtual bool Parse(const char *text, const int textLength)
const char * c_str(void) const
int SkipUntilString(const char *string)
const char * ToString(idStr &str, const int precision=8)
void Set(const float x, const float y)
void RenameBody(const char *oldName, const char *newName)
float defaultAngularFriction
bool WriteSlider(idFile *f, const idDeclAF_Constraint &c) const
bool RebuildTextSource(void)
const float * ToFloatPtr(void) const
void SetDefault(const idDeclAF *file)
static const char * JointModToString(declAFJointMod_t jointMod)
bool Finish(const char *fileName, const getJointTransform_t GetJointTransform, const idJointMat *frame, void *model) const
virtual void virtual void Warning(const char *fmt,...) id_attribute((format(printf
int ReadToken(idToken *token)
int sprintf(idStr &string, const char *fmt,...)
bool(* getJointTransform_t)(void *model, const idJointMat *frame, const char *jointName, idVec3 &origin, idMat3 &axis)
bool ParseSlider(idLexer &src)