dan miller wrote:
> Ethan --
> 
> I know ODE pretty well but not the heightfield stuff.  I need it for a
> couple projects I'm working on.  I'd love to collaborate on it, or at least
> act as a beta tester.  I don't have much experience with Pyrex but it looks
> straightforward enough.
> 
> Please feel free to email me at danbmil99 at yahoo dot com.

How do you feel about being an alpha tester? Attached is a patch that
builds but I can't promise much more than that. Specifically it only
wraps one HeightfieldBuild function (there are two or three others)
and there aren't too many docstrings.

You should be able to use it like:

def heightback(data, x, z):
    return x**3+z**3

d = ode.HeightfieldData()
d.build_callback(None, heightback, 1, 1, 8, 8, 1, 0, 1, 0)
g = ode.GeomHeightfield(d, False, space)

The parameters to build_callback are:

* data for callback
* callback, which should return a float
* width of geom
* depth of geom
* number of width samples
* number of depth samples
* scale factor applied to values computed by callback
* offset added to values computed by callback
* thickness
* whether to tile

If you can come up with a cool demo that demonstrates the code in
question, that would be a really handy example. (If you have the ODE
sources handy, there's an example in
ode-0.7/ode/test/test_heightfield.cpp.) Of course, let me know if it
doesn't work.

Ethan
diff -Nur pyode-pristine/src/declarations.pyx pyode-heightfield/src/declarations.pyx
--- pyode-pristine/src/declarations.pyx	2007-05-30 20:44:18.000000000 -0400
+++ pyode-heightfield/src/declarations.pyx	2007-05-30 20:46:05.000000000 -0400
@@ -49,6 +49,8 @@
         int _dummy
     cdef struct dxTriMeshData:
         int _dummy
+    cdef struct dxHeightfieldData:
+        int _dummy
 
     # Types
     ctypedef dxWorld* dWorldID
@@ -58,6 +60,7 @@
     ctypedef dxJoint* dJointID
     ctypedef dxJointGroup* dJointGroupID
     ctypedef dxTriMeshData* dTriMeshDataID
+    ctypedef dxHeightfieldData* dHeightfieldDataID
     ctypedef dReal dVector3[4]
     ctypedef dReal dVector4[4]
     ctypedef dReal dMatrix3[4*3]
@@ -81,6 +84,7 @@
         dVector3 t2
 
     ctypedef void dNearCallback(void* data, dGeomID o1, dGeomID o2)
+    ctypedef dReal dHeightfieldGetHeight( void* p_user_data, int x, int z )
 
     ctypedef struct dSurfaceParameters:
         int mode
@@ -451,3 +455,17 @@
 
     void dGeomTriMeshEnableTC(dGeomID g, int geomClass, int enable)
     int dGeomTriMeshIsTCEnabled(dGeomID g, int geomClass)
+
+    # Heightfield
+    dHeightfieldDataID dGeomHeightfieldDataCreate()
+    void dGeomHeightfieldDataDestroy(dHeightfieldDataID g)
+    void dGeomHeightfieldDataBuildCallback(dHeightfieldDataID d,
+                                           void* pUserData,
+                                           dHeightfieldGetHeight* pCallback,
+                                           dReal width, dReal depth,
+                                           int widthSamples, int depthSamples,
+                                           dReal scale, dReal offset,
+                                           dReal thickness, int bWrap)
+    dGeomID dCreateHeightfield (dSpaceID space, dHeightfieldDataID data,
+                                 int bPlaceable)
+
diff -Nur pyode-pristine/src/heightfield.pyx pyode-heightfield/src/heightfield.pyx
--- pyode-pristine/src/heightfield.pyx	1969-12-31 19:00:00.000000000 -0500
+++ pyode-heightfield/src/heightfield.pyx	2007-05-30 20:44:30.000000000 -0400
@@ -0,0 +1,59 @@
+######################################################################
+# Python Open Dynamics Engine Wrapper
+# Copyright (C) 2004 PyODE developers (see file AUTHORS)
+# All rights reserved.
+#
+# 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.
+#   (2) The BSD-style license that is included with this library in
+#       the file LICENSE-BSD.
+#
+# 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 and LICENSE-BSD for more details. 
+######################################################################
+
+cdef class GeomHeightfield(GeomObject):
+    """Heightfield object.
+
+    To construct the heightfield geom, you need a HeightfieldData object that
+    stores the heightfield data. This object has to be passed as the first
+    argument to the constructor.
+
+    Constructor::
+        GeomHeightfield(data, space=None)
+    """
+    cdef HeightfieldData data
+
+    def __new__(self, HeightfieldData data not None,
+                placeable=True, space=None):
+        cdef SpaceBase sp
+        cdef dSpaceID sid
+
+        self.data = data
+
+        sid=NULL
+        if space!=None:
+            sp = space
+            sid = sp.sid
+        self.gid = dCreateHeightfield(sid, data.hfdid, <int>placeable)
+
+        _geom_c2py_lut[<long>self.gid] = self
+
+    def __init__(self, HeightfieldData data not None, space=None):
+        self.space = space
+        self.body = None
+
+    def placeable(self):
+        return True
+
+    def _id(self):
+        cdef long id
+        id = <long>self.gid
+        return id
diff -Nur pyode-pristine/src/heightfielddata.pyx pyode-heightfield/src/heightfielddata.pyx
--- pyode-pristine/src/heightfielddata.pyx	1969-12-31 19:00:00.000000000 -0500
+++ pyode-heightfield/src/heightfielddata.pyx	2007-05-30 20:44:30.000000000 -0400
@@ -0,0 +1,49 @@
+######################################################################
+# Python Open Dynamics Engine Wrapper
+# Copyright (C) 2004 PyODE developers (see file AUTHORS)
+# All rights reserved.
+#
+# 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.
+#   (2) The BSD-style license that is included with this library in
+#       the file LICENSE-BSD.
+#
+# 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 and LICENSE-BSD for more details. 
+######################################################################
+
+cdef class HeightfieldData:
+    """This class is used to store heightfield data.
+    """
+    cdef dHeightfieldDataID hfdid
+
+    def __new__(self):
+        self.hfdid = dGeomHeightfieldDataCreate()
+
+    def __dealloc__(self):
+        if self.hfdid!=NULL:
+            dGeomHeightfieldDataDestroy(self.hfdid)
+
+    def build_callback(self, userdata, callback, width, depth, wsamp, dsamp,
+                       scale, offset, thickness, bwrap):
+        cdef object tup
+        cdef void* data
+        tup = (callback, arg)
+        data = <void*>tup
+        dGeomHeightfieldDataBuildCallback(self.hfdid,
+                                          data, get_height, width, depth,
+                                          wsamp, dsamp, scale, offset,
+                                          thickness, bwrap)
+
+cdef dReal get_height(void *data, int x, int z):
+    cdef object tup
+    tup = <object>data
+    callback, arg = tup
+    return callback(arg, x, z)

Attachment: signature.asc
Description: OpenPGP digital signature

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Pyode-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/pyode-user

Reply via email to