diff --git a/main.go b/main.go index 7819393..aed5a75 100755 --- a/main.go +++ b/main.go @@ -33,8 +33,14 @@ func main() { scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_CONTACTS, true) scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_SCENEQUERIES, true) - for { + pMat := p.CreateMaterial(0.5, 0.5, 0.6) + groundPlane := pgo.CreatePlane(p, pgo.NewPlane(0, 1, 0, 1), pMat) + s.AddActor(groundPlane.ToActor()) + for { + s.Simulate(1 / 60.0) + a, b := s.FetchResults(true) + println("a:", a, "; b:", b) } p.Release() diff --git a/pgo/libs/libphysx-c.a b/pgo/libs/libphysx-c.a index cac0d89..e75609b 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 0ed7e1e..d1871c6 100755 --- a/pgo/pgo.go +++ b/pgo/pgo.go @@ -20,11 +20,17 @@ 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); @@ -36,6 +42,14 @@ struct CPxCpuDispatcher* CPxDefaultCpuDispatcher_toCPxCpuDispatcher(struct CPxDe 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" @@ -121,6 +135,23 @@ func (s *Scene) GetScenePvdClient() *PvdSceneClient { } } +func (s *Scene) AddActor(a *Actor) { + C.CPxScene_addActor(s.cS, a.cA) +} + +// void CPxScene_simulate(CSTRUCT CPxScene*, CPxReal elapsedTime); +func (s *Scene) Simulate(elapsedTime float32) { + C.CPxScene_simulate(s.cS, C.float(elapsedTime)) +} + +// bool CPxScene_fetchResults(struct CPxScene*, bool block, CPxU32* errorState); +func (s *Scene) FetchResults(block bool) (bool, uint32) { + + var errState uint32 + b := C.CPxScene_fetchResults(s.cS, C._Bool(block), (*C.uint)(&errState)) + return bool(b), errState +} + type Physics struct { cPhysics *C.struct_CPxPhysics } @@ -131,6 +162,12 @@ func (p *Physics) CreateScene(sd *SceneDesc) *Scene { } } +func (p *Physics) CreateMaterial(staticFriction, dynamicFriction, restitution float32) *Material { + return &Material{ + cM: C.CPxPhysics_createMaterial(p.cPhysics, C.float(staticFriction), C.float(dynamicFriction), C.float(restitution)), + } +} + func CreatePhysics(f *Foundation, ts *TolerancesScale, trackOutstandingAllocations bool, pvd *Pvd) *Physics { p := &Physics{} @@ -161,7 +198,6 @@ 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)} } @@ -184,7 +220,6 @@ 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), @@ -206,3 +241,39 @@ type PvdSceneClient struct { func (p *PvdSceneClient) SetScenePvdFlag(flag PvdSceneFlag, value bool) { C.CPxPvdSceneClient_setScenePvdFlag(p.cPvdSceneClient, uint32(flag), C._Bool(value)) } + +type Material struct { + cM *C.struct_CPxMaterial +} + +type Plane struct { + cP *C.struct_CPxPlane +} + +func NewPlane(nx, ny, nz, distance float32) *Plane { + return &Plane{ + cP: C.NewCPxPlane(C.float(nx), C.float(ny), C.float(nz), C.float(distance)), + } +} + +type Actor struct { + 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), + } +} diff --git a/pgo/physx-c/CPxScene.h b/pgo/physx-c/CPxScene.h index d441619..7ed75ce 100755 --- a/pgo/physx-c/CPxScene.h +++ b/pgo/physx-c/CPxScene.h @@ -15,6 +15,8 @@ extern "C" { CPxAPI CSTRUCT CPxPvdSceneClient* CPxScene_getScenePvdClient(CSTRUCT CPxScene*); 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); CPxAPI void CPxScene_release(CSTRUCT CPxScene*);