Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / ODE Physics Help(Spheres)!!

Author
Message
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 27th Jan 2010 00:50 Edited at: 27th Jan 2010 02:56
Hey guys, I've just started doing some stuff with the ODE physics engine and I have a quick question about spheres. Basically i have this really weird problem. I create a box(for a floor), and then create a sphere above the box(floor) with a radius of 10. Once i run the program, the sphere falls, but stops(collides) 10 units above the box i rendered. What i noticed is that as you decrease or increase the radius, so does that value of units above the box. For ex. If i have a sphere with a radius of 15 it will stop 15 units above the object it is supposed to collide with. This is really weird and i cant figure this out! Hope you guys can help me!

Also, in my current code, when my sphere collides with something it doesn't roll around. Does anyone know how i can get it to roll around?

Here's my code:
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 27th Jan 2010 16:58
Hey, I'm trying to implement ODE into DarkGDK, too!
I think it's awesome and so much better then DarkPhysics.

As far as I can see at first glance you're doing wrong here:

Quote: "dbPositionObject(1,pos[1],pos[2],pos[3]);"


I think the position floats are in pos[0]..pos[2]!



And did you notice that you swapped the Z and Y coordinates for you gravity? You may just change them, because Y is up/down in DarkGDK space.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 27th Jan 2010 17:53
Ohh I see now. OK thanks ill try that when I get home
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 28th Jan 2010 00:59 Edited at: 28th Jan 2010 01:00
I just got done changing what you told me to do, but still i have the same problem, the sphere always stops 10 units above the ground. This is a really weird issue... not really sure whats going on. If anyone could help me please do!! Also i think it has to do with something in the ODE part, ODE must be creating the ground cube too big or something.

Update Code:
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 30th Jan 2010 19:20
Ok well i just got done doing some tests, and i setup the program to drop some boxes, and they work fine! They collide with the box(floor) and are perfectly level. So therefore, i know the floor box isn't the issue and that it has to be something with the sphere. ODE must be creating its radius too big or something.
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 30th Jan 2010 19:24
It sounds kind of strange, I just use the same units for ODE as I use for DarkGDK and it works!
If my DarkGDK sphere object's radius is 5.0f then I set the ODE geom's radius to 5.0f too, and it fits perfectly.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 30th Jan 2010 19:47
Do you think it could be how i compiled ode? I compiled it using the single debug option. Pauli do you think you could try my code on your computer and see if it works properly?

Thanks!
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 30th Jan 2010 19:57
I compiled in SingleDebug, too.
But you have to be careful: If you set "/MT Multithreaded" (instead of "/MTd Multithreaded Debug") in the project settings when compiling ODE, you need to have the same setting in you DarkGDK project, too!

I'll try your code later and report here. Sorry but I can't do it right now since I'm about to leave in a minute.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 30th Jan 2010 19:59
Ok thanks dude! Yea just post here once you've tried it.
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 1st Feb 2010 00:16
Just tried out your code. It seems in dgdk, when you make a sphere and it says radius it is actually diameter, so its actually half the size you think it is. You could either make the sphere in dgdk twice as big or make the sphere in ode half as small. So it's not a fault of ODE.

binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 1st Feb 2010 02:22
Wooo! Sweet it works! Now just one more thing... Rotation isnt working? The sphere bounces, but it wont roll? How can i fix this?
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 1st Feb 2010 14:38
Glad you got the radius thing working. I didn't realize that DarkGDK uses diameter, because I create the ODE geoms based on the real object size anyways...

But rotation is a bit more complicated. First you need to get the Rotation Quaternion of the geom. Then you transform this quaternion to Euler angles. Finally you rotate your DarkGDK object according to these Euler angles.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 2nd Feb 2010 00:54
Huh, ok. That sounds a bit confusing... Now first of all, i have a few problems. Is dGeomGetRotation supposed to return anything? Because when i try and display the values they all just show 0. Also could you give me an example on how i am supposed to do this?

Here is what i've tried:


Doesnt work... i must be doing something wrong. Hope you can help me figure this most likely simple thing out!
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 2nd Feb 2010 01:39 Edited at: 2nd Feb 2010 01:43
Well, your code above looks like you want to rotate the ODE body to the angles of a DarkGDK object?

I do it like this: (but I think there are other ways too, because you can handle rotations in ODE with matrix or quarternions)



This first creates a rotation matrix from the objects Euler angles. Then it just applies this matrix to the body.

EDIT: I recently had a thread about ODE here, too. There is a demo if you want to see what I've done so far. I think ODE is great!
Good luck!

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 2nd Feb 2010 02:05 Edited at: 2nd Feb 2010 03:26
Im still a little confused how can i fit that into my code, so that when my Shere collides with something it rotates and rolls, just the like the objects in your demo.

You said this: Well, your code above looks like you want to rotate the ODE body to the angles of a DarkGDK object?

Actually i want to do the complete opposite. I want to rotate a DarkGDK object based on an ODE body. Just like in your demo, when you drop objects, they collide with the surface then rotate and roll and bounce around.

Also could you(if you want to) post the source code for your demo that you have in your other thread? I think it would greatly help ODE newcomers.

Thanks!
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 4th Feb 2010 02:17 Edited at: 4th Feb 2010 02:17
Anyone... I really need help on this i've been working on this rotation thing forever and cannot seem to figure it out... All i want to do is rotate a DarkGDK object based on an ODE body!

Hope someone can help me!

Also is dGeomGetRotation supposed to return anything? Because when i print its values they all return 0.

Thanks in advanced guys!
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 4th Feb 2010 04:53
I didn't spend to much time on things like rotation in ode because Lee did most of the work in the wrapper. These are some of the functions he used though which should make it easier.



binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 4th Feb 2010 14:39
Ok I'm starting to understand a little more... so would tge heading,attitude and bank be the xyz of the rotation?or would it be the pvecangles?
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 4th Feb 2010 14:56 Edited at: 4th Feb 2010 14:58
Sorry for the late response, but I have been busy finishing up my own ODE thing lately.
I hope you understand that I won't just paste my whole code here, since I'm not sure what I will do with it... (publish or not)
But because this maybe helpful to you and others I will explain a bit.

Here is how I update my DarkGDK objects rotation according to the ODE simulation:

First get the rotation quaternion of the ODE geom:



Then convert the quaternion to euler angles, which are required by DarkGDK rotation: (you will find a QuaternionToEuler() function on the web)



Finally, rotate the object:



Hope this helps.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 4th Feb 2010 15:17
wow than ks! Ill have to try that when I get home! Is that how you do it in your demo?
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 4th Feb 2010 15:21
Yes exactly.
It is part of a function called UpdateBodies() that I execute right after the SimLoop() in my UpdatePhysics() function.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 4th Feb 2010 15:29
Ahh ok and also is dgeomgetrotation supposed to return anything if you display the dreal values directly? Because when I display values such as dreal[1] for example it just displays zero?
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 4th Feb 2010 15:34 Edited at: 4th Feb 2010 15:35
There are two different ways to handle rotations in ODE:
Rotation matrix and Quaternion.
dGeomGetRotation() gets the rotation matrix. I'm using dGeomGetQuaternion(). I'm not sure why the returned values are zero in your case.
DarkGDK needs Euler angles, so you will have to convert either from rotation matrix to euler or from quaternion to euler.

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 4th Feb 2010 15:44
OK ill try this later. Thanks
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 4th Feb 2010 20:47
I can't seem to find that quaternion to Euler function. Do you have a link?
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 5th Feb 2010 12:45
Check this:
http://www.ode.org/old_list_archives/2005-October/016896.html

Just in case you may wonder what GRAD_PI means:



Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 5th Feb 2010 14:34 Edited at: 5th Feb 2010 15:41
So should I just make my own function from that code? Also for the function you need quaternion[0-4] and I just checked and the values 1 to 4 that I got from dgeomgetquaternion are all zero... same with dgeomgetrotation... what's going on! The only ones that hav a value are [0] and their value is 1 all the rest are zero!
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 5th Feb 2010 16:57
Yes you should just put that code in a function.
I can't see why your quaternion values are all zero! Strange...
Are you sure you are passing a correct dGeomID to the dGeomGetQuaternion() function?

You may want to take a look at my physics package:
QuickODE


Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 5th Feb 2010 21:08 Edited at: 6th Feb 2010 00:32
Wow nice plugin... Now i did some work and i figured out that dGeomGetRotation returns all zeros for spheres(its always the spheres that have the problems). Basically i setup a box, and when i ran the dGeomGetRotation, it returned values and such unlike the sphere. Anyone know why the sphere isnt returning any values but the box is?

BTW: I got rotation working for boxes, but not spheres because of the issue above.

Thanks!
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 7th Feb 2010 01:37 Edited at: 7th Feb 2010 20:57
This is sooo weird... i have no idea why dgeomgetrotation returns all zeros for only spheres, but works fine on boxes. This code should work fine, therefore leading to believe that this is an error with ODE. Also same thing happens with dbodygetrortaion. It returns all zeros on spheres. Also could someone try out that code... Maybe its the build or version of ODE in using... which is 0.11.1 the latest.

In case you guys need the code to help me solve this problem, here it is!

binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 9th Feb 2010 01:35
Alright... I got a little farther in solving my problem. Basically now I got the sphere rotating by using dbodysetangularvel. Ok so now my sphere is falling, and rotating. But I have one last problem, and that is the sphere keeps rolling and falling, but when it collides with the ground plane, it doesn't roll around it. It just bounces and keeps rotating. How can I make it so when it collides with something such as my floor, it will roll around and not just stay stationary.

Thanks!
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 9th Feb 2010 13:00
Allriiight fnally we can put this thread to sleep I finally got everything working. Thanks everyone for help! Next stop...trimeshes.
_Pauli_
AGK Developer
15
Years of Service
User Offline
Joined: 13th Aug 2009
Location: Germany
Posted: 9th Feb 2010 14:41
I found that the hardest part in implementing ODE.
You may take a look at this thread. It deals with trimeshes.

Good luck!

Now the plot thickens, the fps decreases, and the awesomeness goes through the roof.
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 10th Feb 2010 02:57
Thank you soo much pauli for that thread! Dude i got trimesh collision working within 10 minutes!!! Woo im so happy everything is working!
Bhax
17
Years of Service
User Offline
Joined: 2nd Jun 2007
Location:
Posted: 12th Feb 2010 02:15
Guys, could you please help a c++ noob here?

I've been trying to make binsky's code to run, but i keep getting "unresolved external symbol" for ODE.

I've included the "include" and "lib" folders of ODE in the respective places under "Projects and solutions -> VC++ Directories" but to no luck. So, what's the proper setup for ODE to run this?

Thanks in advance!
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 12th Feb 2010 16:06
Make sure you compile the ode lib, I used the ReleaseSingleLib Option.

Then in any project that uses ODE you can do one of two things:

You can go to Project > Properties > Configuration Properties > Linker > Input, and in the box that says Additional Dependencies type in the name of the ode lib, most likely "ode_single.lib".

Or you can also add it by using code,
#pragma comment(lib, "ode_single.lib")

binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 12th Feb 2010 22:57 Edited at: 13th Feb 2010 00:07
In case you want it Bhax here is the updated code with trimesh support.



Also i've just finished an ode wrapper for Darkgdk, i probably wont post it up though, because there is already quickode. The only thing it has that quickode doesnt is dynamic trimesh. Just tested my dynamic tri mesh ode function and it works! Perfect collision.
Bhax
17
Years of Service
User Offline
Joined: 2nd Jun 2007
Location:
Posted: 13th Feb 2010 13:10
@Slayer93 Thanks, that solved it! I used the pragma comment. But i had to use the ODE lib _Pauli_ posted on his QuickODE thread, here:
http://forum.thegamecreators.com/?m=forum_view&t=165423&b=5&msg=1958672#m1958672

If i use the ode_single.lib i compiled, i get a mix of LNK 4049, 4217, 2019, 2001 errors. I create the ode.sln using "premake4 vs2008" and then i build the solution using ReleaseSingleLib. I noticed _Pauli_ lib is 5498KB in size while mine is 2174KB. So i wonder what i'm doing wrong.

@binsky Thanks, that's really helpful, i'll try i right away. I've been using JV-ODE dll for a while now, it's good to be able to use ODE directly.
Slayer93
20
Years of Service
User Offline
Joined: 5th Aug 2004
Location: I wish I knew
Posted: 14th Feb 2010 04:53
Yeah its a pain to try to get the ODE Lib to compile, took me a couple of times to get it right, if you ever need to try it again then, IIRC, all the extra things you need to do is change the Code Generation to /MT or /MTd (it has to match the Code Generation in your dgdk project).

Bhax
17
Years of Service
User Offline
Joined: 2nd Jun 2007
Location:
Posted: 15th Feb 2010 20:02
@Slayer93: Thanks, you were right again. Just by changing the code from /MD to /MT solved the problem.

@binsky: Thanks for your code, i learned a lot from it.

Anyway, here's an adaption of one of Jim Williams JV-ODE demos i ported to DarkGDK, but this time using ODE directly:



Thanks again for your help, guys!
binsky
15
Years of Service
User Offline
Joined: 6th Feb 2009
Location:
Posted: 15th Feb 2010 21:30
You're welcome! and good luck! as for me my next project is ODE character controllers.

Login to post a reply

Server time is: 2024-11-20 03:39:37
Your offset time is: 2024-11-20 03:39:37