PhysX POC Alhamdullah!

This commit is contained in:
bloeys
2022-01-20 04:46:38 +04:00
parent ccecb3a1b0
commit e8bee27262
15 changed files with 268 additions and 52 deletions

20
main.go
View File

@ -33,10 +33,28 @@ func main() {
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_CONTACTS, true) scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_CONTACTS, true)
scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_SCENEQUERIES, true) scenePvdClient.SetScenePvdFlag(pgo.PvdSceneFlag_eTRANSMIT_SCENEQUERIES, true)
//Add plane
pMat := p.CreateMaterial(0.5, 0.5, 0.6) pMat := p.CreateMaterial(0.5, 0.5, 0.6)
groundPlane := pgo.CreatePlane(p, pgo.NewPlane(0, 1, 0, 1), pMat) groundPlane := pgo.CreatePlane(p, pgo.NewPlane(0, 1, 0, 0), pMat)
s.AddActor(groundPlane.ToActor()) s.AddActor(groundPlane.ToActor())
//Add dynamic box
v := pgo.NewVec3(0, 10, 0)
q := pgo.NewQuat(0, 0, 1, 0)
tr := pgo.NewTransform(v, q)
qID := pgo.NewQuat(0, 0, 1, 0)
shapeOffset := pgo.NewTransform(v, qID)
box := pgo.NewBoxGeometry(0.5, 0.5, 0.5)
dynBox := pgo.CreateDynamic(p, tr, box.ToGeometry(), pMat, 10, shapeOffset)
s.AddActor(dynBox.ToActor())
v = pgo.NewVec3(0.5, 12, 0)
tr2 := pgo.NewTransform(v, qID)
dynBox2 := pgo.CreateDynamic(p, tr2, box.ToGeometry(), pMat, 10, shapeOffset)
s.AddActor(dynBox2.ToActor())
for { for {
s.Simulate(1 / 60.0) s.Simulate(1 / 60.0)
a, b := s.FetchResults(true) a, b := s.FetchResults(true)

Binary file not shown.

View File

@ -6,50 +6,6 @@ package pgo
#include <wrap.cxx> #include <wrap.cxx>
#include <stdlib.h> //Needed for C.free #include <stdlib.h> //Needed for C.free
//Functions
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);
//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);
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*);
//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" import "C"
@ -256,24 +212,98 @@ func NewPlane(nx, ny, nz, distance float32) *Plane {
} }
} }
type Quat struct {
cQ C.struct_CPxQuat
}
// CPxAPI CPxInline CSTRUCT CPxQuat NewCPxQuat(float angleRads, float x, float y, float z);
func NewQuat(angleRads, x, y, z float32) *Quat {
return &Quat{
cQ: C.NewCPxQuat(C.float(angleRads), C.float(x), C.float(y), C.float(z)),
}
}
type Transform struct {
cT C.struct_CPxTransform
}
// struct CPxTransform NewCPxTransform(struct CPxVec3*, struct CPxQuat*);
func NewTransform(v *Vec3, q *Quat) *Transform {
return &Transform{
cT: C.NewCPxTransform(&v.cV, &q.cQ),
}
}
type Geometry struct {
cG C.struct_CPxGeometry
}
type SphereGeometry struct {
cSg C.struct_CPxSphereGeometry
}
// struct CPxGeometry CPxSphereGeometry_toCPxGeometry(struct CPxSphereGeometry*);
func (sg *SphereGeometry) ToGeometry() *Geometry {
return &Geometry{
cG: C.CPxSphereGeometry_toCPxGeometry(&sg.cSg),
}
}
// struct CPxSphereGeometry NewCPxSphereGeometry(CPxReal radius);
func NewSphereGeometry(radius float32) *SphereGeometry {
return &SphereGeometry{
cSg: C.NewCPxSphereGeometry(C.float(radius)),
}
}
type BoxGeometry struct {
cBg C.struct_CPxBoxGeometry
}
func (bg *BoxGeometry) ToGeometry() *Geometry {
return &Geometry{
cG: C.CPxBoxGeometry_toCPxGeometry(&bg.cBg),
}
}
func NewBoxGeometry(hx, hy, hz float32) *BoxGeometry {
return &BoxGeometry{
cBg: C.NewCPxBoxGeometry(C.float(hx), C.float(hy), C.float(hz)),
}
}
type Actor struct { type Actor struct {
cA *C.struct_CPxActor cA C.struct_CPxActor
} }
type RigidStatic struct { type RigidStatic struct {
cRs *C.struct_CPxRigidStatic cRs *C.struct_CPxRigidStatic
} }
//struct CPxActor* CPxRigidStatic_toCPxActor(struct CPxRigidStatic*);
func (rs *RigidStatic) ToActor() *Actor { func (rs *RigidStatic) ToActor() *Actor {
return &Actor{ return &Actor{
cA: C.CPxRigidStatic_toCPxActor(rs.cRs), 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 { func CreatePlane(p *Physics, plane *Plane, mat *Material) *RigidStatic {
return &RigidStatic{ return &RigidStatic{
cRs: C.CPxCreatePlane(p.cPhysics, plane.cP, mat.cM), cRs: C.CPxCreatePlane(p.cPhysics, plane.cP, mat.cM),
} }
} }
type RigidDynamic struct {
cRd *C.struct_CPxRigidDynamic
}
func (rs *RigidDynamic) ToActor() *Actor {
return &Actor{
cA: C.CPxRigidDynamic_toCPxActor(rs.cRd),
}
}
func CreateDynamic(p *Physics, t *Transform, g *Geometry, m *Material, density float32, shapeOffset *Transform) *RigidDynamic {
return &RigidDynamic{
cRd: C.CPxCreateDynamic(p.cPhysics, &t.cT, g.cG, m.cM, C.float(density), &shapeOffset.cT),
}
}

19
pgo/physx-c/CExtSimpleFactory.h Executable file
View File

@ -0,0 +1,19 @@
#ifndef CExtSimpleFactory_H
#define CExtSimpleFactory_H
#include "CPxPhysics.h"
#include "CPxGeometry.h"
#include "CPxTransform.h"
#include "CPxRigidDynamic.h"
#ifdef __cplusplus
extern "C" {
#endif
CPxAPI CSTRUCT CPxRigidDynamic* CPxCreateDynamic(CSTRUCT CPxPhysics* sdk, CSTRUCT CPxTransform* transform, CSTRUCT CPxGeometry geometry, CSTRUCT CPxMaterial* material, CPxReal density, CSTRUCT CPxTransform* shapeOffset);
#ifdef __cplusplus
}
#endif
#endif // !CExtSimpleFactory_H

19
pgo/physx-c/CPxBoxGeometry.h Executable file
View File

@ -0,0 +1,19 @@
#ifndef CPxBoxGeometry_H
#define CPxBoxGeometry_H
#ifdef __cplusplus
extern "C" {
#endif
struct CPxBoxGeometry
{
float hx, hy, hz;
};
CPxAPI CPxInline CSTRUCT CPxBoxGeometry NewCPxBoxGeometry(float hx, float hy, float hz);
#ifdef __cplusplus
}
#endif
#endif // !CPxBoxGeometry_H

41
pgo/physx-c/CPxGeometry.h Executable file
View File

@ -0,0 +1,41 @@
#ifndef CPxGeometry_H
#define CPxGeometry_H
#include "CPxBoxGeometry.h"
#include "CPxSphereGeometry.h"
#ifdef __cplusplus
extern "C" {
#endif
enum CPxGeometryType
{
CPxGeometryType_eSPHERE,
CPxGeometryType_ePLANE,
CPxGeometryType_eCAPSULE,
CPxGeometryType_eBOX,
CPxGeometryType_eCONVEXMESH,
CPxGeometryType_eTRIANGLEMESH,
CPxGeometryType_eHEIGHTFIELD,
CPxGeometryType_eGEOMETRY_COUNT, //!< internal use only!
CPxGeometryType_eINVALID = -1 //!< internal use only!
};
struct CPxGeometry
{
void* obj;
CENUM CPxGeometryType type;
};
CPxAPI CPxInline CSTRUCT CPxSphereGeometry CPxGeometry_toCPxSphere(CSTRUCT CPxGeometry);
CPxAPI CPxInline CSTRUCT CPxGeometry CPxSphereGeometry_toCPxGeometry(CSTRUCT CPxSphereGeometry*);
CPxAPI CPxInline CSTRUCT CPxBoxGeometry CPxGeometry_toCPxBox(CSTRUCT CPxGeometry);
CPxAPI CPxInline CSTRUCT CPxGeometry CPxBoxGeometry_toCPxGeometry(CSTRUCT CPxBoxGeometry*);
#ifdef __cplusplus
}
#endif
#endif // !CPxGeometry_H

View File

@ -5,6 +5,7 @@
extern "C" { extern "C" {
#endif #endif
//TODO: Maybe convert this into a value type like CPxSphereGeometry?
struct CPxPlane struct CPxPlane
{ {
void* obj; void* obj;

19
pgo/physx-c/CPxQuat.h Executable file
View File

@ -0,0 +1,19 @@
#ifndef CPxQuat_H
#define CPxQuat_H
#ifdef __cplusplus
extern "C" {
#endif
struct CPxQuat
{
float x, y, z, w;
};
CPxAPI CPxInline CSTRUCT CPxQuat NewCPxQuat(float angleRads, float x, float y, float z);
#ifdef __cplusplus
}
#endif
#endif // !CPxQuat_H

21
pgo/physx-c/CPxRigidDynamic.h Executable file
View File

@ -0,0 +1,21 @@
#ifndef CPxRigidDynamic_H
#define CPxRigidDynamic_H
#include "CPxActor.h"
#ifdef __cplusplus
extern "C" {
#endif
struct CPxRigidDynamic
{
void* obj;
};
CPxAPI CSTRUCT CPxActor CPxRigidDynamic_toCPxActor(CSTRUCT CPxRigidDynamic*);
#ifdef __cplusplus
}
#endif
#endif // !CPxRigidDynamic_H

View File

@ -16,7 +16,7 @@ extern "C" {
}; };
CPxAPI CSTRUCT CPxRigidStatic* CPxCreatePlane(CSTRUCT CPxPhysics* sdk, CSTRUCT CPxPlane* plane, CSTRUCT CPxMaterial* material); CPxAPI CSTRUCT CPxRigidStatic* CPxCreatePlane(CSTRUCT CPxPhysics* sdk, CSTRUCT CPxPlane* plane, CSTRUCT CPxMaterial* material);
CPxAPI CSTRUCT CPxActor* CPxRigidStatic_toCPxActor(CSTRUCT CPxRigidStatic*); CPxAPI CSTRUCT CPxActor CPxRigidStatic_toCPxActor(CSTRUCT CPxRigidStatic*);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -14,7 +14,7 @@ extern "C" {
}; };
CPxAPI CSTRUCT CPxPvdSceneClient* CPxScene_getScenePvdClient(CSTRUCT CPxScene*); CPxAPI CSTRUCT CPxPvdSceneClient* CPxScene_getScenePvdClient(CSTRUCT CPxScene*);
CPxAPI void CPxScene_addActor(CSTRUCT CPxScene*, CSTRUCT CPxActor* actor); CPxAPI void CPxScene_addActor(CSTRUCT CPxScene*, CSTRUCT CPxActor actor);
CPxAPI void CPxScene_simulate(CSTRUCT CPxScene*, CPxReal elapsedTime); CPxAPI void CPxScene_simulate(CSTRUCT CPxScene*, CPxReal elapsedTime);
CPxAPI bool CPxScene_fetchResults(CSTRUCT CPxScene*, bool block, CPxU32* errorState); CPxAPI bool CPxScene_fetchResults(CSTRUCT CPxScene*, bool block, CPxU32* errorState);

19
pgo/physx-c/CPxSphereGeometry.h Executable file
View File

@ -0,0 +1,19 @@
#ifndef CPxSphereGeometry_H
#define CPxSphereGeometry_H
#ifdef __cplusplus
extern "C" {
#endif
struct CPxSphereGeometry
{
CPxReal radius;
};
CPxAPI CPxInline CSTRUCT CPxSphereGeometry NewCPxSphereGeometry(CPxReal radius);
#ifdef __cplusplus
}
#endif
#endif // !CPxSphereGeometry_H

23
pgo/physx-c/CPxTransform.h Executable file
View File

@ -0,0 +1,23 @@
#ifndef CPxTransform_H
#define CPxTransform_H
#include "CPxVec3.h"
#include "CPxQuat.h"
#ifdef __cplusplus
extern "C" {
#endif
struct CPxTransform
{
CSTRUCT CPxVec3 p;
CSTRUCT CPxQuat q;
};
CPxAPI CPxInline CSTRUCT CPxTransform NewCPxTransform(CSTRUCT CPxVec3*, CSTRUCT CPxQuat*);
#ifdef __cplusplus
}
#endif
#endif // !CPxTransform_H

View File

@ -9,7 +9,7 @@ extern "C" {
float x, y, z; float x, y, z;
}; };
CPxAPI CSTRUCT CPxVec3 NewCPxVec3(float x, float y, float z); CPxAPI CPxInline CSTRUCT CPxVec3 NewCPxVec3(float x, float y, float z);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -1,6 +1,7 @@
#include <stdint.h> #include <stdint.h>
#include <stdbool.h> #include <stdbool.h>
#define CPxAPI #define CPxAPI
#define CPxInline
#define CSTRUCT struct #define CSTRUCT struct
#define CENUM enum #define CENUM enum
#define CPxU32 uint32_t #define CPxU32 uint32_t
@ -15,8 +16,13 @@
#include <CPxScene.h> #include <CPxScene.h>
#include <CPxSceneDesc.h> #include <CPxSceneDesc.h>
#include <CPxTolerancesScale.h> #include <CPxTolerancesScale.h>
#include <CPxVec3.h>
#include <CPxPlane.h> #include <CPxPlane.h>
#include <CPxActor.h> #include <CPxActor.h>
#include <CPxRigidStatic.h> #include <CPxRigidStatic.h>
#include <CPxRigidDynamic.h>
#include <CPxTransform.h>
#include <CPxPvdSceneClient.h> #include <CPxPvdSceneClient.h>
#include <CExtSimpleFactory.h>
#include <CPxGeometry.h>
#include <CPxBoxGeometry.h>
#include <CPxSphereGeometry.h>