Skip to content

Commit

Permalink
geometry renderer macro in physx (#16396)
Browse files Browse the repository at this point in the history
  • Loading branch information
hana-alice authored Oct 10, 2023
1 parent fcb95b5 commit 6eb501d
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 15 deletions.
4 changes: 4 additions & 0 deletions native/cocos/physics/physx/PhysXWorld.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ void PhysXWorld::step(float fixedTimeStep) {
_mScene->simulate(fixedTimeStep);
_mScene->fetchResults(true);
syncPhysicsToScene();
#if CC_USE_GEOMETRY_RENDERER
debugDraw();
#endif
}

#if CC_USE_GEOMETRY_RENDERER
pipeline::GeometryRenderer* PhysXWorld::getDebugRenderer () {
auto cameras = Root::getInstance()->getMainWindow()->getCameras();
scene::Camera* camera = nullptr;
Expand Down Expand Up @@ -222,6 +225,7 @@ void PhysXWorld::setDebugDrawConstraintSize(float size) {
float PhysXWorld::getDebugDrawConstraintSize() {
return _debugConstraintSize;
}
#endif

void PhysXWorld::setGravity(float x, float y, float z) {
_mScene->setGravity(physx::PxVec3(x, y, z));
Expand Down
37 changes: 22 additions & 15 deletions native/cocos/physics/physx/PhysXWorld.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@
#include "base/Macros.h"
#include "base/std/container/vector.h"
#include "core/scene-graph/Node.h"
#include "renderer/pipeline/GeometryRenderer.h"
#include "physics/physx/PhysXEventManager.h"
#include "physics/physx/PhysXFilterShader.h"
#include "physics/physx/PhysXInc.h"
#include "physics/physx/PhysXRigidBody.h"
#include "physics/physx/PhysXSharedBody.h"
#include "physics/physx/character-controllers/PhysXCharacterController.h"
#include "physics/spec/IWorld.h"
#include "renderer/pipeline/GeometryRenderer.h"

namespace cc {
namespace physics {
Expand All @@ -61,17 +61,17 @@ class PhysXWorld final : virtual public IPhysicsWorld {
RaycastResult &raycastClosestResult() override;

bool sweep(RaycastOptions &opt, const physx::PxGeometry &geometry, const physx::PxQuat &orientation);
bool sweepClosest(RaycastOptions& opt, const physx::PxGeometry& geometry, const physx::PxQuat& orientation);
bool sweepClosest(RaycastOptions &opt, const physx::PxGeometry &geometry, const physx::PxQuat &orientation);
bool sweepBox(RaycastOptions &opt, float halfExtentX, float halfExtentY, float halfExtentZ,
float orientationW, float orientationX, float orientationY, float orientationZ) override;
float orientationW, float orientationX, float orientationY, float orientationZ) override;
bool sweepBoxClosest(RaycastOptions &opt, float halfExtentX, float halfExtentY, float halfExtentZ,
float orientationW, float orientationX, float orientationY, float orientationZ) override;
float orientationW, float orientationX, float orientationY, float orientationZ) override;
bool sweepSphere(RaycastOptions &opt, float radius) override;
bool sweepSphereClosest(RaycastOptions &opt, float radius) override;
bool sweepCapsule(RaycastOptions &opt, float radius, float height,
float orientationW, float orientationX, float orientationY, float orientationZ) override;
float orientationW, float orientationX, float orientationY, float orientationZ) override;
bool sweepCapsuleClosest(RaycastOptions &opt, float radius, float height,
float orientationW, float orientationX, float orientationY, float orientationZ) override;
float orientationW, float orientationX, float orientationY, float orientationZ) override;
ccstd::vector<RaycastResult> &sweepResult() override;
RaycastResult &sweepClosestResult() override;

Expand All @@ -86,7 +86,7 @@ class PhysXWorld final : virtual public IPhysicsWorld {
inline ccstd::vector<std::shared_ptr<ContactEventPair>> &getContactEventPairs() override {
return _mEventMgr->getConatctPairs();
}
inline ccstd::vector<std::shared_ptr<CCTShapeEventPair>>& getCCTShapeEventPairs() override {
inline ccstd::vector<std::shared_ptr<CCTShapeEventPair>> &getCCTShapeEventPairs() override {
return _mEventMgr->getCCTShapePairs();
}
inline ccstd::vector<std::shared_ptr<CCTTriggerEventPair>> &getCCTTriggerEventPairs() override {
Expand All @@ -109,13 +109,13 @@ class PhysXWorld final : virtual public IPhysicsWorld {
void removeActor(const PhysXSharedBody &sb);
void addCCT(const PhysXCharacterController &cct);
void removeCCT(const PhysXCharacterController &cct);
//Mapping PhysX Object ID and Pointer

// Mapping PhysX Object ID and Pointer
uint32_t addPXObject(uintptr_t PXObjectPtr);
void removePXObject(uint32_t pxObjectID);
uintptr_t getPXPtrWithPXObjectID(uint32_t pxObjectID);

//Mapping Wrapper PhysX Object ID and Pointer
// Mapping Wrapper PhysX Object ID and Pointer
uint32_t addWrapperObject(uintptr_t wrapperObjectPtr);
void removeWrapperObject(uint32_t wrapperObjectID);
uintptr_t getWrapperPtrWithObjectID(uint32_t wrapperObjectID);
Expand All @@ -125,17 +125,24 @@ class PhysXWorld final : virtual public IPhysicsWorld {
float getFixedTimeStep() const override { return _fixedTimeStep; }
void setFixedTimeStep(float fixedTimeStep) override { _fixedTimeStep = fixedTimeStep; }

virtual void setDebugDrawFlags(EPhysicsDrawFlags flags) override;
virtual EPhysicsDrawFlags getDebugDrawFlags() override;
#if CC_USE_GEOMETRY_RENDERER
void setDebugDrawFlags(EPhysicsDrawFlags flags) override;
EPhysicsDrawFlags getDebugDrawFlags() override;

virtual void setDebugDrawConstraintSize(float size) override;
virtual float getDebugDrawConstraintSize() override;
void setDebugDrawConstraintSize(float size) override;
float getDebugDrawConstraintSize() override;

private:
pipeline::GeometryRenderer* getDebugRenderer();
pipeline::GeometryRenderer *getDebugRenderer();
void debugDraw();
void setDebugDrawMode();
#else
void setDebugDrawFlags(EPhysicsDrawFlags flags) override{};
EPhysicsDrawFlags getDebugDrawFlags() override { return EPhysicsDrawFlags::NONE; };

void setDebugDrawConstraintSize(float size) override{};
float getDebugDrawConstraintSize() override { return 0.0; };
#endif
private:
static PhysXWorld *instance;
physx::PxFoundation *_mFoundation;
Expand Down

0 comments on commit 6eb501d

Please sign in to comment.