JV-ODE Physics Thread 13

Blitz3D Forums/Blitz3D Userlibs/JV-ODE Physics Thread 13

VIP3R(Posted 2010) [#1]
Current JV-ODE Version: 1.32

Now available for Blitz3D & BlitzMax (Win32)

The JV-ODE Physics Wrapper is an advanced user library supporting almost all of the Open Dynamics Engine functions wrapped inside a DLL (Dynamic Link Library).

The library can be used with any programming language that supports DLL's, including Blitz3D and BlitzMax (Win32). The Euler rotation system in JV-ODE has been adapted to match the left-handed Euler rotation used in Blitz3D, however functions for accessing Quaternion and Axis Angle rotation systems are also included. The full versions contain all of the necessary files to get you started, including over 40 demos showing the various features found in ODE and a complete Function Reference document.

The BlitzMax (Win32) version also features a built-in 'bare-bones' OpenGL 3D engine module and B3D mesh loader module for demo purposes.

To view more information and screenshots click here.

Options are now available to purchase the wrapper using either PayPal or Share*it.

The Blitz3D restricted demo version is now available for download here (207KB)

The BlitzMax (Win32) restricted demo version is now available for download here (376KB)

Have Fun :)

Previous JV-ODE Blitz3D Threads: 1 2 3 4 5 6 7 8 9 10 11 12

Useful Links: ODE.org Website - ODE Wiki - ODE User Guide (PDF) - ODE User Guide (HTML)


Blitzplotter(Posted 2010) [#2]
Hi, I made a small alteration to the tower generation code to allow it to be placed anywhere dependant upon an array of x,y & z co-ords.... I've just realised that it needs more modification before numerous towers can be invoked to stop duplicates of ODE bodies appearing.

[EDIT]Fixed the problem (my fault...) - I'd encapsulated the updatecubes within an If statement that needed a little modifying, happy dayz:-

The tower code posted at the end of the last thread is a great example of code that with a little manipulation will give the possibility of making brick walls that can be 'crashed through'. Cool.





That asides, I've successfully created the tower block at the end of my first elevated blocks.

[EDIT] have simply equated the start of the tower block to offset vars from the start of the cars for the time being.



[EDIT...text removed] Just did this to relax after coding an object oriented 2D (boring!) knight program for college. The concepts are interesting, however for sheer satisfaction you can't be Blitz 3D + JV-ODE & a bit of devilish particle system code.


Charrua(Posted 2010) [#3]
hi!

i wrote 5 demos of using JV-ODE with a free world editor.
The idea is to place objects (nothing new) and then load the world (nothing new) but, with a lib i wrote, ode objects (body, geom, joint) are created based on the shape defined on the editor, position, scale, etc.

take a look

http://sites.google.com/site/odriozolajuanignacio/juanodriozola/blitz3d

comments are welcome

Juan


Ian Caio(Posted 2010) [#4]
Hey all,

I was writing a demo, about joints, testing the Ball and Socket, the Hinge and the Slider joints. Just 2 cubes connected for each one of them. The problem is that until now, I always thought of static objects as being Geoms without Bodies. Thats basically one of the first things I learned. But then I got into a dilema. If for example, Im going to do a door:
1 - I would make a wall and a door
2 - I would connect them with 1 Hinge joint, and set the parameters.

The problem is, that the wall is a Static object, and the door is a Rigid Body. But I can only attach joints for two Bodies. So the wall would have to be a body too. Is there another way to solve this "problem"? and how I would make the Body remain static? (I have tryied to set the angular and linear velocity to 0 in the loop but it didnt really worked)

Now, you have been helping me, so let me try to share something with you too. Maybe you already know this site, but anyways:
http://docs.taoframework.com/Tao.Ode/

This website has lots of stuff related to ODE (and other libraries) and it has helped me a lot, you will find almost all the commands there, and some explanation too. If I could I would download it (was planning on recording ODE related stuff in a CD with the JV-ODE itself). If you find a way tell me :)

Cya


VIP3R(Posted 2010) [#5]
The solution is to attach the hinge joint between the door body and the 'world'. To specify the world, you use a zero value for the body parameter.

For example...

dJointAttach(HingeJoint,DoorBody,0)


Ian Caio(Posted 2010) [#6]
Thanks VIP3R,

I have seen it before, on the RagDoll demo, but was not really sure how it worked. But for Sliders for example, how would I position the joint? I didnt found dJointSliderSetAnchor, which I understood as being the "position joint", only dJointSliderSetAxis, which I guess says the "rotation" of the Slider. Tell me if I understood it wrong, because I found out this by testing, and I might be.

But now more for curiosity, how do I keep a body static? Is there a way? Like, setting all the forces to 0 or something like that? Because as I tryied setting forces, and velocity to 0 and it didnt work.

Cya


VIP3R(Posted 2010) [#7]
A joint anchor defines the 'pivot' position of the joint, this doesn't apply with the slider joint as it only extends and contracts.

To keep a rigid body static, you can add a fixed joint to connect the body to the 'world', locking it into place.

To cancel any forces on the body, you zero all forces, torque and velocity...

dBodySetForce(body,0,0,0)
dBodySetTorque(body,0,0,0)
dBodySetAngularVel(body,0,0,0)
dBodySetLinearVel(body,0,0,0)


You must do this every iteration before stepping the simulation though, calling them once will not work.


Blitzplotter(Posted 2010) [#8]
Hi Folks. I've been running outa steam what with one thing and the other - if anyone wants the media assocaited with the following code I'll upload it with a list of links. The code to implement the two player racer (images A COUPLE OF POSTS UP) with a 3rd view is available here: please note, the code is designed to work with keyboard and a basic USB joypad at the moment:-




Charrua(Posted 2010) [#9]
Hi



i updated the awc world editor.
Joints and Phisics objects are displayed and managed better, but still working. There are some new features like wayPoints placement, export to b3d and lightmapping.






http://blitzbasic.com/toolbox/toolbox.php?tool=247


Juan


Blitzplotter(Posted 2010) [#10]
Charrua, your editor is looking very impressive, the dots showing the path of the flying object looks interesting.


Charrua(Posted 2010) [#11]
thank's BlitzPlotter

the dots are simply WritePixelFast after RenderWorld, is a function of many included on Paths.bb, a Path Following System i recently place in the code archives.

The editor needs a way of enter/edit phiscs params, next week probably i update the editor with this capabilities.

The most important part is the "ode lib", "awc ode lib" is an interface to that lib, it receives the info from the editor and do call to "ode lib" wich is general purpose and may facilitate the work with ode.

"ode lib" has general purpose Ode routines. The one i think is very useful creates a Geom and Body from a blitz entity (oCreate()).
There are some Scale Diferences, 1.98 instead of 2.0 and 0.99 instead of 1-0 when creating Geoms. Slightly smaller than it should be, the purpose is that the blitz entity should be a door, but normally, doors has a small separation from floor. Any way if you need or think isn't necesary, change it.

Juan


Uber Jase(Posted 2010) [#12]
Seeing as the Physx wrapper seems dead I am looking for a new physics wrapper and this 1 looks great and well supported. Just a few question though before I buy:)

Does the engine support boyancy? Has it got kenetic movement for stuff like machinary ect?

Oh, and is it easy to use like the Physx wrapper was?

Thanks:)


VIP3R(Posted 2010) [#13]
Yes it supports 'simple' buoyancy. Can you expand on the second question? I'm not quite sure what you mean.

I can't answer the third question as I've not used Physx, but you can try the free JV-ODE demo version to get a taster.


gburgess(Posted 2010) [#14]
Urrrgh, this is making me bang my head against a wall. I'm trying to create a simple helicopter game, and I thought I could counterweight the helicopter with an invisible non-collidable geom underneath it, so that the player can't easily turn it upside down. Now, the geom is definitely there, but it's not having any effect on the motion of the chopper. I'm using AddForce to keep the chopper in the air, and dBodySetAngularVel to rotate the chopper. Now, I guess dBodySetAngularVel would overwrite any movement caused by the "weight", but when the user stops moving the mouse, dBodySetAngularVel stops being called, so I expected the chopper to auto-right itself.

I'm going about this the wrong way aren't I?


VIP3R(Posted 2010) [#15]
Well you've got the right idea, but you've overlooked something. A geom is only used for collision geometry, so it does not have any weight. You need to add a body instead of a geom, you can then give this extra body some mass (weight). To connect the counterweight body to your helicopter body, you can use a fixed joint.


gburgess(Posted 2010) [#16]
Ah, I see. That makes much more sense. Thanks, I'll give that a try! Not delved into joints yet, so this is sure to be a lot of fun.


VIP3R(Posted 2010) [#17]
You will be glad to hear the fixed joint is relatively simple. After you've positioned the helicopter and counterweight bodies during your setup routine, you would then connect them like this...

FixedJoint=dJointCreateFixed(World,0)
dJointAttach(FixedJoint,HelicopterBody,CounterweightBody)



outsider(Posted 2010) [#18]
Hi,

Can I sell my JV-ODE lib copy?


VIP3R(Posted 2010) [#19]
Yes if you wish.

You will need to confirm the new owners details (via email) before they become a registered user though.


Ian Caio(Posted 2010) [#20]
May I do a question not so JV-ODE related?

VIP3R, I was looking at the Ragdoll-Zombie example, and I wondered which program did you use to edit the zombie model so it fitted in the demo.


VIP3R(Posted 2010) [#21]
Sure :)

It was the reverse, I made the demo fit the zombie model (the original Psionics3D version).

You will find some model/animation editing tools here.


gburgess(Posted 2010) [#22]
You will be glad to hear the fixed joint is relatively simple. After you've positioned the helicopter and counterweight bodies during your setup routine, you would then connect them like this...

FixedJoint=dJointCreateFixed(World,0)
dJointAttach(FixedJoint,HelicopterBody,CounterweightBody)


Thanks, that confirms it, that's exactly what I'm doing. Unfortunately, I'm getting some very strange effects :(

After doing the above, I position HelicopterBody in the world, and yet it's height seems to be variable depending on the mass of the helicopter and/or the counterweight body. Which I really don't understand. Going to have to strip everything out to figure this out. Grrrr, I hate physics engines. Not your fault, I blame ODE!


VIP3R(Posted 2010) [#23]
If you can post or send me some code I can take a look for you.


gburgess(Posted 2010) [#24]
That would be awesome, and very kind of you.

This is my routine for assembling the helicopter. If you like, I can just zip up and email you everything, it might make more sense that way. This function scans through all the loaded data to find joints, geoms and bodies for the actor specified in name$. The bodies are added and positioned first (with a "root" one being chosen as the "handle" of the whole thing), then the geoms are added to the bodies, then the joints are added last, and joined to the specified bodies.
Type Actor
	Field aData.ActorData
	Field modelhandle%

	Field bodyRoot%
	Field bodies%[100]
	Field bodiesLayers$[100]
	Field bodiesIds$[100]
	Field geoms%[100]
	Field geomsLayers$[100]
	Field geomsIds$[100]
	Field joints%[100]
	Field mass%

	Field helperPivot%
End Type

Function Actor_new.Actor(name$)
this.actor=New Actor
this\aData.ActorData=ActorData_get(name$)

this\modelhandle% = CopyEntity(this\aData\modelhandle%)
CreateShadowCaster this\modelhandle%

i%=0
For cab.ActorBody=Each ActorBody
	If cab\aData=this\aData
		this\bodies[i%] = dBodyCreate(world)
		this\mass%=dMassCreate()
		If cab\bodyType$="box"
			dMassSetBoxTotal this\mass%, cab\mass#, cab\xsize#,cab\ysize#,cab\zsize#
		EndIf
		this\bodiesLayers[i%]=cab\layerName$
		this\bodiesIds[i%]=cab\id$
		dBodySetMass(this\bodies[i%],this\mass% )
		dBodySetPosition(this\bodies[i%],cab\xpos#,cab\ypos#,cab\zpos#)
		dBodySetRotation(this\bodies[i%],cab\xrot#,cab\yrot#,cab\zrot#)
		If cab\maxAngularSpeed#<>-1 dBodySetMaxAngularSpeed(this\bodies[i%],cab\maxAngularSpeed#):DebugLog "Set MAS"
		;dBodySetFiniteRotationMode(this\body%,1)
		If cab\root%=1
			this\bodyRoot%=this\bodies[i%]
			DebugLog "Root:"+i%+" "+cab\id$
		EndIf

		dBodyDisable(this\bodies[i%])		
		i%=i%+1
	EndIf
Next

i%=0
For cag.ActorGeom= Each ActorGeom
	If cag\aData=this\aData
		;If cag\geomSpace$=""
			spawnSpace=actorSpace
		;ElseIf cag\geomSpace$="voidWeight"
		;	spawnSpace=voidSpace
		;EndIf
		
		If cag\geomType$="box"
			this\geoms%[i%]=dCreateBox(spawnSpace,cag\xsize#,cag\ysize#,cag\zsize#)
		EndIf
		this\geomsLayers[i%]=cag\layerName$
		this\geomsIds[i%]=cag\id$
		For j%=0 To 99
			If this\bodiesLayers[j%]=this\geomsLayers[i%]
				dGeomSetBody this\geoms%[i%],this\bodies%[j%]
			EndIf
		Next
		dGeomSetOffsetPosition(this\geoms%[i%],cag\xpos#,cag\ypos#,cag\zpos#)

		;dGeomSetSurfaceSlip1(this\geoms%[i%],1)
		;dGeomSetSurfaceSlip2(this\geoms%[i%],1)
		;dGeomSetSurfaceMu(this\geoms%[i%],1)
		;dBodySetSurfaceBounce(this\geoms%[i%],0)
		i%=i%+1
	EndIf
Next

i%=0
For caj.ActorJoint=Each ActorJoint
	If caj\aData=this\aData
		joint1%=-1
		joint2%=-1
		For j%=0 To 99
			If this\bodiesIds$[j%]=caj\jointId1$
				For i%=0 To 99
					If this\bodiesIds$[i%]=caj\jointId2$
						joint1%=j%
						joint2%=i%
					EndIf
				Next
			EndIf
		Next
		If joint1%=-1 Or joint2%=-1 RuntimeError("Bad joint data in "+this\aData\name$+" ("+joint1%+" to "+joint2%+")")
		If caj\jointType$="fixed"
			this\joints%[i%]=dJointCreateFixed (world, 0);
			dJointAttach (this\joints%[i%], this\bodies[joint1%], this\bodies[joint2%]);
			;dJointSetFixed (this\joints%[i%])
			;DebugLog "Attached joint: "+joint1%+" to "+joint2%
			i%=i%+1
		EndIf
	EndIf
Next

For i%=0 To 99
	If this\bodies%[i%]<>0
		dBodySetLinearVel(this\bodies[i%],0,0,0)
		dBodySetAngularVel(this\bodies[i%],0,0,0)
		dBodyEnable(this\bodies%[i%])
	EndIf
Next


this\helperPivot%=CreatePivot()

Return this
End Function


And this is where I call the above, and then position it using the "root" one mentioned above.

player.Actor=Actor_new("playerChopper")
dBodyDisable(player\bodyRoot%)
dBodySetPosition(player\bodyRoot%,0,200,0)
dBodyEnable(player\bodyRoot%)


I know for sure that the data being loaded is correct, so I'm kind of stumped about what the problem is. If this looks okay to you, then it must be in the code I'm using to apply force to the chopper. Somehow.

Thanks for looking, I appreciate it.


VIP3R(Posted 2010) [#25]
It looks ok, it's a bit difficult to see if the joints are connecting between the correct bodies. I might need the entire code to check it fully.

Going back to the original issue, if the helicopter/counterweight increases, you will need to increase the forces too. If you're doing that and the joints are connecting the correct bodies, it might be caused by the ordering of the setup/run. For example, you may be stepping the simulation during the setup procedure when it should not be stepped until the setup is complete. This would cause the helicopter to start at different heights depending on the mass.

Send me the code via email if you like and I'll check it for you.


gburgess(Posted 2010) [#26]
As far as I understand, I'm doing all that. Emailing you the code now. The above excerpt is from the Actors.bb file. wf.bb is the main file. Thanks again for taking the time to look at this. Currently, the numbers output on the debug log is the Y position of the helicopter. As you can see, at the beginnig it rapidly changes from what it should be to settle on a different value altogether.

I really hope I'm not just doing something dumb.


VIP3R(Posted 2010) [#27]
Ah, got it.

Ok, what's happening was this... you created the helicopter body at ypos=0 and the counterweight body at ypos=-10, then before you step the simulation you change the helicopter body to ypos=200, expecting the counterweight to move to ypos=190. In actual fact the counterweight was still at -10 not 190, so when you stepped the sim, the fixed joint acted like an elastic band between the helicopter and counterweight. It pulled them both towards each other, thus lowering the height of the helicopter. The helicopter and counterweight also ended up at the same y position, instead of being separated by 10 units.

There was some important info I forgot about the fixed joint, the dJointSetFixed(Joint) function must be called after attaching the joint to maintain their relative positions, otherwise they will both be joined at their center.

To fix the code you need to do two things, first you must move the counterweight body as well as the helicopter body in 'wf.bb'...

player.Actor=Actor_new("playerChopper")
dBodyDisable(player\bodyRoot%)
dBodySetPosition(player\bodyRoot%,0,200,0)
dBodySetPosition(CountweightBody,0,190,0) ; <<<< HERE
dBodyEnable(player\bodyRoot%)


...otherwise you will get that elastic band effect.

Next, remove the comment here to maintain the relative positions in 'Actor.bb'...

;dJointSetFixed (this\joints%[i%])

It should work as expected once the above is done.


gburgess(Posted 2010) [#28]
Ah, yes, I was experimenting with the dJointSetFixed command, and commented it out when it didn't seem to be helping. I thought once they were joined via a joint, they'd all move as one.

Thanks very much (again!) for your assistance on this, I'll plug in this change when I'm in front of the code.


Ian Caio(Posted 2010) [#29]
Hey VIP3R,
Im working on a project, and I was now starting to set up the physics, related to the character movement. But since Im going to use JV-ODE in the game it would be a little complicated to mix the Blitz native collision system with the JV-ODE one.
The thing is, using forces would be harder since the movement is based on a constant velocity. So I thought about using the command dBodySetLinearVel(). The problem is I need to apply a Relative Velocity, so it moves where it faces. But I didnt find any command like "dBodySetRelLinearVel()", only for forces.

And do you think this is the better way doing this? (Im asking because it would be better to use forces now them make everything on velocity and then have troubles in the future)

Thanks (:
Cya


VIP3R(Posted 2010) [#30]
@Glenny-boy: You're welcome :)

There isn't a relative version of dBodySetLinearVel(), although it could be done if you work out how much velocity to apply to each axis (X/Y/Z).

I would recommend using forces instead. If you need to constantly apply/update the velocity, you will most likely have problems as it will override the physics responses.


GIB3D(Posted 2010) [#31]
I haven't used JV-ODE for awhile, I've been using PhysX but I have both. I was wondering, are there any magnet/vehicle commands?


Ian Caio(Posted 2010) [#32]
Hey VIP3R,

It really seems like its worth doing it with forces. But Im facing some problems. Im gonna focus on one of them that is being more complicated to me:

Im using a Sphere as a geometry to the character since I guess its faster then the other collision. For Y Axis rotation (with the mouse), Im using a variable that changes with the MouseXSpeed and then using "dBodySetRotation(0,Variable,0)" after then WorldStep for making the character face the direction. For making the movements Im just using "dBodyAddRelForce" and a constant force (still gonna work it). The problem is that it seens like the sphere is not responding to the Friction the way I was expecting. Seens like the accelleration gets harder because of the friction, but when its already moving it does not desaccellerate. Doesnt matter how bigger the Mu value is. I tested without the command "dBodySetRotation" and the ball start rolling (dur) but it seens like the issue is still there. However, if I use a Box instead of a sphere seens like it just respond better when the rotation command is not there.

Is there a problem about using dBodySetRotation for forcing some angule for a body while its reacting to the simulation?
For this character simulation is a sphere the best geom to use?

Sorry for asking too much

Cya (:


VIP3R(Posted 2010) [#33]
@GIB3D: There are no 'built-in' functions for magnets/vehicles, both can be simulated but you will have to construct them yourself. There was a magnet demo in one of the older JV-ODE threads IIRC.

@ian caio: No problem, feel free to ask :)

Using dBodySetRotation() while the body is reacting will override the physics responses, in the same way as setting the velocity manually.

The following functions should only be used during the initial setup of an object, or when you wish to reset an object...

dBodySetPosition(body,x#,y#,z#)
dBodySetRotation(body,pitch#,yaw#,roll#)
dBodySetQuaternion(body,qw#,qx#,qy#,qz#)
dBodySetAxisAngle(body,angle#,rx#,ry#,rz#)
dBodySetLinearVel(body,x#,y#,z#)
dBodySetAngularVel(body,x#,y#,z#)


A sphere can work well for a character, it's better than using an upright capsule/ray IMO. There's a demo that might help you located here.


Ian Caio(Posted 2010) [#34]
Thanks a lot for the Demo VIP3R,
Its already helping a lot. Im gonna go make a sketch-up, of the way I want the character to behave in the physics, and change the demo until I get the final result. But Im getting a nice idea of how its supposed to work.

Also, thanks for the Fix on the JV-ODE Docs (only saw it a few minutes ago), its working perfectly.

By the way, I sent you an email (on your profile mail) (:

Cya


VIP3R(Posted 2010) [#35]
You're welcome :)


Ian Caio(Posted 2010) [#36]
VIP3R, How can I specify the kinetic friction coefficient? I have saw that there are two commands: dContactSetMu and dContactSetMu2. Is that what Mu2 stands for? And is there a way to make a geometry not affected by friction without having to use dContactSetMu giving 0 as value? I have tryied using the command "dGeomContactSetMu" and giving zero as parameter, but it didnt seen to work.

Thanks,
Cya (:


VIP3R(Posted 2010) [#37]
Yes, Mu sets the friction coefficient and Mu2 is used to set the friction coefficient in the perpendicular direction (if used, otherwise Mu sets both directions). There's more information in the official ODE user guide, see the 'contact' joint.

Using the dGeomContact...() functions allows you to set the friction per geom. If it wasn't working, you probably didn't set the geom contact mode for that geom...

dGeomContactSetMode(geom,dContactSlip1)

...you have to set the geom contact mode before the geom contact functions will work.

Look at the 'Demo-GeomFriction' demo, it shows how to set different friction values on individual geoms.


Ian Caio(Posted 2010) [#38]
Thanks for the reply,

I Guess I got it. Mu2 is for the X Axis friction of a geom.
I tryied to read about the Contact joints in the ODE User Guide, but didnt understand the modes really well.
After setting the Contact Mode I only have to set Mu to "0" for making the geom not affected by the friction?

I have read here, that ODE simulates friction another way. And that Mu does not correspond to the Friction Coefficient. Is this right?

Another question that has a little to do with that. If I dont create any mass, what is going to be the mass of the object?

Cya (:


Ian Caio(Posted 2010) [#39]
I have been making some tests, and I guess I have the answer for a few of my own questions:

1 - For making the Geometry not affected by the friction, I had to use a value that neutralized the other Geometry Mu. For example, I made a wall with a value of 32Mu. For making the other geometry dont react to the wall friction, I had to give a -32Mu value. It didnt seen to affect the friction with other geometries that had a Mu value under 32Mu. Im just kind of confused about why is this necessary, But Im gonna try to read the UserGuide again, look for something about this.

2 - Yeah, Mu does not correspond to the Friction Coefficient. But I cant really explain why. Its on the UserGuide thought, Im just not getting it really well.

3 - If you dont create any mass, the standard mass is gonna be 1:
Well, considering that the stepsize# parameter of the dWorldStep command means the time elapsed in seconds, using the formula F=m*a I realized that if there was no friction or collision, if I applied a force of 10N in the Z direction, and 0.1 second was elapsed, the speed would be 1. If you take those information and use the formula you will get that the mass is equivalent to 1.

All of these answers were get with tests, so Im not pretty sure of some of them.

Cya

EDIT:
Just found something interesting. Seens like if you use the dContactApprox1 contact mode it makes the Mu value an approximation to the Friction Coefficient. For Example, using this mode would make 0.5Mu equivalent to the Columbus formula coefficient. Im just going to try to understand the ODE standard friction system. If I find something I post here.


VIP3R(Posted 2010) [#40]
Ok, I can see where the confusion is coming from.

From the ODE guide (Physics model - Friction Approximation)...
The Coulomb friction model is a simple, but effective way to model friction at contact points.
It is a simple relationship between the normal and tangential forces present at a contact point
(see the contact joint section for a description of these forces). The rule is:

| fT | <= mu * | fN |

where fN and fT are the normal and tangential force vectors respectively,
and mu is the friction coefficient (typically a number around 1.0).
Now, if you have two colliding objects, one with zero friction and the other with X amount of friction, the total friction is the mean of the two (0 + X / 2). This is the default contact surface mode behaviour in JV-ODE.

There are three contact surface modes in JV-ODE - mean, maximum and minimum, which can be used to change the way the contact properties like friction are used. Changing the contact surface mode will be global, it is not per geom. See the dSetInternalContactSurfaceMode(mode) function in the JV-ODE Function Reference for more information.

Using the dContactApprox1 contact mode will use a different approximation to the default (constant-force-limit).

You can either customise the friction for the colliding objects so that the mean value results in zero. Or, you can change the contact surface mode to minimum, so that only the lowest value (zero) is used.

Regarding the mass question, you're correct, the default mass is 1.


Ian Caio(Posted 2010) [#41]
Before I posted this I had readed the Friction Approximation section of the UserGuide, but as I said, I didnt understant it really well..

Seens like ODE is able to use 2 models of friction. In the first one the Mu means the maximum tangencial force that can be applied in the object. And its independent of the Normal. But when I use Mu=32 I dont have to apply a 32N or higher force in the object for moving it. So I guess its not as I think it is..

The second one seens to be the closest one to the Coloumb friction model.

Maybe I could use (-dInifinity) for the Mu value. That way a object Mu would never be lower then the main geometry Mu. Just dont know if this takes more processing time..

Thanks for answering,
Cya


Charrua(Posted 2010) [#42]
just in case some one is interested in:

http://blitzbasic.com/Community/posts.php?topic=90118

Juan


Santiworld(Posted 2010) [#43]
hi, i have some probrem with the ode physics.

i have a simple car simulation, one car, and one scenary.

i have this ode objets, 4 wheels, 4 joints and the carbody and the trimesh scenary.

some data of the scenary mesh
polys : 4005
Verts : 3280

 

Global terreno = LoadMesh("b3d\terreno.b3d")
Global terreno_ode = CreateTriMesh(Space,terreno)
dGeomContactSetMu(terreno_ode,200)



in my computers, the game work perfectly.
but in others computers, the car jump like crazy.

i have the same problems in the Simple Race time ago.

my teory is, in poor computers, maybe the ode crash becouse there is to many polys for the trimesh scenary??

i don't know...

i use the standar ode values from car demo.

regards!, Santiago


VIP3R(Posted 2010) [#44]
I don't have anywhere near enough information tbh.

Is it different behaviour (cars jittery) only, or an actual crash or both?

What are the specs of the computers? (OS / CPU / GPU / Memory / Display Hz)

What type of timing are you using?

What type of physics stepping are you using? (WorldStep / QuickStep)

It is not likely that the TriMesh polycount is anything to do with it directly, but it may be linked to the type of space you use (HashSpace, SimpleSpace etc).


Santiworld(Posted 2010) [#45]
Hi :), i will post all information i have, and the loop code use for this game.

bad behaviour : youtubevideo http://www.youtube.com/watch?v=HA8ylhLjoco
this video is accelerated becouse was record from a cellular phone

good behaviour : http://www.youtube.com/user/indiesoft#p/a/u/1/2dd3ZXIs2Ys


the car behaviour is no real, everytime a wheel touch the scenary, is like if the sceanary return with a big force the car.

specs of the computers : the game fail in SO : Vista on a HP and Compact computer, i don't have more data of the other computers. :(


 Not KeyHit(1)
		
	
		
		
		update_mouse()
		update_cam()
		update_keys()
		UpdateCars()
		UpdateGeoms()
		update_rules()
		
		
		
		PTime=MilliSecs()
		dSpaceCollide(Space,World,ContactGroup)
		dWorldQuickStep(World,0.1)
		dJointGroupEmpty(ContactGroup)
		PhysicsTime#=MilliSecs()-PTime
		
		
	
	
	
	UpdateWorld()
	RenderWorld()
	
	
	text_2d()
	Flip()
		
Wend




if you wan't, i can send by mail a game copy to try, is only 8mb.
i test the game in all computers i have, no problems, but some people have this problem, maybe is the computer spects?


VIP3R(Posted 2010) [#46]
Hmm, are you using any timing to maintain a set framerate? (for example, delta timing etc)

Have you tried using different ODE spaces? HashSpace or SimpleSpace

I still don't have enough information to help at this point.

You can send the source code and media via email if you would like me to try it here, but only if you remove any third party library code (I do not have access to stuff like FastImage etc).

If I can't recreate the problem here, you will have to get the full specs of the problem computers. Vista on HP/Compaq is not enough info.

Btw, it looks excellent so far (as did Simple Race) :)


Santiworld(Posted 2010) [#47]
hi...

i use 2 optiones, with frametween and without frametween, in booth is the same.

Have you tried using different ODE spaces? HashSpace or SimpleSpace - i don't know how :)


at the moment, the game fail only in windows vista. very strange...

now i upload the game to internet, you can download from http://www.indiesoft.com.ar/indieoffroad.html

please, tell me if you can reproude the fail. thanks!


VIP3R(Posted 2010) [#48]
To change the ODE spaces you would do the following...

For HashSpace

Global Space=dHashSpaceCreate(0)

For SimpleSpace

Global Space=dSimpleSpaceCreate(0)

...and the same for all sub-spaces if you use them.

I'll take a look at the download later and let you know if I can reproduce it.


Santiworld(Posted 2010) [#49]
i made a test, i use a flat scenary and the game works fine.

for some reason, the scenary is the problem.

but why in some computers work and in others works without problems?


--------------------------------------------------------

this happend in some computers.

in the same computers work with xp but in vista dosen't work

http://www.youtube.com/watch?v=AGLfoCvNN1k

http://www.youtube.com/watch?v=k-TnqsJSTxM


Santiworld(Posted 2010) [#50]
hi Vip3r.

maybe i found the problem...!!!! - EDIT (i wrong, the problem persist)

I use .b3d files, exporting with b3dpipeline in max9

i export the same scenary in .3ds file and the physic work perfect, and the same file in .b3d format fails in the physics.

now i load a .3ds for ode physics, hide scenary (WORKS!!!) (EDIT - only in a few computers)
and i load a .B3D for visible scenary.

this make any sense?, can be the b3dpipeline exporting strange b3d file?
this maybe is the same reason for the old simple race fails too.

if you want i can upload the .b3d file to recreate the physics problem

regards, Santiago.


Santiworld(Posted 2010) [#51]
ok, back to the begining again..

now i learn that is no mather if i use .3ds or .b3d files.

i am using max9 and b3d pipeline for export the files b3d, or max for .3ds export.

no i made a new test.

i use the CarDemo.bb and i load the 3d scenary, and the problem is also in the cardemo program.

i try with .b3d and .3ds file, and the problem appear in booth.

i upload the .b3d and .3ds file, plase tell me if you can try to know what happen..

i don't know why in some computers somethimes works perfectly.

i going to send you the link by mail

[CODE]
; ### Create Plane

;dCreatePlane(Space,0,1,0,0)

;Global Plane=CreatePlane()
;EntityAlpha Plane,0.8

;EntityTexture Plane,PlaneTexture()

Global terreno = LoadMesh("scenary\terreno.3ds")
terreno_ode = CreateTriMesh(Space,terreno)
dGeomContactSetMu(terreno_ode,200)[/CODE]

sometimes, the car works ok, until the blue body of car touch the scenary, thats make the car flys to the space.


VIP3R(Posted 2010) [#52]
Thanks for sending the mesh files Santiago.

Well, both meshes (3DS and B3D) work fine here on Windows Vista. I can drive the car all the way to the green arrow, when the car flips upside down and touches the mesh it rests normally.

From your description, it sounds like the simulation explodes when the ODE box touches the TriMesh. The most common cause of these kind of issues is faulty contacts being generated during a collision, sending the object flying off into the distance.

To help find the solution, you need to make a note of the following items on the affected machines...

CPU Type & Speed (Intel / AMD etc)
RAM Speed & Size
Windows Version (Including Service Pack Version / Localisation etc)

There must be a common factor on the affected machines, I would suggest you collect all of the above data on machines it works ok on and on machines it doesn't work on to see if there's a pattern.

The TriMesh construction is also very important, I have seen B3D meshes before which display normally, but do not work as a TriMesh. The TriMesh is built using the vertice and indice data only, and these must be ordered correctly. It's extremely difficult to debug and it's even worse when only certain machines show the problem. Exporting the mesh using different software or using a different method/pipeline could correct the issue.


Charrua(Posted 2010) [#53]
hi, mine is one of the computers that fails is a

Laptop Toshiba L305

Windows Vista Home Basic, SP2

Intel Pentium Dual CPU T3400 @2.16 GHz, 2 GB RAM.

Juan


VIP3R(Posted 2010) [#54]
Thanks Charrua, that's very helpful.

It works ok on the following setup...

Windows Vista Business SP2
Intel Core 2 Duo 6400 CPU
2GB RAM


Charrua(Posted 2010) [#55]
In this machine, i have an xp emulated via VMWare, running that virtual machine, the game of Santiago run ok, so i discard CPU or hardware.

From vista, doing right click and setting on the properties windows the XP compatibility mode makes no sense. Running the app in administrator mode, the same.

I dont press a key, and a second or two after the initila screens, when appear the car, the wheels start to bounce all over the place with the car static on it's position.

really very strange

Juan


VIP3R(Posted 2010) [#56]
Interesting, so it may not be related to the machine architecture.

Now we need to know which editions of Vista are affected.


Santiworld(Posted 2010) [#57]
this is very interesting, look a group of scientists find a cure.

I want to add that in some occasions in my computer, making changes, eh could make it fail the same scenario.

my theory is the problem of mesh, the interpretation of the mesh and is also affected by the hard (as if it were fault tolerance)

in single race, I felt the same way, in the menu, the car falls on a plane.
sometimes it was the 3rd or 4th career, returning to the menu, crazy physics appeared again. then was like that depended on a memory load or something that was stored ... I also happened when he placed a lot of cars ..

4x4off in the case of road, I have a single car, and a stage, that's weird

Greetings!


Santiworld(Posted 2010) [#58]
hi Vip3r, have you any news about the mesh problem?

regards!
Santiago


VIP3R(Posted 2010) [#59]
Hi Santiago,

I can't reproduce the issue here and I haven't been provided with more information regarding the problematic operating systems.

There's not much else I can do other than to repeat the above suggestion...


Exporting the mesh using different software or using a different method/pipeline could correct the issue.




Blitzplotter(Posted 2010) [#60]
I've just implemented up to 10 collapsible towers within my platformer, thinking about a GUI front end to maybe allow the game player to choose where they want their towers and how big they want them - maybe even invoke a variable mass function to them, maybe associate the variable mass with a colour.

I am trying to invoke 10 'elevators' that will ease the pain of driving back round to the level/cube 1 ramp to get back on. So, I'll try and dig out my contact code to automate the movement of the 3d slimline cubes.


Blitzplotter(Posted 2010) [#61]
If anyone's interested just made a quick installer for my little racing game which owes a lot to JV-ODE, in fact would have been nigh on impossible without it!

Installer here:-

Click here for installer


Charrua(Posted 2010) [#62]
i uploaded an update of AWC with some minor changes:
now from the editor LowStop and HiStop can be read/set for joints and mass for bodies.
Documentation in pdf

Juan

bp, too much smoke for my nose!

Juan


Blitzplotter(Posted 2010) [#63]
Charrua, will try your new awc once i get home, heh heh, i know one of my cars is not to ozone friendly - it took me a 'little' while to implement the smoke effectively.


Ian Caio(Posted 2010) [#64]
Hey all,

I have been trying to reach the character physics for a while, but still didnt got it right. For now I have been setting velocity manually trough Force functions, so if the player stopped pressing the movement buttons, the char would stop completely. The problem is that any external forces would be neutralized. So I got back from where I started, I thought it would be better to control the char with forces and let him stop with the Friction naturally, not manually with forces. But a few problems had showed up.
-The first one is that when the Z velocity equals to the X velocity the friction stop acting on the object, it keeps on moving. I kind found out it has something to do with the fact that Im keeping the rotation of the object neutral (dBodySetRotation(Body,0,0,0)). But I still dont know what that has to do with the friction not working in this direction.

-The second one is related to the Friction coefficient. Im using the dContactApprox1 flag, so the numbers of Mu are related to the Coulomb friction equation. When this value gets equals or over 1, it starts making small jumps as long as he speeds up. This also happens when I put a value equal/over 20 on the standard dContactMode flag. This is a obstacle because a bigger friction would mean the char to stop faster, but its being also a problem, because it wouldnt walk the way its supposed to. He would be giving small jumps.

If you need the source code for the tests I have been making, tell me, so I can organize the code better before.

A Last thing that has nothing to do with the Friction: I found in the JV-ODE commands some functions related to HeightMaps. Is it possible to use them on Blitz3D? I saw it needs some height map related data (which I dont know exactly what it is) and I dont know if its possible to get it throught Blitz3D normally. Is it?
Maybe if its not, there was some kind of hacking could be made to get this data, with some pointers. Lots of things are possible through Userlibs.

Cya


VIP3R(Posted 2010) [#65]
There's something else you can try, go back to this point...


For now I have been setting velocity manually trough Force functions, so if the player stopped pressing the movement buttons, the char would stop completely. The problem is that any external forces would be neutralized.


When the movement buttons are pressed, do what you were already doing. Now when the player stops pressing the movement buttons, stop applying forces so the character can be affected by external forces again.

From some of the recent discussions on the ODE mail list, it appears that the HeightField feature is broken, to the point where they are considering removing it until it's more stable. For this reason I would advise against using it for now. The data structure was specified using the greyscale values of the heightmap (see here).

You can use other tools to generate a B3D mesh from a HeightMap (there may be something in the Blitz code archives that does this), then convert the B3D to TriMesh. The TriMesh included in the JV-ODE demos was created in this way.


Ian Caio(Posted 2010) [#66]
Hey VIP3R,

Thanks for the answers,
So I guess its better to use Trimeshs instead of Heightmaps. Rather have a little more "trouble" to use them then to use a non-stable feature. Actually theres no trouble at all, just make the heightmap become a mesh.

About the Character physics, thats what Im planning doing. The problem is that I need something to stop the character walking when the movement buttons are not pressed. So instead of doing it manually (neutralizing the speed using forces, which neutralize external forces), I thought about using the ODE friction. But there were those problems I said before, about the friction value being too high, or the direction that makes the friction stop working. If I find out how to get over this its gonna be easier to implement the moving forces (:

Cya


VIP3R(Posted 2010) [#67]
When the movement buttons are not pressed, can you keep applying the forces until the character stops, then stop applying them? Using friction to stop it is likely to lead to problems. Have you tried using the damping functions instead?

Here's some more info on character physics in ODE...
http://opende.sourceforge.net/wiki/index.php/HOWTO_upright_capsule


Ian Caio(Posted 2010) [#68]
Hey VIP3R,

First thank you a lot for the help, I finally got the character physics working the way I wanted it to work. I used Damping, but not the ODE Damping, a Damping formula. It worked perfectly. Im just working some small detail out, but for now they are not being problems. The basic is ready (:

Now I have a small question: If you create a plane with dCreatePlane() how would you destroy its geometry?

See ya


VIP3R(Posted 2010) [#69]
Hi Ian,

Glad to hear it's working well.

To destroy the plane geometry, use the 'dGeomDestroy(geom)' function...

Global ODEPlane=dCreatePlane(Space,0,1,0,0)
...
dGeomDestroy(ODEPlane)



Orso(Posted 2010) [#70]
VIP3R Hello, I am interested in jv-ode ODE, but after watching many post do not know if you have c + +, for Blit SDK. You say: The library Can be used with That Supports Any programming language DLL's, Including Blitz3D and BlitzMax (Win32).


VIP3R(Posted 2010) [#71]
JV-ODE will work with C++ or Blitz3DSDK. The full version contains an include file for use with C++.

The JV-ODE demos will only run with Blitz3D/BlitzMax, and would need to be converted to run in C++ with Blitz3DSDK.

If you need further information, please let me know.


Orso(Posted 2010) [#72]
Thanks, perfect. I'll have to download and try


Orso(Posted 2010) [#73]
Hi vip3r,
I've been playing with your library from the editor Blitz3D and well, everything works,
but when I opened my first project from dev-c + +, I get an error "(ODE INTERNAL ERROR 2) bad argument (s)". I know that 27 line failure, look at the code.

#include <blitz3dsdk.h>
#include "JV-ODE-include.c"

int World;
int Spacio;
int ContactGrup;
//..............................................................................
int main()
{
// ........init bb
bbBeginBlitz3D();
bbGraphics3D( 640, 480, 0, 2 );
bbAmbientLight( 64, 64, 64);
BBEntity camera = bbCreateCamera();
BBEntity light = bbCreateLight();
BBEntity cube = bbCreateCube();
bbPositionEntity( camera, 0, 10, -5 );
bbRotateEntity( light, 90, 0, 0 );

//.......init jv-ode
dInitODE();
World=dWorldCreate();
dWorldSetAutoDisableFlag(World,1);//---- line 27 ----

//.....Program loop
while( !bbKeyHit( KEY_ESCAPE ) )
{
bbUpdateWorld();
bbRenderWorld();
bbFlip();
}

//......Dinit jv-ode
dWorldDestroy(World);
dCloseODE();

bbEndBlitz3D();
return 0;
}


VIP3R(Posted 2010) [#74]
Hi Orso,

I've emailed you regarding the above issue. The error is due to a missing DLL registration call.


Orso(Posted 2010) [#75]
Thank you, now is fine.


jeffmorris(Posted 2010) [#76]
VIP3R, How do I get JV-ODE Physics V1.32? I have JV-ODE Physics V1.27.


VIP3R(Posted 2010) [#77]
You would have received an update email when each new version was released.

I've sent a download link for the latest version to your registered email address (the one you used to purchase it).


jeffmorris(Posted 2010) [#78]
VIP3R, Thanks for sending me JV-ODE Physics V1.32. I started using Blitz3D after trying to use 3D Game Studio. I was trying to create some kind of a driving simulator in a city. 3D Game Studio had problems with large 3D meshes. I modified the CarDemo code to load the 3D meshes and to let me use gamepad instead of keyboard. I have to use an invisible plane for physics because I don't know how to set up 3D meshes for physics.

roads=LoadMesh("roads01.3ds")
RotateEntity roads,0,0,0
PositionEntity roads,0,0,0
brush=CreateBrush()
BrushColor brush,31,31,31
PaintMesh roads,brush
ground=LoadMesh("ground01.3ds")
RotateEntity ground,0,0,0
PositionEntity ground,0,0,0
brush=CreateBrush()
BrushColor brush,0,127,0
PaintMesh ground,brush
water=LoadMesh("water01.3ds")
RotateEntity water,0,0,0
PositionEntity water,0,0,0
brush=CreateBrush()
BrushColor brush,0,0,127
PaintMesh water,brush



VIP3R(Posted 2010) [#79]
You need to create a TriMesh for each 3ds mesh, except the water mesh (unless you want that to collide). See the 'Create TriMesh' section of the TriMesh demos.

When using more than one mesh that could overlap / collide (like the ground and road), multiple spaces should be used. Create a sub-space of space, then place all TriMeshes (and the plane) into the sub-space. To prevent any meshes within the same sub-space from colliding with each other, you must disable internal space collisions using dSetInternalSpaceCollideMode(0).

The above is shown in the demo 'CarDemo-TriMesh-X4' where four terrain meshes and a plane safely overlap, there is also a multiple space demo which will help.


jeffmorris(Posted 2010) [#80]
I tried to modify the 'CarDemo-TriMesh-X4' code but the car falls through the green ground. The car stays on the roads. The 3D meshes don't overlap each other.

;dCreatePlane(SceneSpace,0,1,0,0)
;Global Plane=CreatePlane()
;EntityAlpha Plane,0
;EntityTexture Plane,PlaneTexture()

TerrainMesh(1)=LoadMesh("ground01.3ds")
ScaleMesh TerrainMesh(1),1,1,1
EntityColor TerrainMesh(1),0,191,0
TriMesh(1)=CreateTriMesh(SceneSpace,TerrainMesh(1))
dGeomSetRotation(TriMesh(1),0,0,0)

TerrainMesh(2)=LoadMesh("roads01.3ds")
ScaleMesh TerrainMesh(2),1,1,1
EntityColor TerrainMesh(2),31,31,31
TriMesh(2)=CreateTriMesh(SceneSpace,TerrainMesh(2))
dGeomSetRotation(TriMesh(2),0,0,0)

TerrainMesh(3)=LoadMesh("water01.3ds")
ScaleMesh TerrainMesh(3),1,1,1
EntityColor TerrainMesh(3),0,127,127
TriMesh(3)=CreateTriMesh(SceneSpace,TerrainMesh(3))
dGeomSetRotation(TriMesh(3),0,0,0)

PositionEntity TerrainMesh(1),0,0,0
PositionEntity TerrainMesh(2),0,0,0
PositionEntity TerrainMesh(3),0,0,0

dGeomSetPosition(TriMesh(1),0,0,0)
dGeomSetPosition(TriMesh(2),0,0,0)
dGeomSetPosition(TriMesh(3),0,0,0)


If I try to disable internal space collisions using dSetInternalSpaceCollideMode(0), Blitz3D stops responding.


VIP3R(Posted 2010) [#81]
Is the ground a simple single layer mesh?

It's unlikely that dSetInternalSpaceCollideMode(0) is causing B3D to stop responding, the problem may be elsewhere. If you can post the entire code (in a codebox), I'll take a look.


jeffmorris(Posted 2010) [#82]
Include "JV-ODE.bb"
AppTitle "JV-ODE TriMesh Car Demo - TriMesh X4"
Graphics3D 1280,1024,1
Global CMass#=200.0
Global WMass#=14.0
Global WorldERP#=1.0
Global WorldFriction#=70.0
Global Torque#=24.0
Global SuspensionHS#=0.01
Global Force#=0.0
Global Steer#=0.0
Global Car
Global CGeom
Global CMesh
Global CarStartY=30
Dim Wheel(4)
Dim WGeom(4)
Dim Joint(4)
Dim TerrainMesh(3)
Dim TriMesh(3)
Type ODEGeom
	Field body
	Field geom
	Field mesh
End Type
dInitODE()
Global World=dWorldCreate()
Global Space=dHashSpaceCreate(0)
Global CarSpace=dHashSpaceCreate(Space)
Global SceneSpace=dHashSpaceCreate(Space)
Global ContactGroup=dJointGroupCreate(0)
dSetInternalSpaceCollideMode(0)
dWorldSetAutoDisableFlag(World,1)
dWorldSetGravity(World,0,-0.98,0)
dWorldSetERP(World,WorldERP)
dContactSetMode(dContactSlip1)
dContactSetMu(WorldFriction)
ode.ODEGeom=New ODEGeom
ode\body=dBodyCreate(World)
Car=ode\body
dBodySetPosition(ode\body,0,CarStartY,0)
dBodySetRotation(ode\body,0,0,0)
mass=dMassCreate()
dMassSetBoxTotal(mass,CMass,3,1,4)
dBodySetMass(ode\body,mass)
dMassDestroy(mass)
ode\geom=dCreateBox(CarSpace,3,1,4)
CGeom=ode\geom
dGeomSetBody(ode\geom,ode\body)
ode\mesh=CreateCube()
CMesh=ode\mesh
ScaleMesh ode\mesh,1.5,0.5,2
EntityColor ode\mesh,0,0,191
For count=1 To 4
	ode.ODEGeom=New ODEGeom
	ode\body=dBodyCreate(World)
	Wheel(count)=ode\body
	dBodySetPosition(ode\body,0,0,0)
	dBodySetRotation(ode\body,0,0,90)
	mass=dMassCreate()
	dMassSetSphereTotal(mass,WMass,0.7)
	dBodySetMass(ode\body,mass)
	dMassDestroy(mass)
	ode\geom=dCreateSphere(CarSpace,0.7)
	WGeom(count)=ode\geom
	dGeomSetBody(ode\geom,ode\body)
	ode\mesh=CreateCylinder()
	ScaleMesh ode\mesh,0.7,0.25,0.7
	EntityColor ode\mesh,31,31,31
Next
dBodySetPosition(Wheel(1),-2,CarStartY-0.5,+2)
dBodySetPosition(Wheel(2),+2,CarStartY-0.5,+2)
dBodySetPosition(Wheel(3),-2,CarStartY-0.5,-2)
dBodySetPosition(Wheel(4),+2,CarStartY-0.5,-2)
Global Light=CreateLight()
RotateEntity Light,50,-50,0
LightColor Light,255,255,255
AmbientLight 130,130,130
Global CameraPivot=CreatePivot()
Global Camera=CreateCamera(CameraPivot)
CameraClsColor Camera,0,127,255
CameraRange Camera,1,1000

;dCreatePlane(SceneSpace,0,1,0,0)
;Global Plane=CreatePlane()
;EntityAlpha Plane,0
;EntityTexture Plane,PlaneTexture()

TerrainMesh(1)=LoadMesh("ground01.3ds")
ScaleMesh TerrainMesh(1),1,1,1
EntityColor TerrainMesh(1),0,191,0
TriMesh(1)=CreateTriMesh(SceneSpace,TerrainMesh(1))
dGeomSetRotation(TriMesh(1),0,0,0)

TerrainMesh(2)=LoadMesh("roads01.3ds")
ScaleMesh TerrainMesh(2),1,1,1
EntityColor TerrainMesh(2),31,31,31
TriMesh(2)=CreateTriMesh(SceneSpace,TerrainMesh(2))
dGeomSetRotation(TriMesh(2),0,0,0)

TerrainMesh(3)=LoadMesh("water01.3ds")
ScaleMesh TerrainMesh(3),1,1,1
EntityColor TerrainMesh(3),0,127,127
TriMesh(3)=CreateTriMesh(SceneSpace,TerrainMesh(3))
dGeomSetRotation(TriMesh(3),0,0,0)

PositionEntity TerrainMesh(1),0,0,0
PositionEntity TerrainMesh(2),0,0,0
PositionEntity TerrainMesh(3),0,0,0

dGeomSetPosition(TriMesh(1),0,0,0)
dGeomSetPosition(TriMesh(2),0,0,0)
dGeomSetPosition(TriMesh(3),0,0,0)

SetupCar()

While Not KeyHit(1)
	UpdateKeys()
	UpdateCar()
	UpdateGeoms()
	PTime=MilliSecs()
	dSpaceCollide(Space,World,ContactGroup)
	dWorldQuickStep(World,0.1)
	dJointGroupEmpty(ContactGroup)
	PhysicsTime#=MilliSecs()-PTime
	UpdateCam()
	RenderWorld
	Text 0,0,"JV-ODE Version "+dGetVersion()
	Text 0,15,"Physics Time:"+PhysicsTime
	Text 0,50,"Force:"+Force
	Text 0,65,"Torque:"+Torque
	Text 640,0,"A - Accelerate"
	Text 640,15,"Z - Brake/Reverse"
	Text 640,30,"Arrows - Steering"
	Text 640,45,"Space - Reset Car"
	Flip 1
Wend
dJointGroupDestroy(ContactGroup)
dSpaceDestroy(Space)
dWorldDestroy(World)
dCloseODE()
End
Function SetupCar()
For count=1 To 4
	Joint(count)=dJointCreateHinge2(World,0)
	dJointAttach(Joint(count),Car,Wheel(count))
	dJointSetHinge2Anchor(Joint(count),dBodyGetPositionX(Wheel(count)),dBodyGetPositionY(Wheel(count)),dBodyGetPositionZ(Wheel(count)))
	dJointSetHinge2Axis1(Joint(count),0,1,0)
	dJointSetHinge2Axis2(Joint(count),-1,0,0)
	dJointSetHinge2Param(Joint(count),dParamSuspensionERP,0.8)
	dJointSetHinge2Param(Joint(count),dParamSuspensionCFM,SuspensionHS)
	If count>2
		dJointSetHinge2Param(Joint(count),dParamLoStop,0)
		dJointSetHinge2Param(Joint(count),dParamHiStop,0)
	End If
Next
End Function
Function UpdateKeys()

If KeyDown(30)=1
	Force=Force+0.08
	If Force>30 Then Force=30
	End If
If KeyDown(44)=1
	Force=Force-0.1
	If Force<-10 Then Force=-10
	If Force>0 Then Force=Force*0.97
	End If
If KeyDown(30)=0 And KeyDown(44)=0 Then Force=Force*0.99
If KeyDown(203)=1 Or KeyDown(205)=1
	If KeyDown(203)=1
		Steer=0.5
		Else
		Steer=-0.5
		End If
	Else
	Steer=0.0
	End If
If KeyHit(57)=1
	Force=0.0
	dBodySetRotation(Car,dGeomGetPitch(CGeom),dGeomGetYaw(CGeom),0)
	End If
End Function
Function UpdateCar()
For count=1 To 4
	dBodyEnable(Wheel(count))
Next
dBodyEnable(Car)
For count=1 To 4
	dJointSetHinge2Param(Joint(count),dParamVel2,Force)
	dJointSetHinge2Param(Joint(count),dParamFMax2,Torque)
Next
For count=1 To 2
	angle#=Steer-dJointGetHinge2Angle1(Joint(count))
	dJointSetHinge2Param(Joint(count),dParamVel,angle)
	dJointSetHinge2Param(Joint(count),dParamFMax,400)
Next
End Function
Function UpdateCam()
PositionEntity Camera,0,3,-3
PivotX#=Cos(EntityYaw(CMesh)-90)+EntityX(CMesh)
PivotY#=EntityY(CMesh)
PivotZ#=Sin(EntityYaw(CMesh)-90)+EntityZ(CMesh)
PositionEntity CameraPivot,PivotX,PivotY,PivotZ
PointEntity CameraPivot,CMesh
End Function
Function UpdateGeoms()
For ode.ODEGeom=Each ODEGeom
	PositionEntity ode\mesh,dGeomGetPositionX(ode\geom),dGeomGetPositionY(ode\geom),dGeomGetPositionZ(ode\geom)
	RotateEntity ode\mesh,dGeomGetPitch(ode\geom),dGeomGetYaw(ode\geom),dGeomGetRoll(ode\geom)
Next
End Function


I created 3D meshes in either AutoCAD or 3DS MAX and exported them to 3DS files.


VIP3R(Posted 2010) [#83]
Can you edit your post to use a 'codebox' tag instead of 'code'?

The code you posted works fine with the JV-ODE demo meshes... LoadMesh("media\terrain.b3d")

Make sure your car isn't positioned inside/underneath the ground mesh and try each TriMesh individually to see if the problem is related to a particular mesh.

Let me know if you find anything.


jeffmorris(Posted 2010) [#84]
VIP3R, How can I send you the files so that you can check them you?


VIP3R(Posted 2010) [#85]
Zip them up and send them to the email address in my Blitz profile. Don't use any other compression than zip.

Don't forget the codebox edit.


jeffmorris(Posted 2010) [#86]
I tried to send you E-mail message at the address listed in your profile but my E-Mail client told me that your E-Mail address doesn't exist. I went to your website and used one of your E-Mail addresses listed on your website.


VIP3R(Posted 2010) [#87]
Ok, your problems are due to the design of your meshes.

For example, the following wireframe mesh is the JV-ODE demo terrain viewed from above...

[Edit] Images removed

Notice the continuous grid pattern of the mesh, with no holes etc.

Your meshes are like this (scaled down to 1/10th)...

[Edit] Images removed

The ground mesh doesn't work because it is made up of islands, it needs to be one continuous mesh.


jeffmorris(Posted 2010) [#88]
I may have to abandon Blitz3D for Unity game engine.


Oiduts Studios(Posted 2010) [#89]
Hello I need some help. I am trying to create a rope from one point to another by using points defined by the player. I used the rope example and I just can't seem to find the formula that can find how many points are on a line for a set distance. Like this...



Thats all I really need, I know how to set up the rope itself.
And it is is 2D so no Z axis
Thanks for the help!

Last edited 2010


VIP3R(Posted 2010) [#90]
Well the rope demo simply moves the position by subtracting the sphere radius multiplied by two. The sphere radius is 4, so the next sphere would be positioned at 4 x 2 = 8 which is the sphere diameter.

The formula for finding how many points there are on a 2D line would be like this...
Total Points = Line Length / Distance Between Points


Oiduts Studios(Posted 2010) [#91]
Thank you for the help on my last post by the way.

I am doing a project where you are a whale (Moby Dick) and you must destroy a ship while eating the crew as they fall into the water. I have seemed to work out the boat physics quite well but I do have a few questions.

How do I keep everything on a 2D plane?

What't the easiest way to detect collision force on the boat vs. ship without the water interfering?

Thanks for the help again!


VIP3R(Posted 2010) [#92]

How do I keep everything on a 2D plane?


If you mean lock one axis of the three and restrict it to two axis, you would connect every object to the world with a 2D joint. Have a look at the 2D spheres demo.

Do you mean ship vs whale? You can measure the collision depth with dGeom1CollisionDepth(geom,index) and dGeom2CollisionDepth(geom,index). The water should have no effect other than physical response, for example buoyancy forces. The 'CarDemo-DetailedC' demo shows how to obtain detailed collision data.


Oiduts Studios(Posted 2010) [#93]
Ok, I have the colisions but I have 1 more question, my world is centered around 0,0,10. The joint is at 0,0,0. I can't seem to find a way to position the joint, is this possible?


VIP3R(Posted 2010) [#94]
It's not possible to position/offset the 2D joint on the Z axis, if you create an object at 0,0,10 it will automatically pull the object back to 0,0,0.

The only solution is to move the world center to 0,0,0 and adjust the camera position.


Oiduts Studios(Posted 2010) [#95]
Aww alright, I wish I would of done that first instead of putting it off until last. Thank you for answering my questions


Blitzplotter(Posted 2011) [#96]
VIP3R, I've incorporated Drak's NPC waypoint code into the twin car demo to provide homing missiles within the twin car demo, the code for which I've posted below the image of one of the cars being pounded by homing (ohh, alright, spheres):-




If you want the codeboxes removing let me know :)

The main piece of code



Drak's slightly modified NPC waypoint code for inclusion, note you need it in the same directory as the above code to compile:-



Last edited 2011


VIP3R(Posted 2011) [#97]
The code boxes are fine ;)

You will need to initialise ODE with JV-ODE V1.27+ or you'll get an error.

To do this, add 'dInitODE()' before creating the ODE world...

dInitODE()

Global World=dWorldCreate()



Blitzplotter(Posted 2011) [#98]
Aaaah, I suspect you have identified the root of my problem with getting JV-ODE to work on a new computer I bought. I initially started using JV-ODE on a 'mothballed' older computer, but did some parallel development on the wife's laptop on occasion. I've managed to compile on the wife's laptop for a while, but encountered problems getting JV-ODE to play on my newer 'main' computer.

I've quite a bit of JV-ODE on my various computers, and forgot about the subtle nuances which may've crept in due to my lack of version control. Thanks for pointing out what also may've been my hiccup on my newer computer.

I feel a 'tower defense' style game coming on... using (I think it was Devil's particle engine) the car(s) could have an increasing amount of smoke spewing from them until they cannot take any more & the wheels fall off! Happy New Year.

Last edited 2011


VIP3R(Posted 2011) [#99]
Happy New Year BP :)

If you've got older versions of JV-ODE installed, don't forget to update the 'JV-ODE.decls' file in the Blitz3D userlibs folder when using the latest version of JV-ODE.


Charrua(Posted 2011) [#100]
VIP3R

Hi, i'm testing my Blitz3D JV-ODE dll with xors3d and it seems to work!
is it ok to use it with xors3d?

Juan


VIP3R(Posted 2011) [#101]
Yes, you can use JV-ODE with any 2D or 3D engines.


Charrua(Posted 2011) [#102]
thank's
always very fast and well supported!

Juan


ToeB(Posted 2011) [#103]
I have a problem with the JV-ODE. I write at the moment a racing game, and I have a track as TriMesh. Unfortunately, there are always errors with the car, it suddenly jumps to infinity. I've tried the example with a heightmap as Trimesh, it went smoothly. You know what's wrong?

(Sry 4 the bad Google-translator-english but i cant write that good..)

regards, toeb


VIP3R(Posted 2011) [#104]
Objects jump into infinity like that when something makes the simulation explode.

It can be caused by bad collision contacts (with the TriMesh), or a bad simulation setup.

If the car is stable on a plane (or a large flat cube), it will most likely be the track mesh at fault. To fix it you will need to clean up any imperfections in the mesh before it's converted to a TriMesh.

You could also replace it with the JV-ODE demo TriMesh to determine if it's the simulation setup or the mesh that's the root of the problem.


ToeB(Posted 2011) [#105]
Thank you for your fast help up here. I just use the simplespace instead of the and HashSpace: It Works! (so far). But I got the same "bug" in the TriMesh demo. (BTW: in the demo "CarDemo - TriMesh - X4", i get everytime i touch my car with the spheres of MAV on "dSpaceCollide")


ToeB(Posted 2011) [#106]
Ok now i have a new question. In the ODE-Guide they write:
To model this in ODE set the tire-road contact parameters as follows: set friction direction 1 in the
direction that the tire is rolling in, and set the FDS slip coefficient in friction direction 2 to k v, where
v is the tire rolling velocity and k is a tire parameter that you can chose based on experimentation.
Note that FDS is quite separate from the sticking/slipping effects of Coulomb friction - both modes
can be used together at a single contact point.
(Page 36).

But how i can find out the direction the Tires are rolling in ? I tried to get it with "dBodyGetLinearVelX/Y/Z", but it doesnt work.

My code for Updating the Car:


I hope you can help me.

ToeB


VIP3R(Posted 2011) [#107]
You need to calculate the vector of the wheel direction and use that vector with the dGeomContactSetFDir1() function. If you're not familiar with vectors, you will need to look into 3D math. The code archives has some vector related math functions I believe.

dBodyGetLinearVelX/Y/Z is used to return the linear velocity, not a vector.


Charrua(Posted 2011) [#108]
hi

something like that is what i used, based on some code posted so far on this forums:

this code is executed for each wheel (count=0 to 3)

If DirFric Then
	Local x_component#
	Local y_component#
	Local z_component#
	wheel_angle#=dGeomGetYaw(Auto\Rueda[count]\Geom)
				
	x_component#=Sin(wheel_angle#)*-1.0 
	y_component#=0.0
	z_component#=Sin(wheel_angle#+90.0)
				
	dGeomContactSetMu(Auto\Rueda[count]\Geom,100)
	dGeomContactSetMu2(Auto\Rueda[count]\Geom,10000)
								
	dGeomContactSetFDir1(Auto\Rueda[count]\Geom,x_component#,y_component#,z_component#)
	dGeomContactSetSlip1(Auto\Rueda[count]\Geom,0.001)
				
	Spin#=dJointGetHinge2Angle2Rate(Auto\Rueda[count]\joint)
	dGeomContactSetSlip2(Auto\Rueda[count]\Geom,0.001+(Abs(spin#)/20000))
				
End If



Juan

Last edited 2011


ToeB(Posted 2011) [#109]
Oh nice thanks ! That works pretty good! But one question: Whitch "Mu" or "Mu2" did you set to the Track ?

ToeB


Charrua(Posted 2011) [#110]
hi

look at:
http://blitzbasic.com/Community/posts.php?topic=90169#1025809

regards

btw it works on an horizontal plane (y component not evaluated)

Juan


VIP3R(Posted 2011) [#111]
Thanks Charrua, much appreciated :)


BTW: in the demo "CarDemo - TriMesh - X4", i get everytime i touch my car with the spheres of MAV on "dSpaceCollide"


I wasn't sure if you meant the demo with your code added or not but I looked into it anyway. I haven't been able to recreate the issue here (no MAV) in the default TriMesh X4 demo (on Win7 64-bit), but there have been strange issues fixed by switching from Hash Spaces to Simple Spaces before.


ToeB(Posted 2011) [#112]
No i found out that the error was the incorrect setting up at the begining. So i set the Mode "Slip1" or "FDir1" without setting their Paramteters.. So it caused an Error ;)

Thank you all :)


ToeB(Posted 2012) [#113]
I have another question:
I bought the ODE-Wrapper for BlitzMax, and i want to use it with minib3d. But the problem is that i get an error everytime i use the TriMesh Function. My Code:
SuperStrict 

Import sidesign.minib3d
Import devcode.jvode
Include "include\minib3dODE.bmx"

Graphics3D( 800, 600, 32, 2 )

Type ODEGeom
	Field body:Int
	Field geom:Int
	Field mesh:TMesh
End Type

Global ODEGeomList:TList=CreateList()

' ###################################################################################################

' ### Setup ODE

dInitODE()

Global World:Int=dWorldCreate()
Global Space:Int=dHashSpaceCreate(0)
Global ContactGroup:Int=dJointGroupCreate(0)

dWorldSetAutoDisableFlag(World,1)
dWorldSetGravity(World,0,-0.98,0)
dWorldSetERP(World,0.03)
dContactSetMode(dContactBounce)
dContactSetBounce(0.4)
dContactSetMu(0.4)

' ### Create Light

Global Light:TLight=CreateLight()
PositionEntity Light,-40,70,-40
LightColor Light,255,255,255
AmbientLight 130,130,130

' ### Create Camera

Global Camera:TCamera=CreateCamera()
CameraClsColor Camera,0,0,0
CameraRange Camera,1,1000
PositionEntity Camera,0,50, -70
RotateEntity Camera,30,0,0

' ### Create Plane

dCreatePlane(Space,0,1,0,0)

Global Plane:TMesh=CreatePlane( 1000, 10 )
EntityAlpha Plane,0.8

'EntityTexture Plane,PlaneTexture


Local PTime:Int
Local Timer:Int
Local PhysicsTime:Float

While Not AppTerminate() And Not KeyDown(KEY_ESCAPE)

	If KeyHit(KEY_SPACE) Then 'MilliSecs()-Timer>700
		If PhysicsTime<10 Then AddObject()
		Timer=MilliSecs()
	End If

	UpdateGeoms()

	PTime=MilliSecs()

	dSpaceCollide(Space,World,ContactGroup)
	dWorldQuickStep(World,0.1)
	dJointGroupEmpty(ContactGroup)

	PhysicsTime=MilliSecs()-PTime

	RenderWorld

	'DrawText "JV-ODE Version "+FixFloat(dGetVersion()), 0, 0
	'DrawText "Physics Time:"+FixFloat(PhysicsTime), 0, 15

	Flip 1

Wend

dJointGroupDestroy(ContactGroup)
dSpaceDestroy(Space)
dWorldDestroy(World)
dCloseODE()

End


Function AddObject()

	Local xp:Float
	Local zp:Float
	Local ode:ODEGeom
	
	xp=Rand(-10,10)
	zp=Rand(-10,10)
	
	ode:ODEGeom=New ODEGeom
	ode.body=dBodyCreate(World)
	dBodySetPosition(ode.body,xp,30,zp)
	dBodySetRotation(ode.body,Rnd(360), Rnd(360), Rnd(360))
	dBodySetAngularVeL( ode.body, Rnd( -0.2, 0.2 ), Rnd( -0.2, 0.2 ), Rnd( -0.2, 0.2 ) )
	dBodySetAutoDisableFlag(ode.body,1)
	ode.mesh=LoadMesh("data\TestCar\Coll.b3d")
	ScaleMesh ode.mesh,2,2,2
	EntityColor ode.mesh,Rand(0,255),Rand(0,255),Rand(0,255)
	EntityShininess ode.mesh,0.7
	ode.geom=CreateMiniB3dTriMesh(Space,ode.mesh)
	dGeomSetBody(ode.geom,ode.body)
	ListAddLast(ODEGeomList,ode:ODEGeom)

End Function

' ###################################################################################################

Function UpdateGeoms()

	Local ode:ODEGeom
	
	For ode:ODEGeom=EachIn ODEGeomList
		PositionEntity ode.mesh,dGeomGetPositionX(ode.geom),dGeomGetPositionY(ode.geom),dGeomGetPositionZ(ode.geom)
		RotateEntity ode.mesh,dGeomGetPitch(ode.geom),dGeomGetYaw(ode.geom),dGeomGetRoll(ode.geom)
	Next

End Function


Function CreatePlane:TMesh( s:Float, uvscale:Float=1 )
	Local uv:Float = 1.0 / s * uvscale 
	Local mesh:TMesh = CreateMesh( )
	Local surf:TSurface = CreateSurface( mesh )
	Local v0:Int = AddVertex( surf, -s, 0, -s, 0, 1 )
	Local v1:Int = AddVertex( surf, -s, 0, +s, 0, 0 )
	Local v2:Int = AddVertex( surf, +s, 0, +s, 1, 0 )
	Local v3:Int = AddVertex( surf, +s, 0, -s, 1, 1 )
	AddTriangle( surf, v0, v1, v2 )
	AddTriangle( surf, v0, v2, v3 )
	
	
	Local tex:TTexture = LoadTexture( "data\Plane.png" )
	ScaleTexture( tex, uv, uv )
	EntityTexture( mesh, tex )
	
	Return mesh
End Function


I hope you can help me !


VIP3R(Posted 2012) [#114]
You need to include the CreateMiniB3dTriMesh() function code as it's in a separate file...

Include "Function-CreateMiniB3DTriMesh.bmx"

The file is located in the JV-ODE misc folder.


ToeB(Posted 2012) [#115]
Yes. The Function is in here (Just Renamed the "Function-CreateMiniB3DTriMesh.bmx") :
Include "include\minib3dODE.bmx"


I get this error in the dSpaceCollide- Function (Change the LoadMesh function into "CreateCube" or sth like that, start the program and hit space a few times..


VIP3R(Posted 2012) [#116]
Does it work with the 'torus.b3d' mesh included with JV-ODE?

What happens if you change the type of Space used? For example...

Global Space:Int=dSimpleSpaceCreate(0)

instead of...

Global Space:Int=dHashSpaceCreate(0)


ToeB(Posted 2012) [#117]
Yes, the Sample works. But the Sample uses the JVODEOpenGl-Module as the Framework and not miniB3d.

SimpleSpace didnt work :( got the same error !


ToeB(Posted 2012) [#118]
Btw: Is there any JV-ODE Version for Linux ? I just find win32 Versions!

Thank you


KronosUK(Posted 2012) [#119]
if you have

Global TriBank:TBank
Global VertBank:TBank

in your file "minib3dODE.bmx" rem or delete those lines out.

It would appear each object created needs its own banks which makes sense i guess.

Last edited 2012


ToeB(Posted 2012) [#120]
Lol. I tried this, but i didnt work. Now i tried again, now it works oO

Thanks :D

But is there any Version for Linux or MaxOS ?


VIP3R(Posted 2012) [#121]
JV-ODE is Windows only.


ToeB(Posted 2012) [#122]
Mhm ok. But you wrote the Wrapper, so you have the sourcecode. Is it possible to Compile this for Linux, isnt it ?


VIP3R(Posted 2012) [#123]
It's technically possible, but not without a lot of extra work.

There are no plans for Linux or MacOS versions.


ToeB(Posted 2012) [#124]
Maybe you can send me the code and i do this "extra work". Because i really need a Linux Version. I would only use this code for my Project!

Would be cool. Maybe u can write me an email?
tobias.hendricks@...


VIP3R(Posted 2012) [#125]
Hi ToeB, I sent the following reply to another member of your team via email earlier...

I made the decision long ago that a BlitzMax Linux/MacOS version of JV-ODE would not be developed. One key reason for this was the ever imminent arrival of Max3D, which was intended to have a cross platform ODE module incorporated into it, making the JV-ODE BlitzMax wrapper redundant the moment Max3D was released. When Max3D eventually did get released (ahem), the opportunity was long gone IMO.

I do not supply source code to commercial software. However, if you have the skills that would be necessary to get JV-ODE working on Linux/MacOS, then you have all that is needed to use ODE directly in BlitzMax as a C library (without the need for a wrapper). If you can find a download of the Max3D code, you might be able to use the ODE stuff in there too.