11 Commits
v0.1.2 ... dev

Author SHA1 Message Date
07bf698c2c Implement onTrigger callbacks 2023-10-10 10:58:49 +04:00
c740204bd5 Wrap more rigiddynamic funcs 2023-10-10 03:43:00 +04:00
8c12404511 Fix bug in create dynamic 2023-10-09 09:27:06 +04:00
fdb8fbbccf Implement transform get/set functions 2023-10-09 07:19:09 +04:00
3d0a4f977b Comments and ClearUserData 2023-10-05 14:34:42 +04:00
5a55870493 Add funcs to set/get rigid actor user data 2023-10-05 13:25:48 +04:00
a01e4b6bbd Switch to mostly returning objects instead of pointers since
almost all objects contain only one pointer inside, making them
very small, so no point paying (de)allocation costs.

This has also been done to physx-c
2022-12-19 00:43:04 +04:00
96c55ad30d Add flag to say if pvd is supported 2022-12-07 06:38:33 +04:00
dd5a42c760 Support both checked and release modes 2022-12-07 06:34:13 +04:00
ceabe5d59b Flag to disable pvd 2022-12-07 06:06:49 +04:00
7e63090cb1 Move to go 1.18 2022-12-07 03:24:25 +04:00
38 changed files with 792 additions and 438 deletions

4
go.mod
View File

@ -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
View File

@ -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=

85
main.go
View File

@ -2,53 +2,65 @@ package main
import (
"fmt"
"unsafe"
"github.com/bloeys/physx-go/pgo"
)
func contactHandler(cph pgo.ContactPairHeader) {
// ra1 := cph.GetRigidActors()[0]
// ra2 := cph.GetRigidActors()[1]
// fmt.Printf("Collision! User data 1: %v; User data 2: %v\n", ra1.GetUserData(), ra2.GetUserData())
// pairs := cph.GetPairs()
// for i := 0; i < len(pairs); i++ {
// points := pairs[i].GetContactPoints()
// for j := 0; j < pairs[i].GetContactPointCount(); j++ {
// pos := points[j].GetPos()
// println("Contact at pos:", pos.String())
// fmt.Println("Contact at pos:", pos.String())
// }
// }
}
func main() {
f := pgo.CreateFoundation()
println("foundation:", f)
fmt.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)
fmt.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)
fmt.Println("Pvd:", pvd)
fmt.Println("connected to PVD:", pvd.Connect(pvdTr, pgo.PvdInstrumentationFlag_eALL))
}
ts := pgo.NewTolerancesScale(1, 9.81)
p := pgo.CreatePhysics(f, ts, false, pvd)
println("Physics:", p)
fmt.Println("Physics:", p)
sd := pgo.NewSceneDesc(ts)
sd.SetGravity(pgo.NewVec3(0, -9.8, 0))
sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, nil).ToCpuDispatcher())
defaultCpuDispatcher := pgo.DefaultCpuDispatcherCreate(2, nil)
sd.SetCpuDispatcher(defaultCpuDispatcher.ToCpuDispatcher())
sd.SetOnContactCallback(contactHandler)
scene := p.CreateScene(sd)
println("Scene:", scene)
fmt.Println("Scene:", scene)
scenePvdClient := scene.GetScenePvdClient()
println("ScenePvdClient:", scenePvdClient)
if pgo.PvdSupported {
scenePvdClient := scene.GetScenePvdClient()
fmt.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)
}
//Add plane
pMat := p.CreateMaterial(0.5, 0.5, 0.6)
@ -117,20 +129,35 @@ func main() {
//Make some changes and print info
dynSphere.SetMass(1)
dynCapsule.SetMass(1)
println("Box 1 mass:", dynBox.GetMass())
println("Box 2 mass:", dynBox2.GetMass())
println("Sphere mass:", dynSphere.GetMass())
println("Capsule mass:", dynCapsule.GetMass())
fmt.Println("Box 1 mass:", dynBox.GetMass())
fmt.Println("Box 2 mass:", dynBox2.GetMass())
fmt.Println("Sphere mass:", dynSphere.GetMass())
fmt.Println("Capsule mass:", dynCapsule.GetMass())
println("Capsule linear damping A:", dynCapsule.GetLinearDamping())
fmt.Println("Capsule linear damping A:", dynCapsule.GetLinearDamping())
dynCapsule.SetLinearDamping(0.05)
println("Capsule linear damping B:", dynCapsule.GetLinearDamping())
fmt.Println("Capsule linear damping B:", dynCapsule.GetLinearDamping())
//Run simulation
// r := bufio.NewReader(os.Stdin)
raycastBuffer := pgo.NewRaycastBuffer(1)
defer raycastBuffer.Release()
// Example of correct usage of user data
x := new(int64)
*x = 1095
ra.SetUserData(unsafe.Pointer(x))
z := (*int64)(ra.GetUserData())
fmt.Println("User data:", *z)
// The rigid actor might get garbage collected after this point (as its no longer used), but that will now cause
// a memory leak and a crash since the user data got pinned (i.e. GC will not move or free it) when we used SetUserData above, but can no longer be unpinned as the runtime.Pinner object will get garbage collected with the rigid actor.
//
// To solve this we have 2 options:
// 1. The pinner is unpinned before it is garbage collected by calling ClearUserData
// 2. The object holding the active pinner (the rigid actor on which SetUserData was used) must remain alive (e.g. by pinning it, putting it in file scope, in a long lived object etc)
ra.ClearUserData()
scene.SetScratchBuffer(4)
for {
scene.Collide(1 / 50.0)
@ -140,17 +167,13 @@ func main() {
scene.RaycastWithHitBuffer(pgo.NewVec3(0, 0, 0), pgo.NewVec3(0, 1, 0), 9, raycastBuffer, 1)
if raycastBuffer.HasBlock() {
block := raycastBuffer.GetBlock()
d := block.GetDistance()
pos := block.GetPos()
fmt.Printf("Raycast hit at dist (%v) and post %v\n", d, pos.String())
// block := raycastBuffer.GetBlock()
// d := block.GetDistance()
// pos := block.GetPos()
// fmt.Printf("Raycast hit at dist (%v) and post %v\n", d, pos.String())
}
// fmt.Printf("\nRaycast hit: %v\n", rHit)
// println("Press enter...")
// fmt.Println("Press enter...")
// r.ReadBytes('\n')
}
// p.Release()
// pvd.Release()
// pvdTr.Release()
}

26
pgo/callbackExports.go Executable file
View File

@ -0,0 +1,26 @@
package pgo
/*
#include "wrap.c"
*/
import "C"
import "unsafe"
//export goOnContactCallback
func goOnContactCallback(p unsafe.Pointer) {
contactCallback(ContactPairHeader{cCPH: (*C.struct_CPxContactPairHeader)(p)})
}
//export goOnTriggerCallback
func goOnTriggerCallback(p unsafe.Pointer, count uint32) {
// @PERF
triggerPairs := make([]TriggerPair, count)
tPairs := unsafe.Slice((*C.struct_CPxTriggerPair)(p), count)
for i := 0; i < len(triggerPairs); i++ {
triggerPairs[i].cTp = &tPairs[i]
}
triggerCallback(triggerPairs)
}

View File

@ -1,10 +1,18 @@
package pgo
/*
#include <stdint.h> // Needed for uint32_t
void goOnContactCallback_cgo(void* pairHeader)
{
void goOnContactCallback(void*);
goOnContactCallback(pairHeader);
}
void goOnTriggerCallback_cgo(void* triggerPairs, uint32_t count)
{
void goOnTriggerCallback(void*, uint32_t);
goOnTriggerCallback(triggerPairs, count);
}
*/
import "C"

5
pgo/consts_checked.go Executable file
View File

@ -0,0 +1,5 @@
//go:build !physx_release
package pgo
const PvdSupported = true

5
pgo/consts_release.go Executable file
View File

@ -0,0 +1,5 @@
//go:build physx_release
package pgo
const PvdSupported = false

View File

@ -1,12 +0,0 @@
package pgo
/*
#include "wrap.c"
*/
import "C"
import "unsafe"
//export goOnContactCallback
func goOnContactCallback(p unsafe.Pointer) {
contactCallback(ContactPairHeader{cCPH: (*C.struct_CPxContactPairHeader)(p)})
}

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -2,16 +2,22 @@ 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
//simulation event callbacks forward declarations. Actual definitions MUST be in a go different file
void goOnContactCallback_cgo(void* pairHeader);
void goOnTriggerCallback_cgo(void* triggerPairs, CPxU32 count);
*/
import "C"
import (
"runtime"
"unsafe"
"github.com/bloeys/gglm/gglm"
@ -19,29 +25,30 @@ import (
var (
contactCallback func(ContactPairHeader) = func(ContactPairHeader) {}
triggerCallback func([]TriggerPair) = func([]TriggerPair) {}
)
type Foundation struct {
cFoundation *C.struct_CPxFoundation
cFoundation C.struct_CPxFoundation
}
func (f *Foundation) Release() {
C.CPxFoundation_release(f.cFoundation)
}
func CreateFoundation() *Foundation {
func CreateFoundation() Foundation {
f := &Foundation{}
f := Foundation{}
f.cFoundation = C.CPxCreateFoundation()
return f
}
type Pvd struct {
cPvd *C.struct_CPxPvd
cPvd C.struct_CPxPvd
}
func (p *Pvd) Connect(pvdTr *PvdTransport, instFlag PvdInstrumentationFlag) bool {
func (p *Pvd) Connect(pvdTr PvdTransport, instFlag PvdInstrumentationFlag) bool {
return bool(C.CPxPvd_connect(p.cPvd, pvdTr.cPvdTr, uint32(instFlag)))
}
@ -49,7 +56,7 @@ func (p *Pvd) Release() {
C.CPxPvd_release(p.cPvd)
}
func CreatePvd(f *Foundation) *Pvd {
func CreatePvd(f Foundation) *Pvd {
p := &Pvd{}
p.cPvd = C.CPxCreatePvd(f.cFoundation)
@ -58,17 +65,13 @@ func CreatePvd(f *Foundation) *Pvd {
}
type PvdTransport struct {
cPvdTr *C.struct_CPxPvdTransport
cPvdTr C.struct_CPxPvdTransport
}
func (p *PvdTransport) Release() {
C.CPxPvdTransport_release(p.cPvdTr)
}
func DefaultPvdSocketTransportCreate(host string, port, timeoutMillis int) *PvdTransport {
func DefaultPvdSocketTransportCreate(host string, port, timeoutMillis int) PvdTransport {
//This CString should NOT be freed because its stored internally. If this is freed connection to PVD will fail
p := &PvdTransport{}
p := PvdTransport{}
p.cPvdTr = C.CPxDefaultPvdSocketTransportCreate(C.CString(host), C.int(port), C.int(timeoutMillis))
return p
}
@ -77,8 +80,8 @@ type TolerancesScale struct {
cTolScale C.struct_CPxTolerancesScale
}
func NewTolerancesScale(length, speed float32) *TolerancesScale {
return &TolerancesScale{
func NewTolerancesScale(length, speed float32) TolerancesScale {
return TolerancesScale{
cTolScale: C.struct_CPxTolerancesScale{
length: C.float(length),
speed: C.float(speed),
@ -87,11 +90,11 @@ func NewTolerancesScale(length, speed float32) *TolerancesScale {
}
type Scene struct {
cS *C.struct_CPxScene
cS C.struct_CPxScene
}
func (s *Scene) GetScenePvdClient() *PvdSceneClient {
return &PvdSceneClient{
func (s *Scene) GetScenePvdClient() PvdSceneClient {
return PvdSceneClient{
cPvdSceneClient: C.CPxScene_getScenePvdClient(s.cS),
}
}
@ -135,7 +138,7 @@ func (s *Scene) Raycast(origin, unitDir *Vec3, distance float32) (bool, RaycastB
return bool(ret), rb
}
func (s *Scene) RaycastWithHitBuffer(origin, unitDir *Vec3, distance float32, rb *RaycastBuffer, touchesToRead uint) bool {
func (s *Scene) RaycastWithHitBuffer(origin, unitDir *Vec3, distance float32, rb RaycastBuffer, touchesToRead uint) bool {
ret := C.CPxScene_raycastWithHitBuffer(s.cS, &origin.cV, &unitDir.cV, C.float(distance), rb.cRb, C.uint(touchesToRead))
return bool(ret)
@ -174,9 +177,9 @@ func (rb *RaycastBuffer) Release() {
C.CPxRaycastBuffer_release(rb.cRb)
}
func NewRaycastBuffer(maxTouches uint32) *RaycastBuffer {
func NewRaycastBuffer(maxTouches uint32) RaycastBuffer {
rb := &RaycastBuffer{
rb := RaycastBuffer{
cRb: C.NewCPxRaycastBufferWithAlloc(C.uint(maxTouches)),
}
@ -236,29 +239,29 @@ func (rh *RaycastHit) GetUV() (float32, float32) {
}
type Physics struct {
cPhysics *C.struct_CPxPhysics
cPhysics C.struct_CPxPhysics
}
func (p *Physics) CreateScene(sd *SceneDesc) *Scene {
return &Scene{
cS: C.CPxPhysics_createScene(p.cPhysics, &sd.cSD),
func (p *Physics) CreateScene(sd SceneDesc) Scene {
return Scene{
cS: C.CPxPhysics_createScene(p.cPhysics, sd.cSD),
}
}
func (p *Physics) CreateMaterial(staticFriction, dynamicFriction, restitution float32) *Material {
return &Material{
func (p *Physics) CreateMaterial(staticFriction, dynamicFriction, restitution float32) Material {
return Material{
cM: C.CPxPhysics_createMaterial(p.cPhysics, C.float(staticFriction), C.float(dynamicFriction), C.float(restitution)),
}
}
func (p *Physics) CreateRigidDynamic(tr *Transform) *RigidDynamic {
return &RigidDynamic{
func (p *Physics) CreateRigidDynamic(tr *Transform) RigidDynamic {
return RigidDynamic{
cRd: C.CPxPhysics_createRigidDynamic(p.cPhysics, &tr.cT),
}
}
func (p *Physics) CreateRigidStatic(tr *Transform) *RigidStatic {
return &RigidStatic{
func (p *Physics) CreateRigidStatic(tr *Transform) RigidStatic {
return RigidStatic{
cRs: C.CPxPhysics_createRigidStatic(p.cPhysics, &tr.cT),
}
}
@ -267,11 +270,11 @@ func (p *Physics) Release() {
C.CPxPhysics_release(p.cPhysics)
}
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{}
if pvd != nil {
p.cPhysics = C.CPxCreatePhysics(f.cFoundation, ts.cTolScale, C._Bool(trackOutstandingAllocations), pvd.cPvd)
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)
}
@ -300,25 +303,25 @@ type Shape struct {
func (s *Shape) GetLocalPose() *Transform {
return &Transform{
cT: C.CPxShape_getLocalPose(&s.cShape),
cT: C.CPxShape_getLocalPose(s.cShape),
}
}
func (s *Shape) SetLocalPose(tr *Transform) {
C.CPxShape_setLocalPose(&s.cShape, &tr.cT)
C.CPxShape_setLocalPose(s.cShape, &tr.cT)
}
func (s *Shape) GetSimulationFilterData() FilterData {
return FilterData{
cFilterData: C.CPxShape_getSimulationFilterData(&s.cShape),
cFilterData: C.CPxShape_getSimulationFilterData(s.cShape),
}
}
func (s *Shape) SetSimulationFilterData(fd *FilterData) {
C.CPxShape_setSimulationFilterData(&s.cShape, &fd.cFilterData)
C.CPxShape_setSimulationFilterData(s.cShape, &fd.cFilterData)
}
func CreateExclusiveShape(rigidActor RigidActor, geom *Geometry, mat *Material, shapeFlags ShapeFlags) Shape {
func CreateExclusiveShape(rigidActor RigidActor, geom Geometry, mat Material, shapeFlags ShapeFlags) Shape {
return Shape{
cShape: C.createExclusiveShape(rigidActor.cRa, geom.cG, mat.cM, uint32(shapeFlags)),
}
@ -351,24 +354,24 @@ func NewVec3(x, y, z float32) *Vec3 {
}
type CpuDispatcher struct {
cCpuDisp *C.struct_CPxCpuDispatcher
cCpuDisp C.struct_CPxCpuDispatcher
}
type DefaultCpuDispatcher struct {
cDefCpuDisp *C.struct_CPxDefaultCpuDispatcher
cDefCpuDisp C.struct_CPxDefaultCpuDispatcher
}
func (d *DefaultCpuDispatcher) ToCpuDispatcher() *CpuDispatcher {
return &CpuDispatcher{cCpuDisp: (*C.struct_CPxCpuDispatcher)(d.cDefCpuDisp)}
func (d *DefaultCpuDispatcher) ToCpuDispatcher() CpuDispatcher {
return CpuDispatcher{cCpuDisp: C.CPxDefaultCpuDispatcher_toCPxCpuDispatcher(d.cDefCpuDisp)}
}
// 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 {
func DefaultCpuDispatcherCreate(numThreads uint32, affinityMasksPerThread []uint32) DefaultCpuDispatcher {
if len(affinityMasksPerThread) == 0 {
return &DefaultCpuDispatcher{
return DefaultCpuDispatcher{
cDefCpuDisp: C.CPxDefaultCpuDispatcherCreate(C.uint(numThreads), nil),
}
}
@ -378,7 +381,7 @@ func DefaultCpuDispatcherCreate(numThreads uint32, affinityMasksPerThread []uint
arr[i] = C.uint(affinityMasksPerThread[i])
}
return &DefaultCpuDispatcher{
return DefaultCpuDispatcher{
cDefCpuDisp: C.CPxDefaultCpuDispatcherCreate(C.uint(numThreads), &arr[0]),
}
}
@ -388,22 +391,29 @@ type SceneDesc struct {
}
func (sd *SceneDesc) SetGravity(v *Vec3) {
C.CPxSceneDesc_set_gravity(&sd.cSD, v.cV)
C.CPxSceneDesc_set_gravity(sd.cSD, v.cV)
}
func (sd *SceneDesc) SetCpuDispatcher(cd *CpuDispatcher) {
C.CPxSceneDesc_set_cpuDispatcher(&sd.cSD, cd.cCpuDisp)
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.
// SetOnContactCallback sets the GLOBAL contact callback handler. We 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)))
C.CPxSceneDesc_set_onContactCallback(sd.cSD, (C.CPxOnContactCallback)(unsafe.Pointer(C.goOnContactCallback_cgo)))
}
func NewSceneDesc(ts *TolerancesScale) *SceneDesc {
return &SceneDesc{
// SetOnTriggerCallback sets the GLOBAL trigger callback handler. We currently only supports 1 trugger callback handler.
// Setting a handler overrides the previous one. Only the most recent one gets called.
func (sd *SceneDesc) SetOnTriggerCallback(cb func([]TriggerPair)) {
triggerCallback = cb
C.CPxSceneDesc_set_onTriggerCallback(sd.cSD, (C.CPxOnTriggerCallback)(unsafe.Pointer(C.goOnTriggerCallback_cgo)))
}
func NewSceneDesc(ts TolerancesScale) SceneDesc {
return SceneDesc{
cSD: C.NewCPxSceneDesc(ts.cTolScale),
}
}
@ -509,6 +519,42 @@ func (cpp *ContactPairPoint) GetInternalFaceIndices() (float32, float32) {
return float32(cpp.cCpp.internalFaceIndex0), float32(cpp.cCpp.internalFaceIndex1)
}
type TriggerPair struct {
cTp *C.struct_CPxTriggerPair
}
func (tp *TriggerPair) TriggerShape() Shape {
return Shape{
cShape: tp.cTp.triggerShape,
}
}
func (tp *TriggerPair) TriggerActor() RigidActor {
return RigidActor{
cRa: tp.cTp.triggerActor,
}
}
func (tp *TriggerPair) OtherShape() Shape {
return Shape{
cShape: tp.cTp.otherShape,
}
}
func (tp *TriggerPair) OtherActor() RigidActor {
return RigidActor{
cRa: tp.cTp.otherActor,
}
}
func (tp *TriggerPair) Status() PairFlags {
return PairFlags(tp.cTp.status)
}
func (tp *TriggerPair) Flags() TriggerPairFlag {
return TriggerPairFlag(tp.cTp.flags)
}
type PvdSceneFlag uint32
const (
@ -518,19 +564,15 @@ const (
)
type PvdSceneClient struct {
cPvdSceneClient *C.struct_CPxPvdSceneClient
cPvdSceneClient C.struct_CPxPvdSceneClient
}
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
cM C.struct_CPxMaterial
}
type Plane struct {
@ -548,7 +590,6 @@ type Quat struct {
cQ C.struct_CPxQuat
}
// CPxAPI CPxInline CSTRUCT CPxQuat NewCPxQuat(float angleRads, float x, float y, float z);
func NewQuat(angleRads, x, y, z float32) *Quat {
return &Quat{
cQ: C.NewCPxQuat(C.float(angleRads), C.float(x), C.float(y), C.float(z)),
@ -559,6 +600,50 @@ type Transform struct {
cT C.struct_CPxTransform
}
func (t *Transform) Pos() Vec3 {
return Vec3{cV: t.cT.p}
}
func (t *Transform) PosX() float32 {
return float32(t.cT.p.x)
}
func (t *Transform) PosY() float32 {
return float32(t.cT.p.y)
}
func (t *Transform) PosZ() float32 {
return float32(t.cT.p.z)
}
func (t *Transform) SetPos(v *Vec3) {
t.cT.p = v.cV
}
func (t *Transform) Rot() Quat {
return Quat{cQ: t.cT.q}
}
func (t *Transform) RotX() float32 {
return float32(t.cT.q.x)
}
func (t *Transform) RotY() float32 {
return float32(t.cT.q.y)
}
func (t *Transform) RotZ() float32 {
return float32(t.cT.q.z)
}
func (t *Transform) RotW() float32 {
return float32(t.cT.q.w)
}
func (t *Transform) SetRot(r *Quat) {
t.cT.q = r.cQ
}
// struct CPxTransform NewCPxTransform(struct CPxVec3*, struct CPxQuat*);
func NewTransform(v *Vec3, q *Quat) *Transform {
return &Transform{
@ -574,16 +659,24 @@ type SphereGeometry struct {
cSg C.struct_CPxSphereGeometry
}
func (sg *SphereGeometry) GetRadius() float32 {
return float32(sg.cSg.radius)
}
func (sg *SphereGeometry) SetRadius(r float32) {
sg.cSg.radius = C.float(r)
}
// struct CPxGeometry CPxSphereGeometry_toCPxGeometry(struct CPxSphereGeometry*);
func (sg *SphereGeometry) ToGeometry() *Geometry {
return &Geometry{
func (sg SphereGeometry) ToGeometry() Geometry {
return Geometry{
cG: C.CPxSphereGeometry_toCPxGeometry(&sg.cSg),
}
}
// struct CPxSphereGeometry NewCPxSphereGeometry(CPxReal radius);
func NewSphereGeometry(radius float32) *SphereGeometry {
return &SphereGeometry{
func NewSphereGeometry(radius float32) SphereGeometry {
return SphereGeometry{
cSg: C.struct_CPxSphereGeometry{
radius: C.float(radius),
},
@ -594,14 +687,28 @@ type BoxGeometry struct {
cBg C.struct_CPxBoxGeometry
}
func (bg *BoxGeometry) ToGeometry() *Geometry {
return &Geometry{
// GetExtents returns the extents of each dimension of the box.
// An extent is half the length total length.
//
// For example, a cube of size 1x1x1 would have an extent of 0.5 on each side
func (bg *BoxGeometry) GetExtents() (ex, ey, ez float32) {
return float32(bg.cBg.hx), float32(bg.cBg.hy), float32(bg.cBg.hz)
}
func (bg *BoxGeometry) SetExtents(ex, ey, ez float32) {
bg.cBg.hx = C.float(ex)
bg.cBg.hy = C.float(ey)
bg.cBg.hz = C.float(ez)
}
func (bg BoxGeometry) ToGeometry() Geometry {
return Geometry{
cG: C.CPxBoxGeometry_toCPxGeometry(&bg.cBg),
}
}
func NewBoxGeometry(hx, hy, hz float32) *BoxGeometry {
return &BoxGeometry{
func NewBoxGeometry(hx, hy, hz float32) BoxGeometry {
return BoxGeometry{
cBg: C.struct_CPxBoxGeometry{
hx: C.float(hx),
hy: C.float(hy),
@ -614,14 +721,23 @@ type CapsuleGeometry struct {
cCg C.struct_CPxCapsuleGeometry
}
func (bg *CapsuleGeometry) ToGeometry() *Geometry {
return &Geometry{
func (bg *CapsuleGeometry) GetParams() (radius, extent float32) {
return float32(bg.cCg.radius), float32(bg.cCg.halfHeight)
}
func (bg *CapsuleGeometry) SetParams(radius, extent float32) {
bg.cCg.radius = C.float(radius)
bg.cCg.halfHeight = C.float(extent)
}
func (bg CapsuleGeometry) ToGeometry() Geometry {
return Geometry{
cG: C.CPxCapsuleGeometry_toCPxGeometry(&bg.cCg),
}
}
func NewCapsuleGeometry(radius, halfHeight float32) *CapsuleGeometry {
return &CapsuleGeometry{
func NewCapsuleGeometry(radius, halfHeight float32) CapsuleGeometry {
return CapsuleGeometry{
cCg: C.struct_CPxCapsuleGeometry{
radius: C.float(radius),
halfHeight: C.float(halfHeight),
@ -634,17 +750,52 @@ type Actor struct {
}
type RigidActor struct {
cRa C.struct_CPxRigidActor
cRa C.struct_CPxRigidActor
pinner runtime.Pinner
}
func (ra *RigidActor) SetSimFilterData(fd *FilterData) {
C.CPxRigidActor_setSimFilterData(&ra.cRa, &fd.cFilterData)
C.CPxRigidActor_setSimFilterData(ra.cRa, fd.cFilterData)
}
// CPxAPI void CPxRigidActor_setSimFilterData(CSTRUCT CPxRigidActor* cra, CSTRUCT CPxFilterData* cfd);
// SetUserData sets the void* field on the rigid actor which can be used for any purpose.
// For example, it can be used to store an id or pointer that ties this rigid actor to some other object
//
// Note-1: The passed pointer will be stored in C and as such needs to be pinned, which this function will do.
// You can refer to this for notes on pinning and pointer rules: Refer to: https://pkg.go.dev/cmd/cgo#hdr-Passing_pointers
//
// Note-2: Since this RigidActor object is the one that pinned the user data, it MUST be kept alive at least until ClearUserData is used, at which point the data is unpinned and cleared.
// If this RigidActor object gets garabage collected before clear, the pinner will detect its getting collected with stuff still pinned (which is a leak) and will panic.
func (ra *RigidActor) SetUserData(userData unsafe.Pointer) {
// Note: Do NOT use interfaces here, as we need to ensure the original value
// pointed to is pinned, not the pointer to the interface (i.e. pinning the interface).
// Better avoid crazy to debug issues
// User data is a Go pointer stored in C/C++ code, and as such MUST be pinned
// before that is done, and must be unpinned when no longer stored in C/C++.
//
// Here we assume every write is of a different object, and so we always unpin before storing
// the new object.
//
// Refer to: https://pkg.go.dev/cmd/cgo#hdr-Passing_pointers
ra.pinner.Unpin()
ra.pinner.Pin(userData)
C.CPxRigidActor_set_userData(ra.cRa, userData)
}
func (ra *RigidActor) GetUserData() unsafe.Pointer {
return C.CPxRigidActor_get_userData(ra.cRa)
}
func (ra *RigidActor) ClearUserData() {
ra.pinner.Unpin()
C.CPxRigidActor_set_userData(ra.cRa, nil)
}
type RigidStatic struct {
cRs *C.struct_CPxRigidStatic
cRs C.struct_CPxRigidStatic
}
func (rs *RigidStatic) ToActor() Actor {
@ -659,8 +810,8 @@ func (rs *RigidStatic) ToRigidActor() RigidActor {
}
}
func CreatePlane(p *Physics, plane *Plane, mat *Material) *RigidStatic {
return &RigidStatic{
func CreatePlane(p Physics, plane *Plane, mat Material) RigidStatic {
return RigidStatic{
cRs: C.CPxCreatePlane(p.cPhysics, &plane.cP, mat.cM),
}
}

View File

@ -10,7 +10,7 @@
extern "C" {
#endif
CPxAPI CSTRUCT CPxRigidDynamic* CPxCreateDynamic(CSTRUCT CPxPhysics* sdk, CSTRUCT CPxTransform* transform, CSTRUCT CPxGeometry geometry, CSTRUCT CPxMaterial* material, CPxReal density, CSTRUCT CPxTransform* shapeOffset);
CPxAPI CSTRUCT CPxRigidDynamic CPxCreateDynamic(CSTRUCT CPxPhysics sdk, CSTRUCT CPxTransform* transform, CSTRUCT CPxGeometry geometry, CSTRUCT CPxMaterial material, CPxReal density, CSTRUCT CPxTransform* shapeOffset);
#ifdef __cplusplus
}

View File

@ -10,7 +10,7 @@ extern "C" {
void* obj;
};
CPxAPI void CPxActor_release(CSTRUCT CPxActor*);
CPxAPI void CPxActor_release(CSTRUCT CPxActor);
#ifdef __cplusplus
}

View File

@ -2,6 +2,7 @@
#define CPxContactPairHeader_H
#include "CPxShape.h"
#include "CPxPairFlag.h"
#include "CPxRigidActor.h"
#ifdef __cplusplus
@ -53,222 +54,6 @@ extern "C" {
CPxContactPairFlag_eINTERNAL_CONTACTS_ARE_FLIPPED = (1 << 5)
};
enum CPxPairFlags
{
/**
\brief Process the contacts of this collision pair in the dynamics solver.
\note Only takes effect if the colliding actors are rigid bodies.
*/
CPxPairFlags_eSOLVE_CONTACT = (1 << 0),
/**
\brief Call contact modification callback for this collision pair
\note Only takes effect if the colliding actors are rigid bodies.
@see PxContactModifyCallback
*/
CPxPairFlags_eMODIFY_CONTACTS = (1 << 1),
/**
\brief Call contact report callback or trigger callback when this collision pair starts to be in contact.
If one of the two collision objects is a trigger shape (see #PxShapeFlag::eTRIGGER_SHAPE)
then the trigger callback will get called as soon as the other object enters the trigger volume.
If none of the two collision objects is a trigger shape then the contact report callback will get
called when the actors of this collision pair start to be in contact.
\note Only takes effect if the colliding actors are rigid bodies.
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact() PxSimulationEventCallback.onTrigger()
*/
CPxPairFlags_eNOTIFY_TOUCH_FOUND = (1 << 2),
/**
\brief Call contact report callback while this collision pair is in contact
If none of the two collision objects is a trigger shape then the contact report callback will get
called while the actors of this collision pair are in contact.
\note Triggers do not support this event. Persistent trigger contacts need to be tracked separately by observing eNOTIFY_TOUCH_FOUND/eNOTIFY_TOUCH_LOST events.
\note Only takes effect if the colliding actors are rigid bodies.
\note No report will get sent if the objects in contact are sleeping.
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
\note If this flag gets enabled while a pair is in touch already, there will be no eNOTIFY_TOUCH_PERSISTS events until the pair loses and regains touch.
@see PxSimulationEventCallback.onContact() PxSimulationEventCallback.onTrigger()
*/
CPxPairFlags_eNOTIFY_TOUCH_PERSISTS = (1 << 3),
/**
\brief Call contact report callback or trigger callback when this collision pair stops to be in contact
If one of the two collision objects is a trigger shape (see #PxShapeFlag::eTRIGGER_SHAPE)
then the trigger callback will get called as soon as the other object leaves the trigger volume.
If none of the two collision objects is a trigger shape then the contact report callback will get
called when the actors of this collision pair stop to be in contact.
\note Only takes effect if the colliding actors are rigid bodies.
\note This event will also get triggered if one of the colliding objects gets deleted.
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact() PxSimulationEventCallback.onTrigger()
*/
CPxPairFlags_eNOTIFY_TOUCH_LOST = (1 << 4),
/**
\brief Call contact report callback when this collision pair is in contact during CCD passes.
If CCD with multiple passes is enabled, then a fast moving object might bounce on and off the same
object multiple times. Hence, the same pair might be in contact multiple times during a simulation step.
This flag will make sure that all the detected collision during CCD will get reported. For performance
reasons, the system can not always tell whether the contact pair lost touch in one of the previous CCD
passes and thus can also not always tell whether the contact is new or has persisted. eNOTIFY_TOUCH_CCD
just reports when the two collision objects were detected as being in contact during a CCD pass.
\note Only takes effect if the colliding actors are rigid bodies.
\note Trigger shapes are not supported.
\note Only takes effect if eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact() PxSimulationEventCallback.onTrigger()
*/
CPxPairFlags_eNOTIFY_TOUCH_CCD = (1 << 5),
/**
\brief Call contact report callback when the contact force between the actors of this collision pair exceeds one of the actor-defined force thresholds.
\note Only takes effect if the colliding actors are rigid bodies.
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact()
*/
CPxPairFlags_eNOTIFY_THRESHOLD_FORCE_FOUND = (1 << 6),
/**
\brief Call contact report callback when the contact force between the actors of this collision pair continues to exceed one of the actor-defined force thresholds.
\note Only takes effect if the colliding actors are rigid bodies.
\note If a pair gets re-filtered and this flag has previously been disabled, then the report will not get fired in the same frame even if the force threshold has been reached in the
previous one (unless #eNOTIFY_THRESHOLD_FORCE_FOUND has been set in the previous frame).
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact()
*/
CPxPairFlags_eNOTIFY_THRESHOLD_FORCE_PERSISTS = (1 << 7),
/**
\brief Call contact report callback when the contact force between the actors of this collision pair falls below one of the actor-defined force thresholds (includes the case where this collision pair stops being in contact).
\note Only takes effect if the colliding actors are rigid bodies.
\note If a pair gets re-filtered and this flag has previously been disabled, then the report will not get fired in the same frame even if the force threshold has been reached in the
previous one (unless #eNOTIFY_THRESHOLD_FORCE_FOUND or #eNOTIFY_THRESHOLD_FORCE_PERSISTS has been set in the previous frame).
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact()
*/
CPxPairFlags_eNOTIFY_THRESHOLD_FORCE_LOST = (1 << 8),
/**
\brief Provide contact points in contact reports for this collision pair.
\note Only takes effect if the colliding actors are rigid bodies and if used in combination with the flags eNOTIFY_TOUCH_... or eNOTIFY_THRESHOLD_FORCE_...
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact() PxContactPair PxContactPair.extractContacts()
*/
CPxPairFlags_eNOTIFY_CONTACT_POINTS = (1 << 9),
/**
\brief This flag is used to indicate whether this pair generates discrete collision detection contacts.
\note Contacts are only responded to if eSOLVE_CONTACT is enabled.
*/
CPxPairFlags_eDETECT_DISCRETE_CONTACT = (1 << 10),
/**
\brief This flag is used to indicate whether this pair generates CCD contacts.
\note The contacts will only be responded to if eSOLVE_CONTACT is enabled on this pair.
\note The scene must have PxSceneFlag::eENABLE_CCD enabled to use this feature.
\note Non-static bodies of the pair should have PxRigidBodyFlag::eENABLE_CCD specified for this feature to work correctly.
\note This flag is not supported with trigger shapes. However, CCD trigger events can be emulated using non-trigger shapes
and requesting eNOTIFY_TOUCH_FOUND and eNOTIFY_TOUCH_LOST and not raising eSOLVE_CONTACT on the pair.
@see PxRigidBodyFlag::eENABLE_CCD
@see PxSceneFlag::eENABLE_CCD
*/
CPxPairFlags_eDETECT_CCD_CONTACT = (1 << 11),
/**
\brief Provide pre solver velocities in contact reports for this collision pair.
If the collision pair has contact reports enabled, the velocities of the rigid bodies before contacts have been solved
will be provided in the contact report callback unless the pair lost touch in which case no data will be provided.
\note Usually it is not necessary to request these velocities as they will be available by querying the velocity from the provided
PxRigidActor object directly. However, it might be the case that the velocity of a rigid body gets set while the simulation is running
in which case the PxRigidActor would return this new velocity in the contact report callback and not the velocity the simulation used.
@see PxSimulationEventCallback.onContact(), PxContactPairVelocity, PxContactPairHeader.extraDataStream
*/
CPxPairFlags_ePRE_SOLVER_VELOCITY = (1 << 12),
/**
\brief Provide post solver velocities in contact reports for this collision pair.
If the collision pair has contact reports enabled, the velocities of the rigid bodies after contacts have been solved
will be provided in the contact report callback unless the pair lost touch in which case no data will be provided.
@see PxSimulationEventCallback.onContact(), PxContactPairVelocity, PxContactPairHeader.extraDataStream
*/
CPxPairFlags_ePOST_SOLVER_VELOCITY = (1 << 13),
/**
\brief Provide rigid body poses in contact reports for this collision pair.
If the collision pair has contact reports enabled, the rigid body poses at the contact event will be provided
in the contact report callback unless the pair lost touch in which case no data will be provided.
\note Usually it is not necessary to request these poses as they will be available by querying the pose from the provided
PxRigidActor object directly. However, it might be the case that the pose of a rigid body gets set while the simulation is running
in which case the PxRigidActor would return this new pose in the contact report callback and not the pose the simulation used.
Another use case is related to CCD with multiple passes enabled, A fast moving object might bounce on and off the same
object multiple times. This flag can be used to request the rigid body poses at the time of impact for each such collision event.
@see PxSimulationEventCallback.onContact(), PxContactPairPose, PxContactPairHeader.extraDataStream
*/
CPxPairFlags_eCONTACT_EVENT_POSE = (1 << 14),
CPxPairFlags_eNEXT_FREE = (1 << 15), //!< For internal use only.
/**
\brief Provided default flag to do simple contact processing for this collision pair.
*/
CPxPairFlags_eCONTACT_DEFAULT = CPxPairFlags_eSOLVE_CONTACT | CPxPairFlags_eDETECT_DISCRETE_CONTACT,
/**
\brief Provided default flag to get commonly used trigger behavior for this collision pair.
*/
CPxPairFlags_eTRIGGER_DEFAULT = CPxPairFlags_eNOTIFY_TOUCH_FOUND | CPxPairFlags_eNOTIFY_TOUCH_LOST | CPxPairFlags_eDETECT_DISCRETE_CONTACT
};
struct CPxContactPairPoint
{
/**
@ -314,7 +99,7 @@ extern "C" {
CPxU8 patchCount;
CPxU16 contactStreamSize;
CENUM CPxPairFlags events;
CENUM CPxPairFlag events;
CENUM CPxContactPairFlag flags;
CSTRUCT CPxContactPairPoint* extractedContactPoints;
@ -343,4 +128,4 @@ extern "C" {
}
#endif
#endif // !1
#endif

View File

@ -10,14 +10,6 @@ extern "C" {
void* obj;
};
/// <summary>
/// This only frees C representation of the base class (the CPxCpuDispatcher struct). obj is NOT freed.
/// To release the PhysX resources release must be called on the actual C implementation (e.g. CPxDefaultCpuDispatcher_release)
/// </summary>
/// <param name="CPxCpuDispatcher"></param>
/// <returns></returns>
CPxAPI void CPxCpuDispatcher_release(CSTRUCT CPxCpuDispatcher*);
#ifdef __cplusplus
}
#endif

View File

@ -11,9 +11,9 @@ extern "C" {
void* obj;
};
CPxAPI CSTRUCT CPxDefaultCpuDispatcher* CPxDefaultCpuDispatcherCreate(CPxU32 numThreads, CPxU32* affinityMasks);
CPxAPI CSTRUCT CPxCpuDispatcher* CPxDefaultCpuDispatcher_toCPxCpuDispatcher(CSTRUCT CPxDefaultCpuDispatcher* cdcd);
CPxAPI void CPxDefaultCpuDispatcher_release(CSTRUCT CPxDefaultCpuDispatcher* cdcd);
CPxAPI CSTRUCT CPxDefaultCpuDispatcher CPxDefaultCpuDispatcherCreate(CPxU32 numThreads, CPxU32* affinityMasks);
CPxAPI CSTRUCT CPxCpuDispatcher CPxDefaultCpuDispatcher_toCPxCpuDispatcher(CSTRUCT CPxDefaultCpuDispatcher cdcd);
CPxAPI void CPxDefaultCpuDispatcher_release(CSTRUCT CPxDefaultCpuDispatcher cdcd);
#ifdef __cplusplus
}

View File

@ -9,8 +9,8 @@ extern "C" {
void* obj;
};
CPxAPI CSTRUCT CPxFoundation* CPxCreateFoundation();
CPxAPI void CPxFoundation_release(CSTRUCT CPxFoundation* cpf);
CPxAPI CSTRUCT CPxFoundation CPxCreateFoundation();
CPxAPI void CPxFoundation_release(CSTRUCT CPxFoundation cpf);
#ifdef __cplusplus
}
#endif

View File

@ -10,8 +10,6 @@ extern "C" {
void* obj;
};
CPxAPI void CPxMaterial_release(CSTRUCT CPxMaterial*);
#ifdef __cplusplus
}
#endif

228
pgo/physx-c/CPxPairFlag.h Executable file
View File

@ -0,0 +1,228 @@
#ifndef CPxPairFlag_H
#define CPxPairFlag_H
#ifdef __cplusplus
extern "C" {
#endif
enum CPxPairFlag
{
/**
\brief Process the contacts of this collision pair in the dynamics solver.
\note Only takes effect if the colliding actors are rigid bodies.
*/
CPxPairFlags_eSOLVE_CONTACT = (1 << 0),
/**
\brief Call contact modification callback for this collision pair
\note Only takes effect if the colliding actors are rigid bodies.
@see PxContactModifyCallback
*/
CPxPairFlags_eMODIFY_CONTACTS = (1 << 1),
/**
\brief Call contact report callback or trigger callback when this collision pair starts to be in contact.
If one of the two collision objects is a trigger shape (see #PxShapeFlag::eTRIGGER_SHAPE)
then the trigger callback will get called as soon as the other object enters the trigger volume.
If none of the two collision objects is a trigger shape then the contact report callback will get
called when the actors of this collision pair start to be in contact.
\note Only takes effect if the colliding actors are rigid bodies.
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact() PxSimulationEventCallback.onTrigger()
*/
CPxPairFlags_eNOTIFY_TOUCH_FOUND = (1 << 2),
/**
\brief Call contact report callback while this collision pair is in contact
If none of the two collision objects is a trigger shape then the contact report callback will get
called while the actors of this collision pair are in contact.
\note Triggers do not support this event. Persistent trigger contacts need to be tracked separately by observing eNOTIFY_TOUCH_FOUND/eNOTIFY_TOUCH_LOST events.
\note Only takes effect if the colliding actors are rigid bodies.
\note No report will get sent if the objects in contact are sleeping.
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
\note If this flag gets enabled while a pair is in touch already, there will be no eNOTIFY_TOUCH_PERSISTS events until the pair loses and regains touch.
@see PxSimulationEventCallback.onContact() PxSimulationEventCallback.onTrigger()
*/
CPxPairFlags_eNOTIFY_TOUCH_PERSISTS = (1 << 3),
/**
\brief Call contact report callback or trigger callback when this collision pair stops to be in contact
If one of the two collision objects is a trigger shape (see #PxShapeFlag::eTRIGGER_SHAPE)
then the trigger callback will get called as soon as the other object leaves the trigger volume.
If none of the two collision objects is a trigger shape then the contact report callback will get
called when the actors of this collision pair stop to be in contact.
\note Only takes effect if the colliding actors are rigid bodies.
\note This event will also get triggered if one of the colliding objects gets deleted.
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact() PxSimulationEventCallback.onTrigger()
*/
CPxPairFlags_eNOTIFY_TOUCH_LOST = (1 << 4),
/**
\brief Call contact report callback when this collision pair is in contact during CCD passes.
If CCD with multiple passes is enabled, then a fast moving object might bounce on and off the same
object multiple times. Hence, the same pair might be in contact multiple times during a simulation step.
This flag will make sure that all the detected collision during CCD will get reported. For performance
reasons, the system can not always tell whether the contact pair lost touch in one of the previous CCD
passes and thus can also not always tell whether the contact is new or has persisted. eNOTIFY_TOUCH_CCD
just reports when the two collision objects were detected as being in contact during a CCD pass.
\note Only takes effect if the colliding actors are rigid bodies.
\note Trigger shapes are not supported.
\note Only takes effect if eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact() PxSimulationEventCallback.onTrigger()
*/
CPxPairFlags_eNOTIFY_TOUCH_CCD = (1 << 5),
/**
\brief Call contact report callback when the contact force between the actors of this collision pair exceeds one of the actor-defined force thresholds.
\note Only takes effect if the colliding actors are rigid bodies.
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact()
*/
CPxPairFlags_eNOTIFY_THRESHOLD_FORCE_FOUND = (1 << 6),
/**
\brief Call contact report callback when the contact force between the actors of this collision pair continues to exceed one of the actor-defined force thresholds.
\note Only takes effect if the colliding actors are rigid bodies.
\note If a pair gets re-filtered and this flag has previously been disabled, then the report will not get fired in the same frame even if the force threshold has been reached in the
previous one (unless #eNOTIFY_THRESHOLD_FORCE_FOUND has been set in the previous frame).
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact()
*/
CPxPairFlags_eNOTIFY_THRESHOLD_FORCE_PERSISTS = (1 << 7),
/**
\brief Call contact report callback when the contact force between the actors of this collision pair falls below one of the actor-defined force thresholds (includes the case where this collision pair stops being in contact).
\note Only takes effect if the colliding actors are rigid bodies.
\note If a pair gets re-filtered and this flag has previously been disabled, then the report will not get fired in the same frame even if the force threshold has been reached in the
previous one (unless #eNOTIFY_THRESHOLD_FORCE_FOUND or #eNOTIFY_THRESHOLD_FORCE_PERSISTS has been set in the previous frame).
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact()
*/
CPxPairFlags_eNOTIFY_THRESHOLD_FORCE_LOST = (1 << 8),
/**
\brief Provide contact points in contact reports for this collision pair.
\note Only takes effect if the colliding actors are rigid bodies and if used in combination with the flags eNOTIFY_TOUCH_... or eNOTIFY_THRESHOLD_FORCE_...
\note Only takes effect if eDETECT_DISCRETE_CONTACT or eDETECT_CCD_CONTACT is raised
@see PxSimulationEventCallback.onContact() PxContactPair PxContactPair.extractContacts()
*/
CPxPairFlags_eNOTIFY_CONTACT_POINTS = (1 << 9),
/**
\brief This flag is used to indicate whether this pair generates discrete collision detection contacts.
\note Contacts are only responded to if eSOLVE_CONTACT is enabled.
*/
CPxPairFlags_eDETECT_DISCRETE_CONTACT = (1 << 10),
/**
\brief This flag is used to indicate whether this pair generates CCD contacts.
\note The contacts will only be responded to if eSOLVE_CONTACT is enabled on this pair.
\note The scene must have PxSceneFlag::eENABLE_CCD enabled to use this feature.
\note Non-static bodies of the pair should have PxRigidBodyFlag::eENABLE_CCD specified for this feature to work correctly.
\note This flag is not supported with trigger shapes. However, CCD trigger events can be emulated using non-trigger shapes
and requesting eNOTIFY_TOUCH_FOUND and eNOTIFY_TOUCH_LOST and not raising eSOLVE_CONTACT on the pair.
@see PxRigidBodyFlag::eENABLE_CCD
@see PxSceneFlag::eENABLE_CCD
*/
CPxPairFlags_eDETECT_CCD_CONTACT = (1 << 11),
/**
\brief Provide pre solver velocities in contact reports for this collision pair.
If the collision pair has contact reports enabled, the velocities of the rigid bodies before contacts have been solved
will be provided in the contact report callback unless the pair lost touch in which case no data will be provided.
\note Usually it is not necessary to request these velocities as they will be available by querying the velocity from the provided
PxRigidActor object directly. However, it might be the case that the velocity of a rigid body gets set while the simulation is running
in which case the PxRigidActor would return this new velocity in the contact report callback and not the velocity the simulation used.
@see PxSimulationEventCallback.onContact(), PxContactPairVelocity, PxContactPairHeader.extraDataStream
*/
CPxPairFlags_ePRE_SOLVER_VELOCITY = (1 << 12),
/**
\brief Provide post solver velocities in contact reports for this collision pair.
If the collision pair has contact reports enabled, the velocities of the rigid bodies after contacts have been solved
will be provided in the contact report callback unless the pair lost touch in which case no data will be provided.
@see PxSimulationEventCallback.onContact(), PxContactPairVelocity, PxContactPairHeader.extraDataStream
*/
CPxPairFlags_ePOST_SOLVER_VELOCITY = (1 << 13),
/**
\brief Provide rigid body poses in contact reports for this collision pair.
If the collision pair has contact reports enabled, the rigid body poses at the contact event will be provided
in the contact report callback unless the pair lost touch in which case no data will be provided.
\note Usually it is not necessary to request these poses as they will be available by querying the pose from the provided
PxRigidActor object directly. However, it might be the case that the pose of a rigid body gets set while the simulation is running
in which case the PxRigidActor would return this new pose in the contact report callback and not the pose the simulation used.
Another use case is related to CCD with multiple passes enabled, A fast moving object might bounce on and off the same
object multiple times. This flag can be used to request the rigid body poses at the time of impact for each such collision event.
@see PxSimulationEventCallback.onContact(), PxContactPairPose, PxContactPairHeader.extraDataStream
*/
CPxPairFlags_eCONTACT_EVENT_POSE = (1 << 14),
CPxPairFlags_eNEXT_FREE = (1 << 15), //!< For internal use only.
/**
\brief Provided default flag to do simple contact processing for this collision pair.
*/
CPxPairFlags_eCONTACT_DEFAULT = CPxPairFlags_eSOLVE_CONTACT | CPxPairFlags_eDETECT_DISCRETE_CONTACT,
/**
\brief Provided default flag to get commonly used trigger behavior for this collision pair.
*/
CPxPairFlags_eTRIGGER_DEFAULT = CPxPairFlags_eNOTIFY_TOUCH_FOUND | CPxPairFlags_eNOTIFY_TOUCH_LOST | CPxPairFlags_eDETECT_DISCRETE_CONTACT
};
#ifdef __cplusplus
}
#endif
#endif

View File

@ -19,13 +19,13 @@ extern "C" {
void* obj;
};
CPxAPI CSTRUCT CPxPhysics* CPxCreatePhysics(CSTRUCT CPxFoundation* cfoundation, CSTRUCT CPxTolerancesScale cscale, bool trackOutstandingAllocations, CSTRUCT CPxPvd* cpvd);
CPxAPI CSTRUCT CPxScene* CPxPhysics_createScene(CSTRUCT CPxPhysics*, CSTRUCT CPxSceneDesc*);
CPxAPI CSTRUCT CPxMaterial* CPxPhysics_createMaterial(CSTRUCT CPxPhysics*, CPxReal staticFriction, CPxReal dynamicFriction, CPxReal restitution);
CPxAPI CSTRUCT CPxRigidDynamic* CPxPhysics_createRigidDynamic(CSTRUCT CPxPhysics* cp, CSTRUCT CPxTransform* ctr);
CPxAPI CSTRUCT CPxRigidStatic* CPxPhysics_createRigidStatic(CSTRUCT CPxPhysics* cp, CSTRUCT CPxTransform* ctr);
CPxAPI CSTRUCT CPxPhysics CPxCreatePhysics(CSTRUCT CPxFoundation cfoundation, CSTRUCT CPxTolerancesScale cscale, bool trackOutstandingAllocations, CSTRUCT CPxPvd* cpvd);
CPxAPI CSTRUCT CPxScene CPxPhysics_createScene(CSTRUCT CPxPhysics, CSTRUCT CPxSceneDesc);
CPxAPI CSTRUCT CPxMaterial CPxPhysics_createMaterial(CSTRUCT CPxPhysics, CPxReal staticFriction, CPxReal dynamicFriction, CPxReal restitution);
CPxAPI CSTRUCT CPxRigidDynamic CPxPhysics_createRigidDynamic(CSTRUCT CPxPhysics cp, CSTRUCT CPxTransform* ctr);
CPxAPI CSTRUCT CPxRigidStatic CPxPhysics_createRigidStatic(CSTRUCT CPxPhysics cp, CSTRUCT CPxTransform* ctr);
CPxAPI void CPxPhysics_release(CSTRUCT CPxPhysics*);
CPxAPI void CPxPhysics_release(CSTRUCT CPxPhysics);
#ifdef __cplusplus
}

View File

@ -62,9 +62,9 @@ extern "C" {
void* obj;
};
CPxAPI CSTRUCT CPxPvd* CPxCreatePvd(CSTRUCT CPxFoundation*);
CPxAPI bool CPxPvd_connect(CSTRUCT CPxPvd*, CSTRUCT CPxPvdTransport*, CENUM CPxPvdInstrumentationFlag);
CPxAPI void CPxPvd_release(CSTRUCT CPxPvd* cpp);
CPxAPI CSTRUCT CPxPvd CPxCreatePvd(CSTRUCT CPxFoundation);
CPxAPI bool CPxPvd_connect(CSTRUCT CPxPvd, CSTRUCT CPxPvdTransport, CENUM CPxPvdInstrumentationFlag);
CPxAPI void CPxPvd_release(CSTRUCT CPxPvd cpp);
#ifdef __cplusplus
}
#endif

View File

@ -17,14 +17,7 @@ extern "C" {
void* obj;
};
CPxAPI void CPxPvdSceneClient_setScenePvdFlag(CSTRUCT CPxPvdSceneClient* c, CENUM CPxPvdSceneFlag flag, bool value);
/// <summary>
/// This only releases the C struct
/// </summary>
/// <param name=""></param>
/// <returns></returns>
CPxAPI void CPxPvdSceneClient_release(CSTRUCT CPxPvdSceneClient*);
CPxAPI void CPxPvdSceneClient_setScenePvdFlag(CSTRUCT CPxPvdSceneClient c, CENUM CPxPvdSceneFlag flag, bool value);
#ifdef __cplusplus
}

View File

@ -9,8 +9,7 @@ extern "C" {
void* obj;
};
CPxAPI CSTRUCT CPxPvdTransport* CPxDefaultPvdSocketTransportCreate(const char* address, int port, int timeoutMillis);
CPxAPI void CPxPvdTransport_release(CSTRUCT CPxPvdTransport* cppt);
CPxAPI CSTRUCT CPxPvdTransport CPxDefaultPvdSocketTransportCreate(const char* address, int port, int timeoutMillis);
#ifdef __cplusplus
}
#endif

View File

@ -13,7 +13,9 @@ extern "C" {
};
//Sets the CPxFilterData on all the shapes of the actor.
CPxAPI void CPxRigidActor_setSimFilterData(CSTRUCT CPxRigidActor* cra, CSTRUCT CPxFilterData* cfd);
CPxAPI void CPxRigidActor_setSimFilterData(CSTRUCT CPxRigidActor cra, CSTRUCT CPxFilterData cfd);
CPxAPI void CPxRigidActor_set_userData(CSTRUCT CPxRigidActor cra, void* userData);
CPxAPI void* CPxRigidActor_get_userData(CSTRUCT CPxRigidActor cra);
#ifdef __cplusplus
}

View File

@ -11,7 +11,7 @@
extern "C" {
#endif
CPxAPI CSTRUCT CPxShape createExclusiveShape(CSTRUCT CPxRigidActor actor, CSTRUCT CPxGeometry geometry, CSTRUCT CPxMaterial* material, CENUM CPxShapeFlags shapeFlags);
CPxAPI CSTRUCT CPxShape createExclusiveShape(CSTRUCT CPxRigidActor actor, CSTRUCT CPxGeometry geometry, CSTRUCT CPxMaterial material, CENUM CPxShapeFlags shapeFlags);
#ifdef __cplusplus
}

View File

@ -18,37 +18,47 @@ extern "C" {
void* obj;
};
CPxAPI CSTRUCT CPxActor CPxRigidDynamic_toCPxActor(CSTRUCT CPxRigidDynamic*);
CPxAPI CSTRUCT CPxRigidActor CPxRigidDynamic_toCPxRigidActor(CSTRUCT CPxRigidDynamic*);
CPxAPI CSTRUCT CPxActor CPxRigidDynamic_toCPxActor(CSTRUCT CPxRigidDynamic);
CPxAPI CSTRUCT CPxRigidActor CPxRigidDynamic_toCPxRigidActor(CSTRUCT CPxRigidDynamic);
CPxAPI void CPxRigidDynamic_addForce(CSTRUCT CPxRigidDynamic* crd, CSTRUCT CPxVec3* force, CENUM CPxForceMode fmode, bool autoAwake);
CPxAPI void CPxRigidDynamic_addTorque(CSTRUCT CPxRigidDynamic* crd, CSTRUCT CPxVec3* torque, CENUM CPxForceMode fmode, bool autoAwake);
CPxAPI void CPxRigidDynamic_addForce(CSTRUCT CPxRigidDynamic crd, CSTRUCT CPxVec3* force, CENUM CPxForceMode fmode, bool autoAwake);
CPxAPI void CPxRigidDynamic_addTorque(CSTRUCT CPxRigidDynamic crd, CSTRUCT CPxVec3* torque, CENUM CPxForceMode fmode, bool autoAwake);
CPxAPI void CPxRigidDynamic_setLinearDamping(CSTRUCT CPxRigidDynamic* crd, CPxReal damping);
CPxAPI void CPxRigidDynamic_setAngularDamping(CSTRUCT CPxRigidDynamic* crd, CPxReal damping);
CPxAPI CPxReal CPxRigidDynamic_getLinearDamping(CSTRUCT CPxRigidDynamic* crd);
CPxAPI CPxReal CPxRigidDynamic_getAngularDamping(CSTRUCT CPxRigidDynamic* crd);
CPxAPI void CPxRigidDynamic_setLinearDamping(CSTRUCT CPxRigidDynamic crd, CPxReal damping);
CPxAPI void CPxRigidDynamic_setAngularDamping(CSTRUCT CPxRigidDynamic crd, CPxReal damping);
CPxAPI CPxReal CPxRigidDynamic_getLinearDamping(CSTRUCT CPxRigidDynamic crd);
CPxAPI CPxReal CPxRigidDynamic_getAngularDamping(CSTRUCT CPxRigidDynamic crd);
CPxAPI CSTRUCT CPxVec3 CPxRigidDynamic_getLinearVelocity(CSTRUCT CPxRigidDynamic* crd);
CPxAPI CSTRUCT CPxVec3 CPxRigidDynamic_getAngularVelocity(CSTRUCT CPxRigidDynamic* crd);
CPxAPI CSTRUCT CPxVec3 CPxRigidDynamic_getLinearVelocity(CSTRUCT CPxRigidDynamic crd);
CPxAPI void CPxRigidDynamic_setLinearVelocity(CSTRUCT CPxRigidDynamic crd, CSTRUCT CPxVec3* velocity, bool autoAwake);
CPxAPI void CPxRigidDynamic_setMass(CSTRUCT CPxRigidDynamic* crd, CPxReal mass);
CPxAPI CPxReal CPxRigidDynamic_getMass(CSTRUCT CPxRigidDynamic* crd);
CPxAPI CPxReal CPxRigidDynamic_getMaxLinearVelocity(CSTRUCT CPxRigidDynamic crd);
CPxAPI void CPxRigidDynamic_setMaxLinearVelocity(CSTRUCT CPxRigidDynamic crd, CPxReal maxLinearVelocity);
CPxAPI void CPxRigidDynamic_setRigidBodyFlag(CSTRUCT CPxRigidDynamic* crd, CENUM CPxRigidBodyFlag flag, bool value);
CPxAPI void CPxRigidDynamic_setRigidBodyFlags(CSTRUCT CPxRigidDynamic* crd, CENUM CPxRigidBodyFlag flags);
CPxAPI CENUM CPxRigidBodyFlag CPxRigidDynamic_getRigidBodyFlags(CSTRUCT CPxRigidDynamic* crd);
CPxAPI void CPxRigidDynamic_setRigidDynamicLockFlag(CSTRUCT CPxRigidDynamic* crd, CENUM CPxRigidDynamicLockFlag flag, bool value);
CPxAPI void CPxRigidDynamic_setRigidDynamicLockFlags(CSTRUCT CPxRigidDynamic* crd, CENUM CPxRigidDynamicLockFlag flags);
CPxAPI CENUM CPxRigidDynamicLockFlag CPxRigidDynamic_getRigidDynamicLockFlags(CSTRUCT CPxRigidDynamic* crd);
CPxAPI CSTRUCT CPxVec3 CPxRigidDynamic_getAngularVelocity(CSTRUCT CPxRigidDynamic crd);
CPxAPI void CPxRigidDynamic_setAngularVelocity(CSTRUCT CPxRigidDynamic crd, CSTRUCT CPxVec3* velocity, bool autoAwake);
CPxAPI void CPxRigidDynamic_putToSleep(CSTRUCT CPxRigidDynamic* crd);
CPxAPI CSTRUCT CPxTransform CPxRigidDynamic_getGlobalPose(CSTRUCT CPxRigidDynamic* crd);
CPxAPI void CPxRigidDynamic_setGlobalPose(CSTRUCT CPxRigidDynamic* crd, CSTRUCT CPxTransform* tr, bool autoAwake);
CPxAPI CPxReal CPxRigidDynamic_getMaxAngularVelocity(CSTRUCT CPxRigidDynamic crd);
CPxAPI void CPxRigidDynamic_setMaxAngularVelocity(CSTRUCT CPxRigidDynamic crd, CPxReal maxAngularVelocity);
CPxAPI CSTRUCT CPxTransform CPxRigidDynamic_getCMassLocalPose(CSTRUCT CPxRigidDynamic* crd);
CPxAPI void CPxRigidDynamic_setCMassLocalPose(CSTRUCT CPxRigidDynamic* crd, CSTRUCT CPxTransform* tr);
CPxAPI void CPxRigidDynamic_setMass(CSTRUCT CPxRigidDynamic crd, CPxReal mass);
CPxAPI CPxReal CPxRigidDynamic_getMass(CSTRUCT CPxRigidDynamic crd);
CPxAPI void CPxRigidDynamic_setRigidBodyFlag(CSTRUCT CPxRigidDynamic crd, CENUM CPxRigidBodyFlag flag, bool value);
CPxAPI void CPxRigidDynamic_setRigidBodyFlags(CSTRUCT CPxRigidDynamic crd, CENUM CPxRigidBodyFlag flags);
CPxAPI CENUM CPxRigidBodyFlag CPxRigidDynamic_getRigidBodyFlags(CSTRUCT CPxRigidDynamic crd);
CPxAPI void CPxRigidDynamic_setRigidDynamicLockFlag(CSTRUCT CPxRigidDynamic crd, CENUM CPxRigidDynamicLockFlag flag, bool value);
CPxAPI void CPxRigidDynamic_setRigidDynamicLockFlags(CSTRUCT CPxRigidDynamic crd, CENUM CPxRigidDynamicLockFlag flags);
CPxAPI CENUM CPxRigidDynamicLockFlag CPxRigidDynamic_getRigidDynamicLockFlags(CSTRUCT CPxRigidDynamic crd);
CPxAPI void CPxRigidDynamic_putToSleep(CSTRUCT CPxRigidDynamic crd);
CPxAPI CSTRUCT CPxTransform CPxRigidDynamic_getGlobalPose(CSTRUCT CPxRigidDynamic crd);
CPxAPI void CPxRigidDynamic_setGlobalPose(CSTRUCT CPxRigidDynamic crd, CSTRUCT CPxTransform* tr, bool autoAwake);
CPxAPI CSTRUCT CPxTransform CPxRigidDynamic_getCMassLocalPose(CSTRUCT CPxRigidDynamic crd);
CPxAPI void CPxRigidDynamic_setCMassLocalPose(CSTRUCT CPxRigidDynamic crd, CSTRUCT CPxTransform* tr);
#ifdef __cplusplus
}

View File

@ -13,8 +13,8 @@ extern "C" {
void* obj;
};
CPxAPI CSTRUCT CPxActor CPxRigidStatic_toCPxActor(CSTRUCT CPxRigidStatic*);
CPxAPI CSTRUCT CPxRigidActor CPxRigidStatic_toCPxRigidActor(CSTRUCT CPxRigidStatic*);
CPxAPI CSTRUCT CPxActor CPxRigidStatic_toCPxActor(CSTRUCT CPxRigidStatic);
CPxAPI CSTRUCT CPxRigidActor CPxRigidStatic_toCPxRigidActor(CSTRUCT CPxRigidStatic);
#ifdef __cplusplus
}

View File

@ -19,20 +19,20 @@ extern "C" {
CPxU32 scratchBufferSize;
};
CPxAPI CSTRUCT CPxPvdSceneClient* CPxScene_getScenePvdClient(CSTRUCT CPxScene*);
CPxAPI void CPxScene_addActor(CSTRUCT CPxScene*, CSTRUCT CPxActor actor);
CPxAPI void CPxScene_simulate(CSTRUCT CPxScene*, CPxReal elapsedTime);
CPxAPI void CPxScene_collide(CSTRUCT CPxScene*, CPxReal elapsedTime);
CPxAPI bool CPxScene_fetchCollision(CSTRUCT CPxScene*, bool block);
CPxAPI void CPxScene_advance(CSTRUCT CPxScene*);
CPxAPI bool CPxScene_fetchResults(CSTRUCT CPxScene*, bool block, CPxU32* errorState);
CPxAPI CSTRUCT CPxPvdSceneClient CPxScene_getScenePvdClient(CSTRUCT CPxScene);
CPxAPI void CPxScene_addActor(CSTRUCT CPxScene, CSTRUCT CPxActor actor);
CPxAPI void CPxScene_simulate(CSTRUCT CPxScene, CPxReal elapsedTime);
CPxAPI void CPxScene_collide(CSTRUCT CPxScene, CPxReal elapsedTime);
CPxAPI bool CPxScene_fetchCollision(CSTRUCT CPxScene, bool block);
CPxAPI void CPxScene_advance(CSTRUCT CPxScene);
CPxAPI bool CPxScene_fetchResults(CSTRUCT CPxScene, bool block, CPxU32* errorState);
//Does a scene raycast. Allocates memory for hitRet and then reads data into it. It is the callers responsibility to free.
CPxAPI bool CPxScene_raycast(CSTRUCT CPxScene* cs, CSTRUCT CPxVec3* origin, CSTRUCT CPxVec3* unitDir, CPxReal distance, CSTRUCT CPxRaycastBuffer** hitRet);
CPxAPI bool CPxScene_raycast(CSTRUCT CPxScene cs, CSTRUCT CPxVec3* origin, CSTRUCT CPxVec3* unitDir, CPxReal distance, CSTRUCT CPxRaycastBuffer** hitRet);
//Does a scene raycast. 'hit' must be pre-allocated as NO new allocation will happen in the function.
//hit->touches will be filled up to 'touchesToRead' and must also be pre-allocated. If the hit produces more touches than 'touchesToRead' then the additional touches will be ignored.
CPxAPI bool CPxScene_raycastWithHitBuffer(CSTRUCT CPxScene* cs, CSTRUCT CPxVec3* origin, CSTRUCT CPxVec3* unitDir, CPxReal distance, CSTRUCT CPxRaycastBuffer* hit, CPxU32 touchesToRead);
CPxAPI bool CPxScene_raycastWithHitBuffer(CSTRUCT CPxScene cs, CSTRUCT CPxVec3* origin, CSTRUCT CPxVec3* unitDir, CPxReal distance, CSTRUCT CPxRaycastBuffer* hit, CPxU32 touchesToRead);
/// <summary>
/// Creates a scratch buffer thats a multiple of 16K to be used by the scene when running CPxScene_simulate.
@ -40,9 +40,9 @@ extern "C" {
/// If multiples passed are zero then any existing buffers are cleared
/// </summary>
/// <returns></returns>
CPxAPI void CPxScene_setScratchBuffer(CSTRUCT CPxScene*, CPxU32 multiplesOf16k);
CPxAPI void CPxScene_setScratchBuffer(CSTRUCT CPxScene, CPxU32 multiplesOf16k);
CPxAPI void CPxScene_release(CSTRUCT CPxScene*);
CPxAPI void CPxScene_release(CSTRUCT CPxScene);
#ifdef __cplusplus
}

View File

@ -13,7 +13,8 @@ extern "C" {
void* obj;
};
typedef void (*CPxonContactCallback)(void* pairHeader);
typedef void (*CPxOnContactCallback)(void* pairHeader);
typedef void (*CPxOnTriggerCallback)(void* triggerPairs, CPxU32 count);
/// <summary>
/// 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.
@ -21,17 +22,25 @@ extern "C" {
/// <param name="CPxTolerancesScale"></param>
/// <returns></returns>
CPxAPI CSTRUCT CPxSceneDesc NewCPxSceneDesc(CSTRUCT CPxTolerancesScale);
CPxAPI void CPxSceneDesc_set_gravity(CSTRUCT CPxSceneDesc*, CSTRUCT CPxVec3);
CPxAPI void CPxSceneDesc_set_cpuDispatcher(CSTRUCT CPxSceneDesc*, CSTRUCT CPxCpuDispatcher*);
CPxAPI void CPxSceneDesc_set_gravity(CSTRUCT CPxSceneDesc, CSTRUCT CPxVec3);
CPxAPI void CPxSceneDesc_set_cpuDispatcher(CSTRUCT CPxSceneDesc, CSTRUCT CPxCpuDispatcher);
//CPxSceneDesc_set_onContactCallback sets the contact callback handler of the given scene descriptor.
//The callback is sent an object of type 'CPxContactPairHeader*'. This object is only valid for the duration of the callback handler.
//Therefore, the callback handler MUST copy data it wishes to keep for longer than the lifetime of the callback handler, as the memory it was handed might be reused/freed.
// CPxSceneDesc_set_onContactCallback sets the on-contact callback handler of the given scene descriptor.
// The callback is sent an object of type 'CPxContactPairHeader*'. This object is only valid for the duration of the callback handler.
// Therefore, the callback handler MUST copy data it wishes to keep for longer than the lifetime of the callback handler, as the memory it was handed might be reused/freed.
//
//NOTE: This function assumes you are using the default physx-c callback handler. Do NOT use this function if you set 'sceneDesc->simulationEventCallback' with your own custom implementation.
CPxAPI void CPxSceneDesc_set_onContactCallback(CSTRUCT CPxSceneDesc*, CPxonContactCallback cb);
CPxAPI void FreeCPxSceneDesc(CSTRUCT CPxSceneDesc*);
// NOTE: This function assumes you are using the default physx-c callback handler. Do NOT use this function if you set 'sceneDesc->simulationEventCallback' with your own custom implementation.
CPxAPI void CPxSceneDesc_set_onContactCallback(CSTRUCT CPxSceneDesc, CPxOnContactCallback cb);
// CPxSceneDesc_set_onTriggerCallback sets the on-trigger callback handler of the given scene descriptor.
// The callback is sent an object of type 'CPxTriggerPairHeader*'. This object is only valid for the duration of the callback handler.
// Therefore, the callback handler MUST copy data it wishes to keep for longer than the lifetime of the callback handler, as the memory it was handed might be reused/freed.
//
// NOTE: This function assumes you are using the default physx-c callback handler. Do NOT use this function if you set 'sceneDesc->simulationEventCallback' with your own custom implementation.
CPxAPI void CPxSceneDesc_set_onTriggerCallback(CSTRUCT CPxSceneDesc csd, CPxOnTriggerCallback cb);
CPxAPI void FreeCPxSceneDesc(CSTRUCT CPxSceneDesc);
#ifdef __cplusplus
}

View File

@ -13,10 +13,10 @@ extern "C" {
void* obj;
};
CPxAPI void CPxShape_setLocalPose(CSTRUCT CPxShape* cs, CSTRUCT CPxTransform* tr);
CPxAPI CSTRUCT CPxTransform CPxShape_getLocalPose(CSTRUCT CPxShape* cs);
CPxAPI CSTRUCT CPxFilterData CPxShape_getSimulationFilterData(CSTRUCT CPxShape* cs);
CPxAPI void CPxShape_setSimulationFilterData(CSTRUCT CPxShape* cs, CSTRUCT CPxFilterData* cfd);
CPxAPI void CPxShape_setLocalPose(CSTRUCT CPxShape cs, CSTRUCT CPxTransform* tr);
CPxAPI CSTRUCT CPxTransform CPxShape_getLocalPose(CSTRUCT CPxShape cs);
CPxAPI CSTRUCT CPxFilterData CPxShape_getSimulationFilterData(CSTRUCT CPxShape cs);
CPxAPI void CPxShape_setSimulationFilterData(CSTRUCT CPxShape cs, CSTRUCT CPxFilterData* cfd);
#ifdef __cplusplus
}

View File

@ -10,7 +10,7 @@
extern "C" {
#endif
CPxAPI CSTRUCT CPxRigidStatic* CPxCreatePlane(CSTRUCT CPxPhysics* sdk, CSTRUCT CPxPlane* plane, CSTRUCT CPxMaterial* material);
CPxAPI CSTRUCT CPxRigidStatic CPxCreatePlane(CSTRUCT CPxPhysics sdk, CSTRUCT CPxPlane* plane, CSTRUCT CPxMaterial material);
#ifdef __cplusplus
}

27
pgo/physx-c/CPxTriggerPair.h Executable file
View File

@ -0,0 +1,27 @@
#ifndef CPxTriggerPair_H
#define CPxTriggerPair_H
#include "CPxShape.h"
#include "CPxPairFlag.h"
#include "CPxRigidActor.h"
#include "CPxTriggerPairFlag.h"
#ifdef __cplusplus
extern "C" {
#endif
struct CPxTriggerPair
{
CSTRUCT CPxShape triggerShape; //!< The shape that has been marked as a trigger.
CSTRUCT CPxRigidActor triggerActor; //!< The actor to which triggerShape is attached
CSTRUCT CPxShape otherShape; //!< The shape causing the trigger event. \deprecated (see #PxSimulationEventCallback::onTrigger()) If collision between trigger shapes is enabled, then this member might point to a trigger shape as well.
CSTRUCT CPxRigidActor otherActor; //!< The actor to which otherShape is attached
CENUM CPxPairFlag status; //!< Type of trigger event (eNOTIFY_TOUCH_FOUND or eNOTIFY_TOUCH_LOST). eNOTIFY_TOUCH_PERSISTS events are not supported.
CENUM CPxTriggerPairFlag flags; //!< Additional information on the pair (see #PxTriggerPairFlag)
};
#ifdef __cplusplus
}
#endif
#endif

View File

@ -0,0 +1,20 @@
#ifndef CPxTriggerPairFlag_H
#define CPxTriggerPairFlag_H
#ifdef __cplusplus
extern "C"
{
#endif
enum CPxTriggerPairFlag
{
eREMOVED_SHAPE_TRIGGER = (1 << 0), //!< The trigger shape has been removed from the actor/scene.
eREMOVED_SHAPE_OTHER = (1 << 1), //!< The shape causing the trigger event has been removed from the actor/scene.
eNEXT_FREE = (1 << 2) //!< For internal use only.
};
#ifdef __cplusplus
}
#endif
#endif

View File

@ -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
@ -10,7 +14,7 @@ package pgo
import "C"
type RigidDynamic struct {
cRd *C.struct_CPxRigidDynamic
cRd C.struct_CPxRigidDynamic
}
func (rd *RigidDynamic) AddForce(force *Vec3, fmode ForceMode, autoAwake bool) {
@ -25,14 +29,14 @@ func (rd *RigidDynamic) SetLinearDamping(damping float32) {
C.CPxRigidDynamic_setLinearDamping(rd.cRd, C.float(damping))
}
func (rd *RigidDynamic) SetAngularDamping(damping float32) {
C.CPxRigidDynamic_setAngularDamping(rd.cRd, C.float(damping))
}
func (rd *RigidDynamic) GetLinearDamping() float32 {
return float32(C.CPxRigidDynamic_getLinearDamping(rd.cRd))
}
func (rd *RigidDynamic) SetAngularDamping(damping float32) {
C.CPxRigidDynamic_setAngularDamping(rd.cRd, C.float(damping))
}
func (rd *RigidDynamic) GetAngularDamping() float32 {
return float32(C.CPxRigidDynamic_getAngularDamping(rd.cRd))
}
@ -43,12 +47,36 @@ func (rd *RigidDynamic) GetLinearVelocity() Vec3 {
}
}
func (rd *RigidDynamic) SetLinearVelocity(vel *Vec3, autoWake bool) {
C.CPxRigidDynamic_setLinearVelocity(rd.cRd, &vel.cV, C._Bool(autoWake))
}
func (rd *RigidDynamic) GetAngularVelocity() Vec3 {
return Vec3{
cV: C.CPxRigidDynamic_getAngularVelocity(rd.cRd),
}
}
func (rd *RigidDynamic) SetAngularVelocity(vel *Vec3, autoWake bool) {
C.CPxRigidDynamic_setAngularVelocity(rd.cRd, &vel.cV, C._Bool(autoWake))
}
func (rd *RigidDynamic) GetMaxLinearVelocity() float32 {
return float32(C.CPxRigidDynamic_getMaxLinearVelocity(rd.cRd))
}
func (rd *RigidDynamic) SetMaxLinearVelocity(vel float32) {
C.CPxRigidDynamic_setMaxLinearVelocity(rd.cRd, C.float(vel))
}
func (rd *RigidDynamic) GetMaxAngularVelocity() float32 {
return float32(C.CPxRigidDynamic_getMaxAngularVelocity(rd.cRd))
}
func (rd *RigidDynamic) SetMaxAngularVelocity(vel float32) {
C.CPxRigidDynamic_setMaxAngularVelocity(rd.cRd, C.float(vel))
}
func (rd *RigidDynamic) SetMass(mass float32) {
C.CPxRigidDynamic_setMass(rd.cRd, C.float(mass))
}
@ -117,8 +145,15 @@ func (rd *RigidDynamic) ToRigidActor() RigidActor {
}
}
func CreateDynamic(p *Physics, t *Transform, g *Geometry, m *Material, density float32, shapeOffset *Transform) *RigidDynamic {
return &RigidDynamic{
func CreateDynamic(p Physics, t *Transform, g Geometry, m Material, density float32, shapeOffset *Transform) RigidDynamic {
if shapeOffset == nil {
return RigidDynamic{
cRd: C.CPxCreateDynamic(p.cPhysics, &t.cT, g.cG, m.cM, C.float(density), nil),
}
}
return RigidDynamic{
cRd: C.CPxCreateDynamic(p.cPhysics, &t.cT, g.cG, m.cM, C.float(density), &shapeOffset.cT),
}
}

9
pgo/triggerPairFlag.go Executable file
View File

@ -0,0 +1,9 @@
package pgo
type TriggerPairFlag uint32
const (
TriggerPairFlag_eREMOVED_SHAPE_TRIGGER TriggerPairFlag = (1 << 0) //!< The trigger shape has been removed from the actor/scene.
TriggerPairFlag_eREMOVED_SHAPE_OTHER TriggerPairFlag = (1 << 1) //!< The shape causing the trigger event has been removed from the actor/scene.
TriggerPairFlag_eNEXT_FREE TriggerPairFlag = (1 << 2) //!< For internal use only.
)

View File

@ -39,4 +39,5 @@
#include <CPxSimpleFactory.h>
#include <CPxTriggerPair.h>
#include <CPxContactPairHeader.h>

38
switch-physx-mode.sh Executable file
View File

@ -0,0 +1,38 @@
#!/bin/bash
set -e
if [[ $# -ne 1 ]]; then
echo -e "1) Checked mode\n2) Release mode"
exit 0
fi
mode=$1
physxBinDir="../physx/physx/bin/win.x86_64.vc142.mt"
physxCBinDir="../physx-c/x64"
if [[ $mode -eq 1 ]]; then
physxCheckedBinDir="$physxBinDir/checked"
cp "$physxCheckedBinDir/PhysX_64.dll" "$physxCheckedBinDir/PhysXCommon_64.dll" "$physxCheckedBinDir/PhysXFoundation_64.dll" .
physxCCheckedBinDir="$physxCBinDir/Checked"
cp "$physxCCheckedBinDir/physx-c.dll" .
echo "Switched PhysX to Checked mode"
elif [[ $mode -eq 2 ]]; then
physxReleaseBinDir="$physxBinDir/release"
cp "$physxReleaseBinDir/PhysX_64.dll" "$physxReleaseBinDir/PhysXCommon_64.dll" "$physxReleaseBinDir/PhysXFoundation_64.dll" .
physxCReleaseBinDir="$physxCBinDir/Release"
cp "$physxCReleaseBinDir/physx-c.dll" .
echo "Switched PhysX to Release mode"
else
echo "Unknown mode. Please select 1 or 2"
exit 1
fi