diff --git a/main.go b/main.go index a700f07..8abf937 100755 --- a/main.go +++ b/main.go @@ -1,6 +1,10 @@ package main import ( + "bufio" + "fmt" + "os" + "github.com/bloeys/physx-go/pgo" ) @@ -111,12 +115,19 @@ func main() { println("Capsule linear damping B:", dynCapsule.GetLinearDamping()) //Run simulation + r := bufio.NewReader(os.Stdin) s.SetScratchBuffer(4) for { s.Collide(1 / 60.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) + + // println("Press enter...") + // r.ReadBytes('\n') } p.Release() diff --git a/pgo/libs/libphysx-c.a b/pgo/libs/libphysx-c.a index 7da1bf3..829fc00 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 6cb77c2..cd76da6 100755 --- a/pgo/pgo.go +++ b/pgo/pgo.go @@ -126,6 +126,30 @@ func (s *Scene) SetScratchBuffer(multiplesOf16k uint32) { C.CPxScene_setScratchBuffer(s.cS, C.uint(multiplesOf16k)) } +//bool CPxScene_raycast(CSTRUCT CPxScene* cs, CPxVec3* origin, CPxVec3* unitDir, CPxReal distance, CPxRaycastBuffer* hit) +func (s *Scene) Raycast(origin, unitDir *Vec3, distance float32) (bool, RaycastBuffer) { + + rb := RaycastBuffer{} + ret := C.CPxScene_raycast(s.cS, &origin.cV, &unitDir.cV, C.float(distance), &rb.cRb) + return bool(ret), rb +} + +type RaycastHit struct { + cRh *C.struct_CPxRaycastHit +} + +type RaycastBuffer struct { + cRb *C.struct_CPxRaycastBuffer +} + +func (rb *RaycastBuffer) HasBlock() bool { + return bool(rb.cRb.hasBlock) +} + +func (rb *RaycastBuffer) GetBlock() RaycastHit { + return RaycastHit{} +} + type Physics struct { cPhysics *C.struct_CPxPhysics } diff --git a/pgo/physx-c/CPxScene.h b/pgo/physx-c/CPxScene.h index 22d052c..376019b 100755 --- a/pgo/physx-c/CPxScene.h +++ b/pgo/physx-c/CPxScene.h @@ -3,11 +3,39 @@ #include "CPxPvdSceneClient.h" #include "CPxActor.h" +#include "CPxVec3.h" +#include "CPxShape.h" +#include "CPxRigidActor.h" #ifdef __cplusplus extern "C" { #endif + 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) + + /** + \brief Distance to hit. + \note If the eMTD flag is used, distance will be a negative value if shapes are overlapping indicating the penetration depth. + \note Otherwise, this value will be >= 0 */ + CPxF32 distance; + CPxReal u, v; + CPxU32 faceIndex; + struct CPxShape shape; + struct CPxRigidActor actor; + }; + + struct CPxRaycastBuffer + { + struct CPxRaycastHit block; + struct CPxRaycastHit* touches; + CPxU32 nbTouches; + bool hasBlock; + }; + struct CPxScene { void* obj; @@ -22,6 +50,7 @@ extern "C" { 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 bool CPxScene_raycast(CSTRUCT CPxScene* cs, CSTRUCT CPxVec3* origin, CSTRUCT CPxVec3* unitDir, CPxReal distance, CSTRUCT CPxRaycastBuffer** hitRet); /// /// Creates a scratch buffer thats a multiple of 16K to be used by the scene when running CPxScene_simulate. diff --git a/pgo/wrap.c b/pgo/wrap.c index 6491834..9a37122 100755 --- a/pgo/wrap.c +++ b/pgo/wrap.c @@ -7,6 +7,7 @@ #define CENUM enum #define CPxU32 uint32_t #define CPxReal float +#define CPxF32 float #include #include