SO3Engine
SCOLPhysics.cpp
Go to the documentation of this file.
1/*
2-----------------------------------------------------------------------------
3This source file is part of OpenSpace3D
4For the latest info, see http://www.openspace3d.com
5
6Copyright (c) 2012 I-maginer
7
8This program is free software; you can redistribute it and/or modify it under
9the terms of the GNU Lesser General Public License as published by the Free Software
10Foundation; either version 2 of the License, or (at your option) any later
11version.
12
13This program is distributed in the hope that it will be useful, but WITHOUT
14ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
15FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
16
17You should have received a copy of the GNU Lesser General Public License along with
18this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19Place - Suite 330, Boston, MA 02111-1307, USA, or go to
20http://www.gnu.org/copyleft/lesser.txt
21
22-----------------------------------------------------------------------------
23*/
24
25
33#include "SCOLPack/SO3SCOL.h"
34
35// Physic includes
37
48
54
57
58// Renderer includes
59#include "SO3Renderer/SO3Root.h"
60
61// Scene Graph includes
64
68//int SO3_BODY_LEAVE_WORLD_MSG;
69
81/*int getBodyLeaveWorldCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE objm)
82{
83#ifdef SO3_DEBUG
84MMechostr(MSKDEBUG, "getBodyLeaveWorldCallback\n");
85#endif
86
87int k , res;
88res = 0;
89if(!(k = OBJbeginreflex(m, SO3PHYSICBODY, id, SO3_BODY_LEAVE_WORLD)))
90res = OBJcallreflex(m, 0);
91
92return res;
93}*/
94
106int getMaterialContactCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
107{
108#ifdef SO3_DEBUG
109 MMechostr(MSKDEBUG, "getMaterialContactCallback\n");
110#endif
111
112 int obj, res;
113 res = 0;
114 MCOLL* result = (MCOLL*)param;
115 SNode* node0 = result->curScene->GetNode(result->node0);
116 SNode* node1 = result->curScene->GetNode(result->node1);
117
118 if ((node0 == 0) || (node1 == 0))
119 return 0;
120
121 if (node0->GetSceneNodeBody() == NULL || node1->GetSceneNodeBody() == NULL)
122 return 0;
123
124 // equal to OBJbeginreflex
125 // is there a callback assigned to the object?
126 obj = OBJfindTH(m, SO3PHYSICSMATERIALPAIR, id);
127 if (obj == NIL)
128 return -1;
129
130 if (MMfetch(m, obj, OFFOBJREF0 + SO3_MATERIALPAIR_COLLISION * 2) == NIL)
131 return -1;
132
133 // retrieve scene magma
134 int s = MMfetch(m, OBJfindTH(m, SO3SCENETYPE, SCOL_PTR(result->curScene)), OFFOBJMAG);
135
136 int pos = MMmalloc(m, 3, TYPETAB);
137 if (pos == NIL)
138 return MERRMEM;
139
140 int norm = MMmalloc(m, 3, TYPETAB);
141 if (norm == NIL)
142 return MERRMEM;
143
144 int force = MMmalloc(m, 3, TYPETAB);
145 if (force == NIL)
146 return MERRMEM;
147
148 //equal to OBJpreparereflex but replace the object
149 MMsetglobal(m, OFFSCCUR, MMfetch(m, obj, OFFOBJCHN));
150 if (MMpush(m, MMgetglobal(m, OFFSCCUR))) return MERRMEM;
151 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0 + SO3_MATERIALPAIR_COLLISION * 2))) return MERRMEM;
152 if (MMpush(m, s)) return MERRMEM;
153 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0 + SO3_MATERIALPAIR_COLLISION * 2 + 1))) return MERRMEM;
154
155 int b0 = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, SCOL_PTR(node0->GetSceneNodeBody())), OFFOBJMAG);
156 int b1 = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, SCOL_PTR(node1->GetSceneNodeBody())), OFFOBJMAG);
157
158 MMpush(m, b0);
159 MMpush(m, b1);
160
161 MMstore(m, pos, 0, FTOM(result->position.x));
162 MMstore(m, pos, 1, FTOM(result->position.y));
163 MMstore(m, pos, 2, FTOM(result->position.z));
164
165 MMpush(m, PTOM(pos));
166
167 MMstore(m, norm, 0, FTOM(result->normal.x));
168 MMstore(m, norm, 1, FTOM(result->normal.y));
169 MMstore(m, norm, 2, FTOM(result->normal.z));
170 MMpush(m, PTOM(norm));
171
172 MMstore(m, force, 0, FTOM(result->force.x));
173 MMstore(m, force, 1, FTOM(result->force.y));
174 MMstore(m, force, 2, FTOM(result->force.z));
175 MMpush(m, PTOM(force));
176 MMpush(m, FTOM(result->normalspeed));
177
178 res = OBJcallreflex(m, 6);
179 return res;
180}
181
182
194int getMaterialOverlapStartedCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
195{
196#ifdef SO3_DEBUG
197 MMechostr(MSKDEBUG, "getMaterialOverlapStartedCallback\n");
198#endif
199
200 int obj, res;
201 MCOLL* result = (MCOLL*)param;
202 SNode* node0 = result->curScene->GetNode(result->node0);
203 SNode* node1 = result->curScene->GetNode(result->node1);
204
205 if ((node0 == 0) || (node1 == 0))
206 return 0;
207
208 // equal to OBJbeginreflex
209 // is there a callback assigned to the object?
210 obj = OBJfindTH(m, SO3PHYSICSMATERIALPAIR, id);
211 if (obj == NIL)
212 return -1;
213
214 if (MMfetch(m, obj, OFFOBJREF0 + SO3_MATERIALPAIR_OVERLAP_STARTED * 2) == NIL)
215 return -1;
216
217 // retrieve scene magma
218 int s = MMfetch(m, OBJfindTH(m, SO3SCENETYPE, SCOL_PTR(result->curScene)), OFFOBJMAG);
219
220 //equal to OBJpreparereflex but replace the object
221 MMsetglobal(m, OFFSCCUR, MMfetch(m, obj, OFFOBJCHN));
222 if (MMpush(m, MMgetglobal(m, OFFSCCUR))) return MERRMEM;
223 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0 + SO3_MATERIALPAIR_OVERLAP_STARTED * 2))) return MERRMEM;
224 if (MMpush(m, s)) return MERRMEM;
225 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0 + SO3_MATERIALPAIR_OVERLAP_STARTED * 2 + 1))) return MERRMEM;
226
227 if (node0->GetSceneNodeBody() == NULL)
228 {
229 MMpush(m, NIL);
230 MMpush(m, NIL);
231 MMpush(m, NIL);
232 return 0;
233 }
234 if (node1->GetSceneNodeBody() == NULL)
235 {
236 MMpush(m, NIL);
237 MMpush(m, NIL);
238 MMpush(m, NIL);
239 return 0;
240 }
241 int b0 = 0;
242 int b1 = 0;
243
244 b0 = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, SCOL_PTR(node0->GetSceneNodeBody())), OFFOBJMAG);
245 b1 = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, SCOL_PTR(node1->GetSceneNodeBody())), OFFOBJMAG);
246
247 MMpush(m, b0);
248 MMpush(m, b1);
249
250 res = OBJcallreflex(m, 2);
251 return res;
252}
253
254
266int getMaterialOverlapEndedCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
267{
268#ifdef SO3_DEBUG
269 MMechostr(MSKDEBUG, "getMaterialOverlapEndedCallback\n");
270#endif
271
272 int obj, res;
273 MCOLL* result = (MCOLL*)param;
274 SNode* node0 = result->curScene->GetNode(result->node0);
275 SNode* node1 = result->curScene->GetNode(result->node1);
276
277 if ((node0 == 0) || (node1 == 0))
278 return 0;
279
280 // equal to OBJbeginreflex
281 // is there a callback assigned to the object?
282 obj = OBJfindTH(m, SO3PHYSICSMATERIALPAIR, id);
283 if (obj == NIL)
284 return -1;
285
286 if (MMfetch(m, obj, OFFOBJREF0 + SO3_MATERIALPAIR_OVERLAP_ENDED * 2) == NIL)
287 return -1;
288
289 // retrieve scene magma
290 int s = MMfetch(m, OBJfindTH(m, SO3SCENETYPE, SCOL_PTR(result->curScene)), OFFOBJMAG);
291
292 //equal to OBJpreparereflex but replace the object
293 MMsetglobal(m, OFFSCCUR, MMfetch(m, obj, OFFOBJCHN));
294 if (MMpush(m, MMgetglobal(m, OFFSCCUR))) return MERRMEM;
295 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0 + SO3_MATERIALPAIR_OVERLAP_ENDED * 2))) return MERRMEM;
296 if (MMpush(m, s)) return MERRMEM;
297 if (MMpush(m, MMfetch(m, obj, OFFOBJREF0 + SO3_MATERIALPAIR_OVERLAP_ENDED * 2 + 1))) return MERRMEM;
298
299 if (node0->GetSceneNodeBody() == NULL)
300 {
301 MMpush(m, NIL);
302 MMpush(m, NIL);
303 MMpush(m, NIL);
304 return 0;
305 }
306 if (node1->GetSceneNodeBody() == NULL)
307 {
308 MMpush(m, NIL);
309 MMpush(m, NIL);
310 MMpush(m, NIL);
311 return 0;
312 }
313 int b0 = 0;
314 int b1 = 0;
315
316 b0 = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, SCOL_PTR(node0->GetSceneNodeBody())), OFFOBJMAG);
317 b1 = MMfetch(m, OBJfindTH(m, SO3PHYSICBODY, SCOL_PTR(node1->GetSceneNodeBody())), OFFOBJMAG);
318
319 MMpush(m, b0);
320 MMpush(m, b1);
321
322 res = OBJcallreflex(m, 2);
323 return res;
324}
325
326
327
337int SO3WorldSetFPS(mmachine m)
338{
339#ifdef SO3_DEBUG
340 MMechostr(MSKDEBUG, "SO3WorldSetFPS\n");
341#endif
342
343 int fps = MTOI(MMpull(m));
344 int s = MMget(m, 0);
345 if (s == NIL)
346 {
347 MMset(m, 0, NIL);
348 return 0;
349 }
350
351 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
352 if (scene == NULL)
353 {
354 MMset(m, 0, NIL);
355 return 0;
356 }
357
358 if (!scene->GetPhysicsWorld())
359 {
360 MMset(m, 0, NIL);
361 return 0;
362 }
363
364 try
365 {
366 if (fps > 0)
367 scene->GetPhysicsWorld()->SetPhysicFPS(fps);
368
369 MMset(m, 0, ITOM(1));
370 return 0;
371 }
372 catch (Ogre::Exception &e)
373 {
374 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
375 MMset(m, 0, 0);
376 return 0;
377 }
378}
379
380
389int SO3WorldGetFPS(mmachine m)
390{
391#ifdef SO3_DEBUG
392 MMechostr(MSKDEBUG, "SO3WorldGetFPS\n");
393#endif
394
395 int s = MMget(m, 0);
396 if (s == NIL)
397 {
398 MMset(m, 0, NIL);
399 return 0;
400 }
401
402 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
403 if (scene == NULL)
404 {
405 MMset(m, 0, NIL);
406 return 0;
407 }
408
409 if (!scene->GetPhysicsWorld())
410 {
411 MMset(m, 0, NIL);
412 return 0;
413 }
414
415 MMset(m, 0, ITOM(scene->GetPhysicsWorld()->GetPhysicFPS()));
416 return 0;
417}
418
419
428int SO3WorldSetSize(mmachine m)
429{
430#ifdef SO3_DEBUG
431 MMechostr(MSKDEBUG, "SO3WorldSetSize\n");
432#endif
433
434 int sizeMax = MTOP(MMpull(m));
435 int sizeMin = MTOP(MMpull(m));
436 int s = MMget(m, 0);
437 if (s == NIL)
438 {
439 MMset(m, 0, NIL);
440 return 0;
441 }
442
443 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
444 if (scene == NULL)
445 {
446 MMset(m, 0, NIL);
447 return 0;
448 }
449
450 if (!scene->GetPhysicsWorld())
451 {
452 MMset(m, 0, NIL);
453 return 0;
454 }
455
456 try
457 {
458 Ogre::Vector3 vectorMin;
459 vectorMin.x = MTOF(MMfetch(m, sizeMin, 0));
460 vectorMin.y = MTOF(MMfetch(m, sizeMin, 1));
461 vectorMin.z = MTOF(MMfetch(m, sizeMin, 2));
462
463 Ogre::Vector3 vectorMax;
464 vectorMax.x = MTOF(MMfetch(m, sizeMax, 0));
465 vectorMax.y = MTOF(MMfetch(m, sizeMax, 1));
466 vectorMax.z = MTOF(MMfetch(m, sizeMax, 2));
467 scene->GetPhysicsWorld()->SetPhysicWorldSize(vectorMin, vectorMax);
468
469 return 0;
470 }
471 catch (Ogre::Exception &e)
472 {
473 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
474 MMset(m, 0, 0);
475 return 0;
476 }
477}
478
479
495{
496#ifdef SO3_DEBUG
497 MMechostr(MSKDEBUG, "SO3WorldSetFrictionModel\n");
498#endif
499
500 MMpull(m);
501 MMset(m, 0, NIL);
502 return 0;
503}
504
505
520{
521#ifdef SO3_DEBUG
522 MMechostr(MSKDEBUG, "SO3WorldGetFrictionModel\n");
523#endif
524
525 MMset(m, 0, NIL);
526 return 0;
527}
528
529
546{
547#ifdef SO3_DEBUG
548 MMechostr(MSKDEBUG, "SO3WorldSetPlateformArchitecture\n");
549#endif
550
551 int mod = MMpull(m);
552 int s = MMget(m, 0);
553 if (s == NIL)
554 {
555 MMset(m, 0, NIL);
556 return 0;
557 }
558
559 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
560 if (scene == NULL)
561 {
562 MMset(m, 0, NIL);
563 return 0;
564 }
565
566 mod = MTOI(mod);
567
568 // clamp to correct values
569 if (mod < 0)
570 mod = SO3_PA_DEFAULT;
571 else if (mod > SO3_PA_BEST)
572 mod = SO3_PA_BEST;
573
574 if (!scene->GetPhysicsWorld())
575 {
576 MMset(m, 0, NIL);
577 return 0;
578 }
579
580 try
581 {
582 scene->GetPhysicsWorld()->SetPhysicPlatformArchitecture(mod);
583 MMset(m, 0, ITOM(1));
584 return 0;
585 }
586 catch (Ogre::Exception& e)
587 {
588 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
589 MMset(m, 0, NIL);
590 return 0;
591 }
592}
593
594
610{
611#ifdef SO3_DEBUG
612 MMechostr(MSKDEBUG, "SO3WorldGetPlateformArchitecture\n");
613#endif
614
615 int s = MMget(m, 0);
616 if (s == NIL)
617 {
618 MMset(m, 0, NIL);
619 return 0;
620 }
621
622 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
623 if (scene == NULL)
624 {
625 MMset(m, 0, NIL);
626 return 0;
627 }
628
629 if (!scene->GetPhysicsWorld())
630 {
631 MMset(m, 0, NIL);
632 return 0;
633 }
634
635 try
636 {
637 MMset(m, 0, ITOM(scene->GetPhysicsWorld()->GetPhysicPlatformArchitecture()));
638 return 0;
639 }
640 catch (Ogre::Exception& e)
641 {
642 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
643 MMset(m, 0, NIL);
644 return 0;
645 }
646}
647
648
663{
664#ifdef SO3_DEBUG
665 MMechostr(MSKDEBUG, "SO3WorldSetSolverModel\n");
666#endif
667
668 int mod = MMpull(m);
669 int s = MMget(m, 0);
670 if (s == NIL)
671 {
672 MMset(m, 0, NIL);
673 return 0;
674 }
675
676 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
677 if (scene == NULL)
678 {
679 MMset(m, 0, NIL);
680 return 0;
681 }
682
683 mod = MTOI(mod);
684
685 // clamp to correct values
686 if (mod < 0)
687 mod = SO3_SM_ADAPTATIVE;
688
689 if (!scene->GetPhysicsWorld())
690 {
691 MMset(m, 0, NIL);
692 return 0;
693 }
694
695 try
696 {
697 scene->GetPhysicsWorld()->SetPhysicSolverModel(mod);
698 MMset(m, 0, ITOM(1));
699 return 0;
700 }
701 catch (Ogre::Exception& e)
702 {
703 MMechostr(MSKDEBUG, "An exception has occurred: %s\n", e.what());
704 MMset(m, 0, NIL);
705 return 0;
706 }
707}
708
709
723{
724#ifdef SO3_DEBUG
725 MMechostr(MSKDEBUG, "SO3WorldGetSolverModel\n");
726#endif
727
728 int s = MMget(m, 0);
729 if (s == NIL)
730 {
731 MMset(m, 0, NIL);
732 return 0;
733 }
734 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
735 if (scene == NULL)
736 {
737 MMset(m, 0, NIL);
738 return 0;
739 }
740
741 if (!scene->GetPhysicsWorld())
742 {
743 MMset(m, 0, NIL);
744 return 0;
745 }
746
747 MMset(m, 0, ITOM(scene->GetPhysicsWorld()->GetPhysicSolverModel()));
748 return 0;
749}
750
751
761int SO3WorldSetEnabled(mmachine m)
762{
763#ifdef SO3_DEBUG
764 MMechostr(MSKDEBUG, "SO3WorldSetEnabled\n");
765#endif
766
767 int booleen = MTOI(MMpull(m));
768 int s = MMget(m, 0);
769
770 if (s == NIL)
771 {
772 MMset(m, 0, NIL);
773 return 0;
774 }
775
776 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
777 if (scene == NULL)
778 {
779 MMset(m, 0, NIL);
780 return 0;
781 }
782
783 if (!scene->GetPhysicsWorld())
784 {
785 MMset(m, 0, NIL);
786 return 0;
787 }
788
789 if (booleen == 0)
790 {
791 scene->GetPhysicsWorld()->SetPhysicWorldEnable(false);
792 }
793 else
794 {
795#ifdef SCOL_DEBUG
796 MMechostr(MSKDEBUG, " > World is Set To Enable\n");
797#endif
798
799 scene->GetPhysicsWorld()->SetPhysicWorldEnable(true);
800 }
801
802 MMset(m, 0, ITOM(1));
803 return 0;
804}
805
806
815int SO3WorldGetEnabled(mmachine m)
816{
817#ifdef SO3_DEBUG
818 MMechostr(MSKDEBUG, "SO3WorldGetEnabled\n");
819#endif
820
821 int s = MMget(m, 0);
822 if (s == NIL)
823 {
824 MMset(m, 0, NIL);
825 return 0;
826 }
827
828 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
829 if (scene == NULL)
830 {
831 MMset(m, 0, NIL);
832 return 0;
833 }
834
835 if (!scene->GetPhysicsWorld())
836 {
837 MMset(m, 0, NIL);
838 return 0;
839 }
840
841 int val = 0;
842 if (scene->GetPhysicsWorld()->GetPhysicWorldEnable())
843 val = 1;
844
845 MMset(m, 0, ITOM(val));
846 return 0;
847}
848
857int SO3WorldReset(mmachine m)
858{
859#ifdef SO3_DEBUG
860 MMechostr(MSKDEBUG, "SO3WorldReset\n");
861#endif
862
863 int s = MMget(m, 0);
864 if (s == NIL)
865 {
866 MMset(m, 0, NIL);
867 return 0;
868 }
869
870 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
871 if (scene == NULL)
872 {
873 MMset(m, 0, NIL);
874 return 0;
875 }
876
877 if (!scene->GetPhysicsWorld())
878 {
879 MMset(m, 0, NIL);
880 return 0;
881 }
882
883 scene->GetPhysicsWorld()->ResetPhysicWorld();
884
885 MMset(m, 0, ITOM(1));
886 return 0;
887}
888
898{
899#ifdef SO3_DEBUG
900 MMechostr(MSKDEBUG, "SO3WorldSetBodiesInitialState\n");
901#endif
902
903 int s = MMget(m, 0);
904 if (s == NIL)
905 {
906 MMset(m, 0, NIL);
907 return 0;
908 }
909
910 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
911 if (scene == NULL)
912 {
913 MMset(m, 0, NIL);
914 return 0;
915 }
916
917 if (!scene->GetPhysicsWorld())
918 {
919 MMset(m, 0, NIL);
920 return 0;
921 }
922
923 scene->GetPhysicsWorld()->SetPhysicBodiesInitialState();
924
925 MMset(m, 0, ITOM(1));
926 return 0;
927}
928
938{
939#ifdef SO3_DEBUG
940 MMechostr(MSKDEBUG, "SO3BodySetInitialState\n");
941#endif
942
943 int bod = MMget(m, 0);
944 if (bod == NIL)
945 {
946 MMset(m, 0, NIL);
947 return 0;
948 }
949
950 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
951 if (body == NULL)
952 {
953 MMset(m, 0, NIL);
954 return 0;
955 }
956
957 body->GetParentNode()->StoreInitialPRS();
958
959 MMset(m, 0, ITOM(1));
960 return 0;
961}
962
972int SO3WorldShowLines(mmachine m)
973{
974#ifdef SO3_DEBUG
975 MMechostr(MSKDEBUG, "SO3WorldShowLines\n");
976#endif
977
978 int booleen = MTOI(MMpull(m));
979 int s = MMget(m, 0);
980 if (s == NIL)
981 {
982 MMset(m, 0, NIL);
983 return 0;
984 }
985
986 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
987 if (scene == NULL)
988 {
989 MMset(m, 0, NIL);
990 return 0;
991 }
992
993 if (!scene->GetPhysicsWorld())
994 {
995 MMset(m, 0, NIL);
996 return 0;
997 }
998
999 if (booleen == 1)
1000 scene->GetPhysicsWorld()->SetPhysicDebugEnable(true);
1001 else
1002 scene->GetPhysicsWorld()->SetPhysicDebugEnable(false);
1003
1004 MMset(m, 0, ITOM(1));
1005 return 0;
1006}
1007
1008
1018int SO3WorldSetGravity(mmachine m)
1019{
1020#ifdef SO3_DEBUG
1021 MMechostr(MSKDEBUG, "SO3WorldSetGravity\n");
1022#endif
1023
1024 int vec = MTOP(MMpull(m));
1025 int s = MMget(m, 0);
1026 if ((s == NIL) || (vec == NIL))
1027 {
1028 MMset(m, 0, NIL);
1029 return 0;
1030 }
1031
1032 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
1033 if (scene == NULL)
1034 {
1035 MMset(m, 0, NIL);
1036 return 0;
1037 }
1038
1039 int x = MMfetch(m, vec, 0);
1040 int y = MMfetch(m, vec, 1);
1041 int z = MMfetch(m, vec, 2);
1042
1043 if ((x == NIL) || (y == NIL) || (z == NIL))
1044 {
1045 MMset(m, 0, NIL);
1046 return 0;
1047 }
1048
1049 Ogre::Vector3 vgravity = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
1050
1051 if (!scene->GetPhysicsWorld())
1052 {
1053 MMset(m, 0, NIL);
1054 return 0;
1055 }
1056
1057 scene->GetPhysicsWorld()->SetPhysicGravity(vgravity);
1058 MMset(m, 0, ITOM(1));
1059 return 0;
1060}
1061
1070int SO3WorldGetGravity(mmachine m)
1071{
1072#ifdef SO3_DEBUG
1073 MMechostr(MSKDEBUG, "SO3WorldGetGravity\n");
1074#endif
1075
1076 int s = MMget(m, 0);
1077 if (s == NIL)
1078 {
1079 MMset(m, 0, NIL);
1080 return 0;
1081 }
1082
1083 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
1084 if (scene == NULL)
1085 {
1086 MMset(m, 0, NIL);
1087 return 0;
1088 }
1089
1090 if (!scene->GetPhysicsWorld())
1091 {
1092 MMset(m, 0, NIL);
1093 return 0;
1094 }
1095
1096 Ogre::Vector3 vec = scene->GetPhysicsWorld()->GetPhysicGravity();
1097
1098 int tuple = MMmalloc(m, 3, TYPETAB);
1099 if (tuple == NIL)
1100 {
1101 MMset(m, 0, NIL);
1102 return MERRMEM;
1103 }
1104
1105 MMstore(m, tuple, 0, FTOM((vec.x)));
1106 MMstore(m, tuple, 1, FTOM((vec.y)));
1107 MMstore(m, tuple, 2, FTOM((vec.z)));
1108 MMset(m, 0, PTOM(tuple));
1109
1110 return 0;
1111}
1112
1113
1123int SO3BodyCreateBox(mmachine m)
1124{
1125#ifdef SO3_DEBUG
1126 MMechostr(MSKDEBUG, "SO3BodyCreateBox\n");
1127#endif
1128
1129 int vec = MTOP(MMpull(m));
1130 int n = MMget(m, 0);
1131 if ((n == NIL) || (vec == NIL))
1132 {
1133 MMset(m, 0, NIL);
1134 return 0;
1135 }
1136
1137 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
1138 if (node == NULL)
1139 {
1140 MMset(m, 0, NIL);
1141 return 0;
1142 }
1143
1144 if (!node->GetParentScene()->GetPhysicsWorld())
1145 {
1146 MMset(m, 0, NIL);
1147 return 0;
1148 }
1149
1150 // Check if A body exist on node
1151 if (node->GetSceneNodeBody() != NULL)
1152 {
1153 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
1154 }
1155
1156 int x = MMfetch(m, vec, 0);
1157 int y = MMfetch(m, vec, 1);
1158 int z = MMfetch(m, vec, 2);
1159
1160 if ((x == NIL) || (y == NIL) || (z == NIL))
1161 {
1162 MMset(m, 0, NIL);
1163 return 0;
1164 }
1165
1166 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
1167
1168 SBody* body = 0;
1169 try
1170 {
1171 body = node->CreateBoxBody(vector);
1172 }
1173 catch (Ogre::Exception& e)
1174 {
1175 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
1176 }
1177
1178 if (body == 0)
1179 {
1180 MMset(m, 0, NIL);
1181 return 0;
1182 }
1183
1184 // remove last parameter
1185 MMpull(m);
1186 return createBody(m, node);
1187}
1188
1189
1200{
1201#ifdef SO3_DEBUG
1202 MMechostr(MSKDEBUG, "SO3BodyCreateEllipsoid\n");
1203#endif
1204
1205 int vec = MTOP(MMpull(m));
1206 int n = MMget(m, 0);
1207 if ((n == NIL) || (vec == NIL))
1208 {
1209 MMset(m, 0, NIL);
1210 return 0;
1211 }
1212
1213 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
1214 if (node == NULL)
1215 {
1216 MMset(m, 0, NIL);
1217 return 0;
1218 }
1219
1220 if (!node->GetParentScene()->GetPhysicsWorld())
1221 {
1222 MMset(m, 0, NIL);
1223 return 0;
1224 }
1225
1226 // Check if A body exist on node
1227 if (node->GetSceneNodeBody() != NULL)
1228 {
1229 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
1230 }
1231
1232 int x = MMfetch(m, vec, 0);
1233 int y = MMfetch(m, vec, 1);
1234 int z = MMfetch(m, vec, 2);
1235
1236 if ((x == NIL) || (y == NIL) || (z == NIL))
1237 {
1238 MMset(m, 0, NIL);
1239 return 0;
1240 }
1241
1242 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
1243
1244 SBody* body = 0;
1245 try
1246 {
1247 body = node->CreateEllipsoidBody(vector);
1248 }
1249 catch (Ogre::Exception& e)
1250 {
1251 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
1252 }
1253
1254 if (body == 0)
1255 {
1256 MMset(m, 0, NIL);
1257 return 0;
1258 }
1259
1260 // remove last parameter
1261 MMpull(m);
1262 return createBody(m, node);
1263}
1264
1265
1277{
1278#ifdef SO3_DEBUG
1279 MMechostr(MSKDEBUG, "SO3BodyCreateCapsule\n");
1280#endif
1281
1282 int h = MMpull(m);
1283 int rad = MMpull(m);
1284 int n = MMget(m, 0);
1285 if ((n == NIL) || (h == NIL) || (rad == NIL))
1286 {
1287 MMset(m, 0, NIL);
1288 return 0;
1289 }
1290
1291 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
1292 if (node == NULL)
1293 {
1294 MMset(m, 0, NIL);
1295 return 0;
1296 }
1297
1298 if (!node->GetParentScene()->GetPhysicsWorld())
1299 {
1300 MMset(m, 0, NIL);
1301 return 0;
1302 }
1303
1304 // Check if A body exist on node
1305 if (node->GetSceneNodeBody() != NULL)
1306 {
1307 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
1308 }
1309
1310 float height = MTOF(h);
1311 if (height == 0.0f)
1312 height = 0.001f;
1313
1314 float radius = MTOF(rad);
1315 if (radius == 0.0f)
1316 radius = 0.001f;
1317
1318 // Create a SCOL Body
1319 SBody* body = 0;
1320 try
1321 {
1322 body = node->CreateCapsuleBody(radius, height);
1323 }
1324 catch (Ogre::Exception& e)
1325 {
1326 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
1327 }
1328
1329 if (body == 0)
1330 {
1331 MMset(m, 0, NIL);
1332 return 0;
1333 }
1334
1335 // remove last parameter
1336 MMpull(m);
1337 return createBody(m, node);
1338}
1339
1340
1352{
1353#ifdef SO3_DEBUG
1354 MMechostr(MSKDEBUG, "SO3BodyCreateChamferCylinder\n");
1355#endif
1356
1357 int h = MMpull(m);
1358 int rad = MMpull(m);
1359 int n = MMget(m, 0);
1360 if ((n == NIL) || (h == NIL) || (rad == NIL))
1361 {
1362 MMset(m, 0, NIL);
1363 return 0;
1364 }
1365
1366 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
1367 if (node == NULL)
1368 {
1369 MMset(m, 0, NIL);
1370 return 0;
1371 }
1372
1373 if (!node->GetParentScene()->GetPhysicsWorld())
1374 {
1375 MMset(m, 0, NIL);
1376 return 0;
1377 }
1378
1379 // Check if A body exist on node
1380 if (node->GetSceneNodeBody() != NULL)
1381 {
1382 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
1383 }
1384
1385 // Create a SCOL Body
1386 SBody* body = 0;
1387
1388 try
1389 {
1390 body = node->CreateChamferCylinderBody(MTOF(rad), MTOF(h));
1391 }
1392 catch (Ogre::Exception& e)
1393 {
1394 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
1395 }
1396
1397 if (body == 0)
1398 {
1399 MMset(m, 0, NIL);
1400 return 0;
1401 }
1402
1403 // remove last parameter
1404 MMpull(m);
1405 return createBody(m, node);
1406}
1407
1408
1419int SO3BodyCreateCone(mmachine m)
1420{
1421#ifdef SO3_DEBUG
1422 MMechostr(MSKDEBUG, "SO3BodyCreateCone\n");
1423#endif
1424
1425 int h = MMpull(m);
1426 int rad = MMpull(m);
1427 int n = MMget(m, 0);
1428
1429 if ((n == NIL) || (h == NIL) || (rad == NIL))
1430 {
1431 MMset(m, 0, NIL);
1432 return 0;
1433 }
1434
1435 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
1436 if (node == NULL)
1437 {
1438 MMset(m, 0, NIL);
1439 return 0;
1440 }
1441
1442 if (!node->GetParentScene()->GetPhysicsWorld())
1443 {
1444 MMset(m, 0, NIL);
1445 return 0;
1446 }
1447
1448 // Check if A body exist on node
1449 if (node->GetSceneNodeBody() != NULL)
1450 {
1451 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
1452 }
1453
1454 // Create a SCOL Body
1455 SBody* body = 0;
1456 try
1457 {
1458 body = node->CreateConeBody(MTOF(rad), MTOF(h));
1459 }
1460 catch (Ogre::Exception& e)
1461 {
1462 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
1463 }
1464
1465 if (body == 0)
1466 {
1467 MMset(m, 0, NIL);
1468 return 0;
1469 }
1470
1471 // remove last parameter
1472 MMpull(m);
1473 return createBody(m, node);
1474}
1475
1476
1488{
1489#ifdef SO3_DEBUG
1490 MMechostr(MSKDEBUG, "SO3BodyCreateCylinder\n");
1491#endif
1492
1493 int h = MMpull(m);
1494 int rad = MMpull(m);
1495 int n = MMget(m, 0);
1496 if ((n == NIL) || (h == NIL) || (rad == NIL))
1497 {
1498 MMset(m, 0, NIL);
1499 return 0;
1500 }
1501
1502 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
1503 if (node == NULL)
1504 {
1505 MMset(m, 0, NIL);
1506 return 0;
1507 }
1508
1509 if (!node->GetParentScene()->GetPhysicsWorld())
1510 {
1511 MMset(m, 0, NIL);
1512 return 0;
1513 }
1514
1515 // Check if A body exist on node
1516 if (node->GetSceneNodeBody() != NULL)
1517 {
1518 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
1519 }
1520
1521 // Create a SCOL Body
1522 SBody* body = 0;
1523 try
1524 {
1525 body = node->CreateCylinderBody(MTOF(rad), MTOF(h));
1526 }
1527 catch (Ogre::Exception& e)
1528 {
1529 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
1530 }
1531
1532 if (body == 0)
1533 {
1534 MMset(m, 0, NIL);
1535 return 0;
1536 }
1537
1538 // remove last parameter
1539 MMpull(m);
1540 return createBody(m, node);
1541}
1542
1543
1554{
1555#ifdef SO3_DEBUG
1556 MMechostr(MSKDEBUG, "SO3BodyCreatePyramid\n");
1557#endif
1558
1559 int vec = MTOP(MMpull(m));
1560 int n = MMget(m, 0);
1561 if ((n == NIL) || (vec == NIL))
1562 {
1563 MMset(m, 0, NIL);
1564 return 0;
1565 }
1566
1567 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
1568 if (node == NULL)
1569 {
1570 MMset(m, 0, NIL);
1571 return 0;
1572 }
1573
1574 if (!node->GetParentScene()->GetPhysicsWorld())
1575 {
1576 MMset(m, 0, NIL);
1577 return 0;
1578 }
1579
1580 // Check if A body exist on node
1581 if (node->GetSceneNodeBody() != NULL)
1582 {
1583 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
1584 }
1585
1586 int x = MMfetch(m, vec, 0);
1587 int y = MMfetch(m, vec, 1);
1588 int z = MMfetch(m, vec, 2);
1589
1590 if ((x == NIL) || (y == NIL) || (z == NIL))
1591 {
1592 MMset(m, 0, NIL);
1593 return 0;
1594 }
1595
1596 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
1597
1598 SBody* body = 0;
1599 try
1600 {
1601 body = node->CreatePyramidBody(vector);
1602 }
1603 catch (Ogre::Exception& e)
1604 {
1605 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
1606 }
1607
1608 if (body == 0)
1609 {
1610 MMset(m, 0, NIL);
1611 return 0;
1612 }
1613
1614 // remove last parameter
1615 MMpull(m);
1616 return createBody(m, node);
1617}
1618
1619
1631int SO3BodyCreateBoxExt(mmachine m)
1632{
1633#ifdef SO3_DEBUG
1634 MMechostr(MSKDEBUG, "SO3BodyCreateBox\n");
1635#endif
1636
1637 int q = MMpull(m);
1638 int pos = MMpull(m);
1639 int vec = MTOP(MMpull(m));
1640 int n = MMget(m, 0);
1641 if ((n == NIL) || (vec == NIL))
1642 {
1643 MMset(m, 0, NIL);
1644 return 0;
1645 }
1646
1647 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
1648 if (node == NULL)
1649 {
1650 MMset(m, 0, NIL);
1651 return 0;
1652 }
1653
1654 if (!node->GetParentScene()->GetPhysicsWorld())
1655 {
1656 MMset(m, 0, NIL);
1657 return 0;
1658 }
1659
1660 // Check if A body exist on node
1661 if (node->GetSceneNodeBody() != NULL)
1662 {
1663 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
1664 }
1665
1666 int x = MMfetch(m, vec, 0);
1667 int y = MMfetch(m, vec, 1);
1668 int z = MMfetch(m, vec, 2);
1669 int w = 0;
1670
1671 if ((x == NIL) || (y == NIL) || (z == NIL))
1672 {
1673 MMset(m, 0, NIL);
1674 return 0;
1675 }
1676
1677 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
1678
1679 if (vector.x == 0.0f)
1680 vector.x = 0.001f;
1681
1682 if (vector.y == 0.0f)
1683 vector.y = 0.001f;
1684
1685 if (vector.z == 0.0f)
1686 vector.z = 0.001f;
1687
1688 Ogre::Vector3 offset(Ogre::Vector3::ZERO);
1689 if (pos != NIL)
1690 {
1691 pos = MTOP(pos);
1692 x = MMfetch(m, pos, 0);
1693 y = MMfetch(m, pos, 1);
1694 z = MMfetch(m, pos, 2);
1695 offset = Ogre::Vector3((x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
1696 };
1697
1698 Ogre::Quaternion quat(Ogre::Quaternion::IDENTITY);
1699 if (q != NIL)
1700 {
1701 q = MTOP(q);
1702 x = MMfetch(m, q, 0);
1703 y = MMfetch(m, q, 1);
1704 z = MMfetch(m, q, 2);
1705 w = MMfetch(m, q, 3);
1706 quat = Ogre::Quaternion((w == NIL) ? 0.0f : MTOF(w), (x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
1707 };
1708
1709 SBody* body = 0;
1710 try
1711 {
1712 body = node->CreateBoxBody(vector, offset, quat);
1713 }
1714 catch (Ogre::Exception& e)
1715 {
1716 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
1717 }
1718
1719 if (body == 0)
1720 {
1721 MMset(m, 0, NIL);
1722 return 0;
1723 }
1724
1725 // remove last parameter
1726 MMpull(m);
1727 return createBody(m, node);
1728}
1729
1730
1743{
1744#ifdef SO3_DEBUG
1745 MMechostr(MSKDEBUG, "SO3BodyCreateEllipsoid\n");
1746#endif
1747
1748 int q = MMpull(m);
1749 int pos = MMpull(m);
1750 int vec = MTOP(MMpull(m));
1751 int n = MMget(m, 0);
1752 if ((n == NIL) || (vec == NIL))
1753 {
1754 MMset(m, 0, NIL);
1755 return 0;
1756 }
1757
1758 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
1759 if (node == NULL)
1760 {
1761 MMset(m, 0, NIL);
1762 return 0;
1763 }
1764
1765 if (!node->GetParentScene()->GetPhysicsWorld())
1766 {
1767 MMset(m, 0, NIL);
1768 return 0;
1769 }
1770
1771 // Check if A body exist on node
1772 if (node->GetSceneNodeBody() != NULL)
1773 {
1774 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
1775 }
1776
1777 int x = MMfetch(m, vec, 0);
1778 int y = MMfetch(m, vec, 1);
1779 int z = MMfetch(m, vec, 2);
1780 int w = 0;
1781
1782 if ((x == NIL) || (y == NIL) || (z == NIL))
1783 {
1784 MMset(m, 0, NIL);
1785 return 0;
1786 }
1787
1788 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
1789
1790 if (vector.x == 0.0f)
1791 vector.x = 0.001f;
1792
1793 if (vector.y == 0.0f)
1794 vector.y = 0.001f;
1795
1796 if (vector.z == 0.0f)
1797 vector.z = 0.001f;
1798
1799 Ogre::Vector3 offset(Ogre::Vector3::ZERO);
1800 if (pos != NIL)
1801 {
1802 pos = MTOP(pos);
1803 x = MMfetch(m, pos, 0);
1804 y = MMfetch(m, pos, 1);
1805 z = MMfetch(m, pos, 2);
1806 offset = Ogre::Vector3((x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
1807 };
1808
1809 Ogre::Quaternion quat(Ogre::Quaternion::IDENTITY);
1810 if (q != NIL)
1811 {
1812 q = MTOP(q);
1813 x = MMfetch(m, q, 0);
1814 y = MMfetch(m, q, 1);
1815 z = MMfetch(m, q, 2);
1816 w = MMfetch(m, q, 3);
1817 quat = Ogre::Quaternion((w == NIL) ? 0.0f : MTOF(w), (x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
1818 };
1819
1820 SBody* body = 0;
1821 try
1822 {
1823 body = node->CreateEllipsoidBody(vector, offset, quat);
1824 }
1825 catch (Ogre::Exception& e)
1826 {
1827 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
1828 }
1829
1830 if (body == 0)
1831 {
1832 MMset(m, 0, NIL);
1833 return 0;
1834 }
1835
1836 // remove last parameter
1837 MMpull(m);
1838 return createBody(m, node);
1839}
1840
1841
1855{
1856#ifdef SO3_DEBUG
1857 MMechostr(MSKDEBUG, "SO3BodyCreateCapsule\n");
1858#endif
1859
1860 int q = MMpull(m);
1861 int pos = MMpull(m);
1862 int h = MMpull(m);
1863 int rad = MMpull(m);
1864 int n = MMget(m, 0);
1865 if ((n == NIL) || (h == NIL) || (rad == NIL))
1866 {
1867 MMset(m, 0, NIL);
1868 return 0;
1869 }
1870
1871 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
1872 if (node == NULL)
1873 {
1874 MMset(m, 0, NIL);
1875 return 0;
1876 }
1877
1878 if (!node->GetParentScene()->GetPhysicsWorld())
1879 {
1880 MMset(m, 0, NIL);
1881 return 0;
1882 }
1883
1884 // Check if A body exist on node
1885 if (node->GetSceneNodeBody() != NULL)
1886 {
1887 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
1888 }
1889
1890 int x = 0;
1891 int y = 0;
1892 int z = 0;
1893 int w = 0;
1894
1895 Ogre::Vector3 offset(Ogre::Vector3::ZERO);
1896 if (pos != NIL)
1897 {
1898 pos = MTOP(pos);
1899 x = MMfetch(m, pos, 0);
1900 y = MMfetch(m, pos, 1);
1901 z = MMfetch(m, pos, 2);
1902 offset = Ogre::Vector3((x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
1903 };
1904
1905 Ogre::Quaternion quat(Ogre::Quaternion::IDENTITY);
1906 if (q != NIL)
1907 {
1908 q = MTOP(q);
1909 x = MMfetch(m, q, 0);
1910 y = MMfetch(m, q, 1);
1911 z = MMfetch(m, q, 2);
1912 w = MMfetch(m, q, 3);
1913 quat = Ogre::Quaternion((w == NIL) ? 0.0f : MTOF(w), (x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
1914 };
1915
1916 float height = MTOF(h);
1917 if (height == 0.0f)
1918 height = 0.001f;
1919
1920 float radius = MTOF(rad);
1921 if (radius == 0.0f)
1922 radius = 0.001f;
1923
1924 // Create a SCOL Body
1925 SBody* body = 0;
1926 try
1927 {
1928 body = node->CreateCapsuleBody(radius, height, offset, quat);
1929 }
1930 catch (Ogre::Exception& e)
1931 {
1932 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
1933 }
1934
1935 if (body == 0)
1936 {
1937 MMset(m, 0, NIL);
1938 return 0;
1939 }
1940
1941 // remove last parameter
1942 MMpull(m);
1943 return createBody(m, node);
1944}
1945
1946
1960{
1961#ifdef SO3_DEBUG
1962 MMechostr(MSKDEBUG, "SO3BodyCreateChamferCylinder\n");
1963#endif
1964
1965 int q = MMpull(m);
1966 int pos = MMpull(m);
1967 int h = MMpull(m);
1968 int rad = MMpull(m);
1969 int n = MMget(m, 0);
1970 if ((n == NIL) || (h == NIL) || (rad == NIL))
1971 {
1972 MMset(m, 0, NIL);
1973 return 0;
1974 }
1975
1976 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
1977 if (node == NULL)
1978 {
1979 MMset(m, 0, NIL);
1980 return 0;
1981 }
1982
1983 if (!node->GetParentScene()->GetPhysicsWorld())
1984 {
1985 MMset(m, 0, NIL);
1986 return 0;
1987 }
1988
1989 // Check if A body exist on node
1990 if (node->GetSceneNodeBody() != NULL)
1991 {
1992 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
1993 }
1994
1995 int x = 0;
1996 int y = 0;
1997 int z = 0;
1998 int w = 0;
1999
2000 Ogre::Vector3 offset(Ogre::Vector3::ZERO);
2001 if (pos != NIL)
2002 {
2003 pos = MTOP(pos);
2004 x = MMfetch(m, pos, 0);
2005 y = MMfetch(m, pos, 1);
2006 z = MMfetch(m, pos, 2);
2007 offset = Ogre::Vector3((x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
2008 };
2009
2010 Ogre::Quaternion quat(Ogre::Quaternion::IDENTITY);
2011 if (q != NIL)
2012 {
2013 q = MTOP(q);
2014 x = MMfetch(m, q, 0);
2015 y = MMfetch(m, q, 1);
2016 z = MMfetch(m, q, 2);
2017 w = MMfetch(m, q, 3);
2018 quat = Ogre::Quaternion((w == NIL) ? 0.0f : MTOF(w), (x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
2019 };
2020
2021 float height = MTOF(h);
2022 if (height == 0.0f)
2023 height = 0.001f;
2024
2025 float radius = MTOF(rad);
2026 if (radius == 0.0f)
2027 radius = 0.001f;
2028
2029 // Create a SCOL Body
2030 SBody* body = 0;
2031 try
2032 {
2033 body = node->CreateChamferCylinderBody(radius, height, offset, quat);
2034 }
2035 catch (Ogre::Exception& e)
2036 {
2037 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
2038 }
2039
2040 if (body == 0)
2041 {
2042 MMset(m, 0, NIL);
2043 return 0;
2044 }
2045
2046 // remove last parameter
2047 MMpull(m);
2048 return createBody(m, node);
2049}
2050
2051
2065{
2066#ifdef SO3_DEBUG
2067 MMechostr(MSKDEBUG, "SO3BodyCreateCone\n");
2068#endif
2069
2070 int q = MMpull(m);
2071 int pos = MMpull(m);
2072 int h = MMpull(m);
2073 int rad = MMpull(m);
2074 int n = MMget(m, 0);
2075
2076 if ((n == NIL) || (h == NIL) || (rad == NIL))
2077 {
2078 MMset(m, 0, NIL);
2079 return 0;
2080 }
2081
2082 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
2083 if (node == NULL)
2084 {
2085 MMset(m, 0, NIL);
2086 return 0;
2087 }
2088
2089 if (!node->GetParentScene()->GetPhysicsWorld())
2090 {
2091 MMset(m, 0, NIL);
2092 return 0;
2093 }
2094
2095 // Check if A body exist on node
2096 if (node->GetSceneNodeBody() != NULL)
2097 {
2098 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
2099 }
2100
2101 int x = 0;
2102 int y = 0;
2103 int z = 0;
2104 int w = 0;
2105
2106 Ogre::Vector3 offset(Ogre::Vector3::ZERO);
2107 if (pos != NIL)
2108 {
2109 pos = MTOP(pos);
2110 x = MMfetch(m, pos, 0);
2111 y = MMfetch(m, pos, 1);
2112 z = MMfetch(m, pos, 2);
2113 offset = Ogre::Vector3((x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
2114 };
2115
2116 Ogre::Quaternion quat(Ogre::Quaternion::IDENTITY);
2117 if (q != NIL)
2118 {
2119 q = MTOP(q);
2120 x = MMfetch(m, q, 0);
2121 y = MMfetch(m, q, 1);
2122 z = MMfetch(m, q, 2);
2123 w = MMfetch(m, q, 3);
2124 quat = Ogre::Quaternion((w == NIL) ? 0.0f : MTOF(w), (x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
2125 };
2126
2127 float height = MTOF(h);
2128 if (height == 0.0f)
2129 height = 0.001f;
2130
2131 float radius = MTOF(rad);
2132 if (radius == 0.0f)
2133 radius = 0.001f;
2134
2135 // Create a SCOL Body
2136 SBody* body = 0;
2137 try
2138 {
2139 body = node->CreateConeBody(radius, height, offset, quat);
2140 }
2141 catch (Ogre::Exception& e)
2142 {
2143 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
2144 }
2145
2146 if (body == 0)
2147 {
2148 MMset(m, 0, NIL);
2149 return 0;
2150 }
2151
2152 // remove last parameter
2153 MMpull(m);
2154 return createBody(m, node);
2155}
2156
2157
2171{
2172#ifdef SO3_DEBUG
2173 MMechostr(MSKDEBUG, "SO3BodyCreateCylinder\n");
2174#endif
2175
2176 int q = MMpull(m);
2177 int pos = MMpull(m);
2178 int h = MMpull(m);
2179 int rad = MMpull(m);
2180 int n = MMget(m, 0);
2181 if ((n == NIL) || (h == NIL) || (rad == NIL))
2182 {
2183 MMset(m, 0, NIL);
2184 return 0;
2185 }
2186
2187 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
2188 if (node == NULL)
2189 {
2190 MMset(m, 0, NIL);
2191 return 0;
2192 }
2193
2194 if (!node->GetParentScene()->GetPhysicsWorld())
2195 {
2196 MMset(m, 0, NIL);
2197 return 0;
2198 }
2199
2200 // Check if A body exist on node
2201 if (node->GetSceneNodeBody() != NULL)
2202 {
2203 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
2204 }
2205
2206 int x = 0;
2207 int y = 0;
2208 int z = 0;
2209 int w = 0;
2210
2211 Ogre::Vector3 offset(Ogre::Vector3::ZERO);
2212 if (pos != NIL)
2213 {
2214 pos = MTOP(pos);
2215 x = MMfetch(m, pos, 0);
2216 y = MMfetch(m, pos, 1);
2217 z = MMfetch(m, pos, 2);
2218 offset = Ogre::Vector3((x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
2219 };
2220
2221 Ogre::Quaternion quat(Ogre::Quaternion::IDENTITY);
2222 if (q != NIL)
2223 {
2224 q = MTOP(q);
2225 x = MMfetch(m, q, 0);
2226 y = MMfetch(m, q, 1);
2227 z = MMfetch(m, q, 2);
2228 w = MMfetch(m, q, 3);
2229 quat = Ogre::Quaternion((w == NIL) ? 0.0f : MTOF(w), (x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
2230 };
2231
2232 float height = MTOF(h);
2233 if (height == 0.0f)
2234 height = 0.001f;
2235
2236 float radius = MTOF(rad);
2237 if (radius == 0.0f)
2238 radius = 0.001f;
2239
2240 // Create a SCOL Body
2241 SBody* body = 0;
2242 try
2243 {
2244 body = node->CreateCylinderBody(radius, height, offset, quat);
2245 }
2246 catch (Ogre::Exception& e)
2247 {
2248 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
2249 }
2250
2251 if (body == 0)
2252 {
2253 MMset(m, 0, NIL);
2254 return 0;
2255 }
2256
2257 // remove last parameter
2258 MMpull(m);
2259 return createBody(m, node);
2260}
2261
2262
2275{
2276#ifdef SO3_DEBUG
2277 MMechostr(MSKDEBUG, "SO3BodyCreatePyramid\n");
2278#endif
2279
2280 int q = MMpull(m);
2281 int pos = MMpull(m);
2282 int vec = MTOP(MMpull(m));
2283 int n = MMget(m, 0);
2284 if ((n == NIL) || (vec == NIL))
2285 {
2286 MMset(m, 0, NIL);
2287 return 0;
2288 }
2289
2290 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
2291 if (node == NULL)
2292 {
2293 MMset(m, 0, NIL);
2294 return 0;
2295 }
2296
2297 if (!node->GetParentScene()->GetPhysicsWorld())
2298 {
2299 MMset(m, 0, NIL);
2300 return 0;
2301 }
2302
2303 // Check if A body exist on node
2304 if (node->GetSceneNodeBody() != NULL)
2305 {
2306 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
2307 }
2308
2309 int x = MMfetch(m, vec, 0);
2310 int y = MMfetch(m, vec, 1);
2311 int z = MMfetch(m, vec, 2);
2312 int w = 0;
2313
2314 if ((x == NIL) || (y == NIL) || (z == NIL))
2315 {
2316 MMset(m, 0, NIL);
2317 return 0;
2318 }
2319
2320 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
2321
2322 if (vector.x == 0.0f)
2323 vector.x = 0.001f;
2324
2325 if (vector.y == 0.0f)
2326 vector.y = 0.001f;
2327
2328 if (vector.z == 0.0f)
2329 vector.z = 0.001f;
2330
2331 Ogre::Vector3 offset(Ogre::Vector3::ZERO);
2332 if (pos != NIL)
2333 {
2334 pos = MTOP(pos);
2335 x = MMfetch(m, pos, 0);
2336 y = MMfetch(m, pos, 1);
2337 z = MMfetch(m, pos, 2);
2338 offset = Ogre::Vector3((x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
2339 };
2340
2341 Ogre::Quaternion quat(Ogre::Quaternion::IDENTITY);
2342 if (q != NIL)
2343 {
2344 q = MTOP(q);
2345 x = MMfetch(m, q, 0);
2346 y = MMfetch(m, q, 1);
2347 z = MMfetch(m, q, 2);
2348 w = MMfetch(m, q, 3);
2349 quat = Ogre::Quaternion((w == NIL) ? 0.0f : MTOF(w), (x == NIL) ? 0.0f : MTOF(x), (y == NIL) ? 0.0f : MTOF(y), (z == NIL) ? 0.0f : MTOF(z));
2350 };
2351
2352 SBody* body = 0;
2353 try
2354 {
2355 body = node->CreatePyramidBody(vector, offset, quat);
2356 }
2357 catch (Ogre::Exception& e)
2358 {
2359 MMechostr(MSKRUNTIME, "Cannot create body: %s\n", e.what());
2360 }
2361
2362 if (body == 0)
2363 {
2364 MMset(m, 0, NIL);
2365 return 0;
2366 }
2367
2368 // remove last parameter
2369 MMpull(m);
2370 return createBody(m, node);
2371}
2372
2373
2384{
2385#ifdef SO3_DEBUG
2386 MMechostr(MSKDEBUG, "SO3BodyCreateCollisionTree\n");
2387#endif
2388
2389 int opti = MMpull(m);
2390 int n = MMget(m, 0);
2391 if (n == NIL)
2392 {
2393 MMset(m, 0, NIL);
2394 return 0;
2395 }
2396
2397 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
2398 if (node == NULL)
2399 {
2400 MMset(m, 0, NIL);
2401 return 0;
2402 }
2403
2404 bool optimize = false;
2405 if (MTOI(opti) == 1)
2406 bool optimize = true;
2407
2408 if ((node->GetNodeType() != SNode::ENTITY_TYPE_ID)/* && !node->GetAsStaticGeometry()*/)
2409 {
2410 MMset(m, 0, NIL);
2411 return 0;
2412 }
2413
2414 if (!node->GetParentScene()->GetPhysicsWorld())
2415 {
2416 MMset(m, 0, NIL);
2417 return 0;
2418 }
2419
2420 // Check if A body exist on node
2421 if (node->GetSceneNodeBody() != NULL)
2422 {
2423 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
2424 }
2425
2426 // Create a SCOL Body
2427 SBody* body = node->CreateTreeBody(optimize);
2428
2429 if (body == NULL)
2430 {
2431 MMset(m, 0, NIL);
2432 return 0;
2433 }
2434
2435 // remove last parameter
2436 MMpull(m);
2437 return createBody(m, node);
2438}
2439
2440
2450int SO3BodyCreateShape(mmachine m)
2451{
2452#ifdef SO3_DEBUG
2453 MMechostr(MSKDEBUG, "SO3BodyCreateShape\n");
2454#endif
2455
2456 int toler = MMpull(m);
2457 int n = MMget(m, 0);
2458 if (n == NIL)
2459 {
2460 MMset(m, 0, NIL);
2461 return 0;
2462 }
2463
2464 float tolerance = 0;
2465 if (toler != NIL)
2466 tolerance = MTOF(toler);
2467
2468 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
2469 if (node == NULL)
2470 {
2471 MMset(m, 0, NIL);
2472 return 0;
2473 }
2474
2475 if (node->GetNodeType() != SNode::ENTITY_TYPE_ID)
2476 {
2477 MMset(m, 0, NIL);
2478 return 0;
2479 }
2480
2481 SEntity* entity = static_cast<SEntity*> (node);
2482 if (!entity || !entity->getOgreEntityPointer())
2483 {
2484 MMset(m, 0, NIL);
2485 return 0;
2486 }
2487
2488 if (!node->GetParentScene()->GetPhysicsWorld())
2489 {
2490 MMset(m, 0, NIL);
2491 return 0;
2492 }
2493
2494 // Check if A body exist on node
2495 if (node->GetSceneNodeBody() != NULL)
2496 {
2497 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
2498 }
2499
2500 SBody* body = 0;
2501
2502 // Create a SCOL Body
2503 try
2504 {
2505 body = node->CreateConvexHullBody(tolerance);
2506 }
2507 catch (Ogre::Exception)
2508 {
2509 MMset(m, 0, NIL);
2510 return 0;
2511 }
2512
2513 if (body == NULL)
2514 {
2515 MMset(m, 0, NIL);
2516 return 0;
2517 }
2518
2519 // remove last parameter
2520 MMpull(m);
2521 return createBody(m, node);
2522}
2523
2524
2535{
2536#ifdef SO3_DEBUG
2537 MMechostr(MSKDEBUG, "SO3BodyCreateConcaveShape\n");
2538#endif
2539
2540 int toler = MMpull(m);
2541 int n = MMget(m, 0);
2542 if (n == NIL)
2543 {
2544 MMset(m, 0, NIL);
2545 return 0;
2546 }
2547
2548 float tolerance = 0;
2549 if (toler != NIL)
2550 tolerance = MTOF(toler);
2551
2552 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
2553 if (node == NULL)
2554 {
2555 MMset(m, 0, NIL);
2556 return 0;
2557 }
2558
2559 if (node->GetNodeType() != SNode::ENTITY_TYPE_ID)
2560 {
2561 MMset(m, 0, NIL);
2562 return 0;
2563 }
2564
2565 SEntity* entity = static_cast<SEntity*> (node);
2566 if (!entity || !entity->getOgreEntityPointer())
2567 {
2568 MMset(m, 0, NIL);
2569 return 0;
2570 }
2571
2572 if (!node->GetParentScene()->GetPhysicsWorld())
2573 {
2574 MMset(m, 0, NIL);
2575 return 0;
2576 }
2577
2578 // Check if A body exist on node
2579 if (node->GetSceneNodeBody() != NULL)
2580 {
2581 OBJdelTH(m, SO3PHYSICBODY, SCOL_PTR(node->GetSceneNodeBody()));
2582 }
2583
2584 SBody* body = 0;
2585
2586 // Create a SCOL Body
2587 try
2588 {
2589 body = node->CreateConcaveHullBody(tolerance);
2590 }
2591 catch (Ogre::Exception)
2592 {
2593 MMset(m, 0, NIL);
2594 return 0;
2595 }
2596
2597 if (body == NULL)
2598 {
2599 MMset(m, 0, NIL);
2600 return 0;
2601 }
2602
2603 // remove last parameter
2604 MMpull(m);
2605 return createBody(m, node);
2606}
2607
2619{
2620#ifdef SO3_DEBUG
2621 MMechostr(MSKDEBUG, "SO3BodyGetShapeDefinition\n");
2622#endif
2623
2624 int bod = MMget(m, 0);
2625 if (bod == NIL)
2626 {
2627 MMset(m, 0, NIL);
2628 return 0;
2629 }
2630
2631 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
2632 if (body == NULL)
2633 {
2634 MMset(m, 0, NIL);
2635 return 0;
2636 }
2637
2638 SShape* shape = body->GetShape();
2639 if (shape == NULL)
2640 {
2641 MMset(m, 0, NIL);
2642 return 0;
2643 }
2644
2645 float tolerance = 0.0f;
2646 float radius = 0.0f;
2647 float height = 0.0f;
2648 Ogre::Vector3 size;
2649
2650 SShape::ShapeType stype = shape->GetType();
2651
2652 Ogre::Vector3 offsetpos = shape->GetBaseOffset();
2653 Ogre::Quaternion offsetquat = shape->GetBaseRotation();
2654
2655 if (stype == SShape::SO3_BOX_COLLISION)
2656 {
2657 SShapeBox* bshape = static_cast<SShapeBox*>(shape);
2658 size = bshape->GetSize();
2659 }
2660 else if (stype == SShape::SO3_CAPSULE_COLLISION)
2661 {
2662 SShapeCapsule* bshape = static_cast<SShapeCapsule*>(shape);
2663 radius = bshape->GetRadius();
2664 height = bshape->GetHeight();
2665 }
2666 else if (stype == SShape::SO3_CHAMFERCYLINDRE_COLLISION)
2667 {
2668 SShapeChamferCylinder* bshape = static_cast<SShapeChamferCylinder*>(shape);
2669 radius = bshape->GetRadius();
2670 height = bshape->GetHeight();
2671 }
2672 else if (stype == SShape::SO3_CONE_COLLISION)
2673 {
2674 SShapeCone* bshape = static_cast<SShapeCone*>(shape);
2675 radius = bshape->GetRadius();
2676 height = bshape->GetHeight();
2677 }
2678 else if (stype == SShape::SO3_CYLINDER_COLLISION)
2679 {
2680 SShapeCylinder* bshape = static_cast<SShapeCylinder*>(shape);
2681 radius = bshape->GetRadius();
2682 height = bshape->GetHeight();
2683 }
2684 else if (stype == SShape::SO3_ELLIPSOID_COLLISION)
2685 {
2686 SShapeEllipsoid* bshape = static_cast<SShapeEllipsoid*>(shape);
2687 size = bshape->GetSize();
2688 }
2689 else if (stype == SShape::SO3_PYRAMID_COLLISION)
2690 {
2691 SShapePyramid* bshape = static_cast<SShapePyramid*>(shape);
2692 size = bshape->GetSize();
2693 }
2694 else if (stype == SShape::SO3_CONCAVE_COLLISION)
2695 {
2696 SShapeConcaveHull* bshape = static_cast<SShapeConcaveHull*>(shape);
2697 tolerance = bshape->GetTolerance();
2698 }
2699 else if (stype == SShape::SO3_SHAPE_COLLISION)
2700 {
2701 SShapeConvexHull* bshape = static_cast<SShapeConvexHull*>(shape);
2702 tolerance = bshape->GetTolerance();
2703 }
2704 /*
2705 else if (stype == SShape::SO3_TREE_COLLISION)
2706 {
2707 SShapeTree* bshape = static_cast<SShapeTree*>(shape);
2708 }
2709 */
2710
2711 MMpush(m, ITOM((int)stype));
2712 MMpush(m, FTOM(tolerance));
2713
2714 int trh = MMmalloc(m, 2, TYPETAB);
2715 if (trh == NIL)
2716 {
2717 MMset(m, 0, NIL);
2718 return MERRMEM;
2719 }
2720
2721 MMstore(m, trh, 0, FTOM(radius));
2722 MMstore(m, trh, 1, FTOM(height));
2723 MMpush(m, PTOM(trh));
2724
2725 int tsize = MMmalloc(m, 3, TYPETAB);
2726 if (tsize == NIL)
2727 {
2728 MMset(m, 0, NIL);
2729 return MERRMEM;
2730 }
2731 MMstore(m, tsize, 0, FTOM(size.x));
2732 MMstore(m, tsize, 1, FTOM(size.y));
2733 MMstore(m, tsize, 2, FTOM(size.z));
2734 MMpush(m, PTOM(tsize));
2735
2736 int toffset = MMmalloc(m, 3, TYPETAB);
2737 if (toffset == NIL)
2738 {
2739 MMset(m, 0, NIL);
2740 return MERRMEM;
2741 }
2742 MMstore(m, toffset, 0, FTOM(offsetpos.x));
2743 MMstore(m, toffset, 1, FTOM(offsetpos.y));
2744 MMstore(m, toffset, 2, FTOM(offsetpos.z));
2745 MMpush(m, PTOM(toffset));
2746
2747 int torientation = MMmalloc(m, 4, TYPETAB);
2748 if (torientation == NIL)
2749 {
2750 MMset(m, 0, NIL);
2751 return MERRMEM;
2752 }
2753 MMstore(m, torientation, 0, FTOM(offsetquat.x));
2754 MMstore(m, torientation, 1, FTOM(offsetquat.y));
2755 MMstore(m, torientation, 2, FTOM(offsetquat.z));
2756 MMstore(m, torientation, 3, FTOM(offsetquat.w));
2757 MMpush(m, PTOM(torientation));
2758
2759 // FINAL TUPPLE
2760 int result = MMmalloc(m, 6, TYPETAB);
2761 if (result == NIL)
2762 {
2763 MMset(m, 0, NIL);
2764 return MERRMEM;
2765 }
2766 MMstore(m, result, 5, MMpull(m));
2767 MMstore(m, result, 4, MMpull(m));
2768 MMstore(m, result, 3, MMpull(m));
2769 MMstore(m, result, 2, MMpull(m));
2770 MMstore(m, result, 1, MMpull(m));
2771 MMstore(m, result, 0, MMpull(m));
2772 MMset(m, 0, PTOM(result));
2773 return 0;
2774}
2775
2785int SO3BodySetMass(mmachine m)
2786{
2787#ifdef SO3_DEBUG
2788 MMechostr(MSKDEBUG, "SO3BodySetMass\n");
2789#endif
2790
2791 int mass = MMpull(m);
2792 int bod = MMget(m, 0);
2793 if ((bod == NIL) || (mass == NIL))
2794 {
2795 MMset(m, 0, NIL);
2796 return 0;
2797 }
2798
2799 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
2800 if (body == NULL)
2801 {
2802 MMset(m, 0, NIL);
2803 return 0;
2804 }
2805
2806 Ogre::Real omass = (Ogre::Real)MTOF(mass);
2807 body->SetMass(omass);
2808
2809 MMset(m, 0, ITOM(1));
2810 return 0;
2811}
2812
2813
2824{
2825#ifdef SO3_DEBUG
2826 MMechostr(MSKDEBUG, "SO3BodyCreateBasicJointUpVector\n");
2827#endif
2828
2829 int vel = MTOP(MMpull(m));
2830 int bod = MMget(m, 0);
2831 if ((bod == NIL) || (vel == NIL))
2832 {
2833 MMset(m, 0, NIL);
2834 return 0;
2835 }
2836
2837 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
2838 if (body == NULL)
2839 {
2840 MMset(m, 0, NIL);
2841 return 0;
2842 }
2843
2844 Ogre::Vector3 vector(MTOF(MMfetch(m, vel, 0)),
2845 MTOF(MMfetch(m, vel, 1)),
2846 MTOF(MMfetch(m, vel, 2)));
2847
2848 body->SetUpJoint(vector);
2849
2850 MMset(m, 0, ITOM(1));
2851 return 0;
2852}
2853
2854
2864{
2865#ifdef SO3_DEBUG
2866 MMechostr(MSKDEBUG, "SO3BodyDestroyBasicJointUpVector\n");
2867#endif
2868
2869 int bod = MMget(m, 0);
2870 if (bod == NIL)
2871 {
2872 MMset(m, 0, NIL);
2873 return 0;
2874 }
2875
2876 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
2877 if (body == NULL)
2878 {
2879 MMset(m, 0, NIL);
2880 return 0;
2881 }
2882
2883 body->RemoveUpJoint();
2884
2885 MMset(m, 0, 0);
2886 return 0;
2887}
2888
2889
2899int SO3BodySetForce(mmachine m)
2900{
2901#ifdef SO3_DEBUG
2902 MMechostr(MSKDEBUG, "SO3BodySetForce\n");
2903#endif
2904
2905 int vec = MMpull(m);
2906 int bod = MMget(m, 0);
2907 if ((bod == NIL) || (vec == NIL))
2908 {
2909 MMset(m, 0, NIL);
2910 return 0;
2911 }
2912
2913 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
2914 if (body == NULL)
2915 {
2916 MMset(m, 0, NIL);
2917 return 0;
2918 }
2919
2920 vec = MTOP(vec);
2921 int x = MMfetch(m, vec, 0);
2922 int y = MMfetch(m, vec, 1);
2923 int z = MMfetch(m, vec, 2);
2924
2925 if ((x == NIL) || (y == NIL) || (z == NIL))
2926 {
2927 MMset(m, 0, NIL);
2928 return 0;
2929 }
2930
2931 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
2932
2933 body->SetForce(vector);
2934 MMset(m, 0, ITOM(1));
2935 return 0;
2936}
2937
2938
2948int SO3BodyAddForce(mmachine m)
2949{
2950#ifdef SO3_DEBUG
2951 MMechostr(MSKDEBUG, "SO3BodyAddForce\n");
2952#endif
2953
2954 int vec = MTOP(MMpull(m));
2955 int bod = MMget(m, 0);
2956 if ((bod == NIL) || (vec == NIL))
2957 {
2958 MMset(m, 0, NIL);
2959 return 0;
2960 }
2961
2962 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
2963 if (body == NULL)
2964 {
2965 MMset(m, 0, NIL);
2966 return 0;
2967 }
2968
2969 int x = MMfetch(m, vec, 0);
2970 int y = MMfetch(m, vec, 1);
2971 int z = MMfetch(m, vec, 2);
2972
2973 if ((x == NIL) || (y == NIL) || (z == NIL))
2974 {
2975 MMset(m, 0, NIL);
2976 return 0;
2977 }
2978
2979 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
2980
2981 body->SetForce(body->GetForce() + vector);
2982 MMset(m, 0, ITOM(1));
2983 return 0;
2984}
2985
2986
2995int SO3BodyGetForce(mmachine m)
2996{
2997#ifdef SO3_DEBUG
2998 MMechostr(MSKDEBUG, "SO3BodyGetForce\n");
2999#endif
3000
3001 int bod = MMget(m, 0);
3002 if (bod == NIL)
3003 {
3004 MMset(m, 0, NIL);
3005 return 0;
3006 }
3007
3008 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
3009 if (body == NULL)
3010 {
3011 MMset(m, 0, NIL);
3012 return 0;
3013 }
3014
3015 Ogre::Vector3 vector = body->GetForce();
3016 int tuple = MMmalloc(m, 3, TYPETAB);
3017 if (tuple == NIL)
3018 {
3019 MMset(m, 0, NIL);
3020 return MERRMEM;
3021 }
3022
3023 MMstore(m, tuple, 0, FTOM((vector.x)));
3024 MMstore(m, tuple, 1, FTOM((vector.y)));
3025 MMstore(m, tuple, 2, FTOM((vector.z)));
3026 MMset(m, 0, PTOM(tuple));
3027 return 0;
3028}
3029
3030
3041{
3042#ifdef SO3_DEBUG
3043 MMechostr(MSKDEBUG, "SO3BodySetConstantForce\n");
3044#endif
3045
3046 int vec = MTOP(MMpull(m));
3047 int bod = MMget(m, 0);
3048 if ((bod == NIL) || (vec == NIL))
3049 {
3050 MMset(m, 0, NIL);
3051 return 0;
3052 }
3053
3054 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
3055 if (body == NULL)
3056 {
3057 MMset(m, 0, NIL);
3058 return 0;
3059 }
3060
3061 int x = MMfetch(m, vec, 0);
3062 int y = MMfetch(m, vec, 1);
3063 int z = MMfetch(m, vec, 2);
3064
3065 if ((x == NIL) || (y == NIL) || (z == NIL))
3066 {
3067 MMset(m, 0, NIL);
3068 return 0;
3069 }
3070
3071 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3072
3073 body->SetConstantForce(vector);
3074 MMset(m, 0, ITOM(1));
3075 return 0;
3076}
3077
3078
3089{
3090#ifdef SO3_DEBUG
3091 MMechostr(MSKDEBUG, "SO3BodyAddConstantForce\n");
3092#endif
3093
3094 int vec = MTOP(MMpull(m));
3095 int bod = MMget(m, 0);
3096 if ((bod == NIL) || (vec == NIL))
3097 {
3098 MMset(m, 0, NIL);
3099 return 0;
3100 }
3101
3102 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
3103 if (body == NULL)
3104 {
3105 MMset(m, 0, NIL);
3106 return 0;
3107 }
3108
3109 int x = MMfetch(m, vec, 0);
3110 int y = MMfetch(m, vec, 1);
3111 int z = MMfetch(m, vec, 2);
3112
3113 if ((x == NIL) || (y == NIL) || (z == NIL))
3114 {
3115 MMset(m, 0, NIL);
3116 return 0;
3117 }
3118
3119 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3120
3121 body->AddConstantForce(vector);
3122 MMset(m, 0, ITOM(1));
3123 return 0;
3124}
3125
3126
3136{
3137#ifdef SO3_DEBUG
3138 MMechostr(MSKDEBUG, "SO3BodyGetConstantForce\n");
3139#endif
3140
3141 int bod = MMget(m, 0);
3142 if (bod == NIL)
3143 {
3144 MMset(m, 0, NIL);
3145 return 0;
3146 }
3147
3148 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
3149 if (body == NULL)
3150 {
3151 MMset(m, 0, NIL);
3152 return 0;
3153 }
3154
3155 Ogre::Vector3 vector = body->GetConstantForce();
3156 int tuple = MMmalloc(m, 3, TYPETAB);
3157 if (tuple == NIL)
3158 {
3159 MMset(m, 0, NIL);
3160 return MERRMEM;
3161 }
3162
3163 MMstore(m, tuple, 0, FTOM((vector.x)));
3164 MMstore(m, tuple, 1, FTOM((vector.y)));
3165 MMstore(m, tuple, 2, FTOM((vector.z)));
3166 MMset(m, 0, PTOM(tuple));
3167 return 0;
3168}
3169
3180{
3181#ifdef SO3_DEBUG
3182 MMechostr(MSKDEBUG, "SO3BodySetConstantTorque\n");
3183#endif
3184
3185 int vec = MTOP(MMpull(m));
3186 int bod = MMget(m, 0);
3187 if ((bod == NIL) || (vec == NIL))
3188 {
3189 MMset(m, 0, NIL);
3190 return 0;
3191 }
3192
3193 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
3194 if (body == NULL)
3195 {
3196 MMset(m, 0, NIL);
3197 return 0;
3198 }
3199
3200 int x = MMfetch(m, vec, 0);
3201 int y = MMfetch(m, vec, 1);
3202 int z = MMfetch(m, vec, 2);
3203
3204 if ((x == NIL) || (y == NIL) || (z == NIL))
3205 {
3206 MMset(m, 0, NIL);
3207 return 0;
3208 }
3209
3210 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3211
3212 body->SetConstantTorque(vector);
3213 MMset(m, 0, ITOM(1));
3214 return 0;
3215}
3216
3217
3228{
3229#ifdef SO3_DEBUG
3230 MMechostr(MSKDEBUG, "SO3BodyAddConstantTorque\n");
3231#endif
3232
3233 int vec = MTOP(MMpull(m));
3234 int bod = MMget(m, 0);
3235 if ((bod == NIL) || (vec == NIL))
3236 {
3237 MMset(m, 0, NIL);
3238 return 0;
3239 }
3240
3241 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
3242 if (body == NULL)
3243 {
3244 MMset(m, 0, NIL);
3245 return 0;
3246 }
3247
3248 int x = MMfetch(m, vec, 0);
3249 int y = MMfetch(m, vec, 1);
3250 int z = MMfetch(m, vec, 2);
3251
3252 if ((x == NIL) || (y == NIL) || (z == NIL))
3253 {
3254 MMset(m, 0, NIL);
3255 return 0;
3256 }
3257
3258 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3259
3260 body->AddConstantTorque(vector);
3261 MMset(m, 0, ITOM(1));
3262 return 0;
3263}
3264
3265
3275{
3276#ifdef SO3_DEBUG
3277 MMechostr(MSKDEBUG, "SO3BodyGetConstantTorque\n");
3278#endif
3279
3280 int bod = MMget(m, 0);
3281 if (bod == NIL)
3282 {
3283 MMset(m, 0, NIL);
3284 return 0;
3285 }
3286
3287 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
3288 if (body == NULL)
3289 {
3290 MMset(m, 0, NIL);
3291 return 0;
3292 }
3293
3294 Ogre::Vector3 vector = body->GetConstantTorque();
3295 int tuple = MMmalloc(m, 3, TYPETAB);
3296 if (tuple == NIL)
3297 {
3298 MMset(m, 0, NIL);
3299 return MERRMEM;
3300 }
3301
3302 MMstore(m, tuple, 0, FTOM((vector.x)));
3303 MMstore(m, tuple, 1, FTOM((vector.y)));
3304 MMstore(m, tuple, 2, FTOM((vector.z)));
3305 MMset(m, 0, PTOM(tuple));
3306 return 0;
3307}
3308
3309
3320{
3321#ifdef SO3_DEBUG
3322 MMechostr(MSKDEBUG, "SO3BodyAddGlobalForce\n");
3323#endif
3324
3325 int vec = MTOP(MMpull(m));
3326 int bod = MMget(m, 0);
3327 if ((bod == NIL) || (vec == NIL))
3328 {
3329 MMset(m, 0, NIL);
3330 return 0;
3331 }
3332
3333 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
3334 if (body == NULL)
3335 {
3336 MMset(m, 0, NIL);
3337 return 0;
3338 }
3339
3340 int x = MMfetch(m, vec, 0);
3341 int y = MMfetch(m, vec, 1);
3342 int z = MMfetch(m, vec, 2);
3343
3344 if ((x == NIL) || (y == NIL) || (z == NIL))
3345 {
3346 MMset(m, 0, NIL);
3347 return 0;
3348 }
3349
3350 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3351
3352 body->SetGlobalForce(body->GetGlobalForce() + vector);
3353 MMset(m, 0, ITOM(1));
3354 return 0;
3355}
3356
3357
3368{
3369#ifdef SO3_DEBUG
3370 MMechostr(MSKDEBUG, "SO3BodyAddLocalForce\n");
3371#endif
3372
3373 int vec = MTOP(MMpull(m));
3374 int bod = MMget(m, 0);
3375 if ((bod == NIL) || (vec == NIL))
3376 {
3377 MMset(m, 0, NIL);
3378 return 0;
3379 }
3380
3381 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
3382 if (body == NULL)
3383 {
3384 MMset(m, 0, NIL);
3385 return 0;
3386 }
3387
3388 int x = MMfetch(m, vec, 0);
3389 int y = MMfetch(m, vec, 1);
3390 int z = MMfetch(m, vec, 2);
3391
3392 if ((x == NIL) || (y == NIL) || (z == NIL))
3393 {
3394 MMset(m, 0, NIL);
3395 return 0;
3396 }
3397
3398 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3399
3400 body->SetLocalForce(body->GetLocalForce() + vector);
3401 MMset(m, 0, ITOM(1));
3402 return 0;
3403}
3404
3405
3415int SO3BodyAddTorque(mmachine m)
3416{
3417#ifdef SO3_DEBUG
3418 MMechostr(MSKDEBUG, "SO3BodyAddTorque\n");
3419#endif
3420
3421 int vec = MTOP(MMpull(m));
3422 int bod = MMget(m, 0);
3423 if ((bod == NIL) || (vec == NIL))
3424 {
3425 MMset(m, 0, NIL);
3426 return 0;
3427 }
3428
3429 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
3430 if (body == NULL)
3431 {
3432 MMset(m, 0, NIL);
3433 return 0;
3434 }
3435
3436 int x = MMfetch(m, vec, 0);
3437 int y = MMfetch(m, vec, 1);
3438 int z = MMfetch(m, vec, 2);
3439
3440 if ((x == NIL) || (y == NIL) || (z == NIL))
3441 {
3442 MMset(m, 0, NIL);
3443 return 0;
3444 }
3445
3446 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3447
3448 body->SetTorque(body->GetTorque() + vector);
3449 MMset(m, 0, ITOM(1));
3450 return 0;
3451}
3452
3453
3463int SO3BodySetTorque(mmachine m)
3464{
3465#ifdef SO3_DEBUG
3466 MMechostr(MSKDEBUG, "SO3BodySetTorque\n");
3467#endif
3468
3469 int vec = MTOP(MMpull(m));
3470 int bod = MMget(m, 0);
3471 if ((bod == NIL) || (vec == NIL))
3472 {
3473 MMset(m, 0, NIL);
3474 return 0;
3475 }
3476
3477 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
3478 if (body == NULL)
3479 {
3480 MMset(m, 0, NIL);
3481 return 0;
3482 }
3483
3484 int x = MMfetch(m, vec, 0);
3485 int y = MMfetch(m, vec, 1);
3486 int z = MMfetch(m, vec, 2);
3487
3488 if ((x == NIL) || (y == NIL) || (z == NIL))
3489 {
3490 MMset(m, 0, NIL);
3491 return 0;
3492 }
3493
3494 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3495
3496 body->SetTorque(vector);
3497 MMset(m, 0, ITOM(1));
3498 return 0;
3499}
3500
3501
3511int SO3BodySetOmega(mmachine m)
3512{
3513#ifdef SO3_DEBUG
3514 MMechostr(MSKDEBUG, "SO3BodySetOmega\n");
3515#endif
3516
3517 int vec = MTOP(MMpull(m));
3518 int bod = MMget(m, 0);
3519 if ((bod == NIL) || (vec == NIL))
3520 {
3521 MMset(m, 0, NIL);
3522 return 0;
3523 }
3524
3525 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
3526 if (body == NULL)
3527 {
3528 MMset(m, 0, NIL);
3529 return 0;
3530 }
3531
3532 int x = MMfetch(m, vec, 0);
3533 int y = MMfetch(m, vec, 1);
3534 int z = MMfetch(m, vec, 2);
3535
3536 if ((x == NIL) || (y == NIL) || (z == NIL))
3537 {
3538 MMset(m, 0, NIL);
3539 return 0;
3540 }
3541
3542 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3543
3544 body->SetOmega(vector);
3545 MMset(m, 0, ITOM(1));
3546 return 0;
3547}
3548
3549
3559int SO3BodySetVelocity(mmachine m)
3560{
3561#ifdef SO3_DEBUG
3562 MMechostr(MSKDEBUG, "SO3BodySetVelocity\n");
3563#endif
3564
3565 int vec = MTOP(MMpull(m));
3566 int bod = MMget(m, 0);
3567 if ((bod == NIL) || (vec == NIL))
3568 {
3569 MMset(m, 0, NIL);
3570 return 0;
3571 }
3572
3573 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
3574 if (body == NULL)
3575 {
3576 MMset(m, 0, NIL);
3577 return 0;
3578 }
3579
3580 int x = MMfetch(m, vec, 0);
3581 int y = MMfetch(m, vec, 1);
3582 int z = MMfetch(m, vec, 2);
3583
3584 if ((x == NIL) || (y == NIL) || (z == NIL))
3585 {
3586 MMset(m, 0, NIL);
3587 return 0;
3588 }
3589
3590 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3591
3592 body->SetVelocity(vector);
3593 MMset(m, 0, ITOM(1));
3594 return 0;
3595}
3596
3597
3608int SO3BodyAddImpulse(mmachine m)
3609{
3610#ifdef SO3_DEBUG
3611 MMechostr(MSKDEBUG, "SO3BodyAddImpulse\n");
3612#endif
3613
3614 int pos = MTOP(MMpull(m));
3615 int deltav = MTOP(MMpull(m));
3616 int bod = MMget(m, 0);
3617 if ((bod == NIL) || (pos == NIL) || (deltav == NIL))
3618 {
3619 MMset(m, 0, NIL);
3620 return 0;
3621 }
3622
3623 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
3624 if (body == NULL)
3625 {
3626 MMset(m, 0, NIL);
3627 return 0;
3628 }
3629
3630 int x = MMfetch(m, pos, 0);
3631 int y = MMfetch(m, pos, 1);
3632 int z = MMfetch(m, pos, 2);
3633
3634 if ((x == NIL) || (y == NIL) || (z == NIL))
3635 {
3636 MMset(m, 0, NIL);
3637 return 0;
3638 }
3639
3640 Ogre::Vector3 position = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3641
3642 int dx = MMfetch(m, deltav, 0);
3643 int dy = MMfetch(m, deltav, 1);
3644 int dz = MMfetch(m, deltav, 2);
3645
3646 if ((dx == NIL) || (dy == NIL) || (dz == NIL))
3647 {
3648 MMset(m, 0, NIL);
3649 return 0;
3650 }
3651
3652 Ogre::Vector3 delta = Ogre::Vector3(MTOF(dx), MTOF(dy), MTOF(dz));
3653
3654 body->AddImpulse(delta, position);
3655 MMset(m, 0, ITOM(1));
3656 return 0;
3657}
3658
3659
3670int SO3BodyMoveTo(mmachine m)
3671{
3672#ifdef SO3_DEBUG
3673 MMechostr(MSKDEBUG, "SO3BodyMoveTo\n");
3674#endif
3675
3676 int stif = MMpull(m);
3677 int src = MMpull(m);
3678 int bod = MMget(m, 0);
3679 if ((bod == NIL) || (src == NIL))
3680 {
3681 MMset(m, 0, NIL);
3682 return 0;
3683 }
3684
3685 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
3686 if (body == NULL)
3687 {
3688 MMset(m, 0, NIL);
3689 return 0;
3690 }
3691
3692 src = MTOP(src);
3693 int x = MMfetch(m, src, 0);
3694 int y = MMfetch(m, src, 1);
3695 int z = MMfetch(m, src, 2);
3696
3697 if ((x == NIL) || (y == NIL) || (z == NIL))
3698 {
3699 MMset(m, 0, NIL);
3700 return 0;
3701 }
3702
3703 Ogre::Vector3 dstpos = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3704
3705 Ogre::Real stiffness = 1.0;
3706 if (stif != NIL)
3707 stiffness = MTOF(stif);
3708
3709 if (stiffness <= 0.0f)
3710 stiffness = 0.000001f;
3711 else if (stiffness > 1.0f)
3712 stiffness = 1.0f;
3713
3714 body->MoveToPosition(dstpos, stiffness);
3715 MMset(m, 0, ITOM(1));
3716 return 0;
3717}
3718
3719
3730int SO3BodyRotateTo(mmachine m)
3731{
3732#ifdef SO3_DEBUG
3733 MMechostr(MSKDEBUG, "SO3BodyRotateTo\n");
3734#endif
3735
3736 int stif = MMpull(m);
3737 int q = MMpull(m);
3738 int bod = MMget(m, 0);
3739 if ((bod == NIL) || (q == NIL))
3740 {
3741 MMset(m, 0, NIL);
3742 return 0;
3743 }
3744
3745 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
3746 if (body == NULL)
3747 {
3748 MMset(m, 0, NIL);
3749 return 0;
3750 }
3751
3752 Ogre::Quaternion quat(Ogre::Quaternion::IDENTITY);
3753 if (q != NIL)
3754 {
3755 q = MTOP(q);
3756 int qx = MMfetch(m, q, 0);
3757 int qy = MMfetch(m, q, 1);
3758 int qz = MMfetch(m, q, 2);
3759 int qw = MMfetch(m, q, 3);
3760 quat = Ogre::Quaternion((qw == NIL) ? 0.0f : MTOF(qw), (qx == NIL) ? 0.0f : MTOF(qx), (qy == NIL) ? 0.0f : MTOF(qy), (qz == NIL) ? 0.0f : MTOF(qz));
3761 };
3762
3763 Ogre::Real stiffness = 1.0;
3764 if (stif != NIL)
3765 stiffness = MTOF(stif);
3766
3767 if (stiffness <= 0.0f)
3768 stiffness = 0.000001f;
3769 else if (stiffness > 1.0f)
3770 stiffness = 1.0f;
3771
3772 body->RotateToOrientation(quat, stiffness);
3773 MMset(m, 0, ITOM(1));
3774 return 0;
3775}
3776
3777
3778//TODO use an offset applied on each body update
3790{
3791#ifdef SO3_DEBUG
3792 MMechostr(MSKDEBUG, "SO3BodySetPositionOrientation\n");
3793#endif
3794
3795 int rot = MTOP(MMpull(m));
3796 int pos = MTOP(MMpull(m));
3797 int bod = MMget(m, 0);
3798 if ((bod == NIL) || (pos == NIL) || (rot == NIL))
3799 {
3800 MMset(m, 0, NIL);
3801 return 0;
3802 }
3803
3804 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
3805 if (body == NULL)
3806 {
3807 MMset(m, 0, NIL);
3808 return 0;
3809 }
3810
3811 Ogre::Vector3 vector(MTOF(MMfetch(m, pos, 0)),
3812 MTOF(MMfetch(m, pos, 1)),
3813 MTOF(MMfetch(m, pos, 2)));
3814
3815 Ogre::Quaternion quat(MTOF(MMfetch(m, rot, 0)),
3816 MTOF(MMfetch(m, rot, 1)),
3817 MTOF(MMfetch(m, rot, 2)),
3818 MTOF(MMfetch(m, rot, 3)));
3819
3820 body->SetMatrix(vector, quat);
3821 MMset(m, 0, ITOM(1));
3822 return 0;
3823}
3824
3825
3836{
3837#ifdef SO3_DEBUG
3838 MMechostr(MSKDEBUG, "SO3BodySetAngularDamping\n");
3839#endif
3840
3841 int vec = MTOP(MMpull(m));
3842 int bod = MMget(m, 0);
3843 if ((bod == NIL) || (vec == NIL))
3844 {
3845 MMset(m, 0, NIL);
3846 return 0;
3847 }
3848
3849 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
3850 if (body == NULL)
3851 {
3852 MMset(m, 0, NIL);
3853 return 0;
3854 }
3855
3856 int x = MMfetch(m, vec, 0);
3857 int y = MMfetch(m, vec, 1);
3858 int z = MMfetch(m, vec, 2);
3859
3860 if ((x == NIL) || (y == NIL) || (z == NIL))
3861 {
3862 MMset(m, 0, NIL);
3863 return 0;
3864 }
3865
3866 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3867
3868 body->SetAngularDamping(vector);
3869 MMset(m, 0, ITOM(1));
3870 return 0;
3871}
3872
3873
3884{
3885#ifdef SO3_DEBUG
3886 MMechostr(MSKDEBUG, "SO3BodySetCenterOfMass\n");
3887#endif
3888
3889 int vec = MTOP(MMpull(m));
3890 int bod = MMget(m, 0);
3891 if ((bod == NIL) || (vec == NIL))
3892 {
3893 MMset(m, 0, NIL);
3894 return 0;
3895 }
3896
3897 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
3898 if (body == NULL)
3899 {
3900 MMset(m, 0, NIL);
3901 return 0;
3902 }
3903
3904 int x = MMfetch(m, vec, 0);
3905 int y = MMfetch(m, vec, 1);
3906 int z = MMfetch(m, vec, 2);
3907
3908 if ((x == NIL) || (y == NIL) || (z == NIL))
3909 {
3910 MMset(m, 0, NIL);
3911 return 0;
3912 }
3913
3914 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3915
3916 body->SetCenterOfMass(vector);
3917 MMset(m, 0, ITOM(1));
3918 return 0;
3919}
3920
3921
3933{
3934#ifdef SO3_DEBUG
3935 MMechostr(MSKDEBUG, "SO3BodySetMassMatrix\n");
3936#endif
3937
3938 int vec = MTOP(MMpull(m));
3939 float mass = MTOF(MMpull(m));
3940 int bod = MMget(m, 0);
3941 if ((bod == NIL) || (vec == NIL) || (mass == NIL))
3942 {
3943 MMset(m, 0, NIL);
3944 return 0;
3945 }
3946
3947 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
3948 if (body == NULL)
3949 {
3950 MMset(m, 0, NIL);
3951 return 0;
3952 }
3953
3954 int x = MMfetch(m, vec, 0);
3955 int y = MMfetch(m, vec, 1);
3956 int z = MMfetch(m, vec, 2);
3957
3958 if ((x == NIL) || (y == NIL) || (z == NIL))
3959 {
3960 MMset(m, 0, NIL);
3961 return 0;
3962 }
3963
3964 Ogre::Vector3 vector = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
3965
3966 body->SetMassMatrix(mass, vector);
3967 MMset(m, 0, ITOM(1));
3968 return 0;
3969}
3970
3971
3981{
3982#ifdef SO3_DEBUG
3983 MMechostr(MSKDEBUG, "SO3BodyGetAngularDamping\n");
3984#endif
3985
3986 int bod = MMget(m, 0);
3987 if (bod == NIL)
3988 {
3989 MMset(m, 0, NIL);
3990 return 0;
3991 }
3992
3993 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
3994 if (body == NULL)
3995 {
3996 MMset(m, 0, NIL);
3997 return 0;
3998 }
3999
4000 Ogre::Vector3 vector = body->GetAngularDamping();
4001 int tuple = MMmalloc(m, 3, TYPETAB);
4002 if (tuple == NIL)
4003 {
4004 MMset(m, 0, NIL);
4005 return MERRMEM;
4006 }
4007
4008 MMstore(m, tuple, 0, FTOM((vector.x)));
4009 MMstore(m, tuple, 1, FTOM((vector.y)));
4010 MMstore(m, tuple, 2, FTOM((vector.z)));
4011 MMset(m, 0, PTOM(tuple));
4012 return 0;
4013}
4014
4015
4024int SO3BodyGetOmega(mmachine m)
4025{
4026#ifdef SO3_DEBUG
4027 MMechostr(MSKDEBUG, "SO3BodyGetOmega\n");
4028#endif
4029
4030 int bod = MMget(m, 0);
4031 if (bod == NIL)
4032 {
4033 MMset(m, 0, NIL);
4034 return 0;
4035 }
4036
4037 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4038 if (body == NULL)
4039 {
4040 MMset(m, 0, NIL);
4041 return 0;
4042 }
4043
4044 Ogre::Vector3 vector = body->GetOmega();
4045 int tuple = MMmalloc(m, 3, TYPETAB);
4046 if (tuple == NIL)
4047 {
4048 MMset(m, 0, NIL);
4049 return MERRMEM;
4050 }
4051
4052 MMstore(m, tuple, 0, FTOM((vector.x)));
4053 MMstore(m, tuple, 1, FTOM((vector.y)));
4054 MMstore(m, tuple, 2, FTOM((vector.z)));
4055 MMset(m, 0, PTOM(tuple));
4056 return 0;
4057}
4058
4059
4070{
4071#ifdef SO3_DEBUG
4072 MMechostr(MSKDEBUG, "SO3BodySetLinearDamping\n");
4073#endif
4074
4075 int ang = MMpull(m);
4076 int bod = MMget(m, 0);
4077 if ((bod == NIL) || (ang == NIL))
4078 {
4079 MMset(m, 0, NIL);
4080 return 0;
4081 }
4082
4083 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
4084 if (body == NULL)
4085 {
4086 MMset(m, 0, NIL);
4087 return 0;
4088 }
4089
4090 body->SetLinearDamping((Ogre::Real)MTOF(ang));
4091 MMset(m, 0, ITOM(1));
4092 return 0;
4093}
4094
4095
4105int SO3BodySetAutoSleep(mmachine m)
4106{
4107#ifdef SO3_DEBUG
4108 MMechostr(MSKDEBUG, "SO3BodySetAutoSleep\n");
4109#endif
4110
4111 int val = MMpull(m);
4112 int bod = MMget(m, 0);
4113 if ((bod == NIL) || (val == NIL))
4114 {
4115 MMset(m, 0, NIL);
4116 return 0;
4117 }
4118
4119 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4120 if (body == NULL)
4121 {
4122 MMset(m, 0, NIL);
4123 return 0;
4124 }
4125
4126 bool sleep = false;
4127 if ((val != NIL) && (MTOI(val) == 1))
4128 sleep = true;
4129
4130 body->SetAutoSleep(sleep);
4131 MMset(m, 0, ITOM(1));
4132 return 0;
4133}
4134
4135
4145int SO3BodySetType(mmachine m)
4146{
4147#ifdef SO3_DEBUG
4148 MMechostr(MSKDEBUG, "SO3BodySetType\n");
4149#endif
4150
4151 int val = MMpull(m);
4152 int bod = MMget(m, 0);
4153 if ((bod == NIL) || (val == NIL))
4154 {
4155 MMset(m, 0, NIL);
4156 return 0;
4157 }
4158
4159 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4160 if (body == NULL)
4161 {
4162 MMset(m, 0, NIL);
4163 return 0;
4164 }
4165
4166 body->SetType(MTOI(val));
4167 MMset(m, 0, val);
4168 return 0;
4169}
4170
4181{
4182#ifdef SO3_DEBUG
4183 MMechostr(MSKDEBUG, "SO3BodySetIgnoreCollision\n");
4184#endif
4185
4186 int val = MMpull(m);
4187 int bod = MMget(m, 0);
4188 if (bod == NIL)
4189 {
4190 MMset(m, 0, NIL);
4191 return 0;
4192 }
4193
4194 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4195 if (body == NULL)
4196 {
4197 MMset(m, 0, NIL);
4198 return 0;
4199 }
4200
4201 bool state = false;
4202 if (MTOI(val) >= 1)
4203 state = true;
4204
4205 body->SetIgnoreCollision(state);
4206
4207 MMset(m, 0, ITOM(val));
4208 return 0;
4209}
4210
4220{
4221#ifdef SO3_DEBUG
4222 MMechostr(MSKDEBUG, "SO3BodyGetIgnoreCollision\n");
4223#endif
4224
4225 int bod = MMget(m, 0);
4226 if (bod == NIL)
4227 {
4228 MMset(m, 0, NIL);
4229 return 0;
4230 }
4231
4232 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4233 if (body == NULL)
4234 {
4235 MMset(m, 0, NIL);
4236 return 0;
4237 }
4238
4239 bool state = body->GetIgnoreCollision();
4240
4241 MMset(m, 0, state ? ITOM(1) : ITOM(0));
4242 return 0;
4243}
4244
4255{
4256#ifdef SO3_DEBUG
4257 MMechostr(MSKDEBUG, "SO3BodySetContiniousCollisionMode\n");
4258#endif
4259
4260 int val = MTOI(MMpull(m));
4261 int bod = MMget(m, 0);
4262 if ((bod == NIL) || (val == NIL))
4263 {
4264 MMset(m, 0, NIL);
4265 return 0;
4266 }
4267
4268 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4269 if (body == NULL)
4270 {
4271 MMset(m, 0, NIL);
4272 return 0;
4273 }
4274
4275 bool coll = false;
4276 if (val == 1)
4277 coll = true;
4278
4279 body->SetContinuousCollisionMode(coll);
4280 MMset(m, 0, ITOM(1));
4281 return 0;
4282}
4283
4284
4294int SO3BodySetFluid(mmachine m)
4295{
4296#ifdef SO3_DEBUG
4297 MMechostr(MSKDEBUG, "SO3BodySetFluid\n");
4298#endif
4299
4300 int val = MTOI(MMpull(m));
4301 int bod = MMget(m, 0);
4302 if ((bod == NIL) || (val == NIL))
4303 {
4304 MMset(m, 0, NIL);
4305 return 0;
4306 }
4307
4308 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4309 if (body == NULL)
4310 {
4311 MMset(m, 0, NIL);
4312 return 0;
4313 }
4314
4315 bool fluid = false;
4316 if (val == 1)
4317 fluid = true;
4318
4319 body->SetFluidState(fluid);
4320 MMset(m, 0, ITOM(1));
4321 return 0;
4322}
4323
4332int SO3BodyGetFluid(mmachine m)
4333{
4334#ifdef SO3_DEBUG
4335 MMechostr(MSKDEBUG, "SO3BodyGetFluid\n");
4336#endif
4337
4338 int bod = MMget(m, 0);
4339 if (bod == NIL)
4340 {
4341 MMset(m, 0, NIL);
4342 return 0;
4343 }
4344
4345 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4346 if (body == NULL)
4347 {
4348 MMset(m, 0, NIL);
4349 return 0;
4350 }
4351
4352 bool state = body->GetFluidState();
4353
4354 MMset(m, 0, state ? ITOM(1) : ITOM(0));
4355 return 0;
4356}
4357
4358
4369{
4370#ifdef SO3_DEBUG
4371 MMechostr(MSKDEBUG, "SO3BodySetFluidVolumeRatio\n");
4372#endif
4373
4374 int vol = MMpull(m);
4375 int bod = MMget(m, 0);
4376 if ((bod == NIL) || (vol == NIL))
4377 {
4378 MMset(m, 0, NIL);
4379 return 0;
4380 }
4381
4382 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4383 if (body == NULL)
4384 {
4385 MMset(m, 0, NIL);
4386 return 0;
4387 }
4388
4389 float voltowater = MTOF(vol);
4390
4391 body->SetFluidVolumeRatio(voltowater);
4392 MMset(m, 0, ITOM(1));
4393 return 0;
4394}
4395
4405{
4406#ifdef SO3_DEBUG
4407 MMechostr(MSKDEBUG, "SO3BodyGetFluidVolumeRatio\n");
4408#endif
4409
4410 int bod = MMget(m, 0);
4411 if (bod == NIL)
4412 {
4413 MMset(m, 0, NIL);
4414 return 0;
4415 }
4416
4417 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
4418 if (body == NULL)
4419 {
4420 MMset(m, 0, NIL);
4421 return 0;
4422 }
4423
4424 MMset(m, 0, FTOM(body->GetFluidWaterToVolumeRatio()));
4425 return 0;
4426}
4427
4437{
4438#ifdef SO3_DEBUG
4439 MMechostr(MSKDEBUG, "SO3BodyCalculateOffset\n");
4440#endif
4441
4442 int bod = MMget(m, 0);
4443 if (bod == NIL)
4444 {
4445 MMset(m, 0, NIL);
4446 return 0;
4447 }
4448
4449 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
4450 if (body == NULL)
4451 {
4452 MMset(m, 0, NIL);
4453 return 0;
4454 }
4455
4456 Ogre::Vector3 vector = body->CalculateBodyOffset();
4457 int tuple = MMmalloc(m, 3, TYPETAB);
4458 if (tuple == NIL)
4459 {
4460 MMset(m, 0, NIL);
4461 return MERRMEM;
4462 }
4463
4464 MMstore(m, tuple, 0, FTOM((vector.x)));
4465 MMstore(m, tuple, 1, FTOM((vector.y)));
4466 MMstore(m, tuple, 2, FTOM((vector.z)));
4467 MMset(m, 0, PTOM(tuple));
4468 return 0;
4469}
4470
4471
4481{
4482#ifdef SO3_DEBUG
4483 MMechostr(MSKDEBUG, "SO3BodyGetLinearDamping\n");
4484#endif
4485
4486 int bod = MMget(m, 0);
4487 if (bod == NIL)
4488 {
4489 MMset(m, 0, NIL);
4490 return 0;
4491 }
4492
4493 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4494 if (body == NULL)
4495 {
4496 MMset(m, 0, NIL);
4497 return 0;
4498 }
4499
4500 float ld = body->GetLinearDamping();
4501 MMset(m, 0, FTOM(ld));
4502 return 0;
4503}
4504
4505
4514int SO3BodyGetInvMass(mmachine m)
4515{
4516#ifdef SO3_DEBUG
4517 MMechostr(MSKDEBUG, "SO3BodyGetInvMass\n");
4518#endif
4519
4520 int bod = MMget(m, 0);
4521 if (bod == NIL)
4522 {
4523 MMset(m, 0, NIL);
4524 return 0;
4525 }
4526
4527 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4528 if (body == NULL)
4529 {
4530 MMset(m, 0, NIL);
4531 return 0;
4532 }
4533
4534 float mass;
4535 Ogre::Vector3 vector;
4536 body->GetInvMass(mass, vector);
4537 MMpush(m, FTOM(mass));
4538
4539 int inertia = MMmalloc(m, 3, TYPETAB);
4540 if (inertia == NIL)
4541 {
4542 MMpull(m);
4543 MMset(m, 0, NIL);
4544 return MERRMEM;
4545 }
4546
4547 MMstore(m, inertia, 0, FTOM(vector.x));
4548 MMstore(m, inertia, 1, FTOM(vector.y));
4549 MMstore(m, inertia, 2, FTOM(vector.z));
4550 MMpush(m, PTOM(inertia));
4551
4552 // FINAL TUPPLE
4553 int result = MMmalloc(m, 2, TYPETAB);
4554 if (result == NIL)
4555 {
4556 MMpull(m);
4557 MMpull(m);
4558 MMset(m, 0, NIL);
4559 return MERRMEM;
4560 }
4561
4562 MMstore(m, result, 1, MMpull(m));
4563 MMstore(m, result, 0, MMpull(m));
4564 MMset(m, 0, PTOM(result));
4565 return 0;
4566}
4567
4568
4578{
4579#ifdef SO3_DEBUG
4580 MMechostr(MSKDEBUG, "SO3BodyGetMassMatrix\n");
4581#endif
4582
4583 int bod = MMget(m, 0);
4584 if (bod == NIL)
4585 {
4586 MMset(m, 0, NIL);
4587 return 0;
4588 }
4589
4590 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4591 if (body == NULL)
4592 {
4593 MMset(m, 0, NIL);
4594 return 0;
4595 }
4596
4597 float mass;
4598 Ogre::Vector3 vector;
4599 body->GetMassMatrix(mass, vector);
4600 MMpush(m, FTOM(mass));
4601
4602 int inertia = MMmalloc(m, 3, TYPETAB);
4603 if (inertia == NIL)
4604 {
4605 MMpull(m);
4606 MMset(m, 0, NIL);
4607 return MERRMEM;
4608 }
4609 MMstore(m, inertia, 0, FTOM(vector.x));
4610 MMstore(m, inertia, 1, FTOM(vector.y));
4611 MMstore(m, inertia, 2, FTOM(vector.z));
4612 MMpush(m, PTOM(inertia));
4613
4614 // FINAL TUPPLE
4615 int result = MMmalloc(m, 2, TYPETAB);
4616 if (result == NIL)
4617 {
4618 MMpull(m);
4619 MMpull(m);
4620 MMset(m, 0, NIL);
4621 return MERRMEM;
4622 }
4623 MMstore(m, result, 1, MMpull(m));
4624 MMstore(m, result, 0, MMpull(m));
4625 MMset(m, 0, PTOM(result));
4626 return 0;
4627}
4628
4629
4638int SO3BodyGetAutoSleep(mmachine m)
4639{
4640#ifdef SO3_DEBUG
4641 MMechostr(MSKDEBUG, "SO3BodyGetAutoSleep\n");
4642#endif
4643
4644 int bod = MMget(m, 0);
4645 if (bod == NIL)
4646 {
4647 MMset(m, 0, NIL);
4648 return 0;
4649 }
4650
4651 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4652 if (body == NULL)
4653 {
4654 MMset(m, 0, NIL);
4655 return 0;
4656 }
4657
4658 bool sleep = body->GetAutoSleep();
4659
4660 MMset(m, 0, ITOM(sleep ? 1 : 0));
4661 return 0;
4662}
4663
4664
4674{
4675#ifdef SO3_DEBUG
4676 MMechostr(MSKDEBUG, "SO3BodyGetSleepingState\n");
4677#endif
4678
4679 int bod = MMget(m, 0);
4680 if (bod == NIL)
4681 {
4682 MMset(m, 0, NIL);
4683 return 0;
4684 }
4685
4686 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4687 if (body == NULL)
4688 {
4689 MMset(m, 0, NIL);
4690 return 0;
4691 }
4692
4693 bool sleep = body->GetSleepState();
4694
4695 MMset(m, 0, ITOM(sleep ? 1 : 0));
4696 return 0;
4697}
4698
4699
4708int SO3BodyGetType(mmachine m)
4709{
4710#ifdef SO3_DEBUG
4711 MMechostr(MSKDEBUG, "SO3BodyGetType\n");
4712#endif
4713
4714 int bod = MMget(m, 0);
4715 if (bod == NIL)
4716 {
4717 MMset(m, 0, NIL);
4718 return 0;
4719 }
4720
4721 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4722 if (body == NULL)
4723 {
4724 MMset(m, 0, NIL);
4725 return 0;
4726 }
4727
4728 int ld = body->GetType();
4729 MMset(m, 0, ITOM(ld));
4730 return 0;
4731}
4732
4733
4743{
4744#ifdef SO3_DEBUG
4745 MMechostr(MSKDEBUG, "SO3BodyGetContiniousCollisionMode\n");
4746#endif
4747
4748 int bod = MMget(m, 0);
4749 if (bod == NIL)
4750 {
4751 MMset(m, 0, NIL);
4752 return 0;
4753 }
4754
4755 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4756 if (body == NULL)
4757 {
4758 MMset(m, 0, NIL);
4759 return 0;
4760 }
4761
4762 bool coll = body->GetContinuousCollisionMode();
4763 MMset(m, 0, ITOM(coll ? 1 : 0));
4764 return 0;
4765}
4766
4767
4777{
4778#ifdef SO3_DEBUG
4779 MMechostr(MSKDEBUG, "SO3BodyGetCenterOfMass\n");
4780#endif
4781
4782 int bod = MMget(m, 0);
4783 if (bod == NIL)
4784 {
4785 MMset(m, 0, NIL);
4786 return 0;
4787 }
4788
4789 SBody * body = MMgetPointer<SBody*>(m, MTOP(bod));
4790 if (body == NULL)
4791 {
4792 MMset(m, 0, NIL);
4793 return 0;
4794 }
4795
4796 Ogre::Vector3 vector = body->GetCenterOfMass();
4797 int tuple = MMmalloc(m, 3, TYPETAB);
4798 if (tuple == NIL)
4799 {
4800 MMset(m, 0, NIL);
4801 return MERRMEM;
4802 }
4803
4804 MMstore(m, tuple, 0, FTOM((vector.x)));
4805 MMstore(m, tuple, 1, FTOM((vector.y)));
4806 MMstore(m, tuple, 2, FTOM((vector.z)));
4807 MMset(m, 0, PTOM(tuple));
4808 return 0;
4809}
4810
4811
4820int SO3BodyGetVelocity(mmachine m)
4821{
4822#ifdef SO3_DEBUG
4823 MMechostr(MSKDEBUG, "SO3BodyGetVelocity\n");
4824#endif
4825
4826 int bod = MMget(m, 0);
4827 if (bod == NIL)
4828 {
4829 MMset(m, 0, NIL);
4830 return 0;
4831 }
4832
4833 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4834 if (body == NULL)
4835 {
4836 MMset(m, 0, NIL);
4837 return 0;
4838 }
4839
4840 Ogre::Vector3 vec = body->GetVelocity();
4841 int tuple = MMmalloc(m, 3, TYPETAB);
4842 if (tuple == NIL)
4843 {
4844 MMset(m, 0, NIL);
4845 return MERRMEM;
4846 }
4847
4848 MMstore(m, tuple, 0, FTOM((vec.x)));
4849 MMstore(m, tuple, 1, FTOM((vec.y)));
4850 MMstore(m, tuple, 2, FTOM((vec.z)));
4851 MMset(m, 0, PTOM(tuple));
4852 return 0;
4853}
4854
4855
4864int SO3BodyGetTorque(mmachine m)
4865{
4866#ifdef SO3_DEBUG
4867 MMechostr(MSKDEBUG, "SO3BodyGetTorque\n");
4868#endif
4869
4870 int bod = MMget(m, 0);
4871 if (bod == NIL)
4872 {
4873 MMset(m, 0, NIL);
4874 return 0;
4875 }
4876
4877 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4878 if (body == NULL)
4879 {
4880 MMset(m, 0, NIL);
4881 return 0;
4882 }
4883
4884 Ogre::Vector3 vector = body->GetTorque();
4885 int tuple = MMmalloc(m, 3, TYPETAB);
4886 if (tuple == NIL)
4887 {
4888 MMset(m, 0, NIL);
4889 return MERRMEM;
4890 }
4891
4892 MMstore(m, tuple, 0, FTOM((vector.x)));
4893 MMstore(m, tuple, 1, FTOM((vector.y)));
4894 MMstore(m, tuple, 2, FTOM((vector.z)));
4895 MMset(m, 0, PTOM(tuple));
4896 return 0;
4897}
4898
4899
4911{
4912#ifdef SO3_DEBUG
4913 MMechostr(MSKDEBUG, "SO3BodyGetPositionOrientation\n");
4914#endif
4915
4916 int bod = MMget(m, 0);
4917 if (bod == NIL)
4918 {
4919 MMset(m, 0, NIL);
4920 return 0;
4921 }
4922
4923 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4924 if (body == NULL)
4925 {
4926 MMset(m, 0, NIL);
4927 return 0;
4928 }
4929
4930 Ogre::Vector3 vector;
4931 Ogre::Quaternion quat;
4932 body->GetPositionOrientation(vector, quat);
4933
4934 int position = MMmalloc(m, 3, TYPETAB);
4935 if (position == NIL)
4936 {
4937 MMset(m, 0, NIL);
4938 return MERRMEM;
4939 }
4940 MMstore(m, position, 0, FTOM(vector.x));
4941 MMstore(m, position, 1, FTOM(vector.y));
4942 MMstore(m, position, 2, FTOM(vector.z));
4943 MMpush(m, PTOM(position));
4944
4945 int orientation = MMmalloc(m, 4, TYPETAB);
4946 if (orientation == NIL)
4947 {
4948 MMset(m, 0, NIL);
4949 return MERRMEM;
4950 }
4951 MMstore(m, orientation, 0, FTOM(quat.x));
4952 MMstore(m, orientation, 1, FTOM(quat.y));
4953 MMstore(m, orientation, 2, FTOM(quat.z));
4954 MMstore(m, orientation, 3, FTOM(quat.w));
4955 MMpush(m, PTOM(orientation));
4956
4957 // FINAL TUPPLE
4958 int result = MMmalloc(m, 2, TYPETAB);
4959 if (result == NIL)
4960 {
4961 MMset(m, 0, NIL);
4962 return MERRMEM;
4963 }
4964 MMstore(m, result, 1, MMpull(m));
4965 MMstore(m, result, 0, MMpull(m));
4966 MMset(m, 0, PTOM(result));
4967 return 0;
4968}
4969
4970
4980int SO3BodySetFreeze(mmachine m)
4981{
4982#ifdef SO3_DEBUG
4983 MMechostr(MSKDEBUG, "SO3BodySetFreeze\n");
4984#endif
4985
4986 int val = MTOI(MMpull(m));
4987 int bod = MMget(m, 0);
4988 if (bod == NIL)
4989 {
4990 MMset(m, 0, NIL);
4991 return 0;
4992 }
4993
4994 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
4995 if (body == NULL)
4996 {
4997 MMset(m, 0, NIL);
4998 return 0;
4999 }
5000
5001 if (val > 0)
5002 {
5003 body->SetFreezeState(true);
5004 }
5005 else
5006 {
5007 body->SetFreezeState(false);
5008 }
5009 MMset(m, 0, ITOM(1));
5010 return 0;
5011}
5012
5013
5022int SO3BodyGetFreeze(mmachine m)
5023{
5024#ifdef SO3_DEBUG
5025 MMechostr(MSKDEBUG, "SO3BodyGetFreeze\n");
5026#endif
5027
5028 int bod = MMget(m, 0);
5029 if (bod == NIL)
5030 {
5031 MMset(m, 0, NIL);
5032 return 0;
5033 }
5034
5035 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
5036 if (body == NULL)
5037 {
5038 MMset(m, 0, NIL);
5039 return 0;
5040 }
5041
5042 int val = 0;
5043 if (body->GetFreezeState())
5044 val = 1;
5045
5046 MMset(m, 0, MTOI(val));
5047 return 0;
5048}
5049
5050
5061{
5062#ifdef SO3_DEBUG
5063 MMechostr(MSKDEBUG, "SO3BodySetSimulation\n");
5064#endif
5065
5066 int val = MTOI(MMpull(m));
5067 int bod = MMget(m, 0);
5068 if (bod == NIL)
5069 {
5070 MMset(m, 0, NIL);
5071 return 0;
5072 }
5073
5074 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
5075 if (body == NULL)
5076 {
5077 MMset(m, 0, NIL);
5078 return 0;
5079 }
5080
5081 if (val > 0)
5082 {
5083 body->EnableSimulation(true);
5084 }
5085 else
5086 {
5087 body->EnableSimulation(false);
5088 }
5089
5090 MMset(m, 0, ITOM(1));
5091 return 0;
5092}
5093
5094
5104{
5105#ifdef SO3_DEBUG
5106 MMechostr(MSKDEBUG, "SO3BodyGetSimulation\n");
5107#endif
5108
5109 int bod = MMget(m, 0);
5110 if (bod == NIL)
5111 {
5112 MMset(m, 0, NIL);
5113 return 0;
5114 }
5115
5116 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
5117 if (body == NULL)
5118 {
5119 MMset(m, 0, NIL);
5120 return 0;
5121 }
5122
5123 int val = 0;
5124 if (body->GetSimulationState())
5125 val = 1;
5126
5127 MMset(m, 0, MTOI(val));
5128 return 0;
5129}
5130
5131
5142{
5143#ifdef SO3_DEBUG
5144 MMechostr(MSKDEBUG, "SO3BodySetGravityEnable\n");
5145#endif
5146
5147 int val = MTOI(MMpull(m));
5148 int bod = MMget(m, 0);
5149 if (bod == NIL)
5150 {
5151 MMset(m, 0, NIL);
5152 return 0;
5153 }
5154
5155 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
5156 if (body == NULL)
5157 {
5158 MMset(m, 0, NIL);
5159 return 0;
5160 }
5161
5162 if (val == 1)
5163 {
5164 body->SetGravityEnable(true);
5165 }
5166 else
5167 {
5168 body->SetGravityEnable(false);
5169 }
5170 MMset(m, 0, ITOM(1));
5171 return 0;
5172}
5173
5174
5184{
5185#ifdef SO3_DEBUG
5186 MMechostr(MSKDEBUG, "SO3BodyGetGravityEnable\n");
5187#endif
5188
5189 int bod = MMget(m, 0);
5190 if (bod == NIL)
5191 {
5192 MMset(m, 0, NIL);
5193 return 0;
5194 }
5195
5196 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
5197 if (body == NULL)
5198 {
5199 MMset(m, 0, NIL);
5200 return 0;
5201 }
5202
5203 int val = 0;
5204 if (body->GetGravityEnable())
5205 val = 1;
5206
5207 MMset(m, 0, ITOM(val));
5208 return 0;
5209}
5210
5211
5220int SO3BodyGetSceneNode(mmachine m)
5221{
5222#ifdef SO3_DEBUG
5223 MMechostr(MSKDEBUG, "SO3BodyGetSceneNode\n");
5224#endif
5225
5226 int bod = MMget(m, 0);
5227 if (bod == NIL)
5228 {
5229 MMset(m, 0, NIL);
5230 return 0;
5231 }
5232
5233 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
5234 if (body == NULL)
5235 {
5236 MMset(m, 0, NIL);
5237 return 0;
5238 }
5239
5240 int c = OBJfindTH(m, SO3OBJTYPE, SCOL_PTR(body->GetParentNode()));
5241 if (c != NIL)
5242 c = MMfetch(m, c, OFFOBJMAG);
5243
5244 MMset(m, 0, c);
5245 return 0;
5246}
5247
5248
5257int SO3BodyDestroy(mmachine m)
5258{
5259#ifdef SO3_DEBUG
5260 MMechostr(MSKDEBUG, "SO3BodyDestroy\n");
5261#endif
5262
5263 int body = MMget(m, 0);
5264 if (body == NIL)
5265 {
5266 MMset(m, 0, NIL);
5267 return 0;
5268 }
5269
5270 OBJdelTM(m, SO3PHYSICBODY, body);
5271
5272 MMset(m, 0, ITOM(1));
5273 return 0;
5274}
5275
5276
5286int SO3BodyShowDebug(mmachine m)
5287{
5288#ifdef SO3_DEBUG
5289 MMechostr(MSKDEBUG, "SO3BodyShowDebug\n");
5290#endif
5291
5292 int istate = MMpull(m);
5293 int ibody = MMget(m, 0);
5294 if (ibody == NIL)
5295 {
5296 MMset(m, 0, NIL);
5297 return 0;
5298 }
5299
5300 SBody* body = MMgetPointer<SBody*>(m, MTOP(ibody));
5301 if (body == NULL)
5302 {
5303 MMset(m, 0, NIL);
5304 return 0;
5305 }
5306
5307 bool state = false;
5308 if ((istate != NIL) && (MTOI(istate) > 0))
5309 state = true;
5310
5311 body->ShowDebug(state);
5312
5313 MMset(m, 0, ITOM(1));
5314 return 0;
5315}
5316
5325int SO3SceneNodeGetBody(mmachine m)
5326{
5327#ifdef SO3_DEBUG
5328 MMechostr(MSKDEBUG, "SO3SceneNodeGetBody\n");
5329#endif
5330
5331 int n = MMget(m, 0);
5332 if (n == NIL)
5333 {
5334 MMset(m, 0, NIL);
5335 return 0;
5336 }
5337
5338 SNode* node = MMgetPointer<SNode*>(m, MTOP(n));
5339 if (node == NULL)
5340 {
5341 MMset(m, 0, NIL);
5342 return 0;
5343 }
5344
5345 if (!node->GetParentScene()->GetPhysicsWorld())
5346 {
5347 MMset(m, 0, NIL);
5348 return 0;
5349 }
5350
5351 if (node->GetSceneNodeBody() == 0)
5352 {
5353 MMset(m, 0, NIL);
5354 return 0;
5355 }
5356
5357 int mbody = OBJfindTH(m, SO3PHYSICBODY, SCOL_PTR node->GetSceneNodeBody());
5358 if (mbody != NIL)
5359 mbody = MMfetch(m, mbody, OFFOBJMAG);
5360
5361 MMset(m, 0, mbody);
5362 return 0;
5363}
5364
5365
5377int SO3PhysicsRayCast(mmachine m)
5378{
5379#ifdef SO3_DEBUG
5380 MMechostr(MSKDEBUG, "SO3PhysicsRayCast\n");
5381#endif
5382
5383 int dist = MMpull(m);
5384 int dir = MTOP(MMpull(m));
5385 int src = MTOP(MMpull(m));
5386 int s = MMget(m, 0);
5387 if ((s == NIL) || (dir == NIL) || (src == NIL) || (dist == NIL))
5388 {
5389 MMset(m, 0, NIL);
5390 return 0;
5391 }
5392
5393 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
5394 if (scene == NULL)
5395 {
5396 MMset(m, 0, NIL);
5397 return 0;
5398 }
5399
5400 if (!scene->GetPhysicsWorld())
5401 {
5402 MMset(m, 0, NIL);
5403 return 0;
5404 }
5405
5406 int x1 = MMfetch(m, src, 0);
5407 int y1 = MMfetch(m, src, 1);
5408 int z1 = MMfetch(m, src, 2);
5409
5410 if ((x1 == NIL) || (y1 == NIL) || (z1 == NIL))
5411 {
5412 MMset(m, 0, NIL);
5413 return 0;
5414 }
5415
5416 Ogre::Vector3 srcVector(MTOF(x1), MTOF(y1), MTOF(z1));
5417
5418 int x2 = MMfetch(m, dir, 0);
5419 int y2 = MMfetch(m, dir, 1);
5420 int z2 = MMfetch(m, dir, 2);
5421
5422 if ((x2 == NIL) || (y2 == NIL) || (z2 == NIL))
5423 {
5424 MMset(m, 0, NIL);
5425 return 0;
5426 }
5427
5428 Ogre::Vector3 dirVector(MTOF(x2), MTOF(y2), MTOF(z2));
5429
5430 Ogre::Real hitdist = 0;
5431 Ogre::Vector3 hitnormal = Ogre::Vector3::ZERO;
5432 SBody* hitbody = scene->GetPhysicsWorld()->PhysicsRayCast(srcVector, dirVector, MTOF(dist), hitdist, hitnormal);
5433
5434 // no hit
5435 if (hitbody == 0)
5436 {
5437 MMset(m, 0, NIL);
5438 return 0;
5439 }
5440
5441 int mbody = OBJfindTH(m, SO3PHYSICBODY, SCOL_PTR hitbody);
5442 if (mbody != NIL)
5443 mbody = MMfetch(m, mbody, OFFOBJMAG);
5444
5445 // push body
5446 MMpush(m, mbody);
5447
5448 //push dist
5449 MMpush(m, FTOM(hitdist));
5450
5451 //normal tuple
5452 int tuple = MMmalloc(m, 3, TYPETAB);
5453 if (tuple == NIL)
5454 {
5455 MMset(m, 0, NIL);
5456 return MERRMEM;
5457 }
5458
5459 MMstore(m, tuple, 0, FTOM((hitnormal.x)));
5460 MMstore(m, tuple, 1, FTOM((hitnormal.y)));
5461 MMstore(m, tuple, 2, FTOM((hitnormal.z)));
5462 //push normal tuple
5463 MMpush(m, PTOM(tuple));
5464
5465 // FINAL TUPPLE
5466 int result = MMmalloc(m, 3, TYPETAB);
5467 if (result == NIL)
5468 {
5469 MMset(m, 0, NIL);
5470 return MERRMEM;
5471 }
5472
5473 MMstore(m, result, 2, MMpull(m));
5474 MMstore(m, result, 1, MMpull(m));
5475 MMstore(m, result, 0, MMpull(m));
5476 //set result
5477 MMset(m, 0, PTOM(result));
5478
5479#ifdef SO3_DEBUG
5480 MMechostr(MSKDEBUG, "SO3PhysicsRayCast: OK!\n");
5481#endif
5482 return 0;
5483}
5484
5497{
5498#ifdef SO3_DEBUG
5499 MMechostr(MSKDEBUG, "SO3PhysicsRayCastExt\n");
5500#endif
5501
5502 int dist = MMpull(m);
5503 int dir = MTOP(MMpull(m));
5504 int src = MTOP(MMpull(m));
5505 int s = MMget(m, 0);
5506 if ((s == NIL) || (dir == NIL) || (src == NIL) || (dist == NIL))
5507 {
5508 MMset(m, 0, NIL);
5509 return 0;
5510 }
5511
5512 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
5513 if (scene == NULL)
5514 {
5515 MMset(m, 0, NIL);
5516 return 0;
5517 }
5518
5519 if (!scene->GetPhysicsWorld())
5520 {
5521 MMset(m, 0, NIL);
5522 return 0;
5523 }
5524
5525 int x1 = MMfetch(m, src, 0);
5526 int y1 = MMfetch(m, src, 1);
5527 int z1 = MMfetch(m, src, 2);
5528
5529 if ((x1 == NIL) || (y1 == NIL) || (z1 == NIL))
5530 {
5531 MMset(m, 0, NIL);
5532 return 0;
5533 }
5534
5535 Ogre::Vector3 srcVector(MTOF(x1), MTOF(y1), MTOF(z1));
5536
5537 int x2 = MMfetch(m, dir, 0);
5538 int y2 = MMfetch(m, dir, 1);
5539 int z2 = MMfetch(m, dir, 2);
5540
5541 if ((x2 == NIL) || (y2 == NIL) || (z2 == NIL))
5542 {
5543 MMset(m, 0, NIL);
5544 return 0;
5545 }
5546 MMpull(m);
5547
5548 Ogre::Vector3 dirVector(MTOF(x2), MTOF(y2), MTOF(z2));
5549 std::vector<MRAYINFO> hitbodies = scene->GetPhysicsWorld()->PhysicsRayCast(srcVector, dirVector, MTOF(dist));
5550
5551 for (unsigned int i = 0; i < hitbodies.size(); i++)
5552 {
5553 MRAYINFO rinfo = hitbodies[i];
5554 int mbody = OBJfindTH(m, SO3PHYSICBODY, SCOL_PTR rinfo.body);
5555 if (mbody != NIL)
5556 mbody = MMfetch(m, mbody, OFFOBJMAG);
5557
5558 // push body
5559 MMpush(m, mbody);
5560
5561 //push dist
5562 MMpush(m, FTOM(rinfo.distance));
5563
5564 //normal tuple
5565 int tuple = MMmalloc(m, 3, TYPETAB);
5566 if (tuple == NIL)
5567 {
5568 MMset(m, 0, NIL);
5569 return MERRMEM;
5570 }
5571
5572 MMstore(m, tuple, 0, FTOM((rinfo.normal.x)));
5573 MMstore(m, tuple, 1, FTOM((rinfo.normal.y)));
5574 MMstore(m, tuple, 2, FTOM((rinfo.normal.z)));
5575 //push normal tuple
5576 MMpush(m, PTOM(tuple));
5577
5578 // FINAL TUPPLE
5579 int result = MMmalloc(m, 3, TYPETAB);
5580 if (result == NIL)
5581 {
5582 MMset(m, 0, NIL);
5583 return MERRMEM;
5584 }
5585
5586 MMstore(m, result, 2, MMpull(m));
5587 MMstore(m, result, 1, MMpull(m));
5588 MMstore(m, result, 0, MMpull(m));
5589 //set result
5590 MMpush(m, PTOM(result));
5591 }
5592
5593 if (MMpush(m, NIL))
5594 return MERRMEM;
5595
5596 for (unsigned int j = 0; j < hitbodies.size(); j++)
5597 {
5598 if (MMpush(m, 2 * 2))
5599 return MERRMEM;
5600 if (int k = MBdeftab(m))
5601 return k;
5602 }
5603
5604#ifdef SO3_DEBUG
5605 MMechostr(MSKDEBUG, "SO3PhysicsRayCast: OK!\n");
5606#endif
5607 return 0;
5608}
5609
5619{
5620#ifdef SO3_DEBUG
5621 MMechostr(MSKDEBUG, "SO3PhysicsContraintDestroy\n");
5622#endif
5623
5624 int joint = MMget(m, 0);
5625 if (joint == NIL)
5626 {
5627 MMset(m, 0, NIL);
5628 return 0;
5629 }
5630
5631 OBJdelTM(m, SO3PHYSICCONTRAINT, joint);
5632
5633 MMset(m, 0, ITOM(1));
5634 return 0;
5635}
5636
5637
5648{
5649#ifdef SO3_DEBUG
5650 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetCollisionState\n");
5651#endif
5652
5653 int state = MMpull(m);
5654 int mjoint = MMget(m, 0);
5655 if (mjoint == NIL)
5656 {
5657 MMset(m, 0, NIL);
5658 return 0;
5659 }
5660
5661 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
5662 if (joint == NULL)
5663 {
5664 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetCollisionState bad joint type.\n");
5665 MMset(m, 0, NIL);
5666 return 0;
5667 }
5668
5669 bool bstate = false;
5670 if (state != NIL && (MTOI(state) == 1))
5671 bstate = true;
5672
5673 joint->SetCollisionState(bstate);
5674
5675 MMset(m, 0, ITOM(1));
5676 return 0;
5677}
5678
5688{
5689#ifdef SO3_DEBUG
5690 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetCollisionState\n");
5691#endif
5692
5693 int mjoint = MMget(m, 0);
5694 if (mjoint == NIL)
5695 {
5696 MMset(m, 0, NIL);
5697 return 0;
5698 }
5699
5700 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
5701 if (joint == NULL)
5702 {
5703 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetCollisionState bad joint type.\n");
5704 MMset(m, 0, NIL);
5705 return 0;
5706 }
5707
5708 bool bstate = joint->GetCollisionState();
5709
5710 MMset(m, 0, bstate ? ITOM(1) : ITOM(0));
5711 return 0;
5712}
5713
5714
5725{
5726#ifdef SO3_DEBUG
5727 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetStiffness\n");
5728#endif
5729
5730 int val = MMpull(m);
5731 int mjoint = MMget(m, 0);
5732 if (mjoint == NIL)
5733 {
5734 MMset(m, 0, NIL);
5735 return 0;
5736 }
5737
5738 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
5739 if (joint == NULL)
5740 {
5741 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetStiffness bad joint type.\n");
5742 MMset(m, 0, NIL);
5743 return 0;
5744 }
5745
5746 Ogre::Real value = 1.0f;
5747 if (val != NIL)
5748 value = MTOF(val);
5749
5750 joint->SetStiffness(value);
5751
5752 MMset(m, 0, ITOM(1));
5753 return 0;
5754}
5755
5765{
5766#ifdef SO3_DEBUG
5767 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetStiffness\n");
5768#endif
5769
5770 int mjoint = MMget(m, 0);
5771 if (mjoint == NIL)
5772 {
5773 MMset(m, 0, NIL);
5774 return 0;
5775 }
5776
5777 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
5778 if (joint == NULL)
5779 {
5780 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetStiffness bad joint type.\n");
5781 MMset(m, 0, NIL);
5782 return 0;
5783 }
5784
5785 Ogre::Real value = joint->GetStiffness();
5786
5787 MMset(m, 0, FTOM(value));
5788 return 0;
5789}
5790
5791
5805{
5806#ifdef SO3_DEBUG
5807 MMechostr(MSKDEBUG, "SO3PhysicsContraintCreateBallAndSocket\n");
5808#endif
5809
5810 int limits = MMpull(m);
5811 int vec = MTOP(MMpull(m));
5812 int parentbod = MMpull(m);
5813 int sonbod = MMpull(m);
5814 int s = MMget(m, 0);
5815 if (s == NIL || sonbod == NIL)
5816 {
5817 MMset(m, 0, NIL);
5818 return 0;
5819 }
5820
5821 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
5822 if (scene == NULL)
5823 {
5824 MMset(m, 0, NIL);
5825 return 0;
5826 }
5827
5828 SBody* sonBody = MMgetPointer<SBody*>(m, MTOP(sonbod));
5829 if (sonBody == NULL || sonBody->GetParentNode()->GetParentScene() != scene)
5830 {
5831 MMechostr(MSKRUNTIME, "SO3PhysicsContraintCreateBallAndSocket bad body to create joint or the body is not in the same scene.\n");
5832 MMset(m, 0, NIL);
5833 return 0;
5834 }
5835
5836 SBody* parentBody = 0;
5837 if (parentbod != NIL)
5838 parentBody = MMgetPointer<SBody*>(m, MTOP(parentbod));
5839
5840 if (parentBody != NULL && parentBody->GetParentNode()->GetParentScene() != scene)
5841 {
5842 MMechostr(MSKRUNTIME, "SO3PhysicsContraintCreateBallAndSocket bad body to create joint or the body is not in the same scene.\n");
5843 MMset(m, 0, NIL);
5844 return 0;
5845 }
5846
5847 Ogre::Vector3 position = Ogre::Vector3::ZERO;
5848 if (vec != NIL)
5849 {
5850 int x = MMfetch(m, vec, 0);
5851 int y = MMfetch(m, vec, 1);
5852 int z = MMfetch(m, vec, 2);
5853
5854 if ((x != NIL) && (y != NIL) && (z != NIL))
5855 position = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
5856 }
5857
5858 bool useLimits = false;
5859 if (limits != NIL && (MTOI(limits) == 1))
5860 useLimits = true;
5861
5862 SPhysicContraint* joint = 0;
5863 if (scene->GetPhysicsWorld())
5864 {
5865 joint = static_cast<SPhysicContraint*> (new SBallAndSocketContraint(scene, sonBody, parentBody, position, useLimits));
5866 scene->GetPhysicsWorld()->AddPhysicContraint(joint);
5867 }
5868
5869 if (joint == NULL)
5870 {
5871 MMechostr(MSKDEBUG, "SO3PhysicsContraintCreateBallAndSocket : failed to create joint\n");
5872 MMset(m, 0, NIL);
5873 return 0;
5874 }
5875
5876 // remove last parameter
5877 MMpull(m);
5878 return createPhysicContraint(m, joint);
5879}
5880
5881
5894{
5895#ifdef SO3_DEBUG
5896 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetBallAndSocketLimits\n");
5897#endif
5898
5899 int mtwist = MMpull(m);
5900 int mitwist = MMpull(m);
5901 int mcone = MMpull(m);
5902 int mjoint = MMget(m, 0);
5903 if (mjoint == NIL)
5904 {
5905 MMset(m, 0, NIL);
5906 return 0;
5907 }
5908
5909 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
5910 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_BALL_AND_SOCKET_CONTRAINT)
5911 {
5912 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetBallAndSocketLimits bad joint type.\n");
5913 MMset(m, 0, NIL);
5914 return 0;
5915 }
5916
5917 Ogre::Radian maxcone(0.0f);
5918 if (mcone != NIL)
5919 maxcone = MTOF(mcone);
5920
5921 Ogre::Radian mintwist(0.0f);
5922 if (mitwist != NIL)
5923 mintwist = MTOF(mitwist);
5924
5925 Ogre::Radian maxtwist(0.0f);
5926 if (mtwist != NIL)
5927 maxtwist = MTOF(mtwist);
5928
5929 static_cast<SBallAndSocketContraint*>(joint)->SetLimits(maxcone, mintwist, maxtwist);
5930
5931 MMset(m, 0, ITOM(1));
5932 return 0;
5933}
5934
5935
5946{
5947#ifdef SO3_DEBUG
5948 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetBallAndSocketControlled\n");
5949#endif
5950
5951 int ctrl = MMpull(m);
5952 int mjoint = MMget(m, 0);
5953 if (mjoint == NIL)
5954 {
5955 MMset(m, 0, NIL);
5956 return 0;
5957 }
5958
5959 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
5960 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_BALL_AND_SOCKET_CONTRAINT)
5961 {
5962 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetBallAndSocketControlled bad joint type.\n");
5963 MMset(m, 0, NIL);
5964 return 0;
5965 }
5966
5967 bool controlled = false;
5968 if (ctrl != NIL)
5969 controlled = (MTOI(ctrl) > 0) ? true : false;
5970
5971 static_cast<SBallAndSocketContraint*>(joint)->SetControlledState(controlled);
5972
5973 MMset(m, 0, ITOM(1));
5974 return 0;
5975}
5976
5977
5989{
5990#ifdef SO3_DEBUG
5991 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetBallAndSocketAngularVelocity\n");
5992#endif
5993
5994 int val = MMpull(m);
5995 int mjoint = MMget(m, 0);
5996 if (mjoint == NIL)
5997 {
5998 MMset(m, 0, NIL);
5999 return 0;
6000 }
6001
6002 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6003 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_BALL_AND_SOCKET_CONTRAINT)
6004 {
6005 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetBallAndSocketAngularVelocity bad joint type.\n");
6006 MMset(m, 0, NIL);
6007 return 0;
6008 }
6009
6010 float value = 0.0f;
6011 if (val != NIL)
6012 value = MTOF(val);
6013
6014 static_cast<SBallAndSocketContraint*>(joint)->SetAngularVelocity(value);
6015
6016 MMset(m, 0, ITOM(1));
6017 return 0;
6018}
6019
6020
6032{
6033#ifdef SO3_DEBUG
6034 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetBallAndSocketYawAngle\n");
6035#endif
6036
6037 int val = MMpull(m);
6038 int mjoint = MMget(m, 0);
6039 if (mjoint == NIL)
6040 {
6041 MMset(m, 0, NIL);
6042 return 0;
6043 }
6044
6045 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6046 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_BALL_AND_SOCKET_CONTRAINT)
6047 {
6048 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetBallAndSocketYawAngle bad joint type.\n");
6049 MMset(m, 0, NIL);
6050 return 0;
6051 }
6052
6053 float value = 0.0f;
6054 if (val != NIL)
6055 value = MTOF(val);
6056
6057 static_cast<SBallAndSocketContraint*>(joint)->SetYawAngle(value);
6058
6059 MMset(m, 0, ITOM(1));
6060 return 0;
6061}
6062
6063
6075{
6076#ifdef SO3_DEBUG
6077 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetBallAndSocketPitchAngle\n");
6078#endif
6079
6080 int val = MMpull(m);
6081 int mjoint = MMget(m, 0);
6082 if (mjoint == NIL)
6083 {
6084 MMset(m, 0, NIL);
6085 return 0;
6086 }
6087
6088 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6089 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_BALL_AND_SOCKET_CONTRAINT)
6090 {
6091 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetBallAndSocketPitchAngle bad joint type.\n");
6092 MMset(m, 0, NIL);
6093 return 0;
6094 }
6095
6096 float value = 0.0f;
6097 if (val != NIL)
6098 value = MTOF(val);
6099
6100 static_cast<SBallAndSocketContraint*>(joint)->SetPitchAngle(value);
6101
6102 MMset(m, 0, ITOM(1));
6103 return 0;
6104}
6105
6106
6118{
6119#ifdef SO3_DEBUG
6120 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetBallAndSocketRollAngle\n");
6121#endif
6122
6123 int val = MMpull(m);
6124 int mjoint = MMget(m, 0);
6125 if (mjoint == NIL)
6126 {
6127 MMset(m, 0, NIL);
6128 return 0;
6129 }
6130
6131 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6132 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_BALL_AND_SOCKET_CONTRAINT)
6133 {
6134 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetBallAndSocketRollAngle bad joint type.\n");
6135 MMset(m, 0, NIL);
6136 return 0;
6137 }
6138
6139 float value = 0.0f;
6140 if (val != NIL)
6141 value = MTOF(val);
6142
6143 static_cast<SBallAndSocketContraint*>(joint)->SetRollAngle(value);
6144
6145 MMset(m, 0, ITOM(1));
6146 return 0;
6147}
6148
6149
6159{
6160#ifdef SO3_DEBUG
6161 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetBallAndSocketAngle\n");
6162#endif
6163
6164 int mjoint = MMget(m, 0);
6165 if (mjoint == NIL)
6166 {
6167 MMset(m, 0, NIL);
6168 return 0;
6169 }
6170
6171 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6172 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_BALL_AND_SOCKET_CONTRAINT)
6173 {
6174 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetBallAndSocketAngle bad joint type.\n");
6175 MMset(m, 0, NIL);
6176 return 0;
6177 }
6178
6179 Ogre::Vector3 vec = static_cast<SBallAndSocketContraint*>(joint)->GetAngle();
6180 int tuple = MMmalloc(m, 3, TYPETAB);
6181 if (tuple == NIL)
6182 {
6183 MMset(m, 0, NIL);
6184 return MERRMEM;
6185 }
6186
6187 MMstore(m, tuple, 0, FTOM((vec.x)));
6188 MMstore(m, tuple, 1, FTOM((vec.y)));
6189 MMstore(m, tuple, 2, FTOM((vec.z)));
6190 MMset(m, 0, PTOM(tuple));
6191
6192 return 0;
6193}
6194
6195
6205{
6206#ifdef SO3_DEBUG
6207 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetBallAndSocketOmega\n");
6208#endif
6209
6210 int mjoint = MMget(m, 0);
6211 if (mjoint == NIL)
6212 {
6213 MMset(m, 0, NIL);
6214 return 0;
6215 }
6216
6217 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6218 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_BALL_AND_SOCKET_CONTRAINT)
6219 {
6220 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetBallAndSocketOmega bad joint type.\n");
6221 MMset(m, 0, NIL);
6222 return 0;
6223 }
6224
6225 Ogre::Vector3 vec = static_cast<SBallAndSocketContraint*>(joint)->GetOmega();
6226 int tuple = MMmalloc(m, 3, TYPETAB);
6227 if (tuple == NIL)
6228 {
6229 MMset(m, 0, NIL);
6230 return MERRMEM;
6231 }
6232
6233 MMstore(m, tuple, 0, FTOM((vec.x)));
6234 MMstore(m, tuple, 1, FTOM((vec.y)));
6235 MMstore(m, tuple, 2, FTOM((vec.z)));
6236 MMset(m, 0, PTOM(tuple));
6237
6238 return 0;
6239}
6240
6241
6251{
6252#ifdef SO3_DEBUG
6253 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetBallAndSocketForce\n");
6254#endif
6255
6256 int mjoint = MMget(m, 0);
6257 if (mjoint == NIL)
6258 {
6259 MMset(m, 0, NIL);
6260 return 0;
6261 }
6262
6263 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6264 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_BALL_AND_SOCKET_CONTRAINT)
6265 {
6266 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetBallAndSocketForce bad joint type.\n");
6267 MMset(m, 0, NIL);
6268 return 0;
6269 }
6270
6271 Ogre::Vector3 vec = static_cast<SBallAndSocketContraint*>(joint)->GetForce();
6272 int tuple = MMmalloc(m, 3, TYPETAB);
6273 if (tuple == NIL)
6274 {
6275 MMset(m, 0, NIL);
6276 return MERRMEM;
6277 }
6278
6279 MMstore(m, tuple, 0, FTOM((vec.x)));
6280 MMstore(m, tuple, 1, FTOM((vec.y)));
6281 MMstore(m, tuple, 2, FTOM((vec.z)));
6282 MMset(m, 0, PTOM(tuple));
6283
6284 return 0;
6285}
6286
6287
6302{
6303#ifdef SO3_DEBUG
6304 MMechostr(MSKDEBUG, "SO3PhysicsContraintCreateHinge\n");
6305#endif
6306
6307 int limits = MMpull(m);
6308 int dir = MTOP(MMpull(m));
6309 int vec = MTOP(MMpull(m));
6310 int parentbod = MMpull(m);
6311 int sonbod = MMpull(m);
6312 int s = MMget(m, 0);
6313 if (s == NIL || sonbod == NIL)
6314 {
6315 MMset(m, 0, NIL);
6316 return 0;
6317 }
6318
6319 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
6320 if (scene == NULL)
6321 {
6322 MMset(m, 0, NIL);
6323 return 0;
6324 }
6325
6326 SBody* sonBody = MMgetPointer<SBody*>(m, MTOP(sonbod));
6327 if (sonBody == NULL || sonBody->GetParentNode()->GetParentScene() != scene)
6328 {
6329 MMechostr(MSKRUNTIME, "SO3PhysicsContraintCreateHinge bad body to create joint or the body is not in the same scene.\n");
6330 MMset(m, 0, NIL);
6331 return 0;
6332 }
6333
6334 SBody* parentBody = 0;
6335 if (parentbod != NIL)
6336 parentBody = MMgetPointer<SBody*>(m, MTOP(parentbod));
6337
6338 if (parentBody != NULL && parentBody->GetParentNode()->GetParentScene() != scene)
6339 {
6340 MMechostr(MSKRUNTIME, "SO3PhysicsContraintCreateHinge bad body to create joint or the body is not in the same scene.\n");
6341 MMset(m, 0, NIL);
6342 return 0;
6343 }
6344
6345 Ogre::Vector3 position = Ogre::Vector3::ZERO;
6346 if (vec != NIL)
6347 {
6348 int x = MMfetch(m, vec, 0);
6349 int y = MMfetch(m, vec, 1);
6350 int z = MMfetch(m, vec, 2);
6351
6352 if ((x != NIL) && (y != NIL) && (z != NIL))
6353 position = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
6354 }
6355
6356 Ogre::Vector3 direction = Ogre::Vector3(0.0f, 1.0f, 0.0f);
6357 if (dir != NIL)
6358 {
6359 int x = MMfetch(m, dir, 0);
6360 int y = MMfetch(m, dir, 1);
6361 int z = MMfetch(m, dir, 2);
6362
6363 if ((x != NIL) && (y != NIL) && (z != NIL))
6364 direction = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
6365 }
6366
6367 bool useLimits = false;
6368 if (limits != NIL && (MTOI(limits) == 1))
6369 useLimits = true;
6370
6371 SPhysicContraint* joint = 0;
6372 if (scene->GetPhysicsWorld())
6373 {
6374 joint = static_cast<SPhysicContraint*> (new SHingeContraint(scene, sonBody, parentBody, position, direction, useLimits));
6375 scene->GetPhysicsWorld()->AddPhysicContraint(joint);
6376 }
6377
6378 if (joint == NULL)
6379 {
6380 MMechostr(MSKDEBUG, "SO3PhysicsContraintCreateHinge : failed to create joint\n");
6381 MMset(m, 0, NIL);
6382 return 0;
6383 }
6384
6385 // remove last parameter
6386 MMpull(m);
6387 return createPhysicContraint(m, joint);
6388}
6389
6390
6400{
6401#ifdef SO3_DEBUG
6402 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetHingeAngle\n");
6403#endif
6404
6405 int mjoint = MMget(m, 0);
6406 if (mjoint == NIL)
6407 {
6408 MMset(m, 0, NIL);
6409 return 0;
6410 }
6411
6412 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6413 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_HINGE_CONTRAINT)
6414 {
6415 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetHingeAngle bad joint type.\n");
6416 MMset(m, 0, NIL);
6417 return 0;
6418 }
6419
6420 Ogre::Radian value = static_cast<SHingeContraint*>(joint)->GetAngle();
6421 MMset(m, 0, FTOM(value.valueRadians()));
6422
6423 return 0;
6424}
6425
6426
6436{
6437#ifdef SO3_DEBUG
6438 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetHingeOmega\n");
6439#endif
6440
6441 int mjoint = MMget(m, 0);
6442 if (mjoint == NIL)
6443 {
6444 MMset(m, 0, NIL);
6445 return 0;
6446 }
6447
6448 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6449 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_HINGE_CONTRAINT)
6450 {
6451 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetHingeOmega bad joint type.\n");
6452 MMset(m, 0, NIL);
6453 return 0;
6454 }
6455
6456 Ogre::Radian value = static_cast<SHingeContraint*>(joint)->GetAngularVelocity();
6457 MMset(m, 0, FTOM(value.valueRadians()));
6458
6459 return 0;
6460}
6461
6462
6472{
6473#ifdef SO3_DEBUG
6474 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetHingeForce\n");
6475#endif
6476
6477 int mjoint = MMget(m, 0);
6478 if (mjoint == NIL)
6479 {
6480 MMset(m, 0, NIL);
6481 return 0;
6482 }
6483
6484 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6485 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_HINGE_CONTRAINT)
6486 {
6487 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetHingeForce bad joint type.\n");
6488 MMset(m, 0, NIL);
6489 return 0;
6490 }
6491
6492 Ogre::Vector3 vec = static_cast<SHingeContraint*>(joint)->GetForce();
6493 int tuple = MMmalloc(m, 3, TYPETAB);
6494 if (tuple == NIL)
6495 {
6496 MMset(m, 0, NIL);
6497 return MERRMEM;
6498 }
6499
6500 MMstore(m, tuple, 0, FTOM((vec.x)));
6501 MMstore(m, tuple, 1, FTOM((vec.y)));
6502 MMstore(m, tuple, 2, FTOM((vec.z)));
6503 MMset(m, 0, PTOM(tuple));
6504
6505 return 0;
6506}
6507
6508
6517bool MaterialIDExists(SScene* scene, string testName, SMaterialID **result)
6518{
6519 if (!scene->GetPhysicsWorld())
6520 return false;
6521
6522 SMaterialIDMap::iterator iMaterialIDSearched = scene->GetPhysicsWorld()->listOfMaterialID.find(testName);
6523 if (iMaterialIDSearched != scene->GetPhysicsWorld()->listOfMaterialID.end())
6524 {
6525 *result = iMaterialIDSearched->second;
6526 return true;
6527 }
6528 return false;
6529}
6530
6531
6543{
6544#ifdef SO3_DEBUG
6545 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetHingeLimits\n");
6546#endif
6547
6548 int maangle = MMpull(m);
6549 int miangle = MMpull(m);
6550 int mjoint = MMget(m, 0);
6551 if (mjoint == NIL)
6552 {
6553 MMset(m, 0, NIL);
6554 return 0;
6555 }
6556
6557 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6558 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_HINGE_CONTRAINT)
6559 {
6560 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetHingeLimits bad joint type.\n");
6561 MMset(m, 0, NIL);
6562 return 0;
6563 }
6564
6565 Ogre::Radian minangle(0.0f);
6566 if (miangle != NIL)
6567 minangle = MTOF(miangle);
6568
6569 Ogre::Radian maxangle(0.0f);
6570 if (maangle != NIL)
6571 maxangle = MTOF(maangle);
6572
6573 static_cast<SHingeContraint*>(joint)->SetLimits(minangle, maxangle);
6574
6575 MMset(m, 0, ITOM(1));
6576 return 0;
6577}
6578
6591{
6592#ifdef SO3_DEBUG
6593 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetHingeAngle\n");
6594#endif
6595
6596 int mafrict = MMpull(m);
6597 int mifrict = MMpull(m);
6598 int ang = MMpull(m);
6599 int mjoint = MMget(m, 0);
6600 if (mjoint == NIL)
6601 {
6602 MMset(m, 0, NIL);
6603 return 0;
6604 }
6605
6606 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6607 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_HINGE_CONTRAINT)
6608 {
6609 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetHingeMotorAngle bad joint type.\n");
6610 MMset(m, 0, NIL);
6611 return 0;
6612 }
6613
6614 Ogre::Radian angle(0.0f);
6615 if (ang != NIL)
6616 angle = MTOF(ang);
6617
6618 Ogre::Real minFriction = 0.0f;
6619 if (mifrict != NIL)
6620 minFriction = MTOF(mifrict);
6621
6622 Ogre::Real maxFriction = 0.0f;
6623 if (mafrict != NIL)
6624 maxFriction = MTOF(mafrict);
6625
6626 static_cast<SHingeContraint*>(joint)->SetMotorAngle(angle, minFriction, maxFriction);
6627
6628 MMset(m, 0, ITOM(1));
6629 return 0;
6630}
6631
6643{
6644#ifdef SO3_DEBUG
6645 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetHingeMotorOmega\n");
6646#endif
6647
6648 int stre = MMpull(m);
6649 int ang = MMpull(m);
6650 int mjoint = MMget(m, 0);
6651 if (mjoint == NIL)
6652 {
6653 MMset(m, 0, NIL);
6654 return 0;
6655 }
6656
6657 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6658 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_HINGE_CONTRAINT)
6659 {
6660 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetHingeMotorOmega bad joint type.\n");
6661 MMset(m, 0, NIL);
6662 return 0;
6663 }
6664
6665 Ogre::Radian angle(0.0f);
6666 if (ang != NIL)
6667 angle = MTOF(ang);
6668
6669 Ogre::Real strength = 0.5f;
6670 if (stre != NIL)
6671 strength = MTOF(stre);
6672
6673 if (strength > 1.0f)
6674 strength = 1.0f;
6675
6676 static_cast<SHingeContraint*>(joint)->SetMotorOmega(angle, strength);
6677
6678 MMset(m, 0, ITOM(1));
6679 return 0;
6680}
6681
6682
6693{
6694#ifdef SO3_DEBUG
6695 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetHingeTorque\n");
6696#endif
6697
6698 int torq = MMpull(m);
6699 int mjoint = MMget(m, 0);
6700 if (mjoint == NIL)
6701 {
6702 MMset(m, 0, NIL);
6703 return 0;
6704 }
6705
6706 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6707 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_HINGE_CONTRAINT)
6708 {
6709 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetHingeTorque bad joint type.\n");
6710 MMset(m, 0, NIL);
6711 return 0;
6712 }
6713
6714 Ogre::Real torque = 0.0f;
6715 if (torq != NIL)
6716 torque = MTOF(torq);
6717
6718 static_cast<SHingeContraint*>(joint)->SetTorque(torque);
6719
6720 MMset(m, 0, ITOM(1));
6721 return 0;
6722}
6723
6734{
6735#ifdef SO3_DEBUG
6736 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetHingeBrake\n");
6737#endif
6738
6739 int forc = MMpull(m);
6740 int mjoint = MMget(m, 0);
6741 if (mjoint == NIL)
6742 {
6743 MMset(m, 0, NIL);
6744 return 0;
6745 }
6746
6747 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6748 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_HINGE_CONTRAINT)
6749 {
6750 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetHingeBrake bad joint type.\n");
6751 MMset(m, 0, NIL);
6752 return 0;
6753 }
6754
6755 Ogre::Real force = -1.0f;
6756 if (forc != NIL)
6757 force = MTOF(forc);
6758
6759 static_cast<SHingeContraint*>(joint)->SetBrake(force);
6760
6761 MMset(m, 0, ITOM(1));
6762 return 0;
6763}
6764
6765
6776{
6777#ifdef SO3_DEBUG
6778 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetHingeMotorEnable\n");
6779#endif
6780
6781 int state = MMpull(m);
6782 int mjoint = MMget(m, 0);
6783 if (mjoint == NIL)
6784 {
6785 MMset(m, 0, NIL);
6786 return 0;
6787 }
6788
6789 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6790 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_HINGE_CONTRAINT)
6791 {
6792 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetHingeMotorEnable bad joint type.\n");
6793 MMset(m, 0, NIL);
6794 return 0;
6795 }
6796
6797 bool enable = false;
6798 if ((state != NIL) && (MTOI(state) == 1))
6799 enable = true;
6800
6801 static_cast<SHingeContraint*>(joint)->UseMotor(enable);
6802
6803 MMset(m, 0, ITOM(1));
6804 return 0;
6805}
6806
6807
6823{
6824#ifdef SO3_DEBUG
6825 MMechostr(MSKDEBUG, "SO3PhysicsContraintCreateSlider\n");
6826#endif
6827
6828 int spring = MMpull(m);
6829 int limits = MMpull(m);
6830 int dir = MTOP(MMpull(m));
6831 int vec = MTOP(MMpull(m));
6832 int parentbod = MMpull(m);
6833 int sonbod = MMpull(m);
6834 int s = MMget(m, 0);
6835 if (s == NIL || sonbod == NIL)
6836 {
6837 MMset(m, 0, NIL);
6838 return 0;
6839 }
6840
6841 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
6842 if (scene == NULL)
6843 {
6844 MMset(m, 0, NIL);
6845 return 0;
6846 }
6847
6848 SBody* sonBody = MMgetPointer<SBody*>(m, MTOP(sonbod));
6849 if (sonBody == NULL || sonBody->GetParentNode()->GetParentScene() != scene)
6850 {
6851 MMechostr(MSKRUNTIME, "SO3PhysicsContraintCreateSlider bad body to create joint or the body is not in the same scene.\n");
6852 MMset(m, 0, NIL);
6853 return 0;
6854 }
6855
6856 SBody* parentBody = 0;
6857 if (parentbod != NIL)
6858 parentBody = MMgetPointer<SBody*>(m, MTOP(parentbod));
6859
6860 if (parentBody != NULL && parentBody->GetParentNode()->GetParentScene() != scene)
6861 {
6862 MMechostr(MSKRUNTIME, "SO3PhysicsContraintCreateSlider bad body to create joint or the body is not in the same scene.\n");
6863 MMset(m, 0, NIL);
6864 return 0;
6865 }
6866
6867 Ogre::Vector3 position = Ogre::Vector3::ZERO;
6868 if (vec != NIL)
6869 {
6870 int x = MMfetch(m, vec, 0);
6871 int y = MMfetch(m, vec, 1);
6872 int z = MMfetch(m, vec, 2);
6873
6874 if ((x != NIL) && (y != NIL) && (z != NIL))
6875 position = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
6876 }
6877
6878 Ogre::Vector3 direction = Ogre::Vector3(0.0f, 1.0f, 0.0f);
6879 if (dir != NIL)
6880 {
6881 int x = MMfetch(m, dir, 0);
6882 int y = MMfetch(m, dir, 1);
6883 int z = MMfetch(m, dir, 2);
6884
6885 if ((x != NIL) && (y != NIL) && (z != NIL))
6886 direction = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
6887 }
6888 if (direction == Ogre::Vector3::ZERO)
6889 direction = Ogre::Vector3::UNIT_Y;
6890
6891 bool useLimits = false;
6892 if (limits != NIL && (MTOI(limits) == 1))
6893 useLimits = true;
6894
6895 bool useSpring = false;
6896 if (spring != NIL && (MTOI(spring) == 1))
6897 useSpring = true;
6898
6899 SPhysicContraint* joint = 0;
6900 if (scene->GetPhysicsWorld())
6901 {
6902 joint = static_cast<SPhysicContraint*> (new SSliderContraint(scene, sonBody, parentBody, position, direction, useLimits, useSpring));
6903 scene->GetPhysicsWorld()->AddPhysicContraint(joint);
6904 }
6905
6906 if (joint == NULL)
6907 {
6908 MMechostr(MSKDEBUG, "SO3PhysicsContraintCreateSlider : failed to create joint\n");
6909 MMset(m, 0, NIL);
6910 return 0;
6911 }
6912
6913 // remove last parameter
6914 MMpull(m);
6915 return createPhysicContraint(m, joint);
6916}
6917
6918
6928{
6929#ifdef SO3_DEBUG
6930 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetSliderVelocity\n");
6931#endif
6932
6933 int mjoint = MMget(m, 0);
6934 if (mjoint == NIL)
6935 {
6936 MMset(m, 0, NIL);
6937 return 0;
6938 }
6939
6940 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6941 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_SLIDER_CONTRAINT)
6942 {
6943 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetSliderVelocity bad joint type.\n");
6944 MMset(m, 0, NIL);
6945 return 0;
6946 }
6947
6948 Ogre::Real value = static_cast<SSliderContraint*>(joint)->GetVelocity();
6949 MMset(m, 0, FTOM(value));
6950
6951 return 0;
6952}
6953
6954
6964{
6965#ifdef SO3_DEBUG
6966 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetSliderForce\n");
6967#endif
6968
6969 int mjoint = MMget(m, 0);
6970 if (mjoint == NIL)
6971 {
6972 MMset(m, 0, NIL);
6973 return 0;
6974 }
6975
6976 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
6977 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_SLIDER_CONTRAINT)
6978 {
6979 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetSliderForce bad joint type.\n");
6980 MMset(m, 0, NIL);
6981 return 0;
6982 }
6983
6984 Ogre::Vector3 vec = static_cast<SSliderContraint*>(joint)->GetForce();
6985 int tuple = MMmalloc(m, 3, TYPETAB);
6986 if (tuple == NIL)
6987 {
6988 MMset(m, 0, NIL);
6989 return MERRMEM;
6990 }
6991
6992 MMstore(m, tuple, 0, FTOM((vec.x)));
6993 MMstore(m, tuple, 1, FTOM((vec.y)));
6994 MMstore(m, tuple, 2, FTOM((vec.z)));
6995 MMset(m, 0, PTOM(tuple));
6996
6997 return 0;
6998}
6999
7000
7010{
7011#ifdef SO3_DEBUG
7012 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetSliderPosition\n");
7013#endif
7014
7015 int mjoint = MMget(m, 0);
7016 if (mjoint == NIL)
7017 {
7018 MMset(m, 0, NIL);
7019 return 0;
7020 }
7021
7022 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7023 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_SLIDER_CONTRAINT)
7024 {
7025 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetSliderPosition bad joint type.\n");
7026 MMset(m, 0, NIL);
7027 return 0;
7028 }
7029
7030 Ogre::Real pos = static_cast<SSliderContraint*>(joint)->GetDistance();
7031 MMset(m, 0, FTOM(pos));
7032
7033 return 0;
7034}
7035
7036
7048{
7049#ifdef SO3_DEBUG
7050 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetSliderLimits\n");
7051#endif
7052
7053 int madist = MMpull(m);
7054 int midist = MMpull(m);
7055 int mjoint = MMget(m, 0);
7056 if (mjoint == NIL)
7057 {
7058 MMset(m, 0, NIL);
7059 return 0;
7060 }
7061
7062 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7063 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_SLIDER_CONTRAINT)
7064 {
7065 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetSliderLimits bad joint type.\n");
7066 MMset(m, 0, NIL);
7067 return 0;
7068 }
7069
7070 Ogre::Real mindist(0.0f);
7071 if (midist != NIL)
7072 mindist = MTOF(midist);
7073
7074 Ogre::Real maxdist(0.0f);
7075 if (madist != NIL)
7076 maxdist = MTOF(madist);
7077
7078 static_cast<SSliderContraint*>(joint)->SetLimits(mindist, maxdist);
7079
7080 MMset(m, 0, ITOM(1));
7081 return 0;
7082}
7083
7084
7096{
7097#ifdef SO3_DEBUG
7098 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetSliderSpring\n");
7099#endif
7100
7101 int spdamp = MMpull(m);
7102 int spstrength = MMpull(m);
7103 int mjoint = MMget(m, 0);
7104 if (mjoint == NIL)
7105 {
7106 MMset(m, 0, NIL);
7107 return 0;
7108 }
7109
7110 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7111 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_SLIDER_CONTRAINT)
7112 {
7113 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetSliderSpring bad joint type.\n");
7114 MMset(m, 0, NIL);
7115 return 0;
7116 }
7117
7118 Ogre::Real springStrength(0.0f);
7119 if (spstrength != NIL)
7120 springStrength = MTOF(spstrength);
7121
7122 Ogre::Real springDamping(0.0f);
7123 if (spdamp != NIL)
7124 springDamping = MTOF(spdamp);
7125
7126 static_cast<SSliderContraint*>(joint)->SetSpring(springStrength, springDamping);
7127
7128 MMset(m, 0, ITOM(1));
7129 return 0;
7130}
7131
7132
7143{
7144#ifdef SO3_DEBUG
7145 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetSliderFriction\n");
7146#endif
7147
7148 int sfriction = MMpull(m);
7149 int mjoint = MMget(m, 0);
7150 if (mjoint == NIL)
7151 {
7152 MMset(m, 0, NIL);
7153 return 0;
7154 }
7155
7156 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7157 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_SLIDER_CONTRAINT)
7158 {
7159 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetSliderFriction bad joint type.\n");
7160 MMset(m, 0, NIL);
7161 return 0;
7162 }
7163
7164 Ogre::Real friction(0.0f);
7165 if (sfriction != NIL)
7166 friction = MTOF(sfriction);
7167
7168 static_cast<SSliderContraint*>(joint)->SetFriction(friction);
7169
7170 MMset(m, 0, ITOM(1));
7171 return 0;
7172}
7173
7184{
7185#ifdef SO3_DEBUG
7186 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetSliderMotorEnable\n");
7187#endif
7188
7189 int state = MMpull(m);
7190 int mjoint = MMget(m, 0);
7191 if (mjoint == NIL)
7192 {
7193 MMset(m, 0, NIL);
7194 return 0;
7195 }
7196
7197 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7198 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_SLIDER_CONTRAINT)
7199 {
7200 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetSliderMotorEnable bad joint type.\n");
7201 MMset(m, 0, NIL);
7202 return 0;
7203 }
7204
7205 bool enable = false;
7206 if ((state != NIL) && (MTOI(state) == 1))
7207 enable = true;
7208
7209 static_cast<SSliderContraint*>(joint)->UseMotor(enable);
7210
7211 MMset(m, 0, ITOM(1));
7212 return 0;
7213}
7214
7226{
7227#ifdef SO3_DEBUG
7228 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetSliderMotorVelocity\n");
7229#endif
7230
7231 int stre = MMpull(m);
7232 int velo = MMpull(m);
7233 int mjoint = MMget(m, 0);
7234 if (mjoint == NIL)
7235 {
7236 MMset(m, 0, NIL);
7237 return 0;
7238 }
7239
7240 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7241 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_SLIDER_CONTRAINT)
7242 {
7243 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetSliderMotorVelocity bad joint type.\n");
7244 MMset(m, 0, NIL);
7245 return 0;
7246 }
7247
7248 Ogre::Real velocity(0.0f);
7249 if (velo != NIL)
7250 velocity = MTOF(velo);
7251
7252 Ogre::Real strength = 0.5f;
7253 if (stre != NIL)
7254 strength = MTOF(stre);
7255
7256 if (strength > 1.0f)
7257 strength = 1.0f;
7258
7259 static_cast<SSliderContraint*>(joint)->SetMotorVelocity(velocity, strength);
7260
7261 MMset(m, 0, ITOM(1));
7262 return 0;
7263}
7264
7265
7276{
7277#ifdef SO3_DEBUG
7278 MMechostr(MSKDEBUG, "SO3PhysicsContraintCreateVehicle\n");
7279#endif
7280
7281 int sonbod = MMpull(m);
7282 int s = MMget(m, 0);
7283 if (s == NIL || sonbod == NIL)
7284 {
7285 MMset(m, 0, NIL);
7286 return 0;
7287 }
7288
7289 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
7290 if (scene == NULL)
7291 {
7292 MMset(m, 0, NIL);
7293 return 0;
7294 }
7295
7296 SBody* sonBody = MMgetPointer<SBody*>(m, MTOP(sonbod));
7297 if (sonBody == NULL || sonBody->GetParentNode()->GetParentScene() != scene)
7298 {
7299 MMechostr(MSKRUNTIME, "SO3PhysicsContraintCreateVehicle bad body to create joint or the body is not in the same scene.\n");
7300 MMset(m, 0, NIL);
7301 return 0;
7302 }
7303
7304 SPhysicContraint* joint = 0;
7305 if (scene->GetPhysicsWorld())
7306 {
7307 joint = static_cast<SPhysicContraint*>(new SVehicleContraint(scene, sonBody));
7308 scene->GetPhysicsWorld()->AddPhysicContraint(joint);
7309 }
7310
7311 if (joint == NULL)
7312 {
7313 MMechostr(MSKDEBUG, "SO3PhysicsContraintCreateVehicle : failed to create joint\n");
7314 MMset(m, 0, NIL);
7315 return 0;
7316 }
7317
7318 // remove last parameter
7319 MMpull(m);
7320 return createPhysicContraint(m, joint);
7321}
7322
7323
7343{
7344#ifdef SO3_DEBUG
7345 MMechostr(MSKDEBUG, "SO3PhysicsContraintAddVehicleTire\n");
7346#endif
7347
7348 int idriving = MMpull(m);
7349 int isteer = MMpull(m);
7350 int isusshock = MMpull(m);
7351 int isusspring = MMpull(m);
7352 int isuslength = MMpull(m);
7353 int ifriction = MMpull(m);
7354 int iwidth = MMpull(m);
7355 int iradius = MMpull(m);
7356 int imass = MMpull(m);
7357 int inode = MMpull(m);
7358 int mjoint = MMget(m, 0);
7359 if ((mjoint == NIL) || (inode == NIL))
7360 {
7361 MMset(m, 0, NIL);
7362 return 0;
7363 }
7364
7365 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7366 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_VEHICLE_CONTRAINT)
7367 {
7368 MMechostr(MSKRUNTIME, "SO3PhysicsContraintAddVehicleTire bad joint type.\n");
7369 MMset(m, 0, NIL);
7370 return 0;
7371 }
7372
7373 SNode* node = MMgetPointer<SNode*>(m, MTOP(inode));
7374 if (node == NULL)
7375 {
7376 MMset(m, 0, NIL);
7377 return 0;
7378 }
7379
7380 Ogre::Real mass(1.0f);
7381 if (imass != NIL)
7382 mass = MTOF(imass);
7383
7384 Ogre::Real radius(0.0f);
7385 if (iradius != NIL)
7386 radius = MTOF(iradius);
7387
7388 Ogre::Real width(0.1f);
7389 if (iwidth != NIL)
7390 width = MTOF(iwidth);
7391
7392 Ogre::Real friction(1.0f);
7393 if (ifriction != NIL)
7394 friction = MTOF(ifriction);
7395
7396 Ogre::Real suslength(0.0f);
7397 if (isuslength != NIL)
7398 suslength = MTOF(isuslength);
7399
7400 Ogre::Real susspring(0.0f);
7401 if (isusspring != NIL)
7402 susspring = MTOF(isusspring);
7403
7404 Ogre::Real susshock(0.0f);
7405 if (isusshock != NIL)
7406 susshock = MTOF(isusshock);
7407
7408 bool bsteer = false;
7409 if ((isteer != NIL) && (MTOI(isteer) == 1))
7410 bsteer = true;
7411
7412 bool bdriving = false;
7413 if ((idriving != NIL) && (MTOI(idriving) == 1))
7414 bdriving = true;
7415
7416 static_cast<SVehicleContraint*>(joint)->AddTire(node, mass, radius, width, friction, suslength, susspring, susshock, bsteer, bdriving);
7417
7418 MMset(m, 0, ITOM(1));
7419 return 0;
7420}
7421
7422
7432{
7433#ifdef SO3_DEBUG
7434 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetVehicleSpeed\n");
7435#endif
7436
7437 int mjoint = MMget(m, 0);
7438 if (mjoint == NIL)
7439 {
7440 MMset(m, 0, NIL);
7441 return 0;
7442 }
7443
7444 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7445 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_VEHICLE_CONTRAINT)
7446 {
7447 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetVehicleSpeed bad joint type.\n");
7448 MMset(m, 0, NIL);
7449 return 0;
7450 }
7451
7452 Ogre::Real speed = static_cast<SVehicleContraint*>(joint)->GetSpeed();
7453 MMset(m, 0, FTOM(speed));
7454
7455 return 0;
7456}
7457
7458
7469{
7470#ifdef SO3_DEBUG
7471 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetVehicleSteerAngle\n");
7472#endif
7473
7474 int iangle = MMpull(m);
7475 int mjoint = MMget(m, 0);
7476 if (mjoint == NIL)
7477 {
7478 MMset(m, 0, NIL);
7479 return 0;
7480 }
7481
7482 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7483 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_VEHICLE_CONTRAINT)
7484 {
7485 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetVehicleSteerAngle bad joint type.\n");
7486 MMset(m, 0, NIL);
7487 return 0;
7488 }
7489
7490 Ogre::Radian angle(0.0f);
7491 if (iangle != NIL)
7492 angle = Ogre::Radian(MTOF(iangle));
7493
7494 static_cast<SVehicleContraint*>(joint)->SetSteerAngle(angle);
7495
7496 MMset(m, 0, ITOM(1));
7497 return 0;
7498}
7499
7500
7511{
7512#ifdef SO3_DEBUG
7513 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetVehicleDrivingTorque\n");
7514#endif
7515
7516 int itorque = MMpull(m);
7517 int mjoint = MMget(m, 0);
7518 if (mjoint == NIL)
7519 {
7520 MMset(m, 0, NIL);
7521 return 0;
7522 }
7523
7524 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7525 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_VEHICLE_CONTRAINT)
7526 {
7527 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetVehicleDrivingTorque bad joint type.\n");
7528 MMset(m, 0, NIL);
7529 return 0;
7530 }
7531
7532 Ogre::Radian torque(0.0f);
7533 if (itorque != NIL)
7534 torque = Ogre::Radian(MTOF(itorque));
7535
7536 static_cast<SVehicleContraint*>(joint)->SetDrivingTorque(torque);
7537
7538 MMset(m, 0, ITOM(1));
7539 return 0;
7540}
7541
7542
7553{
7554#ifdef SO3_DEBUG
7555 MMechostr(MSKDEBUG, "SO3PhysicsContraintSetVehicleBrake\n");
7556#endif
7557
7558 int ibrake = MMpull(m);
7559 int mjoint = MMget(m, 0);
7560 if (mjoint == NIL)
7561 {
7562 MMset(m, 0, NIL);
7563 return 0;
7564 }
7565
7566 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7567 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_VEHICLE_CONTRAINT)
7568 {
7569 MMechostr(MSKRUNTIME, "SO3PhysicsContraintSetVehicleBrake bad joint type.\n");
7570 MMset(m, 0, NIL);
7571 return 0;
7572 }
7573
7574 Ogre::Real brake(0.0f);
7575 if (ibrake != NIL)
7576 brake = MTOF(ibrake);
7577
7578 static_cast<SVehicleContraint*>(joint)->SetBrake(brake);
7579
7580 MMset(m, 0, ITOM(1));
7581 return 0;
7582}
7583
7584
7594{
7595#ifdef SO3_DEBUG
7596 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetVehicleOnAir\n");
7597#endif
7598
7599 int mjoint = MMget(m, 0);
7600 if (mjoint == NIL)
7601 {
7602 MMset(m, 0, NIL);
7603 return 0;
7604 }
7605
7606 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7607 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_VEHICLE_CONTRAINT)
7608 {
7609 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetVehicleOnAir bad joint type.\n");
7610 MMset(m, 0, NIL);
7611 return 0;
7612 }
7613
7614 MMset(m, 0, ITOM(static_cast<SVehicleContraint*>(joint)->GetVehicleOnAir() ? 1 : 0));
7615 return 0;
7616}
7617
7618
7629{
7630#ifdef SO3_DEBUG
7631 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetVehicleTireAngularVelocity\n");
7632#endif
7633
7634 int inode = MMpull(m);
7635 int mjoint = MMget(m, 0);
7636 if ((mjoint == NIL) || (inode == NIL))
7637 {
7638 MMset(m, 0, NIL);
7639 return 0;
7640 }
7641
7642 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7643 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_VEHICLE_CONTRAINT)
7644 {
7645 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetVehicleTireAngularVelocity bad joint type.\n");
7646 MMset(m, 0, NIL);
7647 return 0;
7648 }
7649
7650 SNode* node = MMgetPointer<SNode*>(m, MTOP(inode));
7651 if (node == NULL)
7652 {
7653 MMset(m, 0, NIL);
7654 return 0;
7655 }
7656
7657 MMset(m, 0, FTOM(static_cast<SVehicleContraint*>(joint)->GetTireAngularVelocity(node)));
7658 return 0;
7659}
7660
7661
7672{
7673#ifdef SO3_DEBUG
7674 MMechostr(MSKDEBUG, "SO3PhysicsContraintGetVehicleTireOnAir\n");
7675#endif
7676
7677 int inode = MMpull(m);
7678 int mjoint = MMget(m, 0);
7679 if ((mjoint == NIL) || (inode == NIL))
7680 {
7681 MMset(m, 0, NIL);
7682 return 0;
7683 }
7684
7685 SPhysicContraint* joint = MMgetPointer<SPhysicContraint*>(m, MTOP(mjoint));
7686 if (joint == NULL || joint->GetType() != SPhysicContraint::SO3_VEHICLE_CONTRAINT)
7687 {
7688 MMechostr(MSKRUNTIME, "SO3PhysicsContraintGetVehicleTireOnAir bad joint type.\n");
7689 MMset(m, 0, NIL);
7690 return 0;
7691 }
7692
7693 SNode* node = MMgetPointer<SNode*>(m, MTOP(inode));
7694 if (node == NULL)
7695 {
7696 MMset(m, 0, NIL);
7697 return 0;
7698 }
7699
7700 int state = (static_cast<SVehicleContraint*>(joint)->GetTireOnAir(node)) ? 1 : 0;
7701 MMset(m, 0, ITOM(state));
7702 return 0;
7703}
7704
7705
7714SMaterialPair* getMaterialPairByWorld(SPhysicWorld* world, int ID1, int ID2)
7715{
7716 SMaterialPairMap::iterator iMaterialPairList = world->listOfPhysicsMaterialPair.begin();
7717 while (iMaterialPairList != world->listOfPhysicsMaterialPair.end())
7718 {
7719 if (((*iMaterialPairList)->getID1() == ID1 && (*iMaterialPairList)->getID2() == ID2) || ((*iMaterialPairList)->getID2() == ID1 && (*iMaterialPairList)->getID1() == ID2))
7720 return (*iMaterialPairList);
7721
7722 iMaterialPairList++;
7723 }
7724
7725 return NULL;
7726}
7727
7728
7738int SO3BodySetMaterial(mmachine m)
7739{
7740#ifdef SO3_DEBUG
7741 MMechostr(MSKDEBUG, "SO3BodySetMaterial\n");
7742#endif
7743
7744 int mat = MMpull(m);
7745 int bod = MMget(m, 0);
7746 if ((bod == NIL) || (mat == NIL))
7747 {
7748 MMset(m, 0, NIL);
7749 return 0;
7750 }
7751
7752 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
7753 if (body == NULL)
7754 {
7755 MMset(m, 0, NIL);
7756 return 0;
7757 }
7758
7759 SMaterialID* matID = MMgetPointer<SMaterialID*>(m, MTOP(mat));
7760 if (matID == NULL)
7761 {
7762 MMset(m, 0, NIL);
7763 return 0;
7764 }
7765
7766 body->SetMaterialID(matID);
7767 MMset(m, 0, ITOM(1));
7768
7769#ifdef SO3_DEBUG
7770 MMechostr(MSKDEBUG, "SO3BodySetMaterial: OK!\n");
7771#endif
7772 return 0;
7773}
7774
7775
7784int SO3BodyGetMaterial(mmachine m)
7785{
7786#ifdef SO3_DEBUG
7787 MMechostr(MSKDEBUG, "SO3BodyGetMaterial\n");
7788#endif
7789
7790 int bod = MMget(m, 0);
7791 if (bod == NIL)
7792 {
7793 MMechostr(MSKDEBUG, "SO3BodyGetMaterial: one of the parameters is NIL!!\n");
7794 MMset(m, 0, NIL);
7795 return 0;
7796 }
7797
7798 SBody* body = MMgetPointer<SBody*>(m, MTOP(bod));
7799 if (body == NULL)
7800 {
7801 MMset(m, 0, NIL);
7802 return 0;
7803 }
7804
7805 const SMaterialID* matID = body->GetMaterial();
7806 if (matID == NULL)
7807 {
7808 MMset(m, 0, NIL);
7809 return 0;
7810 }
7811
7812 int mat = OBJfindTH(m, SO3PHYSICSMATERIALTYPE, SCOL_PTR(matID));
7813 if (mat != NIL)
7814 mat = MMfetch(m, mat, OFFOBJMAG);
7815
7816 MMset(m, 0, mat);
7817 return 0;
7818}
7819
7820
7830//TODO test mat1 and mat2 name with "" and trim
7832{
7833#ifdef SO3_DEBUG
7834 MMechostr(MSKDEBUG, "SO3PhysicsMaterialCreate\n");
7835#endif
7836
7837 int nam = MMpull(m);
7838 int s = MMget(m, 0);
7839 if ((s == NIL) || (nam == NIL))
7840 {
7841 MMset(m, 0, NIL);
7842 return 0;
7843 }
7844
7845 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
7846 if (scene == NULL)
7847 {
7848 MMset(m, 0, NIL);
7849 return 0;
7850 }
7851
7852 if (!scene->GetPhysicsWorld())
7853 {
7854 MMset(m, 0, NIL);
7855 return 0;
7856 }
7857
7858 string name = MMstartstr(m, MTOP(nam));
7859 if (name.empty())
7860 {
7861 MMset(m, 0, NIL);
7862 return 0;
7863 }
7864
7865 //Check if materialID already Exist
7866 SMaterialID* matID;
7867 if (MaterialIDExists(scene, name, &matID))
7868 {
7869 int a = OBJfindTH(m, SO3PHYSICSMATERIALTYPE, SCOL_PTR(matID));
7870 if (a != NIL)
7871 a = MMfetch(m, a, OFFOBJMAG);
7872
7873 MMset(m, 0, a);
7874 return 0;
7875 }
7876
7877 //remove last param
7878 MMpull(m);
7879
7880 // Create Material ID
7881 matID = scene->GetPhysicsWorld()->CreatePhysicMaterialID(name);
7882
7883 // Creating Materials Pair With each Other Material ID in the Scene
7884 SMaterialIDMap::iterator iMaterialIDList = scene->GetPhysicsWorld()->listOfMaterialID.begin();
7885 while (iMaterialIDList != scene->GetPhysicsWorld()->listOfMaterialID.end())
7886 {
7887 SMaterialPair* matPair = scene->GetPhysicsWorld()->CreatePhysicMaterialPair(matID, iMaterialIDList->second);
7888 createMaterialPair(m, matPair, scene);
7889
7890 //restore the stak state
7891 MMpull(m);
7892
7893 iMaterialIDList++;
7894 }
7895
7896#ifdef SO3_DEBUG
7897 MMechostr(MSKDEBUG, "SO3PhysicsMaterialCreate : OK!\n");
7898#endif
7899 return createMaterialID(m, matID, scene);
7900}
7901
7902
7912{
7913#ifdef SO3_DEBUG
7914 MMechostr(MSKDEBUG, "SO3PhysicsMaterialDestroy\n");
7915#endif
7916
7917 int mat = MMget(m, 0);
7918 if (mat == NIL)
7919 {
7920 MMset(m, 0, 0);
7921 return 0;
7922 }
7923
7924 // Destruction of the scol Object
7925 OBJdelTM(m, SO3PHYSICSMATERIALTYPE, mat);
7926
7927 MMset(m, 0, ITOM(1));
7928#ifdef SO3_DEBUG
7929 MMechostr(MSKDEBUG, "SO3PhysicsMaterialDestroy : OK!\n");
7930#endif
7931 return 0;
7932}
7933
7934
7945{
7946#ifdef SO3_DEBUG
7947 MMechostr(MSKDEBUG, "SO3PhysicsGetMaterial\n");
7948#endif
7949
7950 int name = MMpull(m);
7951 int s = MMget(m, 0);
7952 if ((s == NIL) || (name == NIL))
7953 {
7954 MMechostr(MSKDEBUG, "SO3PhysicsGetMaterial: one of the parameters is NIL!!\n");
7955 MMset(m, 0, NIL);
7956 return 0;
7957 }
7958
7959 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
7960 if (scene == NULL)
7961 {
7962 MMset(m, 0, NIL);
7963 return 0;
7964 }
7965
7966 if (!scene->GetPhysicsWorld())
7967 {
7968 MMset(m, 0, NIL);
7969 return 0;
7970 }
7971
7972 string matname = MMstartstr(m, MTOP(name));
7973#ifdef SO3_DEBUG
7974 MMechostr(MSKDEBUG, "Material Name : %s \n", matname.c_str());
7975#endif
7976
7977 if (matname.empty())
7978 {
7979 MMset(m, 0, NIL);
7980 return 0;
7981 }
7982
7983 SMaterialID* matID = NULL;
7984 SMaterialIDMap::iterator iMaterialIDSearched = scene->GetPhysicsWorld()->listOfMaterialID.find(matname);
7985 if (iMaterialIDSearched != scene->GetPhysicsWorld()->listOfMaterialID.end())
7986 matID = iMaterialIDSearched->second;
7987
7988 if (matID == NULL)
7989 {
7990 MMechostr(MSKDEBUG, "Physic material not found %s\n", matname.c_str());
7991 MMset(m, 0, NIL);
7992 return 0;
7993 }
7994
7995 int mat = OBJfindTH(m, SO3PHYSICSMATERIALTYPE, SCOL_PTR(matID));
7996 if (mat != NIL)
7997 mat = MMfetch(m, mat, OFFOBJMAG);
7998
7999 MMset(m, 0, mat);
8000 return 0;
8001}
8002
8003
8013{
8014#ifdef SO3_DEBUG
8015 MMechostr(MSKDEBUG, "SO3PhysicsGetMaterialName\n");
8016#endif
8017
8018 int mat = MMget(m, 0);
8019 if (mat == NIL)
8020 {
8021 MMechostr(MSKDEBUG, "SO3PhysicsGetMaterialName: one of the parameters is NIL!!\n");
8022 MMset(m, 0, NIL);
8023 return 0;
8024 }
8025
8026 SMaterialID* matID = MMgetPointer<SMaterialID*>(m, MTOP(mat));
8027 if (matID == NULL)
8028 {
8029 MMset(m, 0, NIL);
8030 return 0;
8031 }
8032
8033 MMpull(m);
8034 Mpushstrbloc(m, (char*)matID->GetName().c_str());
8035 return 0;
8036}
8037
8049{
8050#ifdef SO3_DEBUG
8051 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetSurfaceThickness\n");
8052#endif
8053
8054 int val = MMpull(m);
8055 int mat2 = MMpull(m);
8056 int mat1 = MMget(m, 0);
8057 if ((mat1 == NIL) || (mat2 == NIL) || (val == NIL))
8058 {
8059 MMset(m, 0, NIL);
8060 return 0;
8061 }
8062
8063 SMaterialID* matID1 = MMgetPointer<SMaterialID*>(m, MTOP(mat1));
8064 if (matID1 == NULL)
8065 {
8066 MMset(m, 0, NIL);
8067 return 0;
8068 }
8069
8070 SMaterialID* matID2 = MMgetPointer<SMaterialID*>(m, MTOP(mat2));
8071 if (matID2 == NULL)
8072 {
8073 MMset(m, 0, NIL);
8074 return 0;
8075 }
8076
8077 // Getting Material Pair Associated in the Scene
8078 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
8079 if (matPair == NULL)
8080 {
8081 MMset(m, 0, NIL);
8082 return 0;
8083 }
8084
8085 matPair->SetDefaultSurfaceThickness((Ogre::Real)(MTOF(val)));
8086 MMset(m, 0, ITOM(1));
8087#ifdef SO3_DEBUG
8088 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetSurfaceThickness : OK!\n");
8089#endif
8090 return 0;
8091}
8092
8093
8105{
8106#ifdef SO3_DEBUG
8107 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetDefaultElasticity\n");
8108#endif
8109
8110 int val = MMpull(m);
8111 int mat2 = MMpull(m);
8112 int mat1 = MMget(m, 0);
8113 if ((mat1 == NIL) || (mat2 == NIL) || (val == NIL))
8114 {
8115 MMechostr(MSKDEBUG, "One of Paramter is NIL!!\n");
8116 MMset(m, 0, NIL);
8117 return 0;
8118 }
8119
8120 SMaterialID* matID1 = MMgetPointer<SMaterialID*>(m, MTOP(mat1));
8121 if (matID1 == NULL)
8122 {
8123 MMechostr(MSKDEBUG, "MatID1 is NULL!!\n");
8124 MMset(m, 0, NIL);
8125 return 0;
8126 }
8127
8128 SMaterialID* matID2 = MMgetPointer<SMaterialID*>(m, MTOP(mat2));
8129 if (matID2 == NULL)
8130 {
8131 MMechostr(MSKDEBUG, "MatID1 is NULL!!\n");
8132 MMset(m, 0, NIL);
8133 return 0;
8134 }
8135
8136 // Getting Material Pair Associated in the Scene
8137 SMaterialPair* matPair;
8138 matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
8139 if (matPair == NULL)
8140 {
8141 MMechostr(MSKDEBUG, "MAtPair is NULL!!\n");
8142 MMset(m, 0, NIL);
8143 return 0;
8144 }
8145 matPair->SetDefaultElasticity((Ogre::Real)(MTOF(val)));
8146
8147 MMset(m, 0, ITOM(1));
8148#ifdef SO3_DEBUG
8149 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetDefaultElasticity : OK!\n");
8150#endif
8151 return 0;
8152}
8153
8154
8167{
8168#ifdef SO3_DEBUG
8169 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetDefaultFriction\n");
8170#endif
8171
8172 int val2 = MMpull(m);
8173 int val1 = MMpull(m);
8174 int mat2 = MMpull(m);
8175 int mat1 = MMget(m, 0);
8176 if ((mat1 == NIL) || (mat2 == NIL) || (val1 == NIL) || (val2 == NIL))
8177 {
8178 MMset(m, 0, NIL);
8179 return 0;
8180 }
8181
8182 SMaterialID* matID1 = MMgetPointer<SMaterialID*>(m, MTOP(mat1));
8183 if (matID1 == NULL)
8184 {
8185 MMset(m, 0, NIL);
8186 return 0;
8187 }
8188
8189 SMaterialID* matID2 = MMgetPointer<SMaterialID*>(m, MTOP(mat2));
8190 if (matID2 == NULL)
8191 {
8192 MMset(m, 0, NIL);
8193 return 0;
8194 }
8195
8196 // Getting Material Pair Associated in the Scene
8197 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
8198 if (matPair == NULL)
8199 {
8200 MMset(m, 0, NIL);
8201 return 0;
8202 }
8203 matPair->SetDefaultFriction((Ogre::Real)(MTOF(val1)), (Ogre::Real)(MTOF(val2)));
8204
8205 MMset(m, 0, ITOM(1));
8206 return 0;
8207}
8208
8209
8221{
8222#ifdef SO3_DEBUG
8223 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetDefaultSoftness\n");
8224#endif
8225
8226 int val = MMpull(m);
8227 int mat2 = MMpull(m);
8228 int mat1 = MMget(m, 0);
8229 if ((mat1 == NIL) || (mat2 == NIL) || (val == NIL))
8230 {
8231 MMechostr(MSKDEBUG, "One of Paramter is NIL!!\n");
8232 MMset(m, 0, NIL);
8233 return 0;
8234 }
8235
8236 SMaterialID* matID1 = MMgetPointer<SMaterialID*>(m, MTOP(mat1));
8237 if (matID1 == NULL)
8238 {
8239 MMset(m, 0, NIL);
8240 return 0;
8241 }
8242
8243 SMaterialID* matID2 = MMgetPointer<SMaterialID*>(m, MTOP(mat2));
8244 if (matID2 == NULL)
8245 {
8246 MMset(m, 0, NIL);
8247 return 0;
8248 }
8249
8250 // Getting Material Pair Associated in the Scene
8251 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
8252 if (matPair == NULL)
8253 {
8254 MMset(m, 0, NIL);
8255 return 0;
8256 }
8257 matPair->SetDefaultSoftness((Ogre::Real)(MTOF(val)));
8258
8259 MMset(m, 0, ITOM(1));
8260 return 0;
8261}
8262
8263
8275{
8276#ifdef SO3_DEBUG
8277 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetDefaultCollidable\n");
8278#endif
8279
8280 int val = MMpull(m);
8281 int mat2 = MMpull(m);
8282 int mat1 = MMget(m, 0);
8283 if ((mat1 == NIL) || (mat2 == NIL) || (val == NIL))
8284 {
8285 MMechostr(MSKDEBUG, "One of Paramter is NIL!!\n");
8286 MMset(m, 0, NIL);
8287 return 0;
8288 }
8289
8290 SMaterialID* matID1 = MMgetPointer<SMaterialID*>(m, MTOP(mat1));
8291 if (matID1 == NULL)
8292 {
8293 MMset(m, 0, NIL);
8294 return 0;
8295 }
8296
8297 SMaterialID* matID2 = MMgetPointer<SMaterialID*>(m, MTOP(mat2));
8298 if (matID2 == NULL)
8299 {
8300 MMset(m, 0, NIL);
8301 return 0;
8302 }
8303
8304 // Getting Material Pair Associated in the Scene
8305 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
8306 if (matPair == NULL)
8307 {
8308 MMset(m, 0, NIL);
8309 return 0;
8310 }
8311
8312 bool coll = false;
8313 if (MTOI(val) == 1)
8314 coll = true;
8315
8316 matPair->SetDefaultCollidable(coll);
8317
8318 MMset(m, 0, ITOM(1));
8319 return 0;
8320}
8321
8322
8335{
8336#ifdef SO3_DEBUG
8337 MMechostr(MSKDEBUG, "SO3PhysicsMaterialSetContiniousCollisionMode\n");
8338#endif
8339 int val = MMpull(m);
8340 int mat2 = MMpull(m);
8341 int mat1 = MMget(m, 0);
8342
8343 MMset(m, 0, NIL);
8344 return 0;
8345}
8346
8359{
8360#ifdef SO3_DEBUG
8361 MMechostr(MSKDEBUG, "SO3WorldApplyImpulsePoint\n");
8362#endif
8363
8364 int istrength = MMpull(m);
8365 int iradius = MMpull(m);
8366 int vec = MTOP(MMpull(m));
8367 int s = MMget(m, 0);
8368 if ((s == NIL) || (vec == NIL))
8369 {
8370 MMset(m, 0, NIL);
8371 return 0;
8372 }
8373
8374 SScene* scene = MMgetPointer<SScene*>(m, MTOP(s));
8375 if (scene == NULL)
8376 {
8377 MMset(m, 0, NIL);
8378 return 0;
8379 }
8380
8381 int x = MMfetch(m, vec, 0);
8382 int y = MMfetch(m, vec, 1);
8383 int z = MMfetch(m, vec, 2);
8384
8385 if ((x == NIL) || (y == NIL) || (z == NIL))
8386 {
8387 MMset(m, 0, NIL);
8388 return 0;
8389 }
8390
8391 if (!scene->GetPhysicsWorld())
8392 {
8393 MMset(m, 0, NIL);
8394 return 0;
8395 }
8396
8397 Ogre::Vector3 position = Ogre::Vector3(MTOF(x), MTOF(y), MTOF(z));
8398 Ogre::Real radius = 1.0f;
8399 if (iradius != NIL)
8400 radius = MTOF(iradius);
8401
8402 Ogre::Real strength = 1.0f;
8403 if (istrength != NIL)
8404 strength = MTOF(istrength);
8405
8406 scene->GetPhysicsWorld()->ApplyImpulsePoint(position, radius, strength);
8407 MMset(m, 0, ITOM(1));
8408 return 0;
8409}
8410
8430{
8431#if SO3_DEBUG == 1
8432 MMechostr(MSKDEBUG, "SO3CbMaterialCollision\n");
8433#endif
8434 int k;
8435
8436 int pUser = MMpull(m);
8437 int pCbk = MMpull(m);
8438 int mat2 = MMpull(m);
8439 int mat1 = MMpull(m);
8440
8441 // check mat1
8442 if (mat1 == NIL)
8443 {
8444 MMechostr(0, "SO3CbMaterialCollision error : mat1 is nil...\n");
8445 MMpush(m, NIL);
8446 return 0;
8447 }
8448
8449 // check mat2
8450 if (mat2 == NIL)
8451 {
8452 MMechostr(0, "SO3CbMaterialCollision error : mat2 is nil...\n");
8453 MMpush(m, NIL);
8454 return 0;
8455 }
8456
8457 SMaterialID* matID1 = MMgetPointer<SMaterialID*>(m, MTOP(mat1));
8458 if (matID1 == NULL)
8459 {
8460 MMpush(m, NIL);
8461 return 0;
8462 }
8463
8464 SMaterialID* matID2 = MMgetPointer<SMaterialID*>(m, MTOP(mat2));
8465 if (matID2 == NULL)
8466 {
8467 MMpush(m, NIL);
8468 return 0;
8469 }
8470
8471 // Getting MaterialPair associated
8472 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
8473 if (matPair == NULL)
8474 {
8475 MMpush(m, NIL);
8476 return 0;
8477 }
8478
8479 if (pCbk == NIL)
8480 {
8481 matPair->SetContactCallbackActivated(false);
8482 }
8483 else
8484 {
8485 matPair->SetContactCallbackActivated(true);
8486 }
8487
8488 int ob = MMfetch(m, OBJfindTH(m, SO3PHYSICSMATERIALPAIR, SCOL_PTR(matPair)), OFFOBJMAG);
8489 if (ob == NIL)
8490 {
8491 matPair->SetContactCallbackActivated(false);
8492 MMpush(m, NIL);
8493 return 0;
8494 }
8495
8496 /*
8497 2 : object
8498 1 : cbfun
8499 0 : argument u0
8500 */
8501 MMpush(m, ob);
8502 MMpush(m, pCbk);
8503 MMpush(m, pUser);
8504
8505 k = OBJaddreflex(m, SO3PHYSICSMATERIALPAIR, SO3_MATERIALPAIR_COLLISION);
8506
8507 MMset(m, 0, ITOM(1));
8508
8509#if SO3_DEBUG == 1
8510 MMechostr(MSKDEBUG, "SO3CbMaterialCollision : OK!\n");
8511#endif
8512 return 0;
8513}
8514
8515
8531{
8532#ifdef SO3_DEBUG
8533 MMechostr(MSKDEBUG, "SO3CbMaterialOverlapStarted\n");
8534#endif
8535
8536 int k;
8537 int pUser = MMpull(m);
8538 int pCbk = MMpull(m);
8539 int mat2 = MMpull(m);
8540 int mat1 = MMpull(m);
8541
8542 // check mat1
8543 if (mat1 == NIL)
8544 {
8545 MMechostr(0, "SO3CbMaterialOverlapStarted error : mat1 is nil...\n");
8546 MMpush(m, NIL);
8547 return 0;
8548 }
8549
8550 // check mat2
8551 if (mat2 == NIL)
8552 {
8553 MMechostr(0, "SO3CbMaterialOverlapStarted error : mat2 is nil...\n");
8554 MMpush(m, NIL);
8555 return 0;
8556 }
8557
8558 SMaterialID* matID1 = MMgetPointer<SMaterialID*>(m, MTOP(mat1));
8559 if (matID1 == NULL)
8560 {
8561 MMpush(m, NIL);
8562 return 0;
8563 }
8564
8565 SMaterialID* matID2 = MMgetPointer<SMaterialID*>(m, MTOP(mat2));
8566 if (matID2 == NULL)
8567 {
8568 MMpush(m, NIL);
8569 return 0;
8570 }
8571
8572 // Getting MaterialPair associated
8573 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
8574 if (matPair == NULL)
8575 {
8576 MMpush(m, NIL);
8577 return 0;
8578 }
8579
8580 if (pCbk == NIL)
8581 {
8582 matPair->SetOverlapStartedCallbackActivated(false);
8583 }
8584 else
8585 {
8586 matPair->SetOverlapStartedCallbackActivated(true);
8587 }
8588
8589 int ob = MMfetch(m, OBJfindTH(m, SO3PHYSICSMATERIALPAIR, SCOL_PTR(matPair)), OFFOBJMAG);
8590 if (ob == NIL)
8591 {
8592 matPair->SetOverlapStartedCallbackActivated(false);
8593 MMpush(m, NIL);
8594 return 0;
8595 }
8596
8597 /*
8598 2 : object
8599 1 : cbfun
8600 0 : argument u0
8601 */
8602 MMpush(m, ob);
8603 MMpush(m, pCbk);
8604 MMpush(m, pUser);
8605
8606 k = OBJaddreflex(m, SO3PHYSICSMATERIALPAIR, SO3_MATERIALPAIR_OVERLAP_STARTED);
8607
8608 MMset(m, 0, ITOM(1));
8609
8610#ifdef SO3_DEBUG
8611 MMechostr(MSKDEBUG, "SO3CbMaterialOverlapStarted : OK!\n");
8612#endif
8613 return 0;
8614}
8615
8616
8632{
8633#ifdef SO3_DEBUG
8634 MMechostr(MSKDEBUG, "SO3CbMaterialOverlapEnded\n");
8635#endif
8636
8637 int k;
8638 int pUser = MMpull(m);
8639 int pCbk = MMpull(m);
8640 int mat2 = MMpull(m);
8641 int mat1 = MMpull(m);
8642
8643 // check mat1
8644 if (mat1 == NIL)
8645 {
8646 MMechostr(0, "SO3CbMaterialOverlapStarted error : mat1 is nil...\n");
8647 MMpush(m, NIL);
8648 return 0;
8649 }
8650
8651 // check mat2
8652 if (mat2 == NIL)
8653 {
8654 MMechostr(0, "SO3CbMaterialOverlapStarted error : mat2 is nil...\n");
8655 MMpush(m, NIL);
8656 return 0;
8657 }
8658
8659 SMaterialID* matID1 = MMgetPointer<SMaterialID*>(m, MTOP(mat1));
8660 if (matID1 == NULL)
8661 {
8662 MMpush(m, NIL);
8663 return 0;
8664 }
8665
8666 SMaterialID* matID2 = MMgetPointer<SMaterialID*>(m, MTOP(mat2));
8667 if (matID2 == NULL)
8668 {
8669 MMpush(m, NIL);
8670 return 0;
8671 }
8672
8673 // Getting MaterialPair associated
8674 SMaterialPair* matPair = getMaterialPairByWorld(matID1->GetParentWorld(), matID1->getID(), matID2->getID());
8675 if (matPair == NULL)
8676 {
8677 MMpush(m, NIL);
8678 return 0;
8679 }
8680
8681 if (pCbk == NIL)
8682 {
8683 matPair->SetOverlapEndedCallbackActivated(false);
8684 }
8685 else
8686 {
8687 matPair->SetOverlapEndedCallbackActivated(true);
8688 }
8689
8690 int ob = MMfetch(m, OBJfindTH(m, SO3PHYSICSMATERIALPAIR, SCOL_PTR(matPair)), OFFOBJMAG);
8691 if (ob == NIL)
8692 {
8693 matPair->SetOverlapEndedCallbackActivated(false);
8694 MMpush(m, NIL);
8695 return 0;
8696 }
8697
8698 /*
8699 2 : object
8700 1 : cbfun
8701 0 : argument u0
8702 */
8703 MMpush(m, ob);
8704 MMpush(m, pCbk);
8705 MMpush(m, pUser);
8706
8707 k = OBJaddreflex(m, SO3PHYSICSMATERIALPAIR, SO3_MATERIALPAIR_OVERLAP_ENDED);
8708
8709 MMset(m, 0, ITOM(1));
8710
8711#ifdef SO3_DEBUG
8712 MMechostr(MSKDEBUG, "SO3CbMaterialOverlapEnded : OK!\n");
8713#endif
8714 return 0;
8715}
8716
8717
8731int SO3CbBodyLeaveWorld(mmachine m)
8732{
8733#ifdef SO3_DEBUG
8734 MMechostr(MSKDEBUG, "SO3CbBodyLeaveWorld\n");
8735#endif
8736 MMpull(m);
8737 MMpull(m);
8738 MMset(m, 0, NIL);
8739
8740 return 0;
8741 //return OBJaddreflex(m, SO3PHYSICBODY, SO3_BODY_LEAVE_WORLD);
8742}
8743
8744NativeDefinition natSO3Phys[] = {
8745 { "SO3_TYPE_BODY_BOX", TYPVAR, "I", SCOL_TYPTYPE(SShape::SO3_BOX_COLLISION) },
8746 { "SO3_TYPE_BODY_CONE", TYPVAR, "I", SCOL_TYPTYPE(SShape::SO3_CONE_COLLISION) },
8747 { "SO3_TYPE_BODY_ELLIPSOID", TYPVAR, "I", SCOL_TYPTYPE(SShape::SO3_ELLIPSOID_COLLISION) },
8748 { "SO3_TYPE_BODY_CAPSULE", TYPVAR, "I", SCOL_TYPTYPE(SShape::SO3_CAPSULE_COLLISION) },
8749 { "SO3_TYPE_BODY_CYLINDER", TYPVAR, "I", SCOL_TYPTYPE(SShape::SO3_CYLINDER_COLLISION) },
8750 { "SO3_TYPE_BODY_COMPOUND", TYPVAR, "I", SCOL_TYPTYPE(SShape::SO3_COMPOUND_COLLISION) },
8751 { "SO3_TYPE_BODY_CHAMFERCYLINDRE", TYPVAR, "I", SCOL_TYPTYPE(SShape::SO3_CHAMFERCYLINDRE_COLLISION)},
8752 { "SO3_TYPE_BODY_PYRAMID", TYPVAR, "I", SCOL_TYPTYPE(SShape::SO3_PYRAMID_COLLISION) },
8753 { "SO3_TYPE_BODY_SHAPE", TYPVAR, "I", SCOL_TYPTYPE(SShape::SO3_SHAPE_COLLISION) },
8754 { "SO3_TYPE_BODY_CONCAVE", TYPVAR, "I", SCOL_TYPTYPE(SShape::SO3_CONCAVE_COLLISION) },
8755 { "SO3_TYPE_BODY_TREE", TYPVAR, "I", SCOL_TYPTYPE(SShape::SO3_TREE_COLLISION) },
8756 { "SO3WorldSetFPS", 2, "fun [SO3_SCENE I] I", SO3WorldSetFPS },
8757 { "SO3WorldSetSize", 3, "fun [SO3_SCENE [F F F] [F F F]] I", SO3WorldSetSize },
8758 { "SO3WorldGetFPS", 1, "fun [SO3_SCENE] I", SO3WorldGetFPS },
8759 { "SO3WorldSetFrictionModel", 2, "fun [SO3_SCENE I] I", SO3WorldSetFrictionModel },
8760 { "SO3WorldGetFrictionModel", 1, "fun [SO3_SCENE] I", SO3WorldGetFrictionModel },
8761 { "SO3WorldSetPlateformArchitecture", 2, "fun [SO3_SCENE I] I", SO3WorldSetPlateformArchitecture },
8762 { "SO3WorldGetPlateformArchitecture", 1, "fun [SO3_SCENE] I", SO3WorldGetPlateformArchitecture },
8763 { "SO3WorldSetSolverModel", 2, "fun [SO3_SCENE I] I", SO3WorldSetSolverModel },
8764 { "SO3WorldGetSolverModel", 1, "fun [SO3_SCENE] I", SO3WorldGetSolverModel },
8765 { "SO3WorldSetEnabled", 2, "fun [SO3_SCENE I] I", SO3WorldSetEnabled },
8766 { "SO3WorldGetEnabled", 1, "fun [SO3_SCENE] I", SO3WorldGetEnabled },
8767 { "SO3WorldShowLines", 2, "fun [SO3_SCENE I] I", SO3WorldShowLines },
8768 { "SO3WorldSetGravity", 2, "fun [SO3_SCENE [F F F]] I", SO3WorldSetGravity },
8769 { "SO3WorldGetGravity", 1, "fun [SO3_SCENE] [F F F]", SO3WorldGetGravity },
8770 { "SO3WorldReset", 1, "fun [SO3_SCENE] I", SO3WorldReset },
8771 { "SO3WorldSetBodiesInitialState", 1, "fun [SO3_SCENE] I", SO3WorldSetBodiesInitialState },
8772 { "SO3BodyCreateBox", 2, "fun [SO3_OBJECT [F F F]] SO3_PHYSICBODY", SO3BodyCreateBox },
8773 { "SO3BodyCreateEllipsoid", 2, "fun [SO3_OBJECT [F F F]] SO3_PHYSICBODY", SO3BodyCreateEllipsoid },
8774 { "SO3BodyCreateCapsule", 3, "fun [SO3_OBJECT F F] SO3_PHYSICBODY", SO3BodyCreateCapsule },
8775 { "SO3BodyCreateChamferCylinder", 3, "fun [SO3_OBJECT F F] SO3_PHYSICBODY", SO3BodyCreateChamferCylinder },
8776 { "SO3BodyCreateCone", 3, "fun [SO3_OBJECT F F] SO3_PHYSICBODY", SO3BodyCreateCone },
8777 { "SO3BodyCreateCylinder", 3, "fun [SO3_OBJECT F F] SO3_PHYSICBODY", SO3BodyCreateCylinder },
8778 { "SO3BodyCreatePyramid", 2, "fun [SO3_OBJECT [F F F]] SO3_PHYSICBODY", SO3BodyCreatePyramid },
8779 { "SO3BodyCreateBoxExt", 4, "fun [SO3_OBJECT [F F F] [F F F] [F F F F]] SO3_PHYSICBODY", SO3BodyCreateBoxExt },
8780 { "SO3BodyCreateEllipsoidExt", 4, "fun [SO3_OBJECT [F F F] [F F F] [F F F F]] SO3_PHYSICBODY", SO3BodyCreateEllipsoidExt },
8781 { "SO3BodyCreateCapsuleExt", 5, "fun [SO3_OBJECT F F [F F F] [F F F F]] SO3_PHYSICBODY", SO3BodyCreateCapsuleExt },
8782 { "SO3BodyCreateChamferCylinderExt", 5, "fun [SO3_OBJECT F F [F F F] [F F F F]] SO3_PHYSICBODY", SO3BodyCreateChamferCylinderExt },
8783 { "SO3BodyCreateConeExt", 5, "fun [SO3_OBJECT F F [F F F] [F F F F]] SO3_PHYSICBODY", SO3BodyCreateConeExt },
8784 { "SO3BodyCreateCylinderExt", 5, "fun [SO3_OBJECT F F [F F F] [F F F F]] SO3_PHYSICBODY", SO3BodyCreateCylinderExt },
8785 { "SO3BodyCreatePyramidExt", 4, "fun [SO3_OBJECT [F F F] [F F F] [F F F F]] SO3_PHYSICBODY", SO3BodyCreatePyramidExt },
8786 { "SO3BodyCreateCollisionTree", 2, "fun [SO3_OBJECT I] SO3_PHYSICBODY", SO3BodyCreateCollisionTree },
8787 { "SO3BodyCreateShape", 2, "fun [SO3_OBJECT F] SO3_PHYSICBODY", SO3BodyCreateShape },
8788 { "SO3BodyCreateConcaveShape", 2, "fun [SO3_OBJECT F] SO3_PHYSICBODY", SO3BodyCreateConcaveShape },
8789 { "SO3BodyGetShapeDefinition", 1, "fun [SO3_PHYSICBODY] [I F [F F] [F F F] [F F F] [F F F F]]", SO3BodyGetShapeDefinition },
8790 { "SO3BodySetMass", 2, "fun [SO3_PHYSICBODY F] I", SO3BodySetMass },
8791 { "SO3BodyCreateBasicJointUpVector", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodyCreateBasicJointUpVector },
8792 { "SO3BodyDestroyBasicJointUpVector", 1, "fun [SO3_PHYSICBODY] I", SO3BodyDestroyBasicJointUpVector },
8793 { "SO3BodySetForce", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodySetForce },
8794 { "SO3BodyAddForce", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodyAddForce },
8795 { "SO3BodyGetForce", 1, "fun [SO3_PHYSICBODY] [F F F]", SO3BodyGetForce },
8796 { "SO3BodyAddGlobalForce", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodyAddGlobalForce },
8797 { "SO3BodyAddLocalForce", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodyAddLocalForce },
8798 { "SO3BodyAddTorque", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodyAddTorque },
8799 { "SO3BodySetTorque", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodySetTorque },
8800 { "SO3BodySetOmega", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodySetOmega },
8801 { "SO3BodySetVelocity", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodySetVelocity },
8802 { "SO3BodyAddImpulse", 3, "fun [SO3_PHYSICBODY [F F F] [F F F]] I", SO3BodyAddImpulse },
8803 { "SO3BodyMoveTo", 3, "fun [SO3_PHYSICBODY [F F F] F] I", SO3BodyMoveTo },
8804 { "SO3BodyRotateTo", 3, "fun [SO3_PHYSICBODY [F F F F] F] I", SO3BodyRotateTo },
8805 { "SO3BodySetPositionOrientation", 3, "fun [SO3_PHYSICBODY [F F F] [F F F F]] I", SO3BodySetPositionOrientation },
8806 { "SO3BodySetAngularDamping", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodySetAngularDamping },
8807 { "SO3BodySetCenterOfMass", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodySetCenterOfMass },
8808 { "SO3BodySetMassMatrix", 3, "fun [SO3_PHYSICBODY F [F F F]] I", SO3BodySetMassMatrix },
8809 { "SO3BodyGetAngularDamping", 1, "fun [SO3_PHYSICBODY] [F F F]", SO3BodyGetAngularDamping },
8810 { "SO3BodyGetOmega", 1, "fun [SO3_PHYSICBODY] [F F F]", SO3BodyGetOmega },
8811 { "SO3BodyGetTorque", 1, "fun [SO3_PHYSICBODY] [F F F]", SO3BodyGetTorque },
8812 { "SO3BodySetConstantForce", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodySetConstantForce },
8813 { "SO3BodyAddConstantForce", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodyAddConstantForce },
8814 { "SO3BodyGetConstantForce", 1, "fun [SO3_PHYSICBODY] [F F F]", SO3BodyGetConstantForce },
8815 { "SO3BodySetConstantTorque", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodySetConstantTorque },
8816 { "SO3BodyAddConstantTorque", 2, "fun [SO3_PHYSICBODY [F F F]] I", SO3BodyAddConstantTorque },
8817 { "SO3BodyGetConstantTorque", 1, "fun [SO3_PHYSICBODY] [F F F]", SO3BodyGetConstantTorque },
8818 { "SO3BodySetLinearDamping", 2, "fun [SO3_PHYSICBODY F] I", SO3BodySetLinearDamping },
8819 { "SO3BodySetAutoSleep", 2, "fun [SO3_PHYSICBODY I] I", SO3BodySetAutoSleep },
8820 { "SO3BodySetType", 2, "fun [SO3_PHYSICBODY I] I", SO3BodySetType },
8821 { "SO3BodySetInitialState", 1, "fun [SO3_PHYSICBODY] I", SO3BodySetInitialState },
8822 { "SO3BodySetContiniousCollisionMode", 2, "fun [SO3_PHYSICBODY I] I", SO3BodySetContiniousCollisionMode },
8823 { "SO3BodyCalculateOffset", 1, "fun [SO3_PHYSICBODY] [F F F]", SO3BodyCalculateOffset },
8824 { "SO3BodyGetLinearDamping", 1, "fun [SO3_PHYSICBODY] F", SO3BodyGetLinearDamping },
8825 { "SO3BodyGetInvMass", 1, "fun [SO3_PHYSICBODY] [F [F F F]]", SO3BodyGetInvMass },
8826 { "SO3BodyGetMassMatrix", 1, "fun [SO3_PHYSICBODY] [F [F F F]]", SO3BodyGetMassMatrix },
8827 { "SO3BodyGetAutoSleep", 1, "fun [SO3_PHYSICBODY] I", SO3BodyGetAutoSleep },
8828 { "SO3BodyGetSleepingState", 1, "fun [SO3_PHYSICBODY] I", SO3BodyGetSleepingState },
8829 { "SO3BodyGetType", 1, "fun [SO3_PHYSICBODY] I", SO3BodyGetType },
8830 { "SO3BodyGetContiniousCollisionMode", 1, "fun [SO3_PHYSICBODY] I", SO3BodyGetContiniousCollisionMode },
8831 { "SO3BodyGetCenterOfMass", 1, "fun [SO3_PHYSICBODY] [F F F]", SO3BodyGetCenterOfMass },
8832 { "SO3BodyGetVelocity", 1, "fun [SO3_PHYSICBODY] [F F F]", SO3BodyGetVelocity },
8833 { "SO3BodyGetPositionOrientation", 1, "fun [SO3_PHYSICBODY] [[F F F] [F F F F]]", SO3BodyGetPositionOrientation },
8834 { "SO3BodySetFreeze", 2, "fun [SO3_PHYSICBODY I] I", SO3BodySetFreeze },
8835 { "SO3BodyGetFreeze", 1, "fun [SO3_PHYSICBODY] I", SO3BodyGetFreeze },
8836 { "SO3BodySetSimulation", 2, "fun [SO3_PHYSICBODY I] I", SO3BodySetSimulation },
8837 { "SO3BodyGetSimulation", 1, "fun [SO3_PHYSICBODY] I", SO3BodyGetSimulation },
8838 { "SO3BodySetGravityEnable", 2, "fun [SO3_PHYSICBODY I] I", SO3BodySetGravityEnable },
8839 { "SO3BodyGetGravityEnable", 1, "fun [SO3_PHYSICBODY] I", SO3BodyGetGravityEnable },
8840 { "SO3BodyGetSceneNode", 1, "fun [SO3_PHYSICBODY] SO3_OBJECT", SO3BodyGetSceneNode },
8841 { "SO3BodySetIgnoreCollision", 2, "fun [SO3_PHYSICBODY I] I", SO3BodySetIgnoreCollision },
8842 { "SO3BodyGetIgnoreCollision", 1, "fun [SO3_PHYSICBODY] I", SO3BodyGetIgnoreCollision },
8843 { "SO3BodySetFluid", 2, "fun [SO3_PHYSICBODY I] I", SO3BodySetFluid },
8844 { "SO3BodyGetFluid", 1, "fun [SO3_PHYSICBODY] I", SO3BodyGetFluid },
8845 { "SO3BodySetFluidVolumeRatio", 2, "fun [SO3_PHYSICBODY F] I", SO3BodySetFluidVolumeRatio },
8846 { "SO3BodyGetFluidVolumeRatio", 1, "fun [SO3_PHYSICBODY] F", SO3BodyGetFluidVolumeRatio },
8847 { "SO3BodyDestroy", 1, "fun [SO3_PHYSICBODY] I", SO3BodyDestroy },
8848 { "SO3BodyShowDebug", 2, "fun [SO3_PHYSICBODY I] I", SO3BodyShowDebug },
8849 { "SO3SceneNodeGetBody", 1, "fun [SO3_OBJECT] SO3_PHYSICBODY", SO3SceneNodeGetBody },
8850 { "SO3BodySetMaterial", 2, "fun [SO3_PHYSICBODY SO3_PHYSICMATERIAL] I", SO3BodySetMaterial },
8851 { "SO3BodyGetMaterial", 1, "fun [SO3_PHYSICBODY] SO3_PHYSICMATERIAL", SO3BodyGetMaterial },
8852 { "SO3PhysicsMaterialCreate", 2, "fun [SO3_SCENE S] SO3_PHYSICMATERIAL", SO3PhysicsMaterialCreate },
8853 { "SO3PhysicsMaterialDestroy", 1, "fun [SO3_PHYSICMATERIAL] I", SO3PhysicsMaterialDestroy },
8854 { "SO3PhysicsMaterialSetDefaultElasticity", 3, "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL F] I", SO3PhysicsMaterialSetDefaultElasticity },
8855 { "SO3PhysicsMaterialSetDefaultFriction", 4, "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL F F] I", SO3PhysicsMaterialSetDefaultFriction },
8856 { "SO3PhysicsMaterialSetDefaultSoftness", 3, "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL F] I", SO3PhysicsMaterialSetDefaultSoftness },
8857 { "SO3PhysicsMaterialSetDefaultCollidable", 3, "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL I] I", SO3PhysicsMaterialSetDefaultCollidable },
8858 { "SO3PhysicsMaterialSetSurfaceThickness", 3, "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL F] I", SO3PhysicsMaterialSetSurfaceThickness },
8859 { "SO3PhysicsMaterialSetContiniousCollisionMode", 3, "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL I] I", SO3PhysicsMaterialSetContiniousCollisionMode },
8860 { "SO3CbMaterialCollision", 4, "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", SO3CbMaterialCollision },
8861 { "SO3CbMaterialOverlapStarted", 4, "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL fun [SO3_SCENE u0 SO3_PHYSICBODY SO3_PHYSICBODY] u1 u0 ] I", SO3CbMaterialOverlapStarted },
8862 { "SO3CbMaterialOverlapEnded", 4, "fun [SO3_PHYSICMATERIAL SO3_PHYSICMATERIAL fun [SO3_SCENE u0 SO3_PHYSICBODY SO3_PHYSICBODY] u1 u0 ] I", SO3CbMaterialOverlapEnded },
8863 { "SO3CbBodyLeaveWorld", 3, "fun [SO3_PHYSICBODY fun [SO3_PHYSICBODY u0] u1 u0] SO3_PHYSICBODY", SO3CbBodyLeaveWorld },
8864 { "SO3PhysicsGetMaterial", 2, "fun [SO3_SCENE S] SO3_PHYSICMATERIAL", SO3PhysicsGetMaterial },
8865 { "SO3PhysicsGetMaterialName", 1, "fun [SO3_PHYSICMATERIAL] S", SO3PhysicsGetMaterialName },
8866 { "SO3PhysicsRayCast", 4, "fun [SO3_SCENE [F F F] [F F F] F] [SO3_PHYSICBODY F [F F F]]", SO3PhysicsRayCast },
8867 { "SO3PhysicsRayCastExt", 4, "fun [SO3_SCENE [F F F] [F F F] F] [[SO3_PHYSICBODY F [F F F]] r1]", SO3PhysicsRayCastExt },
8868 { "SO3PhysicsContraintDestroy", 1, "fun [SO3_PHYSICCONTRAINT] I", SO3PhysicsContraintDestroy },
8869 { "SO3PhysicsContraintSetCollisionState", 2, "fun [SO3_PHYSICCONTRAINT I] I", SO3PhysicsContraintSetCollisionState },
8870 { "SO3PhysicsContraintGetCollisionState", 1, "fun [SO3_PHYSICCONTRAINT] I", SO3PhysicsContraintGetCollisionState },
8871 { "SO3PhysicsContraintSetStiffness", 2, "fun [SO3_PHYSICCONTRAINT F] I", SO3PhysicsContraintSetStiffness },
8872 { "SO3PhysicsContraintGetStiffness", 1, "fun [SO3_PHYSICCONTRAINT] F", SO3PhysicsContraintGetStiffness },
8873 { "SO3PhysicsContraintCreateBallAndSocket", 5, "fun [SO3_SCENE SO3_PHYSICBODY SO3_PHYSICBODY [F F F] I] SO3_PHYSICCONTRAINT]", SO3PhysicsContraintCreateBallAndSocket },
8874 { "SO3PhysicsContraintSetBallAndSocketLimits", 4, "fun [SO3_PHYSICCONTRAINT F F F] I", SO3PhysicsContraintSetBallAndSocketLimits },
8875 { "SO3PhysicsContraintSetBallAndSocketControlled", 2, "fun [SO3_PHYSICCONTRAINT I] I", SO3PhysicsContraintSetBallAndSocketControlled },
8876 { "SO3PhysicsContraintSetBallAndSocketAngularVelocity", 2, "fun [SO3_PHYSICCONTRAINT F] I", SO3PhysicsContraintSetBallAndSocketAngularVelocity },
8877 { "SO3PhysicsContraintSetBallAndSocketYawAngle", 2, "fun [SO3_PHYSICCONTRAINT F] I", SO3PhysicsContraintSetBallAndSocketYawAngle },
8878 { "SO3PhysicsContraintSetBallAndSocketPitchAngle", 2, "fun [SO3_PHYSICCONTRAINT F] I", SO3PhysicsContraintSetBallAndSocketPitchAngle },
8879 { "SO3PhysicsContraintSetBallAndSocketRollAngle", 2, "fun [SO3_PHYSICCONTRAINT F] I", SO3PhysicsContraintSetBallAndSocketRollAngle },
8880 { "SO3PhysicsContraintGetBallAndSocketAngle", 1, "fun [SO3_PHYSICCONTRAINT] [F F F]", SO3PhysicsContraintGetBallAndSocketAngle },
8881 { "SO3PhysicsContraintGetBallAndSocketOmega", 1, "fun [SO3_PHYSICCONTRAINT] [F F F]", SO3PhysicsContraintGetBallAndSocketOmega },
8882 { "SO3PhysicsContraintGetBallAndSocketForce", 1, "fun [SO3_PHYSICCONTRAINT] [F F F]", SO3PhysicsContraintGetBallAndSocketForce },
8883 { "SO3PhysicsContraintCreateHinge", 6, "fun [SO3_SCENE SO3_PHYSICBODY SO3_PHYSICBODY [F F F] [F F F] I] SO3_PHYSICCONTRAINT]", SO3PhysicsContraintCreateHinge },
8884 { "SO3PhysicsContraintSetHingeLimits", 3, "fun [SO3_PHYSICCONTRAINT F F] I", SO3PhysicsContraintSetHingeLimits },
8885 { "SO3PhysicsContraintGetHingeAngle", 1, "fun [SO3_PHYSICCONTRAINT] F", SO3PhysicsContraintGetHingeAngle },
8886 { "SO3PhysicsContraintGetHingeOmega", 1, "fun [SO3_PHYSICCONTRAINT] F", SO3PhysicsContraintGetHingeOmega },
8887 { "SO3PhysicsContraintGetHingeForce", 1, "fun [SO3_PHYSICCONTRAINT] [F F F]", SO3PhysicsContraintGetHingeForce },
8888 { "SO3PhysicsContraintSetHingeMotorAngle", 4, "fun [SO3_PHYSICCONTRAINT F F F] I", SO3PhysicsContraintSetHingeMotorAngle },
8889 { "SO3PhysicsContraintSetHingeMotorOmega", 3, "fun [SO3_PHYSICCONTRAINT F F] I", SO3PhysicsContraintSetHingeMotorOmega },
8890 { "SO3PhysicsContraintSetHingeTorque", 2, "fun [SO3_PHYSICCONTRAINT F] I", SO3PhysicsContraintSetHingeTorque },
8891 { "SO3PhysicsContraintSetHingeBrake", 2, "fun [SO3_PHYSICCONTRAINT F] I", SO3PhysicsContraintSetHingeBrake },
8892 { "SO3PhysicsContraintSetHingeMotorEnable", 2, "fun [SO3_PHYSICCONTRAINT I] I", SO3PhysicsContraintSetHingeMotorEnable },
8893 { "SO3PhysicsContraintCreateSlider", 7, "fun [SO3_SCENE SO3_PHYSICBODY SO3_PHYSICBODY [F F F] [F F F] I I] SO3_PHYSICCONTRAINT]", SO3PhysicsContraintCreateSlider },
8894 { "SO3PhysicsContraintSetSliderLimits", 3, "fun [SO3_PHYSICCONTRAINT F F] I", SO3PhysicsContraintSetSliderLimits },
8895 { "SO3PhysicsContraintSetSliderSpring", 3, "fun [SO3_PHYSICCONTRAINT F F] I", SO3PhysicsContraintSetSliderSpring },
8896 { "SO3PhysicsContraintSetSliderFriction", 2, "fun [SO3_PHYSICCONTRAINT F] I", SO3PhysicsContraintSetSliderFriction },
8897 { "SO3PhysicsContraintGetSliderVelocity", 1, "fun [SO3_PHYSICCONTRAINT] F", SO3PhysicsContraintGetSliderVelocity },
8898 { "SO3PhysicsContraintGetSliderForce", 1, "fun [SO3_PHYSICCONTRAINT] [F F F]", SO3PhysicsContraintGetSliderForce },
8899 { "SO3PhysicsContraintGetSliderPosition", 1, "fun [SO3_PHYSICCONTRAINT] F", SO3PhysicsContraintGetSliderPosition },
8900 { "SO3PhysicsContraintSetSliderMotorEnable", 2, "fun [SO3_PHYSICCONTRAINT I] I", SO3PhysicsContraintSetSliderMotorEnable },
8901 { "SO3PhysicsContraintSetSliderMotorVelocity", 3, "fun [SO3_PHYSICCONTRAINT F F] I", SO3PhysicsContraintSetSliderMotorVelocity },
8902 { "SO3PhysicsContraintCreateVehicle", 2, "fun [SO3_SCENE SO3_PHYSICBODY] SO3_PHYSICCONTRAINT", SO3PhysicsContraintCreateVehicle },
8903 { "SO3PhysicsContraintAddVehicleTire", 11, "fun [SO3_PHYSICCONTRAINT SO3_OBJECT F F F F F F F I I] I", SO3PhysicsContraintAddVehicleTire },
8904 { "SO3PhysicsContraintGetVehicleSpeed", 1, "fun [SO3_PHYSICCONTRAINT] F", SO3PhysicsContraintGetVehicleSpeed },
8905 { "SO3PhysicsContraintSetVehicleSteerAngle", 2, "fun [SO3_PHYSICCONTRAINT F] I", SO3PhysicsContraintSetVehicleSteerAngle },
8906 { "SO3PhysicsContraintSetVehicleDrivingTorque", 2, "fun [SO3_PHYSICCONTRAINT F] I", SO3PhysicsContraintSetVehicleDrivingTorque },
8907 { "SO3PhysicsContraintSetVehicleBrake", 2, "fun [SO3_PHYSICCONTRAINT F] I", SO3PhysicsContraintSetVehicleBrake },
8908 { "SO3PhysicsContraintGetVehicleOnAir", 1, "fun [SO3_PHYSICCONTRAINT] I", SO3PhysicsContraintGetVehicleOnAir },
8909 { "SO3PhysicsContraintGetVehicleTireAngularVelocity", 2, "fun [SO3_PHYSICCONTRAINT SO3_OBJECT] F", SO3PhysicsContraintGetVehicleTireAngularVelocity },
8910 { "SO3PhysicsContraintGetVehicleTireOnAir", 2, "fun [SO3_PHYSICCONTRAINT SO3_OBJECT] I", SO3PhysicsContraintGetVehicleTireOnAir },
8911 { "SO3WorldApplyImpulsePoint", 4, "fun [SO3_SCENE [F F F] F F] I", SO3WorldApplyImpulsePoint }
8912};
8913
8914
8920int SCOLloadPhysics(mmachine m, cbmachine w)
8921{
8922 /* NB : Test à Faire : Creation Object PHYSICCB puis modifier SO3CbMaterialCollision avec "fun [SO3_SCENE SO3_PHYSICCB fun [S u0] u1 u0] I"
8923 */
8924 SO3_MATERIALPAIR_OVERLAP_STARTED_MSG = OBJgetUserEvent();
8926 SO3_MATERIALPAIR_OVERLAP_ENDED_MSG = OBJgetUserEvent();
8928 SO3_MATERIALPAIR_COLLISION_MSG = OBJgetUserEvent();
8930 //SO3_BODY_LEAVE_WORLD_MSG = OBJgetUserEvent();
8931 //OBJdefEvent(SO3_BODY_LEAVE_WORLD_MSG, getBodyLeaveWorldCallback);
8932 return PKhardpak2(m, "SO3Phys.pkg", sizeof(natSO3Phys) / sizeof(natSO3Phys[0]), natSO3Phys);
8933}
8934
8935
8941{
8942 return 0;
8943}
8944
NativeDefinition natSO3Phys[]
int SCOLfreePhysics()
free the SO3Engine Viewport function
int getMaterialOverlapEndedCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
C function that prepares the VM for the execution of the Physic Material Overlap callback.
int SO3_MATERIALPAIR_OVERLAP_STARTED_MSG
main include
int SCOLloadPhysics(mmachine m, cbmachine w)
Load the SO3Engine Viewport function.
SMaterialPair * getMaterialPairByWorld(SPhysicWorld *world, int ID1, int ID2)
function to check if a material ID exists
int getMaterialOverlapStartedCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
C function that prepares the VM for the execution of the Physic Material Overlap callback.
int SO3_MATERIALPAIR_COLLISION_MSG
int getMaterialContactCallback(mmachine m, SCOL_PTR_TYPE id, SCOL_PTR_TYPE param)
C function that prepares the VM for the execution of the callback a body leave the physic world.
bool MaterialIDExists(SScene *scene, string testName, SMaterialID **result)
function to check if a material ID exists
int SO3_MATERIALPAIR_OVERLAP_ENDED_MSG
float mod(float _a, float _b)
MMechostr(MSKDEBUG, " > Start loading Plugin SO3Engine dll\n")
SCOL_EXPORT int cbmachine w
Definition SO3SCOL.cpp:5150
SCOL_EXPORT void SCOL_PTR_TYPE param
Definition SO3SCOL.cpp:5089
int SO3PHYSICCONTRAINT
Definition SO3SCOL.cpp:100
int SO3PHYSICSMATERIALTYPE
Definition SO3SCOL.cpp:95
int createBody(mmachine m, SNode *curNode)
int SO3SCENETYPE
Definition SO3SCOL.cpp:88
int SO3PHYSICSMATERIALPAIR
Definition SO3SCOL.cpp:96
int createPhysicContraint(mmachine m, SPhysicContraint *joint)
int SO3OBJTYPE
Definition SO3SCOL.cpp:90
int SO3PHYSICBODY
Definition SO3SCOL.cpp:99
int createMaterialID(mmachine m, SMaterialID *curMatID, SScene *curScene)
int createMaterialPair(mmachine m, SMaterialPair *curMatPair, SScene *curScene)
Manage Physics Contraints. .
Manage Physics Bodies. .
Manage Physics Contraints. .
SNode * GetNode(const std::string &nodeName) const
Definition SO3Scene.cpp:459
Manage Physics Contraint. .
Manage Box physics shape .
Manage Cone physics shape .
Manage Chamfer Cylinder physics shape .
Manage Concave Hull physics shape .
Manage Cone physics shape .
Manage Convex Hull physics shape .
Manage Cylinder physics shape .
Manage physics shape .
Manage Pyramid physics shape .
Manage Physics Contraints. .
Manage Physics Contraints. .
int SO3BodySetType(mmachine m)
SO3BodySetType : Defines a user type of body.
int SO3PhysicsContraintGetVehicleTireAngularVelocity(mmachine m)
SO3PhysicsContraintGetVehicleTireAngularVelocity : Get a physic vehicle contraint tire angular veloci...
int SO3PhysicsContraintSetHingeMotorEnable(mmachine m)
SO3PhysicsContraintSetHingeMotorEnable : set a physic hinge contraint motor state.
int SO3BodyRotateTo(mmachine m)
SO3BodyRotateTo : Rotate a body to a orientation using forces.
int SO3PhysicsMaterialSetDefaultElasticity(mmachine m)
SO3PhysicsMaterialSetDefaultElasticity : defines Default elasticity between two physics material.
int SO3BodyGetTorque(mmachine m)
SO3BodyGetTorque : Get the torque of a body.
int SO3BodyGetIgnoreCollision(mmachine m)
SO3BodyGetIgnoreCollision : Retrieve the ignore collision state of a body.
int SO3PhysicsContraintSetSliderMotorEnable(mmachine m)
SO3PhysicsContraintSetSliderMotorEnable : set a physic slider contraint motor state.
int SO3PhysicsRayCast(mmachine m)
SO3PhysicsRayCast : send a raycast and return the distance.
int SO3BodyCalculateOffset(mmachine m)
SO3BodyCalculateOffset : calculate the mass offset of a body.
int SO3WorldSetPlateformArchitecture(mmachine m)
SO3WorldSetPlateformArchitecture : This function sets the platform architecture for the world !...
int SO3BodyGetForce(mmachine m)
SO3BodyGetForce : Get the current force of a body.
int SO3BodySetInitialState(mmachine m)
SO3BodySetInitialState : Set the current PRS as initial PRS to this body.
int SO3PhysicsContraintGetBallAndSocketOmega(mmachine m)
SO3PhysicsContraintGetBallAndSocketOmega : Get a physic ball and socket contraint omega.
int SO3PhysicsGetMaterial(mmachine m)
SO3PhysicsGetMaterial : return a material Physics by its name.
int SO3BodyCreateBasicJointUpVector(mmachine m)
SO3BodyCreateBasicJointUpVector : Create an up joint vector.
int SO3PhysicsContraintSetBallAndSocketLimits(mmachine m)
SO3PhysicsContraintSetBallAndSocketLimits : Set a physic ball and socket contraint cone limits.
int SO3BodySetFluid(mmachine m)
SO3BodySetFluid : defines a body as a fluid behavior.
int SO3BodySetVelocity(mmachine m)
SO3BodySetVelocity : Set a velocity to a body.
int SO3PhysicsContraintSetHingeMotorAngle(mmachine m)
SO3PhysicsContraintSetHingeMotorAngle : Set a physic hinge contraint to an angle.
int SO3PhysicsContraintSetSliderLimits(mmachine m)
SO3PhysicsContraintSetSliderLimits : Set a physic slider contraint distance limits.
int SO3BodyCreatePyramidExt(mmachine m)
SO3BodyCreatePyramidExt : Create a body as a pyramid shape.
int SO3PhysicsContraintAddVehicleTire(mmachine m)
SO3PhysicsContraintAddVehicleTire : Add a physic vehicle contraint tire.
int SO3BodySetMass(mmachine m)
SO3BodySetMass : Set a mass to a body.
int SO3BodyCreateConcaveShape(mmachine m)
SO3BodyCreateConcaveShape : Create a body as a shape (automatic calculation)
int SO3PhysicsContraintSetHingeLimits(mmachine m)
SO3PhysicsContraintSetHingeLimits : Set a physic hinge contraint angle limits.
int SO3WorldSetFPS(mmachine m)
SO3WorldSetFPS : defines FPS for physic world.
int SO3BodyCreateShape(mmachine m)
SO3BodyCreateShape : Create a body as a shape (automatic calculation)
int SO3PhysicsMaterialSetContiniousCollisionMode(mmachine m)
SO3PhysicsMaterialSetContiniousCollisionMode : do nothing deprecated.
int SO3BodySetIgnoreCollision(mmachine m)
SO3BodySetIgnoreCollision : Define if a body must be ignored when a collision occure.
int SO3BodyCreateBox(mmachine m)
SO3BodyCreateBox : Create a body as a box shape.
int SO3BodyAddGlobalForce(mmachine m)
SO3BodyAddGlobalForce : Add a global force to a body.
int SO3BodyGetFreeze(mmachine m)
SO3BodyGetFreeze : Get freeze state of a body.
int SO3BodyCreateCone(mmachine m)
SO3BodyCreateCone : Create a body as a cone shape.
int SO3BodyCreateBoxExt(mmachine m)
SO3BodyCreateBoxExt : Create a body as a box shape.
int SO3BodySetSimulation(mmachine m)
SO3BodySetSimulation : Enable or disable a body simulation.
int SO3WorldSetEnabled(mmachine m)
SO3WorldSetEnabled : Activate or Deactivate the physic world.
int SO3PhysicsContraintGetVehicleTireOnAir(mmachine m)
SO3PhysicsContraintGetVehicleTireOnAir : Get a physic vehicle contraint tire on air state.
int SO3BodyGetConstantTorque(mmachine m)
SO3BodyGetConstantTorque : Get the current constant torque of a body.
int SO3PhysicsContraintGetSliderForce(mmachine m)
SO3PhysicsContraintGetSliderForce : Get a physic slider contraint force.
int SO3BodyGetShapeDefinition(mmachine m)
SO3BodyGetShapeDefinition : Get a body shape definition.
int SO3BodyCreateEllipsoid(mmachine m)
SO3BodyCreateEllipsoid : Create a body as an ellipsoid shape.
int SO3PhysicsMaterialSetDefaultSoftness(mmachine m)
SO3PhysicsMaterialSetDefaultSoftness : defines Default softness between two physics material.
int SO3PhysicsContraintCreateSlider(mmachine m)
SO3PhysicsContraintCreateSlider : Create a slider contraint.
int SO3PhysicsContraintSetVehicleDrivingTorque(mmachine m)
SO3PhysicsContraintSetVehicleDrivingTorque : Set a physic vehicle contraint driving torque.
int SO3WorldApplyImpulsePoint(mmachine m)
SO3WorldApplyImpulsePoint : Apply an impulsion on bodies in the point area.
int SO3BodyCreateCylinder(mmachine m)
SO3BodyCreateCylinder : Create a body as a cylinder shape.
int SO3BodySetOmega(mmachine m)
SO3BodySetOmega : Set an omega to a body.
int SO3PhysicsContraintGetVehicleSpeed(mmachine m)
SO3PhysicsContraintGetVehicleSpeed : Get a physic vehicle contraint speed.
int SO3PhysicsContraintSetBallAndSocketAngularVelocity(mmachine m)
SO3PhysicsContraintSetBallAndSocketAngularVelocity : Set a physic ball and socket contraint angular v...
int SO3BodyGetLinearDamping(mmachine m)
SO3BodyGetLinearDamping : Get the linear damping of a body.
int SO3BodySetFreeze(mmachine m)
SO3BodySetFreeze : Set a body to freeze state.
int SO3PhysicsContraintSetBallAndSocketYawAngle(mmachine m)
SO3PhysicsContraintSetBallAndSocketYawAngle : Set a physic ball and socket contraint Yaw angle The co...
int SO3BodyAddLocalForce(mmachine m)
SO3BodyAddLocalForce : Add a local force to a body.
int SO3BodyGetSimulation(mmachine m)
SO3BodyGetSimulation : Get simulation state of a body.
int SO3BodyCreateCylinderExt(mmachine m)
SO3BodyCreateCylinderExt : Create a body as a cylinder shape.
int SO3BodyGetFluid(mmachine m)
SO3BodyGetFluid : Retrieve the fluid state of a body.
int SO3WorldGetGravity(mmachine m)
SO3WorldGetGravity : get the gravity of the scene.
int SO3PhysicsContraintCreateBallAndSocket(mmachine m)
SO3PhysicsContraintCreateBallAndSocket : Create a physic ball and socket contraint.
int SO3BodyGetContiniousCollisionMode(mmachine m)
SO3BodyGetContiniousCollisionMode : Get the continuous collision mode of a body.
int SO3BodyAddTorque(mmachine m)
SO3BodyAddTorque : Add torque vector to a body.
int SO3PhysicsContraintSetHingeTorque(mmachine m)
SO3PhysicsContraintSetHingeTorque : Set a physic hinge contraint torque.
int SO3WorldReset(mmachine m)
SO3WorldReset : Reset the physic world and all bodies states.
int SO3WorldShowLines(mmachine m)
SO3WorldShowLines : Return true if world shows its debug calculation lines.
int SO3BodyGetOmega(mmachine m)
SO3BodyGetOmega : Get the omega of a body.
int SO3BodySetFluidVolumeRatio(mmachine m)
SO3BodySetFluidVolumeRatio : Set a body fluid parameters.
int SO3PhysicsContraintSetSliderMotorVelocity(mmachine m)
SO3PhysicsContraintSetSliderMotorVelocity : Set a physic slider contraint velocity.
int SO3BodySetAngularDamping(mmachine m)
SO3BodySetAngularDamping : defines angular Damping of a body.
int SO3PhysicsContraintGetHingeForce(mmachine m)
SO3PhysicsContraintGetHingeForce : Get a physic hinge contraint force.
int SO3PhysicsContraintSetBallAndSocketControlled(mmachine m)
SO3PhysicsContraintSetBallAndSocketControlled : Set a physic ball and socket contraint controlled mod...
int SO3BodyAddConstantTorque(mmachine m)
SO3BodyAddConstantTorque : Add a torque force to a body that will be constant each frame.
int SO3BodyGetAngularDamping(mmachine m)
SO3BodyGetAngularDamping : Get the angular damping of a body.
int SO3BodyGetVelocity(mmachine m)
SO3BodyGetVelocity : Get the velocity of a body.
int SO3BodySetMaterial(mmachine m)
SO3BodySetMaterial : Set a material for a body.
int SO3PhysicsContraintCreateHinge(mmachine m)
SO3PhysicsContraintCreateHinge : Create a hinge contraint.
int SO3BodySetLinearDamping(mmachine m)
SO3BodySetLinearDamping : defines linear damping of a body.
int SO3PhysicsContraintGetBallAndSocketForce(mmachine m)
SO3PhysicsContraintGetBallAndSocketForce : Get a physic ball and socket contraint force.
int SO3BodyGetFluidVolumeRatio(mmachine m)
SO3BodyGetFluidVolumeRatio : get the fluid parameters of a body.
int SO3BodyDestroy(mmachine m)
SO3BodyDestroy : Destroy a body.
int SO3BodyCreateChamferCylinderExt(mmachine m)
SO3BodyCreateChamferCylinderExt : Create a body as a chamfer cylinder shape.
int SO3BodySetAutoSleep(mmachine m)
SO3BodySetAutoSleep : defines Auto sleep state of a body.
int SO3PhysicsMaterialSetDefaultCollidable(mmachine m)
SO3PhysicsMaterialSetDefaultCollidable : defines Default Collidable state between two physics materia...
int SO3BodyGetPositionOrientation(mmachine m)
SO3BodyGetPositionOrientation : Get the position/orientation of a body.
int SO3BodyAddForce(mmachine m)
SO3BodyAddForce : Add a force to a body.
int SO3BodyGetGravityEnable(mmachine m)
SO3BodyGetGravityEnable : Get freeze state of a body.
int SO3BodyMoveTo(mmachine m)
SO3BodyMoveTo : Move a body to a position using forces.
int SO3PhysicsContraintSetBallAndSocketRollAngle(mmachine m)
SO3PhysicsContraintSetBallAndSocketRollAngle : Set a physic ball and socket contraint Roll angle The ...
int SO3PhysicsContraintGetCollisionState(mmachine m)
SO3PhysicsContraintGetCollisionState : Get a physic contraint collision state between the son and the...
int SO3BodyShowDebug(mmachine m)
SO3BodyShowDebug : Set the body shape visible state.
int SO3WorldSetFrictionModel(mmachine m)
SO3WorldSetFrictionModel : This function sets the friction model for the world ! Deprecated !
int SO3WorldGetSolverModel(mmachine m)
SO3WorldGetSolverModel : This function gets the solver model of the world.
int SO3BodyGetCenterOfMass(mmachine m)
SO3BodyGetCenterOfMass : Get the center of masse of a body.
int SO3BodyAddConstantForce(mmachine m)
SO3BodyAddConstantForce : Add a force to a body that will be constant each frame.
int SO3PhysicsMaterialSetSurfaceThickness(mmachine m)
SO3PhysicsMaterialSetSurfaceThickness : defines Surface thickness between two physics material.
int SO3PhysicsRayCastExt(mmachine m)
SO3PhysicsRayCastExt : send a raycast all the hit bodies.
int SO3PhysicsContraintDestroy(mmachine m)
SO3PhysicsContraintDestroy : Destroy a physic contraint.
int SO3PhysicsMaterialCreate(mmachine m)
SO3PhysicsMaterialCreate : Create a new Physic Material ID.
int SO3WorldGetPlateformArchitecture(mmachine m)
SO3WorldGetPlateformArchitecture : This function gets the platform architecture for the world !...
int SO3PhysicsContraintGetVehicleOnAir(mmachine m)
SO3PhysicsContraintGetVehicleOnAir : Get if a physic vehicle contraint has tires on the ground.
int SO3BodyGetType(mmachine m)
SO3BodyGetType : Returns the user type of body.
int SO3WorldGetFPS(mmachine m)
SO3WorldGetFPS : retrieve the FPS for physic world.
int SO3WorldGetFrictionModel(mmachine m)
SO3WorldGetFrictionModel : This function gets the friction model for the world ! Deprecated !
int SO3PhysicsMaterialDestroy(mmachine m)
SO3PhysicsMaterialDestroy : Destroy a Physic Material ID.
int SO3BodySetCenterOfMass(mmachine m)
SO3BodySetCenterOfMass : defines center of mass for a body.
int SO3BodyGetMaterial(mmachine m)
SO3BodyGetMaterial : Get a material of a body.
int SO3PhysicsContraintCreateVehicle(mmachine m)
SO3PhysicsContraintCreateVehicle : Create a vehicle contraint.
int SO3BodyCreateCapsuleExt(mmachine m)
SO3BodyCreateCapsuleExt : Create a body as a capsule shape.
int SO3BodyGetMassMatrix(mmachine m)
SO3BodyGetMassMatrix : Get the mass matrix of a body.
int SO3PhysicsContraintGetHingeOmega(mmachine m)
SO3PhysicsContraintGetHingeOmega : Get a physic hinge contraint omega.
int SO3PhysicsContraintSetVehicleSteerAngle(mmachine m)
SO3PhysicsContraintSetVehicleSteerAngle : Set a physic vehicle contraint steer angle.
int SO3WorldSetBodiesInitialState(mmachine m)
SO3WorldSetBodiesInitialState : Set the current PRS as initial PRS to all bodies.
int SO3PhysicsContraintSetHingeMotorOmega(mmachine m)
SO3PhysicsContraintSetHingeMotorOmega : Set a physic hinge contraint omega.
int SO3WorldSetSize(mmachine m)
SO3WorldSetSize : function to defines world size.
int SO3BodySetTorque(mmachine m)
SO3BodySetTorque : Set a torque to a body.
int SO3BodySetContiniousCollisionMode(mmachine m)
SO3BodySetContiniousCollisionMode : defines continuous collision mode of a body.
int SO3BodyCreateEllipsoidExt(mmachine m)
SO3BodyCreateEllipsoidExt : Create a body as an ellipsoid shape.
int SO3WorldGetEnabled(mmachine m)
SO3WorldGetEnabled : Return the enable state of the physic world.
int SO3BodySetPositionOrientation(mmachine m)
SO3BodySetPositionOrientation : Set Position/Orientation of a body DO NOT USE.
int SO3PhysicsContraintSetHingeBrake(mmachine m)
SO3PhysicsContraintSetHingeBrake : Set a physic hinge contraint brake.
int SO3PhysicsGetMaterialName(mmachine m)
SO3PhysicsGetMaterialName : return the name of a Physics material.
int SO3PhysicsContraintGetStiffness(mmachine m)
SO3PhysicsContraintGetStiffness : Get a physic contraint stiffness value.
int SO3BodySetConstantTorque(mmachine m)
SO3BodySetConstantTorque : Set a constant torque force to a body that will be constant each frame.
int SO3BodySetGravityEnable(mmachine m)
SO3BodySetGravityEnable : Set a body to freeze state.
int SO3PhysicsContraintGetSliderVelocity(mmachine m)
SO3PhysicsContraintGetSliderVelocity : Get a physic hinge contraint velocity.
int SO3PhysicsContraintSetBallAndSocketPitchAngle(mmachine m)
SO3PhysicsContraintSetBallAndSocketPitchAngle : Set a physic ball and socket contraint Pitch angle Th...
int SO3PhysicsContraintSetSliderFriction(mmachine m)
SO3PhysicsContraintSetSliderFriction : Set a physic slider contraint friction.
int SO3SceneNodeGetBody(mmachine m)
SO3SceneNodeGetBody : Get the body attached to a node.
int SO3BodyGetConstantForce(mmachine m)
SO3BodyGetConstantForce : Get the current constant force of a body.
int SO3BodyDestroyBasicJointUpVector(mmachine m)
SO3BodyDestroyBasicJointUpVector : Destroying an up joint vector.
int SO3BodySetMassMatrix(mmachine m)
SO3BodySetMassMatrix : defines mass matrix of a body.
int SO3BodyGetSleepingState(mmachine m)
SO3BodyGetSleepingState : Get the sleep state of a body.
int SO3PhysicsContraintSetCollisionState(mmachine m)
SO3PhysicsContraintSetCollisionState : Set a physic contraint collision state between the son and the...
int SO3BodyGetAutoSleep(mmachine m)
SO3BodyGetAutoSleep : Get the auto sleep state of a body.
int SO3BodyCreateChamferCylinder(mmachine m)
SO3BodyCreateChamferCylinder : Create a body as a chamfer cylinder shape.
int SO3PhysicsContraintGetSliderPosition(mmachine m)
SO3PhysicsContraintGetSliderPosition : Get a physic slider contraint position.
int SO3PhysicsContraintSetSliderSpring(mmachine m)
SO3PhysicsContraintSetSliderSpring : Set a physic slider contraint spring setting.
int SO3BodyCreateCollisionTree(mmachine m)
SO3BodyCreateCollisionTree : Create a body as an exact collision tree.
int SO3BodySetForce(mmachine m)
SO3BodySetForce : Set a force to a body.
int SO3PhysicsMaterialSetDefaultFriction(mmachine m)
SO3PhysicsMaterialSetDefaultFriction : defines Default friction between two physics material.
int SO3BodyGetInvMass(mmachine m)
SO3BodyGetInvMass : Get the inverse mass matrix of a body.
int SO3WorldSetSolverModel(mmachine m)
SO3WorldSetSolverModel : This function sets thesolver model for the world.
int SO3BodySetConstantForce(mmachine m)
SO3BodySetConstantForce : Set a force to a body that will be constant each frame.
int SO3PhysicsContraintGetBallAndSocketAngle(mmachine m)
SO3PhysicsContraintGetBallAndSocketAngle : Get a physic ball and socket contraint angle.
int SO3BodyCreateCapsule(mmachine m)
SO3BodyCreateCapsule : Create a body as a capsule shape.
int SO3BodyCreateConeExt(mmachine m)
SO3BodyCreateConeExt : Create a body as a cone shape.
int SO3PhysicsContraintSetVehicleBrake(mmachine m)
SO3PhysicsContraintSetVehicleBrake : Set a physic vehicle contraint brake.
int SO3PhysicsContraintSetStiffness(mmachine m)
SO3PhysicsContraintSetStiffness : Set a physic contraint stiffness value.
int SO3BodyGetSceneNode(mmachine m)
SO3BodyGetSceneNode : Get the scene Node asssociated to a body.
int SO3WorldSetGravity(mmachine m)
SO3WorldSetGravity : defines gravity for the scene.
int SO3PhysicsContraintGetHingeAngle(mmachine m)
SO3PhysicsContraintGetHingeAngle : Get a physic hinge contraint angle.
int SO3BodyAddImpulse(mmachine m)
SO3BodyAddImpulse : Add an impulsion to a body.
int SO3BodyCreatePyramid(mmachine m)
SO3BodyCreatePyramid : Create a body as a pyramid shape.
int SO3CbMaterialOverlapStarted(mmachine m)
SO3CbMaterialOverlapStarted : Define the callback scol had to be called when two material ID start to...
int SO3CbBodyLeaveWorld(mmachine m)
SO3CbBodyLeaveWorld : Define the scol callback had to be called when a body leave the physic world de...
int SO3CbMaterialCollision(mmachine m)
SO3CbMaterialCollision : Define the callback scol had to be called when two material ID collide.
int SO3CbMaterialOverlapEnded(mmachine m)
SO3CbMaterialOverlapEnded : Define the callback scol had to be called when two material ID does not o...
const SScene * curScene
Definition SO3Physics.h:47