-
Notifications
You must be signed in to change notification settings - Fork 15
/
joint.go
1303 lines (1084 loc) · 36.6 KB
/
joint.go
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
package ode
// #include <ode/ode.h>
import "C"
import (
"unsafe"
)
// Joint types
const (
BallJointType = C.dJointTypeBall
HingeJointType = C.dJointTypeHinge
SliderJointType = C.dJointTypeSlider
ContactJointType = C.dJointTypeContact
UniversalJointType = C.dJointTypeUniversal
Hinge2JointType = C.dJointTypeHinge2
FixedJointType = C.dJointTypeFixed
NullJointType = C.dJointTypeNull
AMotorJointType = C.dJointTypeAMotor
LMotorJointType = C.dJointTypeLMotor
Plane2DJointType = C.dJointTypePlane2D
PRJointType = C.dJointTypePR
PUJointType = C.dJointTypePU
PistonJointType = C.dJointTypePiston
DBallJointType = C.dJointTypeDBall
DHingeJointType = C.dJointTypeDHinge
TransmissionJointType = C.dJointTypeTransmission
)
// Joint parameters
const (
LoStopJtParam = C.dParamLoStop
HiStopJtParam = C.dParamHiStop
VelJtParam = C.dParamVel
LoVelJtParam = C.dParamLoVel
HiVelJtParam = C.dParamHiVel
FMaxJtParam = C.dParamFMax
FudgeFactorJtParam = C.dParamFudgeFactor
BounceJtParam = C.dParamBounce
CFMJtParam = C.dParamCFM
StopERPJtParam = C.dParamStopERP
StopCFMJtParam = C.dParamStopCFM
SuspensionERPJtParam = C.dParamSuspensionERP
SuspensionCFMJtParam = C.dParamSuspensionCFM
ERPJtParam = C.dParamERP
NumJtParams = C.dParamsInGroup
JtParamGroup1 = C.dParamGroup1
LoStopJtParam1 = C.dParamLoStop1
HiStopJtParam1 = C.dParamHiStop1
VelJtParam1 = C.dParamVel1
LoVelJtParam1 = C.dParamLoVel1
HiVelJtParam1 = C.dParamHiVel1
FMaxJtParam1 = C.dParamFMax1
FudgeFactorJtParam1 = C.dParamFudgeFactor1
BounceJtParam1 = C.dParamBounce1
CFMJtParam1 = C.dParamCFM1
StopERPJtParam1 = C.dParamStopERP1
StopCFMJtParam1 = C.dParamStopCFM1
SuspensionERPJtParam1 = C.dParamSuspensionERP1
SuspensionCFMJtParam1 = C.dParamSuspensionCFM1
ERPJtParam1 = C.dParamERP1
JtParamGroup2 = C.dParamGroup2
LoStopJtParam2 = C.dParamLoStop2
HiStopJtParam2 = C.dParamHiStop2
VelJtParam2 = C.dParamVel2
LoVelJtParam2 = C.dParamLoVel2
HiVelJtParam2 = C.dParamHiVel2
FMaxJtParam2 = C.dParamFMax2
FudgeFactorJtParam2 = C.dParamFudgeFactor2
BounceJtParam2 = C.dParamBounce2
CFMJtParam2 = C.dParamCFM2
StopERPJtParam2 = C.dParamStopERP2
StopCFMJtParam2 = C.dParamStopCFM2
SuspensionERPJtParam2 = C.dParamSuspensionERP2
SuspensionCFMJtParam2 = C.dParamSuspensionCFM2
ERPJtParam2 = C.dParamERP2
JtParamGroup3 = C.dParamGroup3
LoStopJtParam3 = C.dParamLoStop3
HiStopJtParam3 = C.dParamHiStop3
VelJtParam3 = C.dParamVel3
LoVelJtParam3 = C.dParamLoVel3
HiVelJtParam3 = C.dParamHiVel3
FMaxJtParam3 = C.dParamFMax3
FudgeFactorJtParam3 = C.dParamFudgeFactor3
BounceJtParam3 = C.dParamBounce3
CFMJtParam3 = C.dParamCFM3
StopERPJtParam3 = C.dParamStopERP3
StopCFMJtParam3 = C.dParamStopCFM3
SuspensionERPJtParam3 = C.dParamSuspensionERP3
SuspensionCFMJtParam3 = C.dParamSuspensionCFM3
ERPJtParam3 = C.dParamERP3
)
// Angular motor parameters
const (
AMotorUser = C.dAMotorUser
AMotorEuler = C.dAMotorEuler
)
// Transmission parameters
const (
TransmissionParallelAxes = C.dTransmissionParallelAxes
TransmissionIntersectingAxes = C.dTransmissionIntersectingAxes
TransmissionChainDrive = C.dTransmissionChainDrive
)
var (
jointData = map[Joint]interface{}{}
)
// JointFeedback represents feedback forces and torques associated with a
// joint.
type JointFeedback struct {
Force1 Vector3 // force applied to body 1
Torque1 Vector3 // torque applied to body 1
Force2 Vector3 // force applied to body 2
Torque2 Vector3 // torque applied to body 2
}
func (f *JointFeedback) fromC(c *C.dJointFeedback) {
Vector(f.Force1).fromC(&c.f1[0])
Vector(f.Torque1).fromC(&c.t1[0])
Vector(f.Force2).fromC(&c.f2[0])
Vector(f.Torque2).fromC(&c.t2[0])
}
func (f *JointFeedback) toC(c *C.dJointFeedback) {
Vector(f.Force1).toC((*C.dReal)(&c.f1[0]))
Vector(f.Torque1).toC((*C.dReal)(&c.t1[0]))
Vector(f.Force2).toC((*C.dReal)(&c.f2[0]))
Vector(f.Torque2).toC((*C.dReal)(&c.t2[0]))
}
// JointGroup represents a group of joints.
type JointGroup uintptr
// NewJointGroup returns a new JointGroup instance.
func NewJointGroup(maxJoints int) JointGroup {
return cToJointGroup(C.dJointGroupCreate(C.int(maxJoints)))
}
func cToJointGroup(c C.dJointGroupID) JointGroup {
return JointGroup(unsafe.Pointer(c))
}
func (g JointGroup) c() C.dJointGroupID {
return C.dJointGroupID(unsafe.Pointer(g))
}
// Destroy destroys the joint group.
func (g JointGroup) Destroy() {
C.dJointGroupDestroy(g.c())
}
// Empty removes all joints from the group.
func (g JointGroup) Empty() {
C.dJointGroupEmpty(g.c())
}
// Joint represents a joint.
type Joint interface {
c() C.dJointID
Destroy()
SetData(data interface{})
Data() interface{}
NumBodies() int
Attach(body1, body2 Body)
SetEnabled(isEnabled bool)
Enabled() bool
Type() int
Body(index int) Body
SetFeedback(f *JointFeedback)
Feedback() *JointFeedback
}
// JointBase implements Joint, and is embedded by specific Joint types.
type JointBase uintptr
func cToJoint(c C.dJointID) Joint {
base := JointBase(unsafe.Pointer(c))
var j Joint
switch int(C.dJointGetType(c)) {
case BallJointType:
j = BallJoint{base}
case HingeJointType:
j = HingeJoint{base}
case SliderJointType:
j = SliderJoint{base}
case ContactJointType:
j = ContactJoint{base}
case UniversalJointType:
j = UniversalJoint{base}
case Hinge2JointType:
j = Hinge2Joint{base}
case FixedJointType:
j = FixedJoint{base}
case NullJointType:
j = NullJoint{base}
case AMotorJointType:
j = AMotorJoint{base}
case LMotorJointType:
j = LMotorJoint{base}
case Plane2DJointType:
j = Plane2DJoint{base}
case PRJointType:
j = PRJoint{base}
case PUJointType:
j = PUJoint{base}
case PistonJointType:
j = PistonJoint{base}
case DBallJointType:
j = DBallJoint{base}
case DHingeJointType:
j = DHingeJoint{base}
case TransmissionJointType:
j = TransmissionJoint{base}
default:
j = base
}
return j
}
func (j JointBase) c() C.dJointID {
return C.dJointID(unsafe.Pointer(j))
}
// Destroy destroys the joint base.
func (j JointBase) Destroy() {
delete(jointData, j)
C.dJointDestroy(j.c())
}
// SetData associates user-specified data with the joint.
func (j JointBase) SetData(data interface{}) {
jointData[j] = data
}
// Data returns the user-specified data associated with the joint.
func (j JointBase) Data() interface{} {
return jointData[j]
}
// NumBodies returns the number of attached bodies.
func (j JointBase) NumBodies() int {
return int(C.dJointGetNumBodies(j.c()))
}
// Attach attaches two bodies with the joint.
func (j JointBase) Attach(body1, body2 Body) {
C.dJointAttach(j.c(), body1.c(), body2.c())
}
// SetEnabled sets whether the joint is enabled.
func (j JointBase) SetEnabled(isEnabled bool) {
if isEnabled {
C.dJointEnable(j.c())
} else {
C.dJointDisable(j.c())
}
}
// Enabled returns whether the joint is enabled.
func (j JointBase) Enabled() bool {
return bool(C.dJointIsEnabled(j.c()) != 0)
}
// Type returns the joint type.
func (j JointBase) Type() int {
return int(C.dJointGetType(j.c()))
}
// Body returns the attached body, specified by index.
func (j JointBase) Body(index int) Body {
return cToBody(C.dJointGetBody(j.c(), C.int(index)))
}
// SetFeedback sets the feedback forces and torques.
func (j JointBase) SetFeedback(f *JointFeedback) {
c := &C.dJointFeedback{}
f.toC(c)
C.dJointSetFeedback(j.c(), c)
}
// Feedback returns the feedback forces and torques.
func (j JointBase) Feedback() *JointFeedback {
f := &JointFeedback{}
f.fromC(C.dJointGetFeedback(j.c()))
return f
}
// BallJoint implements a ball-and-socket joint.
type BallJoint struct {
JointBase
}
// SetParam sets a joint parameter.
func (j BallJoint) SetParam(parameter int, value float64) {
C.dJointSetBallParam(j.c(), C.int(parameter), C.dReal(value))
}
// Param returns a joint parameter.
func (j BallJoint) Param(parameter int) float64 {
return float64(C.dJointGetBallParam(j.c(), C.int(parameter)))
}
// SetAnchor sets the anchor point for the first body.
func (j BallJoint) SetAnchor(pt Vector3) {
C.dJointSetBallAnchor(j.c(), C.dReal(pt[0]), C.dReal(pt[1]), C.dReal(pt[2]))
}
// Anchor returns the anchor point for the first body.
func (j BallJoint) Anchor() Vector3 {
pt := NewVector3()
C.dJointGetBallAnchor(j.c(), (*C.dReal)(&pt[0]))
return pt
}
// SetAnchor2 sets the anchor point for the second body.
func (j BallJoint) SetAnchor2(pt Vector3) {
C.dJointSetBallAnchor2(j.c(), C.dReal(pt[0]), C.dReal(pt[1]), C.dReal(pt[2]))
}
// Anchor2 returns the anchor point for the second body.
func (j BallJoint) Anchor2() Vector3 {
pt := NewVector3()
C.dJointGetBallAnchor2(j.c(), (*C.dReal)(&pt[0]))
return pt
}
// HingeJoint represents a hinge joint.
type HingeJoint struct {
JointBase
}
// SetParam sets a joint parameter.
func (j HingeJoint) SetParam(parameter int, value float64) {
C.dJointSetHingeParam(j.c(), C.int(parameter), C.dReal(value))
}
// Param returns a joint parameter.
func (j HingeJoint) Param(parameter int) float64 {
return float64(C.dJointGetHingeParam(j.c(), C.int(parameter)))
}
// SetAnchor sets the anchor point.
func (j HingeJoint) SetAnchor(pt Vector3) {
C.dJointSetHingeAnchor(j.c(), C.dReal(pt[0]), C.dReal(pt[1]), C.dReal(pt[2]))
}
// SetAnchorDelta sets the hinge anchor delta.
func (j HingeJoint) SetAnchorDelta(pt, delta Vector3) {
C.dJointSetHingeAnchorDelta(j.c(), C.dReal(pt[0]), C.dReal(pt[1]), C.dReal(pt[2]),
C.dReal(delta[0]), C.dReal(delta[1]), C.dReal(delta[2]))
}
// Anchor returns the anchor point for the first body.
func (j HingeJoint) Anchor() Vector3 {
pt := NewVector3()
C.dJointGetHingeAnchor(j.c(), (*C.dReal)(&pt[0]))
return pt
}
// Anchor2 returns the anchor point for the second body.
func (j HingeJoint) Anchor2() Vector3 {
pt := NewVector3()
C.dJointGetHingeAnchor2(j.c(), (*C.dReal)(&pt[0]))
return pt
}
// SetAxis sets the hinge axis.
func (j HingeJoint) SetAxis(axis Vector3) {
C.dJointSetHingeAxis(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// SetAxisOffset set the hinge axis as if the 2 bodies were already at angle appart.
func (j HingeJoint) SetAxisOffset(axis Vector3, angle float64) {
C.dJointSetHingeAxisOffset(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]),
C.dReal(angle))
}
// Axis returns the hinge axis.
func (j HingeJoint) Axis() Vector3 {
axis := NewVector3()
C.dJointGetHingeAxis(j.c(), (*C.dReal)(&axis[0]))
return axis
}
// AddTorque adds a torque to the joint.
func (j HingeJoint) AddTorque(torque float64) {
C.dJointAddHingeTorque(j.c(), C.dReal(torque))
}
// Angle returns the joint angle.
func (j HingeJoint) Angle() float64 {
return float64(C.dJointGetHingeAngle(j.c()))
}
// AngleRate returns the joint angle's rate of change.
func (j HingeJoint) AngleRate() float64 {
return float64(C.dJointGetHingeAngleRate(j.c()))
}
// SliderJoint represents a slider joints.
type SliderJoint struct {
JointBase
}
// SetParam sets a joint parameter.
func (j SliderJoint) SetParam(parameter int, value float64) {
C.dJointSetSliderParam(j.c(), C.int(parameter), C.dReal(value))
}
// Param returns a joint parameter.
func (j SliderJoint) Param(parameter int) float64 {
return float64(C.dJointGetSliderParam(j.c(), C.int(parameter)))
}
// Position returns the slider position.
func (j SliderJoint) Position() float64 {
return float64(C.dJointGetSliderPosition(j.c()))
}
// PositionRate returns the slider position's rate of change.
func (j SliderJoint) PositionRate() float64 {
return float64(C.dJointGetSliderPositionRate(j.c()))
}
// SetAxis sets the slider axis.
func (j SliderJoint) SetAxis(axis Vector3) {
C.dJointSetSliderAxis(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// SetAxisDelta sets the slider axis delta.
func (j SliderJoint) SetAxisDelta(pt, delta Vector3) {
C.dJointSetSliderAxisDelta(j.c(), C.dReal(pt[0]), C.dReal(pt[1]), C.dReal(pt[2]),
C.dReal(delta[0]), C.dReal(delta[1]), C.dReal(delta[2]))
}
// Axis returns the slider axis.
func (j SliderJoint) Axis() Vector3 {
axis := NewVector3()
C.dJointGetSliderAxis(j.c(), (*C.dReal)(&axis[0]))
return axis
}
// AddForce adds a force to the joint.
func (j SliderJoint) AddForce(force float64) {
C.dJointAddSliderForce(j.c(), C.dReal(force))
}
// ContactJoint represents a contact joint.
type ContactJoint struct {
JointBase
}
// UniversalJoint represents a universal joint.
type UniversalJoint struct {
JointBase
}
// SetParam sets a joint parameter.
func (j UniversalJoint) SetParam(parameter int, value float64) {
C.dJointSetUniversalParam(j.c(), C.int(parameter), C.dReal(value))
}
// Param returns a joint parameter.
func (j UniversalJoint) Param(parameter int) float64 {
return float64(C.dJointGetUniversalParam(j.c(), C.int(parameter)))
}
// SetAnchor sets the anchor point.
func (j UniversalJoint) SetAnchor(pt Vector3) {
C.dJointSetUniversalAnchor(j.c(), C.dReal(pt[0]), C.dReal(pt[1]), C.dReal(pt[2]))
}
// Anchor returns the anchor point for the first body.
func (j UniversalJoint) Anchor() Vector3 {
pt := NewVector3()
C.dJointGetUniversalAnchor(j.c(), (*C.dReal)(&pt[0]))
return pt
}
// Anchor2 returns the anchor point for the second body.
func (j UniversalJoint) Anchor2() Vector3 {
pt := NewVector3()
C.dJointGetUniversalAnchor2(j.c(), (*C.dReal)(&pt[0]))
return pt
}
// SetAxis1 sets the first axis.
func (j UniversalJoint) SetAxis1(axis Vector3) {
C.dJointSetUniversalAxis1(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// SetAxis1Offset sets the first axis as if the 2 bodies were already at
// offset1 and offset2 appart with respect to the first and second axes.
func (j UniversalJoint) SetAxis1Offset(axis Vector3, offset1, offset2 float64) {
C.dJointSetUniversalAxis1Offset(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]),
C.dReal(offset1), C.dReal(offset2))
}
// Axis1 returns the first axis.
func (j UniversalJoint) Axis1() Vector3 {
axis := NewVector3()
C.dJointGetUniversalAxis1(j.c(), (*C.dReal)(&axis[0]))
return axis
}
// SetAxis2 sets the second axis.
func (j UniversalJoint) SetAxis2(axis Vector3) {
C.dJointSetUniversalAxis2(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// SetAxis2Offset sets the second axis as if the 2 bodies were already at
// offset1 and offset2 appart with respect to the first and second axes.
func (j UniversalJoint) SetAxis2Offset(axis Vector3, offset1, offset2 float64) {
C.dJointSetUniversalAxis2Offset(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]),
C.dReal(offset1), C.dReal(offset1))
}
// Axis2 returns the second axis.
func (j UniversalJoint) Axis2() Vector3 {
axis := NewVector3()
C.dJointGetUniversalAxis2(j.c(), (*C.dReal)(&axis[0]))
return axis
}
// Angle1 returns the first angle.
func (j UniversalJoint) Angle1() float64 {
return float64(C.dJointGetUniversalAngle1(j.c()))
}
// Angle1Rate returns the first angle's rate of change.
func (j UniversalJoint) Angle1Rate() float64 {
return float64(C.dJointGetUniversalAngle1Rate(j.c()))
}
// Angle2 returns the second angle.
func (j UniversalJoint) Angle2() float64 {
return float64(C.dJointGetUniversalAngle2(j.c()))
}
// Angle2Rate returns the second angle's rate of change.
func (j UniversalJoint) Angle2Rate() float64 {
return float64(C.dJointGetUniversalAngle2Rate(j.c()))
}
// Angles returns the two angles.
func (j UniversalJoint) Angles() (float64, float64) {
var angle1, angle2 float64
C.dJointGetUniversalAngles(j.c(), (*C.dReal)(&angle1), (*C.dReal)(&angle2))
return angle1, angle2
}
// AddTorques adds torques to the joint.
func (j UniversalJoint) AddTorques(torque1, torque2 float64) {
C.dJointAddUniversalTorques(j.c(), C.dReal(torque1), C.dReal(torque2))
}
// Hinge2Joint represents two hinge joints in series.
type Hinge2Joint struct {
JointBase
}
// SetParam sets a joint parameter.
func (j Hinge2Joint) SetParam(parameter int, value float64) {
C.dJointSetHinge2Param(j.c(), C.int(parameter), C.dReal(value))
}
// Param returns a joint parameter.
func (j Hinge2Joint) Param(parameter int) float64 {
return float64(C.dJointGetHinge2Param(j.c(), C.int(parameter)))
}
// SetAnchor sets the anchor point.
func (j Hinge2Joint) SetAnchor(pt Vector3) {
C.dJointSetHinge2Anchor(j.c(), C.dReal(pt[0]), C.dReal(pt[1]), C.dReal(pt[2]))
}
// Anchor returns the anchor point for the first body.
func (j Hinge2Joint) Anchor() Vector3 {
pt := NewVector3()
C.dJointGetHinge2Anchor(j.c(), (*C.dReal)(&pt[0]))
return pt
}
// Anchor2 returns the anchor point for the second body.
func (j Hinge2Joint) Anchor2() Vector3 {
pt := NewVector3()
C.dJointGetHinge2Anchor2(j.c(), (*C.dReal)(&pt[0]))
return pt
}
// SetAxis1 sets the first axis.
func (j Hinge2Joint) SetAxis1(axis Vector3) {
C.dJointSetHinge2Axis1(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// Axis1 returns the first axis.
func (j Hinge2Joint) Axis1() Vector3 {
axis := NewVector3()
C.dJointGetHinge2Axis1(j.c(), (*C.dReal)(&axis[0]))
return axis
}
// SetAxis2 sets the second axis.
func (j Hinge2Joint) SetAxis2(axis Vector3) {
C.dJointSetHinge2Axis2(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// Axis2 returns the second axis.
func (j Hinge2Joint) Axis2() Vector3 {
axis := NewVector3()
C.dJointGetHinge2Axis2(j.c(), (*C.dReal)(&axis[0]))
return axis
}
// Angle1 returns the first angle.
func (j Hinge2Joint) Angle1() float64 {
return float64(C.dJointGetHinge2Angle1(j.c()))
}
// Angle1Rate returns the first angle's rate of change.
func (j Hinge2Joint) Angle1Rate() float64 {
return float64(C.dJointGetHinge2Angle1Rate(j.c()))
}
// Angle2 returns the second angle.
func (j Hinge2Joint) Angle2() float64 {
return float64(C.dJointGetHinge2Angle2(j.c()))
}
// Angle2Rate returns the second angle's rate of change.
func (j Hinge2Joint) Angle2Rate() float64 {
return float64(C.dJointGetHinge2Angle2Rate(j.c()))
}
// AddTorques adds torques to the joint.
func (j Hinge2Joint) AddTorques(torque1, torque2 float64) {
C.dJointAddHinge2Torques(j.c(), C.dReal(torque1), C.dReal(torque2))
}
// FixedJoint represents a fixed joint.
type FixedJoint struct {
JointBase
}
// SetParam sets a joint parameter.
func (j FixedJoint) SetParam(parameter int, value float64) {
C.dJointSetFixedParam(j.c(), C.int(parameter), C.dReal(value))
}
// Param returns a joint parameter.
func (j FixedJoint) Param(parameter int) float64 {
return float64(C.dJointGetFixedParam(j.c(), C.int(parameter)))
}
// Fix fixes the joint in its current state.
func (j FixedJoint) Fix() {
C.dJointSetFixed(j.c())
}
// NullJoint represents a null joint.
type NullJoint struct {
JointBase
}
// AMotorJoint represents an angular motor joint.
type AMotorJoint struct {
JointBase
}
// SetParam sets a joint parameter.
func (j AMotorJoint) SetParam(parameter int, value float64) {
C.dJointSetAMotorParam(j.c(), C.int(parameter), C.dReal(value))
}
// Param returns a joint parameter.
func (j AMotorJoint) Param(parameter int) float64 {
return float64(C.dJointGetAMotorParam(j.c(), C.int(parameter)))
}
// SetNumAxes sets the number of axes.
func (j AMotorJoint) SetNumAxes(num int) {
C.dJointSetAMotorNumAxes(j.c(), C.int(num))
}
// NumAxes returns the number of axes.
func (j AMotorJoint) NumAxes() int {
return int(C.dJointGetAMotorNumAxes(j.c()))
}
// SetAxis sets the given axis relative to body rel (1 or 2) or none (0).
func (j AMotorJoint) SetAxis(num, rel int, axis Vector3) {
C.dJointSetAMotorAxis(j.c(), C.int(num), C.int(rel),
C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// Axis returns the given axis.
func (j AMotorJoint) Axis(num int) Vector3 {
axis := NewVector3()
C.dJointGetAMotorAxis(j.c(), C.int(num), (*C.dReal)(&axis[0]))
return axis
}
// AxisRel returns the relative mode for the given axis.
func (j AMotorJoint) AxisRel(num int) int {
return int(C.dJointGetAMotorAxisRel(j.c(), C.int(num)))
}
// SetAngle sets the angle of the given axis.
func (j AMotorJoint) SetAngle(num int, angle float64) {
C.dJointSetAMotorAngle(j.c(), C.int(num), C.dReal(angle))
}
// Angle returns the angle of the given axis.
func (j AMotorJoint) Angle(num int) float64 {
return float64(C.dJointGetAMotorAngle(j.c(), C.int(num)))
}
// AngleRate returns the angle's rate of change for the given axis.
func (j AMotorJoint) AngleRate(num int) float64 {
return float64(C.dJointGetAMotorAngleRate(j.c(), C.int(num)))
}
// SetMode sets the mode.
func (j AMotorJoint) SetMode(mode int) {
C.dJointSetAMotorMode(j.c(), C.int(mode))
}
// Mode returns the mode.
func (j AMotorJoint) Mode() int {
return int(C.dJointGetAMotorMode(j.c()))
}
// AddTorques adds torques to the joint.
func (j AMotorJoint) AddTorques(torque1, torque2, torque3 float64) {
C.dJointAddAMotorTorques(j.c(), C.dReal(torque1), C.dReal(torque2), C.dReal(torque3))
}
// LMotorJoint represents a linear motor joint.
type LMotorJoint struct {
JointBase
}
// SetParam sets a joint parameter.
func (j LMotorJoint) SetParam(parameter int, value float64) {
C.dJointSetLMotorParam(j.c(), C.int(parameter), C.dReal(value))
}
// Param returns a joint parameter.
func (j LMotorJoint) Param(parameter int) float64 {
return float64(C.dJointGetLMotorParam(j.c(), C.int(parameter)))
}
// SetNumAxes sets the number of axes.
func (j LMotorJoint) SetNumAxes(num int) {
C.dJointSetLMotorNumAxes(j.c(), C.int(num))
}
// NumAxes returns the number of axes.
func (j LMotorJoint) NumAxes() int {
return int(C.dJointGetLMotorNumAxes(j.c()))
}
// SetAxis sets the given axis relative to a body (1 or 2) or none (0).
func (j LMotorJoint) SetAxis(num, rel int, axis Vector3) {
C.dJointSetLMotorAxis(j.c(), C.int(num), C.int(rel),
C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// Axis returns the given axis.
func (j LMotorJoint) Axis(num int) Vector3 {
axis := NewVector3()
C.dJointGetLMotorAxis(j.c(), C.int(num), (*C.dReal)(&axis[0]))
return axis
}
// Plane2DJoint represents a plane joint.
type Plane2DJoint struct {
JointBase
}
// SetXParam sets a joint parameter.
func (j Plane2DJoint) SetXParam(parameter int, value float64) {
C.dJointSetPlane2DXParam(j.c(), C.int(parameter), C.dReal(value))
}
// SetYParam sets a joint parameter.
func (j Plane2DJoint) SetYParam(parameter int, value float64) {
C.dJointSetPlane2DYParam(j.c(), C.int(parameter), C.dReal(value))
}
// SetAngleParam sets a joint parameter.
func (j Plane2DJoint) SetAngleParam(parameter int, value float64) {
C.dJointSetPlane2DAngleParam(j.c(), C.int(parameter), C.dReal(value))
}
// PRJoint represents a prismatic rotoide joint.
type PRJoint struct {
JointBase
}
// SetParam sets a joint parameter.
func (j PRJoint) SetParam(parameter int, value float64) {
C.dJointSetPRParam(j.c(), C.int(parameter), C.dReal(value))
}
// Param returns a joint parameter.
func (j PRJoint) Param(parameter int) float64 {
return float64(C.dJointGetPRParam(j.c(), C.int(parameter)))
}
// SetAnchor sets the anchor point.
func (j PRJoint) SetAnchor(pt Vector3) {
C.dJointSetPRAnchor(j.c(), C.dReal(pt[0]), C.dReal(pt[1]), C.dReal(pt[2]))
}
// Anchor returns the anchor point.
func (j PRJoint) Anchor() Vector3 {
pt := NewVector3()
C.dJointGetPRAnchor(j.c(), (*C.dReal)(&pt[0]))
return pt
}
// SetAxis1 sets the first axis.
func (j PRJoint) SetAxis1(axis Vector3) {
C.dJointSetPRAxis1(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// Axis1 returns the first axis.
func (j PRJoint) Axis1() Vector3 {
axis := NewVector3()
C.dJointGetPRAxis1(j.c(), (*C.dReal)(&axis[0]))
return axis
}
// SetAxis2 sets the second axis.
func (j PRJoint) SetAxis2(axis Vector3) {
C.dJointSetPRAxis2(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// Axis2 returns the second axis.
func (j PRJoint) Axis2() Vector3 {
axis := NewVector3()
C.dJointGetPRAxis2(j.c(), (*C.dReal)(&axis[0]))
return axis
}
// Position returns the slider position.
func (j PRJoint) Position() float64 {
return float64(C.dJointGetPRPosition(j.c()))
}
// PositionRate returns the slider position's rate of change.
func (j PRJoint) PositionRate() float64 {
return float64(C.dJointGetPRPositionRate(j.c()))
}
// Angle returns the joint angle.
func (j PRJoint) Angle() float64 {
return float64(C.dJointGetPRAngle(j.c()))
}
// AngleRate returns the joint angle's rate of change.
func (j PRJoint) AngleRate() float64 {
return float64(C.dJointGetPRAngleRate(j.c()))
}
// AddTorque adds a torque to the joint.
func (j PRJoint) AddTorque(torque float64) {
C.dJointAddPRTorque(j.c(), C.dReal(torque))
}
// PUJoint represents a prismatic universal joint.
type PUJoint struct {
JointBase
}
// SetParam sets a joint parameter.
func (j PUJoint) SetParam(parameter int, value float64) {
C.dJointSetPUParam(j.c(), C.int(parameter), C.dReal(value))
}
// Param returns a joint parameter.
func (j PUJoint) Param(parameter int) float64 {
return float64(C.dJointGetPUParam(j.c(), C.int(parameter)))
}
// SetAnchor sets the anchor point.
func (j PUJoint) SetAnchor(pt Vector3) {
C.dJointSetPUAnchor(j.c(), C.dReal(pt[0]), C.dReal(pt[1]), C.dReal(pt[2]))
}
// Anchor returns the anchor point.
func (j PUJoint) Anchor() Vector3 {
pt := NewVector3()
C.dJointGetPUAnchor(j.c(), (*C.dReal)(&pt[0]))
return pt
}
// SetAnchorOffset sets the anchor as if the 2 bodies were already delta appart.
func (j PUJoint) SetAnchorOffset(pt, delta Vector3) {
C.dJointSetPUAnchorOffset(j.c(), C.dReal(pt[0]), C.dReal(pt[1]), C.dReal(pt[2]),
C.dReal(delta[0]), C.dReal(delta[1]), C.dReal(delta[2]))
}
// SetAxis1 sets the first axis.
func (j PUJoint) SetAxis1(axis Vector3) {
C.dJointSetPUAxis1(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// Axis1 returns the first axis.
func (j PUJoint) Axis1() Vector3 {
axis := NewVector3()
C.dJointGetPUAxis1(j.c(), (*C.dReal)(&axis[0]))
return axis
}
// SetAxis2 sets the second axis.
func (j PUJoint) SetAxis2(axis Vector3) {
C.dJointSetPUAxis2(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// Axis2 returns the second axis.
func (j PUJoint) Axis2() Vector3 {
axis := NewVector3()
C.dJointGetPUAxis2(j.c(), (*C.dReal)(&axis[0]))
return axis
}
// SetAxis3 sets the third (prismatic) axis.
func (j PUJoint) SetAxis3(axis Vector3) {
C.dJointSetPUAxis3(j.c(), C.dReal(axis[0]), C.dReal(axis[1]), C.dReal(axis[2]))
}
// Axis3 returns the third (prismatic) axis.
func (j PUJoint) Axis3() Vector3 {
axis := NewVector3()
C.dJointGetPUAxis3(j.c(), (*C.dReal)(&axis[0]))
return axis
}
// Position returns the joint position.
func (j PUJoint) Position() float64 {
return float64(C.dJointGetPUPosition(j.c()))
}
// PositionRate returns the joint position's rate of change.
func (j PUJoint) PositionRate() float64 {
return float64(C.dJointGetPUPositionRate(j.c()))
}
// Angle1 returns the first angle.
func (j PUJoint) Angle1() float64 {
return float64(C.dJointGetPUAngle1(j.c()))
}
// Angle1Rate returns the first angle's rate of change.
func (j PUJoint) Angle1Rate() float64 {
return float64(C.dJointGetPUAngle1Rate(j.c()))
}
// Angle2 returns the second angle.
func (j PUJoint) Angle2() float64 {
return float64(C.dJointGetPUAngle2(j.c()))
}
// Angle2Rate returns the second angle's rate of change.
func (j PUJoint) Angle2Rate() float64 {
return float64(C.dJointGetPUAngle2Rate(j.c()))
}
// Angles returns the two joint angles.
func (j PUJoint) Angles() (float64, float64) {
var angle1, angle2 float64
C.dJointGetPUAngles(j.c(), (*C.dReal)(&angle1), (*C.dReal)(&angle2))
return angle1, angle2
}
// PistonJoint represents a piston joint.
type PistonJoint struct {
JointBase
}
// SetParam sets a joint parameter.
func (j PistonJoint) SetParam(parameter int, value float64) {
C.dJointSetPistonParam(j.c(), C.int(parameter), C.dReal(value))
}
// Param returns a joint parameter.
func (j PistonJoint) Param(parameter int) float64 {
return float64(C.dJointGetPistonParam(j.c(), C.int(parameter)))
}