72d5cc322e75 — Leonard Ritter 3 months ago
* ODE: more work on interface, geom offsets
1 files changed, 29 insertions(+), 27 deletions(-)

M tukan/ode/init.sc
M tukan/ode/init.sc +29 -27
@@ 44,6 44,32 @@ typedef Geom < GeomType :: dGeomID
         assign (imply geomid this-type) geom
         deref geom
 
+inline vector-property (T getter setter)
+    property
+        fn (self)
+            viewing self
+            local value : T
+            getter self
+                bitcast &value (mutable @float)
+            value
+        fn (self value)
+            viewing self
+            setter self (unpack value)
+
+inline vector-property2 (T getter setter)
+    property
+        fn (self)
+            viewing self
+            let value = (getter self)
+            T
+                va-map
+                    inline (i)
+                        value @ i
+                    va-range (countof T)
+        fn (self value)
+            viewing self
+            setter self (unpack value)
+
 typedef Body < Wrapper :: dBodyID
     inline __typecall (cls world)
         imply (dBodyCreate world) this-type

          
@@ 60,26 86,13 @@ typedef Body < Wrapper :: dBodyID
         dAreConnectedExcluding self other jointtype
 
     let
-        position =
-            property
-                fn (self)
-                    let pos = (dBodyGetPosition self)
-                    fvec3
-                        pos @ 0
-                        pos @ 1
-                        pos @ 2
-                fn (self position)
-                    dBodySetPosition self (unpack position)
-
+        position = (vector-property2 fvec3 dBodyGetPosition dBodySetPosition)
         quaternion =
             property
                 fn (self)
                     let q = (dBodyGetQuaternion self)
                     fvec4
-                        q @ 1
-                        q @ 2
-                        q @ 3
-                        q @ 0
+                        q @ 1; q @ 2; q @ 3; q @ 0
                 fn (self quaternion)
                     local q : dQuaternion
                     q @ 0 = quaternion.w

          
@@ 135,18 148,6 @@ typedef+ ContactGeom
             super-type.__getattr self name
 
 
-inline vector-property (T getter setter)
-    property
-        fn (self)
-            viewing self
-            local value : T
-            getter self
-                bitcast &value (mutable @float)
-            value
-        fn (self value)
-            viewing self
-            setter self (unpack value)
-
 typedef World < Wrapper :: dWorldID
 
     #let

          
@@ 435,6 436,7 @@ typedef+ GeomType
         property
             _dGeomGetBody
             dGeomSetBody
+    let position-offset = (vector-property2 fvec3 dGeomGetOffsetPosition dGeomSetOffsetPosition)
 
 typedef Plane < GeomType :: dGeomID
     inline... __typecall