From dddb8a65d5b862560af012eeeecd4adac015ce34 Mon Sep 17 00:00:00 2001 From: bloeys Date: Fri, 18 Feb 2022 03:39:11 +0400 Subject: [PATCH] Full onContact data+inlining --- go.mod | 2 + go.sum | 2 + main.go | 28 +-- pgo/contactPairFlag.go | 47 +++++ pgo/contactPairHeaderFlag.go | 8 + pgo/goContactCallbackExport.go | 12 ++ pgo/hitFlag.go | 24 +++ pgo/libs/libphysx-c.a | Bin 22706 -> 23196 bytes pgo/pgo.go | 170 ++++++++++++++---- pgo/physx-c/CPxBoxGeometry.h | 10 +- pgo/physx-c/CPxCapsuleGeometry.h | 8 +- pgo/physx-c/CPxContactPairHeader.h | 71 +++++--- .../CPxDefaultSimulationFilterShader.h | 20 --- pgo/physx-c/CPxFilterData.h | 12 +- pgo/physx-c/CPxGeometry.h | 53 +++++- pgo/physx-c/CPxPlane.h | 2 +- pgo/physx-c/CPxQuat.h | 13 +- pgo/physx-c/CPxScene.h | 38 +++- pgo/physx-c/CPxSphereGeometry.h | 7 +- pgo/physx-c/CPxTransform.h | 9 +- pgo/physx-c/CPxVec3.h | 10 +- pgo/pvdInstrumentationFlag.go | 10 ++ pgo/wrap.c | 4 +- 23 files changed, 439 insertions(+), 121 deletions(-) create mode 100755 go.sum create mode 100755 pgo/contactPairFlag.go create mode 100755 pgo/contactPairHeaderFlag.go create mode 100755 pgo/goContactCallbackExport.go create mode 100755 pgo/hitFlag.go delete mode 100755 pgo/physx-c/CPxDefaultSimulationFilterShader.h create mode 100755 pgo/pvdInstrumentationFlag.go diff --git a/go.mod b/go.mod index 6d07a2d..9ba889c 100755 --- a/go.mod +++ b/go.mod @@ -1,3 +1,5 @@ module github.com/bloeys/physx-go go 1.17 + +require github.com/bloeys/gglm v0.3.1 // indirect diff --git a/go.sum b/go.sum new file mode 100755 index 0000000..0d9fec1 --- /dev/null +++ b/go.sum @@ -0,0 +1,2 @@ +github.com/bloeys/gglm v0.3.1 h1:Sy9upW7SBsBfDXrSmEhid3aQ+7J7itej+upwcxOnPMQ= +github.com/bloeys/gglm v0.3.1/go.mod h1:qwJQ0WzV191wAMwlGicbfbChbKoSedMk7gFFX6GnyOk= diff --git a/main.go b/main.go index 8abf937..abb9be7 100755 --- a/main.go +++ b/main.go @@ -1,13 +1,22 @@ package main import ( - "bufio" - "fmt" - "os" - "github.com/bloeys/physx-go/pgo" ) +func contactHandler(cph pgo.ContactPairHeader) { + + 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()) + } + } +} + func main() { f := pgo.CreateFoundation() println("foundation:", f) @@ -26,7 +35,7 @@ func main() { sd := pgo.NewSceneDesc(ts) sd.SetGravity(pgo.NewVec3(0, -9.8, 0)) sd.SetCpuDispatcher(pgo.DefaultCpuDispatcherCreate(2, 0).ToCpuDispatcher()) - sd.SetOnContactCallback() + sd.SetOnContactCallback(contactHandler) s := p.CreateScene(sd) println("Scene:", s) @@ -115,17 +124,16 @@ func main() { println("Capsule linear damping B:", dynCapsule.GetLinearDamping()) //Run simulation - r := bufio.NewReader(os.Stdin) + // r := bufio.NewReader(os.Stdin) s.SetScratchBuffer(4) for { - s.Collide(1 / 60.0) + s.Collide(1 / 50.0) s.FetchCollision(true) s.Advance() s.FetchResults(true) - rHit, _ := s.Raycast(pgo.NewVec3(0, 0, 0), pgo.NewVec3(0, 1, 0), 9) - fmt.Printf("\nRaycast hit: %v\n", rHit) - + s.Raycast(pgo.NewVec3(0, 0, 0), pgo.NewVec3(0, 1, 0), 9) + // fmt.Printf("\nRaycast hit: %v\n", rHit) // println("Press enter...") // r.ReadBytes('\n') } diff --git a/pgo/contactPairFlag.go b/pgo/contactPairFlag.go new file mode 100755 index 0000000..26473ef --- /dev/null +++ b/pgo/contactPairFlag.go @@ -0,0 +1,47 @@ +package pgo + +type ContactPairFlag uint16 + +const ( + + /** + \brief The shape with index 0 has been removed from the actor/scene. + */ + ContactPairFlag_eREMOVED_SHAPE_0 ContactPairFlag = (1 << 0) + + /** + \brief The shape with index 1 has been removed from the actor/scene. + */ + ContactPairFlag_eREMOVED_SHAPE_1 ContactPairFlag = (1 << 1) + + /** + \brief First actor pair contact. + + The provided shape pair marks the first contact between the two actors, no other shape pair has been touching prior to the current simulation frame. + + \note: This info is only available if #PxPairFlag::eNOTIFY_TOUCH_FOUND has been declared for the pair. + */ + ContactPairFlag_eACTOR_PAIR_HAS_FIRST_TOUCH ContactPairFlag = (1 << 2) + + /** + \brief All contact between the actor pair was lost. + + All contact between the two actors has been lost, no shape pairs remain touching after the current simulation frame. + */ + ContactPairFlag_eACTOR_PAIR_LOST_TOUCH ContactPairFlag = (1 << 3) + + /** + \brief Internal flag, used by #PxContactPair.extractContacts() + + The applied contact impulses are provided for every contact point. + This is the case if #PxPairFlag::eSOLVE_CONTACT has been set for the pair. + */ + ContactPairFlag_eINTERNAL_HAS_IMPULSES ContactPairFlag = (1 << 4) + + /** + \brief Internal flag, used by #PxContactPair.extractContacts() + + The provided contact point information is flipped with regards to the shapes of the contact pair. This mainly concerns the order of the internal triangle indices. + */ + ContactPairFlag_eINTERNAL_CONTACTS_ARE_FLIPPED ContactPairFlag = (1 << 5) +) diff --git a/pgo/contactPairHeaderFlag.go b/pgo/contactPairHeaderFlag.go new file mode 100755 index 0000000..28fe02e --- /dev/null +++ b/pgo/contactPairHeaderFlag.go @@ -0,0 +1,8 @@ +package pgo + +type ContactPairHeaderFlag uint16 + +const ( + ContactPairHeaderFlag_eREMOVED_ACTOR_0 ContactPairHeaderFlag = (1 << 0) //!< The actor with index 0 has been removed from the scene. + ContactPairHeaderFlag_eREMOVED_ACTOR_1 ContactPairHeaderFlag = (1 << 1) //!< The actor with index 1 has been removed from the scene. +) diff --git a/pgo/goContactCallbackExport.go b/pgo/goContactCallbackExport.go new file mode 100755 index 0000000..e55d6ce --- /dev/null +++ b/pgo/goContactCallbackExport.go @@ -0,0 +1,12 @@ +package pgo + +/* +#include "wrap.c" +*/ +import "C" +import "unsafe" + +//export goOnContactCallback +func goOnContactCallback(p unsafe.Pointer) { + contactCallback(ContactPairHeader{cCPH: (*C.struct_CPxContactPairHeader)(p)}) +} diff --git a/pgo/hitFlag.go b/pgo/hitFlag.go new file mode 100755 index 0000000..e7fc27d --- /dev/null +++ b/pgo/hitFlag.go @@ -0,0 +1,24 @@ +package pgo + +type HitFlag uint16 + +const ( + HitFlag_ePOSITION HitFlag = (1 << 0) //!< "position" member of #PxQueryHit is valid + HitFlag_eNORMAL HitFlag = (1 << 1) //!< "normal" member of #PxQueryHit is valid + HitFlag_eUV HitFlag = (1 << 3) //!< "u" and "v" barycentric coordinates of #PxQueryHit are valid. Not applicable to sweep queries. + HitFlag_eASSUME_NO_INITIAL_OVERLAP HitFlag = (1 << 4) //!< Performance hint flag for sweeps when it is known upfront there's no initial overlap. + //!< NOTE: using this flag may cause undefined results if shapes are initially overlapping. + HitFlag_eMESH_MULTIPLE HitFlag = (1 << 5) //!< Report all hits for meshes rather than just the first. Not applicable to sweep queries. + HitFlag_eMESH_ANY HitFlag = (1 << 6) //!< Report any first hit for meshes. If neither eMESH_MULTIPLE nor eMESH_ANY is specified, + //!< a single closest hit will be reported for meshes. + HitFlag_eMESH_BOTH_SIDES HitFlag = (1 << 7) //!< Report hits with back faces of mesh triangles. Also report hits for raycast + //!< originating on mesh surface and facing away from the surface normal. Not applicable to sweep queries. + //!< Please refer to the user guide for heightfield-specific differences. + HitFlag_ePRECISE_SWEEP HitFlag = (1 << 8) //!< Use more accurate but slower narrow phase sweep tests. + //!< May provide better compatibility with PhysX 3.2 sweep behavior. + HitFlag_eMTD HitFlag = (1 << 9) //!< Report the minimum translation depth, normal and contact point. + HitFlag_eFACE_INDEX HitFlag = (1 << 10) //!< "face index" member of #PxQueryHit is valid + HitFlag_eDEFAULT HitFlag = HitFlag_ePOSITION | HitFlag_eNORMAL | HitFlag_eFACE_INDEX + /** \brief Only this subset of flags can be modified by pre-filter. Other modifications will be discarded. */ + HitFlag_eMODIFIABLE_FLAGS HitFlag = HitFlag_eMESH_MULTIPLE | HitFlag_eMESH_BOTH_SIDES | HitFlag_eASSUME_NO_INITIAL_OVERLAP | HitFlag_ePRECISE_SWEEP +) diff --git a/pgo/libs/libphysx-c.a b/pgo/libs/libphysx-c.a index 829fc0038b462556a2ddfdd9db3b1ec0c0c2955f..a2679b73bbeb75d277bfc19834b6eda0e229d1ac 100755 GIT binary patch delta 3469 zcmb`Idr;KZ701sCKjgYApe)N9c6rHLmN&~Ty9+F@<*`4WD?OlZbdcK5?T29(= zi5zMxDh>yxOr190qJ5_PwzpO{xK(a_@rXy_qvR3eQQ<)o7XPS#n8>`DMm7CGbO zkONM}PKjJS0LL&PQQuDs6DG28j6)KcV*s4Iwn>~L^g$S#B(g8iLPSHVglRW9AR6N( ziaP)}1zr-x{ z0N@nelPICcIr(o%6uwUVgt=!Dx;isqCFd?$s3pqjG+fkDONfImoFGysr<#t5W1|Q; zRWTAa3XD^=Rib)7jUy^Qmau(6{Y2dwiOOuU6BR|1(A8EDcG?7|wp*fR3qZ{l8~syD z)Y6VQnKXc7zb0YWKzB;$dnbvYmdM>BVNg*&k*Vb1=HyB&bBlEvZ7XZL=Ko~L%Zs}f zH7{LU@I7fV%`+R#b^mEHTk`9_Kc=H?)smGalc^D!o7)$4H2*+8E9QHDT6)xvW%vV7IbEhK(w%GduOWqMio;6G;G3DU`rkI-v}JgQ=7| z>4Xm8cp8yIgQ#x%NZacHy6gbANY~Tko(6!U)Hc$%KALkjOS)b=we>V_C;8Lo(i#SU zewwQ{QBn^X0md=`+VTKKh$hk(C?`_M*=`yTPYK^q4B%BjDO~CNMg|3`JmrDiEO(W3>vVL*PEo(kc0yio5+0+r8VhDU)@l=D(&dUH~lk#l~j5N_9bh?o*3? zDy!j{ECX)WDp}Iu{-IFvEyKTQ9rCS#HDht4rhz-kJi^eLD$0F-yK|80pU%!5JB0|c z8Squ3(%ZTA*AJszQMtq9+k(b4k!`aYF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>3xh?SZ|b}p z1I-`WTLD4*3xh?I*cNm-0$PAf{IS25ZyPM)R_{*7G6r&0kxhO5{SU6mVS>;tO6YjH zURfApsh?_hmEqe|9w-WCWAPl#+?PB~$D(D3OtvaMXsT(s$TI9aDR)B0Va6`;;N{yF zr5DP-Hg>5u&2@d61TPHfbzzYlSYiku;%Se&@ad`k66TJAcNyGhB={!`b6{7(!U6Z>KH5GN`z68O8`95qOsa}7j`(LTtSRTo@;W_`Q zpLzpCvZunjvEu*xu(Xz>RPSJ?^hQ-(eqG61b0+EFR1g) z?-I~%I%cQkakZMSS6alb!xzS6?->qtDA9LnPUWI-{mzeMB*_suU-i658Z%AGYLgwx zO0_31w3#jcIzccJNjxnMXP zT0XS9zFH1xGz;yjWsl`Ypnw-Q+QgxfLu1k_{U7Y8GoQcz!DDD&wbCn|RQ7c2tg2&OJ@@#O903pUQ2j;HynbL`&?EuVk!} zpKG2c(sB%EWUPuunwN;}JEBJ9lA5@_WwA(YTjjWw)qJ|erp}%C<5f9A4Mz2G(c+6@ zR+k;~xhiwjLi@8S5Z@BB`1z9Y6G71GIIyi#%v*8en?QK=Y=`%H% + #ifdef __cplusplus extern "C" { #endif struct CPxFilterData { - unsigned int word0; - unsigned int word1; - unsigned int word2; - unsigned int word3; - - //TODO: For some reason only this file breaks with CPxU32 (uint32_t). Why? - /*CPxU32 word0; + CPxU32 word0; CPxU32 word1; CPxU32 word2; - CPxU32 word3;*/ + CPxU32 word3; }; #ifdef __cplusplus diff --git a/pgo/physx-c/CPxGeometry.h b/pgo/physx-c/CPxGeometry.h index 24400ce..58f5ac2 100755 --- a/pgo/physx-c/CPxGeometry.h +++ b/pgo/physx-c/CPxGeometry.h @@ -28,14 +28,55 @@ extern "C" { CENUM CPxGeometryType type; }; - CPxAPI CPxInline CSTRUCT CPxSphereGeometry CPxGeometry_toCPxSphereGeometry(CSTRUCT CPxGeometry); - CPxAPI CPxInline CSTRUCT CPxGeometry CPxSphereGeometry_toCPxGeometry(CSTRUCT CPxSphereGeometry*); + // + // CPxSphereGeometry + // + CPxAPI CPxInline CSTRUCT CPxSphereGeometry CPxGeometry_toCPxSphereGeometry(CSTRUCT CPxGeometry cg) + { + return *(CSTRUCT CPxSphereGeometry*)(cg.obj); + //return *static_cast(cg.obj); + } - CPxAPI CPxInline CSTRUCT CPxBoxGeometry CPxGeometry_toCPxBoxGeometry(CSTRUCT CPxGeometry); - CPxAPI CPxInline CSTRUCT CPxGeometry CPxBoxGeometry_toCPxGeometry(CSTRUCT CPxBoxGeometry*); + CPxAPI CPxInline CSTRUCT CPxGeometry CPxSphereGeometry_toCPxGeometry(CSTRUCT CPxSphereGeometry* csg) + { + CSTRUCT CPxGeometry g; + g.obj = csg; + g.type = CPxGeometryType_eSPHERE; + return g; + } - CPxAPI CPxInline CSTRUCT CPxCapsuleGeometry CPxGeometry_toCPxCapsuleGeometry(CSTRUCT CPxGeometry); - CPxAPI CPxInline CSTRUCT CPxGeometry CPxCapsuleGeometry_toCPxGeometry(CSTRUCT CPxCapsuleGeometry*); + // + // CPxBoxGeometry + // + CPxAPI CPxInline CSTRUCT CPxBoxGeometry CPxGeometry_toCPxBoxGeometry(CSTRUCT CPxGeometry cg) + { + return *(CSTRUCT CPxBoxGeometry*)(cg.obj); + //return *static_cast(cg.obj); + } + + CPxAPI CPxInline CSTRUCT CPxGeometry CPxBoxGeometry_toCPxGeometry(CSTRUCT CPxBoxGeometry* cbg) + { + CSTRUCT CPxGeometry g; + g.obj = cbg; + g.type = CPxGeometryType_eBOX; + return g; + } + + // + // CPxCapsuleGeometry + // + CPxAPI CPxInline CSTRUCT CPxCapsuleGeometry CPxGeometry_toCPxCapsuleGeometry(CSTRUCT CPxGeometry cg) + { + return *(CSTRUCT CPxCapsuleGeometry*)(cg.obj); + } + + CPxAPI CPxInline CSTRUCT CPxGeometry CPxCapsuleGeometry_toCPxGeometry(CSTRUCT CPxCapsuleGeometry* ccg) + { + CSTRUCT CPxGeometry g; + g.obj = ccg; + g.type = CPxGeometryType_eCAPSULE; + return g; + } #ifdef __cplusplus } diff --git a/pgo/physx-c/CPxPlane.h b/pgo/physx-c/CPxPlane.h index 6be53e7..5f4cc54 100755 --- a/pgo/physx-c/CPxPlane.h +++ b/pgo/physx-c/CPxPlane.h @@ -5,7 +5,7 @@ extern "C" { #endif - //TODO: Maybe convert this into a value type like CPxSphereGeometry? + //NOTE: 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 index 417dfa7..51b83ba 100755 --- a/pgo/physx-c/CPxQuat.h +++ b/pgo/physx-c/CPxQuat.h @@ -10,8 +10,17 @@ extern "C" { float x, y, z, w; }; - CPxAPI CPxInline CSTRUCT CPxQuat NewCPxQuat(float angleRads, float x, float y, float z); - CPxAPI CPxInline CSTRUCT CPxQuat NewCPxQuatXYZW(float x, float y, float z, float w); + CPxAPI CSTRUCT CPxQuat NewCPxQuat(float angleRads, float x, float y, float z); + CPxAPI CPxInline CSTRUCT CPxQuat NewCPxQuatXYZW(float x, float y, float z, float w) + { + CSTRUCT CPxQuat q; + q.x = x; + q.y = y; + q.z = z; + q.w = w; + return q; + } + #ifdef __cplusplus } diff --git a/pgo/physx-c/CPxScene.h b/pgo/physx-c/CPxScene.h index 376019b..d302618 100755 --- a/pgo/physx-c/CPxScene.h +++ b/pgo/physx-c/CPxScene.h @@ -11,11 +11,33 @@ extern "C" { #endif + enum CPxHitFlag + { + CPxHitFlag_ePOSITION = (1 << 0), //!< "position" member of #PxQueryHit is valid + CPxHitFlag_eNORMAL = (1 << 1), //!< "normal" member of #PxQueryHit is valid + CPxHitFlag_eUV = (1 << 3), //!< "u" and "v" barycentric coordinates of #PxQueryHit are valid. Not applicable to sweep queries. + CPxHitFlag_eASSUME_NO_INITIAL_OVERLAP = (1 << 4), //!< Performance hint flag for sweeps when it is known upfront there's no initial overlap. + //!< NOTE: using this flag may cause undefined results if shapes are initially overlapping. + CPxHitFlag_eMESH_MULTIPLE = (1 << 5), //!< Report all hits for meshes rather than just the first. Not applicable to sweep queries. + CPxHitFlag_eMESH_ANY = (1 << 6), //!< Report any first hit for meshes. If neither eMESH_MULTIPLE nor eMESH_ANY is specified, + //!< a single closest hit will be reported for meshes. + CPxHitFlag_eMESH_BOTH_SIDES = (1 << 7), //!< Report hits with back faces of mesh triangles. Also report hits for raycast + //!< originating on mesh surface and facing away from the surface normal. Not applicable to sweep queries. + //!< Please refer to the user guide for heightfield-specific differences. + CPxHitFlag_ePRECISE_SWEEP = (1 << 8), //!< Use more accurate but slower narrow phase sweep tests. + //!< May provide better compatibility with PhysX 3.2 sweep behavior. + CPxHitFlag_eMTD = (1 << 9), //!< Report the minimum translation depth, normal and contact point. + CPxHitFlag_eFACE_INDEX = (1 << 10), //!< "face index" member of #PxQueryHit is valid + CPxHitFlag_eDEFAULT = CPxHitFlag_ePOSITION | CPxHitFlag_eNORMAL | CPxHitFlag_eFACE_INDEX, + /** \brief Only this subset of flags can be modified by pre-filter. Other modifications will be discarded. */ + CPxHitFlag_eMODIFIABLE_FLAGS = CPxHitFlag_eMESH_MULTIPLE | CPxHitFlag_eMESH_BOTH_SIDES | CPxHitFlag_eASSUME_NO_INITIAL_OVERLAP | CPxHitFlag_ePRECISE_SWEEP + }; + struct CPxRaycastHit { - //CPxHitFlags flags; //!< Hit flags specifying which members contain valid values. - struct CPxVec3 position; //!< World-space hit position (flag: #PxHitFlag::ePOSITION) - struct CPxVec3 normal; //!< World-space hit normal (flag: #PxHitFlag::eNORMAL) + CENUM CPxHitFlag flags; //!< Hit flags specifying which members contain valid values. + CSTRUCT CPxVec3 position; //!< World-space hit position (flag: #PxHitFlag::ePOSITION) + CSTRUCT CPxVec3 normal; //!< World-space hit normal (flag: #PxHitFlag::eNORMAL) /** \brief Distance to hit. @@ -24,14 +46,14 @@ extern "C" { CPxF32 distance; CPxReal u, v; CPxU32 faceIndex; - struct CPxShape shape; - struct CPxRigidActor actor; + CSTRUCT CPxShape shape; + CSTRUCT CPxRigidActor actor; }; struct CPxRaycastBuffer { - struct CPxRaycastHit block; - struct CPxRaycastHit* touches; + CSTRUCT CPxRaycastHit block; + CSTRUCT CPxRaycastHit* touches; CPxU32 nbTouches; bool hasBlock; }; @@ -58,7 +80,7 @@ extern "C" { /// If multiples passed are zero then any existing buffers are cleared /// /// - CPxAPI void CPxScene_setScratchBuffer(CSTRUCT CPxScene*, uint32_t multiplesOf16k); + CPxAPI void CPxScene_setScratchBuffer(CSTRUCT CPxScene*, CPxU32 multiplesOf16k); CPxAPI void CPxScene_release(CSTRUCT CPxScene*); diff --git a/pgo/physx-c/CPxSphereGeometry.h b/pgo/physx-c/CPxSphereGeometry.h index 6803937..ac496c7 100755 --- a/pgo/physx-c/CPxSphereGeometry.h +++ b/pgo/physx-c/CPxSphereGeometry.h @@ -10,7 +10,12 @@ extern "C" { CPxReal radius; }; - CPxAPI CPxInline CSTRUCT CPxSphereGeometry NewCPxSphereGeometry(CPxReal radius); + CPxAPI CPxInline CSTRUCT CPxSphereGeometry NewCPxSphereGeometry(CPxReal radius) + { + CSTRUCT CPxSphereGeometry c; + c.radius = radius; + return c; + } #ifdef __cplusplus } diff --git a/pgo/physx-c/CPxTransform.h b/pgo/physx-c/CPxTransform.h index 9637e01..fe882cb 100755 --- a/pgo/physx-c/CPxTransform.h +++ b/pgo/physx-c/CPxTransform.h @@ -14,7 +14,14 @@ extern "C" { CSTRUCT CPxQuat q; }; - CPxAPI CPxInline CSTRUCT CPxTransform NewCPxTransform(CSTRUCT CPxVec3*, CSTRUCT CPxQuat*); + CPxAPI CPxInline CSTRUCT CPxTransform NewCPxTransform(CSTRUCT CPxVec3* v, CSTRUCT CPxQuat* q) + { + CSTRUCT CPxTransform t; + t.p = *v; + t.q = *q; + + return t; + } #ifdef __cplusplus } #endif diff --git a/pgo/physx-c/CPxVec3.h b/pgo/physx-c/CPxVec3.h index 1ae9197..e143b9d 100755 --- a/pgo/physx-c/CPxVec3.h +++ b/pgo/physx-c/CPxVec3.h @@ -9,7 +9,15 @@ extern "C" { float x, y, z; }; - CPxAPI CPxInline CSTRUCT CPxVec3 NewCPxVec3(float x, float y, float z); + CPxAPI CPxInline CSTRUCT CPxVec3 NewCPxVec3(float x, float y, float z) + { + CSTRUCT CPxVec3 v; + v.x = x; + v.y = y; + v.z = z; + + return v; + } #ifdef __cplusplus } diff --git a/pgo/pvdInstrumentationFlag.go b/pgo/pvdInstrumentationFlag.go new file mode 100755 index 0000000..247188e --- /dev/null +++ b/pgo/pvdInstrumentationFlag.go @@ -0,0 +1,10 @@ +package pgo + +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) +) diff --git a/pgo/wrap.c b/pgo/wrap.c index 9a37122..b8fd264 100755 --- a/pgo/wrap.c +++ b/pgo/wrap.c @@ -2,12 +2,14 @@ #include #define CPxAPI #define CPxInternalAPI -#define CPxInline +#define CPxInline inline #define CSTRUCT struct #define CENUM enum #define CPxU32 uint32_t #define CPxReal float #define CPxF32 float +#define CPxU8 uint8_t +#define CPxU16 uint16_t #include #include