From ce662775a43e6bd03bf664d151228c40a3f89066 Mon Sep 17 00:00:00 2001 From: bloeys Date: Fri, 28 Jan 2022 05:49:27 +0400 Subject: [PATCH] Implementing the rigiddynamic api --- main.go | 14 ++- pgo/forcemode.go | 10 ++ pgo/libs/libphysx-c.a | Bin 12552 -> 16648 bytes pgo/pgo.go | 28 +++--- pgo/physx-c/CPxForceMode.h | 20 ++++ pgo/physx-c/CPxQuat.h | 1 + pgo/physx-c/CPxRigidBodyFlag.h | 136 ++++++++++++++++++++++++++ pgo/physx-c/CPxRigidDynamic.h | 23 +++++ pgo/physx-c/CPxRigidDynamicLockFlag.h | 22 +++++ pgo/physx-c/CPxTransform.h | 1 - pgo/rigidbodyflags.go | 127 ++++++++++++++++++++++++ pgo/rigiddynamic.go | 72 ++++++++++++++ pgo/rigiddynamiclockflags.go | 12 +++ pgo/wrap.c | 1 + 14 files changed, 446 insertions(+), 21 deletions(-) create mode 100755 pgo/forcemode.go create mode 100755 pgo/physx-c/CPxForceMode.h create mode 100755 pgo/physx-c/CPxRigidBodyFlag.h create mode 100755 pgo/physx-c/CPxRigidDynamicLockFlag.h create mode 100755 pgo/rigidbodyflags.go create mode 100755 pgo/rigiddynamic.go create mode 100755 pgo/rigiddynamiclockflags.go diff --git a/main.go b/main.go index 85a9d89..f70412c 100755 --- a/main.go +++ b/main.go @@ -47,26 +47,32 @@ func main() { shapeOffset := pgo.NewTransform(v, qID) box := pgo.NewBoxGeometry(0.5, 0.5, 0.5) - dynBox := pgo.CreateDynamic(p, tr, box.ToGeometry(), pMat, 10, shapeOffset) + dynBox := pgo.CreateDynamic(p, tr, box.ToGeometry(), pMat, 1, shapeOffset) s.AddActor(dynBox.ToActor()) v = pgo.NewVec3(0.5, 12, 0) tr2 := pgo.NewTransform(v, qID) - dynBox2 := pgo.CreateDynamic(p, tr2, box.ToGeometry(), pMat, 10, shapeOffset) + dynBox2 := pgo.CreateDynamic(p, tr2, box.ToGeometry(), pMat, 1, shapeOffset) s.AddActor(dynBox2.ToActor()) //Add sphere v = pgo.NewVec3(0, 16, 0) tr3 := pgo.NewTransform(v, qID) - dynSphere := pgo.CreateDynamic(p, tr3, pgo.NewSphereGeometry(3).ToGeometry(), pMat, 10, shapeOffset) + dynSphere := pgo.CreateDynamic(p, tr3, pgo.NewSphereGeometry(3).ToGeometry(), pMat, 1, shapeOffset) s.AddActor(dynSphere.ToActor()) //Add capsule v = pgo.NewVec3(0, 20, 0) tr4 := pgo.NewTransform(v, qID) - dynCapsule := pgo.CreateDynamic(p, tr4, pgo.NewCapsuleGeometry(0.25, 0.5).ToGeometry(), pMat, 10, shapeOffset) + dynCapsule := pgo.CreateDynamic(p, tr4, pgo.NewCapsuleGeometry(0.25, 0.5).ToGeometry(), pMat, 1, shapeOffset) s.AddActor(dynCapsule.ToActor()) + dynSphere.SetMass(1) + dynCapsule.SetMass(1) + println("Box 1 mass:", dynBox.GetMass()) + println("Box 2 mass:", dynBox2.GetMass()) + println("Sphere mass:", dynSphere.GetMass()) + println("Capsule mass:", dynCapsule.GetMass()) for { s.Simulate(1 / 60.0) s.FetchResults(true) diff --git a/pgo/forcemode.go b/pgo/forcemode.go new file mode 100755 index 0000000..fa5bb30 --- /dev/null +++ b/pgo/forcemode.go @@ -0,0 +1,10 @@ +package pgo + +type ForceMode uint32 + +const ( + ForceMode_eFORCE ForceMode = iota //!< parameter has unit of mass * distance/ time^2, i.e. a force + ForceMode_eIMPULSE //!< parameter has unit of mass * distance /time + ForceMode_eVELOCITY_CHANGE //!< parameter has unit of distance / time, i.e. the effect is mass independent: a velocity change. + ForceMode_eACCELERATION //!< parameter has unit of distance/ time^2, i.e. an acceleration. It gets treated just like a force except the mass is not divided out before integration. +) diff --git a/pgo/libs/libphysx-c.a b/pgo/libs/libphysx-c.a index 02b81e5ebec9230d18f817f98ca4d3dda063cc06..62ece36da3a6812227e677168c58d33c58ada8df 100755 GIT binary patch literal 16648 zcmc&*YiwM_6+TG_p-u=Ufe`W_PVB_a!;W9Ow)3ZTZn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dz=-1A{`bumzElGnVZeC7>QyE@P9(j%>I8kMH%jJe^HGXs9L`m?pe_97&{L4SSZ z9}Rh=JyDQ!*028j@$x@xIKpyfXhuyReRqeQg&}jr4!Pg%mEPiny8PP@U$U2oaCJtl zub;ZdZo-tE;*{sH>u-L;!Llzdh}9mDSNE6PFMcuixjr%qmsr8D)b>xP+4a&ZDKc|RDG#o>}_Yde39e+wj~HvE)&@7DA8d2P`rPd+*>dq@20 zm+znZiI)*6**9`rwM_o~HE$Wxa&F{=vX|ef>3SL2J$gdDpsXu8Gb?kW$5qDOx~D7U IV!Z diff --git a/pgo/pgo.go b/pgo/pgo.go index ff29f8b..02e3a1d 100755 --- a/pgo/pgo.go +++ b/pgo/pgo.go @@ -140,6 +140,18 @@ type Vec3 struct { cV C.struct_CPxVec3 } +func (v *Vec3) X() float32 { + return float32(v.cV.x) +} + +func (v *Vec3) Y() float32 { + return float32(v.cV.y) +} + +func (v *Vec3) Z() float32 { + return float32(v.cV.z) +} + func NewVec3(x, y, z float32) *Vec3 { return &Vec3{ cV: C.NewCPxVec3(C.float(x), C.float(y), C.float(z)), @@ -307,19 +319,3 @@ func CreatePlane(p *Physics, plane *Plane, mat *Material) *RigidStatic { cRs: C.CPxCreatePlane(p.cPhysics, plane.cP, mat.cM), } } - -type RigidDynamic struct { - cRd *C.struct_CPxRigidDynamic -} - -func (rs *RigidDynamic) ToActor() *Actor { - return &Actor{ - cA: C.CPxRigidDynamic_toCPxActor(rs.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/physx-c/CPxForceMode.h b/pgo/physx-c/CPxForceMode.h new file mode 100755 index 0000000..3df9e07 --- /dev/null +++ b/pgo/physx-c/CPxForceMode.h @@ -0,0 +1,20 @@ +#ifndef CPxForceMode_H +#define CPxForceMode_H + +#ifdef __cplusplus +extern "C" { +#endif + + enum CPxForceMode + { + eFORCE, //!< parameter has unit of mass * distance/ time^2, i.e. a force + eIMPULSE, //!< parameter has unit of mass * distance /time + eVELOCITY_CHANGE, //!< parameter has unit of distance / time, i.e. the effect is mass independent: a velocity change. + eACCELERATION //!< parameter has unit of distance/ time^2, i.e. an acceleration. It gets treated just like a force except the mass is not divided out before integration. + }; + +#ifdef __cplusplus +} +#endif + +#endif // !CPxForceMode_H diff --git a/pgo/physx-c/CPxQuat.h b/pgo/physx-c/CPxQuat.h index 3a973ee..417dfa7 100755 --- a/pgo/physx-c/CPxQuat.h +++ b/pgo/physx-c/CPxQuat.h @@ -11,6 +11,7 @@ extern "C" { }; CPxAPI CPxInline CSTRUCT CPxQuat NewCPxQuat(float angleRads, float x, float y, float z); + CPxAPI CPxInline CSTRUCT CPxQuat NewCPxQuatXYZW(float x, float y, float z, float w); #ifdef __cplusplus } diff --git a/pgo/physx-c/CPxRigidBodyFlag.h b/pgo/physx-c/CPxRigidBodyFlag.h new file mode 100755 index 0000000..0f23f2b --- /dev/null +++ b/pgo/physx-c/CPxRigidBodyFlag.h @@ -0,0 +1,136 @@ +#ifndef CPxRigidBodyFlag_H +#define CPxRigidBodyFlag_H + +#ifdef __cplusplus +extern "C" { +#endif + + enum CPxRigidBodyFlag + { + /** + \brief Enables kinematic mode for the actor. + + Kinematic actors are special dynamic actors that are not + influenced by forces (such as gravity), and have no momentum. They are considered to have infinite + mass and can be moved around the world using the setKinematicTarget() method. They will push + regular dynamic actors out of the way. Kinematics will not collide with static or other kinematic objects. + + Kinematic actors are great for moving platforms or characters, where direct motion control is desired. + + You can not connect Reduced joints to kinematic actors. Lagrange joints work ok if the platform + is moving with a relatively low, uniform velocity. + + Sleeping: + \li Setting this flag on a dynamic actor will put the actor to sleep and set the velocities to 0. + \li If this flag gets cleared, the current sleep state of the actor will be kept. + + \note kinematic actors are incompatible with CCD so raising this flag will automatically clear eENABLE_CCD + + @see PxRigidDynamic.setKinematicTarget() + */ + CPxRigidBodyFlag_eKINEMATIC = (1 << 0), //!< Enable kinematic mode for the body. + + /** + \brief Use the kinematic target transform for scene queries. + + If this flag is raised, then scene queries will treat the kinematic target transform as the current pose + of the body (instead of using the actual pose). Without this flag, the kinematic target will only take + effect with respect to scene queries after a simulation step. + + @see PxRigidDynamic.setKinematicTarget() + */ + CPxRigidBodyFlag_eUSE_KINEMATIC_TARGET_FOR_SCENE_QUERIES = (1 << 1), + + /** + \brief Enables swept integration for the actor. + + If this flag is raised and CCD is enabled on the scene, then this body will be simulated by the CCD system to ensure that collisions are not missed due to + high-speed motion. Note individual shape pairs still need to enable PxPairFlag::eDETECT_CCD_CONTACT in the collision filtering to enable the CCD to respond to + individual interactions. + + \note kinematic actors are incompatible with CCD so this flag will be cleared automatically when raised on a kinematic actor + + */ + CPxRigidBodyFlag_eENABLE_CCD = (1 << 2), //!< Enable CCD for the body. + + /** + \brief Enabled CCD in swept integration for the actor. + + If this flag is raised and CCD is enabled, CCD interactions will simulate friction. By default, friction is disabled in CCD interactions because + CCD friction has been observed to introduce some simulation artifacts. CCD friction was enabled in previous versions of the SDK. Raising this flag will result in behavior + that is a closer match for previous versions of the SDK. + + \note This flag requires PxRigidBodyFlag::eENABLE_CCD to be raised to have any effect. + */ + CPxRigidBodyFlag_eENABLE_CCD_FRICTION = (1 << 3), + + /** + \brief Register a rigid body for reporting pose changes by the simulation at an early stage. + + Sometimes it might be advantageous to get access to the new pose of a rigid body as early as possible and + not wait until the call to fetchResults() returns. Setting this flag will schedule the rigid body to get reported + in #PxSimulationEventCallback::onAdvance(). Please refer to the documentation of that callback to understand + the behavior and limitations of this functionality. + + @see PxSimulationEventCallback::onAdvance() + */ + CPxRigidBodyFlag_eENABLE_POSE_INTEGRATION_PREVIEW = (1 << 4), + + /** + \brief Register a rigid body to dynamicly adjust contact offset based on velocity. This can be used to achieve a CCD effect. + */ + CPxRigidBodyFlag_eENABLE_SPECULATIVE_CCD = (1 << 5), + + /** + \brief Permit CCD to limit maxContactImpulse. This is useful for use-cases like a destruction system but can cause visual artefacts so is not enabled by default. + */ + CPxRigidBodyFlag_eENABLE_CCD_MAX_CONTACT_IMPULSE = (1 << 6), + + /** + \brief Carries over forces/accelerations between frames, rather than clearning them + */ + CPxRigidBodyFlag_eRETAIN_ACCELERATIONS = (1 << 7), + + /** + \brief Forces kinematic-kinematic pairs notifications for this actor. + + This flag overrides the global scene-level PxPairFilteringMode setting for kinematic actors. + This is equivalent to having PxPairFilteringMode::eKEEP for pairs involving this actor. + + A particular use case is when you have a large amount of kinematic actors, but you are only + interested in interactions between a few of them. In this case it is best to use set + PxSceneDesc.kineKineFilteringMode = PxPairFilteringMode::eKILL, and then raise the + eFORCE_KINE_KINE_NOTIFICATIONS flag on the small set of kinematic actors that need + notifications. + + \note This has no effect if PxRigidBodyFlag::eKINEMATIC is not set. + + \warning Changing this flag at runtime will not have an effect until you remove and re-add the actor to the scene. + + @see PxPairFilteringMode PxSceneDesc.kineKineFilteringMode + */ + CPxRigidBodyFlag_eFORCE_KINE_KINE_NOTIFICATIONS = (1 << 8), + + /** + \brief Forces static-kinematic pairs notifications for this actor. + + Similar to eFORCE_KINE_KINE_NOTIFICATIONS, but for static-kinematic interactions. + + \note This has no effect if PxRigidBodyFlag::eKINEMATIC is not set. + + \warning Changing this flag at runtime will not have an effect until you remove and re-add the actor to the scene. + + @see PxPairFilteringMode PxSceneDesc.staticKineFilteringMode + */ + CPxRigidBodyFlag_eFORCE_STATIC_KINE_NOTIFICATIONS = (1 << 9), + + /** + \brief Reserved for internal usage + */ + CPxRigidBodyFlag_eRESERVED = (1 << 15) + }; + +#ifdef __cplusplus +} +#endif +#endif // !CPxRigidBodyFlag_H diff --git a/pgo/physx-c/CPxRigidDynamic.h b/pgo/physx-c/CPxRigidDynamic.h index e37be01..a031c4e 100755 --- a/pgo/physx-c/CPxRigidDynamic.h +++ b/pgo/physx-c/CPxRigidDynamic.h @@ -2,6 +2,11 @@ #define CPxRigidDynamic_H #include "CPxActor.h" +#include "CPxVec3.h" +#include "CPxTransform.h" +#include "CPxForceMode.h" +#include "CPxRigidBodyFlag.h" +#include "CPxRigidDynamicLockFlag.h" #ifdef __cplusplus extern "C" { @@ -13,6 +18,24 @@ extern "C" { }; CPxAPI CSTRUCT CPxActor CPxRigidDynamic_toCPxActor(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); + CPxAPI CSTRUCT CPxVec3 CPxRigidDynamic_getLinearVelocity(CSTRUCT CPxRigidDynamic* crd); + + CPxAPI void CPxRigidDynamic_setMass(CSTRUCT CPxRigidDynamic* crd, CPxReal mass); + CPxAPI CPxReal CPxRigidDynamic_getMass(CSTRUCT CPxRigidDynamic* crd); + + CPxAPI void CPxRigidDynamic_setRigidBodyFlag(CSTRUCT CPxRigidDynamic* crd, CENUM CPxRigidBodyFlag flag, bool value); + CPxAPI void CPxRigidDynamic_setRigidBodyFlags(CSTRUCT CPxRigidDynamic* crd, CENUM CPxRigidBodyFlag flags); + CPxAPI CENUM CPxRigidBodyFlag CPxRigidDynamic_getRigidBodyFlags(CSTRUCT CPxRigidDynamic* crd); + + CPxAPI void CPxRigidDynamic_setRigidDynamicLockFlag(CSTRUCT CPxRigidDynamic* crd, CENUM CPxRigidDynamicLockFlag flag, bool value); + CPxAPI void CPxRigidDynamic_setRigidDynamicLockFlags(CSTRUCT CPxRigidDynamic* crd, CENUM CPxRigidDynamicLockFlag flags); + CPxAPI CENUM CPxRigidDynamicLockFlag CPxRigidDynamic_getRigidDynamicLockFlags(CSTRUCT CPxRigidDynamic* crd); + + CPxAPI void CPxRigidDynamic_putToSleep(CSTRUCT CPxRigidDynamic* crd); + CPxAPI CSTRUCT CPxTransform CPxRigidDynamic_getGlobalPose(CSTRUCT CPxRigidDynamic* crd); + CPxAPI void CPxRigidDynamic_setGlobalPose(CSTRUCT CPxRigidDynamic* crd, CSTRUCT CPxTransform* tr, bool autoAwake); #ifdef __cplusplus } diff --git a/pgo/physx-c/CPxRigidDynamicLockFlag.h b/pgo/physx-c/CPxRigidDynamicLockFlag.h new file mode 100755 index 0000000..5f94b87 --- /dev/null +++ b/pgo/physx-c/CPxRigidDynamicLockFlag.h @@ -0,0 +1,22 @@ +#ifndef CPxRigidDynamicLockFlag_H +#define CPxRigidDynamicLockFlag_H + +#ifdef __cplusplus +extern "C" { +#endif + + enum CPxRigidDynamicLockFlag + { + CPxRigidDynamicLockFlag_eLOCK_LINEAR_X = (1 << 0), + CPxRigidDynamicLockFlag_eLOCK_LINEAR_Y = (1 << 1), + CPxRigidDynamicLockFlag_eLOCK_LINEAR_Z = (1 << 2), + CPxRigidDynamicLockFlag_eLOCK_ANGULAR_X = (1 << 3), + CPxRigidDynamicLockFlag_eLOCK_ANGULAR_Y = (1 << 4), + CPxRigidDynamicLockFlag_eLOCK_ANGULAR_Z = (1 << 5) + }; + +#ifdef __cplusplus +} +#endif + +#endif // !CPxRigidDynamicLockFlag_H diff --git a/pgo/physx-c/CPxTransform.h b/pgo/physx-c/CPxTransform.h index a9f01e6..9637e01 100755 --- a/pgo/physx-c/CPxTransform.h +++ b/pgo/physx-c/CPxTransform.h @@ -15,7 +15,6 @@ extern "C" { }; CPxAPI CPxInline CSTRUCT CPxTransform NewCPxTransform(CSTRUCT CPxVec3*, CSTRUCT CPxQuat*); - #ifdef __cplusplus } #endif diff --git a/pgo/rigidbodyflags.go b/pgo/rigidbodyflags.go new file mode 100755 index 0000000..060a13c --- /dev/null +++ b/pgo/rigidbodyflags.go @@ -0,0 +1,127 @@ +package pgo + +type RigidbodyFlags uint32 + +const ( + /** + \brief Enables kinematic mode for the actor. + + Kinematic actors are special dynamic actors that are not + influenced by forces (such as gravity), and have no momentum. They are considered to have infinite + mass and can be moved around the world using the setKinematicTarget() method. They will push + regular dynamic actors out of the way. Kinematics will not collide with static or other kinematic objects. + + Kinematic actors are great for moving platforms or characters, where direct motion control is desired. + + You can not connect Reduced joints to kinematic actors. Lagrange joints work ok if the platform + is moving with a relatively low, uniform velocity. + + Sleeping: + \li Setting this flag on a dynamic actor will put the actor to sleep and set the velocities to 0. + \li If this flag gets cleared, the current sleep state of the actor will be kept. + + \note kinematic actors are incompatible with CCD so raising this flag will automatically clear eENABLE_CCD + + @see PxRigidDynamic.setKinematicTarget() + */ + RigidbodyFlags_eKINEMATIC RigidbodyFlags = (1 << 0) //!< Enable kinematic mode for the body. + + /** + \brief Use the kinematic target transform for scene queries. + + If this flag is raised, then scene queries will treat the kinematic target transform as the current pose + of the body (instead of using the actual pose). Without this flag, the kinematic target will only take + effect with respect to scene queries after a simulation step. + + @see PxRigidDynamic.setKinematicTarget() + */ + RigidbodyFlags_eUSE_KINEMATIC_TARGET_FOR_SCENE_QUERIES RigidbodyFlags = (1 << 1) + + /** + \brief Enables swept integration for the actor. + + If this flag is raised and CCD is enabled on the scene, then this body will be simulated by the CCD system to ensure that collisions are not missed due to + high-speed motion. Note individual shape pairs still need to enable PxPairFlag::eDETECT_CCD_CONTACT in the collision filtering to enable the CCD to respond to + individual interactions. + + \note kinematic actors are incompatible with CCD so this flag will be cleared automatically when raised on a kinematic actor + + */ + RigidbodyFlags_eENABLE_CCD RigidbodyFlags = (1 << 2) //!< Enable CCD for the body. + + /** + \brief Enabled CCD in swept integration for the actor. + + If this flag is raised and CCD is enabled, CCD interactions will simulate friction. By default, friction is disabled in CCD interactions because + CCD friction has been observed to introduce some simulation artifacts. CCD friction was enabled in previous versions of the SDK. Raising this flag will result in behavior + that is a closer match for previous versions of the SDK. + + \note This flag requires PxRigidBodyFlag::eENABLE_CCD to be raised to have any effect. + */ + RigidbodyFlags_eENABLE_CCD_FRICTION RigidbodyFlags = (1 << 3) + + /** + \brief Register a rigid body for reporting pose changes by the simulation at an early stage. + + Sometimes it might be advantageous to get access to the new pose of a rigid body as early as possible and + not wait until the call to fetchResults() returns. Setting this flag will schedule the rigid body to get reported + in #PxSimulationEventCallback::onAdvance(). Please refer to the documentation of that callback to understand + the behavior and limitations of this functionality. + + @see PxSimulationEventCallback::onAdvance() + */ + RigidbodyFlags_eENABLE_POSE_INTEGRATION_PREVIEW RigidbodyFlags = (1 << 4) + + /** + \brief Register a rigid body to dynamicly adjust contact offset based on velocity. This can be used to achieve a CCD effect. + */ + RigidbodyFlags_eENABLE_SPECULATIVE_CCD RigidbodyFlags = (1 << 5) + + /** + \brief Permit CCD to limit maxContactImpulse. This is useful for use-cases like a destruction system but can cause visual artefacts so is not enabled by default. + */ + RigidbodyFlags_eENABLE_CCD_MAX_CONTACT_IMPULSE RigidbodyFlags = (1 << 6) + + /** + \brief Carries over forces/accelerations between frames, rather than clearning them + */ + RigidbodyFlags_eRETAIN_ACCELERATIONS RigidbodyFlags = (1 << 7) + + /** + \brief Forces kinematic-kinematic pairs notifications for this actor. + + This flag overrides the global scene-level PxPairFilteringMode setting for kinematic actors. + This is equivalent to having PxPairFilteringMode::eKEEP for pairs involving this actor. + + A particular use case is when you have a large amount of kinematic actors, but you are only + interested in interactions between a few of them. In this case it is best to use set + PxSceneDesc.kineKineFilteringMode = PxPairFilteringMode::eKILL, and then raise the + eFORCE_KINE_KINE_NOTIFICATIONS flag on the small set of kinematic actors that need + notifications. + + \note This has no effect if PxRigidBodyFlag::eKINEMATIC is not set. + + \warning Changing this flag at runtime will not have an effect until you remove and re-add the actor to the scene. + + @see PxPairFilteringMode PxSceneDesc.kineKineFilteringMode + */ + RigidbodyFlags_eFORCE_KINE_KINE_NOTIFICATIONS RigidbodyFlags = (1 << 8) + + /** + \brief Forces static-kinematic pairs notifications for this actor. + + Similar to eFORCE_KINE_KINE_NOTIFICATIONS, but for static-kinematic interactions. + + \note This has no effect if PxRigidBodyFlag::eKINEMATIC is not set. + + \warning Changing this flag at runtime will not have an effect until you remove and re-add the actor to the scene. + + @see PxPairFilteringMode PxSceneDesc.staticKineFilteringMode + */ + RigidbodyFlags_eFORCE_STATIC_KINE_NOTIFICATIONS RigidbodyFlags = (1 << 9) + + /** + \brief Reserved for internal usage + */ + RigidbodyFlags_eRESERVED RigidbodyFlags = (1 << 15) +) diff --git a/pgo/rigiddynamic.go b/pgo/rigiddynamic.go new file mode 100755 index 0000000..296b419 --- /dev/null +++ b/pgo/rigiddynamic.go @@ -0,0 +1,72 @@ +package pgo + +/* +#cgo CFLAGS: -I physx-c +#cgo LDFLAGS: -L ./libs -l physx-c + +#include +#include //Needed for C.free +*/ +import "C" + +type RigidDynamic struct { + cRd *C.struct_CPxRigidDynamic +} + +func (rd *RigidDynamic) AddForce(force *Vec3, fmode ForceMode, autoAwake bool) { + C.CPxRigidDynamic_addForce(rd.cRd, &force.cV, uint32(fmode), C._Bool(autoAwake)) +} + +func (rd *RigidDynamic) AddTorque(torque *Vec3, fmode ForceMode, autoAwake bool) { + C.CPxRigidDynamic_addTorque(rd.cRd, &torque.cV, uint32(fmode), C._Bool(autoAwake)) +} + +func (rd *RigidDynamic) GetLinearVelocity() Vec3 { + return Vec3{ + cV: C.CPxRigidDynamic_getLinearVelocity(rd.cRd), + } +} + +func (rd *RigidDynamic) SetMass(mass float32) { + C.CPxRigidDynamic_setMass(rd.cRd, C.float(mass)) +} + +func (rd *RigidDynamic) GetMass() float32 { + return float32(C.CPxRigidDynamic_getMass(rd.cRd)) +} + +func (rd *RigidDynamic) SetRigidBodyFlag(flag RigidbodyFlags, value bool) { + C.CPxRigidDynamic_setRigidBodyFlag(rd.cRd, uint32(flag), C._Bool(value)) +} + +func (rd *RigidDynamic) SetRigidBodyFlags(flags RigidbodyFlags) { + C.CPxRigidDynamic_setRigidBodyFlags(rd.cRd, uint32(flags)) +} + +func (rd *RigidDynamic) GetRigidBodyFlags() RigidbodyFlags { + return RigidbodyFlags(C.CPxRigidDynamic_getRigidBodyFlags(rd.cRd)) +} + +func (rd *RigidDynamic) SetRigidDynamicLockFlag(flag RigidDynamicLockFlags, value bool) { + C.CPxRigidDynamic_setRigidDynamicLockFlag(rd.cRd, uint32(flag), C._Bool(value)) +} + +func (rd *RigidDynamic) SetRigidDynamicLockFlags(flags RigidDynamicLockFlags) { + C.CPxRigidDynamic_setRigidDynamicLockFlags(rd.cRd, uint32(flags)) +} + +func (rd *RigidDynamic) GetRigidDynamicLockFlags() RigidDynamicLockFlags { + return RigidDynamicLockFlags(C.CPxRigidDynamic_getRigidDynamicLockFlags(rd.cRd)) +} + +func (rd *RigidDynamic) ToActor() *Actor { + return &Actor{ + cA: C.CPxRigidDynamic_toCPxActor(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/rigiddynamiclockflags.go b/pgo/rigiddynamiclockflags.go new file mode 100755 index 0000000..d8e8dd6 --- /dev/null +++ b/pgo/rigiddynamiclockflags.go @@ -0,0 +1,12 @@ +package pgo + +type RigidDynamicLockFlags uint32 + +const ( + RigidDynamicLockFlags_eLOCK_LINEAR_X RigidDynamicLockFlags = (1 << 0) + RigidDynamicLockFlags_eLOCK_LINEAR_Y RigidDynamicLockFlags = (1 << 1) + RigidDynamicLockFlags_eLOCK_LINEAR_Z RigidDynamicLockFlags = (1 << 2) + RigidDynamicLockFlags_eLOCK_ANGULAR_X RigidDynamicLockFlags = (1 << 3) + RigidDynamicLockFlags_eLOCK_ANGULAR_Y RigidDynamicLockFlags = (1 << 4) + RigidDynamicLockFlags_eLOCK_ANGULAR_Z RigidDynamicLockFlags = (1 << 5) +) diff --git a/pgo/wrap.c b/pgo/wrap.c index 143a2ce..d3c0492 100755 --- a/pgo/wrap.c +++ b/pgo/wrap.c @@ -1,6 +1,7 @@ #include #include #define CPxAPI +#define CPxInternalAPI #define CPxInline #define CSTRUCT struct #define CENUM enum