mirror of
https://github.com/bloeys/physx-go.git
synced 2025-12-29 07:58:20 +00:00
Start raycast implementation
This commit is contained in:
11
main.go
11
main.go
@ -1,6 +1,10 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"fmt"
|
||||||
|
"os"
|
||||||
|
|
||||||
"github.com/bloeys/physx-go/pgo"
|
"github.com/bloeys/physx-go/pgo"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -111,12 +115,19 @@ func main() {
|
|||||||
println("Capsule linear damping B:", dynCapsule.GetLinearDamping())
|
println("Capsule linear damping B:", dynCapsule.GetLinearDamping())
|
||||||
|
|
||||||
//Run simulation
|
//Run simulation
|
||||||
|
r := bufio.NewReader(os.Stdin)
|
||||||
s.SetScratchBuffer(4)
|
s.SetScratchBuffer(4)
|
||||||
for {
|
for {
|
||||||
s.Collide(1 / 60.0)
|
s.Collide(1 / 60.0)
|
||||||
s.FetchCollision(true)
|
s.FetchCollision(true)
|
||||||
s.Advance()
|
s.Advance()
|
||||||
s.FetchResults(true)
|
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()
|
p.Release()
|
||||||
|
|||||||
Binary file not shown.
24
pgo/pgo.go
24
pgo/pgo.go
@ -126,6 +126,30 @@ func (s *Scene) SetScratchBuffer(multiplesOf16k uint32) {
|
|||||||
C.CPxScene_setScratchBuffer(s.cS, C.uint(multiplesOf16k))
|
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 {
|
type Physics struct {
|
||||||
cPhysics *C.struct_CPxPhysics
|
cPhysics *C.struct_CPxPhysics
|
||||||
}
|
}
|
||||||
|
|||||||
@ -3,11 +3,39 @@
|
|||||||
|
|
||||||
#include "CPxPvdSceneClient.h"
|
#include "CPxPvdSceneClient.h"
|
||||||
#include "CPxActor.h"
|
#include "CPxActor.h"
|
||||||
|
#include "CPxVec3.h"
|
||||||
|
#include "CPxShape.h"
|
||||||
|
#include "CPxRigidActor.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
extern "C" {
|
extern "C" {
|
||||||
#endif
|
#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
|
struct CPxScene
|
||||||
{
|
{
|
||||||
void* obj;
|
void* obj;
|
||||||
@ -22,6 +50,7 @@ extern "C" {
|
|||||||
CPxAPI bool CPxScene_fetchCollision(CSTRUCT CPxScene*, bool block);
|
CPxAPI bool CPxScene_fetchCollision(CSTRUCT CPxScene*, bool block);
|
||||||
CPxAPI void CPxScene_advance(CSTRUCT CPxScene*);
|
CPxAPI void CPxScene_advance(CSTRUCT CPxScene*);
|
||||||
CPxAPI bool CPxScene_fetchResults(CSTRUCT CPxScene*, bool block, CPxU32* errorState);
|
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);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Creates a scratch buffer thats a multiple of 16K to be used by the scene when running CPxScene_simulate.
|
/// Creates a scratch buffer thats a multiple of 16K to be used by the scene when running CPxScene_simulate.
|
||||||
|
|||||||
@ -7,6 +7,7 @@
|
|||||||
#define CENUM enum
|
#define CENUM enum
|
||||||
#define CPxU32 uint32_t
|
#define CPxU32 uint32_t
|
||||||
#define CPxReal float
|
#define CPxReal float
|
||||||
|
#define CPxF32 float
|
||||||
|
|
||||||
#include <CPxFoundation.h>
|
#include <CPxFoundation.h>
|
||||||
#include <CPxPvd.h>
|
#include <CPxPvd.h>
|
||||||
|
|||||||
Reference in New Issue
Block a user