mirror of
https://github.com/love2d/love.git
synced 2026-08-16 00:02:12 +02:00
Added RopeJoint
--HG-- branch : box2d-update
This commit is contained in:
@@ -188,6 +188,11 @@ namespace box2d
|
||||
{
|
||||
return new WheelJoint(body1, body2, x, y, ax, ay);
|
||||
}
|
||||
|
||||
RopeJoint * Physics::newRopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength)
|
||||
{
|
||||
return new RopeJoint(body1, body2, x1, y1, x2, y2, maxLength);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
|
||||
@@ -40,6 +40,7 @@
|
||||
#include "FrictionJoint.h"
|
||||
#include "WeldJoint.h"
|
||||
#include "WheelJoint.h"
|
||||
#include "RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -222,6 +223,16 @@ namespace box2d
|
||||
* @param ay The y-component of the world-axis.
|
||||
**/
|
||||
WheelJoint * newWheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay);
|
||||
|
||||
/**
|
||||
* Creates a new RopeJoint connecting body1 with body2.
|
||||
* @param x1 Anchor1 along the x-axis. (Local coordinates)
|
||||
* @param y1 Anchor1 along the y-axis. (Local coordinates)
|
||||
* @param x2 Anchor2 along the x-axis. (Local coordinates)
|
||||
* @param y2 Anchor2 along the y-axis. (Local coordinates)
|
||||
* @param maxLength The maximum distance for the bodies.
|
||||
**/
|
||||
RopeJoint * newRopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength);
|
||||
|
||||
|
||||
}; // Physics
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "RopeJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
RopeJoint::RopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
b2RopeJointDef def;
|
||||
def.bodyA = body1->body;
|
||||
def.bodyB = body2->body;
|
||||
def.localAnchorA = world->scaleDown(b2Vec2(x1,y1));
|
||||
def.localAnchorB = world->scaleDown(b2Vec2(x2,y2));
|
||||
def.maxLength = world->scaleDown(maxLength);
|
||||
joint = (b2RopeJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
RopeJoint::~RopeJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
float RopeJoint::getMaxLength() const
|
||||
{
|
||||
return world->scaleUp(joint->GetMaxLength());
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
@@ -0,0 +1,62 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_ROPE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_ROPE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* The RopeJoint enforces a maximum distance between two points
|
||||
* on two bodies. It has no other effect.
|
||||
**/
|
||||
class RopeJoint : public Joint
|
||||
{
|
||||
private:
|
||||
// The Box2D RopeJoint object.
|
||||
b2RopeJoint * joint;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a RopeJoint connecting body1 to body2.
|
||||
**/
|
||||
RopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength);
|
||||
|
||||
virtual ~RopeJoint();
|
||||
|
||||
/**
|
||||
* Gets the maximum length of the rope.
|
||||
**/
|
||||
float getMaxLength() const;
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_ROPE_JOINT_H
|
||||
@@ -239,6 +239,20 @@ namespace box2d
|
||||
luax_newtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, (void*)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newRopeJoint(lua_State * L)
|
||||
{
|
||||
Body * body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
Body * body2 = luax_checktype<Body>(L, 2, "Body", PHYSICS_BODY_T);
|
||||
float x1 = (float)luaL_checknumber(L, 3);
|
||||
float y1 = (float)luaL_checknumber(L, 4);
|
||||
float x2 = (float)luaL_checknumber(L, 5);
|
||||
float y2 = (float)luaL_checknumber(L, 6);
|
||||
float maxLength = (float)luaL_checknumber(L, 7);
|
||||
RopeJoint * j = instance->newRopeJoint(body1, body2, x1, y1, x2, y2, maxLength);
|
||||
luax_newtype(L, "RopeJoint", PHYSICS_ROPE_JOINT_T, (void*)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg functions[] = {
|
||||
@@ -257,6 +271,7 @@ namespace box2d
|
||||
{ "newFrictionJoint", w_newFrictionJoint },
|
||||
{ "newWeldJoint", w_newWeldJoint },
|
||||
{ "newWheelJoint", w_newWheelJoint },
|
||||
{ "newRopeJoint", w_newRopeJoint },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
@@ -277,6 +292,8 @@ namespace box2d
|
||||
luaopen_gearjoint,
|
||||
luaopen_frictionjoint,
|
||||
luaopen_weldjoint,
|
||||
luaopen_wheeljoint,
|
||||
luaopen_ropejoint,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
@@ -41,6 +41,7 @@
|
||||
#include "wrap_FrictionJoint.h"
|
||||
#include "wrap_WeldJoint.h"
|
||||
#include "wrap_WheelJoint.h"
|
||||
#include "wrap_RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -63,6 +64,7 @@ namespace box2d
|
||||
int w_newFrictionJoint(lua_State * L);
|
||||
int w_newWeldJoint(lua_State * L);
|
||||
int w_newWheelJoint(lua_State * L);
|
||||
int w_newRopeJoint(lua_State * L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_physics(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
RopeJoint * luax_checkropejoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<RopeJoint>(L, idx, "RopeJoint", PHYSICS_ROPE_JOINT_T);
|
||||
}
|
||||
|
||||
int w_RopeJoint_getMaxLength(lua_State * L)
|
||||
{
|
||||
RopeJoint * t = luax_checkropejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxLength());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getMaxLength", w_RopeJoint_getMaxLength },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_ropejoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "RopeJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2006-2011 LOVE Development Team
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
*
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
*
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_ROPE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_ROPE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
RopeJoint * luax_checkropejoint(lua_State * L, int idx);
|
||||
int w_RopeJoint_getMaxLength(lua_State * L);
|
||||
int luaopen_ropejoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_ROPE_JOINT_H
|
||||
Reference in New Issue
Block a user