2013-09-16 21:22:22 +08:00
|
|
|
|
/****************************************************************************
|
2018-01-29 16:25:32 +08:00
|
|
|
|
Copyright (c) 2013-2016 Chukong Technologies Inc.
|
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-10-24 14:09:59 +08:00
|
|
|
|
Copyright (c) 2021 Bytedance Inc.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2021-10-24 14:09:59 +08:00
|
|
|
|
https://adxe.org
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
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:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
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.
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#ifndef __CCPHYSICS_SHAPE_H__
|
|
|
|
|
#define __CCPHYSICS_SHAPE_H__
|
|
|
|
|
|
2014-04-30 08:37:36 +08:00
|
|
|
|
#include "base/ccConfig.h"
|
2013-12-26 23:55:05 +08:00
|
|
|
|
#if CC_USE_PHYSICS
|
2013-11-06 14:51:56 +08:00
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
# include "base/CCRef.h"
|
|
|
|
|
# include "math/CCMath.h"
|
2013-09-16 21:22:22 +08:00
|
|
|
|
|
2015-01-06 10:29:07 +08:00
|
|
|
|
struct cpShape;
|
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
|
|
class PhysicsBody;
|
2013-10-09 17:53:12 +08:00
|
|
|
|
|
2014-07-15 10:55:40 +08:00
|
|
|
|
typedef struct CC_DLL PhysicsMaterial
|
2013-10-09 17:53:12 +08:00
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
|
float density; ///< The density of the object.
|
|
|
|
|
float restitution; ///< The bounciness of the physics body.
|
|
|
|
|
float friction; ///< The roughness of the surface of a shape.
|
|
|
|
|
|
|
|
|
|
PhysicsMaterial() : density(0.0f), restitution(0.0f), friction(0.0f) {}
|
|
|
|
|
|
2013-11-05 08:31:36 +08:00
|
|
|
|
PhysicsMaterial(float aDensity, float aRestitution, float aFriction)
|
2021-12-25 10:04:45 +08:00
|
|
|
|
: density(aDensity), restitution(aRestitution), friction(aFriction)
|
2013-10-23 18:52:09 +08:00
|
|
|
|
{}
|
2021-12-25 10:04:45 +08:00
|
|
|
|
} PhysicsMaterial;
|
2013-10-09 17:53:12 +08:00
|
|
|
|
|
2015-01-07 17:08:04 +08:00
|
|
|
|
const PhysicsMaterial PHYSICSSHAPE_MATERIAL_DEFAULT;
|
2013-10-09 17:53:12 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
2015-05-28 15:47:03 +08:00
|
|
|
|
* @addtogroup physics
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @{
|
2015-06-15 10:28:37 +08:00
|
|
|
|
* @addtogroup physics_2d
|
|
|
|
|
* @{
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2013-10-09 17:53:12 +08:00
|
|
|
|
/**
|
2021-12-25 10:04:45 +08:00
|
|
|
|
* @brief A shape for body. You do not create PhysicsWorld objects directly, instead, you can view PhysicsBody to see
|
|
|
|
|
* how to create it.
|
2013-09-17 16:27:43 +08:00
|
|
|
|
*/
|
2014-07-15 10:55:40 +08:00
|
|
|
|
class CC_DLL PhysicsShape : public Ref
|
2013-09-16 21:22:22 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
enum class Type
|
|
|
|
|
{
|
|
|
|
|
UNKNOWN,
|
|
|
|
|
CIRCLE,
|
|
|
|
|
BOX,
|
2016-07-18 18:10:07 +08:00
|
|
|
|
POLYGON,
|
2013-09-16 21:22:22 +08:00
|
|
|
|
EDGESEGMENT,
|
|
|
|
|
EDGEBOX,
|
2016-07-18 18:10:07 +08:00
|
|
|
|
EDGEPOLYGON,
|
2013-09-16 21:22:22 +08:00
|
|
|
|
EDGECHAIN,
|
2016-07-18 18:10:07 +08:00
|
|
|
|
|
|
|
|
|
/** @deprecated Use Type::POLYGON instead. */
|
|
|
|
|
POLYGEN = POLYGON,
|
|
|
|
|
|
|
|
|
|
/** @deprecated Use Type::EDGEPOLYGON instead. */
|
|
|
|
|
EDGEPOLYGEN = EDGEPOLYGON,
|
2013-09-16 21:22:22 +08:00
|
|
|
|
};
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
public:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
/**
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* Get the body that this shape attaches.
|
|
|
|
|
*
|
|
|
|
|
* @return A PhysicsBody object pointer.
|
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
PhysicsBody* getBody() const { return _body; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* Return this shape's type.
|
|
|
|
|
*
|
|
|
|
|
* @return A Type object.
|
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
Type getType() const { return _type; }
|
2015-03-19 17:58:08 +08:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Return this shape's area.
|
|
|
|
|
*
|
|
|
|
|
* @return A float number.
|
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
float getArea() const { return _area; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this shape's moment.
|
|
|
|
|
*
|
|
|
|
|
* @return A float number.
|
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
float getMoment() const { return _moment; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Set this shape's moment.
|
|
|
|
|
*
|
|
|
|
|
* It will change the body's moment this shape attaches.
|
|
|
|
|
*
|
|
|
|
|
* @param moment A float number.
|
|
|
|
|
*/
|
2013-10-18 15:34:13 +08:00
|
|
|
|
void setMoment(float moment);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Set this shape's tag.
|
|
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param tag An integer number that identifies a shape object.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
void setTag(int tag) { _tag = tag; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this shape's tag.
|
|
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @return An integer number.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
int getTag() const { return _tag; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get the mass of this shape.
|
|
|
|
|
*
|
|
|
|
|
* @return A float number.
|
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
float getMass() const { return _mass; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Set this shape's mass.
|
|
|
|
|
*
|
|
|
|
|
* It will change the body's mass this shape attaches.
|
|
|
|
|
*
|
|
|
|
|
* @param mass A float number.
|
|
|
|
|
*/
|
2013-10-09 17:53:12 +08:00
|
|
|
|
void setMass(float mass);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this shape's density.
|
|
|
|
|
*
|
|
|
|
|
* @return A float number.
|
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
float getDensity() const { return _material.density; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Set this shape's density.
|
|
|
|
|
*
|
|
|
|
|
* It will change the body's mass this shape attaches.
|
|
|
|
|
*
|
|
|
|
|
* @param density A float number.
|
|
|
|
|
*/
|
2013-10-09 17:53:12 +08:00
|
|
|
|
void setDensity(float density);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this shape's restitution.
|
|
|
|
|
*
|
|
|
|
|
* @return A float number.
|
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
float getRestitution() const { return _material.restitution; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Set this shape's restitution.
|
|
|
|
|
*
|
|
|
|
|
* It will change the shape's elasticity.
|
|
|
|
|
*
|
|
|
|
|
* @param restitution A float number.
|
|
|
|
|
*/
|
2013-10-18 15:34:13 +08:00
|
|
|
|
void setRestitution(float restitution);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this shape's friction.
|
|
|
|
|
*
|
|
|
|
|
* @return A float number.
|
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
float getFriction() const { return _material.friction; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Set this shape's friction.
|
|
|
|
|
*
|
|
|
|
|
* It will change the shape's friction.
|
|
|
|
|
*
|
|
|
|
|
* @param friction A float number.
|
|
|
|
|
*/
|
2013-10-09 13:41:19 +08:00
|
|
|
|
void setFriction(float friction);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this shape's PhysicsMaterial object.
|
|
|
|
|
*
|
|
|
|
|
* @return A PhysicsMaterial object reference.
|
|
|
|
|
*/
|
2013-12-13 17:36:58 +08:00
|
|
|
|
const PhysicsMaterial& getMaterial() const { return _material; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Set this shape's material.
|
|
|
|
|
*
|
|
|
|
|
* It will change the shape's mass, elasticity and friction.
|
|
|
|
|
*
|
|
|
|
|
* @param material A PhysicsMaterial object.
|
|
|
|
|
*/
|
2013-11-05 20:02:58 +08:00
|
|
|
|
void setMaterial(const PhysicsMaterial& material);
|
2016-09-12 09:44:21 +08:00
|
|
|
|
bool isSensor() const { return _sensor; }
|
2015-03-01 17:03:01 +08:00
|
|
|
|
void setSensor(bool sensor);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* Calculate the default moment value.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* This function should be overridden in inherit classes.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @return A float number, equals 0.0.
|
|
|
|
|
*/
|
2013-12-13 17:36:58 +08:00
|
|
|
|
virtual float calculateDefaultMoment() { return 0.0f; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this shape's position offset.
|
|
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* This function should be overridden in inherit classes.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @return A Vec2 object.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
virtual Vec2 getOffset() { return Vec2::ZERO; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this shape's center position.
|
|
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* This function should be overridden in inherit classes.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @return A Vec2 object.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
virtual Vec2 getCenter() { return getOffset(); }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* Test point is inside this shape or not.
|
|
|
|
|
*
|
|
|
|
|
* @param point A Vec2 object.
|
|
|
|
|
* @return A bool object.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
bool containsPoint(const Vec2& point) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* Move the points to the center.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
*
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @param points A Vec2 object pointer.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param count An integer number.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @param center A Vec2 object, default value is Vec2(0,0).
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
static void recenterPoints(Vec2* points, int count, const Vec2& center = Vec2::ZERO);
|
2015-03-19 17:58:08 +08:00
|
|
|
|
|
|
|
|
|
/**
|
2016-07-19 07:24:22 +08:00
|
|
|
|
* Get center of the polygon points.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*
|
|
|
|
|
* @param points A Vec2 object pointer.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param count An integer number.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @return A Vec2 object.
|
|
|
|
|
*/
|
2016-07-19 07:24:22 +08:00
|
|
|
|
static Vec2 getPolygonCenter(const Vec2* points, int count);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-12-13 17:36:58 +08:00
|
|
|
|
/**
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* Set a mask that defines which categories this physics body belongs to.
|
|
|
|
|
*
|
2021-12-25 10:04:45 +08:00
|
|
|
|
* Every physics body in a scene can be assigned to up to 32 different categories, each corresponding to a bit in
|
|
|
|
|
* the bit mask. You define the mask values used in your game. In conjunction with the collisionBitMask and
|
|
|
|
|
* contactTestBitMask properties, you define which physics bodies interact with each other and when your game is
|
|
|
|
|
* notified of these interactions.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param bitmask An integer number, the default value is 0xFFFFFFFF (all bits set).
|
2013-12-13 17:36:58 +08:00
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
void setCategoryBitmask(int bitmask) { _categoryBitmask = bitmask; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get a mask that defines which categories this physics body belongs to.
|
|
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @return An integer number.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
int getCategoryBitmask() const { return _categoryBitmask; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-12-13 17:36:58 +08:00
|
|
|
|
/**
|
|
|
|
|
* A mask that defines which categories of bodies cause intersection notifications with this physics body.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*
|
2021-12-25 10:04:45 +08:00
|
|
|
|
* When two bodies share the same space, each body's category mask is tested against the other body's contact mask
|
|
|
|
|
* by performing a logical AND operation. If either comparison results in a non-zero value, an PhysicsContact object
|
|
|
|
|
* is created and passed to the physics world’s delegate. For best performance, only set bits in the contacts mask
|
|
|
|
|
* for interactions you are interested in.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param bitmask An integer number, the default value is 0x00000000 (all bits cleared).
|
2013-12-13 17:36:58 +08:00
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
void setContactTestBitmask(int bitmask) { _contactTestBitmask = bitmask; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get a mask that defines which categories of bodies cause intersection notifications with this physics body.
|
|
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @return An integer number.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
int getContactTestBitmask() const { return _contactTestBitmask; }
|
2015-03-19 17:58:08 +08:00
|
|
|
|
|
2013-12-13 17:36:58 +08:00
|
|
|
|
/**
|
|
|
|
|
* A mask that defines which categories of physics bodies can collide with this physics body.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*
|
2021-12-25 10:04:45 +08:00
|
|
|
|
* When two physics bodies contact each other, a collision may occur. This body's collision mask is compared to the
|
|
|
|
|
* other body's category mask by performing a logical AND operation. If the result is a non-zero value, then this
|
|
|
|
|
* body is affected by the collision. Each body independently chooses whether it wants to be affected by the other
|
|
|
|
|
* body. For example, you might use this to avoid collision calculations that would make negligible changes to a
|
|
|
|
|
* body's velocity.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param bitmask An integer number, the default value is 0xFFFFFFFF (all bits set).
|
2013-12-13 17:36:58 +08:00
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
void setCollisionBitmask(int bitmask) { _collisionBitmask = bitmask; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get a mask that defines which categories of physics bodies can collide with this physics body.
|
|
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @return An integer number.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
int getCollisionBitmask() const { return _collisionBitmask; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2014-08-08 16:38:20 +08:00
|
|
|
|
/**
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* Set the group of body.
|
|
|
|
|
*
|
2021-12-25 10:04:45 +08:00
|
|
|
|
* Collision groups let you specify an integral group index. You can have all fixtures with the same group index
|
|
|
|
|
* always collide (positive index) or never collide (negative index).
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param group An integer number, it have high priority than bit masks.
|
2014-08-08 16:38:20 +08:00
|
|
|
|
*/
|
2013-10-29 17:31:35 +08:00
|
|
|
|
void setGroup(int group);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get the group of body.
|
|
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @return An integer number.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*/
|
2016-09-12 09:44:21 +08:00
|
|
|
|
int getGroup() { return _group; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
protected:
|
2013-10-18 15:34:13 +08:00
|
|
|
|
void setBody(PhysicsBody* body);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-12-13 17:36:58 +08:00
|
|
|
|
/** calculate the area of this shape */
|
|
|
|
|
virtual float calculateArea() { return 0.0f; }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2014-06-27 17:30:21 +08:00
|
|
|
|
virtual void setScale(float scaleX, float scaleY);
|
2015-01-07 17:08:04 +08:00
|
|
|
|
virtual void updateScale();
|
2015-01-06 10:29:07 +08:00
|
|
|
|
void addShape(cpShape* shape);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
protected:
|
|
|
|
|
PhysicsShape();
|
2013-09-17 16:27:43 +08:00
|
|
|
|
virtual ~PhysicsShape() = 0;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
protected:
|
|
|
|
|
PhysicsBody* _body;
|
2015-01-06 10:29:07 +08:00
|
|
|
|
std::vector<cpShape*> _cpShapes;
|
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
Type _type;
|
2013-09-30 20:43:19 +08:00
|
|
|
|
float _area;
|
|
|
|
|
float _mass;
|
2013-10-18 15:34:13 +08:00
|
|
|
|
float _moment;
|
2015-03-01 17:03:01 +08:00
|
|
|
|
bool _sensor;
|
2014-06-27 17:30:21 +08:00
|
|
|
|
float _scaleX;
|
|
|
|
|
float _scaleY;
|
|
|
|
|
float _newScaleX;
|
|
|
|
|
float _newScaleY;
|
2013-10-09 17:53:12 +08:00
|
|
|
|
PhysicsMaterial _material;
|
2013-09-29 09:39:20 +08:00
|
|
|
|
int _tag;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
int _categoryBitmask;
|
|
|
|
|
int _collisionBitmask;
|
|
|
|
|
int _contactTestBitmask;
|
|
|
|
|
int _group;
|
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
friend class PhysicsWorld;
|
|
|
|
|
friend class PhysicsBody;
|
2013-10-18 15:34:13 +08:00
|
|
|
|
friend class PhysicsJoint;
|
2013-11-08 14:25:03 +08:00
|
|
|
|
friend class PhysicsDebugDraw;
|
2013-09-16 21:22:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/** A circle shape. */
|
2014-07-15 10:55:40 +08:00
|
|
|
|
class CC_DLL PhysicsShapeCircle : public PhysicsShape
|
2013-09-16 21:22:22 +08:00
|
|
|
|
{
|
2013-09-30 20:43:19 +08:00
|
|
|
|
public:
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Creates a PhysicsShapeCircle with specified value.
|
|
|
|
|
*
|
|
|
|
|
* @param radius A float number, it is the circle's radius.
|
|
|
|
|
* @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @return An autoreleased PhysicsShapeCircle object pointer.
|
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
static PhysicsShapeCircle* create(float radius,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
const Vec2& offset = Vec2(0.0f, 0.0f));
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Calculate the area of a circle with specified radius.
|
|
|
|
|
*
|
|
|
|
|
* @param radius A float number
|
|
|
|
|
* @return A float number
|
|
|
|
|
*/
|
2013-10-18 15:34:13 +08:00
|
|
|
|
static float calculateArea(float radius);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Calculate the moment of a circle with specified value.
|
|
|
|
|
*
|
|
|
|
|
* @param mass A float number
|
|
|
|
|
* @param radius A float number
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @return A float number
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
static float calculateMoment(float mass, float radius, const Vec2& offset = Vec2::ZERO);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Calculate the moment for a circle.
|
|
|
|
|
*
|
|
|
|
|
* @return A float number.
|
|
|
|
|
*/
|
2013-11-06 15:43:29 +08:00
|
|
|
|
virtual float calculateDefaultMoment() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get the circle's radius.
|
|
|
|
|
*
|
|
|
|
|
* @return A float number.
|
|
|
|
|
*/
|
2013-11-01 16:26:03 +08:00
|
|
|
|
float getRadius() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this circle's position offset.
|
|
|
|
|
*
|
|
|
|
|
* @return A Vec2 object.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
virtual Vec2 getOffset() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
bool init(float radius,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
const Vec2& offset = Vec2::ZERO);
|
2013-12-13 17:36:58 +08:00
|
|
|
|
virtual float calculateArea() override;
|
2015-01-07 17:08:04 +08:00
|
|
|
|
virtual void updateScale() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
protected:
|
|
|
|
|
PhysicsShapeCircle();
|
2013-11-06 15:43:29 +08:00
|
|
|
|
virtual ~PhysicsShapeCircle();
|
2013-09-16 21:22:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/** A polygon shape. */
|
2014-07-15 10:55:40 +08:00
|
|
|
|
class CC_DLL PhysicsShapePolygon : public PhysicsShape
|
2013-09-16 21:22:22 +08:00
|
|
|
|
{
|
2013-09-30 20:43:19 +08:00
|
|
|
|
public:
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Creates a PhysicsShapePolygon with specified value.
|
|
|
|
|
*
|
|
|
|
|
* @param points A Vec2 object pointer, it is an array of Vec2.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param count An integer number, contains the count of the points array.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @return An autoreleased PhysicsShapePolygon object pointer.
|
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
static PhysicsShapePolygon* create(const Vec2* points,
|
|
|
|
|
int count,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
const Vec2& offset = Vec2::ZERO,
|
|
|
|
|
float radius = 0.0f);
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Calculate the area of a polygon with specified value.
|
|
|
|
|
*
|
|
|
|
|
* @param points A Vec2 object pointer, it is an array of Vec2.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param count An integer number, contains the count of the points array.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @return A float number.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
static float calculateArea(const Vec2* points, int count);
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Calculate the moment of a polygon with specified value.
|
|
|
|
|
*
|
|
|
|
|
* @param mass A float number
|
|
|
|
|
* @param points A Vec2 object pointer, it is an array of Vec2.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param count An integer number, contains the count of the points array.
|
|
|
|
|
* @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @return A float number
|
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
static float calculateMoment(float mass,
|
|
|
|
|
const Vec2* points,
|
|
|
|
|
int count,
|
|
|
|
|
const Vec2& offset = Vec2::ZERO,
|
|
|
|
|
float radius = 0.0f);
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Calculate the moment for a polygon.
|
|
|
|
|
*
|
|
|
|
|
* @return A float number.
|
|
|
|
|
*/
|
2013-10-18 15:34:13 +08:00
|
|
|
|
float calculateDefaultMoment() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get a point of this polygon's points array.
|
|
|
|
|
*
|
|
|
|
|
* @param i A index of this polygon's points array.
|
|
|
|
|
* @return A point value.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
Vec2 getPoint(int i) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this polygon's points array.
|
|
|
|
|
*
|
|
|
|
|
* @param outPoints A Vec2 array pointer.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
void getPoints(Vec2* outPoints) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this polygon's points array count.
|
|
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @return An integer number.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*/
|
2013-12-05 17:19:01 +08:00
|
|
|
|
int getPointsCount() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this polygon's center position.
|
|
|
|
|
*
|
|
|
|
|
* @return A Vec2 object.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
virtual Vec2 getCenter() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
bool init(const Vec2* points,
|
|
|
|
|
int count,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
const Vec2& offset = Vec2::ZERO,
|
|
|
|
|
float radius = 0.0f);
|
2013-12-13 17:36:58 +08:00
|
|
|
|
float calculateArea() override;
|
2015-01-07 17:08:04 +08:00
|
|
|
|
virtual void updateScale() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
protected:
|
|
|
|
|
PhysicsShapePolygon();
|
|
|
|
|
virtual ~PhysicsShapePolygon();
|
2014-06-27 17:30:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/** A box shape. */
|
2014-07-15 10:55:40 +08:00
|
|
|
|
class CC_DLL PhysicsShapeBox : public PhysicsShapePolygon
|
2014-06-27 17:30:21 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Creates a PhysicsShapeBox with specified value.
|
|
|
|
|
*
|
2021-10-24 14:09:59 +08:00
|
|
|
|
* @param size The size contains this box's width and height.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @return An autoreleased PhysicsShapeBox object pointer.
|
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
static PhysicsShapeBox* create(const Vec2& size,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
const Vec2& offset = Vec2::ZERO,
|
|
|
|
|
float radius = 0.0f);
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this box's width and height.
|
|
|
|
|
*
|
2021-10-23 23:27:14 +08:00
|
|
|
|
* @return An Vec2 object.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*/
|
2021-10-23 23:27:14 +08:00
|
|
|
|
Vec2 getSize() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this box's position offset.
|
|
|
|
|
*
|
|
|
|
|
* @return A Vec2 object.
|
|
|
|
|
*/
|
2014-06-27 17:30:21 +08:00
|
|
|
|
virtual Vec2 getOffset() override { return getCenter(); }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-10-18 15:34:13 +08:00
|
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
bool init(const Vec2& size,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
const Vec2& offset = Vec2::ZERO,
|
|
|
|
|
float radius = 0.0f);
|
|
|
|
|
|
2014-06-27 17:30:21 +08:00
|
|
|
|
protected:
|
|
|
|
|
PhysicsShapeBox();
|
|
|
|
|
virtual ~PhysicsShapeBox();
|
2013-09-16 21:22:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/** A segment shape. */
|
2014-07-15 10:55:40 +08:00
|
|
|
|
class CC_DLL PhysicsShapeEdgeSegment : public PhysicsShape
|
2013-09-16 21:22:22 +08:00
|
|
|
|
{
|
2013-09-30 20:43:19 +08:00
|
|
|
|
public:
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Creates a PhysicsShapeEdgeSegment with specified value.
|
|
|
|
|
*
|
|
|
|
|
* @param a It's the edge's begin position.
|
|
|
|
|
* @param b It's the edge's end position.
|
|
|
|
|
* @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
|
|
|
|
|
* @param border It's a edge's border width.
|
|
|
|
|
* @return An autoreleased PhysicsShapeEdgeSegment object pointer.
|
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
static PhysicsShapeEdgeSegment* create(const Vec2& a,
|
|
|
|
|
const Vec2& b,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
float border = 1);
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this edge's begin position.
|
|
|
|
|
*
|
|
|
|
|
* @return A Vec2 object.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
Vec2 getPointA() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this edge's end position.
|
|
|
|
|
*
|
|
|
|
|
* @return A Vec2 object.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
Vec2 getPointB() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this edge's center position.
|
|
|
|
|
*
|
|
|
|
|
* @return A Vec2 object.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
virtual Vec2 getCenter() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-30 20:43:19 +08:00
|
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
bool init(const Vec2& a,
|
|
|
|
|
const Vec2& b,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
float border = 1);
|
2015-01-07 17:08:04 +08:00
|
|
|
|
virtual void updateScale() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
protected:
|
|
|
|
|
PhysicsShapeEdgeSegment();
|
|
|
|
|
virtual ~PhysicsShapeEdgeSegment();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
friend class PhysicsBody;
|
|
|
|
|
};
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/** An edge polygon shape. */
|
2014-07-15 10:55:40 +08:00
|
|
|
|
class CC_DLL PhysicsShapeEdgePolygon : public PhysicsShape
|
2013-09-16 21:22:22 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Creates a PhysicsShapeEdgePolygon with specified value.
|
|
|
|
|
*
|
|
|
|
|
* @param points A Vec2 object pointer, it contains an array of points.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param count An integer number, contains the count of the points array.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
|
|
|
|
|
* @param border It's a edge's border width.
|
|
|
|
|
* @return An autoreleased PhysicsShapeEdgePolygon object pointer.
|
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
static PhysicsShapeEdgePolygon* create(const Vec2* points,
|
|
|
|
|
int count,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
float border = 1);
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this polygon's center position.
|
|
|
|
|
*
|
|
|
|
|
* @return A Vec2 object.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
virtual Vec2 getCenter() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this polygon's points array.
|
|
|
|
|
*
|
|
|
|
|
* @param outPoints A Vec2 array pointer.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
void getPoints(Vec2* outPoints) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this polygon's points array count.
|
|
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @return An integer number.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*/
|
2013-12-05 17:19:01 +08:00
|
|
|
|
int getPointsCount() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
bool init(const Vec2* points,
|
|
|
|
|
int count,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
float border = 1);
|
2015-01-07 17:08:04 +08:00
|
|
|
|
virtual void updateScale() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
protected:
|
|
|
|
|
PhysicsShapeEdgePolygon();
|
|
|
|
|
virtual ~PhysicsShapeEdgePolygon();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
friend class PhysicsBody;
|
2014-06-27 17:30:21 +08:00
|
|
|
|
};
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/** An edge box shape. */
|
2014-07-15 10:55:40 +08:00
|
|
|
|
class CC_DLL PhysicsShapeEdgeBox : public PhysicsShapeEdgePolygon
|
2014-06-27 17:30:21 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Creates a PhysicsShapeEdgeBox with specified value.
|
|
|
|
|
*
|
2021-10-24 14:09:59 +08:00
|
|
|
|
* @param size The size contains this box's width and height.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
|
|
|
|
|
* @param border It's a edge's border width.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @return An autoreleased PhysicsShapeEdgeBox object pointer.
|
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
static PhysicsShapeEdgeBox* create(const Vec2& size,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
float border = 0,
|
|
|
|
|
const Vec2& offset = Vec2::ZERO);
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this box's position offset.
|
|
|
|
|
*
|
|
|
|
|
* @return A Vec2 object.
|
|
|
|
|
*/
|
2014-06-27 17:30:21 +08:00
|
|
|
|
virtual Vec2 getOffset() override { return getCenter(); }
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2014-06-27 17:30:21 +08:00
|
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
bool init(const Vec2& size,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
float border = 1,
|
|
|
|
|
const Vec2& offset = Vec2::ZERO);
|
|
|
|
|
|
2013-10-18 15:34:13 +08:00
|
|
|
|
protected:
|
2014-06-27 17:30:21 +08:00
|
|
|
|
PhysicsShapeEdgeBox();
|
|
|
|
|
virtual ~PhysicsShapeEdgeBox();
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2014-06-27 17:30:21 +08:00
|
|
|
|
friend class PhysicsBody;
|
2013-09-16 21:22:22 +08:00
|
|
|
|
};
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/** A chain shape. */
|
2014-07-15 10:55:40 +08:00
|
|
|
|
class CC_DLL PhysicsShapeEdgeChain : public PhysicsShape
|
2013-09-16 21:22:22 +08:00
|
|
|
|
{
|
|
|
|
|
public:
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Creates a PhysicsShapeEdgeChain with specified value.
|
|
|
|
|
*
|
|
|
|
|
* @param points A Vec2 object pointer, it contains an array of points.
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @param count An integer number, contains the count of the points array.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
* @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
|
|
|
|
|
* @param border It's a edge's border width.
|
|
|
|
|
* @return An autoreleased PhysicsShapeEdgeChain object pointer.
|
|
|
|
|
*/
|
2021-12-25 10:04:45 +08:00
|
|
|
|
static PhysicsShapeEdgeChain* create(const Vec2* points,
|
|
|
|
|
int count,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
float border = 1);
|
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this chain's center position.
|
|
|
|
|
*
|
|
|
|
|
* @return A Vec2 object.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
virtual Vec2 getCenter() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this chain's points array.
|
|
|
|
|
*
|
|
|
|
|
* @param outPoints A Vec2 array pointer.
|
|
|
|
|
*/
|
2014-05-15 01:07:09 +08:00
|
|
|
|
void getPoints(Vec2* outPoints) const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/**
|
|
|
|
|
* Get this chain's points array count.
|
|
|
|
|
*
|
2015-09-22 16:08:23 +08:00
|
|
|
|
* @return An integer number.
|
2015-03-19 17:58:08 +08:00
|
|
|
|
*/
|
2013-12-05 17:19:01 +08:00
|
|
|
|
int getPointsCount() const;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
protected:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
bool init(const Vec2* points,
|
|
|
|
|
int count,
|
|
|
|
|
const PhysicsMaterial& material = PHYSICSSHAPE_MATERIAL_DEFAULT,
|
|
|
|
|
float border = 1);
|
2015-01-07 17:08:04 +08:00
|
|
|
|
virtual void updateScale() override;
|
2021-12-25 10:04:45 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
protected:
|
|
|
|
|
PhysicsShapeEdgeChain();
|
|
|
|
|
virtual ~PhysicsShapeEdgeChain();
|
2014-06-27 17:30:21 +08:00
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
friend class PhysicsBody;
|
|
|
|
|
};
|
|
|
|
|
|
2015-06-15 10:28:37 +08:00
|
|
|
|
/** @} */
|
2015-03-19 17:58:08 +08:00
|
|
|
|
/** @} */
|
|
|
|
|
|
2013-09-16 21:22:22 +08:00
|
|
|
|
NS_CC_END
|
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
|
#endif // CC_USE_PHYSICS
|
|
|
|
|
#endif // __CCPHYSICS_FIXTURE_H__
|