Import irrlicht.b3d
Import "PhysX_func.bmx"
'Strict
Global irr:ib3d_engine = _g_ib3d_engine
Local width=640,height=480,depth=16,mode=2,shadows=True
irr.Graphics3D(width,height,depth,mode,shadows)
Global vertnun, facnum
Global plane:PLANE = irr.createPlane(200,200,1,1,0)
ib3d_EntityColor(plane,20,40,200)
Local cam:CAMERA = irr.CreateCamera()
cam.Position(0,10,-60)
Local light:LIGHT = irr.CreateLight(2)
light.Position(-15,30,-150)
ib3d_LightColor(light,200,200,200)
ib3d_AmbientLight(32,32,32)
ib3d_LightRange(light,1000)
ib3d_LightCastShadows(light,1)
' used by camera code
Local mxs#=0
Local mys#=0
Local move#=0.5
MouseXSpeed() ' flush
MouseYSpeed() ' flush
' used by fps code
Local old_ms=MilliSecs()
Local renders
Local fps
'physic
dir$ = CurrentDir ()
dir = Replace$( dir$,"/","\" )
pxRegWriteDriverPath (dir.ToCString())
'Create World
PxCreateWorld(0, "key")
pxSetGravity(0, -1.5, 0)
pxRegWriteDriverPath ("C:\Program Files\AGEIA Technologies".ToCString())
planeBody = PxBodyCreateCube(200,1,200, 0)
pxBodySetPosition(planeBody ,0,0,0)
Rem
'Create TriMesh
Local ent:MESH = irr.LoadMesh("media/TriMesh.b3d")
ent.Position(0,0,0)
BodyCreateTriMesh(ent)
End Rem
'Create Hull
Local teapot:MESH = irr.LoadMesh("media/teapot.b3d")
teapot_body = BodyCreateHull%(teapot)
pxBodySetPosition(teapot_body, 0, 60,0)
'Create Sphere
Local sphere:PRIMITIVE = irr.CreateSphere()
sphere.Position(10,10,0)
ib3d_ScaleEntity(sphere,4,4,4)
'create Cube
Local cube:PRIMITIVE = irr.CreateCube()
ib3d_EntityColor(cube,0,120,0)
cube.Position(-15,10,0)
Global sphereBody = PxBodyCreateSphere(4, 10)
pxBodySetPosition(sphereBody,10, 20,0)
Global cubeBody = PxBodyCreateCube(4,4,4, 10)
pxBodySetPosition(cubeBody,5,30,0)
planeBody = PxBodyCreateCube(25,1,25, 0)
pxBodySetPosition(planeBody ,0,-1,0)
While Not irr.KeyDown(KEY_ESCAPE)
If KeyHit(KEY_ENTER) Then DebugStop
'move camera forwards/backwards/Left/Right with cursor keys
If irr.KeyDown(KEY_UP)=True Then cam.Move(0,0,move#) ' move camera forward
If irr.KeyDown(KEY_DOWN)=True Then cam.Move(0,0,-move#) ' move camera back
If irr.KeyDown(KEY_LEFT)=True Then cam.Move(-move#,0,0) ' move camera left
If irr.KeyDown(KEY_RIGHT)=True Then cam.Move(move#,0,0) ' move camera right
''
teapot.Position(pxBodyGetPositionX(teapot_body),pxBodyGetPositionY(teapot_body),pxBodyGetPositionZ(teapot_body))
teapot.Rotate(pxBodyGetRotationPitch(teapot_body),pxBodyGetRotationYaw(teapot_body),pxBodyGetRotationRoll(teapot_body))
sphere.Position(pxBodyGetPositionX(sphereBody),pxBodyGetPositionY(sphereBody),pxBodyGetPositionZ(sphereBody))
sphere.Rotate(pxBodyGetRotationPitch(sphereBody),pxBodyGetRotationYaw(sphereBody),pxBodyGetRotationRoll(sphereBody))
cube.Position(pxBodyGetPositionX(cubeBody),pxBodyGetPositionY(cubeBody),pxBodyGetPositionZ(cubeBody))
cube.Rotate(pxBodyGetRotationPitch(cubeBody),pxBodyGetRotationYaw(cubeBody),pxBodyGetRotationRoll(cubeBody))
' surf:SURFACE = ent.GetSurface(1)
pxRenderPhysic(30, 0)
irr.RenderWorld()
renders=renders+1
Flip
Wend
irr.EndGraphics()
End
Function BodyCreateHull%(mesh:MESH)
Local nsurf% = mesh.CountSurfaces()
Local nvert% = 0
For ns = 0 Until nsurf
Local surf:SURFACE = mesh.GetSurface(ns)
nvert = nvert + ib3d_CountVertices(surf)
Next
vbank:TBank = CreateBank(nvert*4*3)
nv = 0
For ns = 0 Until nsurf
surf:SURFACE = mesh.GetSurface(ns)
nvv = ib3d_CountVertices(surf)
For nvc = 0 To nvv - 1
PokeFloat vbank,nv*12+0,ib3d_VertexX(surf,nvc)
PokeFloat vbank,nv*12+4,ib3d_VertexY(surf,nvc)
PokeFloat vbank,nv*12+8,ib3d_VertexZ(surf,nvc)
nv = nv+1
Next
Next
Local vbp:Byte Ptr
vbp = vbank.Buf()
Local bbb%= pxBodyCreateHull(vbp, nvert, 10)
Return bbb
End Function