diff --git a/main.go b/main.go
index b10ebaa..fa3a299 100755
--- a/main.go
+++ b/main.go
@@ -9,15 +9,29 @@ func main() {
defer f.Release()
println("foundation:", f)
- pvd := pgo.CreatePvd(f)
- // defer pvd.Release()
- println("Pvd:", pvd)
-
- pvdTr := pgo.DefaultPvdSocketTransportCreate("127.0.0.1", 9876, 500)
- // defer pvdTr.Release()
+ pvdTr := pgo.DefaultPvdSocketTransportCreate("0.0.0.0", 5426, 100000)
println("Pvd transport:", pvdTr)
- // for {
- // time.Sleep(1 / 60 * time.Second)
- // }
+ pvd := pgo.CreatePvd(f)
+ println("Pvd:", pvd)
+ println("connect:", pvd.Connect(pvdTr, pgo.PvdInstrumentationFlag_eALL))
+
+ ts := pgo.NewTolerancesScale(1, 9.81)
+ p := pgo.CreatePhysics(f, ts, false, pvd)
+ println("Physics:", p)
+
+ sd := pgo.NewSceneDesc(ts)
+ sd.SetGravity(pgo.NewVec3(0, -9.8, 0))
+ sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, 0).ToCpuDispatcher())
+
+ s := p.CreateScene(sd)
+ println("Scene:", s)
+
+ for {
+
+ }
+
+ p.Release()
+ pvd.Release()
+ pvdTr.Release()
}
diff --git a/pgo/libs/libphysx-c.a b/pgo/libs/libphysx-c.a
index 823f088..b42540a 100755
Binary files a/pgo/libs/libphysx-c.a and b/pgo/libs/libphysx-c.a differ
diff --git a/pgo/pgo.go b/pgo/pgo.go
index 1247910..ca11bf3 100755
--- a/pgo/pgo.go
+++ b/pgo/pgo.go
@@ -12,14 +12,39 @@ struct CPxFoundation* CPxCreateFoundation();
void CPxFoundation_release(struct CPxFoundation*);
struct CPxPvd* CPxCreatePvd(struct CPxFoundation*);
+bool CPxPvd_connect(struct CPxPvd*, struct CPxPvdTransport*, enum CPxPvdInstrumentationFlag);
void CPxPvd_release(struct CPxPvd*);
struct CPxPvdTransport* CPxDefaultPvdSocketTransportCreate(const char* address, int port, int timeoutMillis);
void CPxPvdTransport_release(struct CPxPvdTransport* cppt);
+
+struct CPxTolerancesScale NewCPxTolerancesScale(CPxReal length, CPxReal speed);
+
+struct CPxPhysics* CPxCreatePhysics(struct CPxFoundation* cfoundation, struct CPxTolerancesScale cscale, bool trackOutstandingAllocations, struct CPxPvd* cpvd);
+struct CPxScene* CPxPhysics_createScene(struct CPxPhysics*, struct CPxSceneDesc*);
+void CPxPhysics_release(struct CPxPhysics*);
+
+struct CPxVec3 NewCPxVec3(float x, float y, float z);
+
+struct CPxDefaultCpuDispatcher* CPxDefaultCpuDispatcherCreate(CPxU32 numThreads, CPxU32 affinityMasks);
+struct CPxCpuDispatcher* CPxDefaultCpuDispatcher_toCPxCpuDispatcher(struct CPxDefaultCpuDispatcher* cdcd);
+
+struct CPxSceneDesc* NewCPxSceneDesc(struct CPxTolerancesScale);
+void CPxSceneDesc_set_gravity(struct CPxSceneDesc*, struct CPxVec3);
+void CPxSceneDesc_set_cpuDispatcher(struct CPxSceneDesc*, struct CPxCpuDispatcher*);
*/
import "C"
import "unsafe"
+type PvdInstrumentationFlag uint32
+
+const (
+ PvdInstrumentationFlag_eDEBUG PvdInstrumentationFlag = 1 << 0
+ PvdInstrumentationFlag_ePROFILE PvdInstrumentationFlag = 1 << 1
+ PvdInstrumentationFlag_eMEMORY PvdInstrumentationFlag = 1 << 2
+ PvdInstrumentationFlag_eALL PvdInstrumentationFlag = (PvdInstrumentationFlag_eDEBUG | PvdInstrumentationFlag_ePROFILE | PvdInstrumentationFlag_eMEMORY)
+)
+
type Foundation struct {
cFoundation *C.struct_CPxFoundation
}
@@ -40,6 +65,10 @@ type Pvd struct {
cPvd *C.struct_CPxPvd
}
+func (p *Pvd) Connect(pvdTr *PvdTransport, instFlag PvdInstrumentationFlag) bool {
+ return bool(C.CPxPvd_connect(p.cPvd, pvdTr.cPvdTr, uint32(instFlag)))
+}
+
func (p *Pvd) Release() {
C.CPxPvd_release(p.cPvd)
}
@@ -67,6 +96,91 @@ func DefaultPvdSocketTransportCreate(host string, port, timeoutMillis int) *PvdT
p := &PvdTransport{}
p.cPvdTr = C.CPxDefaultPvdSocketTransportCreate(hostCStr, C.int(port), C.int(timeoutMillis))
+ return p
+}
+
+type TolerancesScale struct {
+ cTolScale C.struct_CPxTolerancesScale
+}
+
+func NewTolerancesScale(length, speed float32) *TolerancesScale {
+
+ ts := &TolerancesScale{}
+ ts.cTolScale = C.NewCPxTolerancesScale(C.float(length), C.float(speed))
+ return ts
+}
+
+type Scene struct {
+ cS *C.struct_CPxScene
+}
+
+type Physics struct {
+ cPhysics *C.struct_CPxPhysics
+}
+
+// struct CPxScene* CPxPhysics_createScene(struct CPxPhysics*, struct CPxSceneDesc*);
+func (p *Physics) CreateScene(sd *SceneDesc) *Scene {
+ return &Scene{
+ cS: C.CPxPhysics_createScene(p.cPhysics, sd.cSD),
+ }
+}
+
+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)
return p
}
+
+func (p *Physics) Release() {
+ C.CPxPhysics_release(p.cPhysics)
+}
+
+type Vec3 struct {
+ cV C.struct_CPxVec3
+}
+
+func NewVec3(x, y, z float32) *Vec3 {
+ return &Vec3{
+ cV: C.NewCPxVec3(C.float(x), C.float(y), C.float(z)),
+ }
+}
+
+type CpuDispatcher struct {
+ cCpuDisp *C.struct_CPxCpuDispatcher
+}
+
+type DefaultCpuDispatcher struct {
+ cDefCpuDisp *C.struct_CPxDefaultCpuDispatcher
+}
+
+// struct CPxCpuDispatcher* CPxDefaultCpuDispatcher_toCPxCpuDispatcher(struct CPxDefaultCpuDispatcher* cdcd);
+func (d *DefaultCpuDispatcher) ToCpuDispatcher() *CpuDispatcher {
+ return &CpuDispatcher{cCpuDisp: (*C.struct_CPxCpuDispatcher)(d.cDefCpuDisp)}
+}
+
+func DefaultCpuDispatcherCreate(numThreads, affinityMasks uint32) *DefaultCpuDispatcher {
+ return &DefaultCpuDispatcher{
+ cDefCpuDisp: C.CPxDefaultCpuDispatcherCreate(C.uint(numThreads), C.uint(affinityMasks)),
+ }
+}
+
+type SceneDesc struct {
+ cSD *C.struct_CPxSceneDesc
+}
+
+func (sd *SceneDesc) SetGravity(v *Vec3) {
+ C.CPxSceneDesc_set_gravity(sd.cSD, v.cV)
+}
+
+func (sd *SceneDesc) SetCpuDispatcher(cd *CpuDispatcher) {
+ C.CPxSceneDesc_set_cpuDispatcher(sd.cSD, cd.cCpuDisp)
+}
+
+//struct CPxSceneDesc* NewCPxSceneDesc(struct CPxTolerancesScale);
+func NewSceneDesc(ts *TolerancesScale) *SceneDesc {
+ return &SceneDesc{
+ cSD: C.NewCPxSceneDesc(ts.cTolScale),
+ }
+}
diff --git a/pgo/physx-c/CPxCpuDispatcher.h b/pgo/physx-c/CPxCpuDispatcher.h
new file mode 100755
index 0000000..bde6a4a
--- /dev/null
+++ b/pgo/physx-c/CPxCpuDispatcher.h
@@ -0,0 +1,25 @@
+#ifndef CPxCpuDispatcher_H
+#define CPxCpuDispatcher_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ struct CPxCpuDispatcher
+ {
+ void* obj;
+ };
+
+ ///
+ /// 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)
+ ///
+ ///
+ ///
+ CPxAPI void CPxCpuDispatcher_release(CSTRUCT CPxCpuDispatcher*);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !PxCpuDispatcher_H
\ No newline at end of file
diff --git a/pgo/physx-c/CPxDefaultCpuDispatcher.h b/pgo/physx-c/CPxDefaultCpuDispatcher.h
new file mode 100755
index 0000000..4a161e1
--- /dev/null
+++ b/pgo/physx-c/CPxDefaultCpuDispatcher.h
@@ -0,0 +1,22 @@
+#ifndef CPxDefaultCpuDispatcher_H
+#define CPxDefaultCpuDispatcher_H
+
+#include "CPxCpuDispatcher.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ struct CPxDefaultCpuDispatcher {
+ 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);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !CPxDefaultCpuDispatcher_H
\ No newline at end of file
diff --git a/pgo/physx-c/CPxDefaultSimulationFilterShader.h b/pgo/physx-c/CPxDefaultSimulationFilterShader.h
new file mode 100755
index 0000000..fce7c60
--- /dev/null
+++ b/pgo/physx-c/CPxDefaultSimulationFilterShader.h
@@ -0,0 +1,20 @@
+#ifndef CPxDefaultSimulationFilterShader_H
+#define CPxDefaultSimulationFilterShader_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ struct CPxDefaultSimulationFilterShader
+ {
+ void* obj;
+ };
+
+ //CPxAPI CSTRUCT CPxDefaultSimulationFilterShader* NewCPxDefaultSimulationFilterShader();
+ //CPxAPI void FreeCPxDefaultSimulationFilterShader(CSTRUCT CPxDefaultSimulationFilterShader*);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !CPxDefaultSimulationFilterShader_H
diff --git a/pgo/physx-c/CPxFoundation.h b/pgo/physx-c/CPxFoundation.h
index 4edbd82..7e40b98 100755
--- a/pgo/physx-c/CPxFoundation.h
+++ b/pgo/physx-c/CPxFoundation.h
@@ -1,5 +1,5 @@
-#ifndef __CPxFoundation_H__
-#define __CPxFoundation_H__
+#ifndef CPxFoundation_H
+#define CPxFoundation_H
#ifdef __cplusplus
extern "C" {
diff --git a/pgo/physx-c/CPxPhysics.h b/pgo/physx-c/CPxPhysics.h
new file mode 100755
index 0000000..8eeb427
--- /dev/null
+++ b/pgo/physx-c/CPxPhysics.h
@@ -0,0 +1,26 @@
+#ifndef CPxPhysics_H
+#define CPxPhysics_H
+
+#include "CPxPvd.h"
+#include "CPxFoundation.h"
+#include "CPxScene.h"
+#include "CPxSceneDesc.h"
+#include "CPxTolerancesScale.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ struct CPxPhysics {
+ 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 void CPxPhysics_release(CSTRUCT CPxPhysics*);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/pgo/physx-c/CPxPvd.h b/pgo/physx-c/CPxPvd.h
index 8053702..2fb3cb7 100755
--- a/pgo/physx-c/CPxPvd.h
+++ b/pgo/physx-c/CPxPvd.h
@@ -1,17 +1,69 @@
-#ifndef __CPxPvd_H__
-#define __CPxPvd_H__
+#ifndef CPxPvd_H
+#define CPxPvd_H
#include "CPxFoundation.h"
+#include "CPxPvdTransport.h"
#ifdef __cplusplus
extern "C" {
#endif
+
+ enum CPxPvdInstrumentationFlag
+ {
+ /**
+ \brief Send debugging information to PVD.
+
+ This information is the actual object data of the rigid statics, shapes,
+ articulations, etc. Sending this information has a noticeable impact on
+ performance and thus this flag should not be set if you want an accurate
+ performance profile.
+ */
+ CPxPvdInstrumentationFlag_eDEBUG = 1 << 0,
+
+ /**
+ \brief Send profile information to PVD.
+
+ This information populates PVD's profile view. It has (at this time) negligible
+ cost compared to Debug information and makes PVD *much* more useful so it is quite
+ highly recommended.
+
+ This flag works together with a PxCreatePhysics parameter.
+ Using it allows the SDK to send profile events to PVD.
+ */
+ CPxPvdInstrumentationFlag_ePROFILE = 1 << 1,
+
+ /**
+ \brief Send memory information to PVD.
+
+ The PVD sdk side hooks into the Foundation memory controller and listens to
+ allocation/deallocation events. This has a noticable hit on the first frame,
+ however, this data is somewhat compressed and the PhysX SDK doesn't allocate much
+ once it hits a steady state. This information also has a fairly negligible
+ impact and thus is also highly recommended.
+
+ This flag works together with a PxCreatePhysics parameter,
+ trackOutstandingAllocations. Using both of them together allows users to have
+ an accurate view of the overall memory usage of the simulation at the cost of
+ a hashtable lookup per allocation/deallocation. Again, PhysX makes a best effort
+ attempt not to allocate or deallocate during simulation so this hashtable lookup
+ tends to have no effect past the first frame.
+
+ Sending memory information without tracking outstanding allocations means that
+ PVD will accurate information about the state of the memory system before the
+ actual connection happened.
+ */
+ CPxPvdInstrumentationFlag_eMEMORY = 1 << 2,
+
+ eALL = (CPxPvdInstrumentationFlag_eDEBUG | CPxPvdInstrumentationFlag_ePROFILE | CPxPvdInstrumentationFlag_eMEMORY)
+ };
+
struct CPxPvd
{
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);
#ifdef __cplusplus
}
diff --git a/pgo/physx-c/CPxPvdTransport.h b/pgo/physx-c/CPxPvdTransport.h
index fdaf709..4c077a2 100755
--- a/pgo/physx-c/CPxPvdTransport.h
+++ b/pgo/physx-c/CPxPvdTransport.h
@@ -1,5 +1,5 @@
-#ifndef __CPxPvdTransport_H__
-#define __CPxPvdTransport_H__
+#ifndef CPxPvdTransport_H
+#define CPxPvdTransport_H
#ifdef __cplusplus
extern "C" {
diff --git a/pgo/physx-c/CPxScene.h b/pgo/physx-c/CPxScene.h
new file mode 100755
index 0000000..deea264
--- /dev/null
+++ b/pgo/physx-c/CPxScene.h
@@ -0,0 +1,20 @@
+#ifndef CPxScene_H
+#define CPxScene_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ struct CPxScene
+ {
+ void* obj;
+ };
+
+ CPxAPI void CPxScene_release(CSTRUCT CPxScene*);
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif // !CPxScene_H
diff --git a/pgo/physx-c/CPxSceneDesc.h b/pgo/physx-c/CPxSceneDesc.h
new file mode 100755
index 0000000..84ba6d3
--- /dev/null
+++ b/pgo/physx-c/CPxSceneDesc.h
@@ -0,0 +1,30 @@
+#ifndef CPxSceneDesc_H
+#define CPxSceneDesc_H
+
+#include "CPxTolerancesScale.h"
+#include "CPxVec3.h"
+#include "CPxCpuDispatcher.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ struct CPxSceneDesc {
+ void* obj;
+ };
+
+ ///
+ /// Creates a SceneDesc with filterShader=physx::PxDefaultSimulationFilterShader
+ ///
+ ///
+ ///
+ 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 FreeCPxSceneDesc(CSTRUCT CPxSceneDesc*);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/pgo/physx-c/CPxTolerancesScale.h b/pgo/physx-c/CPxTolerancesScale.h
new file mode 100755
index 0000000..f898062
--- /dev/null
+++ b/pgo/physx-c/CPxTolerancesScale.h
@@ -0,0 +1,19 @@
+#ifndef CPxTolerancesScale_H
+#define CPxTolerancesScale_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ struct CPxTolerancesScale
+ {
+ CPxReal length, speed;
+ };
+
+ CPxAPI CSTRUCT CPxTolerancesScale NewCPxTolerancesScale(CPxReal length, CPxReal speed);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
\ No newline at end of file
diff --git a/pgo/physx-c/CPxVec3.h b/pgo/physx-c/CPxVec3.h
new file mode 100755
index 0000000..d4ee78d
--- /dev/null
+++ b/pgo/physx-c/CPxVec3.h
@@ -0,0 +1,18 @@
+#ifndef CPxVec3_H
+#define CPxVec3_H
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+ struct CPxVec3 {
+ float x, y, z;
+ };
+
+ CPxAPI CSTRUCT CPxVec3 NewCPxVec3(float x, float y, float z);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif // !define CPxVec3_H
\ No newline at end of file
diff --git a/pgo/wrap.cxx b/pgo/wrap.cxx
index b120050..36265ec 100755
--- a/pgo/wrap.cxx
+++ b/pgo/wrap.cxx
@@ -1,4 +1,18 @@
+#include
+#include
#define CPxAPI
#define CSTRUCT struct
+#define CENUM enum
+#define CPxU32 uint32_t
+#define CPxReal float
+
#include
#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include
+#include