RagDoll Ogre PhysikEngine

Hier könnt Ihr gute, von Euch geschriebene Codes posten. Sie müssen auf jeden Fall funktionieren und sollten möglichst effizient, elegant und beispielhaft oder einfach nur cool sein.
Benutzeravatar
bobobo
jaAdmin
Beiträge: 3857
Registriert: 13.09.2004 17:48
Kontaktdaten:

RagDoll Ogre PhysikEngine

Beitrag von bobobo »

Ich brauch das nicht. Eventuell kann damit ja jemand was anfangen.
Ich finde es aber auf jeden Fall erstmal "nett", obwohl die Knilche
ab und zu im Boden stecken bleiben

Code: Alles auswählen

;
;
; ------------------------------------------------------------
;
;   PureBasic - RagDoll
;
;    (c) 2002 - Fantaisie Software , bobobo
; OpenGL scheitert bei mir, das mag am Treiber liegen (Laptop)
; das Programm sollte im Verzeichnis  \Examples\3D liegen
; weil es auf den Screenrequester und andere Daten dort zugreift
; alles ohne Gewähr
; ------------------------------------------------------------
;

#CameraSpeed = 0.5

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY ,rott, moveit

If InitEngine3D()
  
  Add3DArchive(#PB_Compiler_Home + "/Examples/3D/" +"Data/Textures", #PB_3DArchive_FileSystem)
  
  Add3DArchive(#PB_Compiler_Home + "/Examples/3D/" +"Data/Packs/desert.zip", #PB_3DArchive_Zip)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    WorldShadows(#PB_Shadow_Additive  )
    
    SkyBox("desert07.jpg")
    
    camera=CreateCamera(#PB_Any,0,0,100,100)
    MoveCamera(camera,0, 260 ,15, #PB_Absolute)
    
    texture1t=CreateTexture(#PB_Any,256,256)
    StartDrawing(TextureOutput(texture1t))
    
    Box(0, 0, 256, 256, RGBA(222,222,255, 200))
    For l=0 To 128 
      Circle(Random(256),Random(256),Random(4)+1,RGBA(0,0,255,255))
    Next l
    StopDrawing()
    
    texture1=CreateMaterial(#PB_Any, TextureID(texture1t))
    ScaleMaterial(texture1,100,100)
    
    texture2= CreateTexture(#PB_Any,256,256)
    StartDrawing(TextureOutput(texture2))
    Box(0,0,256,256,RGBA(80,80,80,180))
    
    For l=0 To 400
      Circle(Random(256),Random(256),Random(3)+1,RGBA(Random(5)+100,Random(5)+100,Random(5)+100,180))
    Next l
    
    DrawText(0,0,"ragdoll ®",RGBA(255,0,0,255),RGBA(80,80,80,222))
    StopDrawing()
    texture2=CreateMaterial(#PB_Any, TextureID(texture2))
    
    Structure components
      ball.i
      limb.i
      texture.i
      Bodymesh.i
      Body.i
      HeadMesh.i
      Head.i
      arml.i
      armlu.i
      armr.i
      armru.i
      legl.i
      leglu.i
      legr.i
      legru.i
      ct_bodyhead.i
      ct_arml.i
      hinge_arml.i
      ct_armr.i
      hinge_armr.i
      hinge_legl.i
      hinge_leglu.i
      hinge_legr.i
      hinge_legru.i
      posx.i
      posy.i
      posz.i
    EndStructure
    
    Define ragdoll.components
    
    NewList ragdolls.components()
    
    For r=1 To 3 ;3 Dinger
      
      AddElement(ragdolls())
      ragdolls()\posx=r*2-2
      ragdolls()\posy=260
      ragdolls()\posz=0
      
      ragdolls()\texture=texture2;CreateMaterial(#PB_Any, TextureID(texture2))
      
      ;bodyparts
      ragdolls()\Bodymesh=CreateCube(#PB_Any,1)
      ragdolls()\Body=CreateEntity(#PB_Any,MeshID(ragdolls()\Bodymesh),MaterialID(ragdolls()\texture),ragdolls()\posx,ragdolls()\posy,ragdolls()\posz)
      ScaleEntity(ragdolls()\Body,1.0,1,0.25)
      
      ragdolls()\HeadMesh = CreateSphere(#PB_Any,0.5)
      ragdolls()\limb   = CreateCylinder(#PB_Any,0.1,0.80)
      ragdolls()\Head = CreateEntity(#PB_Any,MeshID(ragdolls()\HeadMesh),MaterialID(ragdolls()\texture),  ragdolls()\posx,ragdolls()\posy+1,ragdolls()\posz)
      
      ragdolls()\arml  = CreateEntity(#PB_Any,MeshID(ragdolls()\limb),MaterialID(ragdolls()\texture)  ,ragdolls()\posx-0.6,ragdolls()\posy,ragdolls()\posz)
      ragdolls()\armlu = CreateEntity(#PB_Any,MeshID(ragdolls()\limb),MaterialID(ragdolls()\texture) ,ragdolls()\posx-0.6,ragdolls()\posy-1,ragdolls()\posz)
      
      ragdolls()\armr  = CreateEntity(#PB_Any,MeshID(ragdolls()\limb),MaterialID(ragdolls()\texture)  ,ragdolls()\posx+0.6,ragdolls()\posy,ragdolls()\posz)
      ragdolls()\armru = CreateEntity(#PB_Any,MeshID(ragdolls()\limb),MaterialID(ragdolls()\texture) ,ragdolls()\posx+ 0.6,ragdolls()\posy-1,ragdolls()\posz)
      
      ragdolls()\legl = CreateEntity(#PB_Any,MeshID(ragdolls()\limb),MaterialID(ragdolls()\texture) ,ragdolls()\posx-0.3,ragdolls()\posy-1,ragdolls()\posz)
      ragdolls()\legr = CreateEntity(#PB_Any,MeshID(ragdolls()\limb),MaterialID(ragdolls()\texture) ,ragdolls()\posx+ 0.3,ragdolls()\posy-1,ragdolls()\posz)
      
      ragdolls()\leglu = CreateEntity(#PB_Any,MeshID(ragdolls()\limb),MaterialID(ragdolls()\texture),ragdolls()\posx-0.3,ragdolls()\posy-2,ragdolls()\posz)
      ragdolls()\legru = CreateEntity(#PB_Any,MeshID(ragdolls()\limb),MaterialID(ragdolls()\texture),ragdolls()\posx+ 0.3,ragdolls()\posy-2,ragdolls()\posz)
      ;bodyPhysics
      EntityPhysicBody(ragdolls()\Body,#PB_Entity_BoxBody  ,10, 0,1)
      EntityRenderMode(ragdolls()\Body, #PB_Entity_CastShadow)
      
      EntityRenderMode(ragdolls()\Head, #PB_Entity_CastShadow)
      EntityPhysicBody(ragdolls()\Head, #PB_Entity_SphereBody, 5, 0.25, 1)
      
      EntityRenderMode(ragdolls()\arml, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\arml, #PB_Entity_CylinderBody,  1, 0 ,1)
      EntityRenderMode(ragdolls()\armlu, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\armlu, #PB_Entity_CylinderBody, 1, 0, 1)
      
      EntityRenderMode(ragdolls()\armr, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\armr, #PB_Entity_CylinderBody,  1, 0, 1)
      EntityRenderMode(ragdolls()\armru, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\armru, #PB_Entity_CylinderBody, 1, 0,1)
      
      EntityRenderMode(ragdolls()\legl, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\legl, #PB_Entity_CylinderBody, 1, 0,1)
      EntityRenderMode(ragdolls()\leglu, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\leglu, #PB_Entity_CylinderBody,1, 0,1)
      
      EntityRenderMode(ragdolls()\legr, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\legr, #PB_Entity_SphereBody, 1, 0,1)
      EntityRenderMode(ragdolls()\legru, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\legru, #PB_Entity_SphereBody,1, 0,1)
      
      ;joints
      ragdolls()\ct_bodyhead=ConeTwistJoint(#PB_Any,EntityID(ragdolls()\Body)  , 0, 0.7,0,EntityID(ragdolls()\Head) ,0,-0.4,0)
      
      ragdolls()\ct_arml     = ConeTwistJoint(#PB_Any,EntityID(ragdolls()\Body),-0.6,  0.5 ,0,EntityID(ragdolls()\arml)       , 0, 0.4,0)
      ragdolls()\hinge_arml  = HingeJoint(#PB_Any,EntityID(ragdolls()\arml)    ,   0, -0.45,0,1,0,0,EntityID(ragdolls()\armlu), 0,0.45,0,1,0,0)
      
      ragdolls()\ct_armr     = ConeTwistJoint(#PB_Any,EntityID(ragdolls()\Body), 0.6, 0.5,0,EntityID(ragdolls()\armr),        0, 0.4,0)
      ragdolls()\hinge_armr  = HingeJoint(#PB_Any,EntityID(ragdolls()\armr)    , 0  ,-0.45,0,1,0,0,EntityID(ragdolls()\armru), 0,0.45,0,1,0,0)
      
      ragdolls()\hinge_legl  = HingeJoint(#PB_Any,EntityID(ragdolls()\Body)    ,-0.3,-0.60,0,1,0,0,EntityID(ragdolls()\legl) , 0,0.40,0,1,0,0)
      ragdolls()\hinge_legr  = HingeJoint(#PB_Any,EntityID(ragdolls()\Body)    , 0.3,-0.60,0,1,0,0,EntityID(ragdolls()\legr) , 0,0.40,0,1,0,0)
      ragdolls()\hinge_leglu = HingeJoint(#PB_Any,EntityID(ragdolls()\legl)    ,   0,-0.45,0,1,0,0,EntityID(ragdolls()\leglu), 0,0.45,0,1,0,0)
      ragdolls()\hinge_legru = HingeJoint(#PB_Any,EntityID(ragdolls()\legr)    ,   0,-0.45,0,1,0,0,EntityID(ragdolls()\legru), 0,0.45,0,1,0,0)
      
      ;joints attributes       
      SetJointAttribute(ragdolls()\ct_bodyhead,#PB_ConeTwistJoint_SwingSpan,0.25)
      SetJointAttribute(ragdolls()\ct_bodyhead,#PB_ConeTwistJoint_SwingSpan2,0)
      SetJointAttribute(ragdolls()\ct_bodyhead,#PB_ConeTwistJoint_TwistSpan,0.25)
      ;       ;          
      SetJointAttribute(ragdolls()\ct_arml,#PB_ConeTwistJoint_SwingSpan ,0.2);seitl
      SetJointAttribute(ragdolls()\ct_arml,#PB_ConeTwistJoint_SwingSpan2,1);dreh
      SetJointAttribute(ragdolls()\ct_arml,#PB_ConeTwistJoint_TwistSpan ,2);vorzurück
      ;       ;          
      SetJointAttribute(ragdolls()\hinge_arml,#PB_HingeJoint_LowerLimit,0)
      SetJointAttribute(ragdolls()\hinge_arml,#PB_HingeJoint_UpperLimit,120)
      SetJointAttribute(ragdolls()\hinge_armr,#PB_HingeJoint_LowerLimit,0)
      SetJointAttribute(ragdolls()\hinge_armr,#PB_HingeJoint_UpperLimit,120)
      
      SetJointAttribute(ragdolls()\ct_armr,#PB_ConeTwistJoint_SwingSpan,0.2);seitlich
      SetJointAttribute(ragdolls()\ct_armr,#PB_ConeTwistJoint_SwingSpan2,1);dreh
      SetJointAttribute(ragdolls()\ct_armr,#PB_ConeTwistJoint_TwistSpan,2);vorzurück
      
      SetJointAttribute(ragdolls()\hinge_legl,#PB_HingeJoint_LowerLimit,-1)
      SetJointAttribute(ragdolls()\hinge_legl,#PB_HingeJoint_UpperLimit,120)
      SetJointAttribute(ragdolls()\hinge_legr,#PB_HingeJoint_LowerLimit,-1)
      SetJointAttribute(ragdolls()\hinge_legr,#PB_HingeJoint_UpperLimit,120)
      
      SetJointAttribute(ragdolls()\hinge_leglu,#PB_HingeJoint_LowerLimit,-120)
      SetJointAttribute(ragdolls()\hinge_leglu,#PB_HingeJoint_UpperLimit,1)
      SetJointAttribute(ragdolls()\hinge_legru,#PB_HingeJoint_LowerLimit,-120)
      SetJointAttribute(ragdolls()\hinge_legru,#PB_HingeJoint_UpperLimit,1)
    Next 
    ;
    
    
    
    plate=CreateCube(#PB_Any,1)
    ScaleMaterial(texture1,0.5,0.5)
    ;Kartons (50kg)
;     NewList plates()
;     For xp=0 To 10
;       For yp=0 To 10
;         AddElement(plates())
;         plates()=CreateEntity(#PB_Any,MeshID(plate),MaterialID(texture1),35+0.25*Random(100)-50,290,35+0.25*Random(100)-50)
;         ScaleEntity(plates(),1,0.5+Random(1)/4,1)
;         EntityRenderMode(plates(), #PB_Entity_CastShadow)
;         EntityPhysicBody(plates(),#PB_Entity_BoxBody,50,0.3,0.5)
;       Next yp
;     Next xp
    
    platte=CreateEntity(#PB_Any,MeshID(plate),MaterialID(texture1),0,0,0)
    ScaleEntity(platte,50,0.01,50)
    MoveEntity(platte,0,256,0)
    EntityRenderMode(platte, #PB_Entity_CastShadow)
    EntityPhysicBody(platte,#PB_Entity_StaticBody,1000,1,0.5)
    
    sun=CreateLight(#PB_Any,RGB(238, 173, 148),17830,12860,10930,#PB_Light_Point)
    
    CameraLookAt(camera,EntityX(ragdolls()\Head),EntityY(ragdolls()\Head),EntityZ(ragdolls()\Head))
    dance=1
    hands=1
    Repeat
      Screen3DEvents()
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      
      If hands=1
        hands=2
        Debug hands  
        ;Händchenhalten    
        sp=-0.5
        tau.f=0
        damp.f=0.5
        SelectElement(ragdolls(),0)
        jx=EntityX(ragdolls()\armru)
        
        jy=EntityY(ragdolls()\armru)
        jz=EntityZ(ragdolls()\armru)
        id=EntityID(ragdolls()\armru)
        SelectElement(ragdolls(),1)
        jx1=EntityX(ragdolls()\armlu)
        jy1=EntityY(ragdolls()\armlu)
        jz1=EntityZ(ragdolls()\armlu)
        id1=EntityID(ragdolls()\armlu)
        knupf1=PointJoint(#PB_Any,id,0,sp,0,id1,0,sp,0)
        SetJointAttribute(knupf1,#PB_PointJoint_Damping,damp)
        SetJointAttribute(knupf1,#PB_PointJoint_Tau,tau)
        
        jx=EntityX(ragdolls()\armru)
        jy=EntityY(ragdolls()\armru)
        jz=EntityZ(ragdolls()\armru)
        id=EntityID(ragdolls()\armru)
        SelectElement(ragdolls(),2)
        jx1=EntityX(ragdolls()\armlu)
        jy1=EntityY(ragdolls()\armlu)
        jz1=EntityZ(ragdolls()\armlu)
        id1=EntityID(ragdolls()\armlu)
        knupf2=PointJoint(#PB_Any,id,0,sp,0,id1,0,sp,0)
        SetJointAttribute(knupf2,#PB_PointJoint_Damping,damp)
        SetJointAttribute(knupf2,#PB_PointJoint_Tau,tau)
        
        
      EndIf
      If hands=3
        Debug hands  
        hands=0
        If knupf1
          FreeJoint(knupf1)
          knupf1=0
        EndIf
        If knupf2
          FreeJoint(knupf2)
          knupf2=0
        EndIf
        If knupf3
          FreeJoint(knupf3)
          knupf3=0
        EndIf
        
      EndIf
      
      If dance=1
        ForEach ragdolls()
          If EntityY(ragdolls()\Head)<259.5
            ApplyEntityImpulse(ragdolls()\Head  ,0, 9,0,0,1,0)
            ApplyEntityImpulse(ragdolls()\legru  ,0, -5,0,0,-1,0)
            ApplyEntityImpulse(ragdolls()\leglu  ,0, -5,0,0,-1,0)
            If EntityY(ragdolls()\leglu)<256.8
              ApplyEntityImpulse(ragdolls()\leglu,Random(2)-1,Random(8),Random(2)-1)
            EndIf
            If EntityY(ragdolls()\legru)<256.8
              ApplyEntityImpulse(ragdolls()\legru,Random(2)-1,Random(8),Random(2)-1)
            EndIf
            ApplyEntityImpulse(ragdolls()\armlu,Random(2)-1,Random(2)-1,Random(2)-1)
            ApplyEntityImpulse(ragdolls()\armru,Random(2)-1,Random(2)-1,Random(2)-1)
          EndIf
        Next          
      EndIf
      
      If ExamineKeyboard()
        
        If KeyboardPushed(#PB_Key_P) Or KeyboardReleased(#PB_Key_R)
          px.f=0
          py.f=0
          pz.f=0
          ForEach ragdolls()
            px+EntityX(ragdolls()\Body)
            py+EntityY(ragdolls()\Body)
            pz+EntityZ(ragdolls()\Body)
          Next
          px=px/ListSize(ragdolls())
          py=py/ListSize(ragdolls())
          pz=pz/ListSize(ragdolls())
          
          CameraLookAt(camera,px,py,pz)
        EndIf
        
        If KeyboardPushed(#PB_Key_S) And shoot=0
          ForEach ragdolls()
            ApplyEntityImpulse(ragdolls()\Body,0,0,-100,Random(8)-4,Random(8)-4,Random(8)-4)
            shoot=1
          Next
        EndIf
        
        If KeyboardReleased(#PB_Key_S)
          shoot=0
        EndIf
        
        If KeyboardPushed(#PB_Key_R)
          ForEach ragdolls()
            MoveEntity(ragdolls()\Head,ragdolls()\posx,ragdolls()\posy,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\Body,ragdolls()\posx,ragdolls()\posy-1,ragdolls()\posz,#PB_Absolute)
            RotateEntity(ragdolls()\Body,0,0,0,#PB_Absolute)
            MoveEntity(ragdolls()\legr,ragdolls()\posx+0.3,ragdolls()\posy-2,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\legl,ragdolls()\posx-0.3,ragdolls()\posy-2,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\legru,ragdolls()\posx+0.3,ragdolls()\posy-2.9,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\leglu,ragdolls()\posx-0.3,ragdolls()\posy-2.9,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\armr,ragdolls()\posx+0.6,ragdolls()\posy-1,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\arml,ragdolls()\posx-0.6,ragdolls()\posy-1,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\armru,ragdolls()\posx+0.6,ragdolls()\posy-2,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\armlu,ragdolls()\posx-0.6,ragdolls()\posy-2,ragdolls()\posz,#PB_Absolute)
          Next
        EndIf
        If KeyboardReleased(#PB_Key_V) 
          Select hands
            Case 0
              hands=1
              
            Case 2
              hands=3
              
          EndSelect
          
        EndIf
        
        
        If KeyboardPushed(#PB_Key_T)
          ForEach ragdolls()
            ApplyEntityImpulse(ragdolls()\armlu ,0,-1,0,0,-1,0)
            ApplyEntityImpulse(ragdolls()\armru ,0,-1,0,0,-1,0)
            ApplyEntityImpulse(ragdolls()\leglu,0,-3,0,0,-1,0)
            ApplyEntityImpulse(ragdolls()\legru,0,-3,0,0,-1,0)
            ApplyEntityImpulse(ragdolls()\Head  ,0, 10,0,0,1,0)
          Next
        EndIf
        
        If KeyboardPushed(#PB_Key_J)
          ForEach ragdolls()
            ApplyEntityImpulse(ragdolls()\Body,0,10,0)
          Next
        EndIf
        
        If KeyboardPushed(#PB_Key_U) And dance=0
          dance=1
        EndIf
        
        If KeyboardPushed(#PB_Key_I)
          dance=0
        EndIf
        
        
        If KeyboardPushed(#PB_Key_F)
          ForEach ragdolls()
            If EntityY(ragdolls()\Body)<259
              ApplyEntityImpulse(ragdolls()\Body,0, 3,0,0,-10,0)
              ApplyEntityImpulse(ragdolls()\armlu  ,0, 3,0,0,-10,0)
              ApplyEntityImpulse(ragdolls()\armru  ,0, 3,0,0,-10,0)
              ApplyEntityImpulse(ragdolls()\leglu ,0, 3,0,0,-10,0)
              ApplyEntityImpulse(ragdolls()\legru ,0, 3,0,0,-10,0)
              ApplyEntityImpulse(ragdolls()\Head   ,0,6,0,0,0  ,0)
            EndIf
          Next
        EndIf
        
        If KeyboardPushed(#PB_Key_H)
          ForEach ragdolls()
            ApplyEntityImpulse(ragdolls()\armlu,0,1,0,0,-2,0)
            ApplyEntityImpulse(ragdolls()\armru,0,1,0,0,-2,0)
            ApplyEntityImpulse(ragdolls()\legl,0,-4,0,0,-20,0)
            ApplyEntityImpulse(ragdolls()\legr,0,-4,0,0,-20,0)
            ApplyEntityImpulse(ragdolls()\Head,0,5,0,0,0,0)
            ApplyEntityImpulse(ragdolls()\Body,0,4,0,0,10,0)
          Next
        EndIf
        
        If KeyboardPushed(#PB_Key_Add)
          wg+1
          WorldGravity(wg)
        EndIf
        
        If KeyboardPushed(#PB_Key_Subtract)
          wg-1
          WorldGravity(wg)
        EndIf
        
        If KeyboardPushed(#PB_Key_G)
          ;CameraLookAt(camera,EntityX(ragdolls()\Body),EntityY(ragdolls()\Body),EntityZ(ragdolls()\Body))
          ForEach ragdolls()
            ApplyEntityImpulse(ragdolls()\Head   ,0, 2,0)
            ApplyEntityImpulse(ragdolls()\legl , 0, Random(4),0,0,-6,0)
            ApplyEntityImpulse(ragdolls()\legr , 0, Random(4),0,0,-6,0)
            ApplyEntityImpulse(ragdolls()\armlu , 0, Random(1),0,0,6,0)
            ApplyEntityImpulse(ragdolls()\armru , 0, Random(1),0,0,6,0)
            
            ApplyEntityImpulse(ragdolls()\Body,0,-6,0,0,0,0)
          Next
        EndIf
        
;         If KeyboardPushed(#PB_Key_N)
;           ForEach plates()
;             ApplyEntityImpulse(plates(),0,8.5,0)
;           Next
;         EndIf
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed
        Else
          KeyY = 0
        EndIf
      EndIf
      
      RotateCamera(camera, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (camera, KeyX, 0, KeyY)
      
      RenderWorld()
      
      If IsSprite(out) ;freesprite if exists
        FreeSprite(out)
      EndIf
      
      out=CreateSprite(#PB_Any,ScreenWidth(),20)
      
      StartDrawing(SpriteOutput(out))
      If hands
        hao.s=" V:Hands Off,"
      Else
        hao.s=" V:Hands On,"
      EndIf
      
      If dance
        ho.s=" I:IdiotDance OFF,"
        ;DrawText(0,0,"R:reset, "+ho+" P:LookatAll,")
      Else
        ho.s=" U:IdiotDance ON, "
        
      EndIf
      DrawText(0,0,"R:reset, T:upright, H:hail ,G:strange ,T: upright, F:forceup (near plate),"+ho+" J:Up,"+hao+"P:LookatAll")
      StopDrawing()
      DisplayTransparentSprite(out,0,0)
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
‮pb aktuell5.7 - windoof aktuell und sowas von 10
Ich hab Tinnitus im Auge. Ich seh nur Pfeifen.
Benutzeravatar
Chimorin
Beiträge: 451
Registriert: 30.01.2013 16:11
Computerausstattung: MSI GTX 660 OC mit TwinFrozr III
6Gb DDR 3 RAM
AMD Phenom II X4 B55 @ 3,6GHz
Windows 7 Home Premium 64-bit

Re: RagDoll Ogre PhysikEngine

Beitrag von Chimorin »

Was kann man noch dazu sagen? Fett :bounce: :D
Bild

- formerly known as Bananenfreak -
Benutzeravatar
Regenduft
Beiträge: 574
Registriert: 25.03.2008 15:07
Wohnort: THE LÄÄÄND!

Re: RagDoll Ogre PhysikEngine

Beitrag von Regenduft »

Wie geil ist das denn?! :lol:
Gehört meiner Meinung nach fest in den Examples-Ordner von PureBasic! :allright:
PureBasic 5.73 LTE x86/x64 | Windows 7 (x64)
Benutzeravatar
NicTheQuick
Ein Admin
Beiträge: 8675
Registriert: 29.08.2004 20:20
Computerausstattung: Ryzen 7 5800X, 32 GB DDR4-3200
Ubuntu 22.04.3 LTS
GeForce RTX 3080 Ti
Wohnort: Saarbrücken
Kontaktdaten:

Re: RagDoll Ogre PhysikEngine

Beitrag von NicTheQuick »

Bild
Benutzeravatar
Regenduft
Beiträge: 574
Registriert: 25.03.2008 15:07
Wohnort: THE LÄÄÄND!

Re: RagDoll Ogre PhysikEngine

Beitrag von Regenduft »

Bild
PureBasic 5.73 LTE x86/x64 | Windows 7 (x64)
Benutzeravatar
NicTheQuick
Ein Admin
Beiträge: 8675
Registriert: 29.08.2004 20:20
Computerausstattung: Ryzen 7 5800X, 32 GB DDR4-3200
Ubuntu 22.04.3 LTS
GeForce RTX 3080 Ti
Wohnort: Saarbrücken
Kontaktdaten:

Re: RagDoll Ogre PhysikEngine

Beitrag von NicTheQuick »

Hm... Selbst wenn ich die Pfade absolut hinschreibe, klappt es nicht. Muss ich da unter Linux irgendein Subsystem verwenden? Eigentlich gibt es doch nur "gtk3", oder? Es kommt aber auch nirgendwo ein Fehler. Nur mit dem OpenWindowedScreen kommt eine Speicherverletzung bei "StopDrawing()" in Zeile 48, aber im Vollbild geht es sonst ja, also halb so wild.
Bild
Benutzeravatar
SoS
Beiträge: 340
Registriert: 29.08.2004 09:31
Kontaktdaten:

Re: RagDoll Ogre PhysikEngine

Beitrag von SoS »

Sieht nett aus :allright:
Hat aber einen derben speicherfressenden Bug drinn.

Code: Alles auswählen

out=CreateSprite(#PB_Any,ScreenWidth(),20)
Wird ständig neu erstellt ohne ihn jemals wieder freizugeben.
Bei mir sind 16Gb im nu aufgebraucht. :D
Benutzeravatar
bobobo
jaAdmin
Beiträge: 3857
Registriert: 13.09.2004 17:48
Kontaktdaten:

Re: RagDoll Ogre PhysikEngine

Beitrag von bobobo »

ich hab's auf Grund der Ratschläge (Danke dafür) (sprite und 3d-Verzeichnis) etwas angepasst.
außerdem halten die Knilche nun optional Händchen.
‮pb aktuell5.7 - windoof aktuell und sowas von 10
Ich hab Tinnitus im Auge. Ich seh nur Pfeifen.
Benutzeravatar
bobobo
jaAdmin
Beiträge: 3857
Registriert: 13.09.2004 17:48
Kontaktdaten:

Re: RagDoll Ogre PhysikEngine - Bloody RagDolls

Beitrag von bobobo »

noch so einen .. etwas anders

Code: Alles auswählen

;
; ------------------------------------------------------------
;
;   PureBasic - RagDoll
;
;    (c) 2002 - Fantaisie Software , bobobo
; OpenGL scheitert bei mir, das mag am Treiber liegen (Laptop)
; das Programm sollte im Verzeichnis  \Examples\3D liegen
; weil es auf den Screenrequester und andere Daten dort zugreift
; alles ohne Gewähr
; ------------------------------------------------------------
;

#CameraSpeed = 0.5

IncludeFile "Screen3DRequester.pb"

Define.f KeyX, KeyY, MouseX, MouseY ,rott, moveit
Define.i Knupf1,knupf2, Knupf3 , hands 

Structure components
  nodeid.i
  ball.i
  limb.i
  texture.i
  Bodymesh.i
  Body.i
  HeadMesh.i
  Head.i
  Nose.i
  eyer.i
  eyel.i
  mouth.i
  earl.i
  earr.i
  arml.i
  armlu.i
  armr.i
  armru.i
  legl.i
  leglu.i
  legr.i
  legru.i
  footl.i
  footr.i
  ct_bodyhead.i
  ct_arml.i
  hinge_arml.i
  ct_armr.i
  hinge_armr.i
  hinge_legl.i
  hinge_leglu.i
  hinge_legr.i
  hinge_legru.i
  posx.i
  posy.i
  posz.i
EndStructure

Define ragdoll.components
Global NewList ragdolls.components()


Structure blood
  id.i
  time.i
EndStructure

bloodygameheight=340
NewList blood.blood()

Procedure killjoints()
  
  ForEach ragdolls()
    FreeJoint(#PB_All)
  Next
  
EndProcedure

Procedure makejoints()
  ;joints
  ForEach ragdolls()
    RotateEntity(ragdolls()\Head,0,0,0,#PB_Absolute)
    RotateEntity(ragdolls()\body,0,0,0,#PB_Absolute)
    RotateEntity(ragdolls()\arml,0,0,0,#PB_Absolute)
    RotateEntity(ragdolls()\armlu,0,0,0,#PB_Absolute)
    RotateEntity(ragdolls()\armr,0,0,0,#PB_Absolute)
    RotateEntity(ragdolls()\armru,0,0,0,#PB_Absolute)
    RotateEntity(ragdolls()\legl,0,0,0,#PB_Absolute)
    RotateEntity(ragdolls()\leglu,0,0,0,#PB_Absolute)
    RotateEntity(ragdolls()\legr,0,0,0,#PB_Absolute)
    RotateEntity(ragdolls()\legru,0,0,0,#PB_Absolute)
    
    
    ragdolls()\ct_bodyhead=ConeTwistJoint(#PB_Any,EntityID(ragdolls()\Body)  , 0, 0.7,0,EntityID(ragdolls()\Head) ,0,-0.4,0)
    ;ragdolls()\ct_bodyhead=PointJoint(#PB_Any,EntityID(ragdolls()\Body)  , 0, 0.7,0,EntityID(ragdolls()\Head) ,0,-0.4,0)
    
    ragdolls()\ct_arml     = ConeTwistJoint(#PB_Any,EntityID(ragdolls()\Body),-0.6,  0.5 ,0,EntityID(ragdolls()\arml)       , 0, 0.4,0)
    ragdolls()\hinge_arml  = HingeJoint(#PB_Any,EntityID(ragdolls()\arml)    ,   0, -0.45,0,1,0,0,EntityID(ragdolls()\armlu), 0,0.45,0,1,0,0)
    
    ragdolls()\ct_armr     = ConeTwistJoint(#PB_Any,EntityID(ragdolls()\Body), 0.6, 0.5,0,EntityID(ragdolls()\armr),        0, 0.4,0)
    ragdolls()\hinge_armr  = HingeJoint(#PB_Any,EntityID(ragdolls()\armr)    , 0  ,-0.45,0,1,0,0,EntityID(ragdolls()\armru), 0,0.45,0,1,0,0)
    
    ragdolls()\hinge_legl  = HingeJoint(#PB_Any,EntityID(ragdolls()\Body)    ,-0.3,-0.60,0,1,0,0,EntityID(ragdolls()\legl) , 0,0.40,0,1,0,0)
    ragdolls()\hinge_legr  = HingeJoint(#PB_Any,EntityID(ragdolls()\Body)    , 0.3,-0.60,0,1,0,0,EntityID(ragdolls()\legr) , 0,0.40,0,1,0,0)
    ragdolls()\hinge_leglu = HingeJoint(#PB_Any,EntityID(ragdolls()\legl)    ,   0,-0.45,0,1,0,0,EntityID(ragdolls()\leglu), 0,0.45,0,1,0,0)
    ragdolls()\hinge_legru = HingeJoint(#PB_Any,EntityID(ragdolls()\legr)    ,   0,-0.45,0,1,0,0,EntityID(ragdolls()\legru), 0,0.45,0,1,0,0)
    
    ;joints attributes       
    SetJointAttribute(ragdolls()\ct_bodyhead,#PB_ConeTwistJoint_SwingSpan,0.5)
    SetJointAttribute(ragdolls()\ct_bodyhead,#PB_ConeTwistJoint_SwingSpan2,0.5)
    SetJointAttribute(ragdolls()\ct_bodyhead,#PB_ConeTwistJoint_TwistSpan,0.5)
    ;       ;          
    SetJointAttribute(ragdolls()\ct_arml,#PB_ConeTwistJoint_SwingSpan ,0.2);seitl
    SetJointAttribute(ragdolls()\ct_arml,#PB_ConeTwistJoint_SwingSpan2,1);dreh
    SetJointAttribute(ragdolls()\ct_arml,#PB_ConeTwistJoint_TwistSpan ,2);vorzurück
    ;       ;          
    SetJointAttribute(ragdolls()\hinge_arml,#PB_HingeJoint_LowerLimit,0)
    SetJointAttribute(ragdolls()\hinge_arml,#PB_HingeJoint_UpperLimit,120)
    SetJointAttribute(ragdolls()\hinge_armr,#PB_HingeJoint_LowerLimit,0)
    SetJointAttribute(ragdolls()\hinge_armr,#PB_HingeJoint_UpperLimit,120)
    
    SetJointAttribute(ragdolls()\ct_armr,#PB_ConeTwistJoint_SwingSpan,0.2);seitlich
    SetJointAttribute(ragdolls()\ct_armr,#PB_ConeTwistJoint_SwingSpan2,1);dreh
    SetJointAttribute(ragdolls()\ct_armr,#PB_ConeTwistJoint_TwistSpan,2);vorzurück
    
    SetJointAttribute(ragdolls()\hinge_legl,#PB_HingeJoint_LowerLimit,-1)
    SetJointAttribute(ragdolls()\hinge_legl,#PB_HingeJoint_UpperLimit,120)
    SetJointAttribute(ragdolls()\hinge_legr,#PB_HingeJoint_LowerLimit,-1)
    SetJointAttribute(ragdolls()\hinge_legr,#PB_HingeJoint_UpperLimit,120)
    
    SetJointAttribute(ragdolls()\hinge_leglu,#PB_HingeJoint_LowerLimit,-120)
    SetJointAttribute(ragdolls()\hinge_leglu,#PB_HingeJoint_UpperLimit,1)
    SetJointAttribute(ragdolls()\hinge_legru,#PB_HingeJoint_LowerLimit,-120)
    SetJointAttribute(ragdolls()\hinge_legru,#PB_HingeJoint_UpperLimit,1)
  Next
EndProcedure

If InitEngine3D()
  ;Ergebnis = WorldDebug(#PB_World_DebugBody)
  
  Add3DArchive(#PB_Compiler_Home + "/Examples/3D/" +"Data/Textures", #PB_3DArchive_FileSystem)
  
  Add3DArchive(#PB_Compiler_Home + "/Examples/3D/" +"Data/Packs/desert.zip", #PB_3DArchive_Zip)
  Parse3DScripts()
  
  InitSprite()
  InitKeyboard()
  InitMouse()
  
  If Screen3DRequester()
    
    WorldShadows(#PB_Shadow_Additive,512)
    
    SkyBox("desert07.jpg")
    
    camera=CreateCamera(#PB_Any,0,0,100,100)
    MoveCamera(camera,0, 260 ,15, #PB_Absolute)
    
    texture1t=CreateTexture(#PB_Any,256,256)
    font=LoadFont(#PB_Any,"",8,#PB_Font_HighQuality)
    StartDrawing(TextureOutput(texture1t))
    DrawingFont(FontID(font))
    Box(0, 0, 256, 256, RGBA(222,222,255, 200))
    For l=0 To 128 
      Circle(Random(256),Random(256),Random(4)+1,RGBA(128,128,255,255))
    Next l
    DrawingMode(#PB_2DDrawing_Transparent)
    
    FrontColor(#Black)
    ;BackColor(#Black)
    th=TextHeight("X")
    ty=0
    DrawText(0, 0,"V:Hands OFF/ON (**)")
    ty+th
    DrawText(0,ty,"U:IdiotDance OFF/ON (**)")
    ty+th
    DrawText(0,ty,"R:reset (*)")
    ty+th
    DrawText(0,ty,"B:BloodyGame (**)")
    ty+th
    DrawText(0,ty,"BloodyGameHeight N:increase , M: decrease (*)")
    ty+th
    DrawText(0,ty,"T:upright (*)")
    ty+th
    DrawText(0,ty,"H:hail (*), G:strange (*)")
    ty+th
    DrawText(0,ty,"T: upright (*)")
    ty+th
    DrawText(0,ty,"F:forceup (near plate) (trampoline) (*)")
    ty+th
    DrawText(0,ty,"J:forceup (*)")
    ty+th
    DrawText(0,ty,"P:LookatAll (*)")
    ty+th
    DrawText(0,ty,"S:Shoot (**)")
    ty+th
    DrawText(0,ty,"L:Disassemble , O: Assemble (**)")
    ty+th
    DrawText(0,ty,"1,2,3,4,6,8 turns head (*)")
    ty+th
    DrawText(0,ty,"Add:Gravitiy decrease")
    ty+th
    DrawText(0,ty,"Sub:Gravitiy increase")
    ty+th
    DrawText(0,ty,"(*) while pressed,  (**) when release key")
    Debug ty
    StopDrawing()
    
    texture1=CreateMaterial(#PB_Any, TextureID(texture1t))
    
    texture2=CreateTexture(#PB_Any,256,256)
    StartDrawing(TextureOutput(texture2))
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    Box(0,0,256,256,RGBA(0,0,0,0))
    
    DrawingFont(FontID(font))
   
    ;FrontColor(RGBA(0,0,0,255))
    DrawText(0,0,"Press B and have fun",RGBA(255,255,0,255),RGBA(0,0,0,0))
    DrawText(0,40,"Hold N for a time and press B",RGBA(255,255,0,255),RGBA(0,0,0,0))
    DrawText(0,80,"and have even more fun",RGBA(255,255,0,255),RGBA(0,0,0,0))
    StopDrawing()
    infomat=CreateMaterial(#PB_Any,TextureID(texture2))
    MaterialBlendingMode(infomat,#PB_Material_AlphaBlend)
    
    texture2= CreateTexture(#PB_Any,256,256)
    StartDrawing(TextureOutput(texture2))
    Box(0,0,256,256,RGBA(80,80,80,180))
    
    For l=0 To 400
      Circle(Random(256),Random(256),Random(3)+1,RGBA(Random(5)+100,Random(5)+100,Random(5)+100,180))
    Next l
    
    DrawText(0,0,"ragdoll ®",RGBA(255,0,0,255),RGBA(80,80,80,222))
    StopDrawing()
    
    
    texture2=CreateMaterial(#PB_Any, TextureID(texture2))
    
    textureblue = CreateTexture(#PB_Any,256,256)
    StartDrawing(TextureOutput(textureblue))
    Box(0,0,256,256,#White)
    Ellipse(0,128,25,50,RGB(30, 144, 255))
    Ellipse(256,128,25,50,RGB(30, 144, 255))
    Ellipse(0,128,10,20,RGB(0 ,   0,   0))
    Ellipse(256,128,10,20,RGB(0 ,   0,   0))
    StopDrawing()
    MatEye = CreateMaterial(#PB_Any,TextureID(textureblue))
    
    textureflesh = CreateTexture(#PB_Any,256,256)
    StartDrawing(TextureOutput(textureflesh))
    Box(0,0,256,256,RGB(255, 218, 185))
    For f=0 To 512
      Circle(Random(255),Random(255),Random(2),RGB(243, 208, 161))
    Next
    
    StopDrawing()
    MatFlesh = CreateMaterial(#PB_Any,TextureID(textureflesh))
    
    texturemouth = CreateTexture(#PB_Any,256,256)
    StartDrawing(TextureOutput(texturemouth))
    Box(0,0,256,256,#White)
    For t=0 To 256 Step 16
      Line(t,0,1,256,#Black)
      Line(t-1,0,1,256,#Black)
      Line(t-2,0,1,256,#Black)
      Line(t+1,0,1,256,#Black)
      Line(t+2,0,1,256,#Black)
    Next t
    
    StopDrawing()
    MatMouth = CreateMaterial(#PB_Any,TextureID(texturemouth))
    
    texturekontakt= CreateTexture(#PB_Any,256,256)
    
    StartDrawing(TextureOutput(texturekontakt))
    DrawingMode(#PB_2DDrawing_AlphaBlend)
    Box(0,0,256,256,RGBA(0,0,0,0))
    For c=1 To 32
      bx=64+Random(128)
      by=64+Random(128)
      br=Random(32)
      Circle(bx,by,br,RGBA(255,0,0,br*4))
    Next c
    
    StopDrawing()
    
    MatKontakt = CreateMaterial(#PB_Any,TextureID(texturekontakt))
    
    MaterialBlendingMode(MatKontakt,#PB_Material_AlphaBlend)
    RotateMaterial(MatKontakt,0.005,#PB_Material_Animated)
    AddMaterialLayer(MatKontakt,TextureID(texturekontakt),#PB_Material_Add)
    
    Bodymesh = CreateCube(#PB_Any,1)
    LimbMesh = CreateCylinder(#PB_Any, 0.1 ,0.80)
    
    HeadMesh  = CreateSphere(#PB_Any , 0.5 ,15,15)
    NoseMesh  = CreateSphere(#PB_Any , 0.25, 3, 4)
    EyeMeshl  = CreateSphere(#PB_Any , 0.10,20,20)
    EyeMeshr  = CreateSphere(#PB_Any , 0.10,20,20)
    MouthMesh = CreateSphere(#PB_Any , 0.25,15,15)
    EarMeshl =  CreateSphere(#PB_Any , 0.25,20,20)
    EarMeshr =  CreateSphere(#PB_Any , 0.25,20,20)
    FootMeshl = CreateSphere(#PB_Any , 0.25,20,20)
    FootMeshr = CreateSphere(#PB_Any , 0.25,20,20)
    
    kontaktMesh= CreatePlane(#PB_Any,0.25,0.25,1,1,1,1)
    TransformMesh(kontaktMesh,0,0.05,0,1,1,1,0,0,0)
    kontakt=CreateEntity(#PB_Any,MeshID(kontaktMesh),MaterialID(MatKontakt))
    EntityRenderMode(kontakt, #PB_Entity_CastShadow)
    
    
    TransformMesh(NoseMesh , 0.00, 0.00, 0.50, 1.00, 1.00, 1.00,  0.00, 0.00, 0.00)
    TransformMesh(EyeMeshl ,-0.35, 0.20, 0.25, 1.00, 1.00, 1.00,  0.00, 0.00, 0.00)
    TransformMesh(EyeMeshr , 0.35, 0.20, 0.25, 1.00, 1.00, 1.00,  0.00, 0.00, 0.00)
    TransformMesh(MouthMesh, 0.00,-0.15, 0.22, 1.50, 0.45, 1.00, 40.00,  0.00,  0.00)
    TransformMesh(EarMeshl ,-0.50,-0.10,-0.20, 1.00, 1.00, 0.25,  0.00,  0.00,  0.00)
    TransformMesh(EarMeshr , 0.50,-0.10,-0.20, 1.00, 1.00, 0.25,  0.00,  0.00,  0.00)
    TransformMesh(FootMeshl,-0.05,-0.40, 0.25, 0.50, 0.25, 1.00, 10.00,  0.00,  0.00)
    TransformMesh(FootMeshr, 0.05,-0.40, 0.25, 0.50, 0.25, 1.00, 10.00,  0.00,  0.00)
    
    For r=1 To 3 ;3 Dinger
      
      AddElement(ragdolls())
      
      ragdolls()\posx=r*2-2
      ragdolls()\posy=260
      ragdolls()\posz=0
      
      ragdolls()\texture=texture2
      
      ;bodyparts
      
      ragdolls()\Body=CreateEntity(#PB_Any,MeshID(Bodymesh),MaterialID(ragdolls()\texture),ragdolls()\posx,ragdolls()\posy,ragdolls()\posz)
      ScaleEntity(ragdolls()\Body,1.0,1,0.25)
      
      ragdolls()\Nose  = CreateEntity(#PB_Any,MeshID(NoseMesh) ,MaterialID(MatFlesh))
      ragdolls()\eyel  = CreateEntity(#PB_Any,MeshID(EyeMeshl) ,MaterialID(MatEye))
      ragdolls()\eyer  = CreateEntity(#PB_Any,MeshID(EyeMeshr) ,MaterialID(MatEye))
      ragdolls()\mouth = CreateEntity(#PB_Any,MeshID(MouthMesh),MaterialID(MatMouth))
      ragdolls()\earl  = CreateEntity(#PB_Any,MeshID(EarMeshl) ,MaterialID(MatFlesh))
      ragdolls()\earr  = CreateEntity(#PB_Any,MeshID(EarMeshr) ,MaterialID(MatFlesh))
      
      
      ragdolls()\Head = CreateEntity(#PB_Any,MeshID(HeadMesh),MaterialID(MatFlesh),  ragdolls()\posx,ragdolls()\posy+1,ragdolls()\posz)
      AttachEntityObject(ragdolls()\Head,"",EntityID(ragdolls()\Nose) ,0,0,0,0,0,0)
      AttachEntityObject(ragdolls()\Head,"",EntityID(ragdolls()\eyel) ,0,0,0,0,0,0)
      AttachEntityObject(ragdolls()\Head,"",EntityID(ragdolls()\eyer) ,0,0,0,0,0,0)
      AttachEntityObject(ragdolls()\Head,"",EntityID(ragdolls()\mouth),0,0,0,0,0,0)
      AttachEntityObject(ragdolls()\Head,"",EntityID(ragdolls()\earl) ,0,0,0,0,0,0)
      AttachEntityObject(ragdolls()\Head,"",EntityID(ragdolls()\earr) ,0,0,0,0,0,0)
      
      
      ragdolls()\arml  = CreateEntity(#PB_Any,MeshID(LimbMesh),MaterialID(ragdolls()\texture) ,ragdolls()\posx-0.6,ragdolls()\posy,ragdolls()\posz)
      ragdolls()\armlu = CreateEntity(#PB_Any,MeshID(LimbMesh),MaterialID(ragdolls()\texture) ,ragdolls()\posx-0.6,ragdolls()\posy-1,ragdolls()\posz)
      ragdolls()\armr  = CreateEntity(#PB_Any,MeshID(LimbMesh),MaterialID(ragdolls()\texture) ,ragdolls()\posx+0.6,ragdolls()\posy,ragdolls()\posz)
      ragdolls()\armru = CreateEntity(#PB_Any,MeshID(LimbMesh),MaterialID(ragdolls()\texture) ,ragdolls()\posx+ 0.6,ragdolls()\posy-1,ragdolls()\posz)
      
      ragdolls()\legl = CreateEntity(#PB_Any,MeshID(LimbMesh),MaterialID(ragdolls()\texture)  ,ragdolls()\posx-0.3,ragdolls()\posy-1,ragdolls()\posz)
      ragdolls()\legr = CreateEntity(#PB_Any,MeshID(LimbMesh),MaterialID(ragdolls()\texture)  ,ragdolls()\posx+ 0.3,ragdolls()\posy-1,ragdolls()\posz)
      
      ragdolls()\leglu = CreateEntity(#PB_Any,MeshID(LimbMesh),MaterialID(ragdolls()\texture) ,ragdolls()\posx-0.3,ragdolls()\posy-2,ragdolls()\posz)
      ragdolls()\legru = CreateEntity(#PB_Any,MeshID(LimbMesh),MaterialID(ragdolls()\texture) ,ragdolls()\posx+ 0.3,ragdolls()\posy-2,ragdolls()\posz)
      ragdolls()\footl = CreateEntity(#PB_Any,MeshID(FootMeshl),MaterialID(ragdolls()\texture))
      
      AttachEntityObject(ragdolls()\leglu,"",EntityID(ragdolls()\footl) ,0,0,0,0,0,0)
      ragdolls()\footr = CreateEntity(#PB_Any,MeshID(FootMeshr),MaterialID(ragdolls()\texture))
      
      AttachEntityObject(ragdolls()\legru,"",EntityID(ragdolls()\footr) ,0,0,0,0,0,0)
      
      ;bodyPhysics
      EntityPhysicBody(ragdolls()\Body,#PB_Entity_BoxBody  ,10, 0,1)
      EntityRenderMode(ragdolls()\Body, #PB_Entity_CastShadow)
      
      EntityRenderMode(ragdolls()\Head, #PB_Entity_CastShadow)
      EntityPhysicBody(ragdolls()\Head, #PB_Entity_SphereBody, 5, 0.25, 1)
      
      EntityRenderMode(ragdolls()\arml, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\arml, #PB_Entity_CylinderBody,  1, 0 ,1)
      EntityRenderMode(ragdolls()\armlu, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\armlu, #PB_Entity_CylinderBody, 1, 0, 1)
      
      EntityRenderMode(ragdolls()\armr, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\armr, #PB_Entity_CylinderBody,  1, 0, 1)
      EntityRenderMode(ragdolls()\armru, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\armru, #PB_Entity_CylinderBody, 1, 0,1)
      
      EntityRenderMode(ragdolls()\legl, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\legl, #PB_Entity_CylinderBody, 1, 0,1)
      EntityRenderMode(ragdolls()\leglu, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\leglu, #PB_Entity_CylinderBody,1, 0,1)
      
      EntityRenderMode(ragdolls()\legr, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\legr, #PB_Entity_CylinderBody, 1, 0,1)
      EntityRenderMode(ragdolls()\legru, #PB_Entity_CastShadow) 
      EntityPhysicBody(ragdolls()\legru, #PB_Entity_CylinderBody,1, 0,1)
    
    Next 
    
    makejoints()  
    ;
    
    
    plate=CreateCube(#PB_Any,1)
    ScaleMaterial(texture1,1,1)
    RotateMaterial(texture1,90,#PB_Material_Fixed)
    
    platte=CreateEntity(#PB_Any,MeshID(plate),MaterialID(texture1),0,0,0)
    
    ScaleEntity(platte,70,0.01,70)
    MoveEntity(platte,0,256,0)
    EntityRenderMode(platte, #PB_Entity_CastShadow)
    EntityPhysicBody(platte,#PB_Entity_StaticBody,1000,1,0.5)
    
    info=CreateEntity(#PB_Any,MeshID(plate),MaterialID(infomat),0,0,0)
    ScaleEntity(info,10,0.01,10)
    MoveEntity(info,5,260,0)
    RotateEntity(info,90,0,0)
    EntityRenderMode(info,  #PB_Entity_DisplaySkeleton )
    
    suncolor=#White
    
    sun=CreateLight(#PB_Any,suncolor,17830,12860,10930,#PB_Light_Point)
    
    CameraLookAt(camera,EntityX(ragdolls()\Head),EntityY(ragdolls()\Head),EntityZ(ragdolls()\Head))
    dance=1
    hands=1
    
    
    Repeat
      Debug hands
      
      Debug "************"
      
      Screen3DEvents()
      If ExamineMouse()
        MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
        MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
      EndIf
      
      If hands=1
        hands=2
        ;Debug hands  
        ;Händchenhalten    
        sp=-0.5
        tau.f=0
        damp.f=0.5
        SelectElement(ragdolls(),0)
        jx=EntityX(ragdolls()\armru)
        
        jy=EntityY(ragdolls()\armru)
        jz=EntityZ(ragdolls()\armru)
        id=EntityID(ragdolls()\armru)
        SelectElement(ragdolls(),1)
        jx1=EntityX(ragdolls()\armlu)
        jy1=EntityY(ragdolls()\armlu)
        jz1=EntityZ(ragdolls()\armlu)
        id1=EntityID(ragdolls()\armlu)
        knupf1=PointJoint(#PB_Any,id,0,sp,0,id1,0,sp,0)
        SetJointAttribute(knupf1,#PB_PointJoint_Damping,damp)
        SetJointAttribute(knupf1,#PB_PointJoint_Tau,tau)
        
        jx=EntityX(ragdolls()\armru)
        jy=EntityY(ragdolls()\armru)
        jz=EntityZ(ragdolls()\armru)
        id=EntityID(ragdolls()\armru)
        SelectElement(ragdolls(),2)
        jx1=EntityX(ragdolls()\armlu)
        jy1=EntityY(ragdolls()\armlu)
        jz1=EntityZ(ragdolls()\armlu)
        id1=EntityID(ragdolls()\armlu)
        knupf2=PointJoint(#PB_Any,id,0,sp,0,id1,0,sp,0)
        SetJointAttribute(knupf2,#PB_PointJoint_Damping,damp)
        SetJointAttribute(knupf2,#PB_PointJoint_Tau,tau)
        
        
      EndIf
      
      If hands=3
        ;Debug hands  
        hands=0
        If knupf1
          FreeJoint(knupf1)
          knupf1=0
        EndIf
        If knupf2
          FreeJoint(knupf2)
          knupf2=0
        EndIf
        If knupf3
          FreeJoint(knupf3)
          knupf3=0
        EndIf
        
      EndIf
      
      If dance=1
        ;dance=2
        ForEach ragdolls()
          If EntityY(ragdolls()\Head)<259.5
            ApplyEntityImpulse(ragdolls()\Head  ,0, 9,0,0,1,0)
            ApplyEntityImpulse(ragdolls()\legru  ,0, -5,0,0,-1,0)
            ApplyEntityImpulse(ragdolls()\leglu  ,0, -5,0,0,-1,0)
            If EntityY(ragdolls()\leglu)<256.8
              ApplyEntityImpulse(ragdolls()\leglu,Random(2)-1,Random(8),Random(2)-1)
            EndIf
            If EntityY(ragdolls()\legru)<256.8
              ApplyEntityImpulse(ragdolls()\legru,Random(2)-1,Random(8),Random(2)-1)
            EndIf
            ApplyEntityImpulse(ragdolls()\armlu,Random(2)-1,Random(2)-1,Random(2)-1)
            ApplyEntityImpulse(ragdolls()\armru,Random(2)-1,Random(2)-1,Random(2)-1)
          EndIf
        Next          
      EndIf
      
      KeyboardMode(#PB_Keyboard_International)
      
      If ExamineKeyboard()
        If KeyboardPushed(#PB_Key_P) Or KeyboardReleased(#PB_Key_R) 
          px.f=0
          py.f=0
          pz.f=0
          ForEach ragdolls()
            px+EntityX(ragdolls()\Body)
            py+EntityY(ragdolls()\Body)
            pz+EntityZ(ragdolls()\Body)
          Next
          px=px/ListSize(ragdolls())
          py=py/ListSize(ragdolls())
          pz=pz/ListSize(ragdolls())
          MoveCamera(camera,0, 260 ,15, #PB_Absolute)
          CameraLookAt(camera,px,py,pz)
        EndIf
        If KeyboardPushed(#PB_Key_N)
          bloodygameheight+1
        EndIf
        If KeyboardPushed(#PB_Key_M)
          bloodygameheight-1
          If bloodygameheight<290
            bloodygameheight=290
          EndIf
          
        EndIf
        If KeyboardReleased(#PB_Key_O)
          killjoints()
          hands=0
          makejoints()
        EndIf
        If KeyboardReleased(#PB_Key_L)
          killjoints()
          hands=0
        EndIf
        
        If KeyboardReleased(#PB_Key_B)
          px.f=0
          py.f=0
          pz.f=0
          ForEach ragdolls()
            px+EntityX(ragdolls()\Body)
            py+EntityY(ragdolls()\Body)
            pz+EntityZ(ragdolls()\Body)
          Next
          px=px/ListSize(ragdolls())
          py=py/ListSize(ragdolls())
          pz=pz/ListSize(ragdolls())
          ForEach(ragdolls())
            ApplyEntityImpulse(ragdolls()\Body,Random(20)-10,0,Random(20)-10)
            ApplyEntityImpulse(ragdolls()\Head,Random(20)-10,0,Random(20)-10)
          Next
          MoveCamera(camera,px,py+10,pz,#PB_Absolute)
          CameraLookAt(camera,0,260,0)
        EndIf
        If KeyboardPushed(#PB_Key_S) And shoot=0
          ForEach ragdolls()
            ApplyEntityImpulse(ragdolls()\Body,0,0,-100,Random(8)-4,Random(8)-4,Random(8)-4)
            shoot=1
          Next
        EndIf
        
        If KeyboardReleased(#PB_Key_S)
          shoot=0
        EndIf
        
        If KeyboardPushed(#PB_Key_R)
          ForEach ragdolls()
            MoveEntity(ragdolls()\Head,ragdolls()\posx,ragdolls()\posy,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\Body,ragdolls()\posx,ragdolls()\posy-1,ragdolls()\posz,#PB_Absolute)
            RotateEntity(ragdolls()\Body,0,0,0,#PB_Absolute)
            MoveEntity(ragdolls()\legr,ragdolls()\posx+0.3,ragdolls()\posy-2,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\legl,ragdolls()\posx-0.3,ragdolls()\posy-2,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\legru,ragdolls()\posx+0.3,ragdolls()\posy-2.9,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\leglu,ragdolls()\posx-0.3,ragdolls()\posy-2.9,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\armr,ragdolls()\posx+0.6,ragdolls()\posy-1,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\arml,ragdolls()\posx-0.6,ragdolls()\posy-1,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\armru,ragdolls()\posx+0.6,ragdolls()\posy-2,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\armlu,ragdolls()\posx-0.6,ragdolls()\posy-2,ragdolls()\posz,#PB_Absolute)
          Next
        EndIf
        
        If KeyboardPushed(#PB_Key_B)
          ForEach ragdolls()
            MoveEntity(ragdolls()\Head,ragdolls()\posx,bloodygameheight,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\Body,ragdolls()\posx,bloodygameheight-1,ragdolls()\posz,#PB_Absolute)
            RotateEntity(ragdolls()\Body,0,0,0,#PB_Absolute)
            MoveEntity(ragdolls()\legr,ragdolls()\posx+0.3,bloodygameheight-2,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\legl,ragdolls()\posx-0.3,bloodygameheight-2,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\legru,ragdolls()\posx+0.3,bloodygameheight-2.9,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\leglu,ragdolls()\posx-0.3,bloodygameheight-2.9,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\armr,ragdolls()\posx+0.6,bloodygameheight-1,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\arml,ragdolls()\posx-0.6,bloodygameheight-1,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\armru,ragdolls()\posx+0.6,bloodygameheight-2,ragdolls()\posz,#PB_Absolute)
            MoveEntity(ragdolls()\armlu,ragdolls()\posx-0.6,bloodygameheight-2,ragdolls()\posz,#PB_Absolute)
          Next
        EndIf
        
        If KeyboardReleased(#PB_Key_V) 
          Select hands
            Case 0
              hands=1
            Case 2
              hands=3
          EndSelect
        EndIf
        
        
        If KeyboardPushed(#PB_Key_T)
          ForEach ragdolls()
            ApplyEntityImpulse(ragdolls()\armlu ,0,-1,0,0,-1,0)
            ApplyEntityImpulse(ragdolls()\armru ,0,-1,0,0,-1,0)
            ApplyEntityImpulse(ragdolls()\leglu,0,-3,0,0,-1,0)
            ApplyEntityImpulse(ragdolls()\legru,0,-3,0,0,-1,0)
            ApplyEntityImpulse(ragdolls()\Head  ,0, 10,0,0,1,0)
          Next
        EndIf
        
        If KeyboardPushed(#PB_Key_J)
          ForEach ragdolls()
            ApplyEntityImpulse(ragdolls()\Body,0,10,0)
          Next
        EndIf
        
        If KeyboardReleased(#PB_Key_U)
          Select dance
            Case 1
              dance=0
            Case 0
              dance=1
          EndSelect
          
        EndIf
        
        
        If KeyboardPushed(#PB_Key_F)
          ForEach ragdolls()
            If EntityY(ragdolls()\Body)<259
              ApplyEntityImpulse(ragdolls()\Body,0, 3,0,0,-10,0)
              ApplyEntityImpulse(ragdolls()\armlu  ,0, 3,0,0,-10,0)
              ApplyEntityImpulse(ragdolls()\armru  ,0, 3,0,0,-10,0)
              ApplyEntityImpulse(ragdolls()\leglu ,0, 3,0,0,-10,0)
              ApplyEntityImpulse(ragdolls()\legru ,0, 3,0,0,-10,0)
              ApplyEntityImpulse(ragdolls()\Head   ,0,6,0,0,0  ,0)
            EndIf
          Next
        EndIf
        
        If KeyboardPushed(#PB_Key_H)
          ForEach ragdolls()
            ApplyEntityImpulse(ragdolls()\armlu,0,1,0,0,-2,0)
            ApplyEntityImpulse(ragdolls()\armru,0,1,0,0,-2,0)
            ApplyEntityImpulse(ragdolls()\legl,0,-4,0,0,-20,0)
            ApplyEntityImpulse(ragdolls()\legr,0,-4,0,0,-20,0)
            ApplyEntityImpulse(ragdolls()\Head,0,5,0,0,0,0)
            ApplyEntityImpulse(ragdolls()\Body,0,4,0,0,10,0)
          Next
        EndIf
        
        If KeyboardPushed(#PB_Key_Add)
          wg+1
          WorldGravity(wg)
        EndIf
        
        If KeyboardPushed(#PB_Key_Subtract)
          wg-1
          WorldGravity(wg)
        EndIf
        
        If KeyboardPushed(#PB_Key_G)
          
          ForEach ragdolls()
            ApplyEntityImpulse(ragdolls()\Head   ,0, 2,0)
            ApplyEntityImpulse(ragdolls()\legl , 0, Random(4),0,0,-6,0)
            ApplyEntityImpulse(ragdolls()\legr , 0, Random(4),0,0,-6,0)
            ApplyEntityImpulse(ragdolls()\armlu , 0, Random(1),0,0,6,0)
            ApplyEntityImpulse(ragdolls()\armru , 0, Random(1),0,0,6,0)
            
            ApplyEntityImpulse(ragdolls()\Body,0,-6,0,0,0,0)
          Next
        EndIf
        
        If KeyboardPushed(#PB_Key_Pad6)
          ForEach ragdolls()
            RotateEntity(ragdolls()\Head,0,10,0,#PB_Relative)
          Next
        EndIf
        If KeyboardPushed(#PB_Key_Pad4)
          ForEach ragdolls()
            RotateEntity(ragdolls()\Head,0,-10,0,#PB_Relative)
          Next
        EndIf
        If KeyboardPushed(#PB_Key_Pad1)
          ForEach ragdolls()
            RotateEntity(ragdolls()\Head,0,0,-5,#PB_Relative)
          Next
        EndIf
        If KeyboardPushed(#PB_Key_Pad3)
          ForEach ragdolls()
            RotateEntity(ragdolls()\Head,0,0,5,#PB_Relative)
          Next
        EndIf
        If KeyboardPushed(#PB_Key_Pad8)
          ForEach ragdolls()
            RotateEntity(ragdolls()\Head,-10,0,0,#PB_Relative)
          Next
        EndIf
        If KeyboardPushed(#PB_Key_Pad2)
          ForEach ragdolls()
            RotateEntity(ragdolls()\Head,10,0,0,#PB_Relative)
          Next
        EndIf
        
        If KeyboardPushed(#PB_Key_Left)
          KeyX = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Right)
          KeyX = #CameraSpeed
        Else
          KeyX = 0
        EndIf
        
        If KeyboardPushed(#PB_Key_Up)
          KeyY = -#CameraSpeed
        ElseIf KeyboardPushed(#PB_Key_Down)
          KeyY = #CameraSpeed
        Else
          KeyY = 0
        EndIf
      EndIf
      
      RotateCamera(camera, MouseY, MouseX, 0, #PB_Relative)
      MoveCamera  (camera, KeyX, 0, KeyY)
      
      ;Make it Bloody
      ExamineWorldCollisions(#True)
      While NextWorldCollision()
        
        If platte=FirstWorldCollisionEntity() Or platte=SecondWorldCollisionEntity()
          WorldCollisionAppliedImpulse()
          
          impy=GetY()
          If impy>666
            killjoints()
            hands=0
          EndIf
          
          If impy>20 ; blood with heavier impulses
            If impy>100
              impy=100
            EndIf
            
            WorldCollisionContact()
            AddElement(blood())
            blood()\id=CopyEntity(kontakt,#PB_Any)
            ScaleEntity(blood()\id,impy/5,1,impy/5,#PB_Relative)
            
            blood()\time=ElapsedMilliseconds()+(impy*impy/2)
            MoveEntity(blood()\id,GetX(),GetY(),GetZ(),#PB_Absolute)
            
          EndIf
          
          
        EndIf
        
      Wend
      ForEach blood()
        If ElapsedMilliseconds()>blood()\time+5000
          FreeEntity(blood()\id)
          DeleteElement(blood())
        EndIf
      Next
      
      RenderWorld()
      
      FlipBuffers()
    Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1
    
  EndIf
  
Else
  MessageRequester("Error", "The 3D Engine can't be initialized", 0)
EndIf
End
‮pb aktuell5.7 - windoof aktuell und sowas von 10
Ich hab Tinnitus im Auge. Ich seh nur Pfeifen.
Benutzeravatar
DrShrek
Beiträge: 1970
Registriert: 08.09.2004 00:59

Re: RagDoll Ogre PhysikEngine

Beitrag von DrShrek »

wenn ich das an 5.70 Beta 1 anpasse stürzt es ab
Siehste! Geht doch....?!
PB*, *4PB, PetriDish, Movie2Image, PictureManager, TrainYourBrain, ...
Antworten