Receive onContact callbacks

This commit is contained in:
bloeys
2022-02-14 08:52:18 +04:00
parent 3344705f6b
commit 2831edb9d4
5 changed files with 35 additions and 7 deletions

View File

@ -22,6 +22,7 @@ func main() {
sd := pgo.NewSceneDesc(ts)
sd.SetGravity(pgo.NewVec3(0, -9.8, 0))
sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, 0).ToCpuDispatcher())
sd.SetOnContactCallback()
s := p.CreateScene(sd)
println("Scene:", s)
@ -63,19 +64,23 @@ func main() {
ra = dynBox2.ToRigidActor()
ra.SetSimFilterData(&fd)
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, 1, shapeOffset)
ra = dynSphere.ToRigidActor()
ra.SetSimFilterData(&fd)
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, 1, shapeOffset)
ra = dynCapsule.ToRigidActor()
ra.SetSimFilterData(&fd)
s.AddActor(dynCapsule.ToActor())
//Add compound shape
@ -89,6 +94,8 @@ func main() {
someShape = pgo.CreateExclusiveShape(dynComp.ToRigidActor(), pgo.NewSphereGeometry(2).ToGeometry(), pMat, pgo.ShapeFlags_eSCENE_QUERY_SHAPE|pgo.ShapeFlags_eSIMULATION_SHAPE|pgo.ShapeFlags_eVISUALIZATION)
someShape.SetLocalPose(pgo.NewTransform(pgo.NewVec3(-5, 0, 0), qID))
ra = dynComp.ToRigidActor()
ra.SetSimFilterData(&fd)
s.AddActor(dynComp.ToActor())
//Make some changes and print info

10
pgo/ccallbacks.go Executable file
View File

@ -0,0 +1,10 @@
package pgo
/*
void goOnContactCallback_cgo(void* pairHeader)
{
void goOnContactCallback(void*);
goOnContactCallback(pairHeader);
}
*/
import "C"

Binary file not shown.

View File

@ -6,8 +6,12 @@ package pgo
#include <wrap.c>
#include <stdlib.h> //Needed for C.free
//simulation event callbacks forward declarations. Actual definitions MUST be in a go different file
void goOnContactCallback_cgo(void* pairHeader);
*/
import "C"
import "unsafe"
type PvdInstrumentationFlag uint32
@ -99,8 +103,6 @@ func (s *Scene) Simulate(elapsedTime float32) {
C.CPxScene_simulate(s.cS, C.float(elapsedTime))
}
// void CPxScene_advance(CSTRUCT CPxScene*);
func (s *Scene) Collide(elapsedTime float32) {
C.CPxScene_collide(s.cS, C.float(elapsedTime))
}
@ -203,9 +205,6 @@ 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)),
@ -264,6 +263,15 @@ func (sd *SceneDesc) SetCpuDispatcher(cd *CpuDispatcher) {
C.CPxSceneDesc_set_cpuDispatcher(sd.cSD, cd.cCpuDisp)
}
//export goOnContactCallback
func goOnContactCallback(p unsafe.Pointer) {
println("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!")
}
func (sd *SceneDesc) SetOnContactCallback() {
C.CPxSceneDesc_set_onContactCallback(sd.cSD, (C.CPxonContactCallback)(unsafe.Pointer(C.goOnContactCallback_cgo)))
}
func NewSceneDesc(ts *TolerancesScale) *SceneDesc {
return &SceneDesc{
cSD: C.NewCPxSceneDesc(ts.cTolScale),

View File

@ -13,14 +13,17 @@ extern "C" {
void* obj;
};
typedef void (*CPxonContactCallback)(void* pairHeader);
/// <summary>
/// Creates a SceneDesc with a custom filterShader that uses word0/word1 as groups shapes belong to, and word2/word3 as mask on the groups.
/// Creates a SceneDesc with a custom filterShader that uses word0/word1 as groups shapes can belong to, word2 as a mask on word0, and word3 as a mask on word1.
/// </summary>
/// <param name="CPxTolerancesScale"></param>
/// <returns></returns>
CPxAPI CSTRUCT CPxSceneDesc* NewCPxSceneDesc(CSTRUCT CPxTolerancesScale);
CPxAPI void CPxSceneDesc_set_gravity(CSTRUCT CPxSceneDesc*, CSTRUCT CPxVec3);
CPxAPI void CPxSceneDesc_set_cpuDispatcher(CSTRUCT CPxSceneDesc*, CSTRUCT CPxCpuDispatcher*);
CPxAPI void CPxSceneDesc_set_onContactCallback(CSTRUCT CPxSceneDesc*, CPxonContactCallback cb);
CPxAPI void FreeCPxSceneDesc(CSTRUCT CPxSceneDesc*);
#ifdef __cplusplus