mirror of
https://github.com/bloeys/physx-go.git
synced 2025-12-29 07:58:20 +00:00
Towards an mvp
This commit is contained in:
114
pgo/pgo.go
114
pgo/pgo.go
@ -12,14 +12,39 @@ 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);
|
||||
|
||||
struct CPxPhysics* CPxCreatePhysics(struct CPxFoundation* cfoundation, struct CPxTolerancesScale cscale, bool trackOutstandingAllocations, struct CPxPvd* cpvd);
|
||||
struct CPxScene* CPxPhysics_createScene(struct CPxPhysics*, struct CPxSceneDesc*);
|
||||
void CPxPhysics_release(struct CPxPhysics*);
|
||||
|
||||
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*);
|
||||
*/
|
||||
import "C"
|
||||
import "unsafe"
|
||||
|
||||
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)
|
||||
)
|
||||
|
||||
type Foundation struct {
|
||||
cFoundation *C.struct_CPxFoundation
|
||||
}
|
||||
@ -40,6 +65,10 @@ type Pvd struct {
|
||||
cPvd *C.struct_CPxPvd
|
||||
}
|
||||
|
||||
func (p *Pvd) Connect(pvdTr *PvdTransport, instFlag PvdInstrumentationFlag) bool {
|
||||
return bool(C.CPxPvd_connect(p.cPvd, pvdTr.cPvdTr, uint32(instFlag)))
|
||||
}
|
||||
|
||||
func (p *Pvd) Release() {
|
||||
C.CPxPvd_release(p.cPvd)
|
||||
}
|
||||
@ -67,6 +96,91 @@ func DefaultPvdSocketTransportCreate(host string, port, timeoutMillis int) *PvdT
|
||||
|
||||
p := &PvdTransport{}
|
||||
p.cPvdTr = C.CPxDefaultPvdSocketTransportCreate(hostCStr, C.int(port), C.int(timeoutMillis))
|
||||
return p
|
||||
}
|
||||
|
||||
type TolerancesScale struct {
|
||||
cTolScale C.struct_CPxTolerancesScale
|
||||
}
|
||||
|
||||
func NewTolerancesScale(length, speed float32) *TolerancesScale {
|
||||
|
||||
ts := &TolerancesScale{}
|
||||
ts.cTolScale = C.NewCPxTolerancesScale(C.float(length), C.float(speed))
|
||||
return ts
|
||||
}
|
||||
|
||||
type Scene struct {
|
||||
cS *C.struct_CPxScene
|
||||
}
|
||||
|
||||
type Physics struct {
|
||||
cPhysics *C.struct_CPxPhysics
|
||||
}
|
||||
|
||||
// struct CPxScene* CPxPhysics_createScene(struct CPxPhysics*, struct CPxSceneDesc*);
|
||||
func (p *Physics) CreateScene(sd *SceneDesc) *Scene {
|
||||
return &Scene{
|
||||
cS: C.CPxPhysics_createScene(p.cPhysics, sd.cSD),
|
||||
}
|
||||
}
|
||||
|
||||
func CreatePhysics(f *Foundation, ts *TolerancesScale, trackOutstandingAllocations bool, pvd *Pvd) *Physics {
|
||||
|
||||
p := &Physics{}
|
||||
p.cPhysics = C.CPxCreatePhysics(f.cFoundation, ts.cTolScale, C._Bool(trackOutstandingAllocations), pvd.cPvd)
|
||||
|
||||
return p
|
||||
}
|
||||
|
||||
func (p *Physics) Release() {
|
||||
C.CPxPhysics_release(p.cPhysics)
|
||||
}
|
||||
|
||||
type Vec3 struct {
|
||||
cV C.struct_CPxVec3
|
||||
}
|
||||
|
||||
func NewVec3(x, y, z float32) *Vec3 {
|
||||
return &Vec3{
|
||||
cV: C.NewCPxVec3(C.float(x), C.float(y), C.float(z)),
|
||||
}
|
||||
}
|
||||
|
||||
type CpuDispatcher struct {
|
||||
cCpuDisp *C.struct_CPxCpuDispatcher
|
||||
}
|
||||
|
||||
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)}
|
||||
}
|
||||
|
||||
func DefaultCpuDispatcherCreate(numThreads, affinityMasks uint32) *DefaultCpuDispatcher {
|
||||
return &DefaultCpuDispatcher{
|
||||
cDefCpuDisp: C.CPxDefaultCpuDispatcherCreate(C.uint(numThreads), C.uint(affinityMasks)),
|
||||
}
|
||||
}
|
||||
|
||||
type SceneDesc struct {
|
||||
cSD *C.struct_CPxSceneDesc
|
||||
}
|
||||
|
||||
func (sd *SceneDesc) SetGravity(v *Vec3) {
|
||||
C.CPxSceneDesc_set_gravity(sd.cSD, v.cV)
|
||||
}
|
||||
|
||||
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),
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user