| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  |  | // Copyright (c) 2018-2019 Kiwano - Nomango
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // Permission is hereby granted, free of charge, to any person obtaining a copy
 | 
					
						
							|  |  |  |  | // of this software and associated documentation files (the "Software"), to deal
 | 
					
						
							|  |  |  |  | // in the Software without restriction, including without limitation the rights
 | 
					
						
							|  |  |  |  | // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 | 
					
						
							|  |  |  |  | // copies of the Software, and to permit persons to whom the Software is
 | 
					
						
							|  |  |  |  | // furnished to do so, subject to the following conditions:
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // The above copyright notice and this permission notice shall be included in
 | 
					
						
							|  |  |  |  | // all copies or substantial portions of the Software.
 | 
					
						
							|  |  |  |  | // 
 | 
					
						
							|  |  |  |  | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 | 
					
						
							|  |  |  |  | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 | 
					
						
							|  |  |  |  | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 | 
					
						
							|  |  |  |  | // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 | 
					
						
							|  |  |  |  | // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 | 
					
						
							|  |  |  |  | // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 | 
					
						
							|  |  |  |  | // THE SOFTWARE.
 | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | #pragma once
 | 
					
						
							|  |  |  |  | #include <kiwano-physics/helper.h>
 | 
					
						
							|  |  |  |  | #include <kiwano-physics/Shape.h>
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:49:34 +08:00
										 |  |  |  | #include <kiwano-physics/Fixture.h>
 | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | namespace kiwano | 
					
						
							|  |  |  |  | { | 
					
						
							|  |  |  |  | 	namespace physics | 
					
						
							|  |  |  |  | 	{ | 
					
						
							|  |  |  |  | 		class World; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		// <20><><EFBFBD><EFBFBD>
 | 
					
						
							| 
									
										
										
										
											2019-10-23 16:49:34 +08:00
										 |  |  |  | 		KGE_DECLARE_SMART_PTR(Body); | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  |  | 		class KGE_API Body | 
					
						
							|  |  |  |  | 			: public ObjectBase | 
					
						
							|  |  |  |  | 		{ | 
					
						
							|  |  |  |  | 		public: | 
					
						
							|  |  |  |  | 			enum class Type | 
					
						
							|  |  |  |  | 			{ | 
					
						
							|  |  |  |  | 				Static = 0, | 
					
						
							|  |  |  |  | 				Kinematic, | 
					
						
							|  |  |  |  | 				Dynamic, | 
					
						
							|  |  |  |  | 			}; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			Body(); | 
					
						
							|  |  |  |  | 			Body(b2Body* body, Actor* actor); | 
					
						
							|  |  |  |  | 			virtual ~Body(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-23 16:49:34 +08:00
										 |  |  |  | 			static BodyPtr Create(World* world, Actor* actor); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:49:34 +08:00
										 |  |  |  | 			// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״
 | 
					
						
							| 
									
										
										
										
											2019-10-23 16:49:34 +08:00
										 |  |  |  | 			Fixture AddShape(Shape* shape, float density = 0.f, float friction = 0.2f, float restitution = 0.f); | 
					
						
							|  |  |  |  | 			Fixture AddCircleShape(float radius, float density = 0.f); | 
					
						
							|  |  |  |  | 			Fixture AddBoxShape(Vec2 const& size, float density = 0.f); | 
					
						
							|  |  |  |  | 			Fixture AddPolygonShape(Vector<Point> const& vertexs, float density = 0.f); | 
					
						
							|  |  |  |  | 			Fixture AddEdgeShape(Point const& p1, Point const& p2, float density = 0.f); | 
					
						
							|  |  |  |  | 			Fixture AddChainShape(Vector<Point> const& vertexs, bool loop, float density = 0.f); | 
					
						
							| 
									
										
										
										
											2019-10-22 16:49:34 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 			// <20><>ȡ<EFBFBD>о<EFBFBD><D0BE>б<EFBFBD>
 | 
					
						
							|  |  |  |  | 			Fixture GetFixture() const						{ KGE_ASSERT(body_); Fixture(body_->GetFixtureList()); } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			// <20>Ƴ<EFBFBD><C6B3>о<EFBFBD>
 | 
					
						
							|  |  |  |  | 			void RemoveFixture(Fixture const& fixture); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			// <20><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
 | 
					
						
							|  |  |  |  | 			float GetMass() const							{ KGE_ASSERT(body_); return body_->GetMass(); } | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  |  | 			// <20><>ȡ<EFBFBD><C8A1>ת<EFBFBD>Ƕ<EFBFBD>
 | 
					
						
							|  |  |  |  | 			float GetRotation() const						{ KGE_ASSERT(body_); return math::Radian2Angle(body_->GetAngle()); } | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			// <20><>ȡλ<C8A1><CEBB>
 | 
					
						
							|  |  |  |  | 			Point GetPosition() const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:49:34 +08:00
										 |  |  |  | 			Point GetLocalPoint(Point const& world) const; | 
					
						
							|  |  |  |  | 			Point GetWorldPoint(Point const& local) const; | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			Type GetType() const							{ KGE_ASSERT(body_); return Type(body_->GetType()); } | 
					
						
							|  |  |  |  | 			void SetType(Type type)							{ KGE_ASSERT(body_); body_->SetType(static_cast<b2BodyType>(type)); } | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-23 16:49:34 +08:00
										 |  |  |  | 			void ApplyForce(Vec2 const& force, Point const& point, bool wake = true); | 
					
						
							|  |  |  |  | 			void ApplyForceToCenter(Vec2 const& force, bool wake = true); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 			void ApplyTorque(float torque, bool wake = true); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:49:34 +08:00
										 |  |  |  | 			bool IsIgnoreRotation() const					{ return ignore_rotation_; } | 
					
						
							|  |  |  |  | 			void SetIgnoreRotation(bool ignore_rotation)	{ ignore_rotation_ = ignore_rotation; } | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:49:34 +08:00
										 |  |  |  | 			Actor* GetActor() const							{ return actor_; } | 
					
						
							|  |  |  |  | 			void SetActor(Actor* actor)						{ actor_ = actor; } | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:49:34 +08:00
										 |  |  |  | 			b2Body* GetB2Body()								{ return body_; } | 
					
						
							|  |  |  |  | 			const b2Body* GetB2Body() const					{ return body_; } | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  |  | 			void SetB2Body(b2Body* body); | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:49:34 +08:00
										 |  |  |  | 			World* GetWorld()								{ return world_; } | 
					
						
							|  |  |  |  | 			const World* GetWorld() const					{ return world_; } | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | 			void UpdateActor(); | 
					
						
							|  |  |  |  | 			void UpdateFromActor(); | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  | 		protected: | 
					
						
							| 
									
										
										
										
											2019-10-22 16:49:34 +08:00
										 |  |  |  | 			bool ignore_rotation_; | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  |  | 			Actor* actor_; | 
					
						
							|  |  |  |  | 			World* world_; | 
					
						
							|  |  |  |  | 			b2Body* body_; | 
					
						
							|  |  |  |  | 		}; | 
					
						
							|  |  |  |  | 	} | 
					
						
							|  |  |  |  | } |