NearCallback in ode anyone?

BlitzMax Forums/BlitzMax Programming/NearCallback in ode anyone?

AntonyWells(Posted 2006) [#1]
Anyone know what you have to do in the near callback in ode?

We've got Mark's ode module compiling ok in 1.18 and have an example from vectrex that demonstrates how to use it, but the only example I can find of the near callback is in C++(Not a problem really, just means we can't test it in max)

Any examples of the simpliest one possible with just collision response?


Damien Sturdy(Posted 2006) [#2]
1.18? You're a version behind :-)

Sorry I couldn't help much Ant, It's just not what I remember :)


AntonyWells(Posted 2006) [#3]
Yeah I'm suspicious about updating bmax, usually breaks something or needs modules re compiling.

We have to find somewhere where there are people who would know. Can't see newton being a good enough replacement.


AntonyWells(Posted 2006) [#4]
I wrote a callback and implemented a test using aurora.

Strict
Import "Aurora.bmx"
Import "Ode.bmx"

Const Max_Contacts = 40
Global ode_actworld,ode_actGroup
Function NearCallBack( data:Byte Ptr,o1:Int,o2:Int )
	Local b1:Int,b2:Int
	 b1 = dGeomGetBody(o1);
	 b2 = dGeomGetBody(o2);

	If b1 And b2 And dAreConnectedExcluding( b1,b2,dJointTypeContact)
		Return 
	End If
	Local cons:dContact[Max_Contacts]
	For Local i=0 Until Max_Contacts
		cons[i] = New dContact
		cons[i].mode = dContactBounce | dContactSoftCFM
		cons[i].mu = dInfinity
		cons[i].mu2 = 0
		cons[i].bounce = 0.1
		cons[i].bounce_vel = 0.1
		cons[i].soft_cfm = 0.01
	Next
	
	Local numc:Int = dCollide( o1,o2,max_contacts,Byte Ptr(cons[0]),SizeOf(dContact) )
	Print "Collisions:"+numc
	If numc
		
		For Local i:Int = 0 Until numc
			Local jid = dJointCreateContact( ode_actworld,ode_actgroup,Byte Ptr(cons[i]) )
			dJointAttach( jid,b1,b2 )
		Next
	EndIf
	
End Function


Local fp:Byte Ptr = Byte Ptr( nearcallback )

Local Display:TDisplay = TDisplay.Create()
Display.OpenScreen()

Global World        : Int
Global Space        : Int

Global BoxBody      : Int
Global BoxMass      : dMass
Global BoxGeom      : Int
Local BoxM:TEntity 

Global PlaneGeom    : Int
Global PlaneMesh    : TEntity

Global Camera       : TCamera = tCamera.Create()

Global Position     : Float Ptr



' Erstelle Welt
World = dWorldCreate()
dWorldSetGravity(World, 0.0, -0.01, 0.0)

' Erstelle Raum
Space = dHashSpaceCreate(0)

' Erstelle Box
BoxBody = dBodyCreate(World)
dBodySetPosition(BoxBody, 0.0, 40.0, 0.0)

BoxMass = New dMass
dMassSetBoxTotal(BoxMass, 0.01, 2.0, 2.0, 2.0)
dBodySetMass(BoxBody, BoxMass)

BoxGeom = dCreateBox(Space, 2.0, 2.0, 2.0)
dGeomSetBody(BoxGeom, BoxBody)

BoxM = TEntity.CreateMesh("box.mesh")
BoxM.Scale(2.0, 2.0, 2.0)
BoxM.Position(0.0, 40.0, 0.0)

' Erstelle Boden
PlaneGeom = dCreatePlane(Space, 0.0, 1.0, 0.0, 0.0)
PlaneMesh = TPrefab.Plane(100,100)

ode_actgroup = dJointGroupCreate( 0 )
ode_actworld = world 

' Erstelle Kamera
Camera.Position(0.0, 10.0, 50.0)
Camera.LookAt( 0,0,0 )

'PlaneMesh.SetMaterial("dirt")

BoxM.setmaterial("dirt")

While Not KeyDown(KEY_ESCAPE)
	dSpaceCollide( space,Null,fp )
	dWorldQuickStep(World, 0.1)
	dJointGroupEmpty( ode_actGroup) 
	If dBodyIsEnabled(BoxBody) Then
		Position = dGeomGetPosition(BoxGeom)
		BoxM.Position(Position[0],Position[1],Position[2])
	EndIf
	
	Render3D()
	CaptureInput()



Wend




But it fails in the callback on the joint creation saying Dnormalize4 was based a zero value.


skidracer(Posted 2006) [#5]
You could try:

Function NearCallBack( data:Byte Ptr,o1:Int,o2:Int ) "C"


AntonyWells(Posted 2006) [#6]
I don't think it's that, as it appears to enter the function fine. I put a debugstop in there. and the problem is definitely this line,

Local jid = dJointCreateContact( ode_actworld,ode_actgroup,Byte Ptr(cons[i]) )

As soon as the geom(The box) hits the floor plane it disappears and ode starts spouting out an error message saying dNormalize4() was passed a zero value.

This is pointing me off wrapping real ode in C++ cos I'm not sure if i'll just get the same error again or it's a bmax problem .


AntonyWells(Posted 2006) [#7]
Here's an excerpt from the output textarea.

[code]
Collisions:0
Collisions:0
Collisions:0
Collisions:0
Collisions:0
Collisions:3
ODE Message 2: vector has zero size in dNormalize4()
ODE Message 2: vector has zero size in dNormalize4()
ODE Message 2: vector has zero size in dNormalize4()
ODE Message 2: vector has zero size in dNormalize4()
ODE Message 2: vector has zero size in dNormalize4()
ODE Message 2: vector has zero size in dNormalize4()
ODE Message 2: vector has zero size in dNormalize4()
ODE Message 2: vector has zero size in dNormalize4()
ODE Message 2: vector has zero size in dNormalize4()
[/quote]

As you can see it happens as soon as the first collisions are registered.


Vectrex(Posted 2006) [#8]
what did I show you? :) Btw I'm really not sure why you guys think newton isn't as stable as ode. It's probably the way you're using it, with direct positioning which is naughty ;)


Damien Sturdy(Posted 2006) [#9]
with direct positioning which is naughty



We only use direct positioning when reseting an entity
however, i do modify rotary velocities, to simulate a hovery bounce using only a tiny amount of CPU. It's also useful in other ways. In a previous project I used physics to interpolate networking. For that to work i needed to directly set velocities.

Is there a way to set velocities? Havent had a chance to look yet! :)


AntonyWells(Posted 2006) [#10]
We've switched back to newton Vectrex and have changed game to something less demanding than a vehicle based game.


skidracer(Posted 2006) [#11]
dContact will be expecting an array of objects (not references which a BlitzMax object array is giving you), try using a using a bank.


AntonyWells(Posted 2006) [#12]
I'm getting a pointer to the first first object in the array though. Isn't that the same thing?

I mean doesn't bmax reserve an array of objects as one contigous(sp?) block of memory like C++? If not that's definitely the problem.


Damien Sturdy(Posted 2006) [#13]
I'd have used a bank anyway? :)


skidracer(Posted 2006) [#14]
The command cons[i] = New dContact allocates memory for a single dContact and stores it's reference in the BlitzMax array...


Vectrex(Posted 2006) [#15]
"Is there a way to set velocities? Havent had a chance to look yet! :) "

yeah in Aurora I think it's TBody:setVeloc, the only abbreviated command ;)

ps Ant, here's a few newton suggestions for the engine I noticed are missing


Vectrex(Posted 2006) [#16]
"Is there a way to set velocities? Havent had a chance to look yet! :) "

yeah in Aurora I think it's TBody:setVeloc, the only abbreviated command ;) plus in OgreNewt there setOmega which is direct rotation speed setting... which are also both naughty, but I'm guilty of it in networking too ;) btw newton's direct vel/omega setting is pretty good, he worked on getting it as correct as possible (for moving static geometry around)

ps Cygus, I would probably try a hovercraft with 4 rays for each corner and adjust the force depending on distance and 'levelness' of the craft. Then you'd get the hovery effect anyway.

ps Ant, here's a few newton suggestions for the engine I noticed are missing.. at least in the old version I'm playing with
- TBody:setContinuousCollision - newton can handle very fast objects at low tick rates in this mode
- TBody:pushLocal - eg push(0,0,0,0,0,1) to push forward regardless of rotation. I noticed FMC does some weird stuff with tforms to achieve this. Newton has global and local forces on a body (in ogrenewt addLocalForce, addGlobalForce). btw the force probably should have been the first param with the second optional, but eh :)
- TInput doesn't seem to map all keys, like... space! :)
- Any joints going in?


Chris C(Posted 2006) [#17]
Have a look on my site for a working callback routine that works!, (I had to come back to it a number of times!)

I've also implemented custom surface types and an "behaviour matrix" I'm not sure if thats in the public version tho.


Damien Sturdy(Posted 2006) [#18]
setOmega which is direct rotation speed setting
Thats the one :-) Thanks.


I would probably try a hovercraft with 4 rays for each corner and adjust the force depending on distance and 'levelness' of the craft. Then you'd get the hovery effect anyway.


Yup. We implemented this in ODE in the end to give a more accurate result. it failed to work at the time but it was proven to be a logic flaw. This would have been how we did it in the final version.

Thanks for your help.


AntonyWells(Posted 2006) [#19]

The command cons[i] = New dContact allocates memory for a single dContact and stores it's reference in the BlitzMax array...


Ah you're right. So is there no way to create a block of types? Like in C++ I would do,

       dContact cons[MAX_CONTACTS]


and it would be an array of contacts because it's all assigned at once.

Failing that, is there a way to cast a byte ptr into a type so I can do this,

Bank = CreateBank( SizeOf(DContact)*MaxContacts )

local con:DContact = DContact( BankBuf( Bank) )

Like in C++?


AntonyWells(Posted 2006) [#20]

Have a look on my site for a working callback routine that works!, (I had to come back to it a number of times!)

I've also implemented custom surface types and an "behaviour matrix" I'm not sure if thats in the public version tho.



Do you have a direct link? I looked but can't find it.


Chris C(Posted 2006) [#21]
promise to donate £5 for every past and future sale of Aurora to the Ogre3d project and I might be more forth comming....


AntonyWells(Posted 2006) [#22]
Oh teh noes.


Fool.


Chris C(Posted 2006) [#23]
no the only fools are the ones you scammed for £40 who'll be real disapointed in a years time, when you fail to continue suporting this engine like your last


AntonyWells(Posted 2006) [#24]
Yeah because a man can never change or learn from his mistakes, he's destined to repeat them over and over again.

What a dim, narrow little opinon you have of others. it's sad.


Chris C(Posted 2006) [#25]
What a dim, narrow little opinon you have of others. it's sad.

no just your use of open source libraries without putting back something


AntonyWells(Posted 2006) [#26]
Don't assume to know everything, I offered Sinbad 10% of each sale but he didn't even respond.
Or are you suggesting I donate 10% in his name to oxfam or something?

As soon as you donate 10% of your wages to oxfam I'll follow suit.


Chris C(Posted 2006) [#27]
yeah right i seriously doubt you did hes very aprochable and has previously replyed to be just regarding sourceforge cvs issues so I dont honestly believe you made the offer

and why didnt you just use this link
http://sourceforge.net/donate/index.php?group_id=2997

As soon as you donate 10% of your wages to oxfam I'll follow suit.

so auroras 100% of your wages gosh you must be poor!


AntonyWells(Posted 2006) [#28]
I asked him in public on the ogre forums, it won't take you long to track down the offer.

And yes Aurora is 100% of my wages and I am poor. Anything else?


Chris C(Posted 2006) [#29]
then do somthing that pays

did a search for aurora on the public forums nothing


AntonyWells(Posted 2006) [#30]
Looked in the general discussion form post started by someone asking 'is this right?' in regards to aurora wrapping ogre.

Sinbad was fine with it, even thanking me for correcting some mistakes that didn't adhere to the license the way I should have.
It was then I asked him. he ignored the question and just thanked me for changing the license thing.


Chris C(Posted 2006) [#31]
there is still code on my site that will solve you problem you could always check it out if youve finished insulting me


AntonyWells(Posted 2006) [#32]
Lol drama queen I've not insulted you once other than calling you a fool in response to a snotty remark.

Grow up.


Chris C(Posted 2006) [#33]
how was asking you to donate to the ogre project snotty you snot nosed kid :D I can do it too. idiot


AntonyWells(Posted 2006) [#34]
I'm 23, not a kid chris, probably ten years older than you juding by your posts :P


Chris C(Posted 2006) [#35]
lol lucky if you reach 24 :))


AntonyWells(Posted 2006) [#36]
You'll be lucky too, cos then you get to use my superior version of ogre for max. :)


Damien Sturdy(Posted 2006) [#37]
...Can you stop the childish bickering? :/