mirror of
https://github.com/bloeys/physx-go.git
synced 2025-12-29 07:58:20 +00:00
Support split sim
This commit is contained in:
8
main.go
8
main.go
@ -38,7 +38,7 @@ func main() {
|
||||
groundPlane := pgo.CreatePlane(p, pgo.NewPlane(0, 1, 0, 0), pMat)
|
||||
s.AddActor(groundPlane.ToActor())
|
||||
|
||||
//Add dynamic box
|
||||
//Add box1
|
||||
v := pgo.NewVec3(0, 10, 0)
|
||||
q := pgo.NewQuat(0, 0, 1, 0)
|
||||
tr := pgo.NewTransform(v, q)
|
||||
@ -50,6 +50,7 @@ func main() {
|
||||
dynBox := pgo.CreateDynamic(p, tr, box.ToGeometry(), pMat, 1, shapeOffset)
|
||||
s.AddActor(dynBox.ToActor())
|
||||
|
||||
//Add box2
|
||||
v = pgo.NewVec3(0.5, 12, 0)
|
||||
tr2 := pgo.NewTransform(v, qID)
|
||||
dynBox2 := pgo.CreateDynamic(p, tr2, box.ToGeometry(), pMat, 1, shapeOffset)
|
||||
@ -68,7 +69,6 @@ func main() {
|
||||
s.AddActor(dynCapsule.ToActor())
|
||||
|
||||
//Add compound shape
|
||||
|
||||
dynComp := p.CreateRigidDynamic(pgo.NewTransform(pgo.NewVec3(0, 35, 0), qID))
|
||||
|
||||
pgo.CreateExclusiveShape(dynComp.ToRigidActor(), pgo.NewBoxGeometry(10, 0.1, 0.1).ToGeometry(), pMat, pgo.ShapeFlags_eSCENE_QUERY_SHAPE|pgo.ShapeFlags_eSIMULATION_SHAPE|pgo.ShapeFlags_eVISUALIZATION)
|
||||
@ -96,7 +96,9 @@ func main() {
|
||||
//Run simulation
|
||||
s.SetScratchBuffer(4)
|
||||
for {
|
||||
s.Simulate(1 / 60.0)
|
||||
s.Collide(1 / 60.0)
|
||||
s.FetchCollision(true)
|
||||
s.Advance()
|
||||
s.FetchResults(true)
|
||||
}
|
||||
|
||||
|
||||
Binary file not shown.
17
pgo/pgo.go
17
pgo/pgo.go
@ -99,6 +99,20 @@ func (s *Scene) Simulate(elapsedTime float32) {
|
||||
C.CPxScene_simulate(s.cS, C.float(elapsedTime))
|
||||
}
|
||||
|
||||
// void CPxScene_advance(CSTRUCT CPxScene*);
|
||||
|
||||
func (s *Scene) Collide(elapsedTime float32) {
|
||||
C.CPxScene_collide(s.cS, C.float(elapsedTime))
|
||||
}
|
||||
|
||||
func (s *Scene) FetchCollision(block bool) bool {
|
||||
return bool(C.CPxScene_fetchCollision(s.cS, C._Bool(block)))
|
||||
}
|
||||
|
||||
func (s *Scene) Advance() {
|
||||
C.CPxScene_advance(s.cS)
|
||||
}
|
||||
|
||||
func (s *Scene) FetchResults(block bool) (bool, uint32) {
|
||||
|
||||
var errState uint32
|
||||
@ -126,9 +140,6 @@ func (p *Physics) CreateMaterial(staticFriction, dynamicFriction, restitution fl
|
||||
}
|
||||
}
|
||||
|
||||
// CPxAPI CSTRUCT CPxRigidDynamic* CPxPhysics_createRigidDynamic(CSTRUCT CPxPhysics* cp, CSTRUCT CPxTransform* ctr);
|
||||
// CPxAPI CSTRUCT CPxRigidStatic* CPxPhysics_createRigidStatic(CSTRUCT CPxPhysics* cp, CSTRUCT CPxTransform* ctr);
|
||||
|
||||
func (p *Physics) CreateRigidDynamic(tr *Transform) *RigidDynamic {
|
||||
return &RigidDynamic{
|
||||
cRd: C.CPxPhysics_createRigidDynamic(p.cPhysics, &tr.cT),
|
||||
|
||||
@ -18,6 +18,9 @@ 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 void CPxScene_collide(CSTRUCT CPxScene*, CPxReal elapsedTime);
|
||||
CPxAPI bool CPxScene_fetchCollision(CSTRUCT CPxScene*, bool block);
|
||||
CPxAPI void CPxScene_advance(CSTRUCT CPxScene*);
|
||||
CPxAPI bool CPxScene_fetchResults(CSTRUCT CPxScene*, bool block, CPxU32* errorState);
|
||||
|
||||
/// <summary>
|
||||
|
||||
Reference in New Issue
Block a user