Ejemplo n.º 1
0
int w_FrictionJoint_setMaxTorque(lua_State *L)
{
	FrictionJoint *t = luax_checkfrictionjoint(L, 1);
	float arg1 = (float)luaL_checknumber(L, 2);
	luax_catchexcept(L, [&](){ t->setMaxTorque(arg1); });
	return 0;
}
Ejemplo n.º 2
0
FrictionJoint *luax_checkfrictionjoint(lua_State *L, int idx)
{
	FrictionJoint *j = luax_checktype<FrictionJoint>(L, idx, PHYSICS_FRICTION_JOINT_ID);
	if (!j->isValid())
		luaL_error(L, "Attempt to use destroyed joint.");
	return j;
}
Ejemplo n.º 3
0
int w_FrictionJoint_setMaxForce(lua_State *L)
{
	FrictionJoint *t = luax_checkfrictionjoint(L, 1);
	float arg1 = (float)luaL_checknumber(L, 2);
	t->setMaxForce(arg1);
	return 0;
}
Ejemplo n.º 4
0
int w_FrictionJoint_setMaxTorque(lua_State *L)
{
	FrictionJoint *t = luax_checkfrictionjoint(L, 1);
	float arg1 = (float)luaL_checknumber(L, 2);
	EXCEPT_GUARD(t->setMaxTorque(arg1);)
	return 0;
Ejemplo n.º 5
0
int w_FrictionJoint_getMaxForce(lua_State *L)
{
	FrictionJoint *t = luax_checkfrictionjoint(L, 1);
	lua_pushnumber(L, t->getMaxForce());
	return 1;
}
Ejemplo n.º 6
0
bool SelectJointOP::OnMouseDrag(int x, int y)
{
	if (SelectBodyOP::OnMouseDrag(x, y)) 
		return true;

	if (m_selected)
	{
		sm::vec2 pos = m_stage->TransPosScrToProj(x, y);
		switch (m_selected->m_type)
		{
		case Joint::e_revoluteJoint:
			{
				RevoluteJoint* joint = static_cast<RevoluteJoint*>(m_selected);
				const float disA = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorA()),
					disB = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorB());
				if (disA < disB)
					joint->SetLocalAnchorA(pos);
				else
					joint->SetLocalAnchorB(pos);
			}
			break;
		case Joint::e_prismaticJoint:
			{
				PrismaticJoint* joint = static_cast<PrismaticJoint*>(m_selected);
				const float disA = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorA()),
					disB = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorB());
				if (disA < disB)
					joint->SetLocalAnchorA(pos);
				else
					joint->SetLocalAnchorB(pos);
			}
			break;
		case Joint::e_distanceJoint:
			{
				DistanceJoint* joint = static_cast<DistanceJoint*>(m_selected);
				const float disA = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorA()),
					disB = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorB());
				if (disA < disB)
					joint->SetLocalAnchorA(pos);
				else
					joint->SetLocalAnchorB(pos);
			}
			break;
		case Joint::e_pulleyJoint:
			{
				PulleyJoint* joint = static_cast<PulleyJoint*>(m_selected);
				const float disA = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorA()),
					disB = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorB());
				const float disGA = sm::dis_pos_to_pos(pos, joint->m_ground_anchor_a),
					disGB = sm::dis_pos_to_pos(pos, joint->m_ground_anchor_b);

				float dis = std::min(std::min(disA, disB), std::min(disGA, disGB));
				if (dis == disA)
					joint->SetLocalAnchorA(pos);
				else if (dis == disB)
					joint->SetLocalAnchorB(pos);
				else if (dis == disGA)
					joint->m_ground_anchor_a = pos;
				else
					joint->m_ground_anchor_b = pos;					
			}
			break;
		case Joint::e_gearJoint:
			{
			}
			break;
		case Joint::e_wheelJoint:
			{
				WheelJoint* joint = static_cast<WheelJoint*>(m_selected);
				const float disA = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorA()),
					disB = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorB());
				if (disA < disB)
					joint->SetLocalAnchorA(pos);
				else
					joint->SetLocalAnchorB(pos);
			}
			break;
		case Joint::e_weldJoint:
			{
				WeldJoint* joint = static_cast<WeldJoint*>(m_selected);
				const float disA = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorA()),
					disB = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorB());
				if (disA < disB)
					joint->SetLocalAnchorA(pos);
				else
					joint->SetLocalAnchorB(pos);
			}
			break;
		case Joint::e_frictionJoint:
			{
				FrictionJoint* joint = static_cast<FrictionJoint*>(m_selected);
				const float disA = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorA()),
					disB = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorB());
				if (disA < disB)
					joint->SetLocalAnchorA(pos);
				else
					joint->SetLocalAnchorB(pos);
			}
			break;
		case Joint::e_ropeJoint:
			{
				RopeJoint* joint = static_cast<RopeJoint*>(m_selected);
				const float disA = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorA()),
					disB = sm::dis_pos_to_pos(pos, joint->GetWorldAnchorB());
				if (disA < disB)
					joint->SetLocalAnchorA(pos);
				else
					joint->SetLocalAnchorB(pos);
			}
			break;
		case Joint::e_motorJoint:
			{
			}
			break;
		}

		ee::SetCanvasDirtySJ::Instance()->SetDirty();
	}

	return false;
}