00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 struct V3Dphysics{
00043
00044 V3DPHYS_vWold ([F F F]);
00045 V3DPHYS_iFps (I);
00046 V3DPHYS_fGravity (F);
00047 V3DPHYS_iArchMode (I);
00048 V3DPHYS_iSolverMode (I);
00049 V3DPHYS_iFrictionMode (I);
00050
00051 V3DPHYS_iLastUpdate (I);
00052 V3DPHYS_bEnable (I
00053
00054 );
00055 };
00056 typedef struct mkV3Dphysics V3Dphysics;
00057
00058
00059 proto V3DphysCreateBodyShape=fun [V3Dsession SO3_OBJECT] SO3_PHYSICBODY;
00060 proto V3DphysCreateBodyEllipsoid=fun [V3Dsession SO3_OBJECT] SO3_PHYSICBODY;
00061 proto V3DphysCreateBodyCustomEllipsoid=fun [V3Dsession SO3_OBJECT [F F F]] SO3_PHYSICBODY;
00062 proto V3DphysCreateBodyBox=fun [V3Dsession SO3_OBJECT] SO3_PHYSICBODY;
00063 proto V3DphysCreateBodyCustomBox=fun [V3Dsession SO3_OBJECT [F F F]] SO3_PHYSICBODY;
00064 proto V3DphysCreateBodyCollisionTree=fun [V3Dsession SO3_OBJECT] SO3_PHYSICBODY;
00065
00066
00067
00068 V3DphysGetNodeBody(sessionstr, node){
00069 SO3SceneNodeGetBody (V3DgetSession sessionstr) node;
00070 }
00071
00072
00073 V3DphysGetBodyNode(sessionstr, body){
00074 SO3BodyGetSceneNode (V3DgetSession sessionstr) body;
00075 }
00076
00077
00078 V3DphysEnablePhysic(sessionstr, state){
00079 if (sessionstr.V3D_physics.V3DPHYS_bEnable == 1 && state == 1) then nil else
00080 (
00081 set sessionstr.V3D_physics.V3DPHYS_bEnable = state;
00082
00083 set sessionstr.V3D_physics.V3DPHYS_iLastUpdate = _tickcount;
00084 SO3WorldSetEnabled (V3DgetSession sessionstr) state;
00085 );
00086 0;
00087 }
00088
00089
00090 V3DphysGetState(sessionstr){
00091 sessionstr.V3D_physics.V3DPHYS_bEnable;
00092 }
00093
00094
00095 V3DphysSetWorld(sessionstr, vec){
00096 if vec == nil then nil else
00097 let vec -> [x y z] in
00098 (
00099 set sessionstr.V3D_physics.V3DPHYS_vWold = vec;
00100 SO3WorldSetSize (V3DgetSession sessionstr) [(-.x /. 2.0) (-.y /. 2.0) (-.z /. 2.0)] [(x /. 2.0) (y /. 2.0) (z /. 2.0)];
00101 );
00102 0;
00103 }
00104
00105
00106 V3DphysGetWorld(sessionstr){
00107 sessionstr.V3D_physics.V3DPHYS_vWold;
00108 }
00109
00110
00111 V3DphysSetFps(sessionstr, fps){
00112 if fps == nil then nil else
00113 (
00114 set sessionstr.V3D_physics.V3DPHYS_iFps = fps;
00115 SO3WorldSetFPS (V3DgetSession sessionstr) sessionstr.V3D_physics.V3DPHYS_iFps;
00116 );
00117 0;
00118 }
00119
00120
00121 V3DphysGetFps(sessionstr){
00122 sessionstr.V3D_physics.V3DPHYS_iFps;
00123 }
00124
00125
00126 V3DphysSetGravity(sessionstr, g){
00127 if g == nil then nil else
00128 (
00129 set sessionstr.V3D_physics.V3DPHYS_fGravity = g;
00130 SO3WorldSetGravity (V3DgetSession sessionstr) (-.(sessionstr.V3D_physics.V3DPHYS_fGravity *. (itof iGlobalUnit)));
00131 );
00132 0;
00133 }
00134
00135
00136 V3DphysGetGravity(sessionstr){
00137 sessionstr.V3D_physics.V3DPHYS_fGravity;
00138 }
00139
00140
00141 V3DphysSetArchitectureMode(sessionstr, mode){
00142 if mode == nil then nil else
00143 (
00144 set sessionstr.V3D_physics.V3DPHYS_iArchMode = mode;
00145 SO3WorldSetPlateformArchitecture (V3DgetSession sessionstr) sessionstr.V3D_physics.V3DPHYS_iArchMode;
00146 );
00147 0;
00148 }
00149
00150
00151 V3DphysGetArchitectureMode(sessionstr){
00152 sessionstr.V3D_physics.V3DPHYS_iArchMode;
00153 }
00154
00155
00156 V3DphysGetArchitectureModeName(sessionstr){
00157 let [SO3_PA_DEFAULT "default"]::[SO3_PA_MEDIUM "medium"]::[SO3_PA_BEST "best"]::nil -> l in
00158 switch l (V3DphysGetArchitectureMode sessionstr);
00159 }
00160
00161
00162 V3DphysSetArchitectureModeByName(sessionstr, smode){
00163 let ["default" SO3_PA_DEFAULT]::["medium" SO3_PA_MEDIUM]::["best" SO3_PA_BEST]::nil -> l in
00164 V3DphysSetArchitectureMode sessionstr (switchstr l smode);
00165 }
00166
00167
00168 V3DphysSetSolverMode(sessionstr, mode){
00169 if mode == nil then nil else
00170 (
00171 set sessionstr.V3D_physics.V3DPHYS_iSolverMode = mode;
00172 SO3WorldSetSolverModel (V3DgetSession sessionstr) sessionstr.V3D_physics.V3DPHYS_iSolverMode;
00173 );
00174 0;
00175 }
00176
00177
00178 V3DphysGetSolverMode(sessionstr){
00179 sessionstr.V3D_physics.V3DPHYS_iSolverMode;
00180 }
00181
00182
00183 V3DphysGetSolverModeName(sessionstr){
00184 let [SO3_SM_EXACT "exact"]::[SO3_SM_ADAPTATIVE "adaptative"]::nil -> l in
00185 switch l (V3DphysGetSolverMode sessionstr);
00186 }
00187
00188
00189 V3DphysSetSolverModeByName(sessionstr, smode){
00190 let ["exact" SO3_SM_EXACT]::["adaptative" SO3_SM_ADAPTATIVE]::nil -> l in
00191 V3DphysSetSolverMode sessionstr (switchstr l smode);
00192 }
00193
00194
00195 V3DphysSetFrictionMode(sessionstr, mode){
00196 if mode == nil then nil else
00197 (
00198 set sessionstr.V3D_physics.V3DPHYS_iFrictionMode = mode;
00199 SO3WorldSetFrictionModel (V3DgetSession sessionstr) sessionstr.V3D_physics.V3DPHYS_iFrictionMode;
00200 );
00201 0;
00202 }
00203
00204
00205 V3DphysGetFrictionMode(sessionstr){
00206 sessionstr.V3D_physics.V3DPHYS_iFrictionMode;
00207 }
00208
00209
00210 V3DphysGetFrictionModeName(sessionstr){
00211 let [SO3_FM_EXACT "exact"]::[SO3_FM_ADAPTATIVE "adaptative"]::nil -> l in
00212 switch l (V3DphysGetFrictionMode sessionstr);
00213 }
00214
00215
00216 V3DphysSetFrictionModeByName(sessionstr, smode){
00217 let ["exact" SO3_FM_EXACT]::["adaptative" SO3_FM_ADAPTATIVE]::nil -> l in
00218 V3DphysSetFrictionMode sessionstr (switchstr l smode);
00219 }
00220
00221
00222 V3DphysSetBodyMass(sessionstr, body, mass){
00223 SO3BodySetMass (V3DgetSession sessionstr) body mass;
00224 0;
00225 }
00226
00227
00228 V3DphysSetBodyLinearDamping(sessionstr, body, value){
00229 SO3BodySetLinearDamping (V3DgetSession sessionstr) body value;
00230 0;
00231 }
00232
00233
00234 V3DphysSetBodyAngularDamping(sessionstr, body, vec){
00235 SO3BodySetAngularDamping (V3DgetSession sessionstr) body vec;
00236 0;
00237 }
00238
00239
00240 V3DphysSetBodyContinuousCollision(sessionstr, body, mode){
00241 SO3BodySetContiniousCollisionMode (V3DgetSession sessionstr) body mode;
00242 0;
00243 }
00244
00245
00246 V3DphysSetBodyMaterial(sessionstr, body, matname){
00247 let if ((matname == nil) || (!strcmp "" (strtrim matname))) then "default" else matname -> matname in
00248 let SO3PhysicsGetMaterial (V3DgetSession sessionstr) matname -> mat in
00249 let if mat == nil then SO3PhysicsMaterialCreate (V3DgetSession sessionstr) matname else mat -> mat in
00250 (
00251 SO3BodySetMaterial (V3DgetSession sessionstr) body mat;
00252 mat;
00253 );
00254 }
00255
00256
00257 V3DphysCreateMaterialOnNode(sessionstr, node){
00258 let SO3ObjectGetName (V3DgetSession sessionstr) node -> name in
00259 let V3DphysGetNodeBody sessionstr node -> body in
00260 if (body == nil) then nil else
00261 let SO3PhysicsMaterialCreate (V3DgetSession sessionstr) strcat name "_physmat" -> mat in
00262 (
00263 SO3BodySetMaterial (V3DgetSession sessionstr) body mat;
00264 mat;
00265 );
00266 }
00267
00268
00269 V3DphysCreateBodyShape(sessionstr, node){
00270 let V3DphysGetNodeBody sessionstr node -> body in
00271 (
00272 if body == nil then nil else
00273 SO3BodyDestroy (V3DgetSession sessionstr) body;
00274
00275 SO3BodyCreateShape (V3DgetSession sessionstr) node;
00276 );
00277 }
00278
00279
00280 V3DphysCreateBodyEllipsoid(sessionstr, node){
00281 let V3DphysGetNodeBody sessionstr node -> body in
00282 (
00283 if body == nil then nil else
00284 SO3BodyDestroy (V3DgetSession sessionstr) body;
00285
00286 let SO3ObjectGetBoundingBoxInfo (V3DgetSession sessionstr) node -> [[sx sy sz] _ _] in
00287 SO3BodyCreateEllipsoid (V3DgetSession sessionstr) node [sx/.2.0 sy/.2.0 sz/.2.0];
00288 );
00289 }
00290
00291
00292 V3DphysCreateBodyCustomEllipsoid(sessionstr, node, vec){
00293 let V3DphysGetNodeBody sessionstr node -> body in
00294 (
00295 if body == nil then nil else
00296 SO3BodyDestroy (V3DgetSession sessionstr) body;
00297
00298 SO3BodyCreateEllipsoid (V3DgetSession sessionstr) node vec;
00299 );
00300 }
00301
00302
00303 V3DphysCreateBodyBox(sessionstr, node){
00304 let V3DphysGetNodeBody sessionstr node -> body in
00305 (
00306 if body == nil then nil else
00307 SO3BodyDestroy (V3DgetSession sessionstr) body;
00308
00309 let SO3ObjectGetBoundingBoxInfo (V3DgetSession sessionstr) node -> [vec _ _] in
00310 SO3BodyCreateBox (V3DgetSession sessionstr) node vec;
00311 );
00312 }
00313
00314
00315 V3DphysCreateBodyCustomBox(sessionstr, node, vec){
00316 let V3DphysGetNodeBody sessionstr node -> body in
00317 (
00318 if body == nil then nil else
00319 SO3BodyDestroy (V3DgetSession sessionstr) body;
00320
00321 SO3BodyCreateBox (V3DgetSession sessionstr) node vec;
00322 );
00323 }
00324
00325
00326 V3DphysCreateBodyCollisionTree(sessionstr, node){
00327 let V3DphysGetNodeBody sessionstr node -> body in
00328 (
00329 if body == nil then nil else
00330 SO3BodyDestroy (V3DgetSession sessionstr) body;
00331
00332 SO3EntitySetCollisionTree (V3DgetSession sessionstr) node;
00333 );
00334 }
00335
00336
00337 V3DphysDestroyBody(sessionstr, node){
00338 let V3DphysGetNodeBody sessionstr node -> body in
00339 (
00340 if body == nil then nil else
00341 SO3BodyDestroy (V3DgetSession sessionstr) body;
00342 );
00343 }
00344
00345
00346 V3DphysSetMaterialProperties(material, bcoll, bcontcoll, staticfriction, kineticfriction, elasticity, softness){
00347 0;
00348 }
00349
00350
00351 V3DphysEnableBody(sessionstr, body, mode){
00352 let if !mode == 0 then 0 else 1 -> state in
00353 SO3BodySetFreeze (V3DgetSession sessionstr) body state;
00354 0;
00355 }
00356
00357
00358 V3DphysShowDebug(sessionstr, state){
00359 SO3WorldShowLines (V3DgetSession sessionstr) state;
00360 0;
00361 }
00362
00363
00364 V3DphysCreate(sessionstr){
00365 let mkV3Dphysics [nil nil nil nil nil nil nil nil] -> physstr in
00366
00367 (
00368 set sessionstr.V3D_physics = physstr;
00369
00370 V3DphysSetArchitectureMode sessionstr SO3_PA_DEFAULT;
00371 V3DphysSetSolverMode sessionstr SO3_SM_EXACT;
00372 V3DphysSetFrictionMode sessionstr SO3_FM_EXACT;
00373
00374 V3DphysSetWorld sessionstr [100000.0 100000.0 100000.0];
00375 V3DphysSetFps sessionstr 75;
00376 V3DphysSetGravity sessionstr 9.81;
00377 V3DphysEnablePhysic sessionstr 0;
00378 );
00379 0;
00380 }
00381
00382
00383 V3DphysDestroy(sessionstr){
00384 V3DphysEnablePhysic sessionstr 0;
00385 set sessionstr.V3D_physics = nil;
00386 0;
00387 }
00388
00389
00390 V3DphysReset(sessionstr){
00391 V3DphysDestroy sessionstr;
00392 V3DphysCreate sessionstr;
00393 0;
00394 }
00395
00396