[Chipmunk2D4PB] 2D Physics Engine

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
djes
Addict
Addict
Posts: 1806
Joined: Sat Feb 19, 2005 2:46 pm
Location: Pas-de-Calais, France

Re: [Chipmunk4PB] v0.1 is released (2D Physic Engine Wrapper

Post by djes »

Thank you! :D
atomo
User
User
Posts: 65
Joined: Thu May 22, 2008 10:32 pm

Re: [Chipmunk4PB] v0.1 is released (2D Physic Engine Wrapper

Post by atomo »

Thanks, i was working on a wrapper too, it will be usefull :)
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [Chipmunk4PB] v0.1 is released (2D Physic Engine Wrapper

Post by IceSoft »

atomo wrote:Thanks, i was working on a wrapper too, it will be usefull :)
I know.
But it will be better you use/test the Chipmunk4PB wrapper and write some examples too ;-)
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
atomo
User
User
Posts: 65
Joined: Thu May 22, 2008 10:32 pm

Re: [Chipmunk4PB] v0.1 is released (2D Physic Engine Wrapper

Post by atomo »

i'll do :wink:
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [Chipmunk4PB] v0.1 is released (2D Physic Engine Wrapper

Post by IceSoft »

A window with 10 bouncing boxes
Development time: 10min
http://www.morty-productions.de/icesoft ... Bounce.zip
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Suirad
User
User
Posts: 42
Joined: Sun Sep 20, 2009 7:37 pm
Location: Melbourne, Florida, USA

Re: [Chipmunk4PB] v0.1 is released (2D Physic Engine Wrapper

Post by Suirad »

IceSoft wrote:A window with 10 bouncing boxes
Development time: 10min
http://www.morty-productions.de/icesoft ... Bounce.zip
would be nice to see the source
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [Chipmunk4PB] v0.3 released (2D Physic Engine Wrapper)

Post by IceSoft »

Chipmunk4PB v0.3 released
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
eddy
Addict
Addict
Posts: 1479
Joined: Mon May 26, 2003 3:07 pm
Location: Nantes

Re: [Chipmunk4PB] v0.3 released (2D Physic Engine Wrapper)

Post by eddy »

Nice. :)

I tried an old sample (4.X.X).
It works great but I can't detect any collision.

- Does collision detection work ? (cpArrayEach)
- Your cpSpaceEachBody function has 4 arguments. I didn't found this 4th in chipmunk doc ?

Here is my example :

Code: Select all

XInclude "Chipmunk4PB_v0.3.pbi"

Global *space.cpSpace
Global *staticBody.cpBody
Global ticks

Procedure DrawPolyShape(*poly.cpPolyShape)
	Protected *verts.cpVect=*poly\verts
	Protected *last.cpVect
	Protected v.cpVect
	Protected first.cpVect
	Protected last.cpVect
	
	*last=*verts+SizeOf(cpVect)*(*poly\numVerts-1)
   cpvrotate(v, *last, *poly\shape\body\rot)
   cpvadd(v, v, *poly\shape\body\p)
	cpv(last, v\x, v\y)
	
	For i=0 To *poly\numVerts-1
		cpvrotate(v, *verts, *poly\shape\body\rot)
	   cpvadd(v, v, *poly\shape\body\p)
      LineXY(last\x, last\y, v\x, v\y, RGB(0, 0, 0))
		cpv(last, v\x, v\y)
		*verts+SizeOf(cpVect)
	Next
   Circle(*poly\shape\body\p\x, *poly\shape\body\p\y, 2, RGB(0, 0, 255))
EndProcedure
Procedure DrawCircleShape(*circle.cpCircleShape)
   Protected x=*circle\tc\x
   Protected y=*circle\tc\y
   Protected r.f=*circle\r
   Protected a.f=*circle\shape\body\a
   Circle(x, y, r)
   LineXY(x, y, x+Cos(a)*r, y+Sin(a)*r)
EndProcedure
Procedure DrawSegmentShape(*seg.cpSegmentShape)
	Protected a.cpVect
	Protected b.cpVect
   
   cpvrotate(a, *seg\a, *seg\shape\body\rot)
   cpvrotate(b, *seg\b, *seg\shape\body\rot)
	cpvadd(a, a, *seg\shape\body\p)
	cpvadd(b, b, *seg\shape\body\p)
   
   LineXY(a\x, a\y, b\x, b\y, RGB(0, 0, 0))
EndProcedure
ProcedureC DrawShape(*shape.cpShape, *datas)
   Select *shape\klass\type
      Case #CP_CIRCLE_SHAPE
         DrawCircleShape(*shape)
      Case #CP_SEGMENT_SHAPE
         DrawSegmentShape(*shape)
      Case #CP_POLY_SHAPE
         DrawPolyShape(*shape)
   EndSelect
EndProcedure
ProcedureC DrawCollisions(*arbiter.cpArbiter, *datas)
   Protected i
   For i=0 To *arbiter\numContacts-1
      *contacts.cpContact=*arbiter\contacts+SizeOf(cpContact)*i
      Circle(*contacts\p\x, *contacts\p\y, 2, #Red)
   Next
EndProcedure
ProcedureC FixBodyPositions(*body.cpBody, *datas)
   ;check if object is offscreen
   If *body\p\y>500 Or *body\p\x>680 Or *body\p\x<-20
		;reset its position if necessary
		*body\p\x=Random(640)
		*body\p\y=-20*Random(30)
   EndIf
EndProcedure


Procedure InitObjects()
   Protected *shape.cpShape
   Protected *body.cpBody
   Protected i, j
   
   cpInitChipmunk()
   cpResetShapeIdCounter()
   
   ;{/// PHYSIC ENVIRONMENT
   *staticBody=cpBodyNew(#INFINITY, #INFINITY)
   
   *space=cpSpaceNew()
	*space\iterations=5
   cpv(*space\gravity, 0, 100)
	cpSpaceResizeStaticHash(*space, 40.0, 999)
	cpSpaceResizeActiveHash(*space, 30.0, 2999)
   ;}
   
   ;{/// TRIANGLES
   Dim TRIANGLE.cpVect(3)
   cpv(TRIANGLE(0), 15, 15)
   cpv(TRIANGLE(1), 0, -10)
   cpv(TRIANGLE(2), -15, 15)
   
   For i=0 To 8
      For j=0 To 5
         s.l=j%2
         Protected stagger.f=s*40
         Protected offset.cpVect
         cpv(offset, i*80+stagger, 100+(j*70) )
         *shape=cpPolyShapeNew(*staticBody, ArraySize(TRIANGLE()), @TRIANGLE(), offset)         
         *shape\e=1.0
         *shape\u=1.0                 
         cpSpaceAddShape(*space, *shape)
      Next
   Next
   ;}
   
   ;{/// FALLING COINS
	Dim COIN.cpVect(5)
   For i=0 To ArraySize(COIN())-1
      Protected angle.f=-2*#PI*i/ArraySize(COIN())
      cpv(COIN(i), 10*Cos(angle), 10*Sin(angle))
      Debug Str(10*Cos(angle))+" "+Str(10*Sin(angle))
   Next
   
   For i=0 To 299
      *body=cpBodyNew(1.0, cpMomentForPoly(1.0, ArraySize(COIN()), @COIN(), cpvzero))
      cpv(*body\p, Random(640), -20*Random(200) )      
      cpSpaceAddBody(*space, *body)
      
      *shape=cpPolyShapeNew(*body, ArraySize(COIN()), @COIN(), cpvzero)
      *shape\e=0.0
      *shape\u=0.4
      cpSpaceAddShape(*space, *shape)
   Next
   ;}
EndProcedure
Procedure MoveObjects()
   ticks+1
   Protected steps.f=1.0
   Protected dt.f=1.0/60.0/steps
   Protected i
   For i=0 To steps
      cpSpaceStep(*space, dt)
      cpSpaceEachBody(*space, @FixBodyPositions(), #Null, #Null)
   Next   
EndProcedure
Procedure DrawObjects()
   ClearScreen(RGB(255, 255, 255))
   StartDrawing(ScreenOutput())
      DrawingMode(#PB_2DDrawing_Outlined)
      cpSpaceHashEach(*space\activeShapes, @DrawShape(), #Null)
      cpSpaceHashEach(*space\staticShapes, @DrawShape(), #Null)
      DrawingMode(#PB_2DDrawing_Default)
      cpArrayEach(*space\arbiters, @DrawCollisions(), #Null)
   StopDrawing()
   FlipBuffers()   
EndProcedure
Procedure FreeObjects()
   cpSpaceFree(*space)
   cpBodyFree(*staticBody)
EndProcedure

InitSprite()
InitKeyboard()
InitObjects()

OpenWindow(100, 0, 0, 640, 480, "Test : Chipmunk 4.1.0 / 5.X.X - PACHINKO", #PB_Window_ScreenCentered | #PB_Window_SystemMenu)
OpenWindowedScreen(WindowID(100), 0, 0, 640, 480, 0, 0, 0)
Repeat
   DrawObjects()
   MoveObjects()
   ExamineKeyboard()
Until KeyboardPushed(#PB_Key_Escape) Or WaitWindowEvent(1)=#PB_Event_CloseWindow
FreeObjects()
End
Imagewin10 x64 5.72 | IDE | PB plugin | Tools | Sprite | JSON | visual tool
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [Chipmunk4PB] v0.3 released (2D Physic Engine Wrapper)

Post by IceSoft »

eddy wrote:It works great but I can't detect any collision.
- Does collision detection work ? (cpArrayEach)
- Your cpSpaceEachBody function has 4 arguments. I didn't found this 4th in chipmunk doc ?
Both are fixed. Will come with the next version.
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [Chipmunk4PB] v0.3 released (2D Physic Engine Wrapper)

Post by IceSoft »

Short demo: shows the collisionshandler functions

http://www.morty-productions.de/icesoft ... andler.zip
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [Chipmunk4PB] v0.4 released (2D Physic Engine Wrapper)

Post by IceSoft »

Update: Chipmunk4PB_v0.4:
Demo (with Source) +Collisionshandler +Constraints
Have fun!
Download link:
http://www.morty-productions.de/icesoft ... unk4PB.zip
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [Chipmunk4PB] v0.4 released (2D Physic Engine Wrapper)

Post by IceSoft »

I created an own forum for the Chipmunk4PB Wrapper:
http://chipmunk4purebasic.freeforums.org/index.php
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
DoubleDutch
Addict
Addict
Posts: 3219
Joined: Thu Aug 07, 2003 7:01 pm
Location: United Kingdom
Contact:

Re: [Chipmunk4PB] v0.4 released (2D Physic Engine Wrapper)

Post by DoubleDutch »

Thanks for the info, will join your forum later today. :)

but, imho, either this or Box2D needs to be built-in to the PB native libs.
https://deluxepixel.com <- My Business website
https://reportcomplete.com <- School end of term reports system
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [Chipmunk4PB] v0.4 released (2D Physic Engine Wrapper)

Post by IceSoft »

Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
IceSoft
Addict
Addict
Posts: 1616
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: [Chipmunk4PB] 7.01 Preview (2D Physic Engine Wrapper)

Post by IceSoft »

After a long time:
Chipmunk4PB_7.01 (preview) is available:
(it works well)

Download:
http://www.morty-productions.de/icesoft ... B_7.01.zip (143.4 KB)

Please replace on HelloNewton2D_Chipmunk4PB.pb (line 140):

Code: Select all

cpSpaceStep(*space, 0.1) with   cpSpaceStep(*space, timeStep)
Contains:
PB example file: Chipmunk4PB_7.01\HelloNewton2D_Chipmunk4PB.pb
Residents file: Chipmunk4PB_7.01\Residents\Chipmunk4PB.res
UserLibrary: Chipmunk4PB_7.01\UserLibraries\Chipmunk4PB
How to configure it:
1) Copy the Chipmunk4PB.res into folder "PureBasic\Residents"
2) Copy the Chipmunk4PB into folder "PureBasic\UserLibraries"
How to test/use it:
1) Start PureBasic => load "HelloNewton2D_Chipmunk4PB.pb" => run this example
Belive!
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Post Reply