00001
00002 #ifndef __FIELD_H__
00003 #define __FIELD_H__
00004
00005
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00019
00020 #ifndef _PSX
00021 #define MAX_FIELDS 128
00022 #else
00023 #define MAX_FIELDS 16
00024 #endif
00025
00026 #define FIELD_PARENT_NONE -1
00027
00028 enum {
00029 FIELD_PRIORITY_MAX = 0,
00030 FIELD_PRIORITY_MIN
00031 };
00032
00033
00034 typedef struct LinearParamsStruct {
00035 VEC Size;
00036 VEC Dir;
00037 REAL Mag;
00038 REAL Damping;
00039 } LINEAR_FIELD_PARAMS;
00040
00041 typedef struct LinearTwistParamsStruct {
00042 VEC Size;
00043 VEC Dir;
00044 REAL Mag;
00045 REAL Damping;
00046 VEC Torque;
00047 } LINEARTWIST_FIELD_PARAMS;
00048
00049 typedef struct VelocityParamsStruct {
00050 VEC Size;
00051 VEC Dir;
00052 REAL Mag;
00053 } VELOCITY_FIELD_PARAMS;
00054
00055 typedef struct SphericalParamsStruct {
00056 REAL RadStart, RadEnd;
00057 REAL GradStart, GradEnd;
00058 } SPHERICAL_FIELD_PARAMS;
00059
00060 typedef struct CylindricalParamsStruct {
00061 VEC Dir;
00062 REAL RadStart, RadEnd;
00063 REAL GradStart, GradEnd;
00064 } CYLINDRICAL_FIELD_PARAMS;
00065
00066 typedef struct OrientationParamsStruct {
00067 VEC Size;
00068 VEC Dir;
00069 REAL Mag;
00070 REAL Damping;
00071 } ORIENTATION_FIELD_PARAMS;
00072
00073 typedef struct LocalParamsStruct {
00074 VEC Size;
00075 VEC *DirPtr;
00076 REAL Mag;
00077 REAL Damping;
00078 } LOCAL_FIELD_PARAMS;
00079
00080 typedef struct VortexParamsStruct {
00081 VEC Size;
00082 VEC Dir;
00083 REAL Mag;
00084 REAL RMin;
00085 REAL RMax;
00086 } VORTEX_FIELD_PARAMS;
00087
00088 typedef struct FieldDataStruct {
00089 long ObjectID;
00090 long Priority;
00091 VEC *Pos;
00092 VEC *Vel;
00093 VEC *AngVel;
00094 MAT *Mat;
00095 QUATERNION *Quat;
00096 REAL Mass;
00097 } FIELD_DATA;
00098
00099 typedef struct ForceFieldStruct {
00100 long Status;
00101 long Type;
00102 long ParentID;
00103 long Priority;
00104
00105 VEC *PosPtr;
00106 MAT *MatPtr;
00107 BBOX BBox;
00108 union ForceFieldParamsUnion {
00109 LINEAR_FIELD_PARAMS LinearParams;
00110 LINEARTWIST_FIELD_PARAMS LinearTwistParams;
00111 LOCAL_FIELD_PARAMS LocalParams;
00112 VELOCITY_FIELD_PARAMS VelocityParams;
00113 SPHERICAL_FIELD_PARAMS SphericalParams;
00114 CYLINDRICAL_FIELD_PARAMS CylindricalParams;
00115 ORIENTATION_FIELD_PARAMS OrientationParams;
00116 VORTEX_FIELD_PARAMS VortexParams;
00117 } Params;
00118 bool (*FieldCollTest)(struct ForceFieldStruct *field, VEC *pos);
00119 void (*AddFieldImpulse)(struct ForceFieldStruct *field, FIELD_DATA *data, VEC *imp, VEC *angImp);
00120
00121 struct ForceFieldStruct *Prev;
00122 struct ForceFieldStruct *Next;
00123
00124 } FORCE_FIELD;
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136 #define FieldPriorityTest(fieldPriority, objectPriority) ((objectPriority) >= (fieldPriority))
00137
00138 #define FIELD_LINEAR 0
00139 #define FIELD_SPHERICAL 1
00140 #define FIELD_VELOCITY 2
00141 #define FIELD_ORIENTATION 4
00142 #define FIELD_VORTEX 8
00143 #define FIELD_LOCAL 16
00144 #define FIELD_LINEARTWIST 32
00145
00147
00148
00149
00151
00152 extern void FreeForceFields();
00153 extern void InitFields(void);
00154 extern void RemoveField(FORCE_FIELD *field);
00155 extern FORCE_FIELD *FirstField(void);
00156 extern FORCE_FIELD *NextField(FORCE_FIELD *field);
00157 extern void AllFieldImpulses(FIELD_DATA *data, VEC *imp, VEC *angImp);
00158
00159 extern FORCE_FIELD *AddLinearField(long parentID, long priority, VEC *posPtr, MAT *matPtr, BBOX *bBox, VEC *size, VEC *dir, REAL mag, REAL damping);
00160 extern bool LinearFieldCollTest(FORCE_FIELD *field, VEC *pos);
00161 extern void LinearFieldImpulse(FORCE_FIELD *field, FIELD_DATA *data, VEC *imp, VEC *angImp);
00162
00163 extern FORCE_FIELD *AddLinearTwistField(long parentID, long priority, VEC *posPtr, MAT *matPtr, BBOX *bBox, VEC *size, VEC *dir, REAL mag, VEC *torque, REAL damping);
00164 extern bool LinearTwistFieldCollTest(FORCE_FIELD *field, VEC *pos);
00165 extern void LinearTwistFieldImpulse(FORCE_FIELD *field, FIELD_DATA *data, VEC *imp, VEC *angImp);
00166
00167 extern FORCE_FIELD *AddLocalField(long parentID, long priority, VEC *posPtr, MAT *matPtr, BBOX *bBox, VEC *size, VEC *dir, REAL mag, REAL damping);
00168 extern bool LocalFieldCollTest(FORCE_FIELD *field, VEC *pos);
00169 extern void LocalFieldImpulse(FORCE_FIELD *field, FIELD_DATA *data, VEC *imp, VEC *angImp);
00170
00171 extern FORCE_FIELD *AddVelocityField(long parentID, long priority, VEC *posPtr, MAT *matPtr, BBOX *bBox, VEC *size, VEC *dir, REAL mag);
00172 extern bool VelocityFieldCollTest(FORCE_FIELD *field, VEC *pos);
00173 extern void VelocityFieldImpulse(FORCE_FIELD *field, FIELD_DATA *data, VEC *imp, VEC *angImp);
00174
00175 extern FORCE_FIELD *AddSphericalField(long parentID, long priority, VEC *posPtr, REAL rStart, REAL rEnd, REAL gStart, REAL gEnd);
00176 extern bool SphericalFieldCollTest(FORCE_FIELD *field, VEC *pos);
00177 extern void SphericalFieldImpulse(FORCE_FIELD *field, FIELD_DATA *data, VEC *imp, VEC *angImp);
00178
00179 extern FORCE_FIELD *AddCylindricalField(long parentID, long priority, VEC *posPtr, VEC *dir, REAL rStart, REAL rEnd, REAL gStart, REAL gEnd);
00180 extern bool CylindricalFieldCollTest(FORCE_FIELD *field, VEC *pos);
00181 extern void CylindricalFieldImpulse(FORCE_FIELD *field, FIELD_DATA *data, VEC *imp, VEC *angImp);
00182
00183 extern FORCE_FIELD *AddVortexField(long parentID, long priority, VEC *posPtr, MAT *matPtr, BBOX *bBox, VEC *size, VEC *dir, REAL mag, REAL rMin, REAL rMax);
00184 extern bool VortexFieldCollTest(FORCE_FIELD *field, VEC *pos);
00185 extern void VortexFieldImpulse(FORCE_FIELD *field, FIELD_DATA *data, VEC *imp, VEC *angImp);
00186
00187 extern FORCE_FIELD *AddOrientationField(long parentID, long priority, VEC *posPtr, MAT *matPtr, BBOX *bBox, VEC *size, VEC *dir, REAL mag, REAL damping);
00188 extern bool OrientationFieldCollTest(FORCE_FIELD *field, VEC *pos);
00189 extern void OrientationFieldImpulse(FORCE_FIELD *field, FIELD_DATA *data, VEC *imp, VEC *angImp);
00190
00191
00193
00194
00195
00197
00198 extern int FLD_NForceFields;
00199 extern REAL FLD_Gravity;
00200 extern BBOX FLD_GlobalBBox;
00201 extern VEC FLD_GlobalSize;
00202 extern FORCE_FIELD *FLD_GravityField;
00203 #endif