| 
									
										
										
										
											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.
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <kiwano-physics/Joint.h>
 | 
					
						
							|  |  |  | #include <kiwano-physics/World.h>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | namespace kiwano | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	namespace physics | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-10-22 16:49:34 +08:00
										 |  |  | 		//
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		// Joint
 | 
					
						
							| 
									
										
										
										
											2019-10-22 16:49:34 +08:00
										 |  |  | 		//
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		Joint::Joint() | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 			: joint_(nullptr) | 
					
						
							|  |  |  | 			, world_(nullptr) | 
					
						
							|  |  |  | 			, type_(Type::Unknown) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		Joint::Joint(b2Joint* joint) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			SetB2Joint(joint); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		Joint::Joint(World* world, b2JointDef* joint_def) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			Init(world, joint_def); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		Joint::~Joint() | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			if (world_) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 				world_->RemoveJoint(this); | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		void Joint::Init(World* world, b2JointDef* joint_def) | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			world_ = world; | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 			if (world_) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 				world_->AddJoint(this); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 				b2Joint* joint = world_->GetB2World()->CreateJoint(joint_def); | 
					
						
							|  |  |  | 				SetB2Joint(joint); | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		BodyPtr Joint::GetBodyA() const | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(joint_); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2Body* body = joint_->GetBodyA(); | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			return BodyPtr(static_cast<Body*>(body->GetUserData())); | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		BodyPtr Joint::GetBodyB() const | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(joint_); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2Body* body = joint_->GetBodyB(); | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			return BodyPtr(static_cast<Body*>(body->GetUserData())); | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		void Joint::SetB2Joint(b2Joint* joint) | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			joint_ = joint; | 
					
						
							|  |  |  | 			if (joint_) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 				type_ = Joint::Type(joint_->GetType()); | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-23 16:49:34 +08:00
										 |  |  | 		//
 | 
					
						
							|  |  |  | 		// DistanceJoint
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		DistanceJoint::DistanceJoint() | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-23 16:49:34 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		DistanceJoint::DistanceJoint(World* world, b2DistanceJointDef* def) | 
					
						
							|  |  |  | 			: Joint(world, def) | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-23 16:49:34 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		DistanceJoint::DistanceJoint(World* world, DistanceJoint::Param const& param) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-23 16:49:34 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(param.body_a && param.body_b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2DistanceJointDef def; | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.anchor_a), world->Stage2World(param.anchor_b)); | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			def.frequencyHz = param.frequency_hz; | 
					
						
							|  |  |  | 			def.dampingRatio = param.damping_ratio; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			Init(world, &def); | 
					
						
							|  |  |  | 			raw_joint_ = static_cast<b2DistanceJoint*>(GetB2Joint()); | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		void DistanceJoint::SetLength(float length) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			raw_joint_->SetLength(world_->Stage2World(length)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float DistanceJoint::GetLength() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetLength()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// FrictionJoint
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		FrictionJoint::FrictionJoint() | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		FrictionJoint::FrictionJoint(World* world, b2FrictionJointDef* def) | 
					
						
							|  |  |  | 			: Joint(world, def) | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		FrictionJoint::FrictionJoint(World* world, FrictionJoint::Param const& param) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(param.body_a && param.body_b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2FrictionJointDef def; | 
					
						
							|  |  |  | 			def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.anchor)); | 
					
						
							|  |  |  | 			def.maxForce = param.max_force; | 
					
						
							|  |  |  | 			def.maxTorque = world->Stage2World(param.max_torque); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			Init(world, &def); | 
					
						
							|  |  |  | 			raw_joint_ = static_cast<b2FrictionJoint*>(GetB2Joint()); | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		void FrictionJoint::SetMaxForce(float length) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_); | 
					
						
							|  |  |  | 			raw_joint_->SetMaxForce(length); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float FrictionJoint::GetMaxForce() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_); | 
					
						
							|  |  |  | 			return raw_joint_->GetMaxForce(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		void FrictionJoint::SetMaxTorque(float length) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			raw_joint_->SetMaxTorque(world_->Stage2World(length)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float FrictionJoint::GetMaxTorque() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetMaxTorque()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// GearJoint
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		GearJoint::GearJoint() | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		GearJoint::GearJoint(World* world, b2GearJointDef* def) | 
					
						
							|  |  |  | 			: Joint(world, def) | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		GearJoint::GearJoint(World* world, GearJoint::Param const& param) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(param.joint_a && param.joint_b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2GearJointDef def; | 
					
						
							|  |  |  | 			def.joint1 = param.joint_a->GetB2Joint(); | 
					
						
							|  |  |  | 			def.joint2 = param.joint_b->GetB2Joint(); | 
					
						
							|  |  |  | 			def.ratio = param.ratio; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			Init(world, &def); | 
					
						
							|  |  |  | 			raw_joint_ = static_cast<b2GearJoint*>(GetB2Joint()); | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		void GearJoint::SetRatio(float ratio) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_); | 
					
						
							|  |  |  | 			raw_joint_->SetRatio(ratio); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float GearJoint::GetRatio() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_); | 
					
						
							|  |  |  | 			return raw_joint_->GetRatio(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// MotorJoint
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		MotorJoint::MotorJoint() | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		MotorJoint::MotorJoint(World* world, b2MotorJointDef* def) | 
					
						
							|  |  |  | 			: Joint(world, def) | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		MotorJoint::MotorJoint(World* world, MotorJoint::Param const& param) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(param.body_a && param.body_b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2MotorJointDef def; | 
					
						
							|  |  |  | 			def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body()); | 
					
						
							|  |  |  | 			def.maxForce = param.max_force; | 
					
						
							|  |  |  | 			def.maxTorque = world->Stage2World(param.max_torque); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			Init(world, &def); | 
					
						
							|  |  |  | 			raw_joint_ = static_cast<b2MotorJoint*>(GetB2Joint()); | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		void MotorJoint::SetMaxForce(float length) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_); | 
					
						
							|  |  |  | 			raw_joint_->SetMaxForce(length); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float MotorJoint::GetMaxForce() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_); | 
					
						
							|  |  |  | 			return raw_joint_->GetMaxForce(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		void MotorJoint::SetMaxTorque(float length) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			raw_joint_->SetMaxTorque(world_->Stage2World(length)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float MotorJoint::GetMaxTorque() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetMaxTorque()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		//
 | 
					
						
							|  |  |  | 		// PrismaticJoint
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		PrismaticJoint::PrismaticJoint() | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		PrismaticJoint::PrismaticJoint(World* world, b2PrismaticJointDef* def) | 
					
						
							|  |  |  | 			: Joint(world, def) | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		PrismaticJoint::PrismaticJoint(World* world, PrismaticJoint::Param const& param) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(param.body_a && param.body_b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2PrismaticJointDef def; | 
					
						
							|  |  |  | 			def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.anchor), Stage2World(param.axis)); | 
					
						
							|  |  |  | 			def.enableLimit = param.enable_limit; | 
					
						
							|  |  |  | 			def.lowerTranslation = world->Stage2World(param.lower_translation); | 
					
						
							|  |  |  | 			def.upperTranslation = world->Stage2World(param.upper_translation); | 
					
						
							|  |  |  | 			def.enableMotor = param.enable_motor; | 
					
						
							|  |  |  | 			def.maxMotorForce = param.max_motor_force; | 
					
						
							|  |  |  | 			def.motorSpeed = world->Stage2World(param.motor_speed); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			Init(world, &def); | 
					
						
							|  |  |  | 			raw_joint_ = static_cast<b2PrismaticJoint*>(GetB2Joint()); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float PrismaticJoint::GetJointTranslation() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetJointTranslation()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float PrismaticJoint::GetJointSpeed() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetJointSpeed()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float PrismaticJoint::GetLowerLimit() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetLowerLimit()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float PrismaticJoint::GetUpperLimit() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetUpperLimit()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		void PrismaticJoint::SetLimits(float lower, float upper) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			raw_joint_->SetLimits(world_->Stage2World(lower), world_->Stage2World(upper)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// PulleyJoint
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		PulleyJoint::PulleyJoint() | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		PulleyJoint::PulleyJoint(World* world, b2PulleyJointDef* def) | 
					
						
							|  |  |  | 			: Joint(world, def) | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		PulleyJoint::PulleyJoint(World* world, PulleyJoint::Param const& param) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(param.body_a && param.body_b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2PulleyJointDef def; | 
					
						
							|  |  |  | 			def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.ground_anchor_a), world->Stage2World(param.ground_anchor_b), | 
					
						
							|  |  |  | 				world->Stage2World(param.anchor_a), world->Stage2World(param.anchor_b), param.ratio); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			Init(world, &def); | 
					
						
							|  |  |  | 			raw_joint_ = static_cast<b2PulleyJoint*>(GetB2Joint()); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Point PulleyJoint::GetGroundAnchorA() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetGroundAnchorA()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		Point PulleyJoint::GetGroundAnchorB() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetGroundAnchorB()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float PulleyJoint::GetRatio() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_); | 
					
						
							|  |  |  | 			return raw_joint_->GetRatio(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float PulleyJoint::GetLengthA() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetLengthA()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float PulleyJoint::GetLengthB() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetLengthB()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float PulleyJoint::GetCurrentLengthA() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetCurrentLengthA()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float PulleyJoint::GetCurrentLengthB() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetCurrentLengthB()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// RevoluteJoint
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		RevoluteJoint::RevoluteJoint() | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		RevoluteJoint::RevoluteJoint(World* world, b2RevoluteJointDef* def) | 
					
						
							|  |  |  | 			: Joint(world, def) | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		RevoluteJoint::RevoluteJoint(World* world, RevoluteJoint::Param const& param) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(param.body_a && param.body_b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2RevoluteJointDef def; | 
					
						
							|  |  |  | 			def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.anchor)); | 
					
						
							|  |  |  | 			def.enableLimit = param.enable_limit; | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			def.lowerAngle = math::Degree2Radian(param.lower_angle); | 
					
						
							|  |  |  | 			def.upperAngle = math::Degree2Radian(param.upper_angle); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			def.enableMotor = param.enable_motor; | 
					
						
							|  |  |  | 			def.maxMotorTorque = world->Stage2World(param.max_motor_torque); | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			def.motorSpeed = math::Degree2Radian(param.motor_speed); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			Init(world, &def); | 
					
						
							|  |  |  | 			raw_joint_ = static_cast<b2RevoluteJoint*>(GetB2Joint()); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float RevoluteJoint::GetJointAngle() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			return math::Radian2Degree(raw_joint_->GetJointAngle()); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float RevoluteJoint::GetJointSpeed() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			return math::Radian2Degree(raw_joint_->GetJointSpeed()); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float RevoluteJoint::GetLowerLimit() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			return math::Radian2Degree(raw_joint_->GetLowerLimit()); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float RevoluteJoint::GetUpperLimit() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			return math::Radian2Degree(raw_joint_->GetUpperLimit()); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		void RevoluteJoint::SetLimits(float lower, float upper) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			raw_joint_->SetLimits(math::Degree2Radian(lower), math::Degree2Radian(upper)); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		void RevoluteJoint::SetMaxMotorTorque(float torque) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			raw_joint_->SetMaxMotorTorque(world_->Stage2World(torque)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float RevoluteJoint::GetMaxMotorTorque() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetMaxMotorTorque()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// RopeJoint
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		RopeJoint::RopeJoint() | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		RopeJoint::RopeJoint(World* world, b2RopeJointDef* def) | 
					
						
							|  |  |  | 			: Joint(world, def) | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		RopeJoint::RopeJoint(World* world, RopeJoint::Param const& param) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(param.body_a && param.body_b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2RopeJointDef def; | 
					
						
							|  |  |  | 			def.bodyA = param.body_a->GetB2Body(); | 
					
						
							|  |  |  | 			def.bodyB = param.body_b->GetB2Body(); | 
					
						
							|  |  |  | 			def.localAnchorA = world->Stage2World(param.local_anchor_a); | 
					
						
							|  |  |  | 			def.localAnchorB = world->Stage2World(param.local_anchor_b); | 
					
						
							|  |  |  | 			def.maxLength = world->Stage2World(param.max_length); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			Init(world, &def); | 
					
						
							|  |  |  | 			raw_joint_ = static_cast<b2RopeJoint*>(GetB2Joint()); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		void RopeJoint::SetMaxLength(float length) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			raw_joint_->SetMaxLength(world_->Stage2World(length)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float RopeJoint::GetMaxLength() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetMaxLength()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// WeldJoint
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		WeldJoint::WeldJoint() | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		WeldJoint::WeldJoint(World* world, b2WeldJointDef* def) | 
					
						
							|  |  |  | 			: Joint(world, def) | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		WeldJoint::WeldJoint(World* world, WeldJoint::Param const& param) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(param.body_a && param.body_b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2WeldJointDef def; | 
					
						
							|  |  |  | 			def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.anchor)); | 
					
						
							|  |  |  | 			def.frequencyHz = param.frequency_hz; | 
					
						
							|  |  |  | 			def.dampingRatio = param.damping_ratio; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			Init(world, &def); | 
					
						
							|  |  |  | 			raw_joint_ = static_cast<b2WeldJoint*>(GetB2Joint()); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 		//
 | 
					
						
							|  |  |  | 		// WheelJoint
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		WheelJoint::WheelJoint() | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		WheelJoint::WheelJoint(World* world, b2WheelJointDef* def) | 
					
						
							|  |  |  | 			: Joint(world, def) | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		WheelJoint::WheelJoint(World* world, WheelJoint::Param const& param) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(param.body_a && param.body_b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2WheelJointDef def; | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			def.Initialize(param.body_a->GetB2Body(), param.body_b->GetB2Body(), world->Stage2World(param.anchor), Stage2World(param.axis)); | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			def.enableMotor = param.enable_motor; | 
					
						
							|  |  |  | 			def.maxMotorTorque = world->Stage2World(param.max_motor_torque); | 
					
						
							|  |  |  | 			def.motorSpeed = world->Stage2World(param.motor_speed); | 
					
						
							|  |  |  | 			def.frequencyHz = param.frequency_hz; | 
					
						
							|  |  |  | 			def.dampingRatio = param.damping_ratio; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			Init(world, &def); | 
					
						
							|  |  |  | 			raw_joint_ = static_cast<b2WheelJoint*>(GetB2Joint()); | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float WheelJoint::GetJointTranslation() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetJointTranslation()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float WheelJoint::GetJointLinearSpeed() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetJointLinearSpeed()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		void WheelJoint::SetMaxMotorTorque(float torque) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			raw_joint_->SetMaxMotorTorque(world_->Stage2World(torque)); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float WheelJoint::GetMaxMotorTorque() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_ && world_); | 
					
						
							|  |  |  | 			return world_->World2Stage(raw_joint_->GetMaxMotorTorque()); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 		// MouseJoint
 | 
					
						
							|  |  |  | 		//
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		MouseJoint::MouseJoint() | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		MouseJoint::MouseJoint(World* world, b2MouseJointDef* def) | 
					
						
							|  |  |  | 			: Joint(world, def) | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-11-06 16:29:36 +08:00
										 |  |  | 		MouseJoint::MouseJoint(World* world, MouseJoint::Param const& param) | 
					
						
							|  |  |  | 			: Joint() | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			, raw_joint_(nullptr) | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(param.body_a && param.body_b); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			b2MouseJointDef def; | 
					
						
							| 
									
										
										
										
											2019-10-23 16:49:34 +08:00
										 |  |  | 			def.bodyA = param.body_a->GetB2Body(); | 
					
						
							|  |  |  | 			def.bodyB = param.body_b->GetB2Body(); | 
					
						
							| 
									
										
										
										
											2019-10-29 18:01:31 +08:00
										 |  |  | 			def.target = world->Stage2World(param.target); | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 			def.maxForce = param.max_force; | 
					
						
							|  |  |  | 			def.frequencyHz = param.frequency_hz; | 
					
						
							|  |  |  | 			def.dampingRatio = param.damping_ratio; | 
					
						
							| 
									
										
										
										
											2019-10-23 16:49:34 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-30 23:12:18 +08:00
										 |  |  | 			Init(world, &def); | 
					
						
							|  |  |  | 			raw_joint_ = static_cast<b2MouseJoint*>(GetB2Joint()); | 
					
						
							| 
									
										
										
										
											2019-10-23 16:49:34 +08:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2019-10-28 17:25:06 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		void MouseJoint::SetMaxForce(float length) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_); | 
					
						
							|  |  |  | 			raw_joint_->SetMaxForce(length); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		float MouseJoint::GetMaxForce() const | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			KGE_ASSERT(raw_joint_); | 
					
						
							|  |  |  | 			return raw_joint_->GetMaxForce(); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-10-23 16:49:34 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2019-10-18 11:50:46 +08:00
										 |  |  | } |