mirror of
https://github.com/bloeys/physx-go.git
synced 2025-12-29 07:58:20 +00:00
Simulation filtering
This commit is contained in:
10
main.go
10
main.go
@ -38,6 +38,9 @@ func main() {
|
||||
groundPlane := pgo.CreatePlane(p, pgo.NewPlane(0, 1, 0, 0), pMat)
|
||||
s.AddActor(groundPlane.ToActor())
|
||||
|
||||
//W0/W1 are filter groups the shape belongs to, and W2/W3 are a filter group mask
|
||||
fd := pgo.NewFilterData(1, 1, 1, 1)
|
||||
|
||||
//Add box1
|
||||
v := pgo.NewVec3(0, 10, 0)
|
||||
q := pgo.NewQuat(0, 0, 1, 0)
|
||||
@ -48,12 +51,19 @@ func main() {
|
||||
|
||||
box := pgo.NewBoxGeometry(0.5, 0.5, 0.5)
|
||||
dynBox := pgo.CreateDynamic(p, tr, box.ToGeometry(), pMat, 1, shapeOffset)
|
||||
|
||||
ra := dynBox.ToRigidActor()
|
||||
ra.SetSimFilterData(&fd)
|
||||
s.AddActor(dynBox.ToActor())
|
||||
|
||||
//Add box2
|
||||
v = pgo.NewVec3(0.5, 12, 0)
|
||||
tr2 := pgo.NewTransform(v, qID)
|
||||
dynBox2 := pgo.CreateDynamic(p, tr2, box.ToGeometry(), pMat, 1, shapeOffset)
|
||||
|
||||
ra = dynBox2.ToRigidActor()
|
||||
ra.SetSimFilterData(&fd)
|
||||
|
||||
s.AddActor(dynBox2.ToActor())
|
||||
|
||||
//Add sphere
|
||||
|
||||
Binary file not shown.
34
pgo/pgo.go
34
pgo/pgo.go
@ -164,6 +164,21 @@ func CreatePhysics(f *Foundation, ts *TolerancesScale, trackOutstandingAllocatio
|
||||
return p
|
||||
}
|
||||
|
||||
type FilterData struct {
|
||||
cFilterData C.struct_CPxFilterData
|
||||
}
|
||||
|
||||
func NewFilterData(w0, w1, w2, w3 uint32) FilterData {
|
||||
return FilterData{
|
||||
cFilterData: C.struct_CPxFilterData{
|
||||
word0: C.uint(w0),
|
||||
word1: C.uint(w1),
|
||||
word2: C.uint(w2),
|
||||
word3: C.uint(w3),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
type Shape struct {
|
||||
cShape C.struct_CPxShape
|
||||
}
|
||||
@ -178,6 +193,19 @@ func (s *Shape) SetLocalPose(tr *Transform) {
|
||||
C.CPxShape_setLocalPose(&s.cShape, &tr.cT)
|
||||
}
|
||||
|
||||
func (s *Shape) GetSimulationFilterData() FilterData {
|
||||
return FilterData{
|
||||
cFilterData: C.CPxShape_getSimulationFilterData(&s.cShape),
|
||||
}
|
||||
}
|
||||
|
||||
func (s *Shape) SetSimulationFilterData(fd *FilterData) {
|
||||
C.CPxShape_setSimulationFilterData(&s.cShape, &fd.cFilterData)
|
||||
}
|
||||
|
||||
// CPxAPI CSTRUCT CPxFilterData CPxShape_getSimulationFilterData(CSTRUCT CPxShape* cs);
|
||||
// CPxAPI void CPxShape_setSimulationFilterData(CSTRUCT CPxShape* cs, CSTRUCT CPxFilterData cfd);
|
||||
|
||||
func CreateExclusiveShape(rigidActor RigidActor, geom *Geometry, mat *Material, shapeFlags ShapeFlags) Shape {
|
||||
return Shape{
|
||||
cShape: C.createExclusiveShape(rigidActor.cRa, geom.cG, mat.cM, uint32(shapeFlags)),
|
||||
@ -356,6 +384,12 @@ type RigidActor struct {
|
||||
cRa C.struct_CPxRigidActor
|
||||
}
|
||||
|
||||
func (ra *RigidActor) SetSimFilterData(fd *FilterData) {
|
||||
C.CPxRigidActor_setSimFilterData(&ra.cRa, &fd.cFilterData)
|
||||
}
|
||||
|
||||
// CPxAPI void CPxRigidActor_setSimFilterData(CSTRUCT CPxRigidActor* cra, CSTRUCT CPxFilterData* cfd);
|
||||
|
||||
type RigidStatic struct {
|
||||
cRs *C.struct_CPxRigidStatic
|
||||
}
|
||||
|
||||
26
pgo/physx-c/CPxFilterData.h
Executable file
26
pgo/physx-c/CPxFilterData.h
Executable file
@ -0,0 +1,26 @@
|
||||
#ifndef CPxFilterData_H
|
||||
#define CPxFilterData_H
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct CPxFilterData
|
||||
{
|
||||
unsigned int word0;
|
||||
unsigned int word1;
|
||||
unsigned int word2;
|
||||
unsigned int word3;
|
||||
|
||||
//TODO: For some reason only this file breaks with CPxU32 (uint32_t). Why?
|
||||
/*CPxU32 word0;
|
||||
CPxU32 word1;
|
||||
CPxU32 word2;
|
||||
CPxU32 word3;*/
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif // !CPxFilterData_H
|
||||
@ -1,6 +1,8 @@
|
||||
#ifndef CPxRigidActor_H
|
||||
#define CPxRigidActor_H
|
||||
|
||||
#include "CPxFilterData.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
@ -10,6 +12,9 @@ extern "C" {
|
||||
void* obj;
|
||||
};
|
||||
|
||||
//Sets the CPxFilterData on all the shapes of the actor.
|
||||
CPxAPI void CPxRigidActor_setSimFilterData(CSTRUCT CPxRigidActor* cra, CSTRUCT CPxFilterData* cfd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
@ -14,7 +14,7 @@ extern "C" {
|
||||
};
|
||||
|
||||
/// <summary>
|
||||
/// Creates a SceneDesc with filterShader=physx::PxDefaultSimulationFilterShader
|
||||
/// Creates a SceneDesc with a custom filterShader that uses word0/word1 as groups shapes belong to, and word2/word3 as mask on the groups.
|
||||
/// </summary>
|
||||
/// <param name="CPxTolerancesScale"></param>
|
||||
/// <returns></returns>
|
||||
|
||||
@ -2,6 +2,7 @@
|
||||
#define CPxShape_H
|
||||
|
||||
#include "CPxTransform.h"
|
||||
#include "CPxFilterData.h"
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
@ -14,6 +15,8 @@ extern "C" {
|
||||
|
||||
CPxAPI void CPxShape_setLocalPose(CSTRUCT CPxShape* cs, CSTRUCT CPxTransform* tr);
|
||||
CPxAPI CSTRUCT CPxTransform CPxShape_getLocalPose(CSTRUCT CPxShape* cs);
|
||||
CPxAPI CSTRUCT CPxFilterData CPxShape_getSimulationFilterData(CSTRUCT CPxShape* cs);
|
||||
CPxAPI void CPxShape_setSimulationFilterData(CSTRUCT CPxShape* cs, CSTRUCT CPxFilterData* cfd);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user