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
00035
00036 #include "SO3SCOL.h"
00037
00038
00039 #include "../SO3PhysicGraph/SO3Body.h"
00040 #include "../SO3PhysicGraph/SO3MaterialID.h"
00041 #include "../SO3PhysicGraph/SO3MaterialPair.h"
00042
00043
00044 #include "../SO3Renderer/SO3Root.h"
00045
00046
00047 #include "../SO3SceneGraph/SO3Entity.h"
00048 #include "../SO3SceneGraph/SO3Scene.h"
00049
00050 int SO3_MATERIALPAIR_OVERLAP_STARTED_MSG;
00051 int SO3_MATERIALPAIR_OVERLAP_ENDED_MSG;
00052 int SO3_MATERIALPAIR_COLLISION_MSG;
00053 int SO3_BODY_LEAVE_WORLD_MSG;
00054
00066 int getBodyLeaveWorldCallback(mmachine m, WindowHandle h, unsigned msg, UINT id, LONG param, int* ret)
00067 {
00068 #ifdef SO3_DEBUG
00069 MMechostr(MSKDEBUG, "getBodyLeaveWorldCallback\n");
00070 #endif
00071
00072 int k , res;
00073 res = 0;
00074 if(!(k = OBJbeginreflex(m, SO3PHYSICBODY, id, SO3_BODY_LEAVE_WORLD)))
00075 res = OBJcallreflex(m, 0);
00076
00077 return res;
00078 }
00079
00091 int getMaterialContactCallback(mmachine m, int id, MCOLL * result)
00092 {
00093 #ifdef SO3_DEBUG
00094 MMechostr(MSKDEBUG, "getMaterialContactCallback\n");
00095 #endif
00096
00097 int obj, res;
00098 res = 0;
00099
00100 SNode* node0 = result->curScene->GetNode(result->node0);
00101 SNode* node1 = result->curScene->GetNode(result->node1);
00102
00103 if ((node0 == 0) || (node1 == 0))
00104 return 0;
00105
00106
00107
00108 obj = OBJfindTH(m, SO3PHYSICSMATERIALPAIR, id);
00109 if (obj == NIL)
00110 return -1;
00111
00112 if (MMfetch(m, obj, OFFOBJREF0+SO3_MATERIALPAIR_COLLISION*2)==NIL)
00113 return -1;
00114
00115
00116 int s = MMfetch(m, OBJfindTH(m, SO3SCENETYPE, (int)(result->curScene)), OFFOBJMAG);
00117
00118
00119 MMsetglobal(m, OFFSCCUR, MMfetch(m, obj, OFFOBJCHN));
00120 if (MMpush(m, MMgetglobal(m, OFFSCCUR))) return MERRMEM;
00121 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0+SO3_MATERIALPAIR_COLLISION*2))) return MERRMEM;
00122 if (MMpush(m, s)) return MERRMEM;
00123 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0+SO3_MATERIALPAIR_COLLISION*2+1))) return MERRMEM;
00124
00125 if(node0->getSceneNodeBody()==NULL)
00126 {
00127 MMpush(m, NIL);
00128 MMpush(m, NIL);
00129 MMpush(m, NIL);
00130 return 0;
00131 }
00132 if(node1->getSceneNodeBody()==NULL)
00133 {
00134 MMpush(m, NIL);
00135 MMpush(m, NIL);
00136 MMpush(m, NIL);
00137 return 0;
00138 }
00139
00140 int b0 = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node0->getSceneNodeBody())), OFFOBJMAG);
00141 int b1 = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node1->getSceneNodeBody())), OFFOBJMAG);
00142
00143 MMpush(m, b0);
00144 MMpush(m, b1);
00145
00146 int pos = MMmalloc(m, 3, TYPETAB);
00147 if(pos==NIL)
00148 {
00149 MMset(m,0,NIL);
00150 return MERRMEM;
00151 }
00152
00153 MMstore(m, pos, 0, FTOM(result->position.x));
00154 MMstore(m, pos, 1, FTOM(result->position.y));
00155 MMstore(m, pos, 2, FTOM(result->position.z));
00156
00157 MMpush(m, PTOM(pos));
00158
00159 int norm = MMmalloc(m, 3, TYPETAB);
00160 if(norm==NIL)
00161 {
00162 MMset(m, 0, NIL);
00163 return MERRMEM;
00164 }
00165
00166 MMstore(m, norm, 0, FTOM(result->normal.x));
00167 MMstore(m, norm, 1, FTOM(result->normal.y));
00168 MMstore(m, norm, 2, FTOM(result->normal.z));
00169 MMpush(m, PTOM(norm));
00170
00171 int force = MMmalloc(m, 3, TYPETAB);
00172 if(force==NIL)
00173 {
00174 MMset(m, 0, NIL);
00175 return MERRMEM;
00176 }
00177
00178 MMstore(m, force, 0, FTOM(result->force.x));
00179 MMstore(m, force, 1, FTOM(result->force.y));
00180 MMstore(m, force, 2, FTOM(result->force.z));
00181 MMpush(m, PTOM(force));
00182 MMpush(m, FTOM(result->normalspeed));
00183
00184 res = OBJcallreflex(m, 6);
00185 return res;
00186 }
00187
00188
00200 int getMaterialOverlapStartedCallback(mmachine m, int id, MCOLL * result)
00201 {
00202 #ifdef SO3_DEBUG
00203 MMechostr(MSKDEBUG, "getMaterialOverlapStartedCallback\n");
00204 #endif
00205
00206 int obj, res;
00207
00208 SNode* node0 = result->curScene->GetNode(result->node0);
00209 SNode* node1 = result->curScene->GetNode(result->node1);
00210
00211 if ((node0 == 0) || (node1 == 0))
00212 return 0;
00213
00214
00215
00216 obj = OBJfindTH(m, SO3PHYSICSMATERIALPAIR, id);
00217 if (obj == NIL)
00218 return -1;
00219
00220 if (MMfetch(m, obj, OFFOBJREF0+SO3_MATERIALPAIR_OVERLAP_STARTED*2)==NIL)
00221 return -1;
00222
00223
00224 int s = MMfetch(m, OBJfindTH(m, SO3SCENETYPE, (int)(result->curScene)), OFFOBJMAG);
00225
00226
00227 MMsetglobal(m, OFFSCCUR, MMfetch(m, obj, OFFOBJCHN));
00228 if (MMpush(m, MMgetglobal(m, OFFSCCUR))) return MERRMEM;
00229 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0+SO3_MATERIALPAIR_OVERLAP_STARTED*2))) return MERRMEM;
00230 if (MMpush(m, s)) return MERRMEM;
00231 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0+SO3_MATERIALPAIR_OVERLAP_STARTED*2+1))) return MERRMEM;
00232
00233 if(node0->getSceneNodeBody()==NULL)
00234 {
00235 MMpush(m, NIL);
00236 MMpush(m, NIL);
00237 MMpush(m, NIL);
00238 return 0;
00239 }
00240 if(node1->getSceneNodeBody()==NULL)
00241 {
00242 MMpush(m, NIL);
00243 MMpush(m, NIL);
00244 MMpush(m, NIL);
00245 return 0;
00246 }
00247 int b0 = 0;
00248 int b1 = 0;
00249
00250 b0 = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node0->getSceneNodeBody())), OFFOBJMAG);
00251 b1 = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node1->getSceneNodeBody())), OFFOBJMAG);
00252
00253 MMpush(m, b0);
00254 MMpush(m, b1);
00255
00256 res = OBJcallreflex(m, 2);
00257 return res;
00258 }
00259
00260
00272 int getMaterialOverlapEndedCallback(mmachine m, int id, MCOLL * result)
00273 {
00274 #ifdef SO3_DEBUG
00275 MMechostr(MSKDEBUG, "getMaterialOverlapEndedCallback\n");
00276 #endif
00277
00278 int obj, res;
00279
00280 SNode* node0 = result->curScene->GetNode(result->node0);
00281 SNode* node1 = result->curScene->GetNode(result->node1);
00282
00283 if ((node0 == 0) || (node1 == 0))
00284 return 0;
00285
00286
00287
00288 obj = OBJfindTH(m, SO3PHYSICSMATERIALPAIR, id);
00289 if (obj == NIL)
00290 return -1;
00291
00292 if (MMfetch(m, obj, OFFOBJREF0+SO3_MATERIALPAIR_OVERLAP_ENDED*2)==NIL)
00293 return -1;
00294
00295
00296 int s = MMfetch(m, OBJfindTH(m, SO3SCENETYPE, (int)(result->curScene)), OFFOBJMAG);
00297
00298
00299 MMsetglobal(m, OFFSCCUR, MMfetch(m, obj, OFFOBJCHN));
00300 if (MMpush(m, MMgetglobal(m, OFFSCCUR))) return MERRMEM;
00301 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0+SO3_MATERIALPAIR_OVERLAP_ENDED*2))) return MERRMEM;
00302 if (MMpush(m, s)) return MERRMEM;
00303 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0+SO3_MATERIALPAIR_OVERLAP_ENDED*2+1))) return MERRMEM;
00304
00305 if(node0->getSceneNodeBody()==NULL)
00306 {
00307 MMpush(m, NIL);
00308 MMpush(m, NIL);
00309 MMpush(m, NIL);
00310 return 0;
00311 }
00312 if(node1->getSceneNodeBody()==NULL)
00313 {
00314 MMpush(m, NIL);
00315 MMpush(m, NIL);
00316 MMpush(m, NIL);
00317 return 0;
00318 }
00319 int b0 = 0;
00320 int b1 = 0;
00321
00322 b0 = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node0->getSceneNodeBody())), OFFOBJMAG);
00323 b1 = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node1->getSceneNodeBody())), OFFOBJMAG);
00324
00325 MMpush(m, b0);
00326 MMpush(m, b1);
00327
00328 res = OBJcallreflex(m, 2);
00329 return res;
00330 }
00331
00332
00346 int SO3WorldSetFrictionModel(mmachine m)
00347 {
00348 #ifdef SO3_DEBUG
00349 MMechostr(MSKDEBUG, "SO3WorldSetFrictionModel\n");
00350 #endif
00351
00352 int mod = MTOI(MMpull(m));
00353 int s = MMget(m, 0);
00354 if(s==NIL)
00355 {
00356 MMset(m, 0, NIL);
00357 return 0;
00358 }
00359
00360 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00361 if(scene==NULL)
00362 {
00363 MMset(m, 0, NIL);
00364 return 0;
00365 }
00366 try
00367 {
00368 scene->GetPhysicsWorld()->SetPhysicFrictionModel(mod);
00369 MMset(m, 0, ITOM(1));
00370 return 0;
00371 }
00372 catch(Ogre::Exception& e)
00373 {
00374 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
00375 MMset(m, 0, NIL);
00376 return 0;
00377 }
00378 }
00379
00380
00393 int SO3WorldGetFrictionModel(mmachine m)
00394 {
00395 #ifdef SO3_DEBUG
00396 MMechostr(MSKDEBUG, "SO3WorldGetFrictionModel\n");
00397 #endif
00398
00399 int s = MMget(m, 0);
00400 if(s==NIL)
00401 {
00402 MMset(m, 0, NIL);
00403 return 0;
00404 }
00405
00406 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00407 if(scene==NULL)
00408 {
00409 MMset(m, 0, NIL);
00410 return 0;
00411 }
00412 try
00413 {
00414 MMset(m, 0, ITOM(scene->GetPhysicsWorld()->GetPhysicFrictionModel()));
00415 return 0;
00416 }
00417 catch(Ogre::Exception& e)
00418 {
00419 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
00420 MMset(m, 0, NIL);
00421 return 0;
00422 }
00423 }
00424
00425
00440 int SO3WorldSetPlateformArchitecture(mmachine m)
00441 {
00442 #ifdef SO3_DEBUG
00443 MMechostr(MSKDEBUG, "SO3WorldSetPlateformArchitecture\n");
00444 #endif
00445
00446 int mod = MTOI(MMpull(m));
00447 int s = MMget(m, 0);
00448 if(s==NIL)
00449 {
00450 MMset(m, 0, NIL);
00451 return 0;
00452 }
00453
00454 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00455 if(scene==NULL)
00456 {
00457 MMset(m, 0, NIL);
00458 return 0;
00459 }
00460 try
00461 {
00462 scene->GetPhysicsWorld()->SetPhysicPlatformArchitecture(mod);
00463 MMset(m, 0, ITOM(1));
00464 return 0;
00465 }
00466 catch(Ogre::Exception& e)
00467 {
00468 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
00469 MMset(m, 0, NIL);
00470 return 0;
00471 }
00472 }
00473
00474
00488 int SO3WorldGetPlateformArchitecture(mmachine m)
00489 {
00490 #ifdef SO3_DEBUG
00491 MMechostr(MSKDEBUG, "SO3WorldGetPlateformArchitecture\n");
00492 #endif
00493
00494 int s = MMget(m, 0);
00495 if(s==NIL)
00496 {
00497 MMset(m, 0, NIL);
00498 return 0;
00499 }
00500
00501 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00502 if(scene==NULL)
00503 {
00504 MMset(m, 0, NIL);
00505 return 0;
00506 }
00507 try
00508 {
00509 MMset(m, 0, ITOM(scene->GetPhysicsWorld()->GetPhysicPlatformArchitecture()));
00510 return 0;
00511 }
00512 catch(Ogre::Exception& e)
00513 {
00514 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
00515 MMset(m, 0, NIL);
00516 return 0;
00517 }
00518 }
00519
00520
00534 int SO3WorldSetSolverModel(mmachine m)
00535 {
00536 #ifdef SO3_DEBUG
00537 MMechostr(MSKDEBUG, "SO3WorldSetSolverModel\n");
00538 #endif
00539
00540 int mod = MTOI(MMpull(m));
00541 int s = MMget(m, 0);
00542 if(s==NIL)
00543 {
00544 MMset(m, 0, NIL);
00545 return 0;
00546 }
00547
00548 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00549 if(scene==NULL)
00550 {
00551 MMset(m, 0, NIL);
00552 return 0;
00553 }
00554 try
00555 {
00556 scene->GetPhysicsWorld()->SetPhysicSolverModel(mod);
00557 MMset(m, 0, ITOM(1));
00558 return 0;
00559 }
00560 catch(Ogre::Exception& e)
00561 {
00562 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
00563 MMset(m, 0, NIL);
00564 return 0;
00565 }
00566 }
00567
00568
00581 int SO3WorldGetSolverModel(mmachine m)
00582 {
00583 #ifdef SO3_DEBUG
00584 MMechostr(MSKDEBUG, "SO3WorldGetSolverModel\n");
00585 #endif
00586
00587 int s = MMget(m,0);
00588 if(s==NIL)
00589 {
00590 MMset(m, 0, NIL);
00591 return 0;
00592 }
00593 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00594 if(scene==NULL)
00595 {
00596 MMset(m, 0, NIL);
00597 return 0;
00598 }
00599 try
00600 {
00601 MMset(m, 0, ITOM(scene->GetPhysicsWorld()->GetPhysicSolverModel()));
00602 return 0;
00603 }
00604 catch(Ogre::Exception& e)
00605 {
00606 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
00607 MMset(m, 0, NIL);
00608 return 0;
00609 }
00610 }
00611
00612
00622 int SO3WorldSetEnabled(mmachine m)
00623 {
00624 #ifdef SO3_DEBUG
00625 MMechostr(MSKDEBUG, "SO3WorldSetEnabled\n");
00626 #endif
00627
00628 int booleen = MTOI(MMpull(m));
00629 int s = MMget(m, 0);
00630
00631 if (s==NIL)
00632 {
00633 MMset(m, 0, NIL);
00634 return 0;
00635 }
00636
00637 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00638 if (scene==NULL)
00639 {
00640 MMset(m, 0, NIL);
00641 return 0;
00642 }
00643
00644 try
00645 {
00646 if(booleen == 0)
00647 {
00648 bool bLastState = scene->GetPhysicsWorld()->GetPhysicWorldEnable();
00649 scene->GetPhysicsWorld()->SetPhysicWorldEnable(false);
00650 }
00651 else
00652 {
00653 #ifdef SCOL_DEBUG
00654 MMechostr(MSKDEBUG, " > World is Set To Enable\n");
00655 #endif
00656
00657 scene->GetPhysicsWorld()->SetPhysicWorldEnable(true);
00658 }
00659
00660 MMset(m, 0, ITOM(1));
00661 return 0;
00662 }
00663 catch(Ogre::Exception& e)
00664 {
00665 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
00666 MMset(m, 0, NIL);
00667 return 0;
00668 }
00669 }
00670
00671
00680 int SO3WorldGetEnabled(mmachine m)
00681 {
00682 #ifdef SO3_DEBUG
00683 MMechostr(MSKDEBUG, "SO3WorldGetEnabled\n");
00684 #endif
00685
00686 int s = MMget(m, 0);
00687 if (s==NIL)
00688 {
00689 MMset(m, 0, NIL);
00690 return 0;
00691 }
00692
00693 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00694 if (scene==NULL)
00695 {
00696 MMset(m, 0, NIL);
00697 return 0;
00698 }
00699
00700 int val = 0;
00701 if(scene->GetPhysicsWorld()->GetPhysicWorldEnable())
00702 val = 1;
00703
00704 MMset(m, 0, ITOM(val));
00705 return 0;
00706 }
00707
00716 int SO3WorldReset(mmachine m)
00717 {
00718 #ifdef SO3_DEBUG
00719 MMechostr(MSKDEBUG, "SO3WorldReset\n");
00720 #endif
00721
00722 int s = MMget(m, 0);
00723 if (s==NIL)
00724 {
00725 MMset(m, 0, NIL);
00726 return 0;
00727 }
00728
00729 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00730 if (scene==NULL)
00731 {
00732 MMset(m, 0, NIL);
00733 return 0;
00734 }
00735
00736 scene->GetPhysicsWorld()->ResetPhysicWorld();
00737
00738 MMset(m, 0, ITOM(1));
00739 return 0;
00740 }
00741
00750 int SO3WorldSetBodiesInitialState(mmachine m)
00751 {
00752 #ifdef SO3_DEBUG
00753 MMechostr(MSKDEBUG, "SO3WorldSetBodiesInitialState\n");
00754 #endif
00755
00756 int s = MMget(m, 0);
00757 if (s==NIL)
00758 {
00759 MMset(m, 0, NIL);
00760 return 0;
00761 }
00762
00763 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00764 if (scene==NULL)
00765 {
00766 MMset(m, 0, NIL);
00767 return 0;
00768 }
00769
00770 scene->GetPhysicsWorld()->SetPhysicBodiesInitialState();
00771
00772 MMset(m, 0, ITOM(1));
00773 return 0;
00774 }
00775
00785 int SO3WorldShowLines(mmachine m)
00786 {
00787 #ifdef SO3_DEBUG
00788 MMechostr(MSKDEBUG, "SO3WorldShowLines\n");
00789 #endif
00790
00791 int booleen = MTOI(MMpull(m));
00792 int s = MMget(m, 0);
00793 if (s==NIL)
00794 {
00795 MMset(m, 0, NIL);
00796 return 0;
00797 }
00798
00799 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00800 if (scene==NULL)
00801 {
00802 MMset(m, 0, NIL);
00803 return 0;
00804 }
00805
00806 if(booleen == 1)
00807 scene->GetPhysicsWorld()->SetPhysicDebugEnable(true);
00808 else
00809 scene->GetPhysicsWorld()->SetPhysicDebugEnable(false);
00810
00811 MMset(m, 0, ITOM(1));
00812 return 0;
00813 }
00814
00815
00825 int SO3WorldSetGravity(mmachine m)
00826 {
00827 #ifdef SO3_DEBUG
00828 MMechostr(MSKDEBUG, "SO3WorldSetGravity\n");
00829 #endif
00830
00831 int vec = MTOP(MMpull(m));
00832 int s = MMget(m, 0);
00833 if((s==NIL) || (vec == NIL))
00834 {
00835 MMset(m, 0, NIL);
00836 return 0;
00837 }
00838
00839 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00840 if(scene==NULL)
00841 {
00842 MMset(m, 0, NIL);
00843 return 0;
00844 }
00845
00846 int x = MMfetch(m, vec, 0);
00847 int y = MMfetch(m, vec, 1);
00848 int z = MMfetch(m, vec, 2);
00849
00850 if((x==NIL) || (y==NIL) || (z==NIL))
00851 {
00852 MMset(m, 0, NIL);
00853 return 0;
00854 }
00855
00856 Ogre::Vector3 vgravity = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
00857
00858 try
00859 {
00860 scene->GetPhysicsWorld()->SetPhysicGravity(vgravity);
00861 MMset(m, 0, ITOM(1));
00862 return 0;
00863 }
00864 catch(Ogre::Exception& e)
00865 {
00866 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
00867 MMset(m, 0, NIL);
00868 return 0;
00869 }
00870 }
00871
00880 int SO3WorldGetGravity(mmachine m)
00881 {
00882 #ifdef SO3_DEBUG
00883 MMechostr(MSKDEBUG, "SO3WorldGetGravity\n");
00884 #endif
00885
00886 int s = MMget(m, 0);
00887 if(s==NIL)
00888 {
00889 MMset(m, 0, NIL);
00890 return 0;
00891 }
00892
00893 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
00894 if(scene==NULL)
00895 {
00896 MMset(m, 0, NIL);
00897 return 0;
00898 }
00899
00900 Ogre::Vector3 vec = scene->GetPhysicsWorld()->GetPhysicGravity();
00901
00902 int tuple = MMmalloc(m, 3, TYPETAB);
00903 if(tuple==NIL)
00904 {
00905 MMset(m, 0, NIL);
00906 return MERRMEM;
00907 }
00908
00909 MMstore(m, tuple, 0, FTOM((vec.x)));
00910 MMstore(m, tuple, 1, FTOM((vec.y)));
00911 MMstore(m, tuple, 2, FTOM((vec.z)));
00912 MMset(m, 0, PTOM(tuple));
00913
00914 return 0;
00915 }
00916
00917
00927 int SO3BodyCreateBox(mmachine m)
00928 {
00929 #ifdef SO3_DEBUG
00930 MMechostr(MSKDEBUG, "SO3BodyCreateBox\n");
00931 #endif
00932
00933 int vec = MTOP(MMpull(m));
00934 int n = MMget(m, 0);
00935 if(n==NIL || vec == NIL)
00936 {
00937 MMset(m, 0, NIL);
00938 return 0;
00939 }
00940
00941 SNode* node = (SNode*) MMfetch(m, MTOP(n), 0);
00942 if(node==NULL)
00943 {
00944 MMset(m, 0, NIL);
00945 return 0;
00946 }
00947
00948
00949 if(node->getSceneNodeBody()!=NULL)
00950 {
00951 int b = 0;
00952 b = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node->getSceneNodeBody())), OFFOBJMAG);
00953 OBJdelTM(m, SO3PHYSICBODY, b);
00954 }
00955
00956 int x = MMfetch(m, vec, 0);
00957 int y = MMfetch(m, vec, 1);
00958 int z = MMfetch(m, vec, 2);
00959
00960 if((x==NIL) || (y==NIL) || (z==NIL))
00961 {
00962 MMset(m, 0, NIL);
00963 return 0;
00964 }
00965
00966 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
00967
00968 SBody* body = 0;
00969 try
00970 {
00971 body = node->CreateBoxBody(vecteur);
00972 }
00973 catch(Ogre::Exception& e)
00974 {
00975 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
00976 }
00977
00978 if (body == 0)
00979 {
00980 MMset(m, 0, NIL);
00981 return 0;
00982 }
00983
00984
00985 MMpull(m);
00986 return createBody(m, node);
00987 }
00988
00989
00999 int SO3BodyCreateEllipsoid(mmachine m)
01000 {
01001 #ifdef SO3_DEBUG
01002 MMechostr(MSKDEBUG, "SO3BodyCreateEllipsoid\n");
01003 #endif
01004
01005 int vec = MTOP(MMpull(m));
01006 int n = MMget(m, 0);
01007 if(n==NIL)
01008 {
01009 MMset(m, 0, NIL);
01010 return 0;
01011 }
01012
01013 SNode* node = (SNode*) MMfetch(m, MTOP(n), 0);
01014 if(node==NULL)
01015 {
01016 MMset(m, 0, NIL);
01017 return 0;
01018 }
01019
01020
01021 if(node->getSceneNodeBody()!=NULL)
01022 {
01023 int b = 0;
01024 b = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node->getSceneNodeBody())), OFFOBJMAG);
01025 OBJdelTM(m, SO3PHYSICBODY, b);
01026 }
01027
01028 int x = MMfetch(m, vec, 0);
01029 int y = MMfetch(m, vec, 1);
01030 int z = MMfetch(m, vec, 2);
01031
01032 if((x==NIL) || (y==NIL) || (z==NIL))
01033 {
01034 MMset(m, 0, NIL);
01035 return 0;
01036 }
01037
01038 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
01039
01040 SBody* body = 0;
01041 try
01042 {
01043 body = node->CreateEllipsoidBody(vecteur);
01044 }
01045 catch(Ogre::Exception& e)
01046 {
01047 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
01048 }
01049
01050 if (body == 0)
01051 {
01052 MMset(m, 0, NIL);
01053 return 0;
01054 }
01055
01056
01057 MMpull(m);
01058 return createBody(m, node);
01059 }
01060
01061
01072 int SO3BodyCreateCapsule(mmachine m)
01073 {
01074 #ifdef SO3_DEBUG
01075 MMechostr(MSKDEBUG, "SO3BodyCreateCapsule\n");
01076 #endif
01077
01078 int h = MMpull(m);
01079 int rad = MMpull(m);
01080 int n = MMget(m, 0);
01081 if((n==NIL)||(h==NIL)||(rad==NIL))
01082 {
01083 MMset(m, 0, NIL);
01084 return 0;
01085 }
01086
01087 SNode* node = (SNode*) MMfetch(m, MTOP(n), 0);
01088 if(node==NULL)
01089 {
01090 MMset(m, 0, NIL);
01091 return 0;
01092 }
01093
01094
01095 if(node->getSceneNodeBody()!=NULL)
01096 {
01097 int b = 0;
01098 b = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node->getSceneNodeBody())), OFFOBJMAG);
01099 OBJdelTM(m, SO3PHYSICBODY, b);
01100 }
01101
01102
01103 SBody* body = 0;
01104 try
01105 {
01106 body = node->CreateCapsuleBody(MTOF(rad), MTOF(h));
01107 }
01108 catch(Ogre::Exception& e)
01109 {
01110 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
01111 }
01112
01113 if (body == 0)
01114 {
01115 MMset(m, 0, NIL);
01116 return 0;
01117 }
01118
01119
01120 MMpull(m);
01121 return createBody(m, node);
01122 }
01123
01124
01135 int SO3BodyCreateChamferCylinder(mmachine m)
01136 {
01137 #ifdef SO3_DEBUG
01138 MMechostr(MSKDEBUG, "SO3BodyCreateChamferCylinder\n");
01139 #endif
01140
01141 int h = MMget(m, 0);
01142 int rad = MMpull(m);
01143 int n = MMpull(m);
01144 if((n==NIL)||(h==NIL)||(rad==NIL))
01145 {
01146 MMset(m, 0, NIL);
01147 return 0;
01148 }
01149
01150 SNode* node = (SNode*) MMfetch(m, MTOP(n), 0);
01151 if(node==NULL)
01152 {
01153 MMset(m, 0, NIL);
01154 return 0;
01155 }
01156
01157
01158 if(node->getSceneNodeBody()!=NULL)
01159 {
01160 int b = 0;
01161 b = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node->getSceneNodeBody())), OFFOBJMAG);
01162 OBJdelTM(m, SO3PHYSICBODY, b);
01163 }
01164
01165
01166 SBody* body = 0;
01167
01168 try
01169 {
01170 body = node->CreateChamferCylinderBody(MTOF(rad), MTOF(h));
01171 }
01172 catch(Ogre::Exception& e)
01173 {
01174 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
01175 }
01176
01177 if (body == 0)
01178 {
01179 MMset(m, 0, NIL);
01180 return 0;
01181 }
01182
01183
01184 MMpull(m);
01185 return createBody(m, node);
01186 }
01187
01188
01199 int SO3BodyCreateCone(mmachine m)
01200 {
01201 #ifdef SO3_DEBUG
01202 MMechostr(MSKDEBUG, "SO3BodyCreateCone\n");
01203 #endif
01204
01205 int h = MMpull(m);
01206 int rad = MMpull(m);
01207 int n = MMget(m, 0);
01208
01209 if((n==NIL)||(h==NIL)||(rad==NIL))
01210 {
01211 MMset(m, 0, NIL);
01212 return 0;
01213 }
01214
01215 SNode* node = (SNode*) MMfetch(m,MTOP(n),0);
01216 if(node==NULL)
01217 {
01218 MMset(m, 0, NIL);
01219 return 0;
01220 }
01221
01222
01223 if(node->getSceneNodeBody()!=NULL)
01224 {
01225 int b = 0;
01226 b = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node->getSceneNodeBody())), OFFOBJMAG);
01227 OBJdelTM(m, SO3PHYSICBODY, b);
01228 }
01229
01230
01231 SBody* body = 0;
01232 try
01233 {
01234 body = node->CreateConeBody(MTOF(rad), MTOF(h));
01235 }
01236 catch(Ogre::Exception& e)
01237 {
01238 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
01239 }
01240
01241 if (body == 0)
01242 {
01243 MMset(m, 0, NIL);
01244 return 0;
01245 }
01246
01247
01248 MMpull(m);
01249 return createBody(m, node);
01250 }
01251
01252
01263 int SO3BodyCreateCylinder(mmachine m)
01264 {
01265 #ifdef SO3_DEBUG
01266 MMechostr(MSKDEBUG, "SO3BodyCreateCylinder\n");
01267 #endif
01268
01269 int h = MMpull(m);
01270 int rad = MMpull(m);
01271 int n = MMget(m, 0);
01272 if((n==NIL)||(h==NIL)||(rad==NIL))
01273 {
01274 MMset(m, 0, NIL);
01275 return 0;
01276 }
01277
01278 SNode* node = (SNode*) MMfetch(m, MTOP(n), 0);
01279 if(node==NULL)
01280 {
01281 MMset(m, 0, NIL);
01282 return 0;
01283 }
01284
01285
01286 if(node->getSceneNodeBody()!=NULL)
01287 {
01288 int b = 0;
01289 b = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node->getSceneNodeBody())), OFFOBJMAG);
01290 OBJdelTM(m, SO3PHYSICBODY, b);
01291 }
01292
01293
01294 SBody* body = 0;
01295 try
01296 {
01297 body = node->CreateCylinderBody(MTOF(rad), MTOF(h));
01298 }
01299 catch(Ogre::Exception& e)
01300 {
01301 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
01302 }
01303
01304 if (body == 0)
01305 {
01306 MMset(m, 0, NIL);
01307 return 0;
01308 }
01309
01310
01311 MMpull(m);
01312 return createBody(m, node);
01313 }
01314
01315
01325 int SO3BodyCreatePyramid(mmachine m)
01326 {
01327 #ifdef SO3_DEBUG
01328 MMechostr(MSKDEBUG, "SO3BodyCreatePyramid\n");
01329 #endif
01330
01331 int vec = MTOP(MMpull(m));
01332 int n = MMget(m, 0);
01333 if((n==NIL))
01334 {
01335 MMset(m, 0, NIL);
01336 return 0;
01337 }
01338
01339 SNode* node = (SNode*) MMfetch(m, MTOP(n), 0);
01340 if(node==NULL)
01341 {
01342 MMset(m, 0, NIL);
01343 return 0;
01344 }
01345
01346
01347
01348 if(node->getSceneNodeBody()!=NULL)
01349 {
01350 int b = 0;
01351 b = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node->getSceneNodeBody())), OFFOBJMAG);
01352 OBJdelTM(m, SO3PHYSICBODY, b);
01353 }
01354
01355 int x = MMfetch(m, vec, 0);
01356 int y = MMfetch(m, vec, 1);
01357 int z = MMfetch(m, vec, 2);
01358
01359 if((x==NIL) || (y==NIL) || (z==NIL))
01360 {
01361 MMset(m, 0, NIL);
01362 return 0;
01363 }
01364
01365 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
01366
01367 SBody* body = 0;
01368 try
01369 {
01370 body = node->CreatePyramidBody(vecteur);
01371 }
01372 catch(Ogre::Exception& e)
01373 {
01374 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
01375 }
01376
01377 if (body == 0)
01378 {
01379 MMset(m, 0, NIL);
01380 return 0;
01381 }
01382
01383
01384 MMpull(m);
01385 return createBody(m, node);
01386 }
01387
01388
01398 int SO3BodyCreateCollisionTree(mmachine m)
01399 {
01400 #ifdef SO3_DEBUG
01401 MMechostr(MSKDEBUG, "SO3BodyCreateCollisionTree\n");
01402 #endif
01403
01404 int opti = MMpull(m);
01405 int n = MMget(m, 0);
01406 if (n==NIL)
01407 {
01408 MMset(m, 0, NIL);
01409 return 0;
01410 }
01411
01412 SNode* node = (SNode*) MMfetch(m, MTOP(n), 0);
01413 if(node==NULL)
01414 {
01415 MMset(m, 0, NIL);
01416 return 0;
01417 }
01418
01419 bool optimize = false;
01420 if (MTOI(opti) == 1)
01421 bool optimize = true;
01422
01423
01424 if(node->getSceneNodeBody()!=NULL)
01425 {
01426 int b = 0;
01427 b = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node->getSceneNodeBody())), OFFOBJMAG);
01428 OBJdelTM(m, SO3PHYSICBODY, b);
01429 }
01430
01431
01432 SBody* body = node->CreateTreeBody(optimize);
01433
01434 if (body == NULL)
01435 {
01436 MMset(m, 0, NIL);
01437 return 0;
01438 }
01439
01440
01441 MMpull(m);
01442 return createBody(m, node);
01443 }
01444
01445
01455 int SO3BodyCreateShape(mmachine m)
01456 {
01457 #ifdef SO3_DEBUG
01458 MMechostr(MSKDEBUG, "SO3BodyCreateShape\n");
01459 #endif
01460
01461 int toler = MMpull(m);
01462 int n = MMget(m, 0);
01463 if (n==NIL)
01464 {
01465 MMset(m, 0, NIL);
01466 return 0;
01467 }
01468
01469 float tolerance = 0;
01470 if (toler != NIL)
01471 tolerance = MTOF(toler);
01472
01473 SNode* node = (SNode*) MMfetch(m, MTOP(n), 0);
01474 if(node==NULL)
01475 {
01476 MMset(m, 0, NIL);
01477 return 0;
01478 }
01479
01480
01481 if(node->getSceneNodeBody()!=NULL)
01482 {
01483 int b = 0;
01484 b = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, (int)(node->getSceneNodeBody())), OFFOBJMAG);
01485 OBJdelTM(m, SO3PHYSICBODY, b);
01486 }
01487
01488 SBody* body = 0;
01489
01490
01491 try
01492 {
01493 body = node->CreateConvexHullBody(tolerance);
01494 }
01495 catch (Ogre::Exception)
01496 {
01497 MMset(m, 0, NIL);
01498 return 0;
01499 }
01500
01501 if (body == NULL)
01502 {
01503 MMset(m, 0, NIL);
01504 return 0;
01505 }
01506
01507
01508 MMpull(m);
01509 return createBody(m, node);
01510 }
01511
01512
01522 int SO3BodySetMass(mmachine m)
01523 {
01524 #ifdef SO3_DEBUG
01525 MMechostr(MSKDEBUG, "SO3BodySetMass\n");
01526 #endif
01527
01528 int mass = MMpull(m);
01529 int bod = MMget(m, 0);
01530 if((bod==NIL) || (mass == NIL))
01531 {
01532 MMset(m, 0, NIL);
01533 return 0;
01534 }
01535
01536 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
01537 if(body==NULL)
01538 {
01539 MMset(m, 0, NIL);
01540 return 0;
01541 }
01542
01543 Ogre::Real omass = (Ogre::Real)MTOF(mass);
01544 body->SetMass(omass);
01545
01546 MMset(m, 0, ITOM(1));
01547 return 0;
01548 }
01549
01550
01560 int SO3BodyCreateBasicJointUpVector(mmachine m)
01561 {
01562 #ifdef SO3_DEBUG
01563 MMechostr(MSKDEBUG, "SO3BodyCreateBasicJointUpVector\n");
01564 #endif
01565
01566 int vel = MTOP(MMpull(m));
01567 int bod = MMget(m, 0);
01568 if((bod==NIL) || (vel == NIL))
01569 {
01570 MMset(m, 0, NIL);
01571 return 0;
01572 }
01573
01574 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
01575 if(body==NULL)
01576 {
01577 MMset(m, 0, NIL);
01578 return 0;
01579 }
01580
01581 Ogre::Vector3 vecteur(MTOF(MMfetch(m, vel, 0)),
01582 MTOF(MMfetch(m, vel, 1)),
01583 MTOF(MMfetch(m, vel, 2)));
01584
01585 body->SetUpJoint(vecteur);
01586
01587 MMset(m, 0, ITOM(1));
01588 return 0;
01589 }
01590
01591
01600 int SO3BodyDestroyBasicJointUpVector(mmachine m)
01601 {
01602 #ifdef SO3_DEBUG
01603 MMechostr(MSKDEBUG,"SO3BodyDestroyBasicJointUpVector\n");
01604 #endif
01605
01606 int bod = MMget(m, 0);
01607 if(bod==NIL)
01608 {
01609 MMset(m, 0, NIL);
01610 return 0;
01611 }
01612
01613 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
01614 if(body==NULL)
01615 {
01616 MMset(m, 0, NIL);
01617 return 0;
01618 }
01619
01620 body->RemoveUpJoint();
01621
01622 MMset(m, 0, 0);
01623 return 0;
01624 }
01625
01626
01636 int SO3BodySetForce(mmachine m)
01637 {
01638 #ifdef SO3_DEBUG
01639 MMechostr(MSKDEBUG, "SO3BodySetForce\n");
01640 #endif
01641
01642 int vec = MTOP(MMpull(m));
01643 int bod = MMget(m, 0);
01644 if((bod==NIL) || (vec == NIL))
01645 {
01646 MMset(m, 0, NIL);
01647 return 0;
01648 }
01649
01650 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
01651 if(body==NULL)
01652 {
01653 MMset(m, 0, NIL);
01654 return 0;
01655 }
01656
01657 int x = MMfetch(m, vec, 0);
01658 int y = MMfetch(m, vec, 1);
01659 int z = MMfetch(m, vec, 2);
01660
01661 if((x==NIL) || (y==NIL) || (z==NIL))
01662 {
01663 MMset(m, 0, NIL);
01664 return 0;
01665 }
01666
01667 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
01668
01669 body->SetForce(vecteur);
01670 MMset(m, 0, ITOM(1));
01671 return 0;
01672 }
01673
01674
01684 int SO3BodyAddForce(mmachine m)
01685 {
01686 #ifdef SO3_DEBUG
01687 MMechostr(MSKDEBUG, "SO3BodyAddForce\n");
01688 #endif
01689
01690 int vec = MTOP(MMpull(m));
01691 int bod = MMget(m, 0);
01692 if((bod==NIL) || (vec == NIL))
01693 {
01694 MMset(m, 0, NIL);
01695 return 0;
01696 }
01697
01698 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
01699 if(body==NULL)
01700 {
01701 MMset(m, 0, NIL);
01702 return 0;
01703 }
01704
01705 int x = MMfetch(m, vec, 0);
01706 int y = MMfetch(m, vec, 1);
01707 int z = MMfetch(m, vec, 2);
01708
01709 if((x==NIL) || (y==NIL) || (z==NIL))
01710 {
01711 MMset(m, 0, NIL);
01712 return 0;
01713 }
01714
01715 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
01716
01717 body->SetForce(body->GetForce() + vecteur);
01718 MMset(m, 0, ITOM(1));
01719 return 0;
01720 }
01721
01722
01731 int SO3BodyGetForce(mmachine m)
01732 {
01733 #ifdef SO3_DEBUG
01734 MMechostr(MSKDEBUG, "SO3BodyGetForce\n");
01735 #endif
01736
01737 int bod = MMget(m, 0);
01738 if(bod==NIL)
01739 {
01740 MMset(m, 0, NIL);
01741 return 0;
01742 }
01743
01744 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
01745 if(body==NULL)
01746 {
01747 MMset(m, 0, NIL);
01748 return 0;
01749 }
01750
01751 Ogre::Vector3 vecteur = body->GetForce();
01752 int tuple = MMmalloc(m, 3, TYPETAB);
01753 if(tuple==NIL)
01754 {
01755 MMset(m, 0, NIL);
01756 return MERRMEM;
01757 }
01758
01759 MMstore(m, tuple, 0, FTOM((vecteur.x)));
01760 MMstore(m, tuple, 1, FTOM((vecteur.y)));
01761 MMstore(m, tuple, 2, FTOM((vecteur.z)));
01762 MMset(m, 0, PTOM(tuple));
01763 return 0;
01764 }
01765
01766
01776 int SO3BodySetConstantForce(mmachine m)
01777 {
01778 #ifdef SO3_DEBUG
01779 MMechostr(MSKDEBUG, "SO3BodySetConstantForce\n");
01780 #endif
01781
01782 int vec = MTOP(MMpull(m));
01783 int bod = MMget(m, 0);
01784 if((bod==NIL) || (vec == NIL))
01785 {
01786 MMset(m, 0, NIL);
01787 return 0;
01788 }
01789
01790 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
01791 if(body==NULL)
01792 {
01793 MMset(m, 0, NIL);
01794 return 0;
01795 }
01796
01797 int x = MMfetch(m, vec, 0);
01798 int y = MMfetch(m, vec, 1);
01799 int z = MMfetch(m, vec, 2);
01800
01801 if((x==NIL) || (y==NIL) || (z==NIL))
01802 {
01803 MMset(m, 0, NIL);
01804 return 0;
01805 }
01806
01807 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
01808
01809 body->SetConstantForce(vecteur);
01810 MMset(m, 0, ITOM(1));
01811 return 0;
01812 }
01813
01814
01824 int SO3BodyAddConstantForce(mmachine m)
01825 {
01826 #ifdef SO3_DEBUG
01827 MMechostr(MSKDEBUG, "SO3BodyAddConstantForce\n");
01828 #endif
01829
01830 int vec = MTOP(MMpull(m));
01831 int bod = MMget(m, 0);
01832 if((bod==NIL) || (vec == NIL))
01833 {
01834 MMset(m, 0, NIL);
01835 return 0;
01836 }
01837
01838 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
01839 if(body==NULL)
01840 {
01841 MMset(m, 0, NIL);
01842 return 0;
01843 }
01844
01845 int x = MMfetch(m, vec, 0);
01846 int y = MMfetch(m, vec, 1);
01847 int z = MMfetch(m, vec, 2);
01848
01849 if((x==NIL) || (y==NIL) || (z==NIL))
01850 {
01851 MMset(m, 0, NIL);
01852 return 0;
01853 }
01854
01855 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
01856
01857 body->AddConstantForce(vecteur);
01858 MMset(m, 0, ITOM(1));
01859 return 0;
01860 }
01861
01862
01871 int SO3BodyGetConstantForce(mmachine m)
01872 {
01873 #ifdef SO3_DEBUG
01874 MMechostr(MSKDEBUG, "SO3BodyGetConstantForce\n");
01875 #endif
01876
01877 int bod = MMget(m, 0);
01878 if(bod==NIL)
01879 {
01880 MMset(m, 0, NIL);
01881 return 0;
01882 }
01883
01884 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
01885 if(body==NULL)
01886 {
01887 MMset(m, 0, NIL);
01888 return 0;
01889 }
01890
01891 Ogre::Vector3 vecteur = body->GetConstantForce();
01892 int tuple = MMmalloc(m, 3, TYPETAB);
01893 if(tuple==NIL)
01894 {
01895 MMset(m, 0, NIL);
01896 return MERRMEM;
01897 }
01898
01899 MMstore(m, tuple, 0, FTOM((vecteur.x)));
01900 MMstore(m, tuple, 1, FTOM((vecteur.y)));
01901 MMstore(m, tuple, 2, FTOM((vecteur.z)));
01902 MMset(m, 0, PTOM(tuple));
01903 return 0;
01904 }
01905
01915 int SO3BodySetConstantTorque(mmachine m)
01916 {
01917 #ifdef SO3_DEBUG
01918 MMechostr(MSKDEBUG, "SO3BodySetConstantTorque\n");
01919 #endif
01920
01921 int vec = MTOP(MMpull(m));
01922 int bod = MMget(m, 0);
01923 if((bod==NIL) || (vec == NIL))
01924 {
01925 MMset(m, 0, NIL);
01926 return 0;
01927 }
01928
01929 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
01930 if(body==NULL)
01931 {
01932 MMset(m, 0, NIL);
01933 return 0;
01934 }
01935
01936 int x = MMfetch(m, vec, 0);
01937 int y = MMfetch(m, vec, 1);
01938 int z = MMfetch(m, vec, 2);
01939
01940 if((x==NIL) || (y==NIL) || (z==NIL))
01941 {
01942 MMset(m, 0, NIL);
01943 return 0;
01944 }
01945
01946 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
01947
01948 body->SetConstantTorque(vecteur);
01949 MMset(m, 0, ITOM(1));
01950 return 0;
01951 }
01952
01953
01963 int SO3BodyAddConstantTorque(mmachine m)
01964 {
01965 #ifdef SO3_DEBUG
01966 MMechostr(MSKDEBUG, "SO3BodyAddConstantTorque\n");
01967 #endif
01968
01969 int vec = MTOP(MMpull(m));
01970 int bod = MMget(m, 0);
01971 if((bod==NIL) || (vec == NIL))
01972 {
01973 MMset(m, 0, NIL);
01974 return 0;
01975 }
01976
01977 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
01978 if(body==NULL)
01979 {
01980 MMset(m, 0, NIL);
01981 return 0;
01982 }
01983
01984 int x = MMfetch(m, vec, 0);
01985 int y = MMfetch(m, vec, 1);
01986 int z = MMfetch(m, vec, 2);
01987
01988 if((x==NIL) || (y==NIL) || (z==NIL))
01989 {
01990 MMset(m, 0, NIL);
01991 return 0;
01992 }
01993
01994 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
01995
01996 body->AddConstantTorque(vecteur);
01997 MMset(m, 0, ITOM(1));
01998 return 0;
01999 }
02000
02001
02010 int SO3BodyGetConstantTorque(mmachine m)
02011 {
02012 #ifdef SO3_DEBUG
02013 MMechostr(MSKDEBUG, "SO3BodyGetConstantTorque\n");
02014 #endif
02015
02016 int bod = MMget(m, 0);
02017 if(bod==NIL)
02018 {
02019 MMset(m, 0, NIL);
02020 return 0;
02021 }
02022
02023 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
02024 if(body==NULL)
02025 {
02026 MMset(m, 0, NIL);
02027 return 0;
02028 }
02029
02030 Ogre::Vector3 vecteur = body->GetConstantTorque();
02031 int tuple = MMmalloc(m, 3, TYPETAB);
02032 if(tuple==NIL)
02033 {
02034 MMset(m, 0, NIL);
02035 return MERRMEM;
02036 }
02037
02038 MMstore(m, tuple, 0, FTOM((vecteur.x)));
02039 MMstore(m, tuple, 1, FTOM((vecteur.y)));
02040 MMstore(m, tuple, 2, FTOM((vecteur.z)));
02041 MMset(m, 0, PTOM(tuple));
02042 return 0;
02043 }
02044
02045
02055 int SO3BodyAddGlobalForce(mmachine m)
02056 {
02057 #ifdef SO3_DEBUG
02058 MMechostr(MSKDEBUG, "SO3BodyAddGlobalForce\n");
02059 #endif
02060
02061 int vec = MTOP(MMpull(m));
02062 int bod = MMget(m, 0);
02063 if((bod==NIL) || (vec == NIL))
02064 {
02065 MMset(m, 0, NIL);
02066 return 0;
02067 }
02068
02069 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
02070 if(body==NULL)
02071 {
02072 MMset(m, 0, NIL);
02073 return 0;
02074 }
02075
02076 int x = MMfetch(m, vec, 0);
02077 int y = MMfetch(m, vec, 1);
02078 int z = MMfetch(m, vec, 2);
02079
02080 if((x==NIL) || (y==NIL) || (z==NIL))
02081 {
02082 MMset(m, 0, NIL);
02083 return 0;
02084 }
02085
02086 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
02087
02088 body->SetGlobalForce(body->GetGlobalForce() + vecteur);
02089 MMset(m, 0, ITOM(1));
02090 return 0;
02091 }
02092
02093
02103 int SO3BodyAddLocalForce(mmachine m)
02104 {
02105 #ifdef SO3_DEBUG
02106 MMechostr(MSKDEBUG, "SO3BodyAddLocalForce\n");
02107 #endif
02108
02109 int vec = MTOP(MMpull(m));
02110 int bod = MMget(m, 0);
02111 if((bod==NIL) || (vec == NIL))
02112 {
02113 MMset(m, 0, NIL);
02114 return 0;
02115 }
02116
02117 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
02118 if(body==NULL)
02119 {
02120 MMset(m, 0, NIL);
02121 return 0;
02122 }
02123
02124 int x = MMfetch(m, vec, 0);
02125 int y = MMfetch(m, vec, 1);
02126 int z = MMfetch(m, vec, 2);
02127
02128 if((x==NIL) || (y==NIL) || (z==NIL))
02129 {
02130 MMset(m, 0, NIL);
02131 return 0;
02132 }
02133
02134 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
02135
02136 body->SetLocalForce(body->GetLocalForce() + vecteur);
02137 MMset(m, 0, ITOM(1));
02138 return 0;
02139 }
02140
02141
02151 int SO3BodyAddTorque(mmachine m)
02152 {
02153 #ifdef SO3_DEBUG
02154 MMechostr(MSKDEBUG,"SO3BodyAddTorque\n");
02155 #endif
02156
02157 int vec = MTOP(MMpull(m));
02158 int bod = MMget(m, 0);
02159 if((bod==NIL) || (vec == NIL))
02160 {
02161 MMset(m, 0, NIL);
02162 return 0;
02163 }
02164
02165 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
02166 if(body==NULL)
02167 {
02168 MMset(m, 0, NIL);
02169 return 0;
02170 }
02171
02172 int x = MMfetch(m, vec, 0);
02173 int y = MMfetch(m, vec, 1);
02174 int z = MMfetch(m, vec, 2);
02175
02176 if((x==NIL) || (y==NIL) || (z==NIL))
02177 {
02178 MMset(m, 0, NIL);
02179 return 0;
02180 }
02181
02182 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
02183
02184 body->SetTorque(body->GetTorque() + vecteur);
02185 MMset(m, 0, ITOM(1));
02186 return 0;
02187 }
02188
02189
02199 int SO3BodySetTorque(mmachine m)
02200 {
02201 #ifdef SO3_DEBUG
02202 MMechostr(MSKDEBUG, "SO3BodySetTorque\n");
02203 #endif
02204
02205 int vec = MTOP(MMpull(m));
02206 int bod = MMget(m, 0);
02207 if((bod==NIL) || (vec == NIL))
02208 {
02209 MMset(m, 0, NIL);
02210 return 0;
02211 }
02212
02213 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
02214 if(body==NULL)
02215 {
02216 MMset(m, 0, NIL);
02217 return 0;
02218 }
02219
02220 int x = MMfetch(m, vec, 0);
02221 int y = MMfetch(m, vec, 1);
02222 int z = MMfetch(m, vec, 2);
02223
02224 if((x==NIL) || (y==NIL) || (z==NIL))
02225 {
02226 MMset(m, 0, NIL);
02227 return 0;
02228 }
02229
02230 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
02231
02232 body->SetTorque(vecteur);
02233 MMset(m, 0, ITOM(1));
02234 return 0;
02235 }
02236
02237
02247 int SO3BodySetOmega(mmachine m)
02248 {
02249 #ifdef SO3_DEBUG
02250 MMechostr(MSKDEBUG, "SO3BodySetOmega\n");
02251 #endif
02252
02253 int vec = MTOP(MMpull(m));
02254 int bod = MMget(m, 0);
02255 if((bod==NIL) || (vec == NIL))
02256 {
02257 MMset(m, 0, NIL);
02258 return 0;
02259 }
02260
02261 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
02262 if(body==NULL)
02263 {
02264 MMset(m, 0, NIL);
02265 return 0;
02266 }
02267
02268 int x = MMfetch(m, vec, 0);
02269 int y = MMfetch(m, vec, 1);
02270 int z = MMfetch(m, vec, 2);
02271
02272 if((x==NIL) || (y==NIL) || (z==NIL))
02273 {
02274 MMset(m, 0, NIL);
02275 return 0;
02276 }
02277
02278 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
02279
02280 body->SetOmega(vecteur);
02281 MMset(m, 0, ITOM(1));
02282 return 0;
02283 }
02284
02285
02295 int SO3BodySetVelocity(mmachine m)
02296 {
02297 #ifdef SO3_DEBUG
02298 MMechostr(MSKDEBUG, "SO3BodySetVelocity\n");
02299 #endif
02300
02301 int vec = MTOP(MMpull(m));
02302 int bod = MMget(m, 0);
02303 if((bod==NIL) || (vec == NIL))
02304 {
02305 MMset(m, 0, NIL);
02306 return 0;
02307 }
02308
02309 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
02310 if(body==NULL)
02311 {
02312 MMset(m, 0, NIL);
02313 return 0;
02314 }
02315
02316 int x = MMfetch(m, vec, 0);
02317 int y = MMfetch(m, vec, 1);
02318 int z = MMfetch(m, vec, 2);
02319
02320 if((x==NIL) || (y==NIL) || (z==NIL))
02321 {
02322 MMset(m, 0, NIL);
02323 return 0;
02324 }
02325
02326 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
02327
02328 body->SetVelocity(vecteur);
02329 MMset(m, 0, ITOM(1));
02330 return 0;
02331 }
02332
02333
02344 int SO3BodyAddImpulse(mmachine m)
02345 {
02346 #ifdef SO3_DEBUG
02347 MMechostr(MSKDEBUG, "SO3BodyAddImpulse\n");
02348 #endif
02349
02350 int pos = MTOP(MMpull(m));
02351 int deltav = MTOP(MMpull(m));
02352 int bod = MMget(m, 0);
02353 if((bod==NIL)||(pos==NIL)||(deltav==NIL))
02354 {
02355 MMset(m, 0, NIL);
02356 return 0;
02357 }
02358
02359 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
02360 if(body==NULL)
02361 {
02362 MMset(m, 0, NIL);
02363 return 0;
02364 }
02365
02366 int x = MMfetch(m, pos, 0);
02367 int y = MMfetch(m, pos, 1);
02368 int z = MMfetch(m, pos, 2);
02369
02370 if((x==NIL) || (y==NIL) || (z==NIL))
02371 {
02372 MMset(m, 0, NIL);
02373 return 0;
02374 }
02375
02376 Ogre::Vector3 position = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
02377
02378 int dx = MMfetch(m, deltav, 0);
02379 int dy = MMfetch(m, deltav, 1);
02380 int dz = MMfetch(m, deltav, 2);
02381
02382 if((dx==NIL) || (dy==NIL) || (dz==NIL))
02383 {
02384 MMset(m, 0, NIL);
02385 return 0;
02386 }
02387
02388 Ogre::Vector3 delta = Ogre::Vector3(MTOF(dx), MTOF(dy), MTOF(dz));
02389
02390 body->AddImpulse(delta, position);
02391 MMset(m, 0, ITOM(1));
02392 return 0;
02393 }
02394
02395
02396
02407 int SO3BodySetPositionOrientation(mmachine m)
02408 {
02409 #ifdef SO3_DEBUG
02410 MMechostr(MSKDEBUG, "SO3BodySetPositionOrientation\n");
02411 #endif
02412
02413 int or = MTOP(MMpull(m));
02414 int pos = MTOP(MMpull(m));
02415 int bod = MMget(m,0);
02416 if((bod==NIL)||(pos == NIL)||(or == NIL))
02417 {
02418 MMset(m, 0, NIL);
02419 return 0;
02420 }
02421
02422 SBody * body = (SBody*) MMfetch(m,MTOP(bod),0);
02423 if(body==NULL)
02424 {
02425 MMset(m,0,NIL);
02426 return 0;
02427 }
02428
02429 Ogre::Vector3 vecteur(MTOF(MMfetch(m, pos, 0)),
02430 MTOF(MMfetch(m, pos, 1)),
02431 MTOF(MMfetch(m, pos, 2)));
02432
02433 Ogre::Quaternion quat(MTOF(MMfetch(m, or, 0)),
02434 MTOF(MMfetch(m, or, 1)),
02435 MTOF(MMfetch(m, or, 2)),
02436 MTOF(MMfetch(m, or, 3)));
02437
02438 body->SetMatrix(vecteur, quat);
02439 MMset(m, 0, ITOM(1));
02440 return 0;
02441 }
02442
02443
02453 int SO3BodySetAngularDamping(mmachine m)
02454 {
02455 #ifdef SO3_DEBUG
02456 MMechostr(MSKDEBUG, "SO3BodySetAngularDamping\n");
02457 #endif
02458
02459 int vec = MTOP(MMpull(m));
02460 int bod = MMget(m, 0);
02461 if((bod==NIL) || (vec == NIL))
02462 {
02463 MMset(m, 0, NIL);
02464 return 0;
02465 }
02466
02467 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
02468 if(body==NULL)
02469 {
02470 MMset(m, 0, NIL);
02471 return 0;
02472 }
02473
02474 int x = MMfetch(m, vec, 0);
02475 int y = MMfetch(m, vec, 1);
02476 int z = MMfetch(m, vec, 2);
02477
02478 if((x==NIL) || (y==NIL) || (z==NIL))
02479 {
02480 MMset(m, 0, NIL);
02481 return 0;
02482 }
02483
02484 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
02485
02486 body->SetAngularDamping(vecteur);
02487 MMset(m, 0, ITOM(1));
02488 return 0;
02489 }
02490
02491
02501 int SO3BodySetCenterOfMass(mmachine m)
02502 {
02503 #ifdef SO3_DEBUG
02504 MMechostr(MSKDEBUG, "SO3BodySetCenterOfMass\n");
02505 #endif
02506
02507 int vec = MTOP(MMpull(m));
02508 int bod = MMget(m, 0);
02509 if((bod==NIL) || (vec == NIL))
02510 {
02511 MMset(m, 0, NIL);
02512 return 0;
02513 }
02514
02515 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
02516 if(body==NULL)
02517 {
02518 MMset(m, 0, NIL);
02519 return 0;
02520 }
02521
02522 int x = MMfetch(m, vec, 0);
02523 int y = MMfetch(m, vec, 1);
02524 int z = MMfetch(m, vec, 2);
02525
02526 if((x==NIL) || (y==NIL) || (z==NIL))
02527 {
02528 MMset(m, 0, NIL);
02529 return 0;
02530 }
02531
02532 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
02533
02534 body->SetCenterOfMass(vecteur);
02535 MMset(m, 0, ITOM(1));
02536 return 0;
02537 }
02538
02539
02550 int SO3BodySetMassMatrix(mmachine m)
02551 {
02552 #ifdef SO3_DEBUG
02553 MMechostr(MSKDEBUG, "SO3BodySetMassMatrix\n");
02554 #endif
02555
02556 int vec = MTOP(MMpull(m));
02557 float mass = MTOF(MMpull(m));
02558 int bod = MMget(m, 0);
02559 if((bod==NIL) || (vec == NIL) || (mass == NIL))
02560 {
02561 MMset(m, 0, NIL);
02562 return 0;
02563 }
02564
02565 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
02566 if(body==NULL)
02567 {
02568 MMset(m, 0, NIL);
02569 return 0;
02570 }
02571
02572 int x = MMfetch(m, vec, 0);
02573 int y = MMfetch(m, vec, 1);
02574 int z = MMfetch(m, vec, 2);
02575
02576 if((x==NIL) || (y==NIL) || (z==NIL))
02577 {
02578 MMset(m, 0, NIL);
02579 return 0;
02580 }
02581
02582 Ogre::Vector3 vecteur = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
02583
02584 body->SetMassMatrix(mass, vecteur);
02585 MMset(m, 0, ITOM(1));
02586 return 0;
02587 }
02588
02589
02598 int SO3BodyGetAngularDamping(mmachine m)
02599 {
02600 #ifdef SO3_DEBUG
02601 MMechostr(MSKDEBUG, "SO3BodyGetAngularDamping\n");
02602 #endif
02603
02604 int bod = MMget(m, 0);
02605 if(bod==NIL)
02606 {
02607 MMset(m, 0, NIL);
02608 return 0;
02609 }
02610
02611 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
02612 if(body==NULL)
02613 {
02614 MMset(m, 0, NIL);
02615 return 0;
02616 }
02617
02618 Ogre::Vector3 vecteur = body->GetAngularDamping();
02619 int tuple = MMmalloc(m, 3, TYPETAB);
02620 if(tuple==NIL)
02621 {
02622 MMset(m, 0, NIL);
02623 return MERRMEM;
02624 }
02625
02626 MMstore(m, tuple, 0, FTOM((vecteur.x)));
02627 MMstore(m, tuple, 1, FTOM((vecteur.y)));
02628 MMstore(m, tuple, 2, FTOM((vecteur.z)));
02629 MMset(m, 0, PTOM(tuple));
02630 return 0;
02631 }
02632
02633
02642 int SO3BodyGetOmega(mmachine m)
02643 {
02644 #ifdef SO3_DEBUG
02645 MMechostr(MSKDEBUG, "SO3BodyGetOmega\n");
02646 #endif
02647
02648 int bod = MMget(m, 0);
02649 if(bod==NIL)
02650 {
02651 MMset(m, 0, NIL);
02652 return 0;
02653 }
02654
02655 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
02656 if(body==NULL)
02657 {
02658 MMset(m, 0, NIL);
02659 return 0;
02660 }
02661
02662 Ogre::Vector3 vecteur = body->GetOmega();
02663 int tuple = MMmalloc(m, 3, TYPETAB);
02664 if(tuple==NIL)
02665 {
02666 MMset(m, 0, NIL);
02667 return MERRMEM;
02668 }
02669
02670 MMstore(m, tuple, 0, FTOM((vecteur.x)));
02671 MMstore(m, tuple, 1, FTOM((vecteur.y)));
02672 MMstore(m, tuple, 2, FTOM((vecteur.z)));
02673 MMset(m,0, PTOM(tuple));
02674 return 0;
02675 }
02676
02677
02687 int SO3BodySetLinearDamping(mmachine m)
02688 {
02689 #ifdef SO3_DEBUG
02690 MMechostr(MSKDEBUG, "SO3BodySetLinearDamping\n");
02691 #endif
02692
02693 int ang = MMpull(m);
02694 int bod = MMget(m, 0);
02695 if((bod==NIL)||(ang == NIL))
02696 {
02697 MMset(m, 0, NIL);
02698 return 0;
02699 }
02700
02701 SBody * body = (SBody*) MMfetch(m, MTOP(bod), 0);
02702 if(body==NULL)
02703 {
02704 MMset(m, 0, NIL);
02705 return 0;
02706 }
02707
02708 body->SetLinearDamping((Ogre::Real)MTOF(ang));
02709 MMset(m, 0, ITOM(1));
02710 return 0;
02711 }
02712
02713
02723 int SO3BodySetAutoSleep(mmachine m)
02724 {
02725 #ifdef SO3_DEBUG
02726 MMechostr(MSKDEBUG, "SO3BodySetAutoSleep\n");
02727 #endif
02728
02729 int val = MMpull(m);
02730 int bod = MMget(m, 0);
02731 if((bod==NIL)||(val == NIL))
02732 {
02733 MMset(m, 0, NIL);
02734 return 0;
02735 }
02736
02737 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
02738 if(body==NULL)
02739 {
02740 MMset(m, 0, NIL);
02741 return 0;
02742 }
02743
02744 bool sleep = false;
02745 if ((val != NIL) && (MTOI(val) == 1))
02746 sleep = true;
02747
02748 body->SetAutoSleep(sleep);
02749 MMset(m, 0, ITOM(1));
02750 return 0;
02751 }
02752
02753
02763 int SO3BodySetType(mmachine m)
02764 {
02765 #ifdef SO3_DEBUG
02766 MMechostr(MSKDEBUG, "SO3BodySetType\n");
02767 #endif
02768
02769 int val = MTOI(MMpull(m));
02770 int bod = MMget(m, 0);
02771 if((bod==NIL)||(val==NIL))
02772 {
02773 MMset(m, 0, NIL);
02774 return 0;
02775 }
02776
02777 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
02778 if(body==NULL)
02779 {
02780 MMset(m, 0, NIL);
02781 return 0;
02782 }
02783
02784 body->SetType(val);
02785
02786 MMset(m, 0, ITOM(val));
02787 return 0;
02788 }
02789
02790
02800 int SO3BodySetContiniousCollisionMode(mmachine m)
02801 {
02802 #ifdef SO3_DEBUG
02803 MMechostr(MSKDEBUG, "SO3BodySetContiniousCollisionMode\n");
02804 #endif
02805
02806 int val = MTOI(MMpull(m));
02807 int bod = MMget(m,0);
02808 if((bod==NIL) || (val == NIL))
02809 {
02810 MMset(m, 0, NIL);
02811 return 0;
02812 }
02813
02814 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
02815 if(body==NULL)
02816 {
02817 MMset(m, 0, NIL);
02818 return 0;
02819 }
02820
02821 bool coll = false;
02822 if (val == 1)
02823 coll = true;
02824
02825 body->SetContinuousCollisionMode(coll);
02826 MMset(m, 0, ITOM(1));
02827 return 0;
02828 }
02829
02830
02839 int SO3BodyGetLinearDamping(mmachine m)
02840 {
02841 #ifdef SO3_DEBUG
02842 MMechostr(MSKDEBUG, "SO3BodyGetLinearDamping\n");
02843 #endif
02844
02845 int bod = MMget(m, 0);
02846 if(bod==NIL)
02847 {
02848 MMset(m, 0, NIL);
02849 return 0;
02850 }
02851
02852 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
02853 if(body==NULL)
02854 {
02855 MMset(m, 0, NIL);
02856 return 0;
02857 }
02858
02859 float ld = body->GetLinearDamping();
02860 MMset(m, 0, FTOM(ld));
02861 return 0;
02862 }
02863
02864
02873 int SO3BodyGetInvMass(mmachine m)
02874 {
02875 #ifdef SO3_DEBUG
02876 MMechostr(MSKDEBUG, "SO3BodyGetInvMass\n");
02877 #endif
02878
02879 int bod = MMget(m, 0);
02880 if(bod==NIL)
02881 {
02882 MMset(m, 0, NIL);
02883 return 0;
02884 }
02885
02886 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
02887 if(body==NULL)
02888 {
02889 MMset(m, 0, NIL);
02890 return 0;
02891 }
02892
02893 float mass;
02894 Ogre::Vector3 vecteur;
02895 body->GetInvMass(mass, vecteur);
02896 MMpush(m, FTOM(mass));
02897
02898 int inertia = MMmalloc(m, 3, TYPETAB);
02899 if(inertia==NIL)
02900 {
02901 MMset(m, 0, NIL);
02902 return MERRMEM;
02903 }
02904
02905 MMstore(m, inertia, 0, FTOM(vecteur.x));
02906 MMstore(m, inertia, 1, FTOM(vecteur.y));
02907 MMstore(m, inertia, 2, FTOM(vecteur.z));
02908 MMpush(m, PTOM(inertia));
02909
02910
02911 int result = MMmalloc(m, 2, TYPETAB);
02912 if(result==NIL)
02913 {
02914 MMset(m, 0, NIL);
02915 return MERRMEM;
02916 }
02917
02918 MMstore(m, result, 1, MMpull(m));
02919 MMstore(m, result, 0, MMpull(m));
02920 MMset(m, 0, PTOM(result));
02921 return 0;
02922 }
02923
02924
02933 int SO3BodyGetMassMatrix(mmachine m)
02934 {
02935 #ifdef SO3_DEBUG
02936 MMechostr(MSKDEBUG, "SO3BodyGetMassMatrix\n");
02937 #endif
02938
02939 int bod = MMget(m, 0);
02940 if(bod==NIL)
02941 {
02942 MMset(m, 0, NIL);
02943 return 0;
02944 }
02945
02946 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
02947 if(body==NULL)
02948 {
02949 MMset(m, 0, NIL);
02950 return 0;
02951 }
02952
02953 float mass;
02954 Ogre::Vector3 vecteur;
02955 body->GetMassMatrix(mass, vecteur);
02956 MMpush(m, FTOM(mass));
02957
02958 int inertia = MMmalloc(m, 3, TYPETAB);
02959 if(inertia==NIL)
02960 {
02961 MMset(m, 0, NIL);
02962 return MERRMEM;
02963 }
02964 MMstore(m, inertia, 0, FTOM(vecteur.x));
02965 MMstore(m, inertia, 1, FTOM(vecteur.y));
02966 MMstore(m, inertia, 2, FTOM(vecteur.z));
02967 MMpush(m, PTOM(inertia));
02968
02969
02970 int result = MMmalloc(m, 2, TYPETAB);
02971 if(result==NIL)
02972 {
02973 MMset(m, 0, NIL);
02974 return MERRMEM;
02975 }
02976 MMstore(m, result, 1, MMpull(m) );
02977 MMstore(m, result, 0, MMpull(m) );
02978 MMset(m, 0, PTOM(result));
02979 return 0;
02980 }
02981
02982
02991 int SO3BodyGetAutoSleep(mmachine m)
02992 {
02993 #ifdef SO3_DEBUG
02994 MMechostr(MSKDEBUG, "SO3BodyGetAutoSleep\n");
02995 #endif
02996
02997 int bod = MMget(m, 0);
02998 if(bod==NIL)
02999 {
03000 MMset(m, 0, NIL);
03001 return 0;
03002 }
03003
03004 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
03005 if(body==NULL)
03006 {
03007 MMset(m, 0, NIL);
03008 return 0;
03009 }
03010
03011 bool sleep = body->GetAutoSleep();
03012
03013 MMset(m, 0, ITOM(sleep ? 1 : 0));
03014 return 0;
03015 }
03016
03017
03026 int SO3BodyGetSleepingState(mmachine m)
03027 {
03028 #ifdef SO3_DEBUG
03029 MMechostr(MSKDEBUG, "SO3BodyGetSleepingState\n");
03030 #endif
03031
03032 int bod = MMget(m, 0);
03033 if(bod==NIL)
03034 {
03035 MMset(m, 0, NIL);
03036 return 0;
03037 }
03038
03039 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
03040 if(body==NULL)
03041 {
03042 MMset(m, 0, NIL);
03043 return 0;
03044 }
03045
03046 bool sleep = body->GetSleepState();
03047
03048 MMset(m, 0, ITOM(sleep ? 1 : 0));
03049 return 0;
03050 }
03051
03052
03061 int SO3BodyGetType(mmachine m)
03062 {
03063 #ifdef SO3_DEBUG
03064 MMechostr(MSKDEBUG, "SO3BodyGetType\n");
03065 #endif
03066
03067 int bod = MMget(m, 0);
03068 if(bod==NIL)
03069 {
03070 MMset(m, 0, NIL);
03071 return 0;
03072 }
03073
03074 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
03075 if(body==NULL)
03076 {
03077 MMset(m, 0, NIL);
03078 return 0;
03079 }
03080
03081 int ld = body->GetType();
03082 MMset(m, 0, ITOM(ld));
03083 return 0;
03084 }
03085
03086
03095 int SO3BodyGetContiniousCollisionMode(mmachine m)
03096 {
03097 #ifdef SO3_DEBUG
03098 MMechostr(MSKDEBUG, "SO3BodyGetContiniousCollisionMode\n");
03099 #endif
03100
03101 int bod = MMget(m, 0);
03102 if(bod==NIL)
03103 {
03104 MMset(m, 0, NIL);
03105 return 0;
03106 }
03107
03108 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
03109 if(body==NULL)
03110 {
03111 MMset(m, 0, NIL);
03112 return 0;
03113 }
03114
03115 bool coll = body->GetContinuousCollisionMode();
03116 MMset(m, 0, ITOM(coll ? 1 : 0));
03117 return 0;
03118 }
03119
03120
03129 int SO3BodyGetCenterOfMass(mmachine m)
03130 {
03131 #ifdef SO3_DEBUG
03132 MMechostr(MSKDEBUG, "SO3BodyGetCenterOfMass\n");
03133 #endif
03134
03135 int bod = MMget(m, 0);
03136 if(bod==NIL)
03137 {
03138 MMset(m, 0, NIL);
03139 return 0;
03140 }
03141
03142 SBody * body = (SBody*) MMfetch(m,MTOP(bod),0);
03143 if(body==NULL)
03144 {
03145 MMset(m, 0, NIL);
03146 return 0;
03147 }
03148
03149 Ogre::Vector3 vecteur = body->GetCenterOfMass();
03150 int tuple = MMmalloc(m, 3, TYPETAB);
03151 if(tuple==NIL)
03152 {
03153 MMset(m, 0, NIL);
03154 return MERRMEM;
03155 }
03156
03157 MMstore(m, tuple, 0, FTOM((vecteur.x)));
03158 MMstore(m, tuple, 1, FTOM((vecteur.y)));
03159 MMstore(m, tuple, 2, FTOM((vecteur.z)));
03160 MMset(m, 0, PTOM(tuple));
03161 return 0;
03162 }
03163
03164
03173 int SO3BodyGetVelocity(mmachine m)
03174 {
03175 #ifdef SO3_DEBUG
03176 MMechostr(MSKDEBUG, "SO3BodyGetVelocity\n");
03177 #endif
03178
03179 int bod = MMget(m, 0);
03180 if(bod==NIL)
03181 {
03182 MMset(m, 0, NIL);
03183 return 0;
03184 }
03185
03186 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
03187 if(body==NULL)
03188 {
03189 MMset(m, 0, NIL);
03190 return 0;
03191 }
03192
03193 Ogre::Vector3 vecteur = body->GetVelocity();
03194 int tuple = MMmalloc(m, 3, TYPETAB);
03195 if(tuple==NIL)
03196 {
03197 MMset(m, 0, NIL);
03198 return MERRMEM;
03199 }
03200
03201 MMstore(m, tuple, 0, FTOM((vecteur.x)));
03202 MMstore(m, tuple, 1, FTOM((vecteur.y)));
03203 MMstore(m, tuple, 2, FTOM((vecteur.z)));
03204 MMset(m, 0, PTOM(tuple));
03205 return 0;
03206 }
03207
03208
03217 int SO3BodyGetTorque(mmachine m)
03218 {
03219 #ifdef SO3_DEBUG
03220 MMechostr(MSKDEBUG, "SO3BodyGetTorque\n");
03221 #endif
03222
03223 int bod = MMget(m, 0);
03224 if(bod==NIL)
03225 {
03226 MMset(m, 0, NIL);
03227 return 0;
03228 }
03229
03230 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
03231 if(body==NULL)
03232 {
03233 MMset(m, 0, NIL);
03234 return 0;
03235 }
03236
03237 Ogre::Vector3 vecteur = body->GetTorque();
03238 int tuple = MMmalloc(m, 3, TYPETAB);
03239 if(tuple==NIL)
03240 {
03241 MMset(m, 0, NIL);
03242 return MERRMEM;
03243 }
03244
03245 MMstore(m, tuple, 0, FTOM((vecteur.x)));
03246 MMstore(m, tuple, 1, FTOM((vecteur.y)));
03247 MMstore(m, tuple, 2, FTOM((vecteur.z)));
03248 MMset(m, 0, PTOM(tuple));
03249 return 0;
03250 }
03251
03252
03263 int SO3BodyGetPositionOrientation(mmachine m)
03264 {
03265 #ifdef SO3_DEBUG
03266 MMechostr(MSKDEBUG, "SO3BodyGetPositionOrientation\n");
03267 #endif
03268
03269 int bod = MMget(m, 0);
03270 if(bod==NIL)
03271 {
03272 MMset(m, 0, NIL);
03273 return 0;
03274 }
03275
03276 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
03277 if(body==NULL)
03278 {
03279 MMset(m, 0, NIL);
03280 return 0;
03281 }
03282
03283 Ogre::Vector3 vecteur;
03284 Ogre::Quaternion quat;
03285 body->GetPositionOrientation(vecteur, quat);
03286
03287 int position = MMmalloc(m, 3, TYPETAB);
03288 if(position==NIL)
03289 {
03290 MMset(m, 0, NIL);
03291 return MERRMEM;
03292 }
03293 MMstore(m, position, 0, FTOM(vecteur.x));
03294 MMstore(m, position, 1, FTOM(vecteur.y));
03295 MMstore(m, position, 2, FTOM(vecteur.z));
03296 MMpush(m, PTOM(position));
03297
03298 int orientation = MMmalloc(m, 4, TYPETAB);
03299 if(orientation==NIL)
03300 {
03301 MMset(m, 0, NIL);
03302 return MERRMEM;
03303 }
03304 MMstore(m, orientation, 0, FTOM(quat.x));
03305 MMstore(m, orientation, 1, FTOM(quat.y));
03306 MMstore(m, orientation, 2, FTOM(quat.z));
03307 MMstore(m, orientation, 3, FTOM(quat.w));
03308 MMpush(m, PTOM(orientation));
03309
03310
03311 int result = MMmalloc(m, 2, TYPETAB);
03312 if(result==NIL)
03313 {
03314 MMset(m, 0, NIL);
03315 return MERRMEM;
03316 }
03317 MMstore(m, result, 1, MMpull(m) );
03318 MMstore(m, result, 0, MMpull(m) );
03319 MMset(m, 0, PTOM(result));
03320 return 0;
03321 }
03322
03323
03333 int SO3BodySetFreeze(mmachine m)
03334 {
03335 #ifdef SO3_DEBUG
03336 MMechostr(MSKDEBUG, "SO3BodySetFreeze\n");
03337 #endif
03338
03339 int val = MTOI(MMpull(m));
03340 int bod = MMget(m, 0);
03341 if(bod==NIL)
03342 {
03343 MMset(m, 0, NIL);
03344 return 0;
03345 }
03346
03347 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
03348 if(body==NULL)
03349 {
03350 MMset(m, 0, NIL);
03351 return 0;
03352 }
03353
03354 if(val == 1)
03355 {
03356 body->SetFreezeState(true);
03357 }
03358 else
03359 {
03360 body->SetFreezeState(false);
03361 }
03362 MMset(m, 0, ITOM(1));
03363 return 0;
03364 }
03365
03366
03375 int SO3BodyGetFreeze(mmachine m)
03376 {
03377 #ifdef SO3_DEBUG
03378 MMechostr(MSKDEBUG, "SO3BodyGetFreeze\n");
03379 #endif
03380
03381 int bod = MMget(m, 0);
03382 if(bod==NIL)
03383 {
03384 MMset(m, 0, NIL);
03385 return 0;
03386 }
03387
03388 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
03389 if(body==NULL)
03390 {
03391 MMset(m, 0, NIL);
03392 return 0;
03393 }
03394
03395 int val = 0;
03396 if(body->GetFreezeState())
03397 val = 1;
03398
03399 MMset(m, 0, MTOI(val));
03400 return 0;
03401 }
03402
03403
03412 int SO3BodyGetSceneNode(mmachine m)
03413 {
03414 #ifdef SO3_DEBUG
03415 MMechostr(MSKDEBUG, "SO3BodyGetSceneNode\n");
03416 #endif
03417
03418 int bod = MMget(m, 0);
03419 if(bod==NIL)
03420 {
03421 MMset(m, 0, NIL);
03422 return 0;
03423 }
03424
03425 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
03426 if(body==NULL)
03427 {
03428 MMset(m, 0, NIL);
03429 return 0;
03430 }
03431
03432 int c = OBJfindTH(m, SO3OBJTYPE, (int)(body->GetParentNode()));
03433 if(c!=NIL)
03434 c = MMfetch(m, c, OFFOBJMAG);
03435
03436 MMset(m, 0, c);
03437 return 0;
03438 }
03439
03440
03449 int SO3BodyDestroy(mmachine m)
03450 {
03451 #ifdef SO3_DEBUG
03452 MMechostr(MSKDEBUG, "SO3BodyDestroy\n");
03453 #endif
03454
03455 int body = MMget(m, 0);
03456 if(body == NIL)
03457 {
03458 MMset(m, 0, NIL);
03459 return 0;
03460 }
03461
03462 OBJdelTM(m, SO3PHYSICBODY, body);
03463
03464 MMset(m, 0, ITOM(1));
03465 return 0;
03466 }
03467
03468
03477 int SO3SceneNodeGetBody(mmachine m)
03478 {
03479 #ifdef SO3_DEBUG
03480 MMechostr(MSKDEBUG, "SO3SceneNodeGetBody\n");
03481 #endif
03482
03483 int n = MMget(m, 0);
03484 if(n==NIL)
03485 {
03486 MMset(m, 0, NIL);
03487 return 0;
03488 }
03489
03490 SNode* node = (SNode*) MMfetch(m, MTOP(n), 0);
03491 if(node==NULL)
03492 {
03493 MMset(m, 0, NIL);
03494 return 0;
03495 }
03496
03497 if(node->getSceneNodeBody() == 0)
03498 {
03499 MMset(m, 0, NIL);
03500 return 0;
03501 }
03502
03503 int mbody = OBJfindTH(m, SO3PHYSICBODY, (int)node->getSceneNodeBody());
03504 if(mbody!=NIL)
03505 mbody = MMfetch(m, mbody, OFFOBJMAG);
03506
03507 MMset(m, 0, mbody);
03508 return 0;
03509 }
03510
03511
03523 int SO3PhysicsRayCast(mmachine m)
03524 {
03525 #ifdef SO3_DEBUG
03526 MMechostr(MSKDEBUG, "SO3PhysicsRayCast\n");
03527 #endif
03528
03529 int dist = MMpull(m);
03530 int dir = MTOP(MMpull(m));
03531 int src = MTOP(MMpull(m));
03532 int s = MTOP(MMget(m ,0));
03533 if((s == NIL)||(dir==NIL)||(src == NIL)||(dist == NIL))
03534 {
03535 MMset(m, 0, NIL);
03536 return 0;
03537 }
03538
03539 SScene* scene = (SScene*) MMfetch(m, s, 0);
03540 if(scene==NULL)
03541 {
03542 MMset(m,0,NIL);
03543 return 0;
03544 }
03545
03546 int x1 = MMfetch(m,src,0);
03547 int y1 = MMfetch(m,src,1);
03548 int z1 = MMfetch(m,src,2);
03549
03550 if((x1==NIL) || (y1==NIL) || (z1==NIL))
03551 {
03552 MMset(m,0,NIL);
03553 return 0;
03554 }
03555
03556 Ogre::Vector3 srcVector(MTOF(x1), MTOF(y1), MTOF(z1));
03557
03558 int x2 = MMfetch(m,dir,0);
03559 int y2 = MMfetch(m,dir,1);
03560 int z2 = MMfetch(m,dir,2);
03561
03562 if((x2==NIL) || (y2==NIL) || (z2==NIL))
03563 {
03564 MMset(m,0,NIL);
03565 return 0;
03566 }
03567
03568 Ogre::Vector3 dirVector(MTOF(x2), MTOF(y2), MTOF(z2));
03569
03570 Ogre::Real hitdist = 0;
03571 Ogre::Vector3 hitnormal = Ogre::Vector3::ZERO;
03572 SBody* hitbody = scene->GetPhysicsWorld()->PhysicsRayCast(srcVector, dirVector, MTOF(dist), hitdist, hitnormal);
03573
03574
03575 if (hitbody == 0)
03576 {
03577 MMset(m,0,NIL);
03578 return 0;
03579 }
03580
03581 int mbody = OBJfindTH(m, SO3PHYSICBODY, (int)hitbody);
03582 if(mbody!=NIL)
03583 mbody = MMfetch(m, mbody, OFFOBJMAG);
03584
03585
03586 MMpush(m, mbody);
03587
03588
03589 MMpush(m, FTOM(hitdist));
03590
03591
03592 int tuple = MMmalloc(m, 3, TYPETAB);
03593 if(tuple==NIL)
03594 {
03595 MMset(m,0,NIL);
03596 return MERRMEM;
03597 }
03598
03599 MMstore(m, tuple, 0, FTOM((hitnormal.x)));
03600 MMstore(m, tuple, 1, FTOM((hitnormal.y)));
03601 MMstore(m, tuple, 2, FTOM((hitnormal.z)));
03602
03603 MMpush(m, PTOM(tuple));
03604
03605
03606 int result = MMmalloc(m, 3, TYPETAB);
03607 if(result==NIL)
03608 {
03609 MMset(m, 0, NIL);
03610 return MERRMEM;
03611 }
03612
03613 MMstore(m, result, 2, MMpull(m));
03614 MMstore(m, result, 1, MMpull(m));
03615 MMstore(m, result, 0, MMpull(m));
03616
03617 MMset(m, 0, PTOM(result));
03618
03619 #ifdef SO3_DEBUG
03620 MMechostr(MSKDEBUG, "SO3PhysicsRayCast: OK!\n");
03621 #endif
03622 return 0;
03623 }
03624
03625
03634 bool MaterialIDExists(SScene* scene, string testName, SMaterialID **result)
03635 {
03636 SMaterialIDMap::iterator iMaterialIDSearched = scene->GetPhysicsWorld()->listOfMaterialID.find(testName);
03637 if(iMaterialIDSearched != scene->GetPhysicsWorld()->listOfMaterialID.end())
03638 {
03639 *result = iMaterialIDSearched->second;
03640 return true;
03641 }
03642 return false;
03643 }
03644
03645
03654 SMaterialPair* getMaterialPairByWorld(SPhysicWorld* world, int ID1,int ID2)
03655 {
03656 SMaterialPairMap::iterator iMaterialPairList = world->listOfPhysicsMaterialPair.begin();
03657 while(iMaterialPairList != world->listOfPhysicsMaterialPair.end())
03658 {
03659 if(((*iMaterialPairList)->getID1() == ID1 && (*iMaterialPairList)->getID2() == ID2)||((*iMaterialPairList)->getID2() == ID1 && (*iMaterialPairList)->getID1() == ID2))
03660 return (*iMaterialPairList);
03661
03662 iMaterialPairList++;
03663 }
03664
03665 return NULL;
03666 }
03667
03668
03678 int SO3BodySetMaterial(mmachine m)
03679 {
03680 #ifdef SO3_DEBUG
03681 MMechostr(MSKDEBUG, "SO3BodySetMaterial\n");
03682 #endif
03683
03684 int mat = MTOP(MMpull(m));
03685 int bod = MTOP(MMget(m ,0));
03686 if((bod==NIL)||(mat == NIL))
03687 {
03688 MMset(m, 0, NIL);
03689 return 0;
03690 }
03691
03692 SBody* body = (SBody*) MMfetch(m, bod, 0);
03693 if(body==NULL)
03694 {
03695 MMset(m, 0, NIL);
03696 return 0;
03697 }
03698
03699 SMaterialID* matID = (SMaterialID*) MMfetch(m, mat, 0);
03700 if(matID==NULL)
03701 {
03702 MMset(m, 0, NIL);
03703 return 0;
03704 }
03705
03706 body->SetMaterialID(matID->getOgreNewtMaterialID());
03707 MMset(m, 0, ITOM(1));
03708
03709 #ifdef SO3_DEBUG
03710 MMechostr(MSKDEBUG, "SO3BodySetMaterial: OK!\n");
03711 #endif
03712 return 0;
03713 }
03714
03715
03724 int SO3BodyGetMaterial(mmachine m)
03725 {
03726 #ifdef SO3_DEBUG
03727 MMechostr(MSKDEBUG,"SO3BodyGetMaterial\n");
03728 #endif
03729
03730 int bod = MMget(m, 0);
03731 if(bod==NIL)
03732 {
03733 MMechostr(MSKDEBUG, "one of the parameters is NIL!!\n");
03734 MMset(m, 0, NIL);
03735 return 0;
03736 }
03737
03738 SBody* body = (SBody*) MMfetch(m, MTOP(bod), 0);
03739 if(body==NULL)
03740 {
03741 MMset(m, 0, NIL);
03742 return 0;
03743 }
03744
03745 SScene* scene = body->GetParentNode()->GetParentScene();
03746 SMaterialID* matID = NULL;
03747 int id = body->GetMaterialID()->getID();
03748
03749 SMaterialIDMap::iterator iMaterialIDList = scene->GetPhysicsWorld()->listOfMaterialID.begin();
03750 while (iMaterialIDList != scene->GetPhysicsWorld()->listOfMaterialID.end())
03751 {
03752 SMaterialID* curMatID = iMaterialIDList->second;
03753 if(curMatID->getID()==id)
03754 matID = curMatID;
03755
03756 iMaterialIDList++;
03757 }
03758
03759 if(matID==NULL)
03760 {
03761 MMset(m, 0, NIL);
03762 return 0;
03763 }
03764
03765 int mat = OBJfindTH(m, SO3PHYSICSMATERIALTYPE, (int)(matID));
03766 if(mat!=NIL)
03767 mat = MMfetch(m, mat, OFFOBJMAG);
03768
03769 MMset(m, 0, mat);
03770 return 0;
03771 }
03772
03773
03783
03784 int SO3PhysicsMaterialCreate(mmachine m)
03785 {
03786 #ifdef SO3_DEBUG
03787 MMechostr(MSKDEBUG,"SO3PhysicsMaterialCreate\n");
03788 #endif
03789
03790 int nam = MMpull(m);
03791 int s = MMget(m, 0);
03792 if((s==NIL)||(nam==NIL))
03793 {
03794 MMset(m,0,NIL);
03795 return 0;
03796 }
03797
03798 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
03799 if(scene==NULL)
03800 {
03801 MMset(m, 0, NIL);
03802 return 0;
03803 }
03804
03805 string name = MMstartstr(m, MTOP(nam));
03806 if(name.empty())
03807 {
03808 MMset(m, 0, NIL);
03809 return 0;
03810 }
03811
03812
03813 SMaterialID* matID;
03814 if(MaterialIDExists(scene, name, &matID))
03815 {
03816 int a = OBJfindTH(m, SO3PHYSICSMATERIALTYPE, (int)(matID));
03817 if(a!=NIL)
03818 a = MMfetch(m, a, OFFOBJMAG);
03819
03820 MMset(m, 0, a);
03821 return 0;
03822 }
03823
03824
03825 MMpull(m);
03826
03827
03828 matID = scene->GetPhysicsWorld()->CreatePhysicMaterialID(name);
03829
03830
03831 SMaterialIDMap::iterator iMaterialIDList = scene->GetPhysicsWorld()->listOfMaterialID.begin();
03832 while (iMaterialIDList != scene->GetPhysicsWorld()->listOfMaterialID.end())
03833 {
03834 SMaterialPair* matPair = scene->GetPhysicsWorld()->CreatePhysicMaterialPair(matID, iMaterialIDList->second);
03835 createMaterialPair(m, matPair, scene);
03836
03837
03838 MMpull(m);
03839
03840 iMaterialIDList++;
03841 }
03842
03843 #ifdef SO3_DEBUG
03844 MMechostr(MSKDEBUG,"SO3PhysicsMaterialCreate : OK!\n");
03845 #endif
03846 return createMaterialID(m, matID, scene);
03847 }
03848
03849
03858 int SO3PhysicsMaterialDestroy(mmachine m)
03859 {
03860 #ifdef SO3_DEBUG
03861 MMechostr(MSKDEBUG,"SO3PhysicsMaterialDestroy\n");
03862 #endif
03863
03864 int mat = MMget(m, 0);
03865 if(mat==NIL)
03866 {
03867 MMset(m, 0, 0);
03868 return 0;
03869 }
03870
03871
03872 OBJdelTM(m, SO3PHYSICSMATERIALTYPE, mat);
03873
03874 MMset(m, 0, ITOM(1));
03875 #ifdef SO3_DEBUG
03876 MMechostr(MSKDEBUG,"SO3PhysicsMaterialDestroy : OK!\n");
03877 #endif
03878 return 0;
03879 }
03880
03881
03891 int SO3PhysicsGetMaterial(mmachine m)
03892 {
03893 #ifdef SO3_DEBUG
03894 MMechostr(MSKDEBUG,"SO3PhysicsGetMaterial\n");
03895 #endif
03896
03897 int name = MMpull(m);
03898 int s = MMget(m, 0);
03899 if((s==NIL)||(name==NIL))
03900 {
03901 MMechostr(MSKDEBUG, "one of the parameters is NIL!!\n");
03902 MMset(m, 0, NIL);
03903 return 0;
03904 }
03905
03906 SScene* scene = (SScene*) MMfetch(m, MTOP(s), 0);
03907 if(scene==NULL)
03908 {
03909 MMset(m, 0, NIL);
03910 return 0;
03911 }
03912
03913 string matname = MMstartstr(m,MTOP(name));
03914 #ifdef SO3_DEBUG
03915 MMechostr(MSKDEBUG,"Material Name : %s \n", matname.c_str());
03916 #endif
03917
03918 if(matname.empty())
03919 {
03920 MMset(m, 0, NIL);
03921 return 0;
03922 }
03923
03924 SMaterialID* matID = NULL;
03925 SMaterialIDMap::iterator iMaterialIDSearched = scene->GetPhysicsWorld()->listOfMaterialID.find(matname);
03926 if(iMaterialIDSearched != scene->GetPhysicsWorld()->listOfMaterialID.end())
03927 matID = iMaterialIDSearched->second;
03928
03929 if(matID == NULL)
03930 {
03931 MMechostr(MSKDEBUG, "Physic material not found\n");
03932 MMset(m, 0, NIL);
03933 return 0;
03934 }
03935
03936 int mat = OBJfindTH(m, SO3PHYSICSMATERIALTYPE, (int)(matID));
03937 if(mat!=NIL)
03938 mat = MMfetch(m, mat, OFFOBJMAG);
03939
03940 MMset(m, 0, mat);
03941 return 0;
03942 }
03943
03944
03955 int SO3PhysicsMaterialSetSurfaceThickness(mmachine m)
03956 {
03957 #ifdef SO3_DEBUG
03958 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetSurfaceThickness\n");
03959 #endif
03960
03961 int val = MMpull(m);
03962 int mat2 = MMpull(m);
03963 int mat1 = MMget(m, 0);
03964 if((mat1==NIL)||(mat2==NIL)||(val==NIL))
03965 {
03966 MMset(m, 0, NIL);
03967 return 0;
03968 }
03969
03970 SMaterialID* matID1 = (SMaterialID*) MMfetch(m, MTOP(mat1), 0);
03971 if(matID1==NULL)
03972 {
03973 MMset(m, 0, NIL);
03974 return 0;
03975 }
03976
03977 SMaterialID* matID2 = (SMaterialID*) MMfetch(m, MTOP(mat2), 0);
03978 if(matID2==NULL)
03979 {
03980 MMset(m, 0, NIL);
03981 return 0;
03982 }
03983
03984
03985 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld() ,matID1->getID(), matID2->getID());
03986 if(matPair == NULL)
03987 {
03988 MMset(m, 0, NIL);
03989 return 0;
03990 }
03991
03992 matPair->SetDefaultSurfaceThickness((Ogre::Real)(MTOF(val)));
03993 MMset(m, 0, ITOM(1));
03994 #ifdef SO3_DEBUG
03995 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetSurfaceThickness : OK!\n");
03996 #endif
03997 return 0;
03998 }
03999
04000
04011 int SO3PhysicsMaterialSetDefaultElasticity(mmachine m)
04012 {
04013 #ifdef SO3_DEBUG
04014 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetDefaultElasticity\n");
04015 #endif
04016
04017 int val = MMpull(m);
04018 int mat2 = MMpull(m);
04019 int mat1 = MMget(m, 0);
04020 if((mat1==NIL)||(mat2==NIL)||(val==NIL))
04021 {
04022 MMechostr(MSKDEBUG, "One of Paramter is NIL!!\n");
04023 MMset(m, 0, NIL);
04024 return 0;
04025 }
04026
04027 SMaterialID* matID1 = (SMaterialID*) MMfetch(m, MTOP(mat1), 0);
04028 if(matID1==NULL)
04029 {
04030 MMechostr(MSKDEBUG,"MatID1 is NULL!!\n");
04031 MMset(m, 0, NIL);
04032 return 0;
04033 }
04034
04035 SMaterialID* matID2 = (SMaterialID*) MMfetch(m, MTOP(mat2), 0);
04036 if(matID2==NULL)
04037 {
04038 MMechostr(MSKDEBUG, "MatID1 is NULL!!\n");
04039 MMset(m, 0, NIL);
04040 return 0;
04041 }
04042
04043
04044 SMaterialPair* matPair;
04045 matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
04046 if(matPair == NULL)
04047 {
04048 MMechostr(MSKDEBUG, "MAtPair is NULL!!\n");
04049 MMset(m, 0, NIL);
04050 return 0;
04051 }
04052 matPair->SetDefaultElasticity((Ogre::Real)(MTOF(val)));
04053
04054 MMset(m, 0, ITOM(1));
04055 #ifdef SO3_DEBUG
04056 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetDefaultElasticity : OK!\n");
04057 #endif
04058 return 0;
04059 }
04060
04061
04073 int SO3PhysicsMaterialSetDefaultFriction(mmachine m)
04074 {
04075 #ifdef SO3_DEBUG
04076 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetDefaultFriction\n");
04077 #endif
04078
04079 int val2 = MMpull(m);
04080 int val1 = MMpull(m);
04081 int mat2 = MMpull(m);
04082 int mat1 = MMget(m, 0);
04083 if((mat1==NIL)||(mat2==NIL)||(val1==NIL)||(val2==NIL))
04084 {
04085 MMset(m, 0, NIL);
04086 return 0;
04087 }
04088
04089 SMaterialID* matID1 = (SMaterialID*) MMfetch(m, MTOP(mat1), 0);
04090 if(matID1==NULL)
04091 {
04092 MMset(m, 0, NIL);
04093 return 0;
04094 }
04095
04096 SMaterialID* matID2 = (SMaterialID*) MMfetch(m, MTOP(mat2), 0);
04097 if(matID2==NULL)
04098 {
04099 MMset(m, 0, NIL);
04100 return 0;
04101 }
04102
04103
04104 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
04105 if(matPair == NULL)
04106 {
04107 MMset(m, 0, NIL);
04108 return 0;
04109 }
04110 matPair->SetDefaultFriction((Ogre::Real)(MTOF(val1)), (Ogre::Real)(MTOF(val2)));
04111
04112 MMset(m, 0, ITOM(1));
04113 return 0;
04114 }
04115
04116
04127 int SO3PhysicsMaterialSetDefaultSoftness(mmachine m)
04128 {
04129 #ifdef SO3_DEBUG
04130 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetDefaultSoftness\n");
04131 #endif
04132
04133 int val = MMpull(m);
04134 int mat2 = MMpull(m);
04135 int mat1 = MMget(m, 0);
04136 if((mat1==NIL)||(mat2==NIL)||(val==NIL))
04137 {
04138 MMechostr(MSKDEBUG, "One of Paramter is NIL!!\n");
04139 MMset(m, 0, NIL);
04140 return 0;
04141 }
04142
04143 SMaterialID* matID1 = (SMaterialID*) MMfetch(m, MTOP(mat1), 0);
04144 if(matID1==NULL)
04145 {
04146 MMset(m, 0, NIL);
04147 return 0;
04148 }
04149
04150 SMaterialID* matID2 = (SMaterialID*) MMfetch(m, MTOP(mat2), 0);
04151 if(matID2==NULL)
04152 {
04153 MMset(m, 0, NIL);
04154 return 0;
04155 }
04156
04157
04158 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
04159 if(matPair == NULL)
04160 {
04161 MMset(m, 0, NIL);
04162 return 0;
04163 }
04164 matPair->SetDefaultSoftness((Ogre::Real)(MTOF(val)));
04165
04166 MMset(m, 0, ITOM(1));
04167 return 0;
04168 }
04169
04170
04181 int SO3PhysicsMaterialSetDefaultCollidable(mmachine m)
04182 {
04183 #ifdef SO3_DEBUG
04184 MMechostr(MSKDEBUG,"SO3PhysicsMaterialSetDefaultCollidable\n");
04185 #endif
04186
04187 int val = MMpull(m);
04188 int mat2 = MMpull(m);
04189 int mat1 = MMget(m,0);
04190 if((mat1==NIL)||(mat2==NIL)||(val==NIL))
04191 {
04192 MMechostr(MSKDEBUG, "One of Paramter is NIL!!\n");
04193 MMset(m, 0, NIL);
04194 return 0;
04195 }
04196
04197 SMaterialID* matID1 = (SMaterialID*) MMfetch(m, MTOP(mat1), 0);
04198 if(matID1==NULL)
04199 {
04200 MMset(m, 0, NIL);
04201 return 0;
04202 }
04203
04204 SMaterialID* matID2 = (SMaterialID*) MMfetch(m, MTOP(mat2), 0);
04205 if(matID2==NULL)
04206 {
04207 MMset(m, 0, NIL);
04208 return 0;
04209 }
04210
04211
04212 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
04213 if(matPair == NULL)
04214 {
04215 MMset(m, 0, NIL);
04216 return 0;
04217 }
04218
04219 bool coll = false;
04220 if (MTOI(val) == 1)
04221 coll = true;
04222
04223 matPair->SetDefaultCollidable(coll);
04224
04225 MMset(m, 0, ITOM(1));
04226 return 0;
04227 }
04228
04229
04240 int SO3PhysicsMaterialSetContiniousCollisionMode(mmachine m)
04241 {
04242 #ifdef SO3_DEBUG
04243 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetContiniousCollisionMode\n");
04244 #endif
04245 int val = MMpull(m);
04246 int mat2 = MMpull(m);
04247 int mat1 = MMget(m, 0);
04248
04249 if((mat1==NIL))
04250 {
04251 MMechostr(MSKDEBUG, "mat1 is NIL!!\n");
04252 MMset(m, 0, NIL);
04253 return 0;
04254 }
04255
04256 if((mat2==NIL))
04257 {
04258 MMechostr(MSKDEBUG, "mat2 is NIL!!\n");
04259 MMset(m, 0, NIL);
04260 return 0;
04261 }
04262
04263 if(val==NIL)
04264 {
04265 MMechostr(MSKDEBUG, "val is NIL!!\n");
04266 MMset(m, 0, NIL);
04267 return 0;
04268 }
04269
04270 SMaterialID* matID1 = (SMaterialID*) MMfetch(m, MTOP(mat1), 0);
04271 if(matID1==NULL)
04272 {
04273 MMset(m, 0, NIL);
04274 return 0;
04275 }
04276
04277 SMaterialID* matID2 = (SMaterialID*) MMfetch(m, MTOP(mat2), 0);
04278 if(matID2==NULL)
04279 {
04280 MMset(m, 0, NIL);
04281 return 0;
04282 }
04283
04284
04285 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
04286 if(matPair == NULL)
04287 {
04288 MMset(m, 0, NIL);
04289 return 0;
04290 }
04291
04292 bool coll = false;
04293 if (MTOI(val) == 1)
04294 coll = true;
04295
04296 matPair->SetContinuousCollisionMode(coll);
04297 MMset(m, 0, ITOM(1));
04298 return 0;
04299 }
04300
04301
04320 int SO3CbMaterialCollision ( mmachine m )
04321 {
04322 #if SO3_DEBUG == 1
04323 MMechostr(MSKDEBUG,"SO3CbMaterialCollision\n");
04324 #endif
04325 int k;
04326
04327 int pUser = MMpull(m);
04328 int pCbk = MMpull(m);
04329 int mat2 = MMpull(m);
04330 int mat1 = MMpull(m);
04331
04332
04333 if(mat1 == NIL)
04334 {
04335 MMechostr(0, "SO3CbMaterialCollision error : mat1 is nil...\n");
04336 MMpush(m, NIL);
04337 return 0;
04338 }
04339
04340
04341 if(mat2 == NIL)
04342 {
04343 MMechostr(0, "SO3CbMaterialCollision error : mat2 is nil...\n");
04344 MMpush(m, NIL);
04345 return 0;
04346 }
04347
04348 SMaterialID* matID1 = (SMaterialID*) MMfetch(m, MTOP(mat1), 0);
04349 if(matID1==NULL)
04350 {
04351 MMpush(m, NIL);
04352 return 0;
04353 }
04354
04355 SMaterialID* matID2 = (SMaterialID*) MMfetch(m, MTOP(mat2), 0);
04356 if(matID2==NULL)
04357 {
04358 MMpush(m, NIL);
04359 return 0;
04360 }
04361
04362
04363 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
04364 if(matPair == NULL)
04365 {
04366 MMpush(m, NIL);
04367 return 0;
04368 }
04369
04370 if (pCbk == NIL)
04371 {
04372 matPair->SetContactCallbackActivated(false);
04373 }
04374 else
04375 {
04376 matPair->SetContactCallbackActivated(true);
04377 }
04378
04379 int ob = MMfetch(m, OBJfindTH(m, SO3PHYSICSMATERIALPAIR, (int)(matPair)), OFFOBJMAG);
04380 if(ob == NIL)
04381 {
04382 matPair->SetContactCallbackActivated(false);
04383 MMpush(m, NIL);
04384 return 0;
04385 }
04386
04387
04388
04389
04390
04391
04392 MMpush(m,ob);
04393 MMpush(m,pCbk);
04394 MMpush(m,pUser);
04395
04396 k = OBJaddreflex(m, SO3PHYSICSMATERIALPAIR, SO3_MATERIALPAIR_COLLISION);
04397
04398 MMset(m, 0, ITOM(1));
04399
04400 #if SO3_DEBUG == 1
04401 MMechostr(MSKDEBUG, "SO3CbMaterialCollision : OK!\n");
04402 #endif
04403 return 0;
04404 }
04405
04406
04421 int SO3CbMaterialOverlapStarted(mmachine m)
04422 {
04423 #ifdef SO3_DEBUG
04424 MMechostr(MSKDEBUG, "SO3CbMaterialOverlapStarted\n");
04425 #endif
04426
04427 int k;
04428 int pUser = MMpull(m);
04429 int pCbk = MMpull(m);
04430 int mat2 = MMpull(m);
04431 int mat1 = MMpull(m);
04432
04433
04434 if(mat1 == NIL)
04435 {
04436 MMechostr (0, "SO3CbMaterialOverlapStarted error : mat1 is nil...\n");
04437 MMpush(m, NIL);
04438 return 0;
04439 }
04440
04441
04442 if(mat2 == NIL)
04443 {
04444 MMechostr (0, "SO3CbMaterialOverlapStarted error : mat2 is nil...\n");
04445 MMpush(m, NIL);
04446 return 0;
04447 }
04448
04449 SMaterialID* matID1 = (SMaterialID*) MMfetch(m, MTOP(mat1), 0);
04450 if(matID1==NULL)
04451 {
04452 MMpush(m, NIL);
04453 return 0;
04454 }
04455
04456 SMaterialID* matID2 = (SMaterialID*) MMfetch(m, MTOP(mat2), 0);
04457 if(matID2==NULL)
04458 {
04459 MMpush(m, NIL);
04460 return 0;
04461 }
04462
04463
04464 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
04465 if(matPair == NULL)
04466 {
04467 MMpush(m, NIL);
04468 return 0;
04469 }
04470
04471 if (pCbk == NIL)
04472 {
04473 matPair->SetOverlapStartedCallbackActivated(false);
04474 }
04475 else
04476 {
04477 matPair->SetOverlapStartedCallbackActivated(true);
04478 }
04479
04480 int ob = MMfetch(m, OBJfindTH(m, SO3PHYSICSMATERIALPAIR, (int)(matPair)), OFFOBJMAG);
04481 if(ob == NIL)
04482 {
04483 matPair->SetOverlapStartedCallbackActivated(false);
04484 MMpush(m, NIL);
04485 return 0;
04486 }
04487
04488
04489
04490
04491
04492
04493 MMpush(m,ob);
04494 MMpush(m,pCbk);
04495 MMpush(m,pUser);
04496
04497 k = OBJaddreflex(m, SO3PHYSICSMATERIALPAIR, SO3_MATERIALPAIR_OVERLAP_STARTED);
04498
04499 MMset(m, 0, ITOM(1));
04500
04501 #ifdef SO3_DEBUG
04502 MMechostr(MSKDEBUG, "SO3CbMaterialOverlapStarted : OK!\n");
04503 #endif
04504 return 0;
04505 }
04506
04507
04522 int SO3CbMaterialOverlapEnded(mmachine m)
04523 {
04524 #ifdef SO3_DEBUG
04525 MMechostr(MSKDEBUG, "SO3CbMaterialOverlapEnded\n");
04526 #endif
04527
04528 int k;
04529 int pUser = MMpull(m);
04530 int pCbk = MMpull(m);
04531 int mat2 = MMpull(m);
04532 int mat1 = MMpull(m);
04533
04534
04535 if(mat1 == NIL)
04536 {
04537 MMechostr (0, "SO3CbMaterialOverlapStarted error : mat1 is nil...\n");
04538 MMpush(m, NIL);
04539 return 0;
04540 }
04541
04542
04543 if(mat2 == NIL)
04544 {
04545 MMechostr (0, "SO3CbMaterialOverlapStarted error : mat2 is nil...\n");
04546 MMpush(m, NIL);
04547 return 0;
04548 }
04549
04550 SMaterialID* matID1 = (SMaterialID*) MMfetch(m, MTOP(mat1), 0);
04551 if(matID1==NULL)
04552 {
04553 MMpush(m, NIL);
04554 return 0;
04555 }
04556
04557 SMaterialID* matID2 = (SMaterialID*) MMfetch(m, MTOP(mat2), 0);
04558 if(matID2==NULL)
04559 {
04560 MMpush(m, NIL);
04561 return 0;
04562 }
04563
04564
04565 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
04566 if(matPair == NULL)
04567 {
04568 MMpush(m, NIL);
04569 return 0;
04570 }
04571
04572 if (pCbk == NIL)
04573 {
04574 matPair->SetOverlapEndedCallbackActivated(false);
04575 }
04576 else
04577 {
04578 matPair->SetOverlapEndedCallbackActivated(true);
04579 }
04580
04581 int ob = MMfetch(m, OBJfindTH(m, SO3PHYSICSMATERIALPAIR, (int)(matPair)), OFFOBJMAG);
04582 if(ob == NIL)
04583 {
04584 matPair->SetOverlapEndedCallbackActivated(false);
04585 MMpush(m, NIL);
04586 return 0;
04587 }
04588
04589
04590
04591
04592
04593
04594 MMpush(m,ob);
04595 MMpush(m,pCbk);
04596 MMpush(m,pUser);
04597
04598 k = OBJaddreflex(m, SO3PHYSICSMATERIALPAIR, SO3_MATERIALPAIR_OVERLAP_ENDED);
04599
04600 MMset(m, 0, ITOM(1));
04601
04602 #ifdef SO3_DEBUG
04603 MMechostr(MSKDEBUG, "SO3CbMaterialOverlapEnded : OK!\n");
04604 #endif
04605 return 0;
04606 }
04607
04608
04621 int SO3CbBodyLeaveWorld(mmachine m)
04622 {
04623 #ifdef SO3_DEBUG
04624 MMechostr(MSKDEBUG, "SO3CbBodyLeaveWorld\n");
04625 #endif
04626
04627 return OBJaddreflex(m, SO3PHYSICBODY, SO3_BODY_LEAVE_WORLD);
04628 }
04629
04630
04634 #define NBPHYSICSPKG 83
04635
04636
04640 char* PHYSICSname[NBPHYSICSPKG]=
04641 {
04642 "SO3WorldSetFrictionModel",
04643 "SO3WorldGetFrictionModel",
04644 "SO3WorldSetPlateformArchitecture",
04645 "SO3WorldGetPlateformArchitecture",
04646 "SO3WorldSetSolverModel",
04647 "SO3WorldGetSolverModel",
04648 "SO3WorldSetEnabled",
04649 "SO3WorldGetEnabled",
04650 "SO3WorldShowLines",
04651 "SO3WorldSetGravity",
04652 "SO3WorldGetGravity",
04653 "SO3WorldReset",
04654 "SO3WorldSetBodiesInitialState",
04655 "SO3BodyCreateBox",
04656 "SO3BodyCreateEllipsoid",
04657 "SO3BodyCreateCapsule",
04658 "SO3BodyCreateChamferCylinder",
04659 "SO3BodyCreateCone",
04660 "SO3BodyCreateCylinder",
04661 "SO3BodyCreatePyramid",
04662 "SO3BodyCreateCollisionTree",
04663 "SO3BodyCreateShape",
04664 "SO3BodySetMass",
04665 "SO3BodyCreateBasicJointUpVector",
04666 "SO3BodyDestroyBasicJointUpVector",
04667 "SO3BodySetForce",
04668 "SO3BodyAddForce",
04669 "SO3BodyGetForce",
04670 "SO3BodyAddGlobalForce",
04671 "SO3BodyAddLocalForce",
04672 "SO3BodyAddTorque",
04673 "SO3BodySetTorque",
04674 "SO3BodySetOmega",
04675 "SO3BodySetVelocity",
04676 "SO3BodyAddImpulse",
04677 "SO3BodySetPositionOrientation",
04678 "SO3BodySetAngularDamping",
04679 "SO3BodySetCenterOfMass",
04680 "SO3BodySetMassMatrix",
04681 "SO3BodyGetAngularDamping",
04682 "SO3BodyGetOmega",
04683 "SO3BodyGetTorque",
04684 "SO3BodySetConstantForce",
04685 "SO3BodyAddConstantForce",
04686 "SO3BodyGetConstantForce",
04687 "SO3BodySetConstantTorque",
04688 "SO3BodyAddConstantTorque",
04689 "SO3BodyGetConstantTorque",
04690 "SO3BodySetLinearDamping",
04691 "SO3BodySetAutoSleep",
04692 "SO3BodySetType",
04693 "SO3BodySetContiniousCollisionMode",
04694 "SO3BodyGetLinearDamping",
04695 "SO3BodyGetInvMass",
04696 "SO3BodyGetMassMatrix",
04697 "SO3BodyGetAutoSleep",
04698 "SO3BodyGetSleepingState",
04699 "SO3BodyGetType",
04700 "SO3BodyGetContiniousCollisionMode",
04701 "SO3BodyGetCenterOfMass",
04702 "SO3BodyGetVelocity",
04703 "SO3BodyGetPositionOrientation",
04704 "SO3BodySetFreeze",
04705 "SO3BodyGetFreeze",
04706 "SO3BodyGetSceneNode",
04707 "SO3BodyDestroy",
04708 "SO3SceneNodeGetBody",
04709 "SO3BodySetMaterial",
04710 "SO3BodyGetMaterial",
04711 "SO3PhysicsMaterialCreate",
04712 "SO3PhysicsMaterialDestroy",
04713 "SO3PhysicsMaterialSetDefaultElasticity",
04714 "SO3PhysicsMaterialSetDefaultFriction",
04715 "SO3PhysicsMaterialSetDefaultSoftness",
04716 "SO3PhysicsMaterialSetDefaultCollidable",
04717 "SO3PhysicsMaterialSetSurfaceThickness",
04718 "SO3PhysicsMaterialSetContiniousCollisionMode",
04719 "SO3CbMaterialCollision",
04720 "SO3CbMaterialOverlapStarted",
04721 "SO3CbMaterialOverlapEnded",
04722 "SO3CbBodyLeaveWorld",
04723 "SO3PhysicsGetMaterial",
04724 "SO3PhysicsRayCast"
04725 };
04726
04727
04731 int (*PHYSICSFunc[NBPHYSICSPKG])(mmachine m)=
04732 {
04733 SO3WorldSetFrictionModel,
04734 SO3WorldGetFrictionModel,
04735 SO3WorldSetPlateformArchitecture,
04736 SO3WorldGetPlateformArchitecture,
04737 SO3WorldSetSolverModel,
04738 SO3WorldGetSolverModel,
04739 SO3WorldSetEnabled,
04740 SO3WorldGetEnabled,
04741 SO3WorldShowLines,
04742 SO3WorldSetGravity,
04743 SO3WorldGetGravity,
04744 SO3WorldReset,
04745 SO3WorldSetBodiesInitialState,
04746 SO3BodyCreateBox,
04747 SO3BodyCreateEllipsoid,
04748 SO3BodyCreateCapsule,
04749 SO3BodyCreateChamferCylinder,
04750 SO3BodyCreateCone,
04751 SO3BodyCreateCylinder,
04752 SO3BodyCreatePyramid,
04753 SO3BodyCreateCollisionTree,
04754 SO3BodyCreateShape,
04755 SO3BodySetMass,
04756 SO3BodyCreateBasicJointUpVector,
04757 SO3BodyDestroyBasicJointUpVector,
04758 SO3BodySetForce,
04759 SO3BodyAddForce,
04760 SO3BodyGetForce,
04761 SO3BodyAddGlobalForce,
04762 SO3BodyAddLocalForce,
04763 SO3BodyAddTorque,
04764 SO3BodySetTorque,
04765 SO3BodySetOmega,
04766 SO3BodySetVelocity,
04767 SO3BodyAddImpulse,
04768 SO3BodySetPositionOrientation,
04769 SO3BodySetAngularDamping,
04770 SO3BodySetCenterOfMass,
04771 SO3BodySetMassMatrix,
04772 SO3BodyGetAngularDamping,
04773 SO3BodyGetOmega,
04774 SO3BodyGetTorque,
04775 SO3BodySetConstantForce,
04776 SO3BodyAddConstantForce,
04777 SO3BodyGetConstantForce,
04778 SO3BodySetConstantTorque,
04779 SO3BodyAddConstantTorque,
04780 SO3BodyGetConstantTorque,
04781 SO3BodySetLinearDamping,
04782 SO3BodySetAutoSleep,
04783 SO3BodySetType,
04784 SO3BodySetContiniousCollisionMode,
04785 SO3BodyGetLinearDamping,
04786 SO3BodyGetInvMass,
04787 SO3BodyGetMassMatrix,
04788 SO3BodyGetAutoSleep,
04789 SO3BodyGetSleepingState,
04790 SO3BodyGetType,
04791 SO3BodyGetContiniousCollisionMode,
04792 SO3BodyGetCenterOfMass,
04793 SO3BodyGetVelocity,
04794 SO3BodyGetPositionOrientation,
04795 SO3BodySetFreeze,
04796 SO3BodyGetFreeze,
04797 SO3BodyGetSceneNode,
04798 SO3BodyDestroy,
04799 SO3SceneNodeGetBody,
04800 SO3BodySetMaterial,
04801 SO3BodyGetMaterial,
04802 SO3PhysicsMaterialCreate,
04803 SO3PhysicsMaterialDestroy,
04804 SO3PhysicsMaterialSetDefaultElasticity,
04805 SO3PhysicsMaterialSetDefaultFriction,
04806 SO3PhysicsMaterialSetDefaultSoftness,
04807 SO3PhysicsMaterialSetDefaultCollidable,
04808 SO3PhysicsMaterialSetSurfaceThickness,
04809 SO3PhysicsMaterialSetContiniousCollisionMode,
04810 SO3CbMaterialCollision,
04811 SO3CbMaterialOverlapStarted,
04812 SO3CbMaterialOverlapEnded,
04813 SO3CbBodyLeaveWorld,
04814 SO3PhysicsGetMaterial,
04815 SO3PhysicsRayCast
04816 };
04817
04818
04822 int PHYSICSnarg[NBPHYSICSPKG]=
04823 {
04824 2,
04825 1,
04826 2,
04827 1,
04828 2,
04829 1,
04830 2,
04831 1,
04832 2,
04833 2,
04834 1,
04835 1,
04836 1,
04837 2,
04838 2,
04839 3,
04840 3,
04841 3,
04842 3,
04843 2,
04844 2,
04845 2,
04846 2,
04847 2,
04848 1,
04849 2,
04850 2,
04851 1,
04852 2,
04853 2,
04854 2,
04855 2,
04856 2,
04857 2,
04858 3,
04859 3,
04860 2,
04861 2,
04862 3,
04863 1,
04864 1,
04865 1,
04866 2,
04867 2,
04868 1,
04869 2,
04870 2,
04871 1,
04872 2,
04873 2,
04874 2,
04875 2,
04876 1,
04877 1,
04878 1,
04879 1,
04880 1,
04881 1,
04882 1,
04883 1,
04884 1,
04885 1,
04886 2,
04887 1,
04888 1,
04889 1,
04890 1,
04891 2,
04892 1,
04893 2,
04894 1,
04895 3,
04896 4,
04897 3,
04898 3,
04899 3,
04900 3,
04901 4,
04902 4,
04903 4,
04904 3,
04905 2,
04906 4
04907 };
04908
04909
04913 char* PHYSICSType[NBPHYSICSPKG]=
04914 {
04915 "fun [SO3_SCENE I] I",
04916 "fun [SO3_SCENE] I",
04917 "fun [SO3_SCENE I] I",
04918 "fun [SO3_SCENE] I",
04919 "fun [SO3_SCENE I] I",
04920 "fun [SO3_SCENE] I",
04921 "fun [SO3_SCENE I] I",
04922 "fun [SO3_SCENE] I",
04923 "fun [SO3_SCENE I] I",
04924 "fun [SO3_SCENE [F F F]] I",
04925 "fun [SO3_SCENE] [F F F]",
04926 "fun [SO3_SCENE] I",
04927 "fun [SO3_SCENE] I",
04928 "fun [SO3_OBJECT [F F F]] SO3_PHYSICBODY",
04929 "fun [SO3_OBJECT [F F F]] SO3_PHYSICBODY",
04930 "fun [SO3_OBJECT F F] SO3_PHYSICBODY",
04931 "fun [SO3_OBJECT F F] SO3_PHYSICBODY",
04932 "fun [SO3_OBJECT F F] SO3_PHYSICBODY",
04933 "fun [SO3_OBJECT F F] SO3_PHYSICBODY",
04934 "fun [SO3_OBJECT [F F F]] SO3_PHYSICBODY",
04935 "fun [SO3_OBJECT I] SO3_PHYSICBODY",
04936 "fun [SO3_OBJECT F] SO3_PHYSICBODY",
04937 "fun [SO3_PHYSICBODY F] I",
04938 "fun [SO3_PHYSICBODY [F F F]] I",
04939 "fun [SO3_PHYSICBODY] I",
04940 "fun [SO3_PHYSICBODY [F F F]] I",
04941 "fun [SO3_PHYSICBODY [F F F]] I",
04942 "fun [SO3_PHYSICBODY] [F F F]",
04943 "fun [SO3_PHYSICBODY [F F F]] I",
04944 "fun [SO3_PHYSICBODY [F F F]] I",
04945 "fun [SO3_PHYSICBODY [F F F]] I",
04946 "fun [SO3_PHYSICBODY [F F F]] I",
04947 "fun [SO3_PHYSICBODY [F F F]] I",
04948 "fun [SO3_PHYSICBODY [F F F]] I",
04949 "fun [SO3_PHYSICBODY [F F F] [F F F]] I",
04950 "fun [SO3_PHYSICBODY [F F F] [F F F F]] I",
04951 "fun [SO3_PHYSICBODY [F F F]] I",
04952 "fun [SO3_PHYSICBODY [F F F]] I",
04953 "fun [SO3_PHYSICBODY F [F F F]] I",
04954 "fun [SO3_PHYSICBODY] [F F F]",
04955 "fun [SO3_PHYSICBODY] [F F F]",
04956 "fun [SO3_PHYSICBODY] [F F F]",
04957 "fun [SO3_PHYSICBODY [F F F]] I",
04958 "fun [SO3_PHYSICBODY [F F F]] I",
04959 "fun [SO3_PHYSICBODY] [F F F]",
04960 "fun [SO3_PHYSICBODY [F F F]] I",
04961 "fun [SO3_PHYSICBODY [F F F]] I",
04962 "fun [SO3_PHYSICBODY] [F F F]",
04963 "fun [SO3_PHYSICBODY F] I",
04964 "fun [SO3_PHYSICBODY I] I",
04965 "fun [SO3_PHYSICBODY I] I",
04966 "fun [SO3_PHYSICBODY I] I",
04967 "fun [SO3_PHYSICBODY] F",
04968 "fun [SO3_PHYSICBODY] [F [F F F]]",
04969 "fun [SO3_PHYSICBODY] [F [F F F]]",
04970 "fun [SO3_PHYSICBODY] I",
04971 "fun [SO3_PHYSICBODY] I",
04972 "fun [SO3_PHYSICBODY] I",
04973 "fun [SO3_PHYSICBODY] I",
04974 "fun [SO3_PHYSICBODY] [F F F]",
04975 "fun [SO3_PHYSICBODY] [F F F]",
04976 "fun [SO3_PHYSICBODY] [[F F F] [F F F F]]",
04977 "fun [SO3_PHYSICBODY I] I",
04978 "fun [SO3_PHYSICBODY] I",
04979 "fun [SO3_PHYSICBODY] SO3_OBJECT",
04980 "fun [SO3_PHYSICBODY] I",
04981 "fun [SO3_OBJECT] SO3_PHYSICBODY",
04982 "fun [SO3_PHYSICBODY SO3_PHYSICMATERIAL] I",
04983 "fun [SO3_PHYSICBODY] SO3_PHYSICMATERIAL",
04984 "fun [SO3_SCENE S] SO3_PHYSICMATERIAL",
04985 "fun [SO3_PHYSICMATERIAL] I",
04986 "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL F] I",
04987 "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL F F] I",
04988 "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL F] I",
04989 "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL I] I",
04990 "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL F] I",
04991 "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL I] I",
04992 "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL fun [SO3_SCENE u0 SO3_PHYSICBODY SO3_PHYSICBODY [F F F] [F F F] [F F F] F] u1 u0 ] I",
04993 "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL fun [SO3_SCENE u0 SO3_PHYSICBODY SO3_PHYSICBODY] u1 u0 ] I",
04994 "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL fun [SO3_SCENE u0 SO3_PHYSICBODY SO3_PHYSICBODY] u1 u0 ] I",
04995 "fun [SO3_PHYSICBODY fun [SO3_PHYSICBODY u0] u1 u0] SO3_PHYSICBODY",
04996 "fun [SO3_SCENE S] SO3_PHYSICMATERIAL",
04997 "fun [SO3_SCENE [F F F] [F F F] F] [SO3_PHYSICBODY F [F F F]]"
04998 };
04999
05000
05006 int SCOLloadPhysics(mmachine m,cbmachine w)
05007 {
05008
05009
05010 SO3_MATERIALPAIR_OVERLAP_STARTED_MSG = OBJgetUserEvent();
05011 OBJdefEvent(SO3_MATERIALPAIR_OVERLAP_STARTED_MSG, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getMaterialOverlapStartedCallback);
05012 SO3_MATERIALPAIR_OVERLAP_ENDED_MSG = OBJgetUserEvent();
05013 OBJdefEvent(SO3_MATERIALPAIR_OVERLAP_ENDED_MSG, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getMaterialOverlapEndedCallback);
05014 SO3_MATERIALPAIR_COLLISION_MSG = OBJgetUserEvent();
05015 OBJdefEvent(SO3_MATERIALPAIR_COLLISION_MSG, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getMaterialContactCallback);
05016 SO3_BODY_LEAVE_WORLD_MSG = OBJgetUserEvent();
05017 OBJdefEvent(SO3_BODY_LEAVE_WORLD_MSG, (int (__cdecl *)(struct Mmachine *,int,unsigned int,int,int,int *))getBodyLeaveWorldCallback);
05018 return PKhardpak(m, "Physics", NBPHYSICSPKG, PHYSICSname, PHYSICSFunc, PHYSICSnarg, PHYSICSType);
05019 }
05020
05021
05026 int SCOLfreePhysics()
05027 {
05028 return 0;
05029 }
05030