diff --git a/main.go b/main.go index aed5a75..d4e1b12 100755 --- a/main.go +++ b/main.go @@ -33,10 +33,28 @@ func main() { 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) - groundPlane := pgo.CreatePlane(p, pgo.NewPlane(0, 1, 0, 1), pMat) + groundPlane := pgo.CreatePlane(p, pgo.NewPlane(0, 1, 0, 0), pMat) s.AddActor(groundPlane.ToActor()) + //Add dynamic box + v := pgo.NewVec3(0, 10, 0) + q := pgo.NewQuat(0, 0, 1, 0) + tr := pgo.NewTransform(v, q) + + qID := pgo.NewQuat(0, 0, 1, 0) + shapeOffset := pgo.NewTransform(v, qID) + + box := pgo.NewBoxGeometry(0.5, 0.5, 0.5) + dynBox := pgo.CreateDynamic(p, tr, box.ToGeometry(), pMat, 10, shapeOffset) + s.AddActor(dynBox.ToActor()) + + v = pgo.NewVec3(0.5, 12, 0) + tr2 := pgo.NewTransform(v, qID) + dynBox2 := pgo.CreateDynamic(p, tr2, box.ToGeometry(), pMat, 10, shapeOffset) + s.AddActor(dynBox2.ToActor()) + for { s.Simulate(1 / 60.0) a, b := s.FetchResults(true) diff --git a/pgo/libs/libphysx-c.a b/pgo/libs/libphysx-c.a index e75609b..9a89d38 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 d1871c6..ad24011 100755 --- a/pgo/pgo.go +++ b/pgo/pgo.go @@ -6,50 +6,6 @@ package pgo #include #include //Needed for C.free - -//Functions -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); - -//PxPhysics -struct CPxPhysics* CPxCreatePhysics(struct CPxFoundation* cfoundation, struct CPxTolerancesScale cscale, bool trackOutstandingAllocations, struct CPxPvd* cpvd); -struct CPxScene* CPxPhysics_createScene(struct CPxPhysics*, struct CPxSceneDesc*); -struct CPxMaterial* CPxPhysics_createMaterial(struct CPxPhysics*, CPxReal staticFriction, CPxReal dynamicFriction, CPxReal restitution); -void CPxPhysics_release(struct CPxPhysics*); - -//PxScene -struct CPxPvdSceneClient* CPxScene_getScenePvdClient(struct CPxScene*); -void CPxScene_addActor(struct CPxScene*, struct CPxActor* actor); -void CPxScene_simulate(struct CPxScene*, CPxReal elapsedTime); -bool CPxScene_fetchResults(struct CPxScene*, bool block, CPxU32* errorState); - -void CPxPvdSceneClient_setScenePvdFlag(struct CPxPvdSceneClient* c, enum CPxPvdSceneFlag flag, bool value); - -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*); - -//Plane -struct CPxPlane* NewCPxPlane(float nx, float ny, float nz, float distance); - -//RigidStatic -struct CPxRigidStatic* CPxCreatePlane(struct CPxPhysics* sdk, struct CPxPlane* plane, struct CPxMaterial* material); -struct CPxActor* CPxRigidStatic_toCPxActor(struct CPxRigidStatic*); - */ import "C" @@ -256,24 +212,98 @@ func NewPlane(nx, ny, nz, distance float32) *Plane { } } +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)), + } +} + +type Transform struct { + cT C.struct_CPxTransform +} + +// struct CPxTransform NewCPxTransform(struct CPxVec3*, struct CPxQuat*); +func NewTransform(v *Vec3, q *Quat) *Transform { + return &Transform{ + cT: C.NewCPxTransform(&v.cV, &q.cQ), + } +} + +type Geometry struct { + cG C.struct_CPxGeometry +} + +type SphereGeometry struct { + cSg C.struct_CPxSphereGeometry +} + +// struct CPxGeometry CPxSphereGeometry_toCPxGeometry(struct CPxSphereGeometry*); +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{ + cSg: C.NewCPxSphereGeometry(C.float(radius)), + } +} + +type BoxGeometry struct { + cBg C.struct_CPxBoxGeometry +} + +func (bg *BoxGeometry) ToGeometry() *Geometry { + return &Geometry{ + cG: C.CPxBoxGeometry_toCPxGeometry(&bg.cBg), + } +} + +func NewBoxGeometry(hx, hy, hz float32) *BoxGeometry { + return &BoxGeometry{ + cBg: C.NewCPxBoxGeometry(C.float(hx), C.float(hy), C.float(hz)), + } +} + type Actor struct { - cA *C.struct_CPxActor + cA C.struct_CPxActor } type RigidStatic struct { cRs *C.struct_CPxRigidStatic } -//struct CPxActor* CPxRigidStatic_toCPxActor(struct CPxRigidStatic*); func (rs *RigidStatic) ToActor() *Actor { return &Actor{ cA: C.CPxRigidStatic_toCPxActor(rs.cRs), } } -// struct CPxRigidStatic* CPxCreatePlane(struct CPxPhysics* sdk, struct CPxPlane* plane, struct CPxMaterial* material); func CreatePlane(p *Physics, plane *Plane, mat *Material) *RigidStatic { return &RigidStatic{ cRs: C.CPxCreatePlane(p.cPhysics, plane.cP, mat.cM), } } + +type RigidDynamic struct { + cRd *C.struct_CPxRigidDynamic +} + +func (rs *RigidDynamic) ToActor() *Actor { + return &Actor{ + cA: C.CPxRigidDynamic_toCPxActor(rs.cRd), + } +} + +func CreateDynamic(p *Physics, t *Transform, g *Geometry, m *Material, density float32, shapeOffset *Transform) *RigidDynamic { + return &RigidDynamic{ + cRd: C.CPxCreateDynamic(p.cPhysics, &t.cT, g.cG, m.cM, C.float(density), &shapeOffset.cT), + } +} diff --git a/pgo/physx-c/CExtSimpleFactory.h b/pgo/physx-c/CExtSimpleFactory.h new file mode 100755 index 0000000..7fc668b --- /dev/null +++ b/pgo/physx-c/CExtSimpleFactory.h @@ -0,0 +1,19 @@ +#ifndef CExtSimpleFactory_H +#define CExtSimpleFactory_H + +#include "CPxPhysics.h" +#include "CPxGeometry.h" +#include "CPxTransform.h" +#include "CPxRigidDynamic.h" + +#ifdef __cplusplus +extern "C" { +#endif + + CPxAPI CSTRUCT CPxRigidDynamic* CPxCreateDynamic(CSTRUCT CPxPhysics* sdk, CSTRUCT CPxTransform* transform, CSTRUCT CPxGeometry geometry, CSTRUCT CPxMaterial* material, CPxReal density, CSTRUCT CPxTransform* shapeOffset); + +#ifdef __cplusplus +} +#endif + +#endif // !CExtSimpleFactory_H diff --git a/pgo/physx-c/CPxBoxGeometry.h b/pgo/physx-c/CPxBoxGeometry.h new file mode 100755 index 0000000..54a7691 --- /dev/null +++ b/pgo/physx-c/CPxBoxGeometry.h @@ -0,0 +1,19 @@ +#ifndef CPxBoxGeometry_H +#define CPxBoxGeometry_H + +#ifdef __cplusplus +extern "C" { +#endif + + struct CPxBoxGeometry + { + float hx, hy, hz; + }; + + CPxAPI CPxInline CSTRUCT CPxBoxGeometry NewCPxBoxGeometry(float hx, float hy, float hz); + +#ifdef __cplusplus +} +#endif + +#endif // !CPxBoxGeometry_H \ No newline at end of file diff --git a/pgo/physx-c/CPxGeometry.h b/pgo/physx-c/CPxGeometry.h new file mode 100755 index 0000000..56726a4 --- /dev/null +++ b/pgo/physx-c/CPxGeometry.h @@ -0,0 +1,41 @@ +#ifndef CPxGeometry_H +#define CPxGeometry_H + +#include "CPxBoxGeometry.h" +#include "CPxSphereGeometry.h" + +#ifdef __cplusplus +extern "C" { +#endif + + enum CPxGeometryType + { + CPxGeometryType_eSPHERE, + CPxGeometryType_ePLANE, + CPxGeometryType_eCAPSULE, + CPxGeometryType_eBOX, + CPxGeometryType_eCONVEXMESH, + CPxGeometryType_eTRIANGLEMESH, + CPxGeometryType_eHEIGHTFIELD, + CPxGeometryType_eGEOMETRY_COUNT, //!< internal use only! + CPxGeometryType_eINVALID = -1 //!< internal use only! + }; + + struct CPxGeometry + { + void* obj; + CENUM CPxGeometryType type; + }; + + CPxAPI CPxInline CSTRUCT CPxSphereGeometry CPxGeometry_toCPxSphere(CSTRUCT CPxGeometry); + CPxAPI CPxInline CSTRUCT CPxGeometry CPxSphereGeometry_toCPxGeometry(CSTRUCT CPxSphereGeometry*); + + CPxAPI CPxInline CSTRUCT CPxBoxGeometry CPxGeometry_toCPxBox(CSTRUCT CPxGeometry); + CPxAPI CPxInline CSTRUCT CPxGeometry CPxBoxGeometry_toCPxGeometry(CSTRUCT CPxBoxGeometry*); + + +#ifdef __cplusplus +} +#endif + +#endif // !CPxGeometry_H \ No newline at end of file diff --git a/pgo/physx-c/CPxPlane.h b/pgo/physx-c/CPxPlane.h index 19382e2..6be53e7 100755 --- a/pgo/physx-c/CPxPlane.h +++ b/pgo/physx-c/CPxPlane.h @@ -5,6 +5,7 @@ extern "C" { #endif + //TODO: Maybe convert this into a value type like CPxSphereGeometry? struct CPxPlane { void* obj; diff --git a/pgo/physx-c/CPxQuat.h b/pgo/physx-c/CPxQuat.h new file mode 100755 index 0000000..3a973ee --- /dev/null +++ b/pgo/physx-c/CPxQuat.h @@ -0,0 +1,19 @@ +#ifndef CPxQuat_H +#define CPxQuat_H + +#ifdef __cplusplus +extern "C" { +#endif + + struct CPxQuat + { + float x, y, z, w; + }; + + CPxAPI CPxInline CSTRUCT CPxQuat NewCPxQuat(float angleRads, float x, float y, float z); + +#ifdef __cplusplus +} +#endif + +#endif // !CPxQuat_H diff --git a/pgo/physx-c/CPxRigidDynamic.h b/pgo/physx-c/CPxRigidDynamic.h new file mode 100755 index 0000000..e37be01 --- /dev/null +++ b/pgo/physx-c/CPxRigidDynamic.h @@ -0,0 +1,21 @@ +#ifndef CPxRigidDynamic_H +#define CPxRigidDynamic_H + +#include "CPxActor.h" + +#ifdef __cplusplus +extern "C" { +#endif + + struct CPxRigidDynamic + { + void* obj; + }; + + CPxAPI CSTRUCT CPxActor CPxRigidDynamic_toCPxActor(CSTRUCT CPxRigidDynamic*); + +#ifdef __cplusplus +} +#endif + +#endif // !CPxRigidDynamic_H \ No newline at end of file diff --git a/pgo/physx-c/CPxRigidStatic.h b/pgo/physx-c/CPxRigidStatic.h index 6fd37d9..248ec9a 100755 --- a/pgo/physx-c/CPxRigidStatic.h +++ b/pgo/physx-c/CPxRigidStatic.h @@ -16,7 +16,7 @@ extern "C" { }; CPxAPI CSTRUCT CPxRigidStatic* CPxCreatePlane(CSTRUCT CPxPhysics* sdk, CSTRUCT CPxPlane* plane, CSTRUCT CPxMaterial* material); - CPxAPI CSTRUCT CPxActor* CPxRigidStatic_toCPxActor(CSTRUCT CPxRigidStatic*); + CPxAPI CSTRUCT CPxActor CPxRigidStatic_toCPxActor(CSTRUCT CPxRigidStatic*); #ifdef __cplusplus } diff --git a/pgo/physx-c/CPxScene.h b/pgo/physx-c/CPxScene.h index 7ed75ce..6c39400 100755 --- a/pgo/physx-c/CPxScene.h +++ b/pgo/physx-c/CPxScene.h @@ -14,7 +14,7 @@ extern "C" { }; CPxAPI CSTRUCT CPxPvdSceneClient* CPxScene_getScenePvdClient(CSTRUCT CPxScene*); - CPxAPI void CPxScene_addActor(CSTRUCT CPxScene*, CSTRUCT CPxActor* actor); + CPxAPI void CPxScene_addActor(CSTRUCT CPxScene*, CSTRUCT CPxActor actor); CPxAPI void CPxScene_simulate(CSTRUCT CPxScene*, CPxReal elapsedTime); CPxAPI bool CPxScene_fetchResults(CSTRUCT CPxScene*, bool block, CPxU32* errorState); diff --git a/pgo/physx-c/CPxSphereGeometry.h b/pgo/physx-c/CPxSphereGeometry.h new file mode 100755 index 0000000..6803937 --- /dev/null +++ b/pgo/physx-c/CPxSphereGeometry.h @@ -0,0 +1,19 @@ +#ifndef CPxSphereGeometry_H +#define CPxSphereGeometry_H + +#ifdef __cplusplus +extern "C" { +#endif + + struct CPxSphereGeometry + { + CPxReal radius; + }; + + CPxAPI CPxInline CSTRUCT CPxSphereGeometry NewCPxSphereGeometry(CPxReal radius); + +#ifdef __cplusplus +} +#endif + +#endif // !CPxSphereGeometry_H \ No newline at end of file diff --git a/pgo/physx-c/CPxTransform.h b/pgo/physx-c/CPxTransform.h new file mode 100755 index 0000000..a9f01e6 --- /dev/null +++ b/pgo/physx-c/CPxTransform.h @@ -0,0 +1,23 @@ +#ifndef CPxTransform_H +#define CPxTransform_H + +#include "CPxVec3.h" +#include "CPxQuat.h" + +#ifdef __cplusplus +extern "C" { +#endif + + struct CPxTransform + { + CSTRUCT CPxVec3 p; + CSTRUCT CPxQuat q; + }; + + CPxAPI CPxInline CSTRUCT CPxTransform NewCPxTransform(CSTRUCT CPxVec3*, CSTRUCT CPxQuat*); + +#ifdef __cplusplus +} +#endif + +#endif // !CPxTransform_H \ No newline at end of file diff --git a/pgo/physx-c/CPxVec3.h b/pgo/physx-c/CPxVec3.h index d4ee78d..1ae9197 100755 --- a/pgo/physx-c/CPxVec3.h +++ b/pgo/physx-c/CPxVec3.h @@ -9,7 +9,7 @@ extern "C" { float x, y, z; }; - CPxAPI CSTRUCT CPxVec3 NewCPxVec3(float x, float y, float z); + CPxAPI CPxInline CSTRUCT CPxVec3 NewCPxVec3(float x, float y, float z); #ifdef __cplusplus } diff --git a/pgo/wrap.cxx b/pgo/wrap.cxx index ebf42a9..6904302 100755 --- a/pgo/wrap.cxx +++ b/pgo/wrap.cxx @@ -1,6 +1,7 @@ #include #include #define CPxAPI +#define CPxInline #define CSTRUCT struct #define CENUM enum #define CPxU32 uint32_t @@ -15,8 +16,13 @@ #include #include #include -#include #include #include #include +#include +#include #include +#include +#include +#include +#include \ No newline at end of file