axmol/core/physics/CCPhysicsBody.h

623 lines
22 KiB
C
Raw Normal View History

/****************************************************************************
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
2022-08-08 18:02:17 +08:00
https://axys1.github.io/
2021-12-25 10:04:45 +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
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
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_BODY_H__
#define __CCPHYSICS_BODY_H__
2014-04-30 08:37:36 +08:00
#include "base/ccConfig.h"
2022-07-15 19:17:01 +08:00
#if AX_USE_PHYSICS
2021-12-25 10:04:45 +08:00
# include "2d/CCComponent.h"
# include "math/CCMath.h"
# include "physics/CCPhysicsShape.h"
# include "base/CCVector.h"
struct cpBody;
NS_AX_BEGIN
class Node;
class PhysicsWorld;
class PhysicsJoint;
2013-10-09 17:53:12 +08:00
const PhysicsMaterial PHYSICSBODY_MATERIAL_DEFAULT(0.1f, 0.5f, 0.5f);
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
* @{
* @addtogroup physics_2d
* @{
2015-03-19 17:58:08 +08:00
*/
2013-09-17 16:27:43 +08:00
/**
* A body affect by physics.
2015-03-19 17:58:08 +08:00
*
* It can attach one or more shapes.
2021-12-25 10:04:45 +08:00
* If you create body with createXXX, it will automatically compute mass and moment with density your specified(which is
* PHYSICSBODY_MATERIAL_DEFAULT by default, and the density value is 0.1f), and it based on the formula: mass = density
* * area. If you create body with createEdgeXXX, the mass and moment will be PHYSICS_INFINITY by default. And it's a
* static body. You can change mass and moment with setMass() and setMoment(). And you can change the body to be dynamic
* or static by use function setDynamic().
2013-09-17 16:27:43 +08:00
*/
2022-07-15 19:17:01 +08:00
class AX_DLL PhysicsBody : public Component
{
public:
const static std::string COMPONENT_NAME;
2021-12-25 10:04:45 +08:00
/**
* Create a body with default mass and moment.
*
* This default mass value is 1.0.
* This default moment value is 200.
* @return An autoreleased PhysicsBody object pointer.
2015-03-19 17:58:08 +08:00
*/
static PhysicsBody* create();
2021-12-25 10:04:45 +08:00
/**
* Create a body with mass and default moment.
*
* @param mass This body's mass.
* @return An autoreleased PhysicsBody object pointer.
2015-03-19 17:58:08 +08:00
*/
static PhysicsBody* create(float mass);
2021-12-25 10:04:45 +08:00
/**
* Create a body with mass and moment.
*
* @param mass This body's mass.
* @param moment This body's moment.
* @return An autoreleased PhysicsBody object pointer.
2015-03-19 17:58:08 +08:00
*/
static PhysicsBody* create(float mass, float moment);
2021-12-25 10:04:45 +08:00
/**
* Create a body contains a circle.
*
* @param radius A float number, it is the circle's radius.
* @param material A PhysicsMaterial object, the default value is PHYSICSSHAPE_MATERIAL_DEFAULT.
* @param offset A Vec2 object, it is the offset from the body's center of gravity in body local coordinates.
* @return An autoreleased PhysicsBody object pointer.
2015-03-19 17:58:08 +08:00
*/
2021-12-25 10:04:45 +08:00
static PhysicsBody* createCircle(float radius,
const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT,
const Vec2& offset = Vec2::ZERO);
/**
2015-03-19 17:58:08 +08:00
* Create a body contains a box shape.
*
2021-10-24 14:09:59 +08:00
* @param size 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 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 PhysicsBody object pointer.
*/
2021-12-25 10:04:45 +08:00
static PhysicsBody* createBox(const Vec2& size,
const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT,
const Vec2& offset = Vec2::ZERO);
2013-09-17 16:27:43 +08:00
/**
* @brief Create a body contains a polygon shape.
2015-03-19 17:58:08 +08:00
*
* @param points Points is an array of Vec2 structs defining a convex hull with a clockwise winding.
* @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 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 PhysicsBody object pointer.
2013-09-17 16:27:43 +08:00
*/
2021-12-25 10:04:45 +08:00
static PhysicsBody* createPolygon(const Vec2* points,
int count,
const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT,
const Vec2& offset = Vec2::ZERO);
/**
* Create a body contains a EdgeSegment shape.
*
2015-03-19 17:58:08 +08:00
* @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 PhysicsBody object pointer.
*/
2021-12-25 10:04:45 +08:00
static PhysicsBody* createEdgeSegment(const Vec2& a,
const Vec2& b,
const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT,
float border = 1);
2015-03-19 17:58:08 +08:00
/**
* Create a body contains a EdgeBox shape.
2021-10-24 22:06:13 +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.
* @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 PhysicsBody object pointer.
*/
2021-12-25 10:04:45 +08:00
static PhysicsBody* createEdgeBox(const Vec2& size,
const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT,
float border = 1,
const Vec2& offset = Vec2::ZERO);
/**
* Create a body contains a EdgePolygon shape.
*
2015-03-19 17:58:08 +08:00
* @param points Points is an array of Vec2 structs defining a convex hull with a clockwise winding.
* @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 PhysicsBody object pointer.
*/
2021-12-25 10:04:45 +08:00
static PhysicsBody* createEdgePolygon(const Vec2* points,
int count,
const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT,
float border = 1);
/**
* Create a body contains a EdgeChain shape.
*
2015-03-19 17:58:08 +08:00
* @param points A Vec2 object pointer, it contains an array of points.
* @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 PhysicsBody object pointer.
2015-03-19 17:58:08 +08:00
*/
2021-12-25 10:04:45 +08:00
static PhysicsBody* createEdgeChain(const Vec2* points,
int count,
const PhysicsMaterial& material = PHYSICSBODY_MATERIAL_DEFAULT,
float border = 1);
2015-03-19 17:58:08 +08:00
/**
* @brief Add a shape to body.
* @param shape The shape to be added.
* @param addMassAndMoment If this is true, the shape's mass and moment will be added to body. The default is true.
* @return This shape's pointer if added success or nullptr if failed.
2013-09-17 16:27:43 +08:00
*/
virtual PhysicsShape* addShape(PhysicsShape* shape, bool addMassAndMoment = true);
2015-03-19 17:58:08 +08:00
/**
* @brief Remove a shape from body.
* @param shape Shape the shape to be removed.
2021-12-25 10:04:45 +08:00
* @param reduceMassAndMoment If this is true, the body mass and moment will be reduced by shape. The default is
* true.
2013-09-17 16:27:43 +08:00
*/
void removeShape(PhysicsShape* shape, bool reduceMassAndMoment = true);
2015-03-19 17:58:08 +08:00
/**
* @brief Remove a shape from body.
* @param tag The tag of the shape to be removed.
2021-12-25 10:04:45 +08:00
* @param reduceMassAndMoment If this is true, the body mass and moment will be reduced by shape. The default is
* true.
2013-09-17 16:27:43 +08:00
*/
void removeShape(int tag, bool reduceMassAndMoment = true);
2021-12-25 10:04:45 +08:00
/**
* Remove all shapes.
*
2021-12-25 10:04:45 +08:00
* @param reduceMassAndMoment If this is true, the body mass and moment will be reduced by shape. The default is
* true.
2015-03-19 17:58:08 +08:00
*/
void removeAllShapes(bool reduceMassAndMoment = true);
2015-03-19 17:58:08 +08:00
/**
* Get the body shapes.
2021-12-25 10:04:45 +08:00
*
2015-03-19 17:58:08 +08:00
* @return A Vector<PhysicsShape*> object contains PhysicsShape pointer.
*/
const Vector<PhysicsShape*>& getShapes() const { return _shapes; }
2015-03-19 17:58:08 +08:00
/**
* Get the first shape of the body shapes.
*
* @return The first shape in this body.
*/
PhysicsShape* getFirstShape() const { return _shapes.size() >= 1 ? _shapes.at(0) : nullptr; }
2021-12-25 10:04:45 +08:00
/**
* get the shape of the body.
*
* @param tag An integer number that identifies a PhysicsShape object.
* @return A PhysicsShape object pointer or nullptr if no shapes were found.
2015-03-19 17:58:08 +08:00
*/
PhysicsShape* getShape(int tag) const;
2021-12-25 10:04:45 +08:00
/**
* Applies a continuous force to body.
2021-12-25 10:04:45 +08:00
*
* @param force The force is applies to this body.
* @param offset A Vec2 object, it is the offset from the body's center of gravity in world coordinates.
2015-03-19 17:58:08 +08:00
*/
virtual void applyForce(const Vec2& force, const Vec2& offset = Vec2::ZERO);
2015-03-19 17:58:08 +08:00
2021-12-25 10:04:45 +08:00
/**
* reset all the force applied to body.
2015-03-19 17:58:08 +08:00
*/
virtual void resetForces();
2015-03-19 17:58:08 +08:00
/**
* Applies a immediate force to body.
*
* @param impulse The impulse is applies to this body.
* @param offset A Vec2 object, it is the offset from the body's center of gravity in world coordinates.
2015-03-19 17:58:08 +08:00
*/
virtual void applyImpulse(const Vec2& impulse, const Vec2& offset = Vec2::ZERO);
2021-12-25 10:04:45 +08:00
/**
* Applies a torque force to body.
*
* @param torque The torque is applies to this body.
2015-03-19 17:58:08 +08:00
*/
virtual void applyTorque(float torque);
2021-12-25 10:04:45 +08:00
/**
* Set the velocity of a body.
2021-12-25 10:04:45 +08:00
*
* @param velocity The velocity is set to this body.
2015-03-19 17:58:08 +08:00
*/
virtual void setVelocity(const Vec2& velocity);
2021-12-25 10:04:45 +08:00
2015-03-19 17:58:08 +08:00
/** Get the velocity of a body. */
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
virtual Vec2 getVelocity();
2021-12-25 10:04:45 +08:00
/**
* Set the angular velocity of a body.
*
* @param velocity The angular velocity is set to this body.
2015-03-19 17:58:08 +08:00
*/
virtual void setAngularVelocity(float velocity);
2021-12-25 10:04:45 +08:00
2015-03-19 17:58:08 +08:00
/** Get the angular velocity of a body at a local point.*/
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
virtual Vec2 getVelocityAtLocalPoint(const Vec2& point);
2021-12-25 10:04:45 +08:00
/** get the angular velocity of a body at a world point */
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
virtual Vec2 getVelocityAtWorldPoint(const Vec2& point);
2021-12-25 10:04:45 +08:00
/** get the angular velocity of a body */
virtual float getAngularVelocity();
2021-12-25 10:04:45 +08:00
/** set the max of velocity */
virtual void setVelocityLimit(float limit);
2021-12-25 10:04:45 +08:00
/** get the max of velocity */
virtual float getVelocityLimit();
2021-12-25 10:04:45 +08:00
/** set the max of angular velocity */
virtual void setAngularVelocityLimit(float limit);
2021-12-25 10:04:45 +08:00
/** get the max of angular velocity */
virtual float getAngularVelocityLimit();
2021-12-25 10:04:45 +08:00
/** remove the body from the world it added to */
void removeFromWorld();
2021-12-25 10:04:45 +08:00
/** get the world body added to. */
PhysicsWorld* getWorld() const { return _world; }
/** get all joints the body have */
const std::vector<PhysicsJoint*>& getJoints() const { return _joints; }
2021-12-25 10:04:45 +08:00
/** get the node the body set to. */
Node* getNode() const { return _owner; }
2021-12-25 10:04:45 +08:00
/**
* 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.
* @param bitmask An integer number, the default value is 0xFFFFFFFF (all bits set).
*/
void setCategoryBitmask(int bitmask);
2021-12-25 10:04:45 +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 worlds delegate. For best performance, only set bits in the contacts mask
* for interactions you are interested in.
* @param bitmask An integer number, the default value is 0x00000000 (all bits cleared).
*/
void setContactTestBitmask(int bitmask);
2021-12-25 10:04:45 +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.
* @param bitmask An integer number, the default value is 0xFFFFFFFF (all bits set).
*/
void setCollisionBitmask(int bitmask);
2021-12-25 10:04:45 +08:00
/**
* Return bitmask of first shape.
2021-12-25 10:04:45 +08:00
*
2015-03-19 17:58:08 +08:00
* @return If there is no shape in body, return default value.(0xFFFFFFFF)
*/
2014-08-08 16:38:20 +08:00
int getCategoryBitmask() const;
2021-12-25 10:04:45 +08:00
/**
* Return bitmask of first shape.
*
2015-03-19 17:58:08 +08:00
* @return If there is no shape in body, return default value.(0x00000000)
*/
2014-08-08 16:38:20 +08:00
int getContactTestBitmask() const;
2021-12-25 10:04:45 +08:00
/**
* Return bitmask of first shape.
2021-12-25 10:04:45 +08:00
*
* @return If there is no shape in body, return default value.(0xFFFFFFFF)
2015-03-19 17:58:08 +08:00
*/
2014-08-08 16:38:20 +08:00
int getCollisionBitmask() const;
2021-12-25 10:04:45 +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). It have high priority than bit masks.
*/
void setGroup(int group);
2021-12-25 10:04:45 +08:00
/**
* Return group of first shape.
2021-12-25 10:04:45 +08:00
*
* @return If there is no shape in body, return default value.(0)
2015-03-19 17:58:08 +08:00
*/
2014-08-08 16:38:20 +08:00
int getGroup() const;
2021-12-25 10:04:45 +08:00
/** get the body position. */
2015-09-08 09:54:01 +08:00
Vec2 getPosition() const;
/** get the body rotation. */
float getRotation();
/** set body position offset, it's the position witch relative to node */
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
void setPositionOffset(const Vec2& position);
/** get body position offset. */
const Vec2& getPositionOffset() const { return _positionOffset; }
2021-12-25 10:04:45 +08:00
/** set body rotation offset, it's the rotation witch relative to node */
void setRotationOffset(float rotation);
2021-12-25 10:04:45 +08:00
/** set the body rotation offset */
float getRotationOffset() const { return _rotationOffset; }
2021-12-25 10:04:45 +08:00
/**
2015-03-19 17:58:08 +08:00
* @brief Test the body is dynamic or not.
*
* A dynamic body will effect with gravity.
2013-09-17 16:27:43 +08:00
*/
bool isDynamic() const { return _dynamic; }
/**
2015-03-19 17:58:08 +08:00
* @brief Set dynamic to body.
2021-12-25 10:04:45 +08:00
*
2015-03-19 17:58:08 +08:00
* A dynamic body will effect with gravity.
2013-09-17 16:27:43 +08:00
*/
void setDynamic(bool dynamic);
2021-12-25 10:04:45 +08:00
/**
2015-03-19 17:58:08 +08:00
* @brief Set the body mass.
*
2021-12-25 10:04:45 +08:00
* @attention If you need add/subtract mass to body, don't use setMass(getMass() +/- mass), because the mass of body
* may be equal to PHYSICS_INFINITY, it will cause some unexpected result, please use addMass() instead.
2013-09-17 16:27:43 +08:00
*/
void setMass(float mass);
2021-12-25 10:04:45 +08:00
2015-03-19 17:58:08 +08:00
/** Get the body mass. */
float getMass() const { return _mass; }
/**
2015-03-19 17:58:08 +08:00
* @brief Add mass to body.
*
* @param mass If _mass(mass of the body) == PHYSICS_INFINITY, it remains.
* if mass == PHYSICS_INFINITY, _mass will be PHYSICS_INFINITY.
* if mass == -PHYSICS_INFINITY, _mass will not change.
* if mass + _mass <= 0, _mass will equal to MASS_DEFAULT(1.0)
* other wise, mass = mass + _mass;
*/
void addMass(float mass);
2021-12-25 10:04:45 +08:00
/**
2015-03-19 17:58:08 +08:00
* @brief Set the body moment of inertia.
*
2021-12-25 10:04:45 +08:00
* @note If you need add/subtract moment to body, don't use setMoment(getMoment() +/- moment), because the moment of
* body may be equal to PHYSICS_INFINITY, it will cause some unexpected result, please use addMoment() instead.
*/
void setMoment(float moment);
2021-12-25 10:04:45 +08:00
2015-03-19 17:58:08 +08:00
/** Get the body moment of inertia. */
float getMoment() const { return _moment; }
2021-12-25 10:04:45 +08:00
/**
2015-03-19 17:58:08 +08:00
* @brief Add moment of inertia to body.
2021-12-25 10:04:45 +08:00
*
2015-03-19 17:58:08 +08:00
* @param moment If _moment(moment of the body) == PHYSICS_INFINITY, it remains.
* if moment == PHYSICS_INFINITY, _moment will be PHYSICS_INFINITY.
* if moment == -PHYSICS_INFINITY, _moment will not change.
* if moment + _moment <= 0, _moment will equal to MASS_DEFAULT(1.0)
* other wise, moment = moment + _moment;
*/
void addMoment(float moment);
2021-12-25 10:04:45 +08:00
/** get linear damping. */
float getLinearDamping() const { return _linearDamping; }
2021-12-25 10:04:45 +08:00
/**
2015-03-19 17:58:08 +08:00
* Set linear damping.
*
* it is used to simulate fluid or air friction forces on the body.
* @param damping The value is 0.0f to 1.0f.
*/
2021-12-25 10:04:45 +08:00
void setLinearDamping(float damping)
{
_linearDamping = damping;
updateDamping();
}
2015-03-19 17:58:08 +08:00
/** Get angular damping. */
float getAngularDamping() const { return _angularDamping; }
/**
2015-03-19 17:58:08 +08:00
* Set angular damping.
*
* It is used to simulate fluid or air friction forces on the body.
* @param damping The value is 0.0f to 1.0f.
*/
2021-12-25 10:04:45 +08:00
void setAngularDamping(float damping)
{
_angularDamping = damping;
updateDamping();
}
2015-03-19 17:58:08 +08:00
/** Whether the body is at rest. */
2013-11-01 16:26:03 +08:00
bool isResting() const;
2021-12-25 10:04:45 +08:00
/** set body to rest */
2014-02-26 19:56:52 +08:00
void setResting(bool rest) const;
2021-12-25 10:04:45 +08:00
/**
2015-03-19 17:58:08 +08:00
* Set the enable value.
*
* If the body it isn't enabled, it will not has simulation by world.
*/
virtual void setEnabled(bool enable) override;
2021-12-25 10:04:45 +08:00
2015-03-19 17:58:08 +08:00
/** Whether the body can rotation. */
bool isRotationEnabled() const { return _rotationEnabled; }
2021-12-25 10:04:45 +08:00
2015-03-19 17:58:08 +08:00
/** Set the body is allow rotation or not */
void setRotationEnable(bool enable);
2021-12-25 10:04:45 +08:00
/** Whether this physics body is affected by the physics world's gravitational force. */
bool isGravityEnabled() const { return _gravityEnabled; }
2021-12-25 10:04:45 +08:00
2015-03-19 17:58:08 +08:00
/** Set the body is affected by the physics world's gravitational force or not. */
void setGravityEnable(bool enable);
2021-12-25 10:04:45 +08:00
2015-03-19 17:58:08 +08:00
/** Get the body's tag. */
int getTag() const { return _tag; }
2021-12-25 10:04:45 +08:00
2015-03-19 17:58:08 +08:00
/** set the body's tag. */
void setTag(int tag) { _tag = tag; }
2021-12-25 10:04:45 +08:00
2015-03-19 17:58:08 +08:00
/** Convert the world point to local. */
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 world2Local(const Vec2& point);
2021-12-25 10:04:45 +08:00
2015-03-19 17:58:08 +08:00
/** Convert the local point to world. */
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 local2World(const Vec2& point);
2015-03-19 17:58:08 +08:00
/** Get the rigid body of chipmunk. */
2015-09-08 09:54:01 +08:00
cpBody* getCPBody() const { return _cpBody; }
virtual void onEnter() override;
virtual void onExit() override;
virtual void onAdd() override;
virtual void onRemove() override;
2021-12-25 10:04:45 +08:00
protected:
PhysicsBody();
virtual ~PhysicsBody();
2021-12-25 10:04:45 +08:00
virtual bool init() override;
virtual void setPosition(float positionX, float positionY);
virtual void setRotation(float rotation);
2014-06-27 17:30:21 +08:00
virtual void setScale(float scaleX, float scaleY);
2021-12-25 10:04:45 +08:00
void update(float delta) override;
void removeJoint(PhysicsJoint* joint);
2021-12-25 10:04:45 +08:00
void updateDamping() { _isDamping = _linearDamping != 0.0f || _angularDamping != 0.0f; }
void addToPhysicsWorld();
void removeFromPhysicsWorld();
2021-12-25 10:04:45 +08:00
void beforeSimulation(const Mat4& parentToWorldTransform,
const Mat4& nodeToWorldTransform,
float scaleX,
float scaleY,
float rotation);
void afterSimulation(const Mat4& parentToWorldTransform, float parentRotation);
2021-12-25 10:04:45 +08:00
protected:
std::vector<PhysicsJoint*> _joints;
Vector<PhysicsShape*> _shapes;
PhysicsWorld* _world;
2021-12-25 10:04:45 +08:00
cpBody* _cpBody;
bool _dynamic;
bool _rotationEnabled;
bool _gravityEnabled;
bool _massDefault;
bool _momentDefault;
float _mass;
float _area;
float _density;
float _moment;
Squashed commit of the following: commit 36c2807d07848448c1fed86f4b119205048691bf Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 29 13:11:40 2016 -0800 binary file 82 commit 9b7cd003b12faefd0522d12f765c027efb001ab2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 29 12:56:39 2016 -0800 fore multiple in windows phone 8.1 too commit daea8a3ef8d69915e7a9d962fd745a1103011bab Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 29 12:50:45 2016 -0800 force multiple commit 0fbabdbf99974e95de083d79c7d6ae7cf735e4b6 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 29 10:44:40 2016 -0800 compiles commit f817766afcd0ffc4ca93f628d55fabc4b5a96ba5 Merge: 7b2cea3 8bf3d33 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 29 09:37:24 2016 -0800 Merge branch 'v3' into chipmunk_v7_2 commit 7b2cea329a56ae2786428d39a499bc12ba3860e6 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Sat Feb 27 01:11:13 2016 -0800 correct paths for win8.1 commit dcf1f046eb1e18474d6f94b2d7dc31fbf1b06cea Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 26 22:46:58 2016 -0800 projects works on win32 commit ab5b14c25ef0fdf224480302f9cb3cc01d5c360c Merge: 04377cc 9af2f4e Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 26 21:57:10 2016 -0800 Merge branch 'v3' into chipmunk_v7_2 commit 04377cce7f46b2c2016ccc3855fc479c4f6aa516 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 26 21:26:55 2016 -0800 trying to make it compile on win32 commit 7703946d99e1cdc6a57f2ccb2a868818c1367291 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 24 10:28:12 2016 -0800 quick hack to make it compile... ...autogenerated files will fix it. commit ea35bf3a5894cb80b09ecd0a4a5408dcc19785f5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 24 09:20:59 2016 -0800 Squashed commit of the following: commit 487e52a7af7cdb40135fd3bd83b2efba0dfe6265 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 20:10:13 2016 -0800 compiles.. sort of commit a7990e2888d5ef1e43b811148b23c0b899105ab3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 19:55:24 2016 -0800 more chipmunk fixes commit 1174f6ec8201324161d7946af0f493b136a56690 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 19:36:15 2016 -0800 more chipmunk fixes commit 00ac2449ca0c35bd9184310d58e74aaa05bd1323 Merge: f942c5a 0594d3c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 19:29:27 2016 -0800 Merge branch 'chipmunk_v7_squashed' of github.com:ricardoquesada/cocos2d-x into chipmunk_v7_squashed commit f942c5a3cc7b24f3ac211d781be1b9c9d4ec0fd7 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 19:28:51 2016 -0800 correct path for chipmunk commit 0594d3c4141d390b2566ea76101e383f15ebcaaf Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 18:44:05 2016 -0800 compiles on ios commit 379503399c384ad77d25d68a2f83b71a829b1c04 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 17:51:36 2016 -0800 chipmunk include fixes commit 95839fb7b406a32255853294b016d8c15aec1ed6 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 17:09:04 2016 -0800 fixes for cmake + mac commit 39449ea3b7efccae2946785c1c11433d964ee480 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 16:51:25 2016 -0800 correct includes commit 98e97d7d2f00e6a78d040dcaf17e5a077e9a88c3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 16:35:40 2016 -0800 fixes chipmunk with cmake commit 337f21f9466703722847635301d841ace9b757cb Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 14:42:01 2016 -0800 updates android and linux projects commit 7111a9993b97f78cf73206804b25665c21a59ca8 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 14:18:26 2016 -0800 cosmetic changes commit ce15038b8d2c0c7ebe31b4e1efe92646b7c70d1b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 06:53:41 2016 -0800 chipmunk autogenerated files commit 66c71bfa3aaab04abf25f284e2e76ce2a74a98de Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 06:47:41 2016 -0800 compatibility both in JS (to reduce space) and in C for (C++ users) commit 0f9ffa0a8ab23a19e1f10b04e6987c2288764b1f Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 06:10:02 2016 -0800 mooooore fixes commit 9ab23014093677e8eda69b105f50410b8c792aa3 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 05:30:58 2016 -0800 doesn't crash with collision handler commit 69275a16817a038244bbaaff9e82a011b6729cb2 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Tue Feb 23 05:16:29 2016 -0800 adds missing space functions commit a6b97bbc76cb9ab293356bb7451cfa858353f589 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 22 22:22:27 2016 -0800 queries... better commit 3442bceca64f5a0ddbbbb1a288146a2a61d87632 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 22 19:48:41 2016 -0800 adds more missing functions fixes other chipmunk JS issues commit 3797a033896d059da58a05ce0de832ed9c150eff Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 22 18:30:21 2016 -0800 yep... poly works ok commit d1bb57776891605b9d3e4fb90736c6869d96b944 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 22 17:28:29 2016 -0800 neede compat files commit 39ec518d4e089124d9a53fe3a8dce3aa0474c233 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Mon Feb 22 17:28:04 2016 -0800 query working! commit 71a8001fd6bc03ac674621f5da38a3f8778430b4 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 19 21:57:03 2016 -0800 almost there commit 9272fdcd06ba188db2fe5701fb2ac21476d54883 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 19 21:18:46 2016 -0800 fixes return values commit 7218778da846e1e36a510c0a19a5ee76f91db032 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 19 20:36:14 2016 -0800 cpMomentForSegment is manual since parameter 4 is optional in chipmunk 6, but not in 7 commit 98d5d3e23c2cdb941cc0b1f3ce8275990356e88d Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 19 17:29:28 2016 -0800 yeah... process the arguments correctly works both for functions and auto_classes commit ce6a4fe3593b4f3b0fcdf11d12e297d789e0d96b Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 19 16:49:00 2016 -0800 compiles and links fixes some issues with the queries. returns shapes instad of the queryInfo commit 3f879482dc6db86e45e4319bc802ccf19b52a46c Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Fri Feb 19 15:03:18 2016 -0800 adds removeCollisionHandler and other fixes commit 32d825fc7bd323e144db6a1badc4a62420b6ea44 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Thu Feb 18 20:59:24 2016 -0800 compiles... doesn't work yet commit bd64de81713fb2d7652a538d667d73f05f5d9320 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed Feb 17 18:17:39 2016 -0800 WIP: chipmunk bindings
2016-03-01 05:53:00 +08:00
float _velocityLimit;
float _angularVelocityLimit;
bool _isDamping;
float _linearDamping;
float _angularDamping;
int _tag;
2021-12-25 10:04:45 +08:00
2015-09-08 09:54:01 +08:00
// when setMass() is invoked, it means body's mass is not calculated by shapes
bool _massSetByUser;
// when setMoment() is invoked, it means body's moment is not calculated by shapes
bool _momentSetByUser;
2021-12-25 10:04:45 +08:00
Squashed commit of the following: commit a9572b8913f3a38b59adbd7b4017ab9848a6b2b5 Author: Ricardo Quesada <ricardoquesada@gmail.com> Date: Wed May 14 10:03:44 2014 -0700 math renames `Vector2` -> `Vec2` `Vector3` -> `Vec3` `Vector4` -> `Vec4` `Matrix` -> `Mat4` commit 4e107f4bd854c26bfceb52b063d6bd9cea02d6a3 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:24:28 2014 -0700 raw version of rename Vector3 commit 1d115573ebe96a5fc815fa44fbe6417ea7dba841 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:07:14 2014 -0700 rename Vector2 after merge commit ab2ed58c129dbc30a4c0970ed94568c5d271657b Merge: 1978d2d 86fb75a Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 09:05:30 2014 -0700 Merge branch 'v3' into v3_renameMathClassName Conflicts: tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UIButtonTest/UIButtonTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UICheckBoxTest/UICheckBoxTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UISliderTest/UISliderTest_Editor.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest.cpp tests/cpp-tests/Classes/UITest/CocoStudioGUITest/UITextFieldTest/UITextFieldTest_Editor.cpp commit 1978d2d174877172ccddc083020a1bbf43ad3b39 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 08:51:45 2014 -0700 rename vector2 in tests/cpp-empty-test folder commit d4e0ff13dcce62724d2fece656543f26aa28e467 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:58:23 2014 -0700 rename vector2 in tests/cpp-tests cpp files commit be50ca2ec75e0fd32a6fcdaa15fe1ebb4cafe79f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:52:57 2014 -0700 rename vector2 in tests/cpp-tests head files commit 6daef564400d4e28c4ce20859a68e0f583fed125 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:49:48 2014 -0700 rename vector2 in extension folder commit 8f3f0f65ceea92c9e7a0d87ab54e62220c5572e2 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:47:22 2014 -0700 rename vector2 in cocos/2d cpp files commit e1f3105aae06d595661a3030f519f7cc13aefbed Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:44:39 2014 -0700 rename vector2 in cocos/2d head files commit 6708d890bfe486109120c3cd4b9fe5c078b7108f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:59 2014 -0700 rename vector2 in cocos/base folder commit d3978fa5447c31ea2f3ece5469b7e746dfba4248 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:43 2014 -0700 rename vector2 in cocos/deprecated folder commit 4bff45139363d6b9706edbbcf9f322d48b4fd019 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:40:26 2014 -0700 rename vector2 in cocos/editor-support folder commit 353d244c995f8b5d14f635c52aed8bc5e5fc1a6f Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:36:48 2014 -0700 rename vector2 in cocos/ui folder commit 758b8f4d513084b9922d7242e9b8f2c7f316de6c Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:39 2014 -0700 rename vector2 in cocos/renderer folder commit 0bd2710dd8714cecb993880bc37affd9ecb05c27 Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:32:15 2014 -0700 rename vector2 in cocos/physics folder commit b7f0581c4587348bdbc1478d5374c2325735f21d Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:25:01 2014 -0700 rename vector2 in cocos/math folder commit a8631a8e1a4e2740807ccd9be9d70de6ecaad7dd Author: Huabing.Xu <dabingnn@gmail.com> Date: Wed May 14 00:16:55 2014 -0700 rename Vector2 to Vec2 deprecate typedef Vector2
2014-05-15 01:07:09 +08:00
Vec2 _positionOffset;
float _rotationOffset;
float _recordedRotation;
double _recordedAngle;
2021-12-25 10:04:45 +08:00
// offset between owner's center point and down left point
Vec3 _ownerCenterOffset;
// offset of owner's center point and anchor point in parent coordinate
Vec2 _offset;
float _recordScaleX;
float _recordScaleY;
float _recordPosX;
float _recordPosY;
friend class PhysicsWorld;
friend class PhysicsShape;
friend class PhysicsJoint;
};
2015-03-19 17:58:08 +08:00
/** @} */
/** @} */
NS_AX_END
2022-07-15 19:17:01 +08:00
#endif // AX_USE_PHYSICS
2021-12-25 10:04:45 +08:00
#endif // __CCPHYSICS_BODY_H__