Hi.
Is the command "Phy Make Rigid Body Dynamic Mesh" going to work in the near future? Is there way to accomplish something similar to this?
Anyway, to the point.
I'm currently working on a physics game where you draw a shape and that shape becomes a dynamic body which will interact with the level.
The goal is to build stuff in order to get a ball inside a rotating swirl. The game will be awesome once finished, but right now that is a very distant reality.
Run this code
REMSTART
**********************************************************
Title: {no name}
Version: v 1.0
Author: Lukas W
About: Draw stuff to get the red ball into the swirl
A Tablet is recommended for accurate drawing.
A Thanks To:
Bergice
Acelepage
BillR
**********************************************************
REMEND
` Setup Application
Sync On
Sync Rate 60
ScrW = 640
ScrH = 480
Start:
Set Display Mode ScrW, ScrH, 32
Color Backdrop 0
Autocam off
Create Bitmap 1, ScrW, ScrH
Set Current Bitmap 0
Position Camera 0, 0, -50
Phy Start
Phy Enable Debug
` **********************************************************
` Initialize 3D Scene, and create source object
Make Object Plain 1, .2, .2
Make Mesh From Object 1, 1
Delete Object 1
Type tObjectData
xp As Float
yp As Float
zp As Float
an As Float
le As Float
EndType
Dim ObjectData(0) As tObjectData
` TEMP - floor
Make Object Box 99, 1000, 10, 1000
Position OBject 99, 0, -50, 0
Phy Make Rigid Body Static Box 99
` **********************************************************
` Setup Drawing History Array
Type tDrawing
ox As Integer
oy As integer
nx As Integer
ny As Integer
objId As Integer
EndType
Dim Drawing(0) As tDrawing
` **********************************************************
` Begin Loop
Do
` Display HUD
Set Cursor 0, 0
Print "FPS: ", Screen FPS()
Print "POL: ",Statistic(1)
Print
Print "Time spent: ", timespent, " ms"
Print
Print "1-640x480 2-800x600 3-1024x768"
If "1" = InKey$() Then ScrW = 640 : ScrH = 480 : GoTo Reset
If "2" = InKey$() Then ScrW = 800 : ScrH = 600 : GoTo Reset
If "3" = InKey$() Then ScrW = 1024 : ScrH = 768 : GoTo Reset
` **********************************************************
` Draw using mouse
If MouseClick() =1 And _draw =0 Then _draw =1 : Set Current Bitmap 1
If MouseClick() =0 And _draw =1 Then _draw =2
If _draw =0 And _hasDrawn =1 Then Empty Array Drawing(0) : Set Current Bitmap 0 : _hasDrawn =0
mx = MouseX() : my = MouseY()
If _draw =1
If mx<>oldmx Or my<>oldmy
Array Insert At Bottom Drawing(0)
pos = Array Count(Drawing(0))
Drawing(pos).ox = oldmx
Drawing(pos).oy = oldmy
Drawing(pos).nx = mx
Drawing(pos).ny = my
EndIf
For x= 1 To Array Count(Drawing(0))
Ink RGB( 255, 255, 255 ), 0
Line Drawing(x).ox, Drawing(x).oy, Drawing(x).nx, Drawing(x).ny
Next x
Copy Bitmap 1, 0
EndIf
oldmx=mx : oldmy=my
` **********************************************************
` Convert Drawing into 3D Object
If _draw =2
timerStart = Timer()
` create 3d object from vector drawing
objectStart = FreeObj()
For x= 1 To Array Count(Drawing(0))
Pick Screen Drawing(x).ox, Drawing(x).oy, 100
xp1# = Get Pick Vector X() : yp1# = Get Pick Vector Y() : zp1# = Get Pick Vector Z()
Pick Screen Drawing(x).nx, Drawing(x).ny, 100
xp2# = Get Pick Vector X() : yp2# = Get Pick Vector Y() : zp2# = Get Pick Vector Z()
length# = 5 + Sqrt( (xp1#-xp2#)^2 + (yp1#-yp2#)^2 )
middlex# = Sqrt( (xp1#-xp2#)^2 ) /2
middley# = Sqrt( (yp1#-yp2#)^2 ) /2
xp# = Camera Position X() + (xp1#+middlex#)
yp# = Camera Position Y() + (yp1#-middley#)
zp# = Camera Position Z() + zp1#
angle# = Atanfull( Drawing(x).ox-Drawing(x).nx, Drawing(x).oy-Drawing(x).ny ) +90
Obj = FreeObj()
Make Object Box Obj, length#, 5, 10
Position Object Obj, xp#, yp#, zp#
Rotate Object Obj, 0, 180, angle# : Fix Object Pivot Obj
Array Insert At Bottom ObjectData(0)
pos = Array Count(ObjectData(0))
ObjectData(pos).xp = xp#
ObjectData(pos).yp = yp#
ObjectData(pos).zp = zp#
ObjectData(pos).an = angle#
ObjectData(pos).le = length#
Next x
objectEnd = (FreeObj() -1)
` convert objects to a mesh
meshStart = FreeMesh()
For x = (objectStart+1) To objectEnd
Mesh = FreeMesh()
Make Mesh From Object Mesh, x
Delete Object x
Next x
meshEnd = (FreeMesh() -1)
` add limbs
limbID = 0
For x = meshStart To meshEnd
Inc limbID, 1
Add Limb objectStart, limbID, x
Link Limb objectStart, limbID-1, limbID
Delete Mesh x
Next x
Perform Checklist for Object Limbs objectStart
totalLimbs = Checklist Quantity()
` reposition limbs
limbID = 1
ox# = ObjectData(1).xp : oy# = ObjectData(1).yp : oz# = ObjectData(1).zp
For x = 2 To Array Count(ObjectData(0))
x# = ObjectData(x).xp : y# = ObjectData(x).yp : z# = ObjectData(x).zp
nx# = ((ObjectData(x-1).xp- x#) *-1)
ny# = ((ObjectData(x-1).yp- y#) *-1)
nz# = 0.0
Inc limbID, 1
If limbID < totalLimbs : Offset Limb objectStart, limbID, nx#, ny#, nz#, 0 : EndIf
Next x
` convert to dynamic mesh
Phy Make Rigid Body Dynamic Box objectStart
`Phy Make Rigid Body Dynamic Mesh objectStart
` done
_draw =0
_hasDrawn =1
Empty Array ObjectData(0)
timerFinish = Timer()
timespent = (timerFinish - timerStart)
EndIf
` **********************************************************
` Update Application
Phy Update
Sync
Loop
Function FreeObj()
Repeat : Inc returnVal, 1 : Until Object Exist( returnVal ) =0
EndFunction returnVal
Function FreeMesh()
Repeat : Inc returnVal, 1 : Until Mesh Exist( returnVal ) =0
EndFunction returnVal
Reset:
For x = 1 to 9999
If Object Exist(1)
Phy Delete Rigid Body x
Delete Object x
EndIf
Next
Delete Bitmap 1
GoTo Start
for a brief of what I have done. You need DarkPhysics of course.
You will see that it creates boxes from your drawing. Never mind how the shape turns out, I have done things roughly in order to get the basics of the game going, and will improve this later on.
You will notice that the dynamic shapes are not colliding with eachother as well. Why not?
If someone would be kind and have a look at my code, experiment around and hopefully come up with a solution.
Also, I am concidering trying this out with Newton. But as I've bought DarkPhysics I feel I need to put it to use.
Too bad everything I've written with it turns out bad or not working at all.
L.
I allways afraided from a clowns. aww..