View previous topic :: View next topic |
Author |
Message |
quartz
Joined: 02 Jul 2006 Posts: 35 Location: Florida, US
|
Posted: Sat Jan 20, 2007 3:06 pm Post subject: Derelict Open Dynamic Engine (ODE) |
|
|
Hey Aldacron,
I have completed derelictfying ODE.
I am in the process of porting some of the examples to D. I have completed the two headless tests which covers a fair portion of the library. Next, I plan on porting one or two of the graphical examples. This should certify it as a complete integration into Derelict.
The math library that comes with ODE is pretty arcane and made mostly of macros. I have ported some of it to D--in order to satify the headless tests--and will continue in order to satify the graphical examples. I personally plan on creating my own vector library for my own use within my games (open source of course). My vector library will know how to resolve itself to the pointer arrays ODE uses.
I have learned a bit more about the interface between C and D with this exercise.
I hope to have the graphical examples done soon and then I will post to my website for you to pick-up. _________________ -Will (Quartz) |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
|
Back to top |
|
|
volcore
Joined: 22 Jan 2007 Posts: 19
|
Posted: Mon Jan 22, 2007 7:43 pm Post subject: |
|
|
We'd be interested in the ODE D bindings as well. |
|
Back to top |
|
|
quartz
Joined: 02 Jul 2006 Posts: 35 Location: Florida, US
|
Posted: Mon Feb 05, 2007 11:57 am Post subject: |
|
|
Just wanted to give a little bit of a status update.
I am just about to add simple shadows and then complete the sphere verse cylinder test. This is the test that shows a sphere and cylinder dropping down on top of each other. It seemed like the simplest of the tests to try and do.
I would like to mention that I am using the Helix library for my vectors and matrices. I made a few changes to it to handle in-place assignments --to minimize GC activity--, but this is a personal thing and doesn't really apply to ODE. I am also using my own camera code and I have created a UML diagram showing both layout and sequence. It is pretty easy to use.
I am planning on completing the graphical test sometime within the next week or so such that I can get it to aldacron well within the first quarter.
For those that wish to play it before-hand I can, upon request, post the Derelict bindings to my website. As I mentioned the headless tests went perfect but seeing is believing as some people say, so I hope to have at least one graphical example complete before I submit it to aldacron. _________________ -Will (Quartz) |
|
Back to top |
|
|
JoeCoder
Joined: 29 Oct 2005 Posts: 294
|
Posted: Fri Feb 09, 2007 12:09 pm Post subject: |
|
|
I'll have to do some more research, but ODE is one of the candidates for adding physics to Yage, so I may end up using it also. |
|
Back to top |
|
|
JJR
Joined: 22 Feb 2004 Posts: 1104
|
Posted: Sat Feb 10, 2007 3:50 am Post subject: |
|
|
Eric, you should talk to h3r3tic. I believe he's used the ODE engine a fair bit and knows its ins and outs. In fact, I think he created a derelictized version of it almost 2 years ago. |
|
Back to top |
|
|
quartz
Joined: 02 Jul 2006 Posts: 35 Location: Florida, US
|
Posted: Sat Feb 17, 2007 9:49 pm Post subject: |
|
|
aldacron,
I have reached a point where I have hit a brick wall. I have finally narrowed down where the problem is, I just don't know how to fix it. Perhaps someone out there knows the solution.
Here is the problem:
I have a test case where a sphere is dropped from above and hits the ground and bounces up. This works correctly with the C version. In D it fails; the sphere goes through the ground plane. Further investigation shows that the contents a certain structure is not being passed to ODE correctly and hence the sphere does not collide properly.
I have spent about two weeks now narrowing it down to where the problem is occurring. upon colliding joints need to be created to represent where the collision occurred -- ODE has a method called "dJointCreateContact(world, contactgroup, dC)". The contact structure should be filled out with certain values based the collision from a call to:
Code: |
int n = dCollide(o1, o2, 1, &(contact.geom), dContact.sizeof);
|
further information is filled prior to creating the joint.
Code: |
contact.surface.slip1 = 0.7;
contact.surface.slip2 = 0.7;
contact.surface.mode = dContactSoftERP | ...;
contact.surface.mu = 50.0; // was: dInfinity
contact.surface.soft_erp = 0.99;
contact.surface.soft_cfm = 0.02;
|
The failure is because none of the contact values in the structure appear inside the call to dJointCreateContac().
The contact struture is basically a structure with structures as follows:
Code: |
struct dSurfaceParameters {
/* must always be defined */
int mode;
dReal mu;
/* only defined if the corresponding flag is set in mode */
dReal mu2;
dReal bounce;
dReal bounce_vel;
dReal soft_erp;
dReal soft_cfm;
dReal motion1,motion2;
dReal slip1,slip2;
}
struct dContactGeom {
dVector3 pos; ///< contact position
dVector3 normal; ///< normal vector
dReal depth; ///< penetration depth
dGeomID g1,g2; ///< the colliding geoms
int side1,side2; ///< (to be documented)
}
/* contact info used by contact joint */
struct dContact {
dSurfaceParameters surface;
dContactGeom geom;
dVector3 fdir1;// = [0, 0, 0, 0];
}
|
From here I attempted to isolate what the problem was. So I created a debug method that only took a dContact* pointer and removed things until something started working. I narrowed it done such that it appears that it is the arrays that are causing the problem. I realize that D arrays have the length.
The problems occurs only when there is structures with in structures. Arrays marshal correctly at the outer most structure but anything inside inner structures doesn't work.
I am not sure if I am making sense but I don't know how else to describe it. Here is a simple example I cooked up to test it:
D definition:
Code: |
struct strA {
int i1;
double d[3];
}
struct strB {
float f1;
strA a1;
}
|
C definition:
Code: |
typedef struct strA {
int i1;
double d[3];
} strA;
typedef struct strB {
float f1;
strA a1;
} strB;
|
If I have D code that fills in strA and passed it to C, then it doesn't show up on the C side:
Code: |
strB b1;
b1.f1 = 123.0f;
b1.a1.i1 = 444;
b1.a1.d[0] = 22.22;
b1.a1.d[1] =33.33;
func1(&b1); // D code
|
C function defined in a C library:
Code: |
void func1(strB* ptrB) {
printf("f1 %0.4f\n", ptrB->b1.f1); // ok. works.
printf("d %0.4f\n", ptrB->a1.d[0]); // 22.22 displays very strangely
}
|
I am not sure where to go at this point. I am guessing I am not doing something correctly with arrays being passed to C from D. I can't change ODE API so I have to figure out how to get D to pass the data correctly. I have tried a ton of tricks but nothing works.
If I can't figure this out then I can't submit ODE to Derelict. I just may as well port ODE to D.
Any suggestion anyone?
Thanks. _________________ -Will (Quartz) |
|
Back to top |
|
|
quartz
Joined: 02 Jul 2006 Posts: 35 Location: Florida, US
|
Posted: Sun Feb 18, 2007 12:17 am Post subject: |
|
|
My problem was solved by GregorR on IRC. It turns out that I need to use align(4) for structures that combine doubles with other types.
Thanks GregorR for the help, it is much appreciated. _________________ -Will (Quartz) |
|
Back to top |
|
|
quartz
Joined: 02 Jul 2006 Posts: 35 Location: Florida, US
|
Posted: Tue Feb 20, 2007 12:09 pm Post subject: |
|
|
Update,
I have my first visual test complete. I has a few spheres and a cylinder colliding.
I am now going to create a very very simple framework to put together some of the other tests and then I should be ready to submit it to the Derelict project.
Aldacron, I may have some questions for you regarding packaging and what-not.
Here are some screenshots:
_________________ -Will (Quartz) |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Tue Feb 20, 2007 6:31 pm Post subject: |
|
|
Cool beans! I'll happily answer any questions you have about packaging. I always go through and fill in the gaps, but the more you can do before handing it over to me the less I have to do
I'm hoping (fingers-crossed, anyway) to spend some quality time with Derelict over the next few days. I need to wrap up the build script stuff and then finish off the list I stickied here. One of the big ones is changing all of the integer constants in each package into enums. If DerelictODE uses that pattern from the get-go, I'd be a happy fellow _________________ The One With D | The One With Aldacron | D Bits |
|
Back to top |
|
|
quartz
Joined: 02 Jul 2006 Posts: 35 Location: Florida, US
|
Posted: Tue Feb 20, 2007 8:58 pm Post subject: |
|
|
So far DerelictODE doesn't use any integer constants. Everything from the start was directly from ODE which used enums.
Things are moving along nicely now that I figured out the alignment issue, but it may take a week or two complete additional tests and a simple framework.
I'll leave another status next week sometime. _________________ -Will (Quartz) |
|
Back to top |
|
|
quartz
Joined: 02 Jul 2006 Posts: 35 Location: Florida, US
|
Posted: Fri Feb 23, 2007 5:48 pm Post subject: |
|
|
I may post this issue to the D newsgroup but I thought I would try here first.
I am running into an issue under Windows where a private method isn't being seen by the linker as private, but under Linux the linker respects the scope. For example, I have two files each a different simulation in ODE. Each declares a private callback function that happens to have the same name:
CylVsSphere.d
Code: |
extern (C) private void collisionCallback(void* data, dGeomID o1, dGeomID o2) {
...
}
|
and
CylBoxSlide.d
Code: |
extern (C) private void collisionCallback(void* data, dGeomID o1, dGeomID o2) {
...
}
|
Compiling, I get this under Windows:
Quote: |
C:\Working\D1.0\Derelict228\examples\graphical>build @simulation -full
Using Double Precision
OPTLINK (R) for Win32 Release 7.50B1
Copyright (C) Digital Mars 1989 - 2001 All Rights Reserved
Simulations\CylBoxSlide.obj(CylBoxSlide) Offset 01494H Record Type 00C3
Error 1: Previous Definition Different : _collisionCallback
|
This compiles fine under Linux. I even tried moving the private keyword outside and around the callback but that doesn't work either. Of course if I rename one of them it compiles fine, but I shouldn't have to do that. I really don't want to have different names in each simulation.
P.S. I am using dmd version 1.007
Any suggestions? _________________ -Will (Quartz) |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Sat Feb 24, 2007 2:40 am Post subject: |
|
|
I'd say file a bug report, if there's not one already. Other than that, I have no helpful ideas. _________________ The One With D | The One With Aldacron | D Bits |
|
Back to top |
|
|
quartz
Joined: 02 Jul 2006 Posts: 35 Location: Florida, US
|
Posted: Sun Feb 25, 2007 10:45 pm Post subject: |
|
|
aldacron,
I feel confident now that DerelictODE is ready. I ported/created five visual examples that test a variety of tricks. The simulations/examples are graphically minimalistic. I didn't do textures or any of the other eye candy such as bounding boxes, contact points drawing. The examples do run just like the C versions though. Okay, I got bored a little and modified a few of them to have fun running into things.
How do you want it?
I can post it to my site when you are ready.
All the tests come with a build response file for windows and linux. The examples are in Derelict's examples directory.
This version was synced with ODE 0.8 the lastest from ode.org.
-Will (Quartz) _________________ -Will (Quartz) |
|
Back to top |
|
|
aldacron
Joined: 05 May 2004 Posts: 1322 Location: Seoul, South Korea
|
Posted: Mon Feb 26, 2007 5:20 am Post subject: |
|
|
Great! Post it to your site, email it to me... whatever works for you. I'll download it, do any tweaking that needs to be done, and will eventually add it to the trunk (not immediately, got some other stuff I want to do first). _________________ The One With D | The One With Aldacron | D Bits |
|
Back to top |
|
|
|