Seite 1 von 1

OGRE soft body

Verfasst: 30.10.2013 13:43
von CSHW89
Hi Leute.
ich wollte mal fragen, ob es mit ogre möglich ist Soft Bodys zu erstellen. Ich würde nämlich gerne eine Kugel erstellen, die so soft ist, dass sie beim Rollen unten eingedrückt wird. Mein zweiter Gedanke war, ein statisches Objekt zu erstellen, das die eingedrückte Kuhle immer besitzt, und die Texture um das Objekt rotieren lassen. Allerdings wären dann andere Situationen, wie Kugel fällt runter, viel schwieriger zu gestalten.
Was würdet ihr sagen, wäre einfacher bzw überhaupt machbar?

lg Kevin

Re: OGRE soft body

Verfasst: 31.10.2013 10:03
von Makke
Hi,

ich verstehe glaube ich nicht genau was du meinst. Verformen von Körpern ? Also so:

Code: Alles auswählen

EnableExplicit

#BlobbySize   = 4

Structure Vec3
  x.f
  y.f
  z.f
EndStructure

Define.b doLoop = #True
Define.i camera, light, texture, material, mesh, floor, blobby

Declare AnimateBlobby()

InitEngine3D()
InitSprite()
InitKeyboard()
InitMouse()

If OpenWindow(0, 0, 0, 1024, 768, "Test", #PB_Window_SystemMenu|#PB_Window_ScreenCentered)
  OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0), WindowHeight(0), 0, 0, 0, #PB_Screen_WaitSynchronization)
  Add3DArchive(#PB_Compiler_Home+"Examples/3D/Data/Textures", #PB_3DArchive_FileSystem)
EndIf

SkyDome("clouds.jpg", 10)

WorldShadows(#PB_Shadow_Additive, 100, RGB(32, 32, 32), 2048)
EnableWorldPhysics(#False)

texture  = LoadTexture(#PB_Any, "grass.jpg")
material = CreateMaterial(#PB_Any, TextureID(texture)) : MaterialFilteringMode(material, #PB_Material_Anisotropic, 8)
mesh     = CreatePlane(#PB_Any, 50, 50, 1, 1, 10, 10)
floor    = CreateEntity(#PB_Any, MeshID(mesh), MaterialID(material))
FreeMesh(mesh)
FreeMaterial(material)
FreeTexture(texture)

texture  = CreateTexture(#PB_Any, 32, 32)
StartDrawing(TextureOutput(texture))
DrawingMode(#PB_2DDrawing_AlphaBlend)
Box(0, 0, 32, 32, RGBA(0,255,0,128))
StopDrawing()
material = CreateMaterial(#PB_Any, TextureID(texture))
MaterialBlendingMode(material, #PB_Material_AlphaBlend)
MaterialShadingMode(material, #PB_Material_Phong)
MaterialFilteringMode(material, #PB_Material_Anisotropic, 8)
mesh     = CreateSphere(#PB_Any, #BlobbySize/2)
blobby   = CreateEntity(#PB_Any, MeshID(mesh), MaterialID(material), 0, #BlobbySize, 0)
FreeMesh(mesh)
FreeMaterial(material)
FreeTexture(texture)

light = CreateLight(#PB_Any, RGB(255,250,240), -50, 50, 0, #PB_Light_Directional)
LightLookAt(light, 0, 0, 0)

camera = CreateCamera(#PB_Any, 0, 0, 100, 100)
CameraRange(camera, 0.1, 100)
MoveCamera(camera, 0, 10, 25, #PB_Absolute)
CameraLookAt(camera, 0, 0, 0)

AmbientColor(0)

Repeat
  
  While WindowEvent() : Wend : SetWindowTitle(0, "Test - " + Str(Engine3DFrameRate(#PB_Engine3D_Current)) + " fps")
  
  If ExamineKeyboard()
    If KeyboardReleased(#PB_Key_Escape)
      doLoop = #False
    EndIf
  EndIf
  
  AnimateBlobby()
  
  RenderWorld()
  FlipBuffers()
  
Until doLoop = #False

End

Macro GetPosition(Object, Position)
  If IsEntity(Object)
    Position\x = EntityX(Object)
    Position\y = EntityY(Object)
    Position\z = EntityZ(Object)
  ElseIf IsNode(Object)
    Position\x = NodeX(Object)
    Position\y = NodeY(Object)
    Position\z = NodeZ(Object)
  EndIf
EndMacro
  
Procedure.f PointSphereCollision(*p.Vec3, *s.Vec3, radius.f)
  If (Pow(*p\x - *s\x, 2) + Pow(*p\y - *s\y, 2) + Pow(*p\z - *s\z, 2)) < Pow(radius, 2)
    ProcedureReturn #True
  Else
    ProcedureReturn #False
  EndIf
EndProcedure

Procedure AnimateBlobby()
  
  Shared         blobby, floor
  Static.b       init
  Static.l       direction, scaleDir
  Static.f       scaleHeight, scaleWidth, scaleStep, maxHeight, curForce
  Protected.Vec3 blobbyPos, floorPos
  
  If init = #False
    direction   = -1
    maxHeight   = #BlobbySize*2.5
    curForce    = 10.0
    scaleHeight = 1.0
    scaleWidth  = 1.0
    scaleStep   = 0.05
    scaleDir    = -1
    init = #True
  EndIf
  
  GetPosition(blobby, blobbyPos)
  GetPosition(blobby, floorPos)
  floorPos\y = EntityY(floor)
  
  If direction = -1
    curForce - 0.4
    If PointSphereCollision(@floorPos, @blobbyPos, #BlobbySize/2)
      direction = 0
    EndIf
  ElseIf direction = 0
    If scaleDir = -1
      scaleHeight - scaleStep
      scaleWidth  + scaleStep/2
      MoveEntity(blobby, 0, -scaleStep, 0, #PB_Relative)
      ScaleEntity(blobby, scaleWidth, scaleHeight, scaleWidth, #PB_Absolute)
      If scaleHeight <= 0.5
        scaleDir = 1
      EndIf
    ElseIf scaleDir = 1
      scaleHeight + scaleStep
      scaleWidth  - scaleStep/2
      MoveEntity(blobby, 0, scaleStep, 0, #PB_Relative)
      ScaleEntity(blobby, scaleWidth, scaleHeight, scaleWidth, #PB_Absolute)
      If scaleHeight >= 1.0
        scaleDir  = -1
        direction = 1
        curForce  = 10
      EndIf
    EndIf
  ElseIf direction = 1
    curForce + 0.25
    If blobbyPos\y >= maxHeight Or curForce > 35.0
      direction = -1
    EndIf
  EndIf
  
  MoveEntity(blobby, 0, direction / curForce, 0, #PB_Relative)
  
EndProcedure
Oder wie soll ich Deine Kugel verstehen ?

Re: OGRE soft body

Verfasst: 31.10.2013 12:39
von CSHW89
Danke erstmal für die Demo! Das geht schon mal in die richtige Richtung. Ich habs aber vermutlich nicht so gut erklärt, wie ichs gern machen wüde, deshalb hier mal ein Bild:
http://cshw89.mevedia.de/Sphere.bmp

Die Kugel (oder besser der Ball) soll sich nicht so sehr wie ein Gummiball, als vielmehr wie ein Schwamm verhalten. Er wird halt am Boden eingedrückt, und am besten dadurch an den Seiten etwas rausgedrückt (aber nicht viel). Das Eindrücken sollte sich aber auch dem Boden anpassen, falls der uneben oder schräg ist. Ich dachte nur, falls ogre soft bodys unterstützt, müsste ich das nicht selbst implementieren.

Aber falls keiner eine andere Idee hat, müsste ich das wohl wirklich mit Echtzeit-Transformationen machen.

lg Kevin

Re: OGRE soft body

Verfasst: 31.10.2013 23:03
von Makke
Hi.
Also weder Ogre noch die in PB implementierte Physikengine unterstützt sowas (soweit ich weiss). Danke für das Bild, ich konnte mir das physikalisch nicht vorstellen.

Solltest Du da mal was haben, wäre toll wenn Du es vorstellst.