mirror of
https://github.com/bloeys/physx-go.git
synced 2025-12-29 16:08:20 +00:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 96c55ad30d | |||
| dd5a42c760 | |||
| ceabe5d59b | |||
| 7e63090cb1 | |||
| 8e358fb31f |
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=
|
||||
|
||||
34
main.go
34
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,19 +40,21 @@ 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)
|
||||
|
||||
scene := p.CreateScene(sd)
|
||||
println("Scene:", scene)
|
||||
|
||||
scenePvdClient := scene.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.Release()
|
||||
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)
|
||||
@ -149,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.
25
pgo/pgo.go
25
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
|
||||
@ -362,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]),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -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