mirror of
https://github.com/bloeys/physx-go.git
synced 2025-12-29 07:58:20 +00:00
Support pvd being null in CreatePhysics
This commit is contained in:
30
main.go
30
main.go
@ -39,10 +39,10 @@ func main() {
|
|||||||
sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, 0).ToCpuDispatcher())
|
sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, 0).ToCpuDispatcher())
|
||||||
sd.SetOnContactCallback(contactHandler)
|
sd.SetOnContactCallback(contactHandler)
|
||||||
|
|
||||||
s := p.CreateScene(sd)
|
scene := p.CreateScene(sd)
|
||||||
println("Scene:", s)
|
println("Scene:", scene)
|
||||||
|
|
||||||
scenePvdClient := s.GetScenePvdClient()
|
scenePvdClient := scene.GetScenePvdClient()
|
||||||
println("ScenePvdClient:", scenePvdClient)
|
println("ScenePvdClient:", scenePvdClient)
|
||||||
|
|
||||||
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_CONSTRAINTS, true)
|
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_CONSTRAINTS, true)
|
||||||
@ -52,7 +52,7 @@ func main() {
|
|||||||
//Add plane
|
//Add plane
|
||||||
pMat := p.CreateMaterial(0.5, 0.5, 0.6)
|
pMat := p.CreateMaterial(0.5, 0.5, 0.6)
|
||||||
groundPlane := pgo.CreatePlane(p, pgo.NewPlane(0, 1, 0, 0), pMat)
|
groundPlane := pgo.CreatePlane(p, pgo.NewPlane(0, 1, 0, 0), pMat)
|
||||||
s.AddActor(groundPlane.ToActor())
|
scene.AddActor(groundPlane.ToActor())
|
||||||
|
|
||||||
//W0/W1 are filter groups the shape belongs to, and W2/W3 are a filter group mask
|
//W0/W1 are filter groups the shape belongs to, and W2/W3 are a filter group mask
|
||||||
fd := pgo.NewFilterData(1, 1, 1, 1)
|
fd := pgo.NewFilterData(1, 1, 1, 1)
|
||||||
@ -70,7 +70,7 @@ func main() {
|
|||||||
|
|
||||||
ra := dynBox.ToRigidActor()
|
ra := dynBox.ToRigidActor()
|
||||||
ra.SetSimFilterData(&fd)
|
ra.SetSimFilterData(&fd)
|
||||||
s.AddActor(dynBox.ToActor())
|
scene.AddActor(dynBox.ToActor())
|
||||||
|
|
||||||
//Add box2
|
//Add box2
|
||||||
v = pgo.NewVec3(0.5, 12, 0)
|
v = pgo.NewVec3(0.5, 12, 0)
|
||||||
@ -79,7 +79,7 @@ func main() {
|
|||||||
|
|
||||||
ra = dynBox2.ToRigidActor()
|
ra = dynBox2.ToRigidActor()
|
||||||
ra.SetSimFilterData(&fd)
|
ra.SetSimFilterData(&fd)
|
||||||
s.AddActor(dynBox2.ToActor())
|
scene.AddActor(dynBox2.ToActor())
|
||||||
|
|
||||||
//Add sphere
|
//Add sphere
|
||||||
v = pgo.NewVec3(0, 16, 0)
|
v = pgo.NewVec3(0, 16, 0)
|
||||||
@ -88,7 +88,7 @@ func main() {
|
|||||||
|
|
||||||
ra = dynSphere.ToRigidActor()
|
ra = dynSphere.ToRigidActor()
|
||||||
ra.SetSimFilterData(&fd)
|
ra.SetSimFilterData(&fd)
|
||||||
s.AddActor(dynSphere.ToActor())
|
scene.AddActor(dynSphere.ToActor())
|
||||||
|
|
||||||
//Add capsule
|
//Add capsule
|
||||||
v = pgo.NewVec3(0, 20, 0)
|
v = pgo.NewVec3(0, 20, 0)
|
||||||
@ -96,7 +96,7 @@ func main() {
|
|||||||
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 = dynCapsule.ToRigidActor()
|
||||||
ra.SetSimFilterData(&fd)
|
ra.SetSimFilterData(&fd)
|
||||||
s.AddActor(dynCapsule.ToActor())
|
scene.AddActor(dynCapsule.ToActor())
|
||||||
|
|
||||||
//Add compound shape
|
//Add compound shape
|
||||||
dynComp := p.CreateRigidDynamic(pgo.NewTransform(pgo.NewVec3(2.5, 35, 0), qID))
|
dynComp := p.CreateRigidDynamic(pgo.NewTransform(pgo.NewVec3(2.5, 35, 0), qID))
|
||||||
@ -111,7 +111,7 @@ func main() {
|
|||||||
|
|
||||||
ra = dynComp.ToRigidActor()
|
ra = dynComp.ToRigidActor()
|
||||||
ra.SetSimFilterData(&fd)
|
ra.SetSimFilterData(&fd)
|
||||||
s.AddActor(dynComp.ToActor())
|
scene.AddActor(dynComp.ToActor())
|
||||||
|
|
||||||
//Make some changes and print info
|
//Make some changes and print info
|
||||||
dynSphere.SetMass(1)
|
dynSphere.SetMass(1)
|
||||||
@ -130,14 +130,14 @@ func main() {
|
|||||||
raycastBuffer := pgo.NewRaycastBuffer(1)
|
raycastBuffer := pgo.NewRaycastBuffer(1)
|
||||||
defer raycastBuffer.Release()
|
defer raycastBuffer.Release()
|
||||||
|
|
||||||
s.SetScratchBuffer(4)
|
scene.SetScratchBuffer(4)
|
||||||
for {
|
for {
|
||||||
s.Collide(1 / 50.0)
|
scene.Collide(1 / 50.0)
|
||||||
s.FetchCollision(true)
|
scene.FetchCollision(true)
|
||||||
s.Advance()
|
scene.Advance()
|
||||||
s.FetchResults(true)
|
scene.FetchResults(true)
|
||||||
|
|
||||||
s.RaycastWithHitBuffer(pgo.NewVec3(0, 0, 0), pgo.NewVec3(0, 1, 0), 9, raycastBuffer, 1)
|
scene.RaycastWithHitBuffer(pgo.NewVec3(0, 0, 0), pgo.NewVec3(0, 1, 0), 9, raycastBuffer, 1)
|
||||||
if raycastBuffer.HasBlock() {
|
if raycastBuffer.HasBlock() {
|
||||||
block := raycastBuffer.GetBlock()
|
block := raycastBuffer.GetBlock()
|
||||||
d := block.GetDistance()
|
d := block.GetDistance()
|
||||||
|
|||||||
10
pgo/pgo.go
10
pgo/pgo.go
@ -270,7 +270,11 @@ func (p *Physics) Release() {
|
|||||||
func CreatePhysics(f *Foundation, ts *TolerancesScale, trackOutstandingAllocations bool, pvd *Pvd) *Physics {
|
func CreatePhysics(f *Foundation, ts *TolerancesScale, trackOutstandingAllocations bool, pvd *Pvd) *Physics {
|
||||||
|
|
||||||
p := &Physics{}
|
p := &Physics{}
|
||||||
p.cPhysics = C.CPxCreatePhysics(f.cFoundation, ts.cTolScale, C._Bool(trackOutstandingAllocations), pvd.cPvd)
|
if pvd != nil {
|
||||||
|
p.cPhysics = C.CPxCreatePhysics(f.cFoundation, ts.cTolScale, C._Bool(trackOutstandingAllocations), pvd.cPvd)
|
||||||
|
} else {
|
||||||
|
p.cPhysics = C.CPxCreatePhysics(f.cFoundation, ts.cTolScale, C._Bool(trackOutstandingAllocations), nil)
|
||||||
|
}
|
||||||
|
|
||||||
return p
|
return p
|
||||||
}
|
}
|
||||||
@ -376,8 +380,8 @@ func (sd *SceneDesc) SetCpuDispatcher(cd *CpuDispatcher) {
|
|||||||
C.CPxSceneDesc_set_cpuDispatcher(&sd.cSD, cd.cCpuDisp)
|
C.CPxSceneDesc_set_cpuDispatcher(&sd.cSD, cd.cCpuDisp)
|
||||||
}
|
}
|
||||||
|
|
||||||
//SetOnContactCallback sets the GLOBAL contact callback handler. Physx-c currently only supports 1 contact callback handler.
|
// SetOnContactCallback sets the GLOBAL contact callback handler. Physx-c currently only supports 1 contact callback handler.
|
||||||
//Setting a contact callback handler overrides the previous one. Only the most recent one gets called.
|
// Setting a contact callback handler overrides the previous one. Only the most recent one gets called.
|
||||||
func (sd *SceneDesc) SetOnContactCallback(cb func(ContactPairHeader)) {
|
func (sd *SceneDesc) SetOnContactCallback(cb func(ContactPairHeader)) {
|
||||||
contactCallback = cb
|
contactCallback = cb
|
||||||
C.CPxSceneDesc_set_onContactCallback(&sd.cSD, (C.CPxonContactCallback)(unsafe.Pointer(C.goOnContactCallback_cgo)))
|
C.CPxSceneDesc_set_onContactCallback(&sd.cSD, (C.CPxonContactCallback)(unsafe.Pointer(C.goOnContactCallback_cgo)))
|
||||||
|
|||||||
Reference in New Issue
Block a user