-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
Copy pathScene_ScriptBinding.h
executable file
·3592 lines (2933 loc) · 117 KB
/
Scene_ScriptBinding.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
//-----------------------------------------------------------------------------
// Copyright (c) 2013 GarageGames, LLC
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//-----------------------------------------------------------------------------
ConsoleMethodGroupBeginWithDocs(Scene, BehaviorComponent)
/*! Gets the system-wide scene count.
@return The system-wide scene count.
*/
ConsoleFunctionWithDocs( getGlobalSceneCount, ConsoleInt, 1, 1, ())
{
return Scene::getGlobalSceneCount();
}
//-----------------------------------------------------------------------------
/*! The gravity force to apply to all objects in the scene.
@param forceX/forceY The direction and magnitude of the force in each direction. Formatted as either (\forceX forceY\ or (forceX, forceY)
@return No return value.
*/
ConsoleMethodWithDocs(Scene, setGravity, ConsoleVoid, 3, 4, (forceX / forceY))
{
// The force.
Vector2 force;
// Grab the element count.
U32 elementCount = Utility::mGetStringElementCount(argv[2]);
// ("forceX forceY")
if (elementCount == 1)
{
force = Vector2(dAtof(argv[2]), dAtof(argv[3]));
}
else if (elementCount == 2)
{
force = Utility::mGetStringElementVector(argv[2]);
}
// Invalid
else
{
Con::warnf("SceneObject::setGravity() - Invalid number of parameters!");
return;
}
// Set gravity.
object->setGravity(force);
}
//-----------------------------------------------------------------------------
/*! Gets the gravity force applied to all objects in the scene.
@return The gravity force applied to all objects in the scene.
*/
ConsoleMethodWithDocs(Scene, getGravity, ConsoleString, 2, 2, ())
{
return Vector2(object->getGravity()).scriptThis();
}
//-----------------------------------------------------------------------------
/*! Sets the number of velocity iterations the physics solver uses.
@return No return value.
*/
ConsoleMethodWithDocs(Scene, setVelocityIterations, ConsoleVoid, 3, 3, (int iterations))
{
object->setVelocityIterations( dAtoi(argv[2]) );
}
//-----------------------------------------------------------------------------
/*! Gets the number of velocity iterations the physics solver uses.
(@return The number of velocity iterations the physics solver uses.
*/
ConsoleMethodWithDocs(Scene, getVelocityIterations, ConsoleInt, 2, 2, ())
{
return object->getVelocityIterations();
}
//-----------------------------------------------------------------------------
/*! Sets the number of position iterations the physics solver uses.
@return No return value.
*/
ConsoleMethodWithDocs(Scene, setPositionIterations, ConsoleVoid, 3, 3, (int iterations))
{
object->setPositionIterations( dAtoi(argv[2]) );
}
//-----------------------------------------------------------------------------
/*! Gets the number of position iterations the physics solver uses.
(@return The number of position iterations the physics solver uses.
*/
ConsoleMethodWithDocs(Scene, getPositionIterations, ConsoleInt, 2, 2, ())
{
return object->getPositionIterations();
}
//-----------------------------------------------------------------------------
/*! Add the SceneObject to the scene.
@param sceneObject The SceneObject to add to the scene.
@return No return value.
*/
ConsoleMethodWithDocs(Scene, add, ConsoleVoid, 3, 3, (sceneObject))
{
// Find the specified object.
SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
// Did we find the object?
if ( !pSceneObject )
{
// No, so warn.
Con::warnf("Scene::addToScene() - Could not find the specified object '%s'.", argv[2]);
return;
}
// Add to Scene.
object->addToScene( pSceneObject );
}
//-----------------------------------------------------------------------------
/*! Remove the SceneObject from the scene.
@param sceneObject The SceneObject to remove from the scene.
@return No return value.
*/
ConsoleMethodWithDocs(Scene, remove, ConsoleVoid, 3, 3, (sceneObject))
{
// Find the specified object.
SceneObject* pSceneObject = dynamic_cast<SceneObject*>(Sim::findObject(argv[2]));
// Did we find the object?
if ( !pSceneObject )
{
// No, so warn.
Con::warnf("Scene::removeFromScene() - Could not find the specified object '%s'.", argv[2]);
return;
}
// Remove from Scene.
object->removeFromScene( pSceneObject );
}
//-----------------------------------------------------------------------------
/*! Clear the scene of all scene objects.
@param deleteObjects A boolean flag that sets whether to delete the objects as well as remove them from the scene (default is true).
@return No return value.
*/
ConsoleMethodWithDocs(Scene, clear, ConsoleVoid, 2, 3, ([deleteObjects]))
{
// Calculate 'Delete Objects' flag.
bool deleteObjects;
if ( argc >= 3 )
deleteObjects = dAtob( argv[2] );
else
deleteObjects = true;
// Clear Scene.
object->clearScene( deleteObjects );
}
//-----------------------------------------------------------------------------
/*! Gets the count of scene objects in the scnee.
@return Returns the number of scene objects in current scene as an integer.
*/
ConsoleMethodWithDocs(Scene, getCount, ConsoleInt, 2, 2, ())
{
// Get Scene Object-Count.
return object->getSceneObjectCount();
}
//-----------------------------------------------------------------------------
/*! Gets the scene object at the selected index.
@param sceneObjectIndex The index of the desired object
@return The scene object at the specified index.
*/
ConsoleMethodWithDocs(Scene, getObject, ConsoleInt, 3, 3, (sceneObjectIndex))
{
// Fetch Object Index.
const U32 objectIndex = dAtoi(argv[2]);
// Fetch scene object count.
const U32 sceneObjectCount = object->getSceneObjectCount();
// Sanity!
if ( objectIndex >= sceneObjectCount )
{
// Error so warn.
Con::warnf("Scene::getObject() - Cannot retrieve specified object index (%d) as there are only (%d) object(s) in the scene!", objectIndex, sceneObjectCount );
// Return no object.
return 0;
}
// Fetch Scene Object.
const SceneObject* pSceneObject = object->getSceneObject( objectIndex );
// Check Object.
if ( pSceneObject != NULL )
{
// No error so return object id.
return pSceneObject->getId();
}
else
{
// Error so warn.
Con::warnf("Scene::getObject() - Cannot retrieve specified object index (%d)!", objectIndex);
// Return no object.
return 0;
}
}
//-----------------------------------------------------------------------------
/*! Gets the Scene Object-List.
@return Returns a string with a list of object IDs
*/
ConsoleMethodWithDocs(Scene, getSceneObjectList, ConsoleString, 2, 2, ())
{
// Scene Object-List.
Vector<SceneObject*> objList;
// Finish here if there are no scene objects.
U32 objCount = object->getSceneObjects( objList );
if( objCount == 0 )
return NULL;
// Our return buffer will be 6 times the size of our object list (4 for Id (+1 for future size?) + 1 for space).
U32 maxBufferSize = objCount * 12;
// Create Returnable Buffer.
char *pBuffer = Con::getReturnBuffer( maxBufferSize );
// Set Buffer Counter.
U32 bufferCount = 0;
// Iterate through the list and generate an id string list to return
for ( S32 n = 0; n < objList.size(); n++ )
{
// Output Object ID.
bufferCount += dSprintf( pBuffer + bufferCount, maxBufferSize-bufferCount, "%d ", objList[n]->getId() );
// Finish early if we run out of buffer space.
if ( bufferCount >= maxBufferSize )
{
// Warn.
Con::warnf("Scene::getSceneObjectList() - Not enough space to return all %d objects!", objList.size());
break;
}
}
// Return buffer.
return pBuffer;
}
//-----------------------------------------------------------------------------
/*! Gets the number of assets set to preload for this scene.
@return The number of assets set to preload for this scene.
*/
ConsoleMethodWithDocs(Scene, getAssetPreloadCount, ConsoleInt, 2, 2, ())
{
return object->getAssetPreloadCount();
}
//-----------------------------------------------------------------------------
/*! Gets the asset to be preloaded at the specified index.
@param index The index of the preloaded asset.
@return The asset to be preloaded at the specified index.
*/
ConsoleMethodWithDocs(Scene, getAssetPreload, ConsoleString, 3, 3, (index))
{
// Fetch preload index.
const S32 index = dAtoi(argv[2]);
// Fetch the asset pointer.
const AssetPtr<AssetBase>* pAssetPtr = object->getAssetPreload( index );
return pAssetPtr == NULL ? NULL : pAssetPtr->getAssetId();
}
//-----------------------------------------------------------------------------
/*! Adds the asset Id so that it is preloaded when the scene is loaded.
The asset loaded immediately by this operation. Duplicate assets are ignored.
@param assetId The asset Id to be added.
@return No return value.
*/
ConsoleMethodWithDocs(Scene, addAssetPreload, ConsoleVoid, 3, 3, (assetId))
{
// Fetch asset Id.
const char* pAssetId = argv[2];
// Add asset preload.
object->addAssetPreload( pAssetId );
}
//-----------------------------------------------------------------------------
/*! Removes the asset Id from being preloaded when the scene is loaded.
The asset may be unloaded immediately by this operation if it has no other references.
@param assetId The asset Id to be removed.
@return No return value.
*/
ConsoleMethodWithDocs(Scene, removeAssetPreload, ConsoleVoid, 3, 3, (assetId))
{
// Fetch asset Id.
const char* pAssetId = argv[2];
// Remove asset preload.
object->removeAssetPreload( pAssetId );
}
//-----------------------------------------------------------------------------
/*! Clears all assets added as a preload.
@return No return value.
*/
ConsoleMethodWithDocs(Scene, clearAssetPreloads, ConsoleVoid, 2, 2, ())
{
// Clear asset preloads.
object->clearAssetPreloads();
}
//-----------------------------------------------------------------------------
/*! Merges the specified scene into this scene by cloning the scenes contents.
*/
ConsoleMethodWithDocs(Scene, mergeScene, ConsoleVoid, 3, 3, (scene))
{
// Find the specified scene.
Scene* pScene = Sim::findObject<Scene>( argv[2] );
// Did we find the scene?
if ( pScene == NULL )
{
// No, so warn.
Con::warnf( "Scene::mergeScene() - Could not find the specified scene '%s'.", argv[2] );
return;
}
object->mergeScene( pScene );
}
//-----------------------------------------------------------------------------
/*! Gets the Scene Controllers.
@return Gets the scene controllers.
*/
ConsoleMethodWithDocs(Scene, getControllers, ConsoleString, 2, 2, ())
{
// Fetch the scene controllers.
SimSet* pControllerSet = object->getControllers();
return ( pControllerSet == NULL ) ? StringTable->EmptyString : pControllerSet->getIdString();
}
//-----------------------------------------------------------------------------
/*! Gets the Scene Time.
@return Returns the time as a floating point number
*/
ConsoleMethodWithDocs(Scene, getSceneTime, ConsoleFloat, 2, 2, ())
{
// Get Scene Time.
return object->getSceneTime();
}
//-----------------------------------------------------------------------------
/*! Sets scene pause status.
@return No return value.
*/
ConsoleMethodWithDocs(Scene, setScenePause, ConsoleVoid, 3, 3, (status))
{
// Set Scene Pause.
object->setScenePause( dAtob(argv[2]) );
}
//-----------------------------------------------------------------------------
/*! Gets scene pause status.
@return Returns a boolean value. True if pause status, false otherwise.
*/
ConsoleMethodWithDocs(Scene, getScenePause, ConsoleBool, 2, 2, ())
{
// Get Scene Pause.
return object->getScenePause();
}
//-----------------------------------------------------------------------------
/*! Gets the joint count.
@return Returns no value
*/
ConsoleMethodWithDocs(Scene, getJointCount, ConsoleInt, 2, 2, ())
{
return object->getJointCount();
}
//-----------------------------------------------------------------------------
/*! Gets whether the joint Id is valid or not.
@param jointId The Id of the joint.
@return whether the joint Id is valid or not.
*/
ConsoleMethodWithDocs(Scene, isJoint, ConsoleBool, 3, 3, (int jointId))
{
// Fetch joint Id.
const S32 jointId = dAtoi( argv[2] );
return object->findJoint( jointId ) != NULL;
}
//-----------------------------------------------------------------------------
/*! Gets the joint type of the specified joint Id.
@param jointId The Id of the joint.
@return The type of joint of the specified joint Id.
*/
ConsoleMethodWithDocs(Scene, getJointType, ConsoleString, 3, 3, (int jointId))
{
// Fetch joint Id.
const S32 jointId = dAtoi( argv[2] );
// Fetch joint type.
const b2JointType jointType = object->getJointType( jointId );
// Ignore if invalid joint.
if ( jointType == e_unknownJoint )
return StringTable->EmptyString;
return Scene::getJointTypeDescription( jointType );
}
//-----------------------------------------------------------------------------
/*! Deletes the specified joint Id.
@param jointId The Id of the joint.
@return Whether the joint was successfully deleted or not.
*/
ConsoleMethodWithDocs(Scene, deleteJoint, ConsoleBool, 3, 3, (int jointId))
{
// Fetch joint Id.
const S32 jointId = dAtoi( argv[2] );
return object->deleteJoint( jointId );
}
//-----------------------------------------------------------------------------
/*! Creates a distance joint.
@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
@param localAnchorA The local point of the first scene object where the joint connects.
@param localAnchorB The local point of the second scene object where the joint connects.
@param distance The distance the joint should maintain between scene objects. The default is the distance currently between the scene objects.
@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness (default).
@param dampingRatio The damping ratio. 0 = no damping (default), 1 = critical damping.
@param collideConnected Whether the scene objects can collide with each other while connected with this joint.
@return The joint Id (-1 if error).
*/
ConsoleMethodWithDocs(Scene, createDistanceJoint, ConsoleInt, 4, 12, (sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [distance], [frequency], [dampingRatio], [collideConnected]))
{
// Fetch scene object references.
const char* sceneObjectA = argv[2];
const char* sceneObjectB = argv[3];
SceneObject* pSceneObjectA = NULL;
SceneObject* pSceneObjectB = NULL;
// Fetch scene object.
if ( *sceneObjectA != 0 )
{
pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
if ( !pSceneObjectA )
Con::warnf("Scene::createDistanceJoint() - Could not find scene object %d.", sceneObjectA);
}
// Fetch scene object.
if (*sceneObjectB != 0 )
{
pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
if ( !pSceneObjectB )
Con::warnf("Scene::createDistanceJoint() - Could not find scene object %d.", sceneObjectB);
}
if ( argc == 4 )
{
return object->createDistanceJoint( pSceneObjectA, pSceneObjectB );
}
// Local anchor A.
const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
b2Vec2 localAnchorA;
S32 nextArg = 5;
if ( anchorAElementCount == 1 && argc > 5 )
{
localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
nextArg = 6;
}
else if ( anchorAElementCount == 2 )
{
localAnchorA = Utility::mGetStringElementVector(argv[4]);
}
// Invalid
else
{
Con::warnf("Scene::createDistanceJoint() - Invalid number of parameters!");
return -1;
}
if ( argc <= nextArg )
{
return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
}
// Local anchor B.
const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
b2Vec2 localAnchorB;
if ( anchorBElementCount == 1 && argc > (nextArg+1) )
{
localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
nextArg += 2;
}
else if ( anchorBElementCount == 2 )
{
localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
}
// Invalid
else
{
Con::warnf("Scene::createDistanceJoint() - Invalid number of parameters!");
return -1;
}
if ( argc <= nextArg )
{
return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
}
// Fetch length.
const F32 length = dAtof(argv[nextArg++]);
if ( argc <= nextArg )
{
return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length );
}
// Fetch frequency (Hertz).
const F32 frequency = dAtof(argv[nextArg++]);
if ( argc <= nextArg )
{
return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length, frequency );
}
// Fetch damping ratio.
const F32 dampingRatio = dAtof(argv[nextArg++]);
if ( argc <= nextArg )
{
return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length, frequency, dampingRatio );
}
// Fetch collide connected.
const bool collideConnected = dAtob(argv[nextArg++]);
return object->createDistanceJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, length, frequency, dampingRatio, collideConnected );
}
//-----------------------------------------------------------------------------
/*! Sets the distance the joint should maintain between scene objects.
@param jointId The Id of the joint to use.
@param length The length the joint should maintain between scene objects.
@return Returns no value.
*/
ConsoleMethodWithDocs(Scene, setDistanceJointLength, ConsoleVoid, 4, 4, (jointId, length))
{
// Fetch joint Id.
const S32 jointId = dAtoi(argv[2]);
// Fetch args.
const F32 length = dAtof(argv[3]);
// Access joint.
object->setDistanceJointLength( jointId, length );
}
//-----------------------------------------------------------------------------
/*! Gets the distance the joint should maintain between scene objects.
@param jointId The Id of the joint to use.
@return Returns the distance the joint should maintain between scene objects (-1 indicates error).
*/
ConsoleMethodWithDocs(Scene, getDistanceJointLength, ConsoleFloat, 3, 3, (jointId))
{
// Fetch joint Id.
const S32 jointId = dAtoi(argv[2]);
// Access joint.
return object->getDistanceJointLength( jointId );
}
//-----------------------------------------------------------------------------
/*! Sets the mass-spring-damper frequency in Hertz.
@param jointId The Id of the joint to use.
@param frequency The mass-spring-damper frequency in Hertz. A value of 0 disables softness.
@return Returns no value.
*/
ConsoleMethodWithDocs(Scene, setDistanceJointFrequency, ConsoleVoid, 4, 4, (jointId, frequency))
{
// Fetch joint Id.
const S32 jointId = dAtoi(argv[2]);
// Fetch args.
const F32 frequency = dAtof(argv[3]);
// Access joint.
object->setDistanceJointFrequency( jointId, frequency );
}
//-----------------------------------------------------------------------------
/*! Gets the mass-spring-damper frequency in Hertz.
@param jointId The Id of the joint to use.
@return Returns the mass-spring-damper frequency in Hertz (-1 indicates error).
*/
ConsoleMethodWithDocs(Scene, getDistanceJointFrequency, ConsoleFloat, 3, 3, (jointId))
{
// Fetch joint Id.
const S32 jointId = dAtoi(argv[2]);
// Access joint.
return object->getDistanceJointFrequency( jointId );
}
//-----------------------------------------------------------------------------
/*! Sets the damping ratio.
@param jointId The Id of the joint to use.
@param dampingRatio The damping ratio. 0 = no damping, 1 = critical damping.
@return Returns no value.
*/
ConsoleMethodWithDocs(Scene, setDistanceJointDampingRatio, ConsoleVoid, 4, 4, (jointId, dampingRatio))
{
// Fetch joint Id.
const S32 jointId = dAtoi(argv[2]);
// Fetch args.
const F32 dampingRatio = dAtof(argv[3]);
// Access joint.
object->setDistanceJointDampingRatio( jointId, dampingRatio );
}
//-----------------------------------------------------------------------------
/*! Gets the damping ratio.
@param jointId The Id of the joint to use.
@return Returns the damping ratio (-1 indicates error).
*/
ConsoleMethodWithDocs(Scene, getDistanceJointDampingRatio, ConsoleFloat, 3, 3, (jointId))
{
// Fetch joint Id.
const S32 jointId = dAtoi(argv[2]);
// Access joint.
return object->getDistanceJointDampingRatio( jointId );
}
//-----------------------------------------------------------------------------
/*! Creates a rope joint.
@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
@param localAnchorA The local point of the first scene object where the joint connects.
@param localAnchorB The local point of the second scene object where the joint connects.
@param maxLength The maximum rigid length of the rope.
@param collideConnected Whether the scene objects can collide with each other while connected with this joint.
@return The joint Id (-1 if error).
*/
ConsoleMethodWithDocs(Scene, createRopeJoint, ConsoleInt, 4, 10, (sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [maxLength], [collideConnected]))
{
// Fetch scene object references.
const char* sceneObjectA = argv[2];
const char* sceneObjectB = argv[3];
SceneObject* pSceneObjectA = NULL;
SceneObject* pSceneObjectB = NULL;
// Fetch scene object.
if ( *sceneObjectA != 0 )
{
pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
if ( !pSceneObjectA )
Con::warnf("Scene::createRopeJoint() - Could not find scene object %d.", sceneObjectA);
}
// Fetch scene object.
if (*sceneObjectB != 0 )
{
pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
if ( !pSceneObjectB )
Con::warnf("Scene::createRopeJoint() - Could not find scene object %d.", sceneObjectB);
}
if ( argc == 4 )
{
return object->createRopeJoint( pSceneObjectA, pSceneObjectB );
}
// Local anchor A.
const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
b2Vec2 localAnchorA;
S32 nextArg = 5;
if ( anchorAElementCount == 1 && argc > 5 )
{
localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
nextArg = 6;
}
else if ( anchorAElementCount == 2 )
{
localAnchorA = Utility::mGetStringElementVector(argv[4]);
}
// Invalid
else
{
Con::warnf("Scene::createRopeJoint() - Invalid number of parameters!");
return -1;
}
if ( argc <= nextArg )
{
return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
}
// Local anchor B.
const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
b2Vec2 localAnchorB;
if ( anchorBElementCount == 1 && argc > (nextArg+1) )
{
localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
nextArg += 2;
}
else if ( anchorBElementCount == 2 )
{
localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
}
// Invalid
else
{
Con::warnf("Scene::createRopeJoint() - Invalid number of parameters!");
return -1;
}
if ( argc <= nextArg )
{
return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
}
// Fetch maximum length.
const F32 maxLength = dAtof(argv[nextArg++]);
if ( argc <= nextArg )
{
return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxLength );
}
// Fetch collide connected.
const bool collideConnected = dAtob(argv[nextArg++]);
return object->createRopeJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, maxLength, collideConnected );
}
//-----------------------------------------------------------------------------
/*! Sets the maximum rigid length of the rope.
@param jointId The Id of the joint to use.
@param maxLength The maximum rigid length of the rope.
@return Returns no value.
*/
ConsoleMethodWithDocs(Scene, setRopeJointMaxLength, ConsoleVoid, 4, 4, (jointId, maxLength))
{
// Fetch joint Id.
const S32 jointId = dAtoi(argv[2]);
// Fetch args.
const F32 maxLength = dAtof(argv[3]);
// Access joint.
object->setRopeJointMaxLength( jointId, maxLength );
}
//-----------------------------------------------------------------------------
/*! Gets the maximum rigid length of the rope.
@param jointId The Id of the joint to use.
@return Returns the maximum rigid length of the rope (-1 indicates error).
*/
ConsoleMethodWithDocs(Scene, getRopeJointMaxLength, ConsoleFloat, 3, 3, (jointId))
{
// Fetch joint Id.
const S32 jointId = dAtoi(argv[2]);
// Access joint.
return object->getRopeJointMaxLength( jointId );
}
//-----------------------------------------------------------------------------
/*! Creates a revolute joint.
@param sceneObjectA The first scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
@param sceneObjectB The second scene object to connect to the joint. Use an empty string to indicate the Scene ground body.
@param localAnchorA The local point of the first scene object where the joint connects.
@param localAnchorB The local point of the second scene object where the joint connects.
@param collideConnected Whether the scene objects can collide with each other while connected with this joint.
@return The joint Id (-1 if error).
*/
ConsoleMethodWithDocs(Scene, createRevoluteJoint, ConsoleInt, 4, 9, (sceneObjectA, sceneObjectB, [localAnchorA X/Y], [localAnchorB X/Y], [collideConnected]))
{
// Fetch scene object references.
const char* sceneObjectA = argv[2];
const char* sceneObjectB = argv[3];
SceneObject* pSceneObjectA = NULL;
SceneObject* pSceneObjectB = NULL;
// Fetch scene object.
if ( *sceneObjectA != 0 )
{
pSceneObjectA = Sim::findObject<SceneObject>(sceneObjectA);
if ( !pSceneObjectA )
Con::warnf("Scene::createRevoluteJoint() - Could not find scene object %d.", sceneObjectA);
}
// Fetch scene object.
if ( *sceneObjectB != 0 )
{
pSceneObjectB = Sim::findObject<SceneObject>(sceneObjectB);
if ( !pSceneObjectB )
Con::warnf("Scene::createRevoluteJoint() - Could not find scene object %d.", sceneObjectB);
}
if ( argc == 4 )
{
return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB );
}
// Local anchor A.
const U32 anchorAElementCount = Utility::mGetStringElementCount(argv[4]);
b2Vec2 localAnchorA;
S32 nextArg = 5;
if ( anchorAElementCount == 1 && argc > 5 )
{
localAnchorA.Set( dAtof(argv[4]), dAtof(argv[5]) );
nextArg = 6;
}
else if ( anchorAElementCount == 2 )
{
localAnchorA = Utility::mGetStringElementVector(argv[4]);
}
// Invalid
else
{
Con::warnf("Scene::createRevoluteJoint() - Invalid number of parameters!");
return -1;
}
if ( argc <= nextArg )
{
return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB, localAnchorA );
}
// Local anchor B.
const U32 anchorBElementCount = Utility::mGetStringElementCount(argv[nextArg]);
b2Vec2 localAnchorB;
if ( anchorBElementCount == 1 && argc > (nextArg+1) )
{
localAnchorB.Set( dAtof(argv[nextArg]), dAtof(argv[nextArg+1]) );
nextArg += 2;
}
else if ( anchorBElementCount == 2 )
{
localAnchorB = Utility::mGetStringElementVector(argv[nextArg++]);
}
// Invalid
else
{
Con::warnf("Scene::createRevoluteJoint() - Invalid number of parameters!");
return -1;
}
if ( argc <= nextArg )
{
return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB );
}
// Fetch collide connected.
const bool collideConnected = dAtob(argv[nextArg++]);
return object->createRevoluteJoint( pSceneObjectA, pSceneObjectB, localAnchorA, localAnchorB, collideConnected );
}
//-----------------------------------------------------------------------------
/*! Sets whether the joint has angular limits or not and the limits themselves.
@param jointId The Id of the joint to use.
@param enableLimit Whether the joint has angular limits or not.
@param lowerAngle The lower angle of the angular limit.
@param upperAngle The upper angle of the angular limit.
@return Returns no value.
*/
ConsoleMethodWithDocs(Scene, setRevoluteJointLimit, ConsoleVoid, 4, 6, (jointId, enableLimit, [lowerAngle], [upperAngle]))
{
// Fetch joint Id.
const S32 jointId = dAtoi(argv[2]);
// Fetch args.
const bool enableLimit = dAtob(argv[3]);
const F32 lowerAngle = argc > 4 ? mDegToRad( dAtof(argv[4]) ) : 0.0f;
const F32 upperAngle = argc > 5 ? mDegToRad( dAtof(argv[5]) ) : lowerAngle;
// Access joint.
object->setRevoluteJointLimit( jointId, enableLimit, lowerAngle, upperAngle );
}
//-----------------------------------------------------------------------------
/*! Gets whether the joint has angular limits or not and the limits themselves.
@param jointId The Id of the joint to use.
@return Returns whether the joint has angular limits or not and the limits themselves (empty string indicates error).
*/
ConsoleMethodWithDocs(Scene, getRevoluteJointLimit, ConsoleString, 3, 3, (jointId))
{
// Fetch joint Id.
const S32 jointId = dAtoi(argv[2]);
// Args.
bool enableLimit;
F32 lowerAngle;
F32 upperAngle;
// Access joint.
if ( !object->getRevoluteJointLimit( jointId, enableLimit, lowerAngle, upperAngle ) )
{
return NULL;
}
// Format output.
char* pBuffer = Con::getReturnBuffer(64);
dSprintf( pBuffer, 64, "%d %g %g", enableLimit, mRadToDeg(lowerAngle), mRadToDeg(upperAngle) );
return pBuffer;
}