no message

This commit is contained in:
gem
2025-02-18 15:21:31 +08:00
commit 2d133e56d7
1980 changed files with 465595 additions and 0 deletions

View File

@@ -0,0 +1,161 @@
/****************************************************************************
Copyright (c) 2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "physics/sdk/CharacterController.h"
#include <memory>
#include "physics/PhysicsSelector.h"
#define CC_PHYSICS_CCT_DEFINITION(CLASS, WRAPPED) \
\
CLASS::CLASS() { \
_impl.reset(ccnew WRAPPED()); \
} \
\
CLASS::~CLASS() { \
_impl.reset(nullptr); \
} \
\
bool CLASS::initialize(Node *node) { \
return _impl->initialize(node); \
} \
\
void CLASS::onEnable() { \
_impl->onEnable(); \
} \
\
void CLASS::onDisable() { \
_impl->onDisable(); \
} \
\
void CLASS::onDestroy() { \
_impl->onDestroy(); \
} \
\
cc::Vec3 CLASS::getPosition() { \
return _impl->getPosition(); \
} \
\
void CLASS::setPosition(float x, float y, float z) { \
_impl->setPosition(x, y, z); \
} \
\
bool CLASS::onGround() { \
return _impl->onGround(); \
} \
\
void CLASS::move(float x, float y, float z, float minDist, float elapsedTime) { \
_impl->move(x, y, z, minDist, elapsedTime); \
} \
\
void CLASS::syncPhysicsToScene() { \
_impl->syncPhysicsToScene(); \
} \
\
void CLASS::setStepOffset(float v) { \
_impl->setStepOffset(v); \
} \
\
float CLASS::getStepOffset() { \
return _impl->getStepOffset(); \
} \
\
void CLASS::setSlopeLimit(float v) { \
_impl->setSlopeLimit(v); \
} \
\
float CLASS::getSlopeLimit() { \
return _impl->getSlopeLimit(); \
} \
\
void CLASS::setContactOffset(float v) { \
_impl->setContactOffset(v); \
} \
\
float CLASS::getContactOffset() { \
return _impl->getContactOffset(); \
} \
\
void CLASS::setDetectCollisions(bool v) { \
_impl->setDetectCollisions(v); \
} \
void CLASS::setOverlapRecovery(bool v) { \
_impl->setOverlapRecovery(v); \
} \
void CLASS::setCenter(float x, float y, float z) { \
_impl->setCenter(x, y, z); \
} \
uint32_t CLASS::getGroup() { \
return _impl->getGroup(); \
} \
\
void CLASS::setGroup(uint32_t g) { \
_impl->setGroup(g); \
} \
\
uint32_t CLASS::getMask() { \
return _impl->getMask(); \
} \
\
void CLASS::setMask(uint32_t m) { \
_impl->setMask(m); \
} \
void CLASS::updateEventListener(EShapeFilterFlag flag) { \
_impl->updateEventListener(flag); \
} \
uint32_t CLASS::getObjectID()const { \
return _impl->getObjectID(); \
} \
\
namespace cc {
namespace physics {
/// COMMON ///
CC_PHYSICS_CCT_DEFINITION(CapsuleCharacterController, WrappedCapsuleCharacterController)
CC_PHYSICS_CCT_DEFINITION(BoxCharacterController, WrappedBoxCharacterController)
/// EXTRAS ///
void CapsuleCharacterController::setRadius(float v) {
_impl->setRadius(v);
}
void CapsuleCharacterController::setHeight(float v) {
_impl->setHeight(v);
}
void BoxCharacterController::setHalfHeight(float v) {
_impl->setHalfHeight(v);
}
void BoxCharacterController::setHalfSideExtent(float v) {
_impl->setHalfSideExtent(v);
}
void BoxCharacterController::setHalfForwardExtent(float v) {
_impl->setHalfForwardExtent(v);
}
} // namespace physics
} // namespace cc

View File

@@ -0,0 +1,80 @@
/****************************************************************************
Copyright (c) 2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#pragma once
#include <memory>
#include "base/Macros.h"
#include "core/scene-graph/Node.h"
#include "physics/spec/IShape.h"
#include "physics/spec/ICharacterController.h"
#define CC_PHYSICS_CCT_CLASS(CLASS) \
class CC_DLL CLASS final : public I##CLASS { \
protected: \
std::unique_ptr<I##CLASS> _impl; \
\
public: \
CLASS(); \
~CLASS() override; \
bool initialize(Node *node) override; \
void onEnable() override; \
void onDisable() override; \
void onDestroy() override; \
virtual cc::Vec3 getPosition() override; \
virtual void setPosition(float x, float y, float z) override; \
virtual bool onGround() override; \
virtual void move(float x, float y, float z, float minDist, \
float elapsedTime) override; \
void syncPhysicsToScene() override; \
virtual void setStepOffset(float v) override; \
virtual float getStepOffset() override; \
virtual void setSlopeLimit(float v) override; \
virtual float getSlopeLimit() override; \
virtual void setContactOffset(float v) override; \
virtual float getContactOffset() override; \
virtual void setDetectCollisions(bool v) override; \
virtual void setOverlapRecovery(bool v) override; \
virtual void setCenter(float x, float y, float z) override; \
uint32_t getGroup() override; \
void setGroup(uint32_t g) override; \
uint32_t getMask() override; \
void setMask(uint32_t m) override; \
void updateEventListener(EShapeFilterFlag flag) override; \
uint32_t getObjectID() const override;
namespace cc {
namespace physics {
CC_PHYSICS_CCT_CLASS(CapsuleCharacterController)
void setRadius(float v) override;
void setHeight(float v) override;
};
CC_PHYSICS_CCT_CLASS(BoxCharacterController)
void setHalfHeight(float v) override;
void setHalfSideExtent(float v) override;
void setHalfForwardExtent(float v) override;
};
}; // namespace physics
} // namespace cc

223
cocos/physics/sdk/Joint.cpp Normal file
View File

@@ -0,0 +1,223 @@
/****************************************************************************
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "physics/sdk/Joint.h"
#include "base/memory/Memory.h"
#include "physics/PhysicsSelector.h"
#define CC_PHYSICS_JOINT_DEFINITION(CLASS, WRAPPED) \
\
CLASS::CLASS() { \
_impl.reset(ccnew WRAPPED()); \
} \
\
CLASS::~CLASS() { \
_impl.reset(nullptr); \
} \
\
void CLASS::initialize(Node *node) { \
_impl->initialize(node); \
} \
\
void CLASS::onEnable() { \
_impl->onEnable(); \
} \
\
void CLASS::onDisable() { \
_impl->onDisable(); \
} \
\
void CLASS::onDestroy() { \
_impl->onDestroy(); \
} \
\
void CLASS::setConnectedBody(uint32_t rigidBodyID) { \
_impl->setConnectedBody(rigidBodyID); \
} \
\
void CLASS::setEnableCollision(bool v) { \
_impl->setEnableCollision(v); \
} \
uint32_t CLASS::getObjectID() const { \
return _impl->getObjectID(); \
}
namespace cc {
namespace physics {
/// COMMON ///
CC_PHYSICS_JOINT_DEFINITION(SphericalJoint, WrappedSphericalJoint)
CC_PHYSICS_JOINT_DEFINITION(RevoluteJoint, WrappedRevoluteJoint)
CC_PHYSICS_JOINT_DEFINITION(FixedJoint, WrappedFixedJoint)
CC_PHYSICS_JOINT_DEFINITION(GenericJoint, WrappedGenericJoint)
/// EXTRAS ///
void SphericalJoint::setPivotA(float x, float y, float z) {
_impl->setPivotA(x, y, z);
}
void SphericalJoint::setPivotB(float x, float y, float z) {
_impl->setPivotB(x, y, z);
}
void RevoluteJoint::setPivotA(float x, float y, float z) {
_impl->setPivotA(x, y, z);
}
void RevoluteJoint::setPivotB(float x, float y, float z) {
_impl->setPivotB(x, y, z);
}
void RevoluteJoint::setAxis(float x, float y, float z) {
_impl->setAxis(x, y, z);
}
void RevoluteJoint::setLimitEnabled(bool v) {
_impl->setLimitEnabled(v);
}
void RevoluteJoint::setLowerLimit(float v) {
_impl->setLowerLimit(v);
}
void RevoluteJoint::setUpperLimit(float v) {
_impl->setUpperLimit(v);
}
void RevoluteJoint::setMotorEnabled(bool v) {
_impl->setMotorEnabled(v);
}
void RevoluteJoint::setMotorVelocity(float v) {
_impl->setMotorVelocity(v);
}
void RevoluteJoint::setMotorForceLimit(float v) {
_impl->setMotorForceLimit(v);
}
void FixedJoint::setBreakForce(float force) {
_impl->setBreakForce(force);
}
void FixedJoint::setBreakTorque(float torque) {
_impl->setBreakTorque(torque);
}
void GenericJoint::setConstraintMode(uint32_t index, uint32_t mode) {
_impl->setConstraintMode(index, mode);
}
void GenericJoint::setLinearLimit(uint32_t index, float lower, float upper) {
_impl->setLinearLimit(index, lower, upper);
}
void GenericJoint::setAngularExtent(float twist, float swing1, float swing2) {
_impl->setAngularExtent(twist, swing1, swing2);
}
void GenericJoint::setLinearSoftConstraint(bool enable) {
_impl->setLinearSoftConstraint(enable);
}
void GenericJoint::setLinearStiffness(float stiffness) {
_impl->setLinearStiffness(stiffness);
}
void GenericJoint::setLinearDamping(float damping) {
_impl->setLinearDamping(damping);
}
void GenericJoint::setLinearRestitution(float restitution) {
_impl->setLinearRestitution(restitution);
}
void GenericJoint::setSwingSoftConstraint(bool enable) {
_impl->setSwingSoftConstraint(enable);
}
void GenericJoint::setTwistSoftConstraint(bool enable) {
_impl->setTwistSoftConstraint(enable);
}
void GenericJoint::setSwingStiffness(float stiffness) {
_impl->setSwingStiffness(stiffness);
}
void GenericJoint::setSwingDamping(float damping) {
_impl->setSwingDamping(damping);
}
void GenericJoint::setSwingRestitution(float restitution) {
_impl->setSwingRestitution(restitution);
}
void GenericJoint::setTwistStiffness(float stiffness) {
_impl->setTwistStiffness(stiffness);
}
void GenericJoint::setTwistDamping(float damping) {
_impl->setTwistDamping(damping);
}
void GenericJoint::setTwistRestitution(float restitution) {
_impl->setTwistRestitution(restitution);
}
void GenericJoint::setDriverMode(uint32_t index, uint32_t mode) {
_impl->setDriverMode(index, mode);
}
void GenericJoint::setLinearMotorTarget(float x, float y, float z) {
_impl->setLinearMotorTarget(x, y, z);
}
void GenericJoint::setLinearMotorVelocity(float x, float y, float z) {
_impl->setLinearMotorVelocity(x, y, z);
}
void GenericJoint::setLinearMotorForceLimit(float limit) {
_impl->setLinearMotorForceLimit(limit);
}
void GenericJoint::setAngularMotorTarget(float x, float y, float z) {
_impl->setAngularMotorTarget(x, y, z);
}
void GenericJoint::setAngularMotorVelocity(float x, float y, float z) {
_impl->setAngularMotorVelocity(x, y, z);
}
void GenericJoint::setAngularMotorForceLimit(float limit) {
_impl->setAngularMotorForceLimit(limit);
}
void GenericJoint::setPivotA(float x, float y, float z) {
_impl->setPivotA(x, y, z);
}
void GenericJoint::setPivotB(float x, float y, float z) {
_impl->setPivotB(x, y, z);
}
void GenericJoint::setAutoPivotB(bool enable) {
_impl->setAutoPivotB(enable);
}
void GenericJoint::setAxis(float x, float y, float z) {
_impl->setAxis(x, y, z);
}
void GenericJoint::setSecondaryAxis(float x, float y, float z) {
_impl->setSecondaryAxis(x, y, z);
}
void GenericJoint::setBreakForce(float force) {
_impl->setBreakForce(force);
}
void GenericJoint::setBreakTorque(float torque) {
_impl->setBreakTorque(torque);
}
} // namespace physics
} // namespace cc

114
cocos/physics/sdk/Joint.h Normal file
View File

@@ -0,0 +1,114 @@
/****************************************************************************
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#pragma once
#include <cstdint>
#include <memory>
#include "base/Macros.h"
#include "core/scene-graph/Node.h"
#include "physics/spec/IJoint.h"
#define CC_PHYSICS_JOINT_CLASS(CLASS) \
class CC_DLL CLASS final : virtual public I##CLASS { \
protected: \
std::unique_ptr<I##CLASS> _impl; \
\
public: \
CLASS(); \
~CLASS() override; \
void initialize(Node *node) override; \
void onEnable() override; \
void onDisable() override; \
void onDestroy() override; \
void setEnableCollision(bool v) override; \
void setConnectedBody(uint32_t rigidBodyID) override; \
uint32_t getObjectID() const override;
namespace cc {
namespace physics {
CC_PHYSICS_JOINT_CLASS(RevoluteJoint)
void setPivotA(float x, float y, float z) override;
void setPivotB(float x, float y, float z) override;
void setAxis(float x, float y, float z) override;
void setLimitEnabled(bool v) override;
void setLowerLimit(float v) override;
void setUpperLimit(float v) override;
void setMotorEnabled(bool v) override;
void setMotorVelocity(float v) override;
void setMotorForceLimit(float v) override;
}; // RevoluteJoint
CC_PHYSICS_JOINT_CLASS(SphericalJoint)
void setPivotA(float x, float y, float z) override;
void setPivotB(float x, float y, float z) override;
}; // SphericalJoint
CC_PHYSICS_JOINT_CLASS(FixedJoint)
void setBreakForce(float force) override;
void setBreakTorque(float torque) override;
}
; // FixedJoint
CC_PHYSICS_JOINT_CLASS(GenericJoint)
void setConstraintMode(uint32_t index, uint32_t mode) override;
void setLinearLimit(uint32_t index, float lower, float upper) override;
void setAngularExtent(float twist, float swing1, float swing2) override;
void setLinearSoftConstraint(bool enable) override;
void setLinearStiffness(float stiffness) override;
void setLinearDamping(float damping) override;
void setLinearRestitution(float restitution) override;
void setSwingSoftConstraint(bool enable) override;
void setTwistSoftConstraint(bool enable) override;
void setSwingStiffness(float stiffness) override;
void setSwingDamping(float damping) override;
void setSwingRestitution(float restitution) override;
void setTwistStiffness(float stiffness) override;
void setTwistDamping(float damping) override;
void setTwistRestitution(float restitution) override;
virtual void setDriverMode(uint32_t index, uint32_t mode) override;
void setLinearMotorTarget(float x, float y, float z) override;
void setLinearMotorVelocity(float x, float y, float z) override;
void setLinearMotorForceLimit(float limit) override;
void setAngularMotorTarget(float x, float y, float z) override;
void setAngularMotorVelocity(float x, float y, float z) override;
void setAngularMotorForceLimit(float limit) override;
void setPivotA(float x, float y, float z) override;
void setPivotB(float x, float y, float z) override;
void setAutoPivotB(bool enable) override;
void setAxis(float x, float y, float z) override;
void setSecondaryAxis(float x, float y, float z) override;
void setBreakForce(float force) override;
void setBreakTorque(float torque) override;
}
;
} // namespace physics
} // namespace cc

View File

@@ -0,0 +1,193 @@
/****************************************************************************
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "physics/sdk/RigidBody.h"
#include <memory>
#include "physics/PhysicsSelector.h"
namespace cc {
namespace physics {
RigidBody::RigidBody() {
_impl = std::make_unique<WrappedRigidBody>();
}
RigidBody::~RigidBody() {
_impl.reset(nullptr);
}
void RigidBody::initialize(Node *node, const ERigidBodyType t, const uint32_t g) {
_impl->initialize(node, t, g);
}
void RigidBody::onEnable() {
_impl->onEnable();
}
void RigidBody::onDisable() {
_impl->onDisable();
}
void RigidBody::onDestroy() {
_impl->onDestroy();
}
bool RigidBody::isAwake() {
return _impl->isAwake();
}
bool RigidBody::isSleepy() {
return _impl->isSleepy();
}
bool RigidBody::isSleeping() {
return _impl->isSleeping();
}
void RigidBody::setType(ERigidBodyType v) {
_impl->setType(v);
}
void RigidBody::setMass(float v) {
_impl->setMass(v);
}
void RigidBody::setLinearDamping(float v) {
_impl->setLinearDamping(v);
}
void RigidBody::setAngularDamping(float v) {
_impl->setAngularDamping(v);
}
void RigidBody::useCCD(bool v) {
_impl->useCCD(v);
}
void RigidBody::useGravity(bool v) {
_impl->useGravity(v);
}
void RigidBody::setLinearFactor(float x, float y, float z) {
_impl->setLinearFactor(x, y, z);
}
void RigidBody::setAngularFactor(float x, float y, float z) {
_impl->setAngularFactor(x, y, z);
}
void RigidBody::setAllowSleep(bool v) {
_impl->setAllowSleep(v);
}
void RigidBody::wakeUp() {
_impl->wakeUp();
}
void RigidBody::sleep() {
_impl->sleep();
}
void RigidBody::clearState() {
_impl->clearState();
}
void RigidBody::clearForces() {
_impl->clearForces();
}
void RigidBody::clearVelocity() {
_impl->clearVelocity();
}
void RigidBody::setSleepThreshold(float v) {
_impl->setSleepThreshold(v);
}
float RigidBody::getSleepThreshold() {
return _impl->getSleepThreshold();
}
cc::Vec3 RigidBody::getLinearVelocity() {
return _impl->getLinearVelocity();
}
void RigidBody::setLinearVelocity(float x, float y, float z) {
_impl->setLinearVelocity(x, y, z);
}
cc::Vec3 RigidBody::getAngularVelocity() {
return _impl->getAngularVelocity();
}
void RigidBody::setAngularVelocity(float x, float y, float z) {
_impl->setAngularVelocity(x, y, z);
}
void RigidBody::applyForce(float x, float y, float z, float rx, float ry, float rz) {
_impl->applyForce(x, y, z, rx, ry, rz);
}
void RigidBody::applyLocalForce(float x, float y, float z, float rx, float ry, float rz) {
_impl->applyLocalForce(x, y, z, rx, ry, rz);
}
void RigidBody::applyImpulse(float x, float y, float z, float rx, float ry, float rz) {
_impl->applyImpulse(x, y, z, rx, ry, rz);
}
void RigidBody::applyLocalImpulse(float x, float y, float z, float rx, float ry, float rz) {
_impl->applyLocalImpulse(x, y, z, rx, ry, rz);
}
void RigidBody::applyTorque(float x, float y, float z) {
_impl->applyTorque(x, y, z);
}
void RigidBody::applyLocalTorque(float x, float y, float z) {
_impl->applyLocalTorque(x, y, z);
}
uint32_t RigidBody::getGroup() {
return _impl->getGroup();
}
void RigidBody::setGroup(uint32_t g) {
_impl->setGroup(g);
}
uint32_t RigidBody::getMask() {
return _impl->getMask();
}
void RigidBody::setMask(uint32_t m) {
_impl->setMask(m);
}
uint32_t RigidBody::getObjectID() const {
return _impl->getObjectID();
}
} // namespace physics
} // namespace cc

View File

@@ -0,0 +1,80 @@
/****************************************************************************
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#pragma once
#include <memory>
#include "base/Macros.h"
#include "physics/spec/IBody.h"
namespace cc {
namespace physics {
class CC_DLL RigidBody final : public IRigidBody {
public:
RigidBody();
~RigidBody() override;
void initialize(Node *node, ERigidBodyType t, uint32_t g) override;
void onEnable() override;
void onDisable() override;
void onDestroy() override;
bool isAwake() override;
bool isSleepy() override;
bool isSleeping() override;
void setType(ERigidBodyType v) override;
void setMass(float v) override;
void setLinearDamping(float v) override;
void setAngularDamping(float v) override;
void useGravity(bool v) override;
void useCCD(bool v) override;
void setLinearFactor(float x, float y, float z) override;
void setAngularFactor(float x, float y, float z) override;
void setAllowSleep(bool v) override;
void wakeUp() override;
void sleep() override;
void clearState() override;
void clearForces() override;
void clearVelocity() override;
void setSleepThreshold(float v) override;
float getSleepThreshold() override;
cc::Vec3 getLinearVelocity() override;
void setLinearVelocity(float x, float y, float z) override;
cc::Vec3 getAngularVelocity() override;
void setAngularVelocity(float x, float y, float z) override;
void applyForce(float x, float y, float z, float rx, float ry, float rz) override;
void applyLocalForce(float x, float y, float z, float rx, float ry, float rz) override;
void applyImpulse(float x, float y, float z, float rx, float ry, float rz) override;
void applyLocalImpulse(float x, float y, float z, float rx, float ry, float rz) override;
void applyTorque(float x, float y, float z) override;
void applyLocalTorque(float x, float y, float z) override;
uint32_t getGroup() override;
void setGroup(uint32_t g) override;
uint32_t getMask() override;
void setMask(uint32_t m) override;
uint32_t getObjectID() const override;
private:
std::unique_ptr<IRigidBody> _impl;
};
} // namespace physics
} // namespace cc

173
cocos/physics/sdk/Shape.cpp Normal file
View File

@@ -0,0 +1,173 @@
/****************************************************************************
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "physics/sdk/Shape.h"
#include "base/memory/Memory.h"
#include "physics/PhysicsSelector.h"
#define CC_PHYSICS_SHAPE_DEFINITION(CLASS, WRAPPED) \
\
CLASS::CLASS() { \
_impl.reset(ccnew WRAPPED()); \
} \
\
CLASS::~CLASS() { \
_impl.reset(nullptr); \
} \
\
void CLASS::initialize(Node *node) { \
_impl->initialize(node); \
} \
\
void CLASS::onEnable() { \
_impl->onEnable(); \
} \
\
void CLASS::onDisable() { \
_impl->onDisable(); \
} \
\
void CLASS::onDestroy() { \
_impl->onDestroy(); \
} \
\
void CLASS::setMaterial(uint16_t ID, float f, float df, float r, \
uint8_t m0, uint8_t m1) { \
_impl->setMaterial(ID, f, df, r, m0, m1); \
} \
\
void CLASS::setAsTrigger(bool v) { \
_impl->setAsTrigger(v); \
} \
\
void CLASS::setCenter(float x, float y, float z) { \
_impl->setCenter(x, y, z); \
} \
\
void CLASS::setGroup(uint32_t g) { \
_impl->setGroup(g); \
} \
\
uint32_t CLASS::getGroup() { \
return _impl->getGroup(); \
} \
\
void CLASS::setMask(uint32_t m) { \
_impl->setMask(m); \
} \
\
uint32_t CLASS::getMask() { \
return _impl->getMask(); \
} \
\
void CLASS::updateEventListener(EShapeFilterFlag v) { \
_impl->updateEventListener(v); \
} \
\
geometry::AABB &CLASS::getAABB() { \
return _impl->getAABB(); \
} \
\
geometry::Sphere &CLASS::getBoundingSphere() { \
return _impl->getBoundingSphere(); \
} \
\
uint32_t CLASS::getObjectID() const { \
return _impl->getObjectID(); \
}
namespace cc {
namespace physics {
/// COMMON ///
CC_PHYSICS_SHAPE_DEFINITION(SphereShape, WrappedSphereShape)
CC_PHYSICS_SHAPE_DEFINITION(BoxShape, WrappedBoxShape)
CC_PHYSICS_SHAPE_DEFINITION(PlaneShape, WrappedPlaneShape)
CC_PHYSICS_SHAPE_DEFINITION(CapsuleShape, WrappedCapsuleShape)
CC_PHYSICS_SHAPE_DEFINITION(CylinderShape, WrappedCylinderShape)
CC_PHYSICS_SHAPE_DEFINITION(ConeShape, WrappedConeShape)
CC_PHYSICS_SHAPE_DEFINITION(TrimeshShape, WrappedTrimeshShape)
CC_PHYSICS_SHAPE_DEFINITION(TerrainShape, WrappedTerrainShape)
/// EXTRAS ///
void SphereShape::setRadius(float v) {
_impl->setRadius(v);
}
void BoxShape::setSize(float x, float y, float z) {
_impl->setSize(x, y, z);
}
void CapsuleShape::setRadius(float v) {
_impl->setRadius(v);
}
void CapsuleShape::setCylinderHeight(float v) {
_impl->setCylinderHeight(v);
}
void CapsuleShape::setDirection(EAxisDirection v) {
_impl->setDirection(v);
}
void PlaneShape::setConstant(float v) {
_impl->setConstant(v);
}
void PlaneShape::setNormal(float x, float y, float z) {
_impl->setNormal(x, y, z);
}
void TrimeshShape::setMesh(uint32_t objectID) {
_impl->setMesh(objectID);
}
void TrimeshShape::useConvex(bool v) {
_impl->useConvex(v);
}
void TerrainShape::setTerrain(uint32_t objectID, float rs, float cs, float hs) {
_impl->setTerrain(objectID, rs, cs, hs);
}
void CylinderShape::setConvex(uint32_t objectID) {
_impl->setConvex(objectID);
}
void CylinderShape::setCylinder(float r, float h, EAxisDirection d) {
_impl->setCylinder(r, h, d);
}
void ConeShape::setConvex(uint32_t objectID) {
_impl->setConvex(objectID);
}
void ConeShape::setCone(float r, float h, EAxisDirection d) {
_impl->setCone(r, h, d);
}
} // namespace physics
} // namespace cc

107
cocos/physics/sdk/Shape.h Normal file
View File

@@ -0,0 +1,107 @@
/****************************************************************************
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#pragma once
#include <cstdint>
#include <memory>
#include "base/Macros.h"
#include "core/geometry/AABB.h"
#include "core/geometry/Sphere.h"
#include "physics/spec/IShape.h"
#define CC_PHYSICS_SHAPE_CLASS(CLASS) \
class CC_DLL CLASS final : public I##CLASS { \
protected: \
std::unique_ptr<I##CLASS> _impl; \
\
public: \
CLASS(); \
~CLASS() override; \
void initialize(Node *node) override; \
void onEnable() override; \
void onDisable() override; \
void onDestroy() override; \
void setMaterial(uint16_t ID, float f, float df, float r, \
uint8_t m0, uint8_t m1) override; \
void setAsTrigger(bool v) override; \
void setCenter(float x, float y, float z) override; \
void updateEventListener(EShapeFilterFlag v) override; \
geometry::AABB &getAABB() override; \
geometry::Sphere &getBoundingSphere() override; \
uint32_t getGroup() override; \
void setGroup(uint32_t g) override; \
uint32_t getMask() override; \
void setMask(uint32_t m) override; \
uint32_t getObjectID() const override;
namespace cc {
namespace physics {
CC_PHYSICS_SHAPE_CLASS(SphereShape)
void setRadius(float v) override;
}; // namespace physics
CC_PHYSICS_SHAPE_CLASS(BoxShape)
void setSize(float x, float y, float z) override;
}; // namespace cc
CC_PHYSICS_SHAPE_CLASS(CapsuleShape)
void setRadius(float v) override;
void setCylinderHeight(float v) override;
void setDirection(EAxisDirection v) override;
}
;
CC_PHYSICS_SHAPE_CLASS(PlaneShape)
void setConstant(float v) override;
void setNormal(float x, float y, float z) override;
}
;
CC_PHYSICS_SHAPE_CLASS(TrimeshShape)
void setMesh(uint32_t objectID) override;
void useConvex(bool v) override;
}
;
CC_PHYSICS_SHAPE_CLASS(CylinderShape)
void setConvex(uint32_t objectID) override;
void setCylinder(float r, float h, EAxisDirection d) override;
}
;
CC_PHYSICS_SHAPE_CLASS(ConeShape)
void setConvex(uint32_t objectID) override;
void setCone(float r, float h, EAxisDirection d) override;
}
;
CC_PHYSICS_SHAPE_CLASS(TerrainShape)
void setTerrain(uint32_t objectID, float rs, float cs, float hs) override;
}
;
} // namespace physics
} // namespace cc

182
cocos/physics/sdk/World.cpp Normal file
View File

@@ -0,0 +1,182 @@
/****************************************************************************
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#include "physics/sdk/World.h"
#include <memory>
#include "physics/PhysicsSelector.h"
namespace cc {
namespace physics {
World::World() {
_impl = std::make_unique<WrappedWorld>();
}
World::~World() {
_impl.reset(nullptr);
}
void World::emitEvents() {
_impl->emitEvents();
}
void World::step(float fixedTimeStep) {
_impl->step(fixedTimeStep);
}
void World::setAllowSleep(bool v) {
_impl->setAllowSleep(v);
}
void World::setGravity(float x, float y, float z) {
_impl->setGravity(x, y, z);
}
bool World::createMaterial(uint16_t id, float f, float df, float r,
uint8_t m0, uint8_t m1) {
return _impl->createMaterial(id, f, df, r, m0, m1);
}
void World::syncSceneToPhysics() {
_impl->syncSceneToPhysics();
}
void World::syncSceneWithCheck() {
_impl->syncSceneWithCheck();
}
void World::destroy() {
_impl->destroy();
}
ccstd::vector<std::shared_ptr<TriggerEventPair>> &World::getTriggerEventPairs() {
return _impl->getTriggerEventPairs();
}
ccstd::vector<std::shared_ptr<ContactEventPair>> &World::getContactEventPairs() {
return _impl->getContactEventPairs();
}
ccstd::vector<std::shared_ptr<CCTShapeEventPair>>& World::getCCTShapeEventPairs() {
return _impl->getCCTShapeEventPairs();
}
ccstd::vector<std::shared_ptr<CCTTriggerEventPair>> &World::getCCTTriggerEventPairs() {
return _impl->getCCTTriggerEventPairs();
}
void World::setDebugDrawFlags(EPhysicsDrawFlags flags) {
_impl->setDebugDrawFlags(flags);
}
EPhysicsDrawFlags World::getDebugDrawFlags() {
return _impl->getDebugDrawFlags();
}
void World::setDebugDrawConstraintSize(float size) {
_impl->setDebugDrawConstraintSize(size);
}
float World::getDebugDrawConstraintSize() {
return _impl->getDebugDrawConstraintSize();
}
void World::setCollisionMatrix(uint32_t i, uint32_t m) {
_impl->setCollisionMatrix(i, m);
}
uint32_t World::createConvex(ConvexDesc &desc) {
return _impl->createConvex(desc);
}
uint32_t World::createTrimesh(TrimeshDesc &desc) {
return _impl->createTrimesh(desc);
}
uint32_t World::createHeightField(HeightFieldDesc &desc) {
return _impl->createHeightField(desc);
}
bool World::raycast(RaycastOptions &opt) {
return _impl->raycast(opt);
}
ccstd::vector<RaycastResult> &World::raycastResult() {
return _impl->raycastResult();
}
bool World::raycastClosest(RaycastOptions &opt) {
return _impl->raycastClosest(opt);
}
RaycastResult &World::raycastClosestResult() {
return _impl->raycastClosestResult();
}
float World::getFixedTimeStep() const {
return _impl->getFixedTimeStep();
}
void World::setFixedTimeStep(float fixedTimeStep) {
_impl->setFixedTimeStep(fixedTimeStep);
}
bool World::sweepBox(RaycastOptions &opt, float halfExtentX, float halfExtentY, float halfExtentZ,
float orientationW, float orientationX, float orientationY, float orientationZ){
return _impl->sweepBox(opt, halfExtentX, halfExtentY, halfExtentZ, orientationW, orientationX, orientationY, orientationZ);
}
bool World::sweepBoxClosest(RaycastOptions &opt, float halfExtentX, float halfExtentY, float halfExtentZ,
float orientationW, float orientationX, float orientationY, float orientationZ){
return _impl->sweepBoxClosest(opt, halfExtentX, halfExtentY, halfExtentZ, orientationW, orientationX, orientationY, orientationZ);
}
bool World::sweepSphere(RaycastOptions &opt, float radius) {
return _impl->sweepSphere(opt, radius);
}
bool World::sweepSphereClosest(RaycastOptions &opt, float radius) {
return _impl->sweepSphereClosest(opt, radius);
}
bool World::sweepCapsule(RaycastOptions &opt, float radius, float height,
float orientationW, float orientationX, float orientationY, float orientationZ) {
return _impl->sweepCapsule(opt, radius, height, orientationW, orientationX, orientationY, orientationZ);
}
bool World::sweepCapsuleClosest(RaycastOptions &opt, float radius, float height,
float orientationW, float orientationX, float orientationY, float orientationZ) {
return _impl->sweepCapsuleClosest(opt, radius, height, orientationW, orientationX, orientationY, orientationZ);
}
RaycastResult &World::sweepClosestResult() {
return _impl->sweepClosestResult();
}
ccstd::vector<RaycastResult> &World::sweepResult() {
return _impl->sweepResult();
}
} // namespace physics
} // namespace cc

83
cocos/physics/sdk/World.h Normal file
View File

@@ -0,0 +1,83 @@
/****************************************************************************
Copyright (c) 2020-2023 Xiamen Yaji Software Co., Ltd.
http://www.cocos.com
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do so,
subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#pragma once
#include <memory>
#include "base/Macros.h"
#include "physics/spec/IWorld.h"
namespace cc {
namespace physics {
class CC_DLL World final : public IPhysicsWorld {
public:
World();
~World() override;
void setGravity(float x, float y, float z) override;
void setAllowSleep(bool v) override;
void step(float fixedTimeStep) override;
void emitEvents() override;
void syncSceneToPhysics() override;
void syncSceneWithCheck() override;
void setDebugDrawFlags(EPhysicsDrawFlags flags) override;
EPhysicsDrawFlags getDebugDrawFlags() override;
void setDebugDrawConstraintSize(float size) override;
float getDebugDrawConstraintSize() override;
void setCollisionMatrix(uint32_t i, uint32_t m) override;
ccstd::vector<std::shared_ptr<TriggerEventPair>> &getTriggerEventPairs() override;
ccstd::vector<std::shared_ptr<ContactEventPair>>& getContactEventPairs() override;
ccstd::vector<std::shared_ptr<CCTShapeEventPair>>& getCCTShapeEventPairs() override;
ccstd::vector<std::shared_ptr<CCTTriggerEventPair>>& getCCTTriggerEventPairs() override;
bool raycast(RaycastOptions &opt) override;
bool raycastClosest(RaycastOptions &opt) override;
ccstd::vector<RaycastResult> &raycastResult() override;
RaycastResult &raycastClosestResult() override;
bool sweepBox(RaycastOptions &opt, float halfExtentX, float halfExtentY, float halfExtentZ,
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;
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;
bool sweepCapsuleClosest(RaycastOptions &opt, float radius, float height,
float orientationW, float orientationX, float orientationY, float orientationZ) override;
RaycastResult &sweepClosestResult() override;
ccstd::vector<RaycastResult> &sweepResult() override;
uint32_t createConvex(ConvexDesc &desc) override;
uint32_t createTrimesh(TrimeshDesc &desc) override;
uint32_t createHeightField(HeightFieldDesc &desc) override;
bool createMaterial(uint16_t id, float f, float df, float r,
uint8_t m0, uint8_t m1) override;
float getFixedTimeStep() const override;
void setFixedTimeStep(float fixedTimeStep) override;
void destroy() override;
private:
std::unique_ptr<IPhysicsWorld> _impl;
};
} // namespace physics
} // namespace cc