mirror of
https://github.com/bloeys/physx-go.git
synced 2025-12-29 07:58:20 +00:00
Shapes+RigidActors+CreateExclusiveShape+add createRigid dynamic/static to physics
This commit is contained in:
Binary file not shown.
45
pgo/pgo.go
45
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),
|
||||
|
||||
@ -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
|
||||
|
||||
17
pgo/physx-c/CPxRigidActor.h
Executable file
17
pgo/physx-c/CPxRigidActor.h
Executable file
@ -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
|
||||
20
pgo/physx-c/CPxRigidActorExt.h
Executable file
20
pgo/physx-c/CPxRigidActorExt.h
Executable file
@ -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
|
||||
@ -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);
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
|
||||
17
pgo/physx-c/CPxShape.h
Executable file
17
pgo/physx-c/CPxShape.h
Executable file
@ -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
|
||||
63
pgo/physx-c/CPxShapeFlags.h
Executable file
63
pgo/physx-c/CPxShapeFlags.h
Executable file
@ -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
|
||||
19
pgo/physx-c/CPxSimpleFactory.h
Executable file
19
pgo/physx-c/CPxSimpleFactory.h
Executable file
@ -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
|
||||
@ -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),
|
||||
|
||||
53
pgo/shaperflags.go
Executable file
53
pgo/shaperflags.go
Executable file
@ -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)
|
||||
)
|
||||
@ -19,12 +19,19 @@
|
||||
#include <CPxTolerancesScale.h>
|
||||
#include <CPxPlane.h>
|
||||
#include <CPxActor.h>
|
||||
|
||||
#include <CPxRigidStatic.h>
|
||||
#include <CPxRigidDynamic.h>
|
||||
#include <CPxRigidActorExt.h>
|
||||
#include <CPxShapeFlags.h>
|
||||
|
||||
#include <CPxTransform.h>
|
||||
#include <CPxPvdSceneClient.h>
|
||||
#include <CExtSimpleFactory.h>
|
||||
|
||||
#include <CPxGeometry.h>
|
||||
#include <CPxBoxGeometry.h>
|
||||
#include <CPxSphereGeometry.h>
|
||||
#include <CPxCapsuleGeometry.h>
|
||||
#include <CPxCapsuleGeometry.h>
|
||||
|
||||
#include <CPxSimpleFactory.h>
|
||||
Reference in New Issue
Block a user