diff --git a/main.go b/main.go index 665d0b6..11218d7 100755 --- a/main.go +++ b/main.go @@ -67,6 +67,12 @@ func main() { dynCapsule := pgo.CreateDynamic(p, tr4, pgo.NewCapsuleGeometry(0.25, 0.5).ToGeometry(), pMat, 1, shapeOffset) s.AddActor(dynCapsule.ToActor()) + //Add compound shape + dynComp := p.CreateRigidDynamic(pgo.NewTransform(pgo.NewVec3(0, 35, 0), qID)) + pgo.CreateExclusiveShape(dynComp.ToRigidActor(), pgo.NewSphereGeometry(2).ToGeometry(), pMat, pgo.ShapeFlags_eSCENE_QUERY_SHAPE|pgo.ShapeFlags_eSIMULATION_SHAPE|pgo.ShapeFlags_eVISUALIZATION) + pgo.CreateExclusiveShape(dynComp.ToRigidActor(), pgo.NewBoxGeometry(10, 0.1, 0.1).ToGeometry(), pMat, pgo.ShapeFlags_eSCENE_QUERY_SHAPE|pgo.ShapeFlags_eSIMULATION_SHAPE|pgo.ShapeFlags_eVISUALIZATION) + s.AddActor(dynComp.ToActor()) + dynSphere.SetMass(1) dynCapsule.SetMass(1) println("Box 1 mass:", dynBox.GetMass()) diff --git a/pgo/libs/libphysx-c.a b/pgo/libs/libphysx-c.a index 885b9f8..2c6768c 100755 Binary files a/pgo/libs/libphysx-c.a and b/pgo/libs/libphysx-c.a differ diff --git a/pgo/pgo.go b/pgo/pgo.go index e6c60b3..3577240 100755 --- a/pgo/pgo.go +++ b/pgo/pgo.go @@ -91,7 +91,7 @@ func (s *Scene) GetScenePvdClient() *PvdSceneClient { } } -func (s *Scene) AddActor(a *Actor) { +func (s *Scene) AddActor(a Actor) { C.CPxScene_addActor(s.cS, a.cA) } @@ -126,6 +126,25 @@ func (p *Physics) CreateMaterial(staticFriction, dynamicFriction, restitution fl } } +// CPxAPI CSTRUCT CPxRigidDynamic* CPxPhysics_createRigidDynamic(CSTRUCT CPxPhysics* cp, CSTRUCT CPxTransform* ctr); +// CPxAPI CSTRUCT CPxRigidStatic* CPxPhysics_createRigidStatic(CSTRUCT CPxPhysics* cp, CSTRUCT CPxTransform* ctr); + +func (p *Physics) CreateRigidDynamic(tr *Transform) *RigidDynamic { + return &RigidDynamic{ + cRd: C.CPxPhysics_createRigidDynamic(p.cPhysics, &tr.cT), + } +} + +func (p *Physics) CreateRigidStatic(tr *Transform) *RigidStatic { + return &RigidStatic{ + cRs: C.CPxPhysics_createRigidStatic(p.cPhysics, &tr.cT), + } +} + +func (p *Physics) Release() { + C.CPxPhysics_release(p.cPhysics) +} + func CreatePhysics(f *Foundation, ts *TolerancesScale, trackOutstandingAllocations bool, pvd *Pvd) *Physics { p := &Physics{} @@ -134,8 +153,14 @@ func CreatePhysics(f *Foundation, ts *TolerancesScale, trackOutstandingAllocatio return p } -func (p *Physics) Release() { - C.CPxPhysics_release(p.cPhysics) +type Shape struct { + cShape C.struct_CPxShape +} + +func CreateExclusiveShape(rigidActor RigidActor, geom *Geometry, mat *Material, shapeFlags ShapeFlags) Shape { + return Shape{ + cShape: C.createExclusiveShape(rigidActor.cRa, geom.cG, mat.cM, uint32(shapeFlags)), + } } type Vec3 struct { @@ -306,16 +331,26 @@ type Actor struct { cA C.struct_CPxActor } +type RigidActor struct { + cRa C.struct_CPxRigidActor +} + type RigidStatic struct { cRs *C.struct_CPxRigidStatic } -func (rs *RigidStatic) ToActor() *Actor { - return &Actor{ +func (rs *RigidStatic) ToActor() Actor { + return Actor{ cA: C.CPxRigidStatic_toCPxActor(rs.cRs), } } +func (rs *RigidStatic) ToRigidActor() RigidActor { + return RigidActor{ + cRa: C.CPxRigidStatic_toCPxRigidActor(rs.cRs), + } +} + func CreatePlane(p *Physics, plane *Plane, mat *Material) *RigidStatic { return &RigidStatic{ cRs: C.CPxCreatePlane(p.cPhysics, plane.cP, mat.cM), diff --git a/pgo/physx-c/CPxPhysics.h b/pgo/physx-c/CPxPhysics.h index d2c4b80..38dc155 100755 --- a/pgo/physx-c/CPxPhysics.h +++ b/pgo/physx-c/CPxPhysics.h @@ -7,6 +7,9 @@ #include "CPxSceneDesc.h" #include "CPxMaterial.h" #include "CPxTolerancesScale.h" +#include "CPxRigidStatic.h" +#include "CPxRigidDynamic.h" +#include "CPxTransform.h" #ifdef __cplusplus extern "C" { @@ -19,6 +22,9 @@ extern "C" { CPxAPI CSTRUCT CPxPhysics* CPxCreatePhysics(CSTRUCT CPxFoundation* cfoundation, CSTRUCT CPxTolerancesScale cscale, bool trackOutstandingAllocations, CSTRUCT CPxPvd* cpvd); CPxAPI CSTRUCT CPxScene* CPxPhysics_createScene(CSTRUCT CPxPhysics*, CSTRUCT CPxSceneDesc*); CPxAPI CSTRUCT CPxMaterial* CPxPhysics_createMaterial(CSTRUCT CPxPhysics*, CPxReal staticFriction, CPxReal dynamicFriction, CPxReal restitution); + CPxAPI CSTRUCT CPxRigidDynamic* CPxPhysics_createRigidDynamic(CSTRUCT CPxPhysics* cp, CSTRUCT CPxTransform* ctr); + CPxAPI CSTRUCT CPxRigidStatic* CPxPhysics_createRigidStatic(CSTRUCT CPxPhysics* cp, CSTRUCT CPxTransform* ctr); + CPxAPI void CPxPhysics_release(CSTRUCT CPxPhysics*); #ifdef __cplusplus diff --git a/pgo/physx-c/CPxRigidActor.h b/pgo/physx-c/CPxRigidActor.h new file mode 100755 index 0000000..86cbbb6 --- /dev/null +++ b/pgo/physx-c/CPxRigidActor.h @@ -0,0 +1,17 @@ +#ifndef CPxRigidActor_H +#define CPxRigidActor_H + +#ifdef __cplusplus +extern "C" { +#endif + + struct CPxRigidActor + { + void* obj; + }; + +#ifdef __cplusplus +} +#endif + +#endif // !CPxRigidActor_H diff --git a/pgo/physx-c/CPxRigidActorExt.h b/pgo/physx-c/CPxRigidActorExt.h new file mode 100755 index 0000000..ac61a6b --- /dev/null +++ b/pgo/physx-c/CPxRigidActorExt.h @@ -0,0 +1,20 @@ +#ifndef CPxRigidActorExt_H +#define CPxRigidActorExt_H + +#include "CPxRigidActor.h" +#include "CPxShape.h" +#include "CPxGeometry.h" +#include "CPxMaterial.h" +#include "CPxShapeFlags.h" + +#ifdef __cplusplus +extern "C" { +#endif + + CPxAPI CSTRUCT CPxShape createExclusiveShape(CSTRUCT CPxRigidActor actor, CSTRUCT CPxGeometry geometry, CSTRUCT CPxMaterial* material, CENUM CPxShapeFlags shapeFlags); + +#ifdef __cplusplus +} +#endif + +#endif // !CPxRigidActorExt_H diff --git a/pgo/physx-c/CPxRigidDynamic.h b/pgo/physx-c/CPxRigidDynamic.h index 16ff161..d822680 100755 --- a/pgo/physx-c/CPxRigidDynamic.h +++ b/pgo/physx-c/CPxRigidDynamic.h @@ -2,6 +2,7 @@ #define CPxRigidDynamic_H #include "CPxActor.h" +#include "CPxRigidActor.h" #include "CPxVec3.h" #include "CPxTransform.h" #include "CPxForceMode.h" @@ -18,6 +19,8 @@ extern "C" { }; CPxAPI CSTRUCT CPxActor CPxRigidDynamic_toCPxActor(CSTRUCT CPxRigidDynamic*); + CPxAPI CSTRUCT CPxRigidActor CPxRigidDynamic_toCPxRigidActor(CSTRUCT CPxRigidDynamic*); + CPxAPI void CPxRigidDynamic_addForce(CSTRUCT CPxRigidDynamic* crd, CSTRUCT CPxVec3* force, CENUM CPxForceMode fmode, bool autoAwake); CPxAPI void CPxRigidDynamic_addTorque(CSTRUCT CPxRigidDynamic* crd, CSTRUCT CPxVec3* torque, CENUM CPxForceMode fmode, bool autoAwake); @@ -25,7 +28,7 @@ extern "C" { CPxAPI void CPxRigidDynamic_setAngularDamping(CSTRUCT CPxRigidDynamic* crd, CPxReal damping); CPxAPI CPxReal CPxRigidDynamic_getLinearDamping(CSTRUCT CPxRigidDynamic* crd); CPxAPI CPxReal CPxRigidDynamic_getAngularDamping(CSTRUCT CPxRigidDynamic* crd); - + CPxAPI CSTRUCT CPxVec3 CPxRigidDynamic_getLinearVelocity(CSTRUCT CPxRigidDynamic* crd); CPxAPI CSTRUCT CPxVec3 CPxRigidDynamic_getAngularVelocity(CSTRUCT CPxRigidDynamic* crd); diff --git a/pgo/physx-c/CPxRigidStatic.h b/pgo/physx-c/CPxRigidStatic.h index 248ec9a..b3d594b 100755 --- a/pgo/physx-c/CPxRigidStatic.h +++ b/pgo/physx-c/CPxRigidStatic.h @@ -1,10 +1,8 @@ #ifndef CPxRigidStatic_H #define CPxRigidStatic_H -#include "CPxPhysics.h" -#include "CPxPlane.h" -#include "CPxMaterial.h" #include "CPxActor.h" +#include "CPxRigidActor.h" #ifdef __cplusplus extern "C" { @@ -15,8 +13,8 @@ extern "C" { void* obj; }; - CPxAPI CSTRUCT CPxRigidStatic* CPxCreatePlane(CSTRUCT CPxPhysics* sdk, CSTRUCT CPxPlane* plane, CSTRUCT CPxMaterial* material); CPxAPI CSTRUCT CPxActor CPxRigidStatic_toCPxActor(CSTRUCT CPxRigidStatic*); + CPxAPI CSTRUCT CPxRigidActor CPxRigidStatic_toCPxRigidActor(CSTRUCT CPxRigidStatic*); #ifdef __cplusplus } diff --git a/pgo/physx-c/CPxShape.h b/pgo/physx-c/CPxShape.h new file mode 100755 index 0000000..e91d05a --- /dev/null +++ b/pgo/physx-c/CPxShape.h @@ -0,0 +1,17 @@ +#ifndef CPxShape_H +#define CPxShape_H + +#ifdef __cplusplus +extern "C" { +#endif + + struct CPxShape + { + void* obj; + }; + +#ifdef __cplusplus +} +#endif + +#endif // !CPxShape_H diff --git a/pgo/physx-c/CPxShapeFlags.h b/pgo/physx-c/CPxShapeFlags.h new file mode 100755 index 0000000..77e5629 --- /dev/null +++ b/pgo/physx-c/CPxShapeFlags.h @@ -0,0 +1,63 @@ +#ifndef CPxShapeFlags_H +#define CPxShapeFlags_H + +#ifdef __cplusplus +extern "C" { +#endif + + enum CPxShapeFlags + { + /** + \brief The shape will partake in collision in the physical simulation. + + \note It is illegal to raise the eSIMULATION_SHAPE and eTRIGGER_SHAPE flags. + In the event that one of these flags is already raised the sdk will reject any + attempt to raise the other. To raise the eSIMULATION_SHAPE first ensure that + eTRIGGER_SHAPE is already lowered. + + \note This flag has no effect if simulation is disabled for the corresponding actor (see #PxActorFlag::eDISABLE_SIMULATION). + + @see PxSimulationEventCallback.onContact() PxScene.setSimulationEventCallback() PxShape.setFlag(), PxShape.setFlags() + */ + CPxShapeFlags_eSIMULATION_SHAPE = (1 << 0), + + /** + \brief The shape will partake in scene queries (ray casts, overlap tests, sweeps, ...). + */ + CPxShapeFlags_eSCENE_QUERY_SHAPE = (1 << 1), + + /** + \brief The shape is a trigger which can send reports whenever other shapes enter/leave its volume. + + \note Triangle meshes and heightfields can not be triggers. Shape creation will fail in these cases. + + \note Shapes marked as triggers do not collide with other objects. If an object should act both + as a trigger shape and a collision shape then create a rigid body with two shapes, one being a + trigger shape and the other a collision shape. It is illegal to raise the eTRIGGER_SHAPE and + eSIMULATION_SHAPE flags on a single PxShape instance. In the event that one of these flags is already + raised the sdk will reject any attempt to raise the other. To raise the eTRIGGER_SHAPE flag first + ensure that eSIMULATION_SHAPE flag is already lowered. + + \note Trigger shapes will no longer send notification events for interactions with other trigger shapes. + + \note Shapes marked as triggers are allowed to participate in scene queries, provided the eSCENE_QUERY_SHAPE flag is set. + + \note This flag has no effect if simulation is disabled for the corresponding actor (see #PxActorFlag::eDISABLE_SIMULATION). + + @see PxSimulationEventCallback.onTrigger() PxScene.setSimulationEventCallback() PxShape.setFlag(), PxShape.setFlags() + */ + CPxShapeFlags_eTRIGGER_SHAPE = (1 << 2), + + /** + \brief Enable debug renderer for this shape + + @see PxScene.getRenderBuffer() PxRenderBuffer PxVisualizationParameter + */ + CPxShapeFlags_eVISUALIZATION = (1 << 3) + }; + +#ifdef __cplusplus +} +#endif + +#endif // !CPxShapeFlags_H diff --git a/pgo/physx-c/CPxSimpleFactory.h b/pgo/physx-c/CPxSimpleFactory.h new file mode 100755 index 0000000..3efd88b --- /dev/null +++ b/pgo/physx-c/CPxSimpleFactory.h @@ -0,0 +1,19 @@ +#ifndef CPxSimpleFactory_H +#define CPxSimpleFactory_H + +#include "CPxPlane.h" +#include "CPxPhysics.h" +#include "CPxMaterial.h" +#include "CPxRigidStatic.h" + +#ifdef __cplusplus +extern "C" { +#endif + + CPxAPI CSTRUCT CPxRigidStatic* CPxCreatePlane(CSTRUCT CPxPhysics* sdk, CSTRUCT CPxPlane* plane, CSTRUCT CPxMaterial* material); + +#ifdef __cplusplus +} +#endif + +#endif // !CPxSimpleFactory_H diff --git a/pgo/rigiddynamic.go b/pgo/rigiddynamic.go index 67400f7..b7b8e14 100755 --- a/pgo/rigiddynamic.go +++ b/pgo/rigiddynamic.go @@ -95,12 +95,18 @@ func (rd *RigidDynamic) SetGlobalPose(tr *Transform, autoAwake bool) { C.CPxRigidDynamic_setGlobalPose(rd.cRd, &tr.cT, C._Bool(autoAwake)) } -func (rd *RigidDynamic) ToActor() *Actor { - return &Actor{ +func (rd *RigidDynamic) ToActor() Actor { + return Actor{ cA: C.CPxRigidDynamic_toCPxActor(rd.cRd), } } +func (rd *RigidDynamic) ToRigidActor() RigidActor { + return RigidActor{ + cRa: C.CPxRigidDynamic_toCPxRigidActor(rd.cRd), + } +} + func CreateDynamic(p *Physics, t *Transform, g *Geometry, m *Material, density float32, shapeOffset *Transform) *RigidDynamic { return &RigidDynamic{ cRd: C.CPxCreateDynamic(p.cPhysics, &t.cT, g.cG, m.cM, C.float(density), &shapeOffset.cT), diff --git a/pgo/shaperflags.go b/pgo/shaperflags.go new file mode 100755 index 0000000..c9625af --- /dev/null +++ b/pgo/shaperflags.go @@ -0,0 +1,53 @@ +package pgo + +type ShapeFlags uint32 + +const ( + /** + \brief The shape will partake in collision in the physical simulation. + + \note It is illegal to raise the eSIMULATION_SHAPE and eTRIGGER_SHAPE flags. + In the event that one of these flags is already raised the sdk will reject any + attempt to raise the other. To raise the eSIMULATION_SHAPE first ensure that + eTRIGGER_SHAPE is already lowered. + + \note This flag has no effect if simulation is disabled for the corresponding actor (see #PxActorFlag::eDISABLE_SIMULATION). + + @see PxSimulationEventCallback.onContact() PxScene.setSimulationEventCallback() PxShape.setFlag(), PxShape.setFlags() + */ + ShapeFlags_eSIMULATION_SHAPE ShapeFlags = (1 << 0) + + /** + \brief The shape will partake in scene queries (ray casts, overlap tests, sweeps, ...). + */ + ShapeFlags_eSCENE_QUERY_SHAPE ShapeFlags = (1 << 1) + + /** + \brief The shape is a trigger which can send reports whenever other shapes enter/leave its volume. + + \note Triangle meshes and heightfields can not be triggers. Shape creation will fail in these cases. + + \note Shapes marked as triggers do not collide with other objects. If an object should act both + as a trigger shape and a collision shape then create a rigid body with two shapes, one being a + trigger shape and the other a collision shape. It is illegal to raise the eTRIGGER_SHAPE and + eSIMULATION_SHAPE flags on a single PxShape instance. In the event that one of these flags is already + raised the sdk will reject any attempt to raise the other. To raise the eTRIGGER_SHAPE flag first + ensure that eSIMULATION_SHAPE flag is already lowered. + + \note Trigger shapes will no longer send notification events for interactions with other trigger shapes. + + \note Shapes marked as triggers are allowed to participate in scene queries, provided the eSCENE_QUERY_SHAPE flag is set. + + \note This flag has no effect if simulation is disabled for the corresponding actor (see #PxActorFlag::eDISABLE_SIMULATION). + + @see PxSimulationEventCallback.onTrigger() PxScene.setSimulationEventCallback() PxShape.setFlag(), PxShape.setFlags() + */ + ShapeFlags_eTRIGGER_SHAPE ShapeFlags = (1 << 2) + + /** + \brief Enable debug renderer for this shape + + @see PxScene.getRenderBuffer() PxRenderBuffer PxVisualizationParameter + */ + ShapeFlags_eVISUALIZATION ShapeFlags = (1 << 3) +) diff --git a/pgo/wrap.c b/pgo/wrap.c index d3c0492..2f5478e 100755 --- a/pgo/wrap.c +++ b/pgo/wrap.c @@ -19,12 +19,19 @@ #include #include #include + #include #include +#include +#include + #include #include #include + #include #include #include -#include \ No newline at end of file +#include + +#include \ No newline at end of file