RagDolls Ogre and Physics

Applications, Games, Tools, User libs and useful stuff coded in PureBasic
User avatar
bobobo
Enthusiast
Enthusiast
Posts: 206
Joined: Mon Jun 09, 2003 8:30 am

Re: RagDolls Ogre and Physics

Post by bobobo »

사십 둘 .
User avatar
Kwai chang caine
Always Here
Always Here
Posts: 5494
Joined: Sun Nov 05, 2006 11:42 pm
Location: Lyon - France

Re: RagDolls Ogre and Physics

Post by Kwai chang caine »

Very nice :D
Works nice here, thanks for sharing 8)
ImageThe happiness is a road...
Not a destination
User avatar
bobobo
Enthusiast
Enthusiast
Posts: 206
Joined: Mon Jun 09, 2003 8:30 am

Re: RagDolls Ogre and Physics

Post by bobobo »

사십 둘 .
BarryG
Addict
Addict
Posts: 4130
Joined: Thu Apr 18, 2019 8:17 am

Re: RagDolls Ogre and Physics

Post by BarryG »

Doesn't compile because of this line:

Code: Select all

IncludeFile "Screen3DRequester.pb"
The file isn't found. Just to let you know that your code needs updating.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: RagDolls Ogre and Physics

Post by Paul »

BarryG wrote: Tue Jul 05, 2022 12:26 pm Doesn't compile because of this line:

Code: Select all

IncludeFile "Screen3DRequester.pb"
The file isn't found. Just to let you know that your code needs updating.
I'm sure it is assumed the code is to be placed in the "\Examples\3D" folder with the rest of the 3D examples but you could simply change
IncludeFile "Screen3DRequester.pb" to IncludeFile #PB_Compiler_Home + "examples/3d/Screen3DRequester.pb" if you want to run the code outside of this folder.
Image Image
BarryG
Addict
Addict
Posts: 4130
Joined: Thu Apr 18, 2019 8:17 am

Re: RagDolls Ogre and Physics

Post by BarryG »

We both know that, but newbies trying the code might not assume that, so I was just letting bobobo know about the issue.
User avatar
bobobo
Enthusiast
Enthusiast
Posts: 206
Joined: Mon Jun 09, 2003 8:30 am

Re: RagDolls Ogre and Physics

Post by bobobo »

finally , an update for pb 6.2 , fixes the meanwhile obsolete(i guess ¿?) screen3d-requester

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - RagDoll fuer Purebasic ab 6.20
;
;    (c) 2002 - Fantaisie Software , bobobo
; 
; das Programm sollte im Verzeichnis  \Examples\3D liegen
; weil ich das sol will
; alles ohne Gewähr
; ------------------------------------------------------------
;

#CameraSpeed = 1



Define.f KeyX, KeyY, MouseX, MouseY ,rott, moveit, I_f
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

InitEngine3D()

InitSprite()
InitKeyboard()
InitMouse()

ExamineDesktops():dx=DesktopWidth(0)*0.8:dy=DesktopHeight(0)*0.8
OpenWindow(0, 0,0, DesktopUnscaledX(dx),DesktopUnscaledY(dy), "Camera - [Esc] quit",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, dx, dy, 0, 0, 0)

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()


;WorldShadows(#PB_Shadow_Additive,512)
SkyBox("desert07.jpg")
camera=CreateCamera(#PB_Any,0,0,100,100)
;CameraRenderMode(camera, #PB_Camera_Plot)
MoveCamera(camera,0, 260 ,15, #PB_Absolute)

texture1t=CreateTexture(#PB_Any,512,512)
font=LoadFont(#PB_Any,"",14,#PB_Font_HighQuality)
StartDrawing(TextureOutput(texture1t))
DrawingFont(FontID(font))
Box(0, 0, 512, 512, RGBA(222,222,255, 200))
For l=0 To 128 
  Circle(Random(512),Random(512),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,"Q:Quakemode, Hello Newzealand")
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,50,"Hold N for a time and press B",RGBA(255,255,0,255),RGBA(0,0,0,0))
DrawText(0,70,"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))

texturedead = CreateTexture(#PB_Any,256,256)
StartDrawing(TextureOutput(texturedead))
Box(0,0,256,256,#White)
For de=0 To 10
  Line(0,128+de,256,1,#Black)
  Line(0,128-de,256,1,#Black)
Next

For de=0 To 10
  Line(de,0,1,256,#Black)
  Line(256-de,0,1,256,#Black)
  
Next

StopDrawing()
MatDeadEye = CreateMaterial(#PB_Any,TextureID(texturedead))

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); ,12,12)
NoseMesh  = CreateSphere(#PB_Any , 0.25, 3, 4)
EyeMeshl  = CreateSphere(#PB_Any , 0.10);,8,8)
EyeMeshr  = CreateSphere(#PB_Any , 0.10);,8,8)
MouthMesh = CreateSphere(#PB_Any , 0.25,15,15)
EarMeshl =  CreateSphere(#PB_Any , 0.25);,8,8)
EarMeshr =  CreateSphere(#PB_Any , 0.25);,8,8)
FootMeshl = CreateSphere(#PB_Any , 0.25,6,6)
FootMeshr = CreateSphere(#PB_Any , 0.25,6,6)

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.02,-0.38, 0.15, 0.50, 0.25, 1.00, 10.00, 20.00,  0.00)
TransformMesh(FootMeshr, 0.02,-0.38, 0.15, 0.50, 0.25, 1.00, 10.00,-20.00,  0.00)

For r=1 To 8 ;3 Dinger
  
  AddElement(ragdolls())
  
  ragdolls()\posx=r*2-2
  ragdolls()\posy=259 ;height
  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)
  
  ;rendermode=#PB_Entity_CastShadow
  ;rendermode=#PB_Entity_CastShadow|#PB_Entity_DisplaySkeleton
  
  ;bodyPhysics
  CreateEntityBody(ragdolls()\Body,#PB_Entity_BoxBody  ,10, 0,1)
  EntityRenderMode(ragdolls()\Body, #PB_Entity_CastShadow)
  
  EntityRenderMode(ragdolls()\Head, #PB_Entity_CastShadow)
  CreateEntityBody(ragdolls()\Head, #PB_Entity_ConvexHullBody, 5, 0.25, 1)
  
  EntityRenderMode(ragdolls()\arml, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\arml, #PB_Entity_CylinderBody,  1, 0 ,1)
  EntityRenderMode(ragdolls()\armlu, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\armlu, #PB_Entity_CylinderBody, 1, 0, 1)
  
  EntityRenderMode(ragdolls()\armr, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\armr, #PB_Entity_CylinderBody,  1, 0, 1)
  EntityRenderMode(ragdolls()\armru, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\armru, #PB_Entity_CylinderBody, 1, 0,1)
  
  EntityRenderMode(ragdolls()\legl, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\legl, #PB_Entity_CylinderBody, 1, 0,1)
  EntityRenderMode(ragdolls()\leglu, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\leglu, #PB_Entity_CylinderBody,1, 0,1)
  
  EntityRenderMode(ragdolls()\legr, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\legr, #PB_Entity_CylinderBody, 1, 0,1)
  EntityRenderMode(ragdolls()\legru, #PB_Entity_CastShadow) 
  CreateEntityBody(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)
;boxes
;For r=1 To 600
;  b=CreateEntity(#PB_Any,MeshID(plate),MaterialID(texture1),Random(20)-10,270,Random(20)-10);,Random(1),Random(10)+274,Random(1))
;  ScaleEntity(b,0.2,3,0.2)
;  CreateEntityBody(b,#PB_Entity_BoxBody   ,05,0.01,100)
;Next r

platte=CreateEntity(#PB_Any,MeshID(plate),MaterialID(texture1),0,0,0)

;ScaleEntity(platte,70,0.01,70)
ScaleEntity(platte,70,0.5,70)
MoveEntity(platte,0,256,0) ; 256 plate height 
EntityRenderMode(platte, #PB_Entity_CastShadow)
CreateEntityBody(platte,#PB_Entity_StaticBody,1,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)
    
    jx=EntityX(ragdolls()\armru)
    jy=EntityY(ragdolls()\armru)
    jz=EntityZ(ragdolls()\armru)
    id=EntityID(ragdolls()\armru)
    SelectElement(ragdolls(),3)
    jx1=EntityX(ragdolls()\armlu)
    jy1=EntityY(ragdolls()\armlu)
    jz1=EntityZ(ragdolls()\armlu)
    id1=EntityID(ragdolls()\armlu)
    knupf3=PointJoint(#PB_Any,id,0,sp,0,id1,0,sp,0)
    SetJointAttribute(knupf3,#PB_PointJoint_Damping,damp)
    SetJointAttribute(knupf3,#PB_PointJoint_Tau,tau)
    
    jx=EntityX(ragdolls()\armru)
    jy=EntityY(ragdolls()\armru)
    jz=EntityZ(ragdolls()\armru)
    id=EntityID(ragdolls()\armru)
    SelectElement(ragdolls(),4)
    jx1=EntityX(ragdolls()\armlu)
    jy1=EntityY(ragdolls()\armlu)
    jz1=EntityZ(ragdolls()\armlu)
    id1=EntityID(ragdolls()\armlu)
    knupf4=PointJoint(#PB_Any,id,0,sp,0,id1,0,sp,0)
    SetJointAttribute(knupf4,#PB_PointJoint_Damping,damp)
    SetJointAttribute(knupf4,#PB_PointJoint_Tau,tau)
    
    jx=EntityX(ragdolls()\armru)
    jy=EntityY(ragdolls()\armru)
    jz=EntityZ(ragdolls()\armru)
    id=EntityID(ragdolls()\armru)
    SelectElement(ragdolls(),5)
    jx1=EntityX(ragdolls()\armlu)
    jy1=EntityY(ragdolls()\armlu)
    jz1=EntityZ(ragdolls()\armlu)
    id1=EntityID(ragdolls()\armlu)
    knupf5=PointJoint(#PB_Any,id,0,sp,0,id1,0,sp,0)
    SetJointAttribute(knupf5,#PB_PointJoint_Damping,damp)
    SetJointAttribute(knupf5,#PB_PointJoint_Tau,tau)
    
    jx=EntityX(ragdolls()\armru)
    jy=EntityY(ragdolls()\armru)
    jz=EntityZ(ragdolls()\armru)
    id=EntityID(ragdolls()\armru)
    SelectElement(ragdolls(),6)
    jx1=EntityX(ragdolls()\armlu)
    jy1=EntityY(ragdolls()\armlu)
    jz1=EntityZ(ragdolls()\armlu)
    id1=EntityID(ragdolls()\armlu)
    knupf6=PointJoint(#PB_Any,id,0,sp,0,id1,0,sp,0)
    SetJointAttribute(knupf6,#PB_PointJoint_Damping,damp)
    SetJointAttribute(knupf6,#PB_PointJoint_Tau,tau)
    
    jx=EntityX(ragdolls()\armru)
    jy=EntityY(ragdolls()\armru)
    jz=EntityZ(ragdolls()\armru)
    id=EntityID(ragdolls()\armru)
    SelectElement(ragdolls(),7)
    jx1=EntityX(ragdolls()\armlu)
    jy1=EntityY(ragdolls()\armlu)
    jz1=EntityZ(ragdolls()\armlu)
    id1=EntityID(ragdolls()\armlu)
    knupf7=PointJoint(#PB_Any,id,0,sp,0,id1,0,sp,0)
    SetJointAttribute(knupf7,#PB_PointJoint_Damping,damp)
    SetJointAttribute(knupf7,#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
    If knupf4
      FreeJoint(knupf4)
      knupf4=0
    EndIf
    If knupf5
      FreeJoint(knupf5)
      knupf5=0
    EndIf
    If knupf6
      FreeJoint(knupf6)
      knupf6=0
    EndIf
    If knupf7
      FreeJoint(knupf7)
      knupf7=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 KeyboardReleased(#PB_Key_R)  Or KeyboardReleased(#PB_Key_E)
      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_P) 
      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_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()
      ForEach ragdolls()
        SetEntityMaterial(ragdolls()\eyel, MaterialID(MatEye))
        SetEntityMaterial(ragdolls()\eyer, MaterialID(MatEye))
      Next
      
    EndIf
    If KeyboardReleased(#PB_Key_L)
      killjoints()
      hands=0
      ForEach ragdolls()
        SetEntityMaterial(ragdolls()\eyel, MaterialID(MatDeadEye))
        SetEntityMaterial(ragdolls()\eyer, MaterialID(MatDeadEye))
      Next
    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)
        ;ApplyEntityForce(ragdolls()\HEAD,(Random(10)+5)*-1,0,(Random(10)+5)*-1) ;nearly ParachuteEffect
      Next
    EndIf
    
    If KeyboardPushed(#PB_Key_J)
      ForEach ragdolls()
        ApplyEntityImpulse(ragdolls()\Head,0,10,0)
      Next
    EndIf
    If KeyboardPushed(#PB_Key_K)
      SelectElement(ragdolls(),1)
      ApplyEntityImpulse(ragdolls()\Head,0,Random(10)+9,0)
      
    EndIf
    If KeyboardPushed(#PB_Key_I)
      I_f+0.1
      SelectElement(ragdolls(),0)
      ApplyEntityImpulse(ragdolls()\armlu,0,10+I_f,0)
      
    EndIf
    If KeyboardReleased(#PB_Key_I)
      i_f=0
    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
    ;Earthquake
    If KeyboardReleased(#PB_Key_Q)
      If earthquake
        ;Debug "Earthquake off"
        
        earthquake=0
      Else
        ; Debug "Earthquake on"
        earthquake=1
      EndIf
      
    EndIf
    
    ;KeyboardPushed Q
    ; plate rumbles (mimimal impulses in different dierctions)
    ;
    
    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
  If earthquake
    ;Debug EntityY(platte)
    rx.f=(Random(200)-99)/1000
    ry.f=(Random(200)-99)/1000
    rz.f=(Random(200)-99)/1000
    MoveEntity(platte, rx,ry+256,rz, #PB_Absolute)
    ApplyEntityForce(platte,0,0,50)
    
    ;Debug ApplyEntityImpulse(platte  ,0,0,0,0,100,0,#PB_World)
  Else
    ;MoveEntity(platte,0,256,0,#PB_Absolute)
  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()
      wcap=WorldCollisionAppliedImpulse()
      ;Debug GetY()
      
      impy=wcap;GetY()
      
      If impy>666
        killjoints()
        hands=0
      EndIf
      If impy>100
        dead=1
        ForEach ragdolls()
          SetEntityMaterial(ragdolls()\eyel, MaterialID(MatDeadEye))
          SetEntityMaterial(ragdolls()\eyer, MaterialID(MatDeadEye))
        Next
      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())
      If dead
        ForEach ragdolls()
          SetEntityMaterial(ragdolls()\eyel, MaterialID(MatEye))
          SetEntityMaterial(ragdolls()\eyer, MaterialID(MatEye))
          
        Next
        dead=0
      EndIf
      
    EndIf
  Next
  
  RenderWorld()
  FlipBuffers()
  
  While WindowEvent():Wend   
  
  ;steuerung
  MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
  MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
  
  KeyX = (KeyboardPushed(#PB_Key_Right)-KeyboardPushed(#PB_Key_Left))*#CameraSpeed
  Keyy = (KeyboardPushed(#PB_Key_Down)-KeyboardPushed(#PB_Key_Up))*#CameraSpeed
  
  RotateCamera(camera, MouseY, MouseX, 0, #PB_Relative)
  MoveCamera  (camera, KeyX, 0, KeyY)
  
  
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1

End
사십 둘 .
User avatar
idle
Always Here
Always Here
Posts: 5839
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: RagDolls Ogre and Physics

Post by idle »

Thanks for the update.
User avatar
Caronte3D
Addict
Addict
Posts: 1355
Joined: Fri Jan 22, 2016 5:33 pm
Location: Some Universe

Re: RagDolls Ogre and Physics

Post by Caronte3D »

Thanks, It's funny :D
You should show all the usable keys on screen :wink:
User avatar
bobobo
Enthusiast
Enthusiast
Posts: 206
Joined: Mon Jun 09, 2003 8:30 am

Re: RagDolls Ogre and Physics

Post by bobobo »

Update . Some repetitive jobs have been simplified, and keyboard shortcut info has been improved

Code: Select all

;
; ------------------------------------------------------------
;
;   PureBasic - RagDoll fuer Purebasic ab 6.20
;
;    (c) 2002 - Fantaisie Software , bobobo
; 
; das Programm sollte im Verzeichnis  \Examples\3D liegen
; weil ich das so will :)
; alles ohne Gewähr
; ------------------------------------------------------------
;

#CameraSpeed = 1



Define.f KeyX, KeyY, MouseX, MouseY ,rott, moveit, I_f
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:knupf.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

InitEngine3D()

InitSprite()
InitKeyboard()
InitMouse()

ExamineDesktops():dx=DesktopWidth(0)*0.8:dy=DesktopHeight(0)*0.8
OpenWindow(0, 0,0, DesktopUnscaledX(dx),DesktopUnscaledY(dy), "Camera - [Esc] quit",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, dx, dy, 0, 0, 0)

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()


;WorldShadows(#PB_Shadow_Additive,512)
SkyBox("desert07.jpg")
camera=CreateCamera(#PB_Any,0,0,100,100)
;CameraRenderMode(camera, #PB_Camera_Plot)
MoveCamera(camera,0, 260 ,15, #PB_Absolute)

texture1t=CreateTexture(#PB_Any,512,512)
font=LoadFont(#PB_Any,"",14,#PB_Font_HighQuality)
fontsmall=LoadFont(#PB_Any,"",6,#PB_Font_Bold)
StartDrawing(TextureOutput(texture1t))
DrawingFont(FontID(font))
Box(0, 0, 512, 512, RGBA(222,222,255, 200))
For l=0 To 128 
  Circle(Random(512),Random(512),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,"Q:Quakemode, Hello Newzealand")
ty+th
DrawText(0,ty,"(*) while pressed,  (**) when release key")
;Debug ty
DrawingFont(FontID(fontsmall))
ttx=512-140
tt=20
tth=TextHeight("X")
FrontColor(#Black)
DrawText(ttx,tt,"used shortcuts (press or release)"):tt+tth
DrawText(ttx,tt,"#PB_Key_Add        "):tt+tth
DrawText(ttx,tt,"#PB_Key_B        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Down        "):tt+tth
DrawText(ttx,tt,"#PB_Key_E        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Escape        "):tt+tth
DrawText(ttx,tt,"#PB_Key_F        "):tt+tth
DrawText(ttx,tt,"#PB_Key_G        "):tt+tth
DrawText(ttx,tt,"#PB_Key_H        "):tt+tth
DrawText(ttx,tt,"#PB_Key_I        "):tt+tth
DrawText(ttx,tt,"#PB_Key_J        "):tt+tth
DrawText(ttx,tt,"#PB_Key_K        "):tt+tth
DrawText(ttx,tt,"#PB_Key_L        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Left        "):tt+tth
DrawText(ttx,tt,"#PB_Key_M        "):tt+tth
DrawText(ttx,tt,"#PB_Key_N        "):tt+tth
DrawText(ttx,tt,"#PB_Key_O        "):tt+tth
DrawText(ttx,tt,"#PB_Key_P        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Pad1        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Pad2        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Pad3        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Pad4        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Pad6        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Pad8        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Q        "):tt+tth
DrawText(ttx,tt,"#PB_Key_R        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Right        "):tt+tth
DrawText(ttx,tt,"#PB_Key_S        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Subtract        "):tt+tth
DrawText(ttx,tt,"#PB_Key_T        "):tt+tth
DrawText(ttx,tt,"#PB_Key_U        "):tt+tth
DrawText(ttx,tt,"#PB_Key_Up        "):tt+tth
DrawText(ttx,tt,"#PB_Key_V         "):tt+tth

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,15,"and get a more complete list",RGBA(255,255,0,255),RGBA(0,0,0,0))
DrawText(0,30,"of used shortcuts",RGBA(255,255,0,255),RGBA(0,0,0,0))

DrawText(0,50,"Hold N for a time and press B",RGBA(255,255,0,255),RGBA(0,0,0,0))
DrawText(0,70,"and have even more fun",RGBA(255,255,0,255),RGBA(0,0,0,0))
LineXY(0,0,52,5,RGBA(255,255,0,255))
LineXY(45,2,52,5,RGBA(255,255,0,255))
LineXY(45,6,52,5,RGBA(255,255,0,255))
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))

texturedead = CreateTexture(#PB_Any,256,256)
StartDrawing(TextureOutput(texturedead))
Box(0,0,256,256,#White)
For de=0 To 10
  Line(0,128+de,256,1,#Black)
  Line(0,128-de,256,1,#Black)
Next

For de=0 To 10
  Line(de,0,1,256,#Black)
  Line(256-de,0,1,256,#Black)
  
Next

StopDrawing()
MatDeadEye = CreateMaterial(#PB_Any,TextureID(texturedead))

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); ,12,12)
NoseMesh  = CreateSphere(#PB_Any , 0.25, 3, 4)
EyeMeshl  = CreateSphere(#PB_Any , 0.10);,8,8)
EyeMeshr  = CreateSphere(#PB_Any , 0.10);,8,8)
MouthMesh = CreateSphere(#PB_Any , 0.25,15,15)
EarMeshl =  CreateSphere(#PB_Any , 0.25);,8,8)
EarMeshr =  CreateSphere(#PB_Any , 0.25);,8,8)
FootMeshl = CreateSphere(#PB_Any , 0.25,6,6)
FootMeshr = CreateSphere(#PB_Any , 0.25,6,6)

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.02,-0.38, 0.15, 0.50, 0.25, 1.00, 10.00, 20.00,  0.00)
TransformMesh(FootMeshr, 0.02,-0.38, 0.15, 0.50, 0.25, 1.00, 10.00,-20.00,  0.00)
bzz=24 ;amount ragdolls
For r=1 To bzz 
  
  AddElement(ragdolls())
  
  ragdolls()\posx=r*2-bzz
  ragdolls()\posy=259 ;height
  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)
  
  ;rendermode=#PB_Entity_CastShadow
  ;rendermode=#PB_Entity_CastShadow|#PB_Entity_DisplaySkeleton
  
  ;bodyPhysics
  CreateEntityBody(ragdolls()\Body,#PB_Entity_BoxBody  ,10, 0,1)
  EntityRenderMode(ragdolls()\Body, #PB_Entity_CastShadow)
  
  EntityRenderMode(ragdolls()\Head, #PB_Entity_CastShadow)
  CreateEntityBody(ragdolls()\Head, #PB_Entity_ConvexHullBody, 5, 0.25, 1)
  
  EntityRenderMode(ragdolls()\arml, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\arml, #PB_Entity_CylinderBody,  1, 0 ,1)
  EntityRenderMode(ragdolls()\armlu, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\armlu, #PB_Entity_CylinderBody, 1, 0, 1)
  
  EntityRenderMode(ragdolls()\armr, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\armr, #PB_Entity_CylinderBody,  1, 0, 1)
  EntityRenderMode(ragdolls()\armru, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\armru, #PB_Entity_CylinderBody, 1, 0,1)
  
  EntityRenderMode(ragdolls()\legl, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\legl, #PB_Entity_CylinderBody, 1, 0,1)
  EntityRenderMode(ragdolls()\leglu, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\leglu, #PB_Entity_CylinderBody,1, 0,1)
  
  EntityRenderMode(ragdolls()\legr, #PB_Entity_CastShadow) 
  CreateEntityBody(ragdolls()\legr, #PB_Entity_CylinderBody, 1, 0,1)
  EntityRenderMode(ragdolls()\legru, #PB_Entity_CastShadow) 
  CreateEntityBody(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)
;boxes
;For r=1 To 600
;  b=CreateEntity(#PB_Any,MeshID(plate),MaterialID(texture1),Random(20)-10,270,Random(20)-10);,Random(1),Random(10)+274,Random(1))
;  ScaleEntity(b,0.1,3,0.1)
;  CreateEntityBody(b,#PB_Entity_BoxBody   ,05,0.01,100)
;Next r

platte=CreateEntity(#PB_Any,MeshID(plate),MaterialID(texture1),0,0,0)

;ScaleEntity(platte,70,0.01,70)
ScaleEntity(platte,70,0.5,70)
MoveEntity(platte,0,256,0) ; 256 plate height 
EntityRenderMode(platte, #PB_Entity_CastShadow)
CreateEntityBody(platte,#PB_Entity_StaticBody,1,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 
    
    size=ListSize(ragdolls())
    sp=-0.5
    tau.f=0
    damp.f=0.5
    For rrr=0 To size-2
    SelectElement(ragdolls(),rrr)
    jx=EntityX(ragdolls()\armru)
    
    jy=EntityY(ragdolls()\armru)
    jz=EntityZ(ragdolls()\armru)
    id=EntityID(ragdolls()\armru)
    SelectElement(ragdolls(),rrr+1)
    jx1=EntityX(ragdolls()\armlu)
    jy1=EntityY(ragdolls()\armlu)
    jz1=EntityZ(ragdolls()\armlu)
    id1=EntityID(ragdolls()\armlu)
    SelectElement(ragdolls(),rrr)
    ragdolls()\knupf =PointJoint(#PB_Any,id,0,sp,0,id1,0,sp,0)
    SetJointAttribute(ragdolls()\knupf,#PB_PointJoint_Damping,damp)
    SetJointAttribute(ragdolls()\knupf,#PB_PointJoint_Tau,tau)
    Next rrr
    
  EndIf
  
  If hands=3
    ;Debug hands  
    hands=0
    
    For rrr=0 To ListSize(ragdolls())-2
      SelectElement(ragdolls(),rrr)
      FreeJoint(ragdolls()\knupf)
    Next rrr
  
      
  
    
  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 KeyboardReleased(#PB_Key_R)  Or KeyboardReleased(#PB_Key_E)
      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_P) 
      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_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()
      ForEach ragdolls()
        SetEntityMaterial(ragdolls()\eyel, MaterialID(MatEye))
        SetEntityMaterial(ragdolls()\eyer, MaterialID(MatEye))
      Next
      
    EndIf
    If KeyboardReleased(#PB_Key_L)
      killjoints()
      hands=0
      ForEach ragdolls()
        SetEntityMaterial(ragdolls()\eyel, MaterialID(MatDeadEye))
        SetEntityMaterial(ragdolls()\eyer, MaterialID(MatDeadEye))
      Next
    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)
      bzz=1
      ForEach ragdolls()
        MoveEntity(ragdolls()\Head,ragdolls()\posx,ragdolls()\posy+bzz,ragdolls()\posz,#PB_Absolute)
        MoveEntity(ragdolls()\Body,ragdolls()\posx,ragdolls()\posy-1+bzz,ragdolls()\posz,#PB_Absolute)
        RotateEntity(ragdolls()\Body,0,0,0,#PB_Absolute)
        MoveEntity(ragdolls()\legr,ragdolls()\posx+0.3,ragdolls()\posy-2+bzz,ragdolls()\posz,#PB_Absolute)
        MoveEntity(ragdolls()\legl,ragdolls()\posx-0.3,ragdolls()\posy-2+bzz,ragdolls()\posz,#PB_Absolute)
        MoveEntity(ragdolls()\legru,ragdolls()\posx+0.3,ragdolls()\posy-2.9+bzz,ragdolls()\posz,#PB_Absolute)
        MoveEntity(ragdolls()\leglu,ragdolls()\posx-0.3,ragdolls()\posy-2.9+bzz,ragdolls()\posz,#PB_Absolute)
        MoveEntity(ragdolls()\armr,ragdolls()\posx+0.6,ragdolls()\posy-1+bzz,ragdolls()\posz,#PB_Absolute)
        MoveEntity(ragdolls()\arml,ragdolls()\posx-0.6,ragdolls()\posy-1+bzz,ragdolls()\posz,#PB_Absolute)
        MoveEntity(ragdolls()\armru,ragdolls()\posx+0.6,ragdolls()\posy-2+bzz,ragdolls()\posz,#PB_Absolute)
        MoveEntity(ragdolls()\armlu,ragdolls()\posx-0.6,ragdolls()\posy-2+bzz,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)
        ;ApplyEntityForce(ragdolls()\HEAD,(Random(10)+5)*-1,0,(Random(10)+5)*-1) ;nearly ParachuteEffect
      Next
    EndIf
    
    If KeyboardPushed(#PB_Key_J)
      ForEach ragdolls()
        ApplyEntityImpulse(ragdolls()\Head,0,10,0)
      Next
    EndIf
    If KeyboardPushed(#PB_Key_K)
      SelectElement(ragdolls(),1)
      ApplyEntityImpulse(ragdolls()\Head,0,Random(10)+9,0)
      
    EndIf
    If KeyboardPushed(#PB_Key_I)
      I_f+0.1
      SelectElement(ragdolls(),0)
      ApplyEntityImpulse(ragdolls()\armlu,0,10+I_f,0)
      
    EndIf
    If KeyboardReleased(#PB_Key_I)
      i_f=0
    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
    ;Earthquake
    If KeyboardReleased(#PB_Key_Q)
      If earthquake
        ;Debug "Earthquake off"
        
        earthquake=0
      Else
        ; Debug "Earthquake on"
        earthquake=1
      EndIf
      
    EndIf
    
    ;KeyboardPushed Q
    ; plate rumbles (mimimal impulses in different dierctions)
    ;
    
    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,1,-6,0)
        ApplyEntityImpulse(ragdolls()\legr , 0, Random(4),0,1,-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
  If earthquake
    ;Debug EntityY(platte)
    rx.f=(Random(200)-99)/1000
    ry.f=(Random(200)-99)/1000
    rz.f=(Random(200)-99)/1000
    MoveEntity(platte, rx,ry+256,rz, #PB_Absolute)
    ApplyEntityForce(platte,0,0,50)
    
    ;Debug ApplyEntityImpulse(platte  ,0,0,0,0,100,0,#PB_World)
  Else
    ;MoveEntity(platte,0,256,0,#PB_Absolute)
  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()
      wcap=WorldCollisionAppliedImpulse()
      ;Debug GetY()
      
      impy=wcap;GetY()
      
      If impy>666
        killjoints()
        hands=0
      EndIf
      If impy>100
        dead=1
        ForEach ragdolls()
          SetEntityMaterial(ragdolls()\eyel, MaterialID(MatDeadEye))
          SetEntityMaterial(ragdolls()\eyer, MaterialID(MatDeadEye))
        Next
      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())
      If dead
        ForEach ragdolls()
          SetEntityMaterial(ragdolls()\eyel, MaterialID(MatEye))
          SetEntityMaterial(ragdolls()\eyer, MaterialID(MatEye))
          
        Next
        dead=0
      EndIf
      
    EndIf
  Next
  
  RenderWorld()
  FlipBuffers()
  
  While WindowEvent():Wend   
  
  ;steuerung
  MouseX = -MouseDeltaX() * #CameraSpeed * 0.05
  MouseY = -MouseDeltaY() * #CameraSpeed * 0.05
  
  KeyX = (KeyboardPushed(#PB_Key_Right)-KeyboardPushed(#PB_Key_Left))*#CameraSpeed
  Keyy = (KeyboardPushed(#PB_Key_Down)-KeyboardPushed(#PB_Key_Up))*#CameraSpeed
  
  RotateCamera(camera, MouseY, MouseX, 0, #PB_Relative)
  MoveCamera  (camera, KeyX, 0, KeyY)
  
  
  RenderWorld()
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape) Or Quit = 1

End
사십 둘 .
Post Reply