mirror of
https://github.com/bloeys/physx-go.git
synced 2025-12-29 07:58:20 +00:00
Receive onContact callbacks
This commit is contained in:
9
main.go
9
main.go
@ -22,6 +22,7 @@ func main() {
|
|||||||
sd := pgo.NewSceneDesc(ts)
|
sd := pgo.NewSceneDesc(ts)
|
||||||
sd.SetGravity(pgo.NewVec3(0, -9.8, 0))
|
sd.SetGravity(pgo.NewVec3(0, -9.8, 0))
|
||||||
sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, 0).ToCpuDispatcher())
|
sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, 0).ToCpuDispatcher())
|
||||||
|
sd.SetOnContactCallback()
|
||||||
|
|
||||||
s := p.CreateScene(sd)
|
s := p.CreateScene(sd)
|
||||||
println("Scene:", s)
|
println("Scene:", s)
|
||||||
@ -63,19 +64,23 @@ func main() {
|
|||||||
|
|
||||||
ra = dynBox2.ToRigidActor()
|
ra = dynBox2.ToRigidActor()
|
||||||
ra.SetSimFilterData(&fd)
|
ra.SetSimFilterData(&fd)
|
||||||
|
|
||||||
s.AddActor(dynBox2.ToActor())
|
s.AddActor(dynBox2.ToActor())
|
||||||
|
|
||||||
//Add sphere
|
//Add sphere
|
||||||
v = pgo.NewVec3(0, 16, 0)
|
v = pgo.NewVec3(0, 16, 0)
|
||||||
tr3 := pgo.NewTransform(v, qID)
|
tr3 := pgo.NewTransform(v, qID)
|
||||||
dynSphere := pgo.CreateDynamic(p, tr3, pgo.NewSphereGeometry(3).ToGeometry(), pMat, 1, shapeOffset)
|
dynSphere := pgo.CreateDynamic(p, tr3, pgo.NewSphereGeometry(3).ToGeometry(), pMat, 1, shapeOffset)
|
||||||
|
|
||||||
|
ra = dynSphere.ToRigidActor()
|
||||||
|
ra.SetSimFilterData(&fd)
|
||||||
s.AddActor(dynSphere.ToActor())
|
s.AddActor(dynSphere.ToActor())
|
||||||
|
|
||||||
//Add capsule
|
//Add capsule
|
||||||
v = pgo.NewVec3(0, 20, 0)
|
v = pgo.NewVec3(0, 20, 0)
|
||||||
tr4 := pgo.NewTransform(v, qID)
|
tr4 := pgo.NewTransform(v, qID)
|
||||||
dynCapsule := pgo.CreateDynamic(p, tr4, pgo.NewCapsuleGeometry(0.25, 0.5).ToGeometry(), pMat, 1, shapeOffset)
|
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())
|
s.AddActor(dynCapsule.ToActor())
|
||||||
|
|
||||||
//Add compound shape
|
//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 = 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))
|
someShape.SetLocalPose(pgo.NewTransform(pgo.NewVec3(-5, 0, 0), qID))
|
||||||
|
|
||||||
|
ra = dynComp.ToRigidActor()
|
||||||
|
ra.SetSimFilterData(&fd)
|
||||||
s.AddActor(dynComp.ToActor())
|
s.AddActor(dynComp.ToActor())
|
||||||
|
|
||||||
//Make some changes and print info
|
//Make some changes and print info
|
||||||
|
|||||||
10
pgo/ccallbacks.go
Executable file
10
pgo/ccallbacks.go
Executable file
@ -0,0 +1,10 @@
|
|||||||
|
package pgo
|
||||||
|
|
||||||
|
/*
|
||||||
|
void goOnContactCallback_cgo(void* pairHeader)
|
||||||
|
{
|
||||||
|
void goOnContactCallback(void*);
|
||||||
|
goOnContactCallback(pairHeader);
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
import "C"
|
||||||
Binary file not shown.
18
pgo/pgo.go
18
pgo/pgo.go
@ -6,8 +6,12 @@ package pgo
|
|||||||
|
|
||||||
#include <wrap.c>
|
#include <wrap.c>
|
||||||
#include <stdlib.h> //Needed for C.free
|
#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 "C"
|
||||||
|
import "unsafe"
|
||||||
|
|
||||||
type PvdInstrumentationFlag uint32
|
type PvdInstrumentationFlag uint32
|
||||||
|
|
||||||
@ -99,8 +103,6 @@ func (s *Scene) Simulate(elapsedTime float32) {
|
|||||||
C.CPxScene_simulate(s.cS, C.float(elapsedTime))
|
C.CPxScene_simulate(s.cS, C.float(elapsedTime))
|
||||||
}
|
}
|
||||||
|
|
||||||
// void CPxScene_advance(CSTRUCT CPxScene*);
|
|
||||||
|
|
||||||
func (s *Scene) Collide(elapsedTime float32) {
|
func (s *Scene) Collide(elapsedTime float32) {
|
||||||
C.CPxScene_collide(s.cS, C.float(elapsedTime))
|
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)
|
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 {
|
func CreateExclusiveShape(rigidActor RigidActor, geom *Geometry, mat *Material, shapeFlags ShapeFlags) Shape {
|
||||||
return Shape{
|
return Shape{
|
||||||
cShape: C.createExclusiveShape(rigidActor.cRa, geom.cG, mat.cM, uint32(shapeFlags)),
|
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)
|
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 {
|
func NewSceneDesc(ts *TolerancesScale) *SceneDesc {
|
||||||
return &SceneDesc{
|
return &SceneDesc{
|
||||||
cSD: C.NewCPxSceneDesc(ts.cTolScale),
|
cSD: C.NewCPxSceneDesc(ts.cTolScale),
|
||||||
|
|||||||
@ -13,14 +13,17 @@ extern "C" {
|
|||||||
void* obj;
|
void* obj;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef void (*CPxonContactCallback)(void* pairHeader);
|
||||||
|
|
||||||
/// <summary>
|
/// <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>
|
/// </summary>
|
||||||
/// <param name="CPxTolerancesScale"></param>
|
/// <param name="CPxTolerancesScale"></param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
CPxAPI CSTRUCT CPxSceneDesc* NewCPxSceneDesc(CSTRUCT CPxTolerancesScale);
|
CPxAPI CSTRUCT CPxSceneDesc* NewCPxSceneDesc(CSTRUCT CPxTolerancesScale);
|
||||||
CPxAPI void CPxSceneDesc_set_gravity(CSTRUCT CPxSceneDesc*, CSTRUCT CPxVec3);
|
CPxAPI void CPxSceneDesc_set_gravity(CSTRUCT CPxSceneDesc*, CSTRUCT CPxVec3);
|
||||||
CPxAPI void CPxSceneDesc_set_cpuDispatcher(CSTRUCT CPxSceneDesc*, CSTRUCT CPxCpuDispatcher*);
|
CPxAPI void CPxSceneDesc_set_cpuDispatcher(CSTRUCT CPxSceneDesc*, CSTRUCT CPxCpuDispatcher*);
|
||||||
|
CPxAPI void CPxSceneDesc_set_onContactCallback(CSTRUCT CPxSceneDesc*, CPxonContactCallback cb);
|
||||||
CPxAPI void FreeCPxSceneDesc(CSTRUCT CPxSceneDesc*);
|
CPxAPI void FreeCPxSceneDesc(CSTRUCT CPxSceneDesc*);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
|||||||
Reference in New Issue
Block a user