no message
This commit is contained in:
81
cocos/physics/spec/IBody.h
Normal file
81
cocos/physics/spec/IBody.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
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 "core/scene-graph/Node.h"
|
||||
#include "math/Vec3.h"
|
||||
#include "physics/spec/ILifecycle.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
enum class ERigidBodyType : uint8_t {
|
||||
DYNAMIC = 1,
|
||||
STATIC = 2,
|
||||
KINEMATIC = 4,
|
||||
};
|
||||
|
||||
class IRigidBody : public ILifecycle {
|
||||
public:
|
||||
~IRigidBody() override = default;
|
||||
virtual void initialize(Node *node, ERigidBodyType t, uint32_t g) = 0;
|
||||
virtual bool isAwake() = 0;
|
||||
virtual bool isSleepy() = 0;
|
||||
virtual bool isSleeping() = 0;
|
||||
virtual void setType(ERigidBodyType v) = 0;
|
||||
virtual void setMass(float v) = 0;
|
||||
virtual void setLinearDamping(float v) = 0;
|
||||
virtual void setAngularDamping(float v) = 0;
|
||||
virtual void useGravity(bool v) = 0;
|
||||
virtual void useCCD(bool v) = 0;
|
||||
virtual void setLinearFactor(float x, float y, float z) = 0;
|
||||
virtual void setAngularFactor(float x, float y, float z) = 0;
|
||||
virtual void setAllowSleep(bool v) = 0;
|
||||
virtual void wakeUp() = 0;
|
||||
virtual void sleep() = 0;
|
||||
virtual void clearState() = 0;
|
||||
virtual void clearForces() = 0;
|
||||
virtual void clearVelocity() = 0;
|
||||
virtual void setSleepThreshold(float v) = 0;
|
||||
virtual float getSleepThreshold() = 0;
|
||||
virtual cc::Vec3 getLinearVelocity() = 0;
|
||||
virtual void setLinearVelocity(float x, float y, float z) = 0;
|
||||
virtual cc::Vec3 getAngularVelocity() = 0;
|
||||
virtual void setAngularVelocity(float x, float y, float z) = 0;
|
||||
virtual void applyForce(float x, float y, float z, float rx, float ry, float rz) = 0;
|
||||
virtual void applyLocalForce(float x, float y, float z, float rx, float ry, float rz) = 0;
|
||||
virtual void applyImpulse(float x, float y, float z, float rx, float ry, float rz) = 0;
|
||||
virtual void applyLocalImpulse(float x, float y, float z, float rx, float ry, float rz) = 0;
|
||||
virtual void applyTorque(float x, float y, float z) = 0;
|
||||
virtual void applyLocalTorque(float x, float y, float z) = 0;
|
||||
virtual uint32_t getGroup() = 0;
|
||||
virtual void setGroup(uint32_t g) = 0;
|
||||
virtual uint32_t getMask() = 0;
|
||||
virtual void setMask(uint32_t m) = 0;
|
||||
virtual uint32_t getObjectID() const = 0;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
81
cocos/physics/spec/ICharacterController.h
Normal file
81
cocos/physics/spec/ICharacterController.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/****************************************************************************
|
||||
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 "core/scene-graph/Node.h"
|
||||
#include "math/Vec3.h"
|
||||
#include "physics/spec/ILifecycle.h"
|
||||
#include "physics/spec/IShape.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class IBaseCharacterController : virtual public ILifecycle {
|
||||
public:
|
||||
~IBaseCharacterController() override = default;
|
||||
virtual bool initialize(Node *node) = 0;
|
||||
|
||||
virtual void setStepOffset(float v) = 0;
|
||||
virtual float getStepOffset() = 0;
|
||||
virtual void setSlopeLimit(float v) = 0;
|
||||
virtual float getSlopeLimit() = 0;
|
||||
virtual void setContactOffset(float v) = 0;
|
||||
virtual float getContactOffset() = 0;
|
||||
virtual void setDetectCollisions(bool v) = 0;
|
||||
virtual void setOverlapRecovery(bool v) = 0;
|
||||
virtual void setCenter(float x, float y, float z) = 0;
|
||||
|
||||
virtual cc::Vec3 getPosition() = 0;
|
||||
virtual void setPosition(float x, float y, float z) = 0;
|
||||
virtual bool onGround() = 0;
|
||||
virtual void move(float x, float y, float z, float minDist, float elapsedTime) = 0;
|
||||
virtual void syncPhysicsToScene() = 0;
|
||||
|
||||
virtual uint32_t getGroup() = 0;
|
||||
virtual void setGroup(uint32_t g) = 0;
|
||||
virtual uint32_t getMask() = 0;
|
||||
virtual void setMask(uint32_t m) = 0;
|
||||
virtual void updateEventListener(EShapeFilterFlag flag) = 0;
|
||||
|
||||
virtual uint32_t getObjectID() const = 0;
|
||||
};
|
||||
|
||||
class ICapsuleCharacterController : virtual public IBaseCharacterController {
|
||||
public:
|
||||
~ICapsuleCharacterController() override = default;
|
||||
virtual void setRadius(float v) = 0;
|
||||
virtual void setHeight(float v) = 0;
|
||||
};
|
||||
|
||||
class IBoxCharacterController : virtual public IBaseCharacterController {
|
||||
public:
|
||||
~IBoxCharacterController() override = default;
|
||||
virtual void setHalfHeight(float v) = 0;
|
||||
virtual void setHalfSideExtent(float v) = 0;
|
||||
virtual void setHalfForwardExtent(float v) = 0;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
113
cocos/physics/spec/IJoint.h
Normal file
113
cocos/physics/spec/IJoint.h
Normal file
@@ -0,0 +1,113 @@
|
||||
/****************************************************************************
|
||||
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 "core/scene-graph/Node.h"
|
||||
#include "physics/spec/ILifecycle.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
class IBaseJoint : virtual public ILifecycle {
|
||||
public:
|
||||
~IBaseJoint() override = default;
|
||||
virtual void initialize(Node *node) = 0;
|
||||
virtual void setEnableCollision(bool v) = 0;
|
||||
virtual void setConnectedBody(uint32_t rigidBodyID) = 0;
|
||||
virtual uint32_t getObjectID() const = 0;
|
||||
};
|
||||
|
||||
class ISphericalJoint : virtual public IBaseJoint {
|
||||
public:
|
||||
~ISphericalJoint() override = default;
|
||||
virtual void setPivotA(float x, float y, float z) = 0;
|
||||
virtual void setPivotB(float x, float y, float z) = 0;
|
||||
};
|
||||
|
||||
class IRevoluteJoint : virtual public IBaseJoint {
|
||||
public:
|
||||
~IRevoluteJoint() override = default;
|
||||
virtual void setPivotA(float x, float y, float z) = 0;
|
||||
virtual void setPivotB(float x, float y, float z) = 0;
|
||||
virtual void setAxis(float x, float y, float z) = 0;
|
||||
virtual void setLimitEnabled(bool v) = 0;
|
||||
virtual void setLowerLimit(float v) = 0;
|
||||
virtual void setUpperLimit(float v) = 0;
|
||||
virtual void setMotorEnabled(bool v) = 0;
|
||||
virtual void setMotorVelocity(float v) = 0;
|
||||
virtual void setMotorForceLimit(float v) = 0;
|
||||
};
|
||||
|
||||
class IFixedJoint : virtual public IBaseJoint {
|
||||
public:
|
||||
~IFixedJoint() override = default;
|
||||
virtual void setBreakForce(float force) = 0;
|
||||
virtual void setBreakTorque(float torque) = 0;
|
||||
};
|
||||
|
||||
class IGenericJoint : virtual public IBaseJoint {
|
||||
public:
|
||||
~IGenericJoint() override = default;
|
||||
|
||||
virtual void setConstraintMode(uint32_t index, uint32_t mode) = 0;
|
||||
virtual void setLinearLimit(uint32_t index, float lower, float upper) = 0;
|
||||
virtual void setAngularExtent(float twist, float swing1, float swing2) = 0;
|
||||
virtual void setLinearSoftConstraint(bool enable) = 0;
|
||||
virtual void setLinearStiffness(float stiffness) = 0;
|
||||
virtual void setLinearDamping(float damping) = 0;
|
||||
virtual void setLinearRestitution(float restitution) = 0;
|
||||
|
||||
virtual void setSwingSoftConstraint(bool enable) = 0;
|
||||
virtual void setTwistSoftConstraint(bool enable) = 0;
|
||||
virtual void setSwingStiffness(float stiffness) = 0;
|
||||
virtual void setSwingDamping(float damping) = 0;
|
||||
virtual void setSwingRestitution(float restitution) = 0;
|
||||
virtual void setTwistStiffness(float stiffness) = 0;
|
||||
virtual void setTwistDamping(float damping) = 0;
|
||||
virtual void setTwistRestitution(float restitution) = 0;
|
||||
|
||||
// motor
|
||||
virtual void setDriverMode(uint32_t index, uint32_t mode) = 0;
|
||||
virtual void setLinearMotorTarget(float x, float y, float z) = 0;
|
||||
virtual void setLinearMotorVelocity(float x, float y, float z) = 0;
|
||||
virtual void setLinearMotorForceLimit(float limit) = 0;
|
||||
|
||||
virtual void setAngularMotorTarget(float x, float y, float z) = 0;
|
||||
virtual void setAngularMotorVelocity(float x, float y, float z) = 0;
|
||||
virtual void setAngularMotorForceLimit(float limit) = 0;
|
||||
|
||||
virtual void setPivotA(float x, float y, float z) = 0;
|
||||
virtual void setPivotB(float x, float y, float z) = 0;
|
||||
virtual void setAutoPivotB(bool enable) = 0;
|
||||
virtual void setAxis(float x, float y, float z) = 0;
|
||||
virtual void setSecondaryAxis(float x, float y, float z) = 0;
|
||||
|
||||
virtual void setBreakForce(float force) = 0;
|
||||
virtual void setBreakTorque(float torque) = 0;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
40
cocos/physics/spec/ILifecycle.h
Normal file
40
cocos/physics/spec/ILifecycle.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/****************************************************************************
|
||||
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 "base/TypeDef.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
class ILifecycle {
|
||||
public:
|
||||
virtual ~ILifecycle() = default;
|
||||
virtual void onEnable() = 0;
|
||||
virtual void onDisable() = 0;
|
||||
virtual void onDestroy() = 0;
|
||||
};
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
130
cocos/physics/spec/IShape.h
Normal file
130
cocos/physics/spec/IShape.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/****************************************************************************
|
||||
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 "core/geometry/AABB.h"
|
||||
#include "core/geometry/Sphere.h"
|
||||
#include "core/scene-graph/Node.h"
|
||||
#include "physics/spec/ILifecycle.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
enum class EAxisDirection : uint8_t {
|
||||
X_AXIS,
|
||||
Y_AXIS,
|
||||
Z_AXIS,
|
||||
};
|
||||
|
||||
enum class EShapeFilterFlag : uint8_t {
|
||||
NONE = 0,
|
||||
IS_TRIGGER = 1 << 0,
|
||||
NEED_EVENT = 1 << 1,
|
||||
NEED_CONTACT_DATA = 1 << 2,
|
||||
DETECT_CONTACT_CCD = 1 << 3,
|
||||
};
|
||||
|
||||
class IBaseShape : virtual public ILifecycle {
|
||||
public:
|
||||
~IBaseShape() override = default;
|
||||
;
|
||||
virtual void initialize(Node *node) = 0;
|
||||
virtual void setMaterial(uint16_t id, float f, float df, float r,
|
||||
uint8_t m0, uint8_t m1) = 0;
|
||||
virtual void setAsTrigger(bool v) = 0;
|
||||
virtual void setCenter(float x, float y, float z) = 0;
|
||||
virtual geometry::AABB &getAABB() = 0;
|
||||
virtual geometry::Sphere &getBoundingSphere() = 0;
|
||||
virtual void updateEventListener(EShapeFilterFlag flag) = 0;
|
||||
virtual uint32_t getGroup() = 0;
|
||||
virtual void setGroup(uint32_t g) = 0;
|
||||
virtual uint32_t getMask() = 0;
|
||||
virtual void setMask(uint32_t m) = 0;
|
||||
virtual uint32_t getObjectID() const = 0;
|
||||
};
|
||||
|
||||
class ISphereShape : virtual public IBaseShape {
|
||||
public:
|
||||
~ISphereShape() override = default;
|
||||
;
|
||||
virtual void setRadius(float v) = 0;
|
||||
};
|
||||
|
||||
class IBoxShape : virtual public IBaseShape {
|
||||
public:
|
||||
~IBoxShape() override = default;
|
||||
;
|
||||
virtual void setSize(float x, float y, float z) = 0;
|
||||
};
|
||||
|
||||
class ICapsuleShape : virtual public IBaseShape {
|
||||
public:
|
||||
~ICapsuleShape() override = default;
|
||||
;
|
||||
virtual void setRadius(float v) = 0;
|
||||
virtual void setCylinderHeight(float v) = 0;
|
||||
virtual void setDirection(EAxisDirection v) = 0;
|
||||
};
|
||||
|
||||
class ICylinderShape : virtual public IBaseShape {
|
||||
public:
|
||||
~ICylinderShape() override = default;
|
||||
;
|
||||
virtual void setConvex(uint32_t ObjectID) = 0;
|
||||
virtual void setCylinder(float r, float h, EAxisDirection d) = 0;
|
||||
};
|
||||
|
||||
class IConeShape : virtual public IBaseShape {
|
||||
public:
|
||||
~IConeShape() override = default;
|
||||
;
|
||||
virtual void setConvex(uint32_t ObjectID) = 0;
|
||||
virtual void setCone(float r, float h, EAxisDirection d) = 0;
|
||||
};
|
||||
|
||||
class IPlaneShape : virtual public IBaseShape {
|
||||
public:
|
||||
~IPlaneShape() override = default;
|
||||
;
|
||||
virtual void setConstant(float v) = 0;
|
||||
virtual void setNormal(float x, float y, float z) = 0;
|
||||
};
|
||||
|
||||
class ITrimeshShape : virtual public IBaseShape {
|
||||
public:
|
||||
~ITrimeshShape() override = default;
|
||||
;
|
||||
virtual void setMesh(uint32_t ObjectID) = 0;
|
||||
virtual void useConvex(bool v) = 0;
|
||||
};
|
||||
|
||||
class ITerrainShape : virtual public IBaseShape {
|
||||
public:
|
||||
virtual void setTerrain(uint32_t ObjectID, float rs, float cs, float hs) = 0;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
190
cocos/physics/spec/IWorld.h
Normal file
190
cocos/physics/spec/IWorld.h
Normal file
@@ -0,0 +1,190 @@
|
||||
/****************************************************************************
|
||||
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/TypeDef.h"
|
||||
#include "base/std/container/vector.h"
|
||||
#include "math/Vec3.h"
|
||||
|
||||
namespace cc {
|
||||
namespace physics {
|
||||
|
||||
enum class ETouchState : uint8_t {
|
||||
ENTER = 0,
|
||||
STAY = 1,
|
||||
EXIT = 2,
|
||||
};
|
||||
|
||||
enum class EPhysicsDrawFlags : uint32_t {
|
||||
NONE = 0,
|
||||
WIRE_FRAME = 0x0001,
|
||||
CONSTRAINT = 0x0002,
|
||||
AABB = 0x0004
|
||||
};
|
||||
|
||||
struct TriggerEventPair {
|
||||
uint32_t shapeA; //wrapper object ID
|
||||
uint32_t shapeB; //wrapper object ID
|
||||
ETouchState state;
|
||||
static constexpr uint8_t COUNT = 3;
|
||||
TriggerEventPair(const uint32_t a, const uint32_t b)
|
||||
: shapeA(a),
|
||||
shapeB(b),
|
||||
state(ETouchState::ENTER) {}
|
||||
};
|
||||
|
||||
struct ContactPoint {
|
||||
Vec3 position;
|
||||
float separation;
|
||||
Vec3 normal;
|
||||
uint32_t internalFaceIndex0;
|
||||
Vec3 impulse;
|
||||
uint32_t internalFaceIndex1;
|
||||
static constexpr uint8_t COUNT = 12;
|
||||
};
|
||||
|
||||
struct ContactEventPair {
|
||||
uint32_t shapeA; //wrapper object ID
|
||||
uint32_t shapeB; //wrapper object ID
|
||||
ETouchState state;
|
||||
ccstd::vector<ContactPoint> contacts;
|
||||
static constexpr uint8_t COUNT = 4;
|
||||
ContactEventPair(const uint32_t a, const uint32_t b)
|
||||
: shapeA(a),
|
||||
shapeB(b),
|
||||
state(ETouchState::ENTER) {}
|
||||
};
|
||||
|
||||
struct CharacterControllerContact {
|
||||
Vec3 worldPosition;
|
||||
Vec3 worldNormal;
|
||||
Vec3 motionDirection;
|
||||
float motionLength;
|
||||
static constexpr uint8_t COUNT = 10;
|
||||
};
|
||||
struct CCTShapeEventPair {
|
||||
uint32_t cct; //wrapper object ID
|
||||
uint32_t shape; //wrapper object ID
|
||||
//ETouchState state;
|
||||
ccstd::vector<CharacterControllerContact> contacts;
|
||||
static constexpr uint8_t COUNT = 3;
|
||||
CCTShapeEventPair(const uint32_t cct, const uint32_t shape)
|
||||
: cct(cct), shape(shape) {
|
||||
}
|
||||
};
|
||||
|
||||
struct CCTTriggerEventPair {
|
||||
uint32_t cct; //wrapper object ID
|
||||
uint32_t shape; //wrapper object ID
|
||||
ETouchState state;
|
||||
static constexpr uint8_t COUNT = 3;
|
||||
CCTTriggerEventPair(const uint32_t cct, const uint32_t shape)
|
||||
: cct(cct),
|
||||
shape(shape),
|
||||
state(ETouchState::ENTER) {}
|
||||
};
|
||||
|
||||
struct ConvexDesc {
|
||||
void *positions;
|
||||
uint32_t positionLength;
|
||||
};
|
||||
|
||||
struct TrimeshDesc : ConvexDesc {
|
||||
void *triangles;
|
||||
uint32_t triangleLength;
|
||||
bool isU16;
|
||||
};
|
||||
|
||||
struct HeightFieldDesc {
|
||||
uint32_t rows;
|
||||
uint32_t columns;
|
||||
void *samples;
|
||||
};
|
||||
|
||||
struct RaycastOptions {
|
||||
Vec3 origin;
|
||||
float distance;
|
||||
Vec3 unitDir;
|
||||
uint32_t mask;
|
||||
bool queryTrigger;
|
||||
};
|
||||
|
||||
struct RaycastResult {
|
||||
uint32_t shape{0};
|
||||
Vec3 hitPoint;
|
||||
float distance;
|
||||
Vec3 hitNormal;
|
||||
RaycastResult() = default;
|
||||
};
|
||||
|
||||
class IPhysicsWorld {
|
||||
public:
|
||||
virtual ~IPhysicsWorld() = default;
|
||||
;
|
||||
virtual void setGravity(float x, float y, float z) = 0;
|
||||
virtual void setAllowSleep(bool v) = 0;
|
||||
virtual void step(float s) = 0;
|
||||
virtual void emitEvents() = 0;
|
||||
virtual void syncSceneToPhysics() = 0;
|
||||
virtual void syncSceneWithCheck() = 0;
|
||||
virtual void destroy() = 0;
|
||||
virtual void setDebugDrawFlags(EPhysicsDrawFlags f) = 0;
|
||||
virtual EPhysicsDrawFlags getDebugDrawFlags() = 0;
|
||||
virtual void setDebugDrawConstraintSize(float s) = 0;
|
||||
virtual float getDebugDrawConstraintSize() = 0;
|
||||
virtual void setCollisionMatrix(uint32_t i, uint32_t m) = 0;
|
||||
virtual ccstd::vector<std::shared_ptr<TriggerEventPair>> &getTriggerEventPairs() = 0;
|
||||
virtual ccstd::vector<std::shared_ptr<ContactEventPair>>& getContactEventPairs() = 0;
|
||||
virtual ccstd::vector<std::shared_ptr<CCTShapeEventPair>>& getCCTShapeEventPairs() = 0;
|
||||
virtual ccstd::vector<std::shared_ptr<CCTTriggerEventPair>> &getCCTTriggerEventPairs() = 0;
|
||||
virtual bool raycast(RaycastOptions &opt) = 0;
|
||||
virtual bool raycastClosest(RaycastOptions &opt) = 0;
|
||||
virtual ccstd::vector<RaycastResult> &raycastResult() = 0;
|
||||
virtual RaycastResult &raycastClosestResult() = 0;
|
||||
virtual bool sweepBox(RaycastOptions &opt, float halfExtentX, float halfExtentY, float halfExtentZ,
|
||||
float orientationW, float orientationX, float orientationY, float orientationZ) = 0;
|
||||
virtual bool sweepBoxClosest(RaycastOptions &opt, float halfExtentX, float halfExtentY, float halfExtentZ,
|
||||
float orientationW, float orientationX, float orientationY, float orientationZ) = 0;
|
||||
virtual bool sweepSphere(RaycastOptions &opt, float radius) = 0;
|
||||
virtual bool sweepSphereClosest(RaycastOptions &opt, float radius) = 0;
|
||||
virtual bool sweepCapsule(RaycastOptions &opt, float radius, float height,
|
||||
float orientationW, float orientationX, float orientationY, float orientationZ) = 0;
|
||||
virtual bool sweepCapsuleClosest(RaycastOptions &opt, float radius, float height,
|
||||
float orientationW, float orientationX, float orientationY, float orientationZ) = 0;
|
||||
virtual RaycastResult &sweepClosestResult() = 0;
|
||||
virtual ccstd::vector<RaycastResult> &sweepResult() = 0;
|
||||
virtual uint32_t createConvex(ConvexDesc &desc) = 0;
|
||||
virtual uint32_t createTrimesh(TrimeshDesc &desc) = 0;
|
||||
virtual uint32_t createHeightField(HeightFieldDesc &desc) = 0;
|
||||
virtual bool createMaterial(uint16_t id, float f, float df, float r,
|
||||
uint8_t m0, uint8_t m1) = 0;
|
||||
virtual void setFixedTimeStep(float v) = 0;
|
||||
virtual float getFixedTimeStep() const = 0;
|
||||
};
|
||||
|
||||
} // namespace physics
|
||||
} // namespace cc
|
||||
Reference in New Issue
Block a user