Page 2 of 6
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Thu Aug 18, 2011 5:24 am
by IceSoft
AndyLy wrote:
1) At first, I need a closer look at the documentation. Some things that I wanted to ask, I realized after reading manual. So you will have a break.
A little later I will ask those things which are not understood.
2) P.s. I quite forgot to say while what I see, I like it. It seems super engine! (but Drawing... only Sprites!)
1) Read the docu of Chipmunk 5.3.4 (The 6.x is a little bit different). Look also on the source on the demo folder.
2) Yes it is. If you want to use sprites the best way is to use the MP3D engine (fast, easy, good suppported)
Last but not least:
I am working on an wrapper update...more in some days (I hope).
Maybe I release the new wrapper together with PB4.60.

Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Thu Aug 18, 2011 10:33 am
by AndyLy
Do not see much need for MP3D engine.
I need sprites, not only because of the speed, but also transparency, non-standard form...
By the way a small example. Just do not find out why not rotate the balls.
https://rapidshare.com/files/4220551090/examp.rar
If rapidshare is not convenient, say, another file sharing.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Thu Aug 18, 2011 10:49 am
by gnasen
AndyLy wrote:Do not see much need for MP3D engine.
I need sprites, not only because of the speed, but also transparency, non-standard form...
By the way a small example. Just do not find out why not rotate the balls.
https://rapidshare.com/files/4220551090/examp.rar
If rapidshare is not convenient, say, another file sharing.
Without any code its just guessing.
What values did you choose for mass, moment of inertia and friction (at ball and at the rackets)?
Did you have a look at these topic in the manual "Moment of Inertia and Area Helper Functions"?
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Thu Aug 18, 2011 10:53 am
by AndyLy
Without any code its just guessing.
What values did you choose for mass, moment of inertia and friction (at ball and at the rackets)?....
I'm still learning.
p.s. I could not find a wrapper functions : cpShapeSetElasticity , cpShapeSetFriction.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Thu Aug 18, 2011 2:06 pm
by gnasen
AndyLy wrote:Without any code its just guessing.
What values did you choose for mass, moment of inertia and friction (at ball and at the rackets)?....
I'm still learning.
p.s. I could not find a wrapper functions : cpShapeSetElasticity , cpShapeSetFriction.
Ah okay, they seem to be missing. I never noticed, because I edited the data directly.
You can use the chipmunk.pbi to see the structure of bodys, shapes etc.
This are the most important ones:
Code: Select all
body = cpBodyNew(bla,blub)
body\p\x = Xcoor
body\p\y = Ycoor
body\m = mass
body\i = momentOfInertia
body\v\x = Xvelocity
body\v\y = Yvelocity
body\f\x = Xforce
body\f\y = Yforce
body\a = angle
body\t = torque
shape = cpPolyShapeNew(bla,blub,gna,wup)
shape\e = elasticity
shape\u = friction
shape\collision_type = collision_layers
shape\group = collision_groups
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Thu Aug 18, 2011 3:21 pm
by IceSoft
AndyLy wrote:
By the way a small example. Just do not find out why not rotate the balls.
"?
I belive the balls are rotating but nut your sprites
AndyLy wrote:p.s. I could not find a wrapper functions : cpShapeSetElasticity , cpShapeSetFriction.
I will add it with the next update.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Thu Aug 18, 2011 3:54 pm
by AndyLy
gnasen
Oh, yes, thank you! Now the balls are push away and rotate. It's pretty realistic.
I tried to understand himself that the data in structure but they are marked by 1-2 letters, so that I could not.
Add :
I can not stop the boxes. I tried to set up and the elasticity and friction, they are still swimming. (source included)
What's wrong with me?
https://rapidshare.com/files/1838229637/examp.rar
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Thu Aug 18, 2011 8:16 pm
by gnasen
AndyLy wrote:What's wrong with me?
I guess nothing with you, but with some settings you use
1. dont use .l for long anymore! Just use .i instead or you may get trouble with 64bit systems.
2. you have to get a little feeling for physical values. Youre gravity is with 900 much to high. Try 100 or something like that (in my main project I use 30) and enjoy the difference

. If everything becomes to "slow", just increase the timestep. Otherwise the bricks are pressed into each other with a very high force. No chance for the solver to get a stable environment.
3. You made your ground bouncy (elasticity <> 0). Sure you want that?
4. You made your ground very flushy. With friction 0, there is no friction at all. So the brick at the bottom may slip away
5. You increased the value of *space\iterations very much. Better dont sacrifice your CPU on this way, better lower youre timestep in cpSpaceStep()
6. I dont know if its already documented in the help files, but you have to increase the value of *space\elasticIterations to maybe 5. Otherwise there is no bouncing.
Thats all I found, most mistakes are not your fault, but the the docs (they are very.... imprecise).
You already did a very good start, so try to include my hints into your code and it should be fine.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Thu Aug 18, 2011 10:05 pm
by AndyLy
I guess nothing with you
The doctor says another.
Thanks for the tips.
Well I tried all the settings that you suggested to me. By many manipulations I was able to to achieve sustainability in the construction 18 rows and more or less realistic fall. But at increase in quantity rows-again destabilization. Why friction between the blocks does not extinguish the forces acting on the block?
My brain does not work anymore. I tried all the settings. You can certainly make the construction to be stable, but it will not behave realistically.
Maybe there is some way to limit (do not know) of their interaction between the blocks?
P.s. Okay, I will not build such construction. Question withdrawn.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Fri Aug 19, 2011 10:05 am
by AndyLy
Guys, I honestly tried to understand the definition of the collision, but did not understand. I am lost in all these Arbiter, Handler, Callback ....
Could you explain more simple (or an example on PureBasic):
I have 2 object, how to determine a collision between them and how to determine whether the object collided with anything at all?
Code: Select all
*mybody = cpBodyNew(1, cpMomentForCircle(1, 0,24, cpv(cpvzero,0,0)) ): cpSpaceAddBody(*space,*mybody)
*myshape=cpCircleShapeNew(*mybody, radius, @cpvzero): cpSpaceAddShape(*space,*myshape)
*mybody2 = cpBodyNew(1, cpMomentForBox(1, 170,20)): cpSpaceAddBody(*space,*mybody2)
*myshape2=cpBoxShapeNew(*mybody2, 170,20): cpSpaceAddShape(*space,*myshape2)
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Fri Aug 19, 2011 12:21 pm
by gnasen
this is not running code, but a how-to:
Code: Select all
;first you have to give your shape a collision type, like
#ball=1
#wall=2
*myshape1\collision_type = #ball
*myshape2\collision_type = #ball
*myshape3\collision_type = #wall
;in the callbacks we want to get the bodies to get for example the collision coordinates
*myshape1\data = *mybody1
*myshape2\data = *mybody2
*myshape3\data = *mybody3
;now if you want to get the collision between a ball and a wall, create a collision handler:
cpSpaceAddCollisionHandler(*space, #ball, #wall, @col_begin(), @col_preSolve(), @col_postSolve(), @col_seperate(), #Null)
;these one is now mapping to the functions:
ProcedureC col_begin(*arb.cpArbiter, *space.cpSpace, *pData)
Debug "begin"
ProcedureReturn #true
EndProcedure
ProcedureC col_preSolve(*arb.cpArbiter, *space.cpSpace, *pData)
Debug "pre"
ProcedureReturn #true
EndProcedure
ProcedureC col_postSolve(*arb.cpArbiter, *space.cpSpace, *pData)
Debug "post"
ProcedureReturn #true
EndProcedure
ProcedureC col_seperate(*arb.cpArbiter, *space.cpSpace, *pData)
Debug "seperate"
ProcedureReturn #true
EndProcedure
;the arbiter gives you every information about the collision you need.
;But never store the pointer to the arbiter itself!
;Outside of this callback it may not exist anymore.
;So grab your information and go, too example:
ProcedureC col_begin(*arb.cpArbiter, *space.cpSpace, *pData)
;we stored the body pointer in the shapes data. This can be found in *arb\private_a\data etc, so now we can get the bodies
Protected *bodyA.cpbody = *arb\private_a\data
Protected *bodyB.cpbody = *arb\private_b\data
Debug "new collision at " + StrF(*bodyA\v\x,2) + " " + StrF(*bodyA\v\y,2)
ProcedureReturn #true
EndProcedure
;if you want to get collision between the two balls, you can just add a new handler:
cpSpaceAddCollisionHandler(*space, #ball, #ball, @col_begin(), @col_preSolve(), @col_postSolve(), @col_seperate(), #Null)
;the callback functions can be the same or differ, your choice.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Fri Aug 19, 2011 1:09 pm
by AndyLy
Thank you very much for your patience! Give God your health!
One thing which I could not understand before, how this handler link to the desired object. I still do not fully understand: collision_type must be a unique number for each object?
P.s. I just quickly tried, works.
By the way, how easily address to any object to change the data? Any id? Or do I need to create variables * myshape1, * myshape2, ... I would like to create a list of my objects, then to access them.
How to get a impulse received body at collision? Empirically determined that this body\w , but not sure.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sat Aug 20, 2011 9:35 am
by gnasen
AndyLy wrote:Thank you very much for your patience! Give God your health!
One thing which I could not understand before, how this handler link to the desired object. I still do not fully understand: collision_type must be a unique number for each object?
The collision_type of an object is used in the handler. If you have too example some balls bouncing on the ground, you maybe dont want to know, if the balls are colliding. In this case, you give everyball the same ID and all the walls a different ID (too example: all balls:1, all walls: 2). If you create the handler, you have to choose 2 collision types. If you choose balls and walls, you get the collision between any ball and any wall. If you choose ball and ball, you get every collision between two balls.
Its just like a filter. Otherwise you may get too much information if you have much objects
AndyLy wrote:
P.s. I just quickly tried, works.
By the way, how easily address to any object to change the data? Any id? Or do I need to create variables * myshape1, * myshape2, ... I would like to create a list of my objects, then to access them.
If you want to store data for later use, you should normally use lists. I use something like this. Its just an example, no runable code:
Code: Select all
Structure object
*body.cpbody
*shape.cpshape
allOtherInfosYouWantToStore.i
EndStructure
Global NewList obj.object()
Procedure createBall()
AddElement(obj())
obj()\Body = cpBodyNew......
obj()\shape = cpCircleShape.....
obj()\allOtherInfosYouWantToStore = ....
EndProcedure
ForEach obj()
Debug StrF(obj()\Body\p\x,2) + " " + StrF(obj()\Body\p\y,2)
Next
AndyLy wrote:
How to get a impulse received body at collision? Empirically determined that this body\w , but not sure.
I never used it till now, but in the help is written:
Code: Select all
cpVect cpArbiterTotalImpulse(cpArbiter *arb);
cpVect cpArbiterTotalImpulseWithFriction(cpArbiter *arb);
Returns the impulse that was applied this step to resolve the collision. These functions should only be called from a postStep() or cpBodyEachArbiter() callback, otherwise the result is undefined.
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sat Aug 20, 2011 12:09 pm
by AndyLy
Thank you. Here's a new demo. Amuse myself with different types and species. How does the physics? I set it realistic?
https://rapidshare.com/files/3679789413/examp.rar
Re: Who is also working on a Chipmunk wrapper (2D physic eng
Posted: Sat Aug 20, 2011 1:44 pm
by gnasen
well done, but it seems to be a problem with the collision ball<->iceblock. In some cases the program quits with an error. Division by zero or something like that?