This is what i got so far. (no cilinders)
Declare sub TransformEntity(byval _Entity as tEntity ptr, byval as const single)
Declare sub TransformEntity(byval _Entity as tEntity ptr, byval pMatrix4x4 as single ptr)
declare function RigidBodyGetTransform alias "CollisionBodyGetTransform" (byval rb as RigidBody ptr) byref as const Transform
declare function RigidBodyGetTransform alias "CollisionBodyGetTransform" (byval rb as RigidBody ptr) byref as Transform
Code: Select all
/'*******************************************************************************
* ReactPhysics3D physics library, http://www.reactphysics3d.com *
* Copyright (c) 2010-2016 Daniel Chappuis *
*********************************************************************************
* *
* This software is provided 'as-is', without any express or implied warranty. *
* In no event will the authors be held liable for any damages arising from the *
* use of this software. *
* *
* Permission is granted to anyone to use this software for any purpose, *
* including commercial applications, and to alter it and redistribute it *
* freely, subject to the following restrictions: *
* *
* 1. The origin of this software must not be misrepresented; you must not claim *
* that you wrote the original software. If you use this software in a *
* product, an acknowledgment in the product documentation would be *
* appreciated but is not required. *
* *
* 2. Altered source versions must be plainly marked as such, and must not be *
* misrepresented as being the original software. *
* *
* 3. This notice may not be removed or altered from any source distribution. *
* *
*******************************************************************************'/
#include once "rp3d.bi" 'https://www.freebasic.net/forum/viewtopic.php?f=14&t=27180
namespace b3d
#include once "openb3d.bi" 'https://www.freebasic.net/forum/viewtopic.php?f=14&t=27233
end namespace
dim BOX_SIZE as const rp3d.vector3 => (2,2,2) '// Box dimensions in meters
dim FLOOR_SIZE as const rp3d.vector3 => (17.255,2,10) '// Floor dimensions in meters
const as single SPHERE_SIZE = 5
const screenx = 800
const screeny = 600
dim as integer rate
screenres screenx, screeny, 32, , &h10002
ScreenInfo ,,,,rate,,
windowtitle " frame rate: " & rate
b3d.Graphics3d screenx, screeny
var camera=b3d.createcamera()
b3d.moveEntity camera, 0,0,-30 'move camera back
b3d.CameraFogColor camera,0,.8,.9
'CameraCLSColor camera,0,.8,.9
b3d.CameraFogRange camera,500,1250
b3d.CameraRange camera,1,1250
b3d.CameraFogMode camera,1
b3d.AmbientLight .25,.35,.25
var sun=b3d.CreateLight( 1)
b3d.RotateEntity sun,-90,0,0
b3d.PositionEntity sun,0,100,-50
b3d.LightColor sun, .5,.5,.5
var sun2=b3d.CreateLight( 1)
b3d.RotateEntity sun2,-90,0,0
b3d.PositionEntity sun2,20,100,-70
b3d.LightColor sun2, .5,.5,.5
var DynamicsWorld = rp3d.CreateDynamicsWorld()
'create floor and add to world
var FloorBody = rp3d.DynamicsWorldCreateRigidBodyPosRotXYZ(DynamicsWorld, 0,-15,0, 0,0,0)
var FloorShape = rp3d.CreateBoxShape(FLOOR_SIZE)
var FloorProxy = rp3d.RigidBodyAddCollisionShapePosRotXYZ(FloorBody,FloorShape,0,0,0, 0,0,0, 10.0)
rp3d.RigidBodySetType(FloorBody, rp3d.BT_STATIC)
rp3d.RigidBodyEnableGravity(FloorBody, false)
var FloorObject = b3d.CreateCube()
b3d.scaleEntity FloorObject, FLOOR_SIZE.x, FLOOR_SIZE.y, FLOOR_SIZE.z
b3d.entityColor FloorObject, 0,.75,0
b3d.moveEntity FloorObject, 0,-15,0
' create sphere and add to world
var SphereBody = rp3d.DynamicsWorldCreateRigidBodyPosRotXYZ(DynamicsWorld, 0,20,0, 0,0,0)
var SphereShape = rp3d.CreateSphereShape(SPHERE_SIZE)
var SphereProxy = rp3d.RigidBodyAddCollisionShapePosRotXYZ(SphereBody,SphereShape,0,0,0, 0,0,0, 10.0)
var SphereObject = b3d.CreateSphere(32) ' 32 is quality
var SphereShadow = b3d.CreateShadow(SphereObject)
b3d.scaleEntity SphereObject, SPHERE_SIZE,SPHERE_SIZE,SPHERE_SIZE
b3d.meshcullradius FloorObject,1000
' create shpere
var BoxBody = rp3d.DynamicsWorldCreateRigidBodyPosRotXYZ(DynamicsWorld, 5,0,0, 0,-0.6,0.1)
var BoxShape = rp3d.CreateBoxShape(BOX_SIZE)
'var BoxShape = rp3d.CreateSphereShape(0.5)
var BoxProxy = rp3d.RigidBodyAddCollisionShapePosRotXYZ(BoxBody,BoxShape,0,0,0, 0,0,0, 10.0)
'rp3d.RigidBodySetType(BoxBody, rp3d.BT_STATIC)
'rp3d.RigidBodyEnableGravity(BoxBody, false)
'rp3d.RigidBodySetMass(BoxBody, 1000)
var BoxObject = b3d.CreateCube()
b3d.scaleEntity BoxObject, BOX_SIZE.x,BOX_SIZE.y,BOX_SIZE.z
b3d.entityColor BoxObject, 1,0,1
var BoxShadow = b3d.CreateShadow(BoxObject)
b3d.meshcullradius BoxObject,1000
'next
dim as single matrix(15)
dim as any ptr transformX = @matrix(0)
do
rp3d.DynamicsWorldUpdate(DynamicsWorld,1/30)
rp3d.TransformGetOpenGLMatrix(rp3d.RigidBodyGetTransform(SphereBody), transformX)
b3d.TransformEntity SphereObject, transformX
rp3d.TransformGetOpenGLMatrix(rp3d.RigidBodyGetTransform(BoxBody), transformX)
b3d.TransformEntity BoxObject, transformX
if rp3d.RigidBodyGetTransform(SphereBody).position.y < -15 then
rp3d.RigidBodySetTransformPosRotXYZ(SphereBody, 0,20,0, 0,0,10)
rp3d.RigidBodySetLinearVelocityXYZ(SphereBody,0,0,0)
'rp3d.RigidBodySetAngularVelocityXYZ(SphereBody,0,0,0)
end if
'b3d.PointEntity camera, SphereObject
b3d.updateworld
b3d.renderworld
ScreenSync
flip
loop while inkey <> chr(27)
rp3d.RigidBodyRemoveCollisionShape(SphereBody, BoxProxy)
rp3d.DestroyBoxShape(BoxShape)
rp3d.DynamicsWorldDestroyRigidBody(DynamicsWorld, BoxBody)
rp3d.RigidBodyRemoveCollisionShape(SphereBody, FloorProxy)
rp3d.DestroyBoxShape(FloorShape)
rp3d.DynamicsWorldDestroyRigidBody(DynamicsWorld, FloorBody)
rp3d.RigidBodyRemoveCollisionShape(SphereBody, SphereProxy)
rp3d.DestroySphereShape(SphereShape)
rp3d.DynamicsWorldDestroyRigidBody(DynamicsWorld, SphereBody)
rp3d.DestroyDynamicsWorld(DynamicsWorld)