ReactPhysics3D 0.7.1 C wrapper Windows/Linux 32/64-bit

External libraries (GTK, GSL, SDL, Allegro, OpenGL, etc) questions.
D.J.Peters
Posts: 8177
Joined: May 28, 2005 3:28
Contact:

ReactPhysics3D 0.7.1 C wrapper Windows/Linux 32/64-bit

Postby D.J.Peters » Nov 23, 2018 5:03

I created a C wrapper for the C++ library ReactPhysis3D 0.7.1

homepage: https://www.reactphysics3d.com/

on github: https://github.com/DanielChappuis/reactphysics3d

FreeBASIC downloads: Thu Jul 04, 2019
React Physics 3D C-libraries for Windows and Linux 32/64-bit
source code as Code::Blocks project:
reactphysics3d-c-0.7.1-src.zip

License:
ReactPhysics3D is licensed under the zlib
https://github.com/DanielChappuis/react ... er/LICENSE
(you can modify and use it commercial also.)

some features:
Rigid body dynamics
Discrete collision detection
Collision shapes (Sphere, Box, Capsule, Convex Mesh, Static Concave Mesh, Height Field)
Multiple collision shapes per body
Broadphase collision detection (Dynamic AABB tree)
Narrowphase collision detection (SAT/GJK)
Collision response and friction (Sequential Impulses Solver)
Joints (Ball and Socket, Hinge, Slider, Fixed)
Collision filtering with categories
Ray casting
Sleeping technique for inactive bodies
Multi-platform (Windows, Linux, Mac OS X)
No external libraries (do not use STL containers)
...
ChangeLog wrote:Version 0.7.1 (July 01, 2019)

Added:
- Make possible for the user to get vertices, normals and triangle indices of a ConcaveMeshShape
- Make possible for the user to get vertices and height values of the HeightFieldShape
- Make possible for the user to use a custom single frame and pool memory allocator
- C wrapper JointSetUserData() JointGetUserData (by me)
Fixed: (see bug tracker on github)
- Bug [#45],[#50],[#52],[#53],[#54],[#55],[#51],[#60],[#57],[#37],[#62],[#63],[#82],[#85],[#79]
- Bug: the free() method was called in PoolAllocator instead of release() method of base allocator.


User manual pdf: included in the zip file (doc folder)

C++ API Documentation online: https://www.reactphysics3d.com/documentation/api/html/index.html

I know no once here will learn or use this kind of complex libraries how ever I share all my work with you :-)

With OpenB3D or Horde3D we have really good render engines for FreeBASIC
TrueAxis or ReactPhysics3D are perfect for games in FreeBASIC also.
Together with FBSound a dream team to create modern games in BASIC.

Joshy
Last edited by D.J.Peters on Jul 09, 2019 11:23, edited 13 times in total.
Munair
Posts: 886
Joined: Oct 19, 2017 15:00
Location: 't Zand, NL
Contact:

Re: React Physics 3D 0.7.0 C wrapper Windows/Linux 32/64-bit

Postby Munair » Nov 24, 2018 13:58

Thank you for sharing Joshy.
D.J.Peters
Posts: 8177
Joined: May 28, 2005 3:28
Contact:

Re: React Physics 3D 0.7.0 C wrapper Windows/Linux 32/64-bit

Postby D.J.Peters » Nov 27, 2018 9:17

Update ReactPhysics3D for FreeBASIC is complete now:
All encapsulated in rp3d namespace same as the original C++.
I separated primary classes in it's own include files and added comments for the most commands.

Joshy
Tourist Trap
Posts: 2933
Joined: Jun 02, 2015 16:24

Re: React Physics 3D 0.7.0 C wrapper Windows/Linux 32/64-bit

Postby Tourist Trap » Nov 28, 2018 22:36

Thanks for the job, the engine looks pretty cool.
D.J.Peters
Posts: 8177
Joined: May 28, 2005 3:28
Contact:

Re: React Physics 3D 0.7.0 C wrapper Windows/Linux 32/64-bit

Postby D.J.Peters » Jul 03, 2019 19:30

New version 0.7.1 are out it comes with many bug fixes and I added JointSet/GetUserData() to the C++ classes.
I will compile and upload last build of reactphysics-c-0.7.1 soon.

Joshy

[edit] done see first post
D.J.Peters
Posts: 8177
Joined: May 28, 2005 3:28
Contact:

Re: ReactPhysics3D 0.7.1 C wrapper Windows/Linux 32/64-bit

Postby D.J.Peters » Jul 04, 2019 6:35

new update

fixed:
RigidBodySetMaterial() was declared in the *.bi file but not implemented in the C wrapper.

Joshy
int soumen
Posts: 1
Joined: Jun 02, 2020 18:47

Re: ReactPhysics3D 0.7.1 C wrapper Windows/Linux 32/64-bit

Postby int soumen » Jun 02, 2020 18:50

I am trying to develop a basic carrom game with this library. How do I create a cylinder?
jepalza
Posts: 70
Joined: Feb 24, 2010 10:08
Location: Spain (Bilbao)

Re: ReactPhysics3D 0.7.1 C wrapper Windows/Linux 32/64-bit

Postby jepalza » Jun 04, 2020 4:19

You need update your "tool's box" ;-)
viewtopic.php?f=17&t=24043&hilit=TrueAxis
Gunslinger
Posts: 46
Joined: Mar 08, 2016 19:10
Location: The Netherlands

Re: ReactPhysics3D 0.7.1 C wrapper Windows/Linux 32/64-bit

Postby Gunslinger » Sep 19, 2020 13:27

int soumen wrote:I am trying to develop a basic carrom game with this library. How do I create a cylinder?

This is what i got so far. (no cilinders)
I did try to translate a demo (CubesScene), but i don't know C+

I had to change TransformEntity in openB3D.bi
Declare sub TransformEntity(byval _Entity as tEntity ptr, byval as const single)
to
Declare sub TransformEntity(byval _Entity as tEntity ptr, byval pMatrix4x4 as single ptr)

And also in rp3d_rigidbody.bi
declare function RigidBodyGetTransform alias "CollisionBodyGetTransform" (byval rb as RigidBody ptr) byref as const Transform
to
declare function RigidBodyGetTransform alias "CollisionBodyGetTransform" (byval rb as RigidBody ptr) byref as Transform

I wish D.J.Peters help with this :)

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)
Last edited by Gunslinger on Sep 20, 2020 20:38, edited 2 times in total.
D.J.Peters
Posts: 8177
Joined: May 28, 2005 3:28
Contact:

Re: ReactPhysics3D 0.7.1 C wrapper Windows/Linux 32/64-bit

Postby D.J.Peters » Sep 20, 2020 13:27

@Gunslinger first thank you for testing and don't shoot me down ;-)
You are right there are 3 wrong declares I will fix it.
(if no once test all my stuff I wrote for FreeBASIC the possible bugs will never found or fixed)

The funny part are two week ago I was thinking about to mix reactphysics3d with libOpenB3D also. :-)

So I will doit today a tiny sunday project.

Your test example can than be done with much less lines of code.

Joshy
Gunslinger
Posts: 46
Joined: Mar 08, 2016 19:10
Location: The Netherlands

Re: ReactPhysics3D 0.7.1 C wrapper Windows/Linux 32/64-bit

Postby Gunslinger » Sep 20, 2020 15:02

I am also thinking about raylib to use with this.
Not that i really like raylib but it seems to fit with basic programming style. And very easy to understand. Lot of nice stuff in raylib.

About this react physics i like it to use the Static Concave Mesh for static terrain. I can really use som help with that.

And i also wish for a freebasic release with more modern libery packed in one.

And i m also thinking about rewrite SNC netwerk. Mij current project. Still learning and testing.


a other example. can not find out how to add a joint point.
dim Anchor as const rp3d.vector3 => (0,0,0)
var jointBody = rp3d.DynamicsWorldCreateJoint(DynamicsWorld, rp3d.FixedJointInfo(BoxBody(1) , BoxBody(0) ,Anchor ))
makes a error

Code: Select all

#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 => (30,2,30)           '// Floor dimensions in meters
const SPHERE_SIZE = 5
const screenx = 1920
const screeny = 1080
const NR_BOXES = 300

screenres screenx, screeny, 32, , &h10002 + 0, 60
b3d.Graphics3d screenx, screeny

var camera=b3d.createcamera()
   b3d.moveEntity camera, 0,20,-100 'move camera back
   b3d.AmbientLight .45,.35,.25
var   sun = b3d.CreateLight( 1)
   b3d.RotateEntity sun,-90,0,0
   b3d.PositionEntity sun,0,100,-50

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, 9.81)
rp3d.RigidBodySetType(FloorBody, rp3d.BT_STATIC)
rp3d.RigidBodyEnableGravity(FloorBody, false)
'rp3d.RigidBodySetMass(FloorBody, 1000)
var FloorObject = b3d.CreateCube()
b3d.scaleEntity FloorObject, FLOOR_SIZE.x, FLOOR_SIZE.y, FLOOR_SIZE.z
b3d.entityColor FloorObject, .75,.75,.75
b3d.moveEntity  FloorObject, 0,-15,0


dim as any ptr BoxBody(NR_BOXES-1), BoxShape(NR_BOXES-1), BoxProxy(NR_BOXES-1)
dim as any ptr BoxObject(NR_BOXES-1), BoxShadow(NR_BOXES-1)

' create box
for i as integer = 0 to (NR_BOXES-1)
   BoxBody(i) = rp3d.DynamicsWorldCreateRigidBodyPosRotXYZ(DynamicsWorld, 0,0,0, 0,0,0)
   BoxShape(i) = rp3d.CreateBoxShape(BOX_SIZE)
   BoxProxy(i) = rp3d.RigidBodyAddCollisionShapePosRotXYZ(BoxBody(i),BoxShape(i),0,0,0, 0,0,0, 10.0)
   BoxObject(i) = b3d.CreateCube()
   b3d.scaleEntity BoxObject(i), BOX_SIZE.x,BOX_SIZE.y,BOX_SIZE.z
   b3d.entityColor BoxObject(i), 1,0,1
   BoxShadow(i) = b3d.CreateShadow(BoxObject(i))
   b3d.meshcullradius BoxObject(i),100
   rp3d.CollisionBodySetIsAllowedToSleep(BoxBody(i),false)
next

dim Anchor as const rp3d.vector3 => (0,0,0)
'var jointBody = rp3d.DynamicsWorldCreateJoint(DynamicsWorld, rp3d.FixedJointInfo(BoxBody(1) , BoxBody(0) ,Anchor ))


dim as single matrix(15)
dim as  any ptr transformX = @matrix(0)

do
   rp3d.DynamicsWorldUpdate(DynamicsWorld,1/60)
   
   rp3d.TransformGetOpenGLMatrix(rp3d.RigidBodyGetTransform(FloorBody), transformX)
   b3d.TransformEntity FloorObject, transformX
   for i as integer = 0 to (NR_BOXES-1)
      rp3d.TransformGetOpenGLMatrix(rp3d.RigidBodyGetTransform(BoxBody(i)), transformX)
      b3d.TransformEntity BoxObject(i), transformX
      
      if rp3d.RigidBodyGetTransform(BoxBody(i)).position.y < -15 then
         rp3d.RigidBodySetTransformPosRotXYZ(BoxBody(i), 0,60,0, 0,0,0)
         rp3d.RigidBodySetLinearVelocityXYZ(BoxBody(i),0,0,0)
         rp3d.RigidBodySetAngularVelocityXYZ(BoxBody(i),0,0,0)
      end if
      'if rp3d.CollisionBodyIsSleeping(BoxBody(i)) then b3d.entityColor BoxObject(i), 1,0,0
   next
   'b3d.PointEntity camera, SphereObject
   b3d.updateworld
   b3d.renderworld
   'ScreenSync
   flip    
loop while inkey <> chr(27)


rp3d.DestroyDynamicsWorld(DynamicsWorld)

Return to “Libraries”

Who is online

Users browsing this forum: No registered users and 1 guest