axmol/cocos/physics/CCPhysicsWorld.h

429 lines
14 KiB
C
Raw Normal View History

/****************************************************************************
Copyright (c) 2013 Chukong Technologies Inc.
http://www.cocos2d-x.org
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
****************************************************************************/
#ifndef __CCPHYSICS_WORLD_H__
#define __CCPHYSICS_WORLD_H__
2014-04-30 08:37:36 +08:00
#include "base/ccConfig.h"
#if CC_USE_PHYSICS
#include <list>
2014-04-27 01:35:57 +08:00
#include "base/CCVector.h"
2014-04-30 08:37:36 +08:00
#include "math/CCGeometry.h"
2014-07-15 10:55:40 +08:00
#include "physics/CCPhysicsBody.h"
2013-12-07 10:48:02 +08:00
struct cpSpace;
NS_CC_BEGIN
class PhysicsBody;
class PhysicsJoint;
class PhysicsShape;
class PhysicsContact;
2015-01-07 17:08:04 +08:00
class Director;
class Node;
class Sprite;
2014-05-02 07:42:35 +08:00
class Scene;
class DrawNode;
class PhysicsDebugDraw;
class EventDispatcher;
class PhysicsWorld;
typedef struct PhysicsRayCastInfo
{
PhysicsShape* shape;
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 start;
Vec2 end; //< in lua, it's name is "ended"
Vec2 contact;
Vec2 normal;
float fraction;
void* data;
}PhysicsRayCastInfo;
/**
* @brief Called for each fixture found in the query. You control how the ray cast
* proceeds by returning a float:
* return true: continue
* return false: terminate the ray cast
* @param fixture the fixture hit by the ray
* @param point the point of initial intersection
* @param normal the normal vector at the point of intersection
* @return true to continue, false to terminate
*/
typedef std::function<bool(PhysicsWorld& world, const PhysicsRayCastInfo& info, void* data)> PhysicsRayCastCallbackFunc;
typedef std::function<bool(PhysicsWorld&, PhysicsShape&, void*)> PhysicsQueryRectCallbackFunc;
typedef PhysicsQueryRectCallbackFunc PhysicsQueryPointCallbackFunc;
2013-09-17 16:27:43 +08:00
/**
2015-05-28 15:47:03 +08:00
* @addtogroup physics
2015-03-18 16:35:38 +08:00
* @{
* @addtogroup physics_2d
* @{
2015-03-18 16:35:38 +08:00
*/
/**
* @class PhysicsWorld CCPhysicsWorld.h
2013-09-17 16:27:43 +08:00
* @brief An PhysicsWorld object simulates collisions and other physical properties. You do not create PhysicsWorld objects directly; instead, you can get it from an Scene object.
*/
2014-07-15 10:55:40 +08:00
class CC_DLL PhysicsWorld
{
public:
static const int DEBUGDRAW_NONE; ///< draw nothing
static const int DEBUGDRAW_SHAPE; ///< draw shapes
static const int DEBUGDRAW_JOINT; ///< draw joints
static const int DEBUGDRAW_CONTACT; ///< draw contact
static const int DEBUGDRAW_ALL; ///< draw all
public:
2015-03-18 16:35:38 +08:00
/**
* Adds a joint to this physics world.
*
* This joint will be added to this physics world at next frame.
* @attention If this joint is already added to another physics world, it will be removed from that world first and then add to this world.
* @param joint A pointer to an existing PhysicsJoint object.
*/
2013-11-04 19:26:34 +08:00
virtual void addJoint(PhysicsJoint* joint);
2015-03-18 16:35:38 +08:00
/**
* Remove a joint from this physics world.
*
* If this world is not locked, the joint is removed immediately, otherwise at next frame.
* If this joint is connected with a body, it will be removed from the body also.
* @param joint A pointer to an existing PhysicsJoint object.
* @param destroy true this joint will be destroyed after remove from this world, false otherwise.
*/
virtual void removeJoint(PhysicsJoint* joint, bool destroy = true);
2015-03-18 16:35:38 +08:00
/**
* Remove all joints from this physics world.
*
* @attention This function is invoked in the destructor of this physics world, you do not use this api in common.
* @param destroy true all joints will be destroyed after remove from this world, false otherwise.
*/
virtual void removeAllJoints(bool destroy = true);
2013-11-04 19:26:34 +08:00
2015-03-18 16:35:38 +08:00
/**
* Remove a body from this physics world.
*
* If this world is not locked, the body is removed immediately, otherwise at next frame.
* @attention If this body has joints, those joints will be removed also.
* @param body A pointer to an existing PhysicsBody object.
*/
2013-11-04 19:26:34 +08:00
virtual void removeBody(PhysicsBody* body);
2015-03-18 16:35:38 +08:00
/**
* Remove body by tag.
*
* If this world is not locked, the object is removed immediately, otherwise at next frame.
* @attention If this body has joints, those joints will be removed also.
* @param tag An interger number that identifies a PhysicsBody object.
*/
2013-11-05 20:02:58 +08:00
virtual void removeBody(int tag);
2015-03-18 16:35:38 +08:00
/**
* Remove all bodies from physics world.
*
* If this world is not locked, those body are removed immediately, otherwise at next frame.
*/
2013-11-04 19:26:34 +08:00
virtual void removeAllBodies();
2015-03-18 16:35:38 +08:00
/**
* Searches for physics shapes that intersects the ray.
*
* Query this physics world along the line segment from start to end.
* @param func Func is called for each shape found.
* @param start A Vec2 object contains the begin position of the ray.
* @param end A Vec2 object contains the end position of the ray.
* @param data User defined data, it is passed to func.
*/
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 rayCast(PhysicsRayCastCallbackFunc func, const Vec2& start, const Vec2& end, void* data);
2015-03-18 16:35:38 +08:00
/**
* Searches for physics shapes that contains in the rect.
*
* Query this physics world to find all shapes overlap rect.
* @param func Func is called for each shape whose bounding box overlaps rect.
* @param rect A Rect object contains a rectangle's x, y, width and height.
* @param data User defined data, it is passed to func.
*/
void queryRect(PhysicsQueryRectCallbackFunc func, const Rect& rect, void* data);
2015-03-18 16:35:38 +08:00
/**
* Searches for physics shapes that contains the point.
*
* @attention The point must lie inside a shape.
* @param func Func is called for each shape contains the point.
* @param point A Vec2 object contains the position of the point.
* @param data User defined data, it is passed to func.
*/
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 queryPoint(PhysicsQueryPointCallbackFunc func, const Vec2& point, void* data);
2015-03-18 16:35:38 +08:00
/**
* Get phsyics shapes that contains the point.
*
* All shapes contains the point will be pushed in a Vector<PhysicsShape*> object.
* @attention The point must lie inside a shape.
* @param point A Vec2 object contains the position of the point.
* @return A Vector<PhysicsShape*> object contains all found PhysicsShape pointer.
*/
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
Vector<PhysicsShape*> getShapes(const Vec2& point) const;
2015-03-18 16:35:38 +08:00
/**
* Get the nearest phsyics shape that contains the point.
*
* Query this physics world at point and return the closest shape.
* @param point A Vec2 object contains the position of the point.
* @return A PhysicsShape object pointer or nullptr if no shapes were found
*/
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
PhysicsShape* getShape(const Vec2& point) const;
2015-03-18 16:35:38 +08:00
/**
* Get all the bodys that in this physics world.
*
* @return A Vector<PhysicsBody*>& object contains all bodies in this physics world.
*/
2013-12-07 10:48:02 +08:00
const Vector<PhysicsBody*>& getAllBodies() const;
2015-03-18 16:35:38 +08:00
/**
* Get a body by tag.
*
* @param tag An interger number that identifies a PhysicsBody object.
* @return A PhysicsBody object pointer or nullptr if no shapes were found.
*/
2013-11-05 20:02:58 +08:00
PhysicsBody* getBody(int tag) const;
2015-03-18 16:35:38 +08:00
/**
* Get a scene contain this physics world.
*
* @attention This value is initialized in constructor
* @return A Scene object reference.
*/
2014-05-02 07:42:35 +08:00
inline Scene& getScene() const { return *_scene; }
2015-03-18 16:35:38 +08:00
/**
* Get the gravity value of this physics world.
*
* @return A Vec2 object.
2015-03-18 16:35:38 +08:00
*/
inline Vec2 getGravity() const { return _gravity; }
2015-03-18 16:35:38 +08:00
/**
* set the gravity value of this physics world.
*
* @param gravity A gravity value of this physics world.
*/
void setGravity(const Vec2& gravity);
2015-03-18 16:35:38 +08:00
/**
2015-03-18 16:35:38 +08:00
* Set the speed of this physics world.
*
* @attention if you setAutoStep(false), this won't work.
* @param speed A float number. Speed is the rate at which the simulation executes. default value is 1.0.
*/
inline void setSpeed(float speed) { if(speed >= 0.0f) { _speed = speed; } }
2015-03-18 16:35:38 +08:00
/**
* Get the speed of this physics world.
*
* @return A float number.
*/
inline float getSpeed() { return _speed; }
2015-03-18 16:35:38 +08:00
/**
2015-03-18 16:35:38 +08:00
* Set the update rate of this physics world
*
* Update rate is the value of EngineUpdateTimes/PhysicsWorldUpdateTimes.
* Set it higher can improve performance, set it lower can improve accuracy of physics world simulation.
* @attention if you setAutoStep(false), this won't work.
* @param rate An interger number, default value is 1.0.
*/
inline void setUpdateRate(int rate) { if(rate > 0) { _updateRate = rate; } }
2015-03-18 16:35:38 +08:00
/**
* Get the update rate of this physics world.
*
* @return An interger number.
*/
inline int getUpdateRate() { return _updateRate; }
2015-03-18 16:35:38 +08:00
/**
* set the number of substeps in an update of the physics world.
2015-03-18 16:35:38 +08:00
*
* One physics update will be divided into several substeps to increase its accuracy.
2015-03-18 16:35:38 +08:00
* @param steps An interger number, default value is 1.
*/
void setSubsteps(int steps);
2015-03-18 16:35:38 +08:00
/**
* Get the number of substeps of this physics world.
*
* @return An interger number.
*/
inline int getSubsteps() const { return _substeps; }
2015-03-18 16:35:38 +08:00
/**
* Set the debug draw mask of this physics world.
*
* This physics world will draw shapes and joints by DrawNode acoording to mask.
* @param mask Mask has four value:DEBUGDRAW_NONE, DEBUGDRAW_SHAPE, DEBUGDRAW_JOINT, DEBUGDRAW_CONTACT and DEBUGDRAW_ALL, default is DEBUGDRAW_NONE
*/
void setDebugDrawMask(int mask);
2015-03-18 16:35:38 +08:00
/**
* Get the bebug draw mask.
*
* @return An interger number.
*/
inline int getDebugDrawMask() { return _debugDrawMask; }
/**
2015-03-18 16:35:38 +08:00
* To control the step of physics.
*
* If you want control it by yourself( fixed-timestep for example ), you can set this to false and call step by yourself.
* @attention If you set auto step to false, setSpeed setSubsteps and setUpdateRate won't work, you need to control the time step by yourself.
* @param autoStep A bool object, defaut value is true.
*/
void setAutoStep(bool autoStep){ _autoStep = autoStep; }
2015-03-18 16:35:38 +08:00
/**
* Get the auto step of this physics world.
*
* @return A bool object.
*/
bool isAutoStep() { return _autoStep; }
2015-03-18 16:35:38 +08:00
/**
2015-03-18 16:35:38 +08:00
* The step for physics world.
*
* The times passing for simulate the physics.
* @attention You need to setAutoStep(false) first before it can work.
* @param delta A float number.
*/
void step(float delta);
protected:
static PhysicsWorld* construct(Scene* scene);
2015-09-08 09:54:01 +08:00
bool init();
virtual void addBody(PhysicsBody* body);
virtual void addShape(PhysicsShape* shape);
virtual void removeShape(PhysicsShape* shape);
virtual void update(float delta, bool userCall = false);
virtual void debugDraw();
virtual int collisionBeginCallback(PhysicsContact& contact);
virtual int collisionPreSolveCallback(PhysicsContact& contact);
virtual void collisionPostSolveCallback(PhysicsContact& contact);
virtual void collisionSeparateCallback(PhysicsContact& contact);
virtual void doAddBody(PhysicsBody* body);
virtual void doRemoveBody(PhysicsBody* body);
virtual void doRemoveJoint(PhysicsJoint* joint);
virtual void addBodyOrDelay(PhysicsBody* body);
virtual void removeBodyOrDelay(PhysicsBody* body);
2013-11-04 19:26:34 +08:00
virtual void updateBodies();
virtual void updateJoints();
protected:
Vec2 _gravity;
float _speed;
int _updateRate;
int _updateRateCount;
float _updateTime;
int _substeps;
cpSpace* _cpSpace;
bool _updateBodyTransform;
2013-12-07 10:48:02 +08:00
Vector<PhysicsBody*> _bodies;
std::list<PhysicsJoint*> _joints;
2014-05-02 07:42:35 +08:00
Scene* _scene;
bool _autoStep;
PhysicsDebugDraw* _debugDraw;
int _debugDrawMask;
EventDispatcher* _eventDispatcher;
2013-12-07 10:48:02 +08:00
Vector<PhysicsBody*> _delayAddBodies;
Vector<PhysicsBody*> _delayRemoveBodies;
2013-11-04 19:26:34 +08:00
std::vector<PhysicsJoint*> _delayAddJoints;
std::vector<PhysicsJoint*> _delayRemoveJoints;
protected:
PhysicsWorld();
virtual ~PhysicsWorld();
void beforeSimulation(Node *node, const Mat4& parentToWorldTransform, float nodeParentScaleX, float nodeParentScaleY, float parentRotation);
void afterSimulation(Node* node, const Mat4& parentToWorldTransform, float parentRotation);
friend class Node;
friend class Sprite;
2014-05-02 07:42:35 +08:00
friend class Scene;
2015-01-07 17:08:04 +08:00
friend class Director;
friend class PhysicsBody;
friend class PhysicsShape;
friend class PhysicsJoint;
friend class PhysicsWorldCallback;
friend class PhysicsDebugDraw;
};
2015-03-19 17:58:08 +08:00
/** A physics helper class. Draw physics shape, joint in debug mode.
* You do not create PhysicsDebugDraw objects directly; Instead, you can activate it by PhysicsWorld::setDebugDrawMask.
*/
2014-07-17 20:58:50 +08:00
class CC_DLL PhysicsDebugDraw
{
protected:
virtual bool begin();
virtual void end();
virtual void drawShape(PhysicsShape& shape);
virtual void drawJoint(PhysicsJoint& joint);
virtual void drawContact();
protected:
PhysicsDebugDraw(PhysicsWorld& world);
virtual ~PhysicsDebugDraw();
protected:
DrawNode* _drawNode;
PhysicsWorld& _world;
friend class PhysicsWorld;
};
2014-07-15 12:00:31 +08:00
extern const float CC_DLL PHYSICS_INFINITY;
2015-03-18 16:35:38 +08:00
/** @} */
/** @} */
NS_CC_END
#endif // CC_USE_PHYSICS
#endif // __CCPHYSICS_WORLD_H__