mirror of
https://github.com/bloeys/physx-go.git
synced 2025-12-29 16:08:20 +00:00
Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8e358fb31f | |||
| 6880bac72a | |||
| 66d8f247f1 |
33
main.go
33
main.go
@ -36,23 +36,24 @@ func main() {
|
||||
|
||||
sd := pgo.NewSceneDesc(ts)
|
||||
sd.SetGravity(pgo.NewVec3(0, -9.8, 0))
|
||||
sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, 0).ToCpuDispatcher())
|
||||
sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, nil).ToCpuDispatcher())
|
||||
sd.SetOnContactCallback(contactHandler)
|
||||
|
||||
s := p.CreateScene(sd)
|
||||
println("Scene:", s)
|
||||
scene := p.CreateScene(sd)
|
||||
println("Scene:", scene)
|
||||
|
||||
scenePvdClient := s.GetScenePvdClient()
|
||||
scenePvdClient := scene.GetScenePvdClient()
|
||||
println("ScenePvdClient:", scenePvdClient)
|
||||
|
||||
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_CONSTRAINTS, true)
|
||||
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_CONTACTS, true)
|
||||
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_SCENEQUERIES, true)
|
||||
scenePvdClient.Release()
|
||||
|
||||
//Add plane
|
||||
pMat := p.CreateMaterial(0.5, 0.5, 0.6)
|
||||
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
|
||||
fd := pgo.NewFilterData(1, 1, 1, 1)
|
||||
@ -70,7 +71,7 @@ func main() {
|
||||
|
||||
ra := dynBox.ToRigidActor()
|
||||
ra.SetSimFilterData(&fd)
|
||||
s.AddActor(dynBox.ToActor())
|
||||
scene.AddActor(dynBox.ToActor())
|
||||
|
||||
//Add box2
|
||||
v = pgo.NewVec3(0.5, 12, 0)
|
||||
@ -79,7 +80,7 @@ func main() {
|
||||
|
||||
ra = dynBox2.ToRigidActor()
|
||||
ra.SetSimFilterData(&fd)
|
||||
s.AddActor(dynBox2.ToActor())
|
||||
scene.AddActor(dynBox2.ToActor())
|
||||
|
||||
//Add sphere
|
||||
v = pgo.NewVec3(0, 16, 0)
|
||||
@ -88,7 +89,7 @@ func main() {
|
||||
|
||||
ra = dynSphere.ToRigidActor()
|
||||
ra.SetSimFilterData(&fd)
|
||||
s.AddActor(dynSphere.ToActor())
|
||||
scene.AddActor(dynSphere.ToActor())
|
||||
|
||||
//Add capsule
|
||||
v = pgo.NewVec3(0, 20, 0)
|
||||
@ -96,7 +97,7 @@ func main() {
|
||||
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())
|
||||
scene.AddActor(dynCapsule.ToActor())
|
||||
|
||||
//Add compound shape
|
||||
dynComp := p.CreateRigidDynamic(pgo.NewTransform(pgo.NewVec3(2.5, 35, 0), qID))
|
||||
@ -111,7 +112,7 @@ func main() {
|
||||
|
||||
ra = dynComp.ToRigidActor()
|
||||
ra.SetSimFilterData(&fd)
|
||||
s.AddActor(dynComp.ToActor())
|
||||
scene.AddActor(dynComp.ToActor())
|
||||
|
||||
//Make some changes and print info
|
||||
dynSphere.SetMass(1)
|
||||
@ -130,14 +131,14 @@ func main() {
|
||||
raycastBuffer := pgo.NewRaycastBuffer(1)
|
||||
defer raycastBuffer.Release()
|
||||
|
||||
s.SetScratchBuffer(4)
|
||||
scene.SetScratchBuffer(4)
|
||||
for {
|
||||
s.Collide(1 / 50.0)
|
||||
s.FetchCollision(true)
|
||||
s.Advance()
|
||||
s.FetchResults(true)
|
||||
scene.Collide(1 / 50.0)
|
||||
scene.FetchCollision(true)
|
||||
scene.Advance()
|
||||
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() {
|
||||
block := raycastBuffer.GetBlock()
|
||||
d := block.GetDistance()
|
||||
|
||||
Binary file not shown.
33
pgo/pgo.go
33
pgo/pgo.go
@ -270,7 +270,11 @@ func (p *Physics) Release() {
|
||||
func CreatePhysics(f *Foundation, ts *TolerancesScale, trackOutstandingAllocations bool, pvd *Pvd) *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
|
||||
}
|
||||
@ -358,9 +362,24 @@ func (d *DefaultCpuDispatcher) ToCpuDispatcher() *CpuDispatcher {
|
||||
return &CpuDispatcher{cCpuDisp: (*C.struct_CPxCpuDispatcher)(d.cDefCpuDisp)}
|
||||
}
|
||||
|
||||
func DefaultCpuDispatcherCreate(numThreads, affinityMasks uint32) *DefaultCpuDispatcher {
|
||||
// DefaultCpuDispatcherCreate sets the number of threads used by physX.
|
||||
// If affinityMasksPerThread is nil/zero then default masks are used, otherwise the size of the array
|
||||
// must match the number of threads
|
||||
func DefaultCpuDispatcherCreate(numThreads uint32, affinityMasksPerThread []uint32) *DefaultCpuDispatcher {
|
||||
|
||||
if len(affinityMasksPerThread) == 0 {
|
||||
return &DefaultCpuDispatcher{
|
||||
cDefCpuDisp: C.CPxDefaultCpuDispatcherCreate(C.uint(numThreads), nil),
|
||||
}
|
||||
}
|
||||
|
||||
arr := make([]C.uint, len(affinityMasksPerThread))
|
||||
for i := 0; i < len(arr); i++ {
|
||||
arr[i] = C.uint(affinityMasksPerThread[i])
|
||||
}
|
||||
|
||||
return &DefaultCpuDispatcher{
|
||||
cDefCpuDisp: C.CPxDefaultCpuDispatcherCreate(C.uint(numThreads), C.uint(affinityMasks)),
|
||||
cDefCpuDisp: C.CPxDefaultCpuDispatcherCreate(C.uint(numThreads), &arr[0]),
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,8 +395,8 @@ func (sd *SceneDesc) SetCpuDispatcher(cd *CpuDispatcher) {
|
||||
C.CPxSceneDesc_set_cpuDispatcher(&sd.cSD, cd.cCpuDisp)
|
||||
}
|
||||
|
||||
//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.
|
||||
// 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.
|
||||
func (sd *SceneDesc) SetOnContactCallback(cb func(ContactPairHeader)) {
|
||||
contactCallback = cb
|
||||
C.CPxSceneDesc_set_onContactCallback(&sd.cSD, (C.CPxonContactCallback)(unsafe.Pointer(C.goOnContactCallback_cgo)))
|
||||
@ -506,6 +525,10 @@ func (p *PvdSceneClient) SetScenePvdFlag(flag PvdSceneFlag, value bool) {
|
||||
C.CPxPvdSceneClient_setScenePvdFlag(p.cPvdSceneClient, uint32(flag), C._Bool(value))
|
||||
}
|
||||
|
||||
func (p *PvdSceneClient) Release() {
|
||||
C.CPxPvdSceneClient_release(p.cPvdSceneClient)
|
||||
}
|
||||
|
||||
type Material struct {
|
||||
cM *C.struct_CPxMaterial
|
||||
}
|
||||
|
||||
@ -11,7 +11,7 @@ extern "C" {
|
||||
void* obj;
|
||||
};
|
||||
|
||||
CPxAPI CSTRUCT CPxDefaultCpuDispatcher* CPxDefaultCpuDispatcherCreate(CPxU32 numThreads, CPxU32 affinityMasks);
|
||||
CPxAPI CSTRUCT CPxDefaultCpuDispatcher* CPxDefaultCpuDispatcherCreate(CPxU32 numThreads, CPxU32* affinityMasks);
|
||||
CPxAPI CSTRUCT CPxCpuDispatcher* CPxDefaultCpuDispatcher_toCPxCpuDispatcher(CSTRUCT CPxDefaultCpuDispatcher* cdcd);
|
||||
CPxAPI void CPxDefaultCpuDispatcher_release(CSTRUCT CPxDefaultCpuDispatcher* cdcd);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user