forked from P33a/SimTwo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathODEImport.pas
2399 lines (2087 loc) · 122 KB
/
ODEImport.pas
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
UNIT ODEImport;
(*************************************************************************
* *
* Open Dynamics Engine, Copyright (C) 2001,2020 Russell L. Smith. *
* All rights reserved. Web: www.ode.org *
* *
* This library is free software; you can redistribute it and/or *
* modify it under the terms of EITHER: *
* (1) The GNU Lesser General Public License as published by the Free *
* Software Foundation; either version 2.1 of the License, or (at *
* your option) any later version. The text of the GNU Lesser *
* General Public License is included with this library in the *
* file LICENSE.TXT. *
* (2) The BSD-style license that is included with this library in *
* the file LICENSE-BSD.TXT. *
* *
* This library is distributed in the hope that it will be useful, *
* but WITHOUT ANY WARRANTY; without even the implied warranty of *
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the files *
* LICENSE.TXT and LICENSE-BSD.TXT for more details. *
* *
*************************************************************************)
(*************************************************************************
Some notes;
Sometimes it's easier and faster to refer to the members of the objects
directly, like Body.Pos, Geom.Data or Body.Mass, instead of calling the built
in routines. Be very careful if you do this, because some of the built in
routines alter states when called.
Examples
bGeomSetBody(Geom, Body); // This method must be used so
Geom.Body := Body; // DON'T DO THIS
Setting the mass of a body is another example. Typically, reading members is
fine, but before writing directly to member fields yourself, you should check
the c source and see what the function/procedure does. The source can be found
at http://www.q12.org/ode/
*************************************************************************)
interface
// remove . from line below if you are using a generic ODE DLL
{$DEFINE VanillaODE}
{$IFNDEF VanillaODE}
{$DEFINE PARODE}
{$ENDIF}
uses
//System.Classes,
//Import.ModuleLoader;
Classes, ModuleLoader;
const
// ********************************************************************
//
// ODE precision:
//
// ODE can be run in Single or Double precision, Single is less precise,
// but requires less memory.
//
// If you choose to run in Single mode, you must deploy the single precision
// dll (this is default)
//
// If you choose to run in Double mode, you must deploy the double precision
// dll (named ode_double.dll and located in the dll directory)
{$define cSINGLE} //Insert . before "$" to make ODEImport double based
{$IFDEF WIN32}
{$IFDEF cSINGLE}
ODEDLL = 'ode32s.dll';
{$ELSE}
ODEDLL = 'ode32d.dll';
{$ENDIF}
{$ENDIF}
{$IFDEF WIN64}
{$IFDEF cSINGLE}
//ODEDLL = 'ode64s.dll';
ODEDLL = 'ode64s0162.dll';
{$ELSE}
ODEDLL = 'ode64d.dll';
{$ENDIF}
{$ENDIF}
{$IFDEF UNIX}
ODEDLL = 'libode.so';
{$ENDIF}
{$IFDEF MACOS}
ODEDLL = 'libode.dylib';
{$ENDIF}
{$IFDEF DARWIN} // MacOS X
ODEDLL = 'libode.dylib';
{$ENDIF}
const
// enum (* TRIMESH_FACE_NORMALS, TRIMESH_LAST_TRANSFORMATION ; *)
TRIMESH_FACE_NORMALS = 0;
TRIMESH_LAST_TRANSFORMATION = 1;
// Just generate any contacts (disables any contact refining).
CONTACTS_UNIMPORTANT = $80000000;
// Change: New Type added, syntax enforcement
type TJointFlag = Integer;
// These consts now have defined types
const
// if this flag is set, the joint was allocated in a joint group
dJOINT_INGROUP: TJointFlag = 1;
(* if this flag is set, the joint was attached with arguments (0,body).
our convention is to treat all attaches as (body,0), i.e. so node[0].body
is always nonzero, so this flag records the fact that the arguments were swapped *)
dJOINT_REVERSE: TJointFlag = 2;
(* if this flag is set, the joint can not have just one body attached to it,
it must have either zero or two bodies attached *)
dJOINT_TWOBODIES: TJointFlag = 4;
// Change: New Type added, syntax enforcement
type TdContactType = Integer;
// These consts now have defined types
const
dContactMu2: TdContactType = $0001;
dContactFDir1: TdContactType = $0002;
dContactBounce: TdContactType = $0004;
dContactSoftERP: TdContactType = $0008;
dContactSoftCFM: TdContactType = $0010;
dContactMotion1: TdContactType = $0020;
dContactMotion2: TdContactType = $0040;
dContactMotionN: TdContactType = $0080;
dContactSlip1: TdContactType = $0100;
dContactSlip2: TdContactType = $0200;
dContactApprox0: TdContactType = $0000;
dContactApprox1_1: TdContactType = $1000;
dContactApprox1_2: TdContactType = $2000;
dContactApprox1: TdContactType = $3000;
// Change: New Type added, syntax enforcement
type TBodyFlags = Integer;
// These consts now have defined types
const
dxBodyFlagFiniteRotation: TBodyFlags = 1; // use finite rotations
dxBodyFlagFiniteRotationAxis: TBodyFlags = 2; // use finite rotations only along axis
dxBodyDisabled: TBodyFlags = 4; // body is disabled
dxBodyNoGravity: TBodyFlags = 8; // body is not influenced by gravity
dxBodyAutoDisable : TBodyFlags = 16; // enable auto-disable on body
dxBodyLinearDamping : TBodyFlags = 32; // use linear damping
dxBodyAngularDamping : TBodyFlags = 64; // use angular damping
dxBodyMaxAngularSpeed : TBodyFlags = 128;// use maximum angular speed
dxBodyGyroscopic : TBodyFlags = 256; // use gyroscopic term
type
{$ifdef cSINGLE}
TdReal = single;
{$else}
TdReal = double;
{$endif}
PdReal = ^TdReal;
{define cODEDebugEnabled} // Debug mode
(* Pointers to internal ODE structures to reproduce C++ classes in Delphi *)
PdxJointGroup = ^TdxJointGroup;
TdJointGroupID = PdxJointGroup;
TdxJointGroup = record
num : int64;
//padding: array[1..4] of byte;
//stack : pointer;
stack : array [1..32] of byte;
end;
PdxJointLimitMotor = ^TdxJointLimitMotor;
TdxJointLimitMotor = record
vel,fmax : TdReal; // powered joint: velocity, max force
lostop,histop : TdReal; // joint limits, relative to initial position
fudge_factor : TdReal; // when powering away from joint limits
normal_cfm : TdReal; // cfm to use when not at a stop
stop_erp,stop_cfm : TdReal; // erp and cfm for when at joint limit
bounce : TdReal; // restitution factor
// variables used between getInfo1() and getInfo2()
limit : integer; // 0=free, 1=at lo limit, 2=at hi limit
limit_err : TdReal; // if at limit, amount over limit
end;
TdRealArray = array[0..15] of TdReal;
PdRealArray = ^TdRealArray;
// typedef dReal dVector33[4];
TdVector3 = array[0..3] of TdReal;//Q: Why isn't TdVector3 = array[0..2] of TdReal? A: Because of SIMD alignment.
PdVector3 = ^TdVector3;
Pd3Axis = ^Td3Axis;
Td3Axis = array[0..2] of TdVector3;
PdInteger3 = ^TdInteger3;
TdInteger3 = array[0..2] of integer;
PdxJointLimitMotor3 = ^TdxJointLimitMotor3;
TdxJointLimitMotor3 = array[0..2] of TdxJointLimitMotor;
PdxJointLimitMotor4 = ^TdxJointLimitMotor4;
TdxJointLimitMotor4 = array[0..3] of TdxJointLimitMotor;
// typedef dReal dVector4[4];
TdVector4 = array[0..3] of TdReal;
PdVector4 = ^TdVector4;
// typedef dReal dMatrix3[4*3];
TdMatrix3 = array[0..4*3-1] of TdReal;
PdMatrix3 = ^TdMatrix3;
TdMatrix3_As3x4 = array[0..2, 0..3] of TdReal;
PdMatrix3_As3x4 = ^TdMatrix3_As3x4;
// typedef dReal dMatrix4[4*4];
TdMatrix4 = array[0..4*4-1] of TdReal;
PdMatrix4 = ^TdMatrix4;
// typedef dReal dMatrix6[8*6];
TdMatrix6 = array[0..8*6-1] of TdReal;
PdMatrix6 = ^TdMatrix6;
// typedef dReal dQuaternion[4];
TdQuaternion = TdVector4;//array[0..3] of TdReal;
PdQuaternion = ^TdQuaternion;
// No typedef for AABB
TdAABB = array[0..5] of TdReal;
TdMass = record
mass : TdReal; // total mass of the rigid body
c : TdVector4; // center of gravity position in body frame (x,y,z)
I : TdMatrix3; // 3x3 inertia tensor in body frame, about POR
end;
PdMass = ^TdMass;
TdxAutoDisable = record
idle_time : TdReal; // time the body needs to be idle to auto-disable it
idle_steps : integer; // steps the body needs to be idle to auto-disable it
average_samples : longword; // size of the average_lvel and average_avel buffers
linear_average_threashold : TdReal; // linear (squared) average velocity threshold
angular_average_threashold : TdReal; // angular (squared) average velocity threshold
end;
TdxDampingParameters = record
linear_scale : TdReal; // multiply the linear velocity by (1 - scale)
angular_scale : TdReal; // multiply the angular velocity by (1 - scale)
linear_threahold : TdReal; // linear (squared) average speed threshold
angular_threashold : TdReal; // angular (squared) average speed threshold
end;
TdxContactParameters = record
max_vel : TdReal; // maximum correcting velocity
min_depth : TdReal; // thickness of 'surface layer'
end;
TdxQuickStepParameters = record
num_iterations : integer; // number of SOR iterations to perform
w : TdReal; // the SOR over-relaxation parameter
end;
PdxGeom = ^TdxGeom;
PPdxGeom = ^PdxGeom;
// Whenever a body has its position or rotation changed during the
// timestep, the callback will be called (with body as the argument).
// Use it to know which body may need an update in an external
// structure (like a 3D engine).
TdMovedCallback = procedure(o1: PdxGeom); cdecl;
// Per triangle callback. Allows the user to say if he wants a collision with
// a particular triangle.
TdTriCallback = function(TriMesh,RefObject : PdxGeom; TriangleIndex : integer) : integer;
// Per object callback. Allows the user to get the list of triangles in 1
// shot. Maybe we should remove this one.
TdTriArrayCallback = procedure(TriMesh,RefObject : PdxGeom; TriIndices:PIntegerArray; TriCount : integer);
// Allows the user to say if a ray collides with a triangle on barycentric
// coords. The user can for example sample a texture with alpha transparency
// to determine if a collision should occur.
TdTriRayCallback = function(TriMesh,Ray : PdxGeom; TriangleIndex : integer; u,v:TdReal) : integer;
PdxWorld = ^TdxWorld;
PdObject = ^TdObject;
PPdObject = ^PdObject;
TdObject = record
Padding : array [1..8] of byte;
World : PdxWorld; // world this object is in
next : PdObject; // next object of this type in list
tome : PPdObject; // pointer to previous object's next ptr
tag : integer; // used by dynamics algorithms
userdata : pointer; // user settable data
end;
PdxBody = ^TdxBody;
PdxJoint= ^TdxJoint;
TdJointID = PdxJoint;
{$IFDEF PARODE}
TdJointBreakCallback = procedure(joint: TdJointID); cdecl;
TJointBreakMode = Integer;
PdxJointBreakInfo = ^TdxJointBreakInfo;
TdxJointBreakInfo = record
flags : integer;
b1MaxF:TdVector3; // maximum force on body 1
b1MaxT:TdVector3; // maximum torque on body 1
b2MaxF:TdVector3; // maximum force on body 2
b2MaxT:TdVector3; // maximum torque on body 2
callback:TdJointBreakCallback; // function that is called when this joint breaks
end;
{$ENDIF}
PdxJointNode = ^TdxJointNode;
TdxJointNode = record
joint : PdxJoint; // pointer to enclosing dxJoint object
body : PdxBody; // *other* body this joint is connected to
next : PdxJointNode; // next node in body's list of connected joints
end;
// info returned by getInfo1 function. the constraint dimension is m (<=6).
// i.e. that is the total number of rows in the jacobian. `nub' is the
// number of unbounded variables (which have lo,hi = -/+ infinity).
TJointInfo1 = record
m,nub : byte;
end;
{
// info returned by getInfo2 function
TJointInfo2 = record
// integrator parameters: frames per second (1/stepsize), default error
// reduction parameter (0..1).
fps,erp : TdReal;
// for the first and second body, pointers to two (linear and angular)
// n*3 jacobian sub matrices, stored by rows. these matrices will have
// been initialized to 0 on entry. if the second body is zero then the
// J2xx pointers may be 0.
J1l,J1a,J2l,J2a : pdReal;
// elements to jump from one row to the next in J's
rowskip : integer;
// right hand sides of the equation J*v = c + cfm * lambda. cfm is the
// "constraint force mixing" vector. c is set to zero on entry, cfm is
// set to a constant value (typically very small or zero) value on entry.
c,cfm : pdReal;
// lo and hi limits for variables (set to -/+ infinity on entry).
lo,hi : pdReal;
// findex vector for variables. see the LCP solver interface for a
// description of what this does. this is set to -1 on entry.
// note that the returned indexes are relative to the first index of
// the constraint.
findex : pinteger;
end;
}
TJointSureMaxInfo = record
max_m : byte;
end;
TdxJoint = record
baseObject : TdObject;
flags : integer; // dJOINT_xxx flags
node : array [0..1] of TdxJointNode; // connections to bodies. node[1].body can be 0
feedback : pointer; // optional feedback structure
lambda : array [0..5] of TdReal; // lambda generated by last step
//Padding: array [1..88] of byte;
//JM: weird:
//Info1 : TJointInfo1;
//SureMaxInfo : TJointSureMaxInfo;
end;
TdxJointNull = TdxJoint;
PdxJointBall = ^TdxJointBall;
TdxJointBall = record
BaseJoint : TdxJoint;
anchor1 : TdVector3;// anchor w.r.t first body
anchor2 : TdVector3;// anchor w.r.t second body
erp : TdReal; // error reduction
cfm : TdReal; // constraint force mix in
end;
PdxJointHinge = ^TdxJointHinge;
TdxJointHinge = record
BaseJoint : TdxJoint;
anchor1 : TdVector3; // anchor w.r.t first body
anchor2 : TdVector3; // anchor w.r.t second body
axis1 : TdVector3; // axis w.r.t first body
axis2 : TdVector3; // axis w.r.t second body
qrel : tdQuaternion; // initial relative rotation body1 -> body2
limot : TdxJointLimitMotor; // limit and motor information
end;
PdxJointUniversial = ^TdxJointUniversial;
TdxJointUniversial = record
BaseJoint : TdxJoint;
anchor1 : TdVector3; // anchor w.r.t first body
anchor2 : TdVector3; // anchor w.r.t second body
axis1 : TdVector3; // axis w.r.t first body
axis2 : TdVector3; // axis w.r.t second body
qrel1 : tdQuaternion; // initial relative rotation body1 -> virtual cross piece
qrel2 : tdQuaternion; // initial relative rotation virtual cross piece -> body2
limot1 : TdxJointLimitMotor; // limit and motor information for axis1
limot2 : TdxJointLimitMotor;// limit and motor information for axis2
end;
PdxJointPR = ^TdxJointPR;
TdxJointPR = record
BaseJoint : TdxJoint;
anchor2:TdVector3; ///< @brief Position of the rotoide articulation
///< w.r.t second body.
///< @note Position of body 2 in world frame +
///< anchor2 in world frame give the position
///< of the rotoide articulation
axisR1:TdVector3 ; ///< axis of the rotoide articulation w.r.t first body.
///< @note This is considered as axis1 from the parameter
///< view.
axisR2:TdVector3 ; ///< axis of the rotoide articulation w.r.t second body.
///< @note This is considered also as axis1 from the
///< parameter view
axisP1:TdVector3; ///< axis for the prismatic articulation w.r.t first body.
///< @note This is considered as axis2 in from the parameter
///< view
qrel:TdQuaternion; ///< initial relative rotation body1 -> body2.
offset:TdVector3; ///< @brief vector between the body1 and the rotoide
///< articulation.
///<
///< Going from the first to the second in the frame
///< of body1.
///< That should be aligned with body1 center along axisP
///< This is calculated when the axis are set.
limotR:TdxJointLimitMotor; ///< limit and motor information for the rotoide articulation.
limotP:TdxJointLimitMotor; ///< limit and motor information for the prismatic articulation.
end;
PdxJointPiston = ^TdxJointPiston;
TdxJointPiston = record
BaseJoint : TdxJoint;
axis1:TdVector3; ///< Axis of the prismatic and rotoide w.r.t first body
axis2:TdVector3; ///< Axis of the prismatic and rotoide w.r.t second body
qrel:TdQuaternion; ///< Initial relative rotation body1 -> body2
/// Anchor w.r.t first body.
/// This is the same as the offset for the Slider joint
/// @note To find the position of the anchor when the body 1 has moved
/// you must add the position of the prismatic joint
/// i.e anchor = R1 * anchor1 + dJointGetPistonPosition() * (R1 * axis1)
anchor1:TdVector3;
anchor2:TdVector3; //< anchor w.r.t second body
/// limit and motor information for the prismatic
/// part of the joint
limotP:TdxJointLimitMotor;
/// limit and motor information for the rotoide
/// part of the joint
limotR:TdxJointLimitMotor;
end;
PdxJointSlider = ^TdxJointSlider;
TdxJointSlider = record
BaseJoint : TdxJoint;
axis1:TdVector3; // axis w.r.t first body
qrel:TdQuaternion; // initial relative rotation body1 -> body2
offset:TdVector3; // point relative to body2 that should be
// aligned with body1 center along axis1
limot:TdxJointLimitMotor; // limit and motor information
end;
PdxJointHinge2 = ^TdxJointHinge2;
TdxJointHinge2 = record
BaseJoint : TdxJoint;
anchor1:TdVector3 ; // anchor w.r.t first body
anchor2:TdVector3 ; // anchor w.r.t second body
axis1:TdVector3; // axis 1 w.r.t first body
axis2:TdVector3; // axis 2 w.r.t second body
c0,s0:TdReal; // cos,sin of desired angle between axis 1,2
v1,v2:TdVector3; // angle ref vectors embedded in first body
w1,w2:TdVector3;
limot1:TdxJointLimitMotor; // limit+motor info for axis 1
limot2:TdxJointLimitMotor; // limit+motor info for axis 2
susp_erp,susp_cfm:TdReal; // suspension parameters (erp,cfm)
end;
TdxJointAMotor = record
BaseJoint : TdxJoint;
mode:integer; // a dAMotorXXX constant
num:integer; // number of axes (0..3)
rel:TdInteger3; // what the axes are relative to (global,b1,b2)
axis:Td3Axis; // three axes
references: array[0..1] of TdVector3;
angle: array[0..2] of TdReal;
limot:TdxJointLimitMotor4; // limit+motor info for axes
end;
TdxJointLMotor = record
BaseJoint : TdxJoint;
num: integer;
rel:TdInteger3;
axis:Td3Axis; // three axes
limot:TdxJointLimitMotor3; // limit+motor info for axes
end;
TdxJointPlane2D = record
BaseJoint : TdxJoint;
row_motor_x:integer;
row_motor_y:integer;
row_motor_angle:integer;
motor_x:TdxJointLimitMotor;
motor_y:TdxJointLimitMotor;
motor_angle:TdxJointLimitMotor;
end;
TdxJointFixed = record
BaseJoint : TdxJoint;
qrel:TdQuaternion; // initial relative rotation body1 -> body2
offset:TdVector3; // relative offset between the bodies
erp:TdReal; // error reduction parameter
cfm:TdReal; // constraint force mix-in
end;
// position vector and rotation matrix for geometry objects that are not
// connected to bodies.
PdxPosR = ^TdxPosR;
TdxPosR = record
pos : TdVector3;
R : TdMatrix3;
end;
TdxBody = record
BaseObject : TdObject;
firstjoint : TdJointID; // list of attached joints
flags : integer; // some dxBodyFlagXXX flags
geom : PdxGeom; // first collision geom associated with body
mass : TdMass; // mass parameters about POR
invI : TdMatrix3 ; // inverse of mass.I
invMass : TdReal; // 1 / mass.mass
posr : TdxPosR; // position and orientation of point of reference
q : TdQuaternion; // orientation quaternion
lvel,avel : TdVector3; // linear and angular velocity of POR
facc,tacc : TdVector3 ; // force and torque accululators
finite_rot_axis : TdVector3 ; // finite rotation axis, unit length or 0=none
adis : TdxAutoDisable; // auto-disable parameters
adis_timeleft : TdReal; // time left to be idle
adis_stepsleft : integer; // steps left to be idle
average_lvel_buffer : pdVector3; // buffer for the linear average velocity calculation
average_avel_buffer : pdVector3; // buffer for the angular average velocity calculation
average_counter : longword; // counter/index to fill the average-buffers
average_ready : integer; // indicates ( with = 1 ), if the Body's buffers are ready for average-calculations
moved_callback : TdMovedCallback; // let the user know the body moved
dampingp : TdxDampingParameters; // damping parameters, depends on flags
max_angular_speed : TdReal; // limit the angular velocity to this magnitude
end;
TBodyList = class(TList)
private
function GetItems(i: integer): PdxBody;
procedure SetItems(i: integer; const Value: PdxBody);
public
property Items[i : integer] : PdxBody read GetItems write SetItems; default;
procedure DeleteAllBodies;
end;
(*struct dxWorld : public dBase {
dxBody *firstbody; // body linked list
dxJoint *firstjoint; // joint linked list
int nb,nj; // number of bodies and joints in lists
dVector3 gravity; // gravity vector (m/s/s)
dReal global_erp; // global error reduction parameter
dReal global_cfm; // global costraint force mixing parameter
};*)
TdxWorld = record //(TdBase)
padding_threads : array [0..39] of byte;
// devia ser este mas não funciona
//padding_threads : array [0..31] of byte;
firstbody : PdxBody; // body linked list
firstjoint : PdxJoint; // joint linked list
nb,nj : integer; // number of bodies and joints in lists
gravity : TdVector3; // gravity vector (m/s/s)
global_erp : TdReal; // global error reduction parameter
global_cfm : TdReal; // global costraint force mixing parameter
adis : TdxAutoDisable;
body_flags : integer;
islands_max_threads : integer;
wmem : pointer;
qs : TdxQuickStepParameters;
contactp : TdxContactParameters;
dampingp : TdxDampingParameters;
max_angular_speed : TdReal;
userdata : pointer;
end;
TdJointFeedback = record
f1 : TdVector3; // force that joint applies to body 1
t1 : TdVector3; // torque that joint applies to body 1
f2 : TdVector3; // force that joint applies to body 2
t2 : TdVector3; // torque that joint applies to body 2
end;
PTdJointFeedback = ^TdJointFeedback;
TdErrorType =
(d_ERR_UNKNOWN, // unknown error
d_ERR_IASSERT, // user assertion failed */
d_ERR_UASSERT, // user assertion failed */
d_ERR_LCP);
TdJointTypeNumbers =
(dJointTypeNone, // or "unknown"
dJointTypeBall,
dJointTypeHinge,
dJointTypeSlider,
dJointTypeContact,
dJointTypeUniversal,
dJointTypeHinge2,
dJointTypeFixed,
dJointTypeNull,
dJointTypeAMotor,
dJointTypeLMotor,
dJointTypePlane2D,
dJointTypePR,
dJointTypePU,
dJointTypePiston,
dJointTypeDBall,
dJointTypeDHinge,
dJointTypeTransmission
);
TdAngularMotorModeNumbers =
(dAMotorUser,
dAMotorEuler);
TdTransmissioModeNumbers =
(dTransmissionParallelAxes,
dTransmissionIntersectingAxes,
dTransmissionChainDrive);
TdSurfaceParameters = record
// must always be defined
mode : integer;
mu : TdReal;
// only defined if the corresponding flag is set in mode
mu2,
rho,
rho2,
rhoN,
bounce,
bounce_vel,
soft_erp,
soft_cfm,
motion1,motion2,motionN,
slip1,slip2 : TdReal
end;
TdContactGeom = record
pos : TdVector3;
normal : TdVector3;
depth : TdReal;
g1,g2 : PdxGeom;
side1,side2 : integer;
end;
PdContactGeom = ^TdContactGeom;
TdContact = record
surface : TdSurfaceParameters;
geom : TdContactGeom;
fdir1 : TdVector3;
end;
PdContact = ^TdContact;
// Collission callback structure
TdNearCallback = procedure(data : pointer; o1, o2 : PdxGeom); cdecl;
TdColliderFn = function(o1, o2 : PdxGeom; flags : Integer;
contact : PdContactGeom; skip : Integer) : Integer; cdecl;
TdGetColliderFnFn = function(num : Integer) : TdColliderFn; cdecl;
TdGetAABBFn = procedure(g : PdxGeom; var aabb : TdAABB); cdecl;
TdGeomDtorFn = procedure(o : PdxGeom); cdecl;
TdAABBTestFn = function(o1, o2 : PdxGeom; const aabb2 : TdAABB) : Integer; cdecl;
(*typedef struct dGeomClass {
int bytes;
dGetColliderFnFn *collider;
dGetAABBFn *aabb;
dAABBTestFn *aabb_test;
dGeomDtorFn *dtor;
} dGeomClass;*)
TdGeomClass = record
bytes : integer; // extra storage size
collider : TdGetColliderFnFn; // collider function
aabb : TdGetAABBFn; // bounding box function
aabb_test : TdAABBTestFn; // aabb tester, can be 0 for none
dtor : TdGeomDtorFn; // destructor, can be 0 for none
end;
PdGeomClass = ^TdGeomClass;
(*struct dxSpace : public dBase {
int type; // don't want to use RTTI
virtual void destroy()=0;
virtual void add (dGeomID)=0;
virtual void remove (dGeomID)=0;
virtual void collide (void *data, dNearCallback *callback)=0;
virtual int query (dGeomID)=0;
};*)
PdxSpace = ^TdxSpace;
TdRealHugeArray = array[0..65535] of TdReal;
PdRealHugeArray = ^TdRealHugeArray;
// Tri-list collider
TdIntegerArray = array[0..65535] of Integer;
PdIntegerArray = ^TdIntegerArray;
TdVector3Array = array[0..65535] of TdVector3;
PdVector3Array = ^TdVector3Array;
(*struct dxTriMeshData{
Model BVTree;
MeshInterface Mesh;
dxTriMeshData();
~dxTriMeshData();
void Build(const void* Vertices, int VertexStide, int VertexCount,
const void* Indices, int IndexCount, int TriStride,
const void* Normals,
bool Single);
/* aabb in model space */
dVector3 AABBCenter;
dVector3 AABBExtents;
/* data for use in collison resolution */
const void* Normals;
Matrix4x4 last_trans;
};*)
TdxTriMeshData = record
unknown : array [1..200] of byte; //
end;
PdxTriMeshData = ^TdxTriMeshData;
TdxHeightfieldData = record
m_fWidth : TdReal;
m_fDepth : TdReal;
m_fSampleWidth : TdReal;
m_fSampleDepth : TdReal;
m_fSampleZXAspect: TdReal;
m_fInvSampleWidth : TdReal;
m_fInvSampleDepth : TdReal;
m_fHalfWidth : TdReal;
m_fHalfDepth : TdReal;
m_fMinHeight : TdReal;
m_fMaxHeight : TdReal;
m_fThickness : TdReal;
m_fScale : TdReal;
m_fOffset : TdReal;
m_nWidthSamples : integer;
m_nDepthSamples : integer;
m_bCopyHeightData : integer;
m_bWrapMode : integer;
m_nGetHeightMode : integer;
m_pHeightData : pointer;
m_pUserData : pointer;
m_contacts : array[0..9] of TdContactGeom;
m_pGetHeightCallback : TdReal;
end;
PdxHeightfieldData = ^TdxHeightfieldData;
(*//simple space - reports all n^2 object intersections
struct dxSimpleSpace : public dxSpace {
dGeomID first;
void destroy();
void add (dGeomID);
void remove (dGeomID);
void collide (void *data, dNearCallback *callback);
int query (dGeomID);
};*)
PdxSimpleSpace = ^TdxSimpleSpace;
(*//currently the space 'container' is just a list of the geoms in the space.
struct dxHashSpace : public dxSpace {
dxGeom *first;
int global_minlevel; // smallest hash table level to put AABBs in
int global_maxlevel; // objects that need a level larger than this will be
// put in a "big objects" list instead of a hash table
void destroy();
void add (dGeomID);
void remove (dGeomID);
void collide (void *data, dNearCallback *callback);
int query (dGeomID);
};*)
PdxHashSpace = ^TdxHashSpace;
(*typedef struct dGeomSpaceData {
dGeomID next;
} dGeomSpaceData; *)
//TODO: delete this
{TdGeomSpaceData = record
next : PdxGeom;
end; }
(*// common data for all geometry objects. the class-specific data area follows
// this structure. pos and R will either point to a separately allocated
// buffer (if body is 0 - pos points to the dxPosR object) or to the pos and
// R of the body (if body nonzero).
struct dxGeom { // a dGeomID is a pointer to this
dxGeomClass *_class; // class of this object
void *data; // user data pointer
dBodyID body; // dynamics body associated with this object (if any)
dReal *pos; // pointer to object's position vector
dReal *R; // pointer to object's rotation matrix
dSpaceID spaceid; // the space this object is in
dGeomSpaceData space; // reserved for use by space this object is in
dReal *space_aabb; // ptr to aabb array held by dSpaceCollide() fn
// class-specific data follows here, with proper alignment.
};*)
TdxGeom = record // a dGeomID is a pointer to this
padding : array [1..8] of byte;
_type : integer; // class of this object
gflags : integer;
data : pointer; // user data pointer
Body : PdxBody ; // dynamics body associated with this object (if any)
body_next : PdxGeom; // next geom in body's linked list of associated geoms
final_posr : PdxPosR; // final position of the geom in world coordinates
offset_posr : PdxPosR; // offset from body in local coordinates
next : PdxGeom;
tome : PPdxGeom;
next_ex : PdxGeom;
tome_ex : PPdxGeom;
parent_space : Pdxspace;
aabb : TdAABB;
category_bits,collide_bits : longword;
end;
TGeomList = class(TList)
private
function GetItems(i: integer): PdxGeom;
procedure SetItems(i: integer; const Value: PdxGeom);
public
property Items[i : integer] : PdxGeom read GetItems write SetItems; default;
procedure DeleteAllGeoms(DeleteDataAsObject : boolean=false);
end;
TdxSpace = record
baseGeom : TdxGeom;
count : integer;
first : PdxGeom;
cleanup : integer;
sublevel: integer;
tls_kind: integer;
current_index : integer;
current_geom : PdxGeom;
lock_count : integer;
end;
// Copies settings from TdxSpace, beacause pascal doeasn't do inheritance
// for records
TdxSimpleSpace = TdxSpace;
// Copies settings from TdxSpace, beacause pascal doeasn't do inheritance
// for records
TdxHashSpace = record
BaseSpace : TdxSpace;
//padding: byte;
global_minlevel : integer;
global_maxlevel : integer;
end;
TdxQuadTreeSpace = record
BaseSpace : TdxSpace;
Blocks : pointer;
DirtyList : pointer;
padding: array [1..48] of byte;
end;
// TJointParams = (
// parameters for limits and motors
// Change: New Type added, sintax enforcement
TJointParams = Integer;
// These consts now have defined types
{$IFDEF PARODE}
const
dJOINT_BREAK_UNKNOWN:TJointBreakMode = $0000;
dJOINT_BROKEN:TJointBreakMode = $0001;
dJOINT_DELETE_ON_BREAK:TJointBreakMode = $0002;
dJOINT_BREAK_AT_B1_FORCE:TJointBreakMode = $0004;
dJOINT_BREAK_AT_B1_TORQUE:TJointBreakMode = $0008;
dJOINT_BREAK_AT_B2_FORCE:TJointBreakMode = $0010;
dJOINT_BREAK_AT_B2_TORQUE:TJointBreakMode = $0020;
{$ENDIF}
const
_priv_dParamLoStop = $000;
_priv_dParamLoStop2 = $100;
_priv_dParamLoStop3 = $200;
const
dParamLoStop: TJointParams = _priv_dParamLoStop;
dParamHiStop: TJointParams = _priv_dParamLoStop + 1;
dParamVel: TJointParams = _priv_dParamLoStop + 2;
dParamLoVel: TJointParams = _priv_dParamLoStop + 3;
dParamHiVel: TJointParams = _priv_dParamLoStop + 4;
dParamFMax: TJointParams = _priv_dParamLoStop + 5;
dParamFudgeFactor: TJointParams = _priv_dParamLoStop + 6;
dParamBounce: TJointParams = _priv_dParamLoStop + 7;
dParamCFM: TJointParams = _priv_dParamLoStop + 8;
dParamStopERP: TJointParams = _priv_dParamLoStop + 9;
dParamStopCFM: TJointParams = _priv_dParamLoStop + 10;
// parameters for suspension
dParamSuspensionERP: TJointParams = _priv_dParamLoStop + 11;
dParamSuspensionCFM: TJointParams = _priv_dParamLoStop + 12;
dParamERP: TJointParams = _priv_dParamLoStop + 13;
dParamGroup1: TJointParams = $000;
dParamLoStop1: TJointParams = _priv_dParamLoStop;
dParamHiStop1: TJointParams = _priv_dParamLoStop + 1;
dParamVel1: TJointParams = _priv_dParamLoStop + 2;
dParamLoVel1: TJointParams = _priv_dParamLoStop + 3;
dParamHiVel1: TJointParams = _priv_dParamLoStop + 4;
dParamFMax1: TJointParams = _priv_dParamLoStop + 5;
dParamFudgeFactor1: TJointParams = _priv_dParamLoStop + 6;
dParamBounce1: TJointParams = _priv_dParamLoStop + 7;
dParamCFM1: TJointParams = _priv_dParamLoStop + 8;
dParamStopERP1: TJointParams = _priv_dParamLoStop + 9;
dParamStopCFM1: TJointParams = _priv_dParamLoStop + 10;
// parameters for suspension
dParamSuspensionERP1: TJointParams = _priv_dParamLoStop + 11;
dParamSuspensionCFM1: TJointParams = _priv_dParamLoStop + 12;
dParamERP1: TJointParams = _priv_dParamLoStop + 13;
// SECOND AXEL
// parameters for limits and motors
dParamGroup2: TJointParams = $100;
dParamLoStop2: TJointParams = _priv_dParamLoStop2;