mirror of
https://github.com/bloeys/physx-go.git
synced 2025-12-29 16:08:20 +00:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 96c55ad30d | |||
| dd5a42c760 | |||
| ceabe5d59b | |||
| 7e63090cb1 | |||
| 8e358fb31f | |||
| 6880bac72a | |||
| 66d8f247f1 |
4
go.mod
4
go.mod
@ -1,5 +1,5 @@
|
||||
module github.com/bloeys/physx-go
|
||||
|
||||
go 1.17
|
||||
go 1.18
|
||||
|
||||
require github.com/bloeys/gglm v0.3.1
|
||||
require github.com/bloeys/gglm v0.43.0
|
||||
|
||||
2
go.sum
2
go.sum
@ -1,2 +1,4 @@
|
||||
github.com/bloeys/gglm v0.3.1 h1:Sy9upW7SBsBfDXrSmEhid3aQ+7J7itej+upwcxOnPMQ=
|
||||
github.com/bloeys/gglm v0.3.1/go.mod h1:qwJQ0WzV191wAMwlGicbfbChbKoSedMk7gFFX6GnyOk=
|
||||
github.com/bloeys/gglm v0.43.0 h1:ZpOghR3PHfpkigTDh+FqxLsF0gN8CD6s/bWoei6LyxI=
|
||||
github.com/bloeys/gglm v0.43.0/go.mod h1:qwJQ0WzV191wAMwlGicbfbChbKoSedMk7gFFX6GnyOk=
|
||||
|
||||
61
main.go
61
main.go
@ -20,15 +20,19 @@ func contactHandler(cph pgo.ContactPairHeader) {
|
||||
}
|
||||
|
||||
func main() {
|
||||
|
||||
f := pgo.CreateFoundation()
|
||||
println("foundation:", f)
|
||||
|
||||
pvdTr := pgo.DefaultPvdSocketTransportCreate("127.0.0.1", 5425, 100000)
|
||||
println("Pvd transport:", pvdTr)
|
||||
var pvd *pgo.Pvd
|
||||
if pgo.PvdSupported {
|
||||
pvdTr := pgo.DefaultPvdSocketTransportCreate("127.0.0.1", 5425, 100000)
|
||||
println("Pvd transport:", pvdTr)
|
||||
|
||||
pvd := pgo.CreatePvd(f)
|
||||
println("Pvd:", pvd)
|
||||
println("connected to PVD:", pvd.Connect(pvdTr, pgo.PvdInstrumentationFlag_eALL))
|
||||
pvd = pgo.CreatePvd(f)
|
||||
println("Pvd:", pvd)
|
||||
println("connected to PVD:", pvd.Connect(pvdTr, pgo.PvdInstrumentationFlag_eALL))
|
||||
}
|
||||
|
||||
ts := pgo.NewTolerancesScale(1, 9.81)
|
||||
p := pgo.CreatePhysics(f, ts, false, pvd)
|
||||
@ -36,23 +40,26 @@ 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()
|
||||
println("ScenePvdClient:", scenePvdClient)
|
||||
if pgo.PvdSupported {
|
||||
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.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 +77,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 +86,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 +95,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 +103,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 +118,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 +137,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()
|
||||
@ -148,8 +155,4 @@ func main() {
|
||||
// println("Press enter...")
|
||||
// r.ReadBytes('\n')
|
||||
}
|
||||
|
||||
// p.Release()
|
||||
// pvd.Release()
|
||||
// pvdTr.Release()
|
||||
}
|
||||
|
||||
5
pgo/consts_checked.go
Executable file
5
pgo/consts_checked.go
Executable file
@ -0,0 +1,5 @@
|
||||
//go:build !physx_release
|
||||
|
||||
package pgo
|
||||
|
||||
const PvdSupported = true
|
||||
5
pgo/consts_release.go
Executable file
5
pgo/consts_release.go
Executable file
@ -0,0 +1,5 @@
|
||||
//go:build physx_release
|
||||
|
||||
package pgo
|
||||
|
||||
const PvdSupported = false
|
||||
Binary file not shown.
BIN
pgo/libs/libphysxc_release_windows_amd64.a
Executable file
BIN
pgo/libs/libphysxc_release_windows_amd64.a
Executable file
Binary file not shown.
39
pgo/pgo.go
39
pgo/pgo.go
@ -2,7 +2,11 @@ package pgo
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -I physx-c
|
||||
#cgo LDFLAGS: -L ./libs -l physx-c
|
||||
#cgo LDFLAGS: -L ./libs
|
||||
|
||||
// NOTE: If you change this update rigiddynamic.go as well
|
||||
#cgo windows,amd64 LDFLAGS: -l physxc_checked_windows_amd64
|
||||
#cgo windows,amd64,physx_release LDFLAGS: -l physxc_release_windows_amd64
|
||||
|
||||
#include <wrap.c>
|
||||
#include <stdlib.h> //Needed for C.free
|
||||
@ -270,7 +274,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 +366,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 +399,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 +529,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);
|
||||
|
||||
|
||||
@ -2,7 +2,11 @@ package pgo
|
||||
|
||||
/*
|
||||
#cgo CFLAGS: -I physx-c
|
||||
#cgo LDFLAGS: -L ./libs -l physx-c
|
||||
#cgo LDFLAGS: -L ./libs
|
||||
|
||||
// NOTE: If you change this update pgo.go as well
|
||||
#cgo windows,amd64 LDFLAGS: -l physxc_checked_windows_amd64
|
||||
#cgo windows,amd64,physx_release LDFLAGS: -l physxc_release_windows_amd64
|
||||
|
||||
#include <wrap.c>
|
||||
#include <stdlib.h> //Needed for C.free
|
||||
|
||||
Reference in New Issue
Block a user