moteur physique

Programmation avancée de jeux en PureBasic
beauregard
Messages : 1307
Inscription : dim. 08/juil./2007 18:32
Localisation : Toulouse

moteur physique

Message par beauregard »

Suite au code chipmunk-demo et des bibliothèques chipmunk et chipmunk( uniquement windows) élaboré par eddy:
http://www.purebasic.fr/english/viewtopic.php?t=31022
j'ai bien essayé de comprendre le pourquoi du comment, mais j'ai rien compris. Néanmoins, j'ai fait des petits trucs en partant de la 4eme demo, et çà donne çà:
Image
C'est un moteur fantastique et j'ai bien fait mumuse :)
Question: est ce que Ogre a son propre moteur physique ? Si non, j'espère que çà va remonter aux oreilles de Fred.
le code suivant est une modif du code original nommé chipmunkDemoMain.pb

Code : Tout sélectionner

;
; Try to make the chipmunk-demo available in PB !
; auteur eddy( grand merci :) ) et légèrement modifié par beauregard:
; intéraction avec le grand carré de la Demo 4( touche 4)
; touches fléchées du clavier gauche et droite.
;

XIncludeFile #PB_Compiler_Home + "Includes\chipmunk_include.pbi" ; Hum !

Define *space, *staticBody ; avec des asterix, çà déchire !
Global INFINITY.f = 1e1000
Global sensrotation.f ; 1er rajout: une variable, hum.

Structure sDemo  ; çà c'est de la bonne variables ma bonne dame, vous pouvez m'en croire !
  *start
  *update
  *destroy
EndStructure

Dim Demos.sDemo(7)

Procedure LinePro (hdc.l,x1.l,y1.l,x2.l,y2.l,width.l,color.l); sept trucs, 7 ! 
  pen.l=CreatePen_(#PS_SOLID,width.l,color.l)
  hPenOld.l=SelectObject_(hdc.l,pen.l)
  MoveToEx_(hdc.l,x1.l,y1.l,0):LineTo_(hdc.l,x2.l,y2.l)
  DeleteObject_(pen.l)
  DeleteObject_(hPenOld.l)
EndProcedure

Procedure CirclePro (hdc.l,x1.l,y1.l,radius.l,width.l,color.l)
  pen.l=CreatePen_(#PS_SOLID,width.l,color.l)
  hPenOld.l=SelectObject_(hdc.l,pen.l)
  Ellipse_(hdc.l,x1.l-(radius.l/2),y1.l-(radius.l/2),x1.l+radius.l,y1.l+radius.l)
  DeleteObject_(pen.l)
  DeleteObject_(hPenOld.l)
EndProcedure

Procedure BoxPro (hdc.l,x1.l,y1.l,x2.l,y2.l,width.l,color.l)
  pen.l=CreatePen_(#PS_SOLID,width.l,color.l)
  hPenOld.l=SelectObject_(hdc.l,pen.l)
  Rectangle_(hdc.l,x1.l,y1.l,x1+x2.l,y1+y2.l)
  DeleteObject_(pen.l)
  DeleteObject_(hPenOld.l)
EndProcedure


Procedure RoundedBoxPro (hdc.l,x1.l,y1.l,x2.l,y2.l,corner.l,width.l,color.l)
  pen.l=CreatePen_(#PS_SOLID,width.l,color.l)
  hPenOld.l=SelectObject_(hdc.l,pen.l)
  RoundRect_(hdc.l,x1.l,y1.l,x1.l+x2.l,y1.l+y2.l,corner.l,corner.l)
  DeleteObject_(pen.l)
  DeleteObject_(hPenOld.l)
EndProcedure

Global actHDC.l

  
ProcedureC collFunc(*shapea, *shapeb, *contacts, numContacts.l, normal_coef.f, *Datas); une petite procédure bien mystérieuse... 
  Debug("Contacts0"+Str(numContacts))
  For i = 0 To numContacts-1
    *c.cpContact = *contacts+ ( SizeOf(cpContact) * i)
    Debug ("Collision at "+StrF(*c\p\x)+","+StrF(*c\p\y))
  Next
  ProcedureReturn 1
EndProcedure



Declare display() 
Declare demo_destroy()
Declare Fin()

XIncludeFile "chipMunkDemo1.pbi"
XIncludeFile "chipMunkDemo2.pbi"
XIncludeFile "chipMunkDemo3.pbi"
;XIncludeFile "chipMunkDemo4.pbi"
XIncludeFile "chipMunkDemo4b.pbi"
; XIncludeFile "chipMunkDemo5.pbi"
; XIncludeFile "chipMunkDemo6.pbi"
;XIncludeFile "chipMunkDemo7.pbi"

Global actDemo.l = 0


If InitSprite() = 0 Or InitKeyboard() = 0
  MessageRequester("Fehler", "Kann DirectX 7 oder höher nicht finden.", 0); c'est de l'allemand, j'ai bon ?
  End
EndIf

wcpInitChipmunk() ; ... fait chaud aujourd'hui !

;Init Function
CallFunctionFast(Demos(actDemo)\start)

; °°°°°°°°°°°°°°°°°°°°  fonte °°°°°°°°°°°°°°°°°°°°°°°°°°
LoadFont ( 0 , "Comic Sans Ms" ,10, #PB_Font_Bold)

Enumeration ; ici, on donne un petit nom à nos sprites( non, chuis pas un numéro !):
   #fonda:#fondb
   #carresr:#jauge
EndEnumeration

If OpenWindow ( 0 , 0, 0, 800, 600, "Chipmunk-Demo Press 1-4 for Demos" , #PB_Window_SystemMenu | #PB_Window_SizeGadget | #PB_Window_TitleBar| #PB_Window_MinimizeGadget | #PB_Window_MaximizeGadget | #PB_Window_ScreenCentered | #PB_Window_ScreenCentered )
;If OpenWindow(0,0,0,640,480,"Chipmunk-Demo Press 1-4 for Demos", #PB_Window_ScreenCentered | #PB_Window_SystemMenu | #PB_Window_SizeGadget)
  If OpenWindowedScreen(WindowID(0),0,0,800,600, 1, 0, 0)
;If OpenScreen(640, 480, 32,"Kuchen")

 CreateSprite ( #fonda , 64, 64, 0)
 StartDrawing ( SpriteOutput ( #fonda ))
    r=0:g=27:b=137
  For t=0 To 63
    Line(0, 0+t, 64, 0 , RGB (r,g,b))
    Tcouleur+1
    If Tcouleur=1
      If r<154:r+1:EndIf
      If g>0:g-1:EndIf
      If b<165:b+1:EndIf
      Tcouleur=0 
    EndIf
  Next
 StopDrawing ()
 
 CreateSprite ( #fondb , 64, 64, 0)
 StartDrawing ( SpriteOutput ( #fondb ))
    r=0:g=27:b=137
  For t=0 To 63
    Line(0, 63-t, 64, 0 , RGB (r,g,b))
    Tcouleur+1
    If Tcouleur=1
      If r<154:r+1:EndIf
      If g>0:g-1:EndIf
      If b<165:b+1:EndIf
      Tcouleur=0 
    EndIf
  Next
 StopDrawing ()

 CreateSprite ( #carresr , 16, 16, 0)
 StartDrawing ( SpriteOutput ( #carresr )); carre sens de rotation
  BackColor ( RGB (0,0,0))
  Box (0,0, 15, 15, RGB (190, 27, 27)):Box (1,1, 13, 13, RGB (210, 27, 27))
 StopDrawing ()
 CreateSprite ( #jauge , 20, 20, 0)
 StartDrawing ( SpriteOutput ( #jauge ))
  BackColor ( RGB (0,0,0))
  Box (0,0, 19, 19, RGB (255, 209, 254)):Box (2,2, 15, 15, RGB (0, 0, 0))
 StopDrawing ()
   
Global zutA.w, zutB.w ; chuis incorrigible...

; ******************************************************************************************************
Repeat ; Boucle principale
; ******************************************************************************************************
    ;ClearScreen(#White  )
    ClearScreen(RGB(0, 27, 137)) 
    ExamineKeyboard()
  
  For t=0 To 12; un fond constitué de sprite2D, qu'il faudra peut être remplacer en sprite3D( car plus rapide).
    DisplayTransparentSprite( #fonda , 0+(t*64), 600-64)
    DisplayTransparentSprite( #fondb , 0+(t*64), 0)    
  Next    
  
    If KeyboardReleased(#PB_Key_1)
        demo_destroy()
        actDemo=0 
        CallCFunctionFast(Demos(actDemo)\start)
    EndIf
    
    If KeyboardReleased(#PB_Key_2)
      If actDemo<> 1 
        demo_destroy()
        actDemo=1 
        CallCFunctionFast(Demos(actDemo)\start)
      EndIf 
    EndIf
    
    If KeyboardReleased(#PB_Key_3)
      If actDemo<> 2
        demo_destroy()
        actDemo=2
        CallCFunctionFast(Demos(actDemo)\start)
      EndIf 
    EndIf
    If KeyboardReleased(#PB_Key_4)
      If actDemo<> 3 
        demo_destroy()
        actDemo=3 
        CallCFunctionFast(Demos(actDemo)\start)
        
      EndIf 
    EndIf
    ; If KeyboardReleased(#PB_Key_5)
      ; If actDemo<> 4
        ; demo_destroy()
        ; actDemo=4
        ; CallCFunctionFast(Demos(actDemo)\start)
      ; EndIf 
    ; EndIf
    ; If KeyboardReleased(#PB_Key_6)
      ; If actDemo<> 5
        ; demo_destroy()
        ; actDemo=5
        ; CallCFunctionFast(Demos(actDemo)\start)
      ; EndIf 
    ; EndIf
    ; If KeyboardReleased(#PB_Key_7)
      ; If actDemo<> 6
        ; demo_destroy()
        ; actDemo=6
        ; CallCFunctionFast(Demos(actDemo)\start)
      ; EndIf 
    ; EndIf
    ;
     
;- Alors attention, c'est là:
If actDemo=3
  If KeyboardReleased ( #PB_Key_Right ) And sensrotation<2
    sensrotation+0.25
  EndIf  
  If KeyboardReleased ( #PB_Key_left ) And sensrotation>-2
    sensrotation-0.25
  EndIf



  StartDrawing ( ScreenOutput ())
    DrawingMode (1)
      FrontColor ( RGB (255,255,255))      
      DrawingFont ( FontID (0)) 
      FrontColor ( RGB (154,154,154)) :DrawText (150+1, 0+1, "sens de rotation:")
      FrontColor ( RGB (234,234,234)) :DrawText (150, 0, "sens de rotation:")
  StopDrawing ()


  If sensrotation>0.24:DisplayTransparentSprite( #carresr , 400+4, 2):EndIf
  If sensrotation>0.49:DisplayTransparentSprite( #carresr , 400+4+20, 2):EndIf  
  If sensrotation>0.74:DisplayTransparentSprite( #carresr , 400+4+20+20, 2):EndIf
  If sensrotation>0.99:DisplayTransparentSprite( #carresr , 400+4+20+20+20, 2):EndIf  
  If sensrotation>1.24:DisplayTransparentSprite( #carresr , 400+4+20+20+20+20, 2):EndIf
  If sensrotation>1.49:DisplayTransparentSprite( #carresr , 400+4+20+20+20+20+20, 2):EndIf

  If sensrotation<-0.24:DisplayTransparentSprite( #carresr , 380, 2):EndIf
  If sensrotation<-0.49:DisplayTransparentSprite( #carresr , 380-20, 2):EndIf  
  If sensrotation<-0.74:DisplayTransparentSprite( #carresr , 380-20-20, 2):EndIf
  If sensrotation<-0.99:DisplayTransparentSprite( #carresr , 380-20-20-20, 2):EndIf  
  If sensrotation<-1.24:DisplayTransparentSprite( #carresr , 380-20-20-20-20, 2):EndIf
  If sensrotation<-1.49:DisplayTransparentSprite( #carresr , 380-20-20-20-20-20, 2):EndIf

  For t=0 To 5; jauge gauche.
    DisplayTransparentSprite( #jauge , 278+(t*20), 0)
  Next
  For t=0 To 5; jauge droite.
    DisplayTransparentSprite( #jauge , 402+(t*20), 0)
  Next
EndIf; If actDemo=3
  
 If KeyboardPushed ( #PB_Key_F ) And nbreis=0:nbreis+1:EndIf
 If KeyboardPushed ( #PB_Key_F )=0 And nbreis=1:nbreis+1:EndIf
 If KeyboardPushed ( #PB_Key_F ) And nbreis=2:nbreis+1:EndIf
 If KeyboardPushed ( #PB_Key_F )=0 And nbreis=3:nbreis=0:EndIf
 Gosub fps ; nombre d'image par seconde. 

    display()
    
    ;Delay(10); j'ai désactivé cette commande, et sans aucune pitié !
    ev.l = WindowEvent()
    FlipBuffers()
  Until KeyboardPushed(#PB_Key_Escape) Or ev = #PB_Event_CloseWindow
  
   
EndIf
EndIf
Fin()

; ******************************************************************************************************


;- fps
fps:
If Val ( FormatDate ( "%ss" , Date ()))=sek 
    fps+1
Else
    FPS$= Str (fps)
    fps=0
EndIf
sek= Val ( FormatDate ( "%ss" , Date ()))
StartDrawing ( ScreenOutput ())
DrawingMode (1)
FrontColor ( RGB (255,255,255))
If nbreis=1 Or nbreis=2:DrawText (1,1, "FPS: " +FPS$)

vram=AvailableScreenMemory()
zutA=sensrotation
;zutB=ticks

  vram$= Str (vram)
  FrontColor ( RGB (154,154,154)) :DrawText (1+1,20+1, "vram: " +vram$)
  FrontColor ( RGB (234,234,234)) :DrawText (1,20, "vram: " +vram$)
     
  zutA$= Str (zutA) 
  FrontColor ( RGB (154,154,154)) :DrawText (1+1,120+1, "zutA: " +zutA$)
  FrontColor ( RGB (234,234,234)) :DrawText (1,120, "zutA: " +zutA$)
  
;  zutB$= Str (sensrotation) 
;  FrontColor ( RGB (154,154,154)) :DrawText (1+1,140+1, "zutB: " +zutB$)
;  FrontColor ( RGB (234,234,234)) :DrawText (1,140, "zutB: " +zutB$)  
EndIf

StopDrawing ()
Return
    
    
ProcedureC drawCollisions(*arbiter, *Datas) ; Ah oui, quand même ! J'ai chaud à la tête, toutes ces...
  num.l = wcpArbiterGetNumContacts(*arbiter);
  For i = 0 To num-1
    wcpArbiterGetContactPoint(*arbiter, i, @vRet.cpVect )  
    CirclePro (actHDC,vRet\x,vRet\y,2,2, #Red)
  Next
  
EndProcedure

    
Procedure drawCircleShape(*shape) ; ...nouvelles commandes innaccessibleblebleblegloubgloub, je, heu, gloubgloub, gloub... gloub.
  *body.cpBody = wcpShapeGetBody(*shape); *body = pb_cpshape_getbody(*shape);
  wcpBodyGetPosition(*body,@vecpos.cpVect); pb_cpbody_getposition(*body,@vecpos.cpVect)
  wcpBodyGetAngle(*body,@angle.f); pb_cpbody_getangle(*body,@angle.f)
  wcpCircleGetTransformedCenter(*shape,@veccenter.cpVect); pb_cpcircleshape_gettransformedcenter(*shape,@veccenter.cpVect)
  wcpCircleGetRadius(*shape,@radius.f);  pb_cpcircleshape_getradius(*shape,@radius.f)
  Circle(veccenter\x , veccenter\y , radius, RGB(245, 245, 245)) 
  
  
  x2.f = (radius*Cos(angle)+veccenter\x)
  y2.f = (radius*Sin(angle)+veccenter\y)
  
  LineXY(veccenter\x,veccenter\y,x2,y2,RGB(170, 245, 245))
  
  
  
;  glVertex2f(r*Cos(rads + a) + x, r*Sin(rads + a) + y);  
  
  
EndProcedure
    
Procedure drawPolyShape(*shape) ; gloub ! 
  DrawingMode(  #PB_2DDrawing_Outlined)
  *body.cpBody = wcpShapeGetBody(*shape); *body = pb_cpshape_getbody(*shape);
  wcpBodyGetPosition(*body,@vecpos.cpVect); pb_cpbody_getposition(*body,@vecpos.cpVect)
  ;  Debug("Body pos("+StrF(vecpos\x)+","+Str(vecpos\y))
  
  
  vertnum.l = wcpPolyShapeGetNumVerts(*shape); pb_cppolyshape_numverts(*shape)
  Dim verts.cpVect(vertnum+1)
  wcpPolyShapeGetVerts(*shape, @verts()); pb_cppolyshape_getverts(*shape, @verts());      
  
  first.cpVect;
  last.cpVect;
  last.cpVect
  
  wcpBodyGetRotation(*body, @bodyRot.cpVect)
  
  For i = 0 To vertnum-1
    
    wcpVectRotate( verts(i), bodyRot, rot) 
    wcpVectAdd( vecpos, rot, v) 
    ;    pb_cpvect_add2(@v.cpVect,@vecpos,  pb_cpvect_rotate(@verts(i), pb_cpbody_getrot(*body)) )    

    If i = 0 
      first\x = v\x
      first\y = v\y
    Else
      LineXY(last\x,last\y,v\x,v\y, RGB(245, 245, 245));#Black) 
      
;       LinePro (actHDC.l,last\x,last\y,v\x,v\y,3,#Black)
    EndIf
    
    last\x = v\x
    last\y = v\y
    
  Next
  LineXY(last\x,last\y,first\x,first\y, RGB(245, 245, 245));#Black) 
  Circle(vecpos\x,vecpos\y,2, RGB(170, 245, 245));#Blue)
;  CirclePro (actHDC,vecpos\x,vecpos\y,2,2,#Blue)
EndProcedure
    
Procedure drawSegmentShape(*shape) ; et désormais il reposa en paix... 
  
  *body.cpBody = wcpShapeGetBody(*shape); *body = pb_cpshape_getbody(*shape);
  wcpBodyGetPosition(*body,@vecpos.cpVect); pb_cpbody_getposition(*body,@vecpos.cpVect)
  wcpBodyGetRotation(*body, @bodyRot.cpVect)
  
  
  
  ; *body = pb_cpshape_getbody(*shape);
  ; *seg = *shape;
  ; pb_cpbody_getposition(*body,@vecpos.cpVect)
  
  wcpSegmentShapeGetPointA(*shape,pointA.cpVect)
  wcpSegmentShapeGetPointB(*shape,pointB.cpVect)
  
  wcpVectRotate( pointA, bodyRot, rota) 
  wcpVectRotate( pointB, bodyRot, rotb) 
  
  wcpVectAdd( vecpos, rota, veca) 
  wcpVectAdd( vecpos, rotb, vecb) 
  
  
  ; pb_cpvect_add2(@veca.cpVect,@vecpos,  pb_cpvect_rotate( pb_cpsegmentshape_getendpointa(*seg), pb_cpbody_getrot(*body)) )
  ; pb_cpvect_add2(@vecb.cpVect,@vecpos,  pb_cpvect_rotate( pb_cpsegmentshape_getendpointb(*seg), pb_cpbody_getrot(*body)) ) 
  LineXY(veca\x, veca\y, vecb\x,vecb\y, RGB(245, 245, 170));#Black)
EndProcedure
    
        
ProcedureC drawObject(*shape, *Datas) ; ... dans sa dernière demeure...
;  Debug("draw")
  type.l = wcpShapeGetType(*shape); pb_cpshape_gettype(*shape) 
  Select type
    Case #CP_CIRCLE_SHAPE
      drawCircleShape(*shape)
;      Debug("Circle")
    Case #CP_SEGMENT_SHAPE
      drawSegmentShape(*shape)
;      Debug("Segment")
    Case #CP_POLY_SHAPE
      drawPolyShape(*shape)
;      Debug("Poly")
  EndSelect 
EndProcedure   

Procedure display() ; ...dans de vastes prairies et sous de frais ombrages...
  Shared *space, ticks.l
  Shared Demos()
  ticks+1
  actHDC = StartDrawing(ScreenOutput())
  
  wcpSpaceHashEach( wcpSpaceGetActiveShapes(*space), @drawObject(), 0)
  wcpSpaceHashEach( wcpSpaceGetStaticShapes(*space), @drawObject(), 0)
  
  ; cpSpaceHashEach(pb_cpspace_getactiveshapes(*space), @drawObject(), 0)
  ; cpSpaceHashEach(pb_cpspace_getstaticshapes(*space), @drawObject(), 0)
  wcpSpaceEachArbiter(*space, @drawCollisions(), #Null)
  StopDrawing()


  CallFunctionFast(Demos(actDemo)\update,ticks)

EndProcedure

  
Procedure demo_destroy() ; ...où il n'éprouva nulle lassitude et ne voudra rien changer...
  Shared *space, *staticBody 
;  cpSpaceFreeChildren(*space);
  wcpSpaceFree(*space);
  wcpBodyFree(*staticBody);

EndProcedure

Procedure.l Fin()
 If IsSprite(#fonda):FreeSprite(#fonda):EndIf
 If IsSprite(#fondb):FreeSprite(#fondb):EndIf
 If IsSprite(#carresr):FreeSprite(#carresr):EndIf
 If IsSprite(#jauge):FreeSprite(#jauge):EndIf 
 
 End ; et c'est toujours un peu triste...
EndProcedure  
  


; jaPBe Version=3.7.10.669
; Build=4
; Language=0x0000 Language Neutral et mon pb d'amour ^.^
; FirstLine=65
; CursorPosition=86
; EnableXP
; EnableOnError
; ExecutableFormat=Windows
; Executable=T:\Dev\PB4\Includes\Examples\chipmunkDemo.exe
; DontSaveDeclare
Dernière modification par beauregard le lun. 21/juil./2008 1:03, modifié 1 fois.
beauregard
Messages : 1307
Inscription : dim. 08/juil./2007 18:32
Localisation : Toulouse

Re: moteur physique

Message par beauregard »

et voilà la 4eme demo modifié, qu'il faut nommer chipmunkDemo4b.pbi

Code : Tout sélectionner

    
Procedure demo4_update(ticks.l) 
  Shared *space,*staticBody
  Protected steps.f = 3.0
  Protected dt.f = 1.0/60.0/steps
  
;  Debug("update demo2 () " + Str(steps) + " / " +StrF(dt) )
  For i = 0 To steps 
    wcpSpaceStep(*space, dt)
    wcpBodyUpdatePosition(*staticBody,dt)
    wcpSpaceRehashStatic(*space)
  Next 
wcpBodySetAngularVelocity(*staticBody, sensrotation);- hum !
EndProcedure


Macro mcCreateAddSegmentShape(__VEC1__, __VEC2__, __E__, __F__)
  *shape.cpShape 
  *shape = wcpSegmentShapeNew(*staticBody,@__VEC1__,__VEC2__,0)
  wcpShapeSetElasticity(*shape,__E__)
  wcpShapeSetFriction(*shape,__F__)
  wcpSpaceAddStaticShape(*space,*shape)
EndMacro
  

Procedure demo4_init()

  Debug("Demo4 Init")

  
  Shared *staticBody,*space
  RandomSeed( Date())
  
  *staticBody = wcpBodyNew(INFINITY,INFINITY);
  _cpv(pos,400,300);320,240)
  wcpBodySetPosition(*staticBody, @pos	) 
  
  wcpResetShapeIdCounter()  
  
  *space = wcpSpaceNew()
  
  wcpSpaceResizeStaticHash(*space, 30.0,999)
  wcpSpaceResizeActiveHash(*space, 200.0,99)
  
  _cpv(vec,0,600)
  wcpSpaceSetGravity(*space, @vec);
  



      
  Define.cpVect a,b,c,d; grand carré sorte de zone de jeu.
  a\x = -250: a\y = -200
  b\x = -250: b\y =  200
  c\x =  254: c\y =  200
  d\x =  254: d\y = -200
	
  
  mcCreateAddSegmentShape(a,b,1.0,1.0)
  mcCreateAddSegmentShape(b,c,1.0,1.0)
  mcCreateAddSegmentShape(c,d,1.0,1.0)
  mcCreateAddSegmentShape(d,a,1.0,1.0); RGB(238, 255, 170)

;- désactivé ici,
; pour la mettre dans la procédure précedente: Procedure demo4_update(ticks.l) 
; wcpBodySetAngularVelocity(*staticBody, sensrotation); 0.4)

; ******** début triangle fixe centre********

  Dim tris.cpVect(3)
  
;  tris(0)\x =  15 : tris(0)\y = 15
;  tris(1)\x =   0: tris(1)\y = -10
;  tris(2)\x = -15 : tris(2)\y = 15

  tris(0)\x =  96 : tris(0)\y = 45
  tris(1)\x =   0: tris(1)\y = -10
  tris(2)\x = -96 : tris(2)\y = 45

;  For i = 0 To 8
;    For j = 0 To 5
      s.l = j % 2
      stagger.f = s*40 
      _cpv(offset, (i*63)+2  + stagger, -50);(j*70) ) ; ?, colonne, ligne
      ; offset.cpVect
      ; offset\x = i*80  + stagger
      ; offset\y = 100+(j*70)
      
      *shape = wcpPolyShapeNew(*staticBody, @tris(),3, @offset)     ;pb_cppolyshape_create(*staticBody, @tris(),3, @offset)
      wcpShapeSetElasticity(*shape,1.0); pb_cpshape_setelasticity(*shape,1.0)
      wcpShapeSetFriction(*shape,1.0); pb_cpshape_setfriction(*shape,1.0)
      wcpSpaceAddShape(*space,*shape); pb_cpspace_addshape(*space,*shape)      
;    Next
;  Next

; ******** fin triangle fixe ******** 

; ******** début triangle fixe exterieur haut ********
  tris(0)\x =  30 : tris(0)\y = 45
  tris(1)\x =   0: tris(1)\y = -10
  tris(2)\x = -30 : tris(2)\y = 45

      s.l = j % 2
      stagger.f = s*40 
      _cpv(offset, (i*63)+2  + stagger, 170);(j*70) ) ; ?, colonne, ligne
      
      *shape = wcpPolyShapeNew(*staticBody, @tris(),3, @offset)     ;pb_cppolyshape_create(*staticBody, @tris(),3, @offset)
      wcpShapeSetElasticity(*shape,1.0); pb_cpshape_setelasticity(*shape,1.0)
      wcpShapeSetFriction(*shape,1.0); pb_cpshape_setfriction(*shape,1.0)
      wcpSpaceAddShape(*space,*shape); pb_cpspace_addshape(*space,*shape)      
; ******** fin triangle fixe ******** 
; ******** début triangle fixe exterieur bas ********
;  tris(0)\x =  30 : tris(0)\y = -10;45
;  tris(1)\x =   0: tris(1)\y = 45;-10
;  tris(2)\x = -30 : tris(2)\y = -10;45
  tris(0)\x =  0 : tris(0)\y = 45
  tris(1)\x =  30: tris(1)\y = -10
  tris(2)\x = -30 : tris(2)\y = -10
  
      s.l = j % 2
      stagger.f = s*40 
      _cpv(offset, (i*63)+2  + stagger, -203);(j*70) ) ; ?, colonne, ligne
      
      *shape = wcpPolyShapeNew(*staticBody, @tris(),3, @offset)     ;pb_cppolyshape_create(*staticBody, @tris(),3, @offset)
      wcpShapeSetElasticity(*shape,1.0); pb_cpshape_setelasticity(*shape,1.0)
      wcpShapeSetFriction(*shape,1.0); pb_cpshape_setfriction(*shape,1.0)
      wcpSpaceAddShape(*space,*shape); pb_cpspace_addshape(*space,*shape)      
; ******** fin triangle fixe ********



  

















	_cpv(zv,0,0)
	
;- minuscule carré
	Dim verts.cpVect(4)  
  verts(0)\x = -7: verts(0)\y = -7
  verts(1)\x = -7: verts(1)\y =  7
  verts(2)\x =  7: verts(2)\y =  7
  verts(3)\x =  7: verts(3)\y = -7 
 
  For i = 0 To 1 
    For j = 0 To 1 
      wcpMomentForPoly(1.0, 4, @verts(), @zv,@mom_pols.f);
      *body = wcpBodyNew(1.0, mom_pols)       
      _cpv(pos, (i*60-150)+320,(j*30-150)+340) ; i:colonne et j:ligne 
      wcpBodySetPosition(*body,@pos)
      wcpSpaceAddBody(*space,*body)

      *shape = wcpPolyShapeNew(*body, @verts(),4, @zv)
      wcpShapeSetElasticity(*shape,0)
      wcpShapeSetFriction(*shape,0.7)
      wcpSpaceAddShape(*space,*shape)      
    Next
  Next
  	
;- petit carré
	Dim verts.cpVect(4)  
  verts(0)\x = -10: verts(0)\y = -10
  verts(1)\x = -10: verts(1)\y =  10
  verts(2)\x =  10: verts(2)\y =  10
  verts(3)\x =  10: verts(3)\y = -10 
 
  For i = 0 To 2 
    For j = 0 To 2 
      wcpMomentForPoly(1.0, 4, @verts(), @zv,@mom_pols.f);
      *body = wcpBodyNew(1.0, mom_pols)       
      _cpv(pos, (i*60-150)+320,(j*30-150)+340) ; i:colonne et j:ligne 
      wcpBodySetPosition(*body,@pos)
      wcpSpaceAddBody(*space,*body)

      *shape = wcpPolyShapeNew(*body, @verts(),4, @zv)
      wcpShapeSetElasticity(*shape,0)
      wcpShapeSetFriction(*shape,0.7)
      wcpSpaceAddShape(*space,*shape)      
    Next
  Next

;- carré moyen
	Dim verts.cpVect(4)  
  verts(0)\x = -15: verts(0)\y = -15
  verts(1)\x = -15: verts(1)\y =  15
  verts(2)\x =  15: verts(2)\y =  15
  verts(3)\x =  15: verts(3)\y = -15
  
  For i = 0 To 3 
    For j = 0 To 3 
      wcpMomentForPoly(1.0, 4, @verts(), @zv,@mom_pols.f);
      *body = wcpBodyNew(1.0, mom_pols)       
      _cpv(pos, (i*60-150)+320,(j*30-150)+340) ; i:colonne et j:ligne 
      wcpBodySetPosition(*body,@pos)
      wcpSpaceAddBody(*space,*body)

      *shape = wcpPolyShapeNew(*body, @verts(),4, @zv)
      wcpShapeSetElasticity(*shape,0)
      wcpShapeSetFriction(*shape,0.7)
      wcpSpaceAddShape(*space,*shape)      
    Next
  Next

;- grand carré 
	Dim verts.cpVect(4)  
  verts(0)\x = -20: verts(0)\y = -20
  verts(1)\x = -20: verts(1)\y =  20
  verts(2)\x =  20: verts(2)\y =  20
  verts(3)\x =  20: verts(3)\y = -20
  
  For i = 0 To 2 
    For j = 0 To 2 
      wcpMomentForPoly(1.0, 4, @verts(), @zv,@mom_pols.f);
      *body = wcpBodyNew(1.0, mom_pols)       
      _cpv(pos, (i*60-150)+320,(j*30-150)+340) ; i:colonne et j:ligne 
      wcpBodySetPosition(*body,@pos)
      wcpSpaceAddBody(*space,*body)

      *shape = wcpPolyShapeNew(*body, @verts(),4, @zv)
      wcpShapeSetElasticity(*shape,0)
      wcpShapeSetFriction(*shape,0.7)
      wcpSpaceAddShape(*space,*shape)      
    Next
  Next 
 


 

 
 
  ;Test mit Kugel  

For t=0 To 3 ; nombre de cercle( ici 2 petits)
  radius.f = 20 
  wcpMomentForCircle(10.0, 0.0, radius, @zv, @momCircle.f)
  *body = wcpBodyNew(1.0, momCircle)
  _cpv(pos,200.5+(t*120),140)
  wcpBodySetPosition(*body,@pos)
  wcpSpaceAddBody(*space,*body)
  ; ; 
  *shape = wcpCircleShapeNew(*body,radius, @zv)
  wcpShapeSetElasticity(*shape,0.4)
  wcpShapeSetFriction(*shape,0.9)
  wcpSpaceAddShape(*space,*shape)  
Next  
For t=0 To 1 ; nombre de cercle( ici 2 grands)
  radius.f = 15*2 
  wcpMomentForCircle(10.0, 0.0, radius, @zv, @momCircle.f)
  *body = wcpBodyNew(1.0, momCircle)
  _cpv(pos,200.5+(t*120),140)
  wcpBodySetPosition(*body,@pos)
  wcpSpaceAddBody(*space,*body)
  ; ; 
  *shape = wcpCircleShapeNew(*body,radius, @zv)
  wcpShapeSetElasticity(*shape,0.4)
  wcpShapeSetFriction(*shape,0.9)
  wcpSpaceAddShape(*space,*shape)  
Next 
 
  
EndProcedure
  
Demos(3)\start =  @demo4_init()
Demos(3)\update =  @demo4_update()


Frenchy Pilou
Messages : 2194
Inscription : jeu. 27/janv./2005 19:07

Message par Frenchy Pilou »

j'ai sauvegardé ton premier code
chipmunkDemoMain.pb

ton 2ème code
chipmunkDemo4b.pbi

je lance chipmunkDemo.exe

et je n'ai que les 4 démos d'avant???
Quel est encore ce mystère?
J'ai bien sûr dénommé l' ancien chipmunkDemoMain.pb pour pouvoir le reprendre ensuite
Qu'ai-je encore raté?
:roll:
beauregard
Messages : 1307
Inscription : dim. 08/juil./2007 18:32
Localisation : Toulouse

enmeler les pinceaux

Message par beauregard »

Frenchy Pilou a écrit :j'ai sauvegardé ton premier code
chipmunkDemoMain.pb
non, il faut le sauvegarder avec un nom à ta convenance, disons beauphysic.pb ( puis tu appui fébrilement sur la touche F5).
Frenchy Pilou a écrit :je lance chipmunkDemo.exe et je n'ai que les 4 démos d'avant???
et bien c'est dès plus logique, puisque eddy a fait l'exe de son code à lui. Tu n'as jamais eu la curiosité de faire un exe d'un de tes codes ?
Frenchy Pilou a écrit :Qu'ai-je encore raté? :roll:
une bonne nuit de repos, comme moi d'ailleurs ;)
Frenchy Pilou
Messages : 2194
Inscription : jeu. 27/janv./2005 19:07

Message par Frenchy Pilou »

Il fallait dire qu'il fallait refaire le bazar du fil de discussion précendent (peu clair pour moi) :roll:
Je ne sais par quel miracle çà a marché dans cet embroglio de fichiers :lol:
Ah c'est pas simple :)
le truc amusant c'est quand on fait tourner à fond la gomme tout se trouve collé aux parois comme dans le cylindre de la mort à la fête foraine :D

Et je me répète il serait bien plus facile que tu fasses un petit bidule comprenant tout ce qu'il faut pour que tout marche en un seul bloc!
Pas besoin pour l'utilisateur occasionnel (moi) de se prendre la tête à faire des acrobaties de fichiers :roll:
beauregard
Messages : 1307
Inscription : dim. 08/juil./2007 18:32
Localisation : Toulouse

Message par beauregard »

Frenchy Pilou a écrit : tout marche en un seul bloc!
Pas besoin pour l'utilisateur occasionnel (moi) de se prendre la tête à faire des acrobaties de fichiers :roll:
J'ai bien essayé, mais des commandes mystérieuses m'en ont empêché...
->au bas de code chipMunkDemo4b.pbi

Code : Tout sélectionner

Demos(3)\start =  @demo4_init()
Demos(3)\update =  @demo4_update()
j'aimerai bien comprendre cette petite commande( du même code):

Code : Tout sélectionner

_cpv(zv,0,0)
Répondre