mirror of
https://github.com/love2d/love.git
synced 2026-08-16 16:20:42 +02:00
Add basic EdgeShape (todo: all edge-related functionality) and further integrated the new Joints
--HG-- branch : box2d-update
This commit is contained in:
@@ -44,10 +44,7 @@ namespace box2d
|
||||
{
|
||||
return shape->m_radius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the radius for the circle.
|
||||
**/
|
||||
|
||||
void CircleShape::setRadius(float r)
|
||||
{
|
||||
shape->m_radius = r;
|
||||
|
||||
@@ -0,0 +1,44 @@
|
||||
/**
|
||||
* 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 "EdgeShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
EdgeShape::EdgeShape(b2EdgeShape * e)
|
||||
{
|
||||
shape = e;
|
||||
}
|
||||
|
||||
EdgeShape::~EdgeShape()
|
||||
{
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
@@ -0,0 +1,54 @@
|
||||
/**
|
||||
* 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_EDGE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_EDGE_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* An Edge is just a line segment. Edges are designed to
|
||||
* be connected and/or chained together.
|
||||
**/
|
||||
class EdgeShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new EdgeShape from a Box2D edge shape.
|
||||
* @param e The edge shape.
|
||||
**/
|
||||
EdgeShape(b2EdgeShape * e);
|
||||
|
||||
virtual ~EdgeShape();
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_EDGE_SHAPE_H
|
||||
@@ -62,30 +62,27 @@ namespace box2d
|
||||
return new Body(world, b2Vec2(0, 0), 1, 1);
|
||||
}
|
||||
|
||||
CircleShape * Physics::newCircleShape(Body * body, float radius)
|
||||
CircleShape * Physics::newCircleShape(float radius)
|
||||
{
|
||||
return newCircleShape(body, 0, 0, radius);
|
||||
return newCircleShape(0, 0, radius);
|
||||
}
|
||||
|
||||
CircleShape * Physics::newCircleShape(Body * body, float x, float y, float radius)
|
||||
CircleShape * Physics::newCircleShape(float x, float y, float radius)
|
||||
{
|
||||
b2CircleDef def;
|
||||
def.density = 1.0f;
|
||||
def.localPosition.Set(x, y);
|
||||
def.friction = 0.5f;
|
||||
def.restitution = 0.1f;
|
||||
def.radius = radius;
|
||||
return new CircleShape(body, &def);
|
||||
b2CircleShape s;
|
||||
s.m_p = b2Vec2(x, y);
|
||||
s.m_radius = radius;
|
||||
return new CircleShape(&s);
|
||||
}
|
||||
|
||||
PolygonShape * Physics::newRectangleShape(float w, float h)
|
||||
{
|
||||
return newRectangleShape(body, 0, 0, w, h, 0);
|
||||
return newRectangleShape(0, 0, w, h, 0);
|
||||
}
|
||||
|
||||
PolygonShape * Physics::newRectangleShape(float x, float y, float w, float h)
|
||||
{
|
||||
return newRectangleShape(body, x, y, w, h, 0);
|
||||
return newRectangleShape(x, y, w, h, 0);
|
||||
}
|
||||
|
||||
PolygonShape * Physics::newRectangleShape(float x, float y, float w, float h, float angle)
|
||||
@@ -95,11 +92,11 @@ namespace box2d
|
||||
return new PolygonShape(&s);
|
||||
}
|
||||
|
||||
PolygonShape * Physics::newEdgeShape(float x1, float y1, float x2, float y2)
|
||||
EdgeShape * Physics::newEdgeShape(float x1, float y1, float x2, float y2)
|
||||
{
|
||||
b2PolygonShape s;
|
||||
s.SetAsEdge(b2vec2(x1, y1), b2vec2(x2, y2));
|
||||
return new PolygonShape(&s);
|
||||
b2EdgeShape s;
|
||||
s.Set(b2Vec2(x1, y1), b2Vec2(x2, y2));
|
||||
return new EdgeShape(&s);
|
||||
}
|
||||
|
||||
int Physics::newPolygonShape(lua_State * L)
|
||||
@@ -181,6 +178,16 @@ namespace box2d
|
||||
{
|
||||
return new FrictionJoint(body1, body2, x, y);
|
||||
}
|
||||
|
||||
WeldJoint * Physics::newWeldJoint(Body * body1, Body * body2, float x, float y)
|
||||
{
|
||||
return new WeldJoint(body1, body2, x, y);
|
||||
}
|
||||
|
||||
WheelJoint * Physics::newWheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay)
|
||||
{
|
||||
return new WheelJoint(body1, body2, x, y, ax, ay);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
|
||||
@@ -29,6 +29,7 @@
|
||||
#include "Shape.h"
|
||||
#include "CircleShape.h"
|
||||
#include "PolygonShape.h"
|
||||
#include "EdgeShape.h"
|
||||
#include "Joint.h"
|
||||
#include "MouseJoint.h"
|
||||
#include "DistanceJoint.h"
|
||||
@@ -37,6 +38,8 @@
|
||||
#include "PulleyJoint.h"
|
||||
#include "GearJoint.h"
|
||||
#include "FrictionJoint.h"
|
||||
#include "WeldJoint.h"
|
||||
#include "WheelJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -89,15 +92,13 @@ namespace box2d
|
||||
Body * newBody(World * world);
|
||||
|
||||
/**
|
||||
* Creates a new CircleShape at the Body origin.
|
||||
* @param body The Body to create the Shape on.
|
||||
* Creates a new CircleShape at (0, 0).
|
||||
* @param radius The radius of the circle.
|
||||
**/
|
||||
CircleShape * newCircleShape(float radius);
|
||||
|
||||
/**
|
||||
* Creates a new CircleShape at (x,y) in local coorinates.
|
||||
* @param body The Body to create the Shape on.
|
||||
* Creates a new CircleShape at (x,y) in local coordinates.
|
||||
* @param x The offset along the x-axis.
|
||||
* @param y The offset along the y-axis.
|
||||
* @param radius The radius of the circle.
|
||||
@@ -134,19 +135,17 @@ namespace box2d
|
||||
PolygonShape * newRectangleShape(float x, float y, float w, float h, float angle);
|
||||
|
||||
/**
|
||||
* Shorthand for creating edge PolygonShapes. The edge
|
||||
* will be created at (x,y) in local coordinates.
|
||||
* @param x The offset along the x-axis.
|
||||
* @param y The offset along the y-axis.
|
||||
* @param w The width of the rectangle.
|
||||
* @param h The height of the rectangle.
|
||||
* @param angle The angle of the rectangle. (rad)
|
||||
**/
|
||||
PolygonShape * newEdgeShape(float x1, float y1, float x2, float y2);
|
||||
* Creates a new EdgeShape. The edge will be created from
|
||||
* (x1,y1) to (x2,y2) in local coordinates.
|
||||
* @param x1 The x coordinate of the first point.
|
||||
* @param y1 The y coordinate of the first point.
|
||||
* @param x2 The x coordinate of the second point.
|
||||
* @param y2 The y coordinate of the second point.
|
||||
**/
|
||||
EdgeShape * newEdgeShape(float x1, float y1, float x2, float y2);
|
||||
|
||||
/**
|
||||
* Creates a new PolygonShape.
|
||||
* @param body The body to create this shape on.
|
||||
* @param ... A variable number of vertices.
|
||||
**/
|
||||
int newPolygonShape(lua_State * L);
|
||||
@@ -207,6 +206,22 @@ namespace box2d
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
**/
|
||||
FrictionJoint * newFrictionJoint(Body * body1, Body * body2, float x, float y);
|
||||
|
||||
/**
|
||||
* Creates a new WeldJoint connecting body1 with body2.
|
||||
* @param x Anchor along the x-axis. (World coordinates)
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
**/
|
||||
WeldJoint * newWeldJoint(Body * body1, Body * body2, float x, float y);
|
||||
|
||||
/**
|
||||
* Creates a new WheelJoint connecting body1 with body2.
|
||||
* @param x Anchor along the x-axis. (World coordinates)
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
* @param ax The x-component of the world-axis.
|
||||
* @param ay The y-component of the world-axis.
|
||||
**/
|
||||
WheelJoint * newWheelJoint(Body * body1, Body * body2, float x, float y, float ax, float ay);
|
||||
|
||||
|
||||
}; // Physics
|
||||
|
||||
@@ -51,6 +51,10 @@ namespace box2d
|
||||
return SHAPE_CIRCLE;
|
||||
case b2Shape::e_polygon:
|
||||
return SHAPE_POLYGON;
|
||||
case b2Shape::e_edge:
|
||||
return SHAPE_EDGE;
|
||||
case b2Shape::e_chain:
|
||||
return SHAPE_CHAIN;
|
||||
default:
|
||||
return SHAPE_INVALID;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
/**
|
||||
* 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_EdgeShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
EdgeShape * luax_checkedgeshape(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<EdgeShape>(L, idx, "EdgeShape", PHYSICS_EDGE_SHAPE_T);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "destroy", w_Shape_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_edgeshape(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "EdgeShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
@@ -0,0 +1,42 @@
|
||||
/**
|
||||
* 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_EDGE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_EDGE_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Shape.h"
|
||||
#include "EdgeShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
EdgeShape * luax_checkedgeshape(lua_State * L, int idx);
|
||||
int luaopen_edgeshape(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_EDGE_SHAPE_H
|
||||
@@ -118,8 +118,8 @@ namespace box2d
|
||||
float y1 = (float)luaL_checknumber(L, 2);
|
||||
float x2 = (float)luaL_checknumber(L, 3);
|
||||
float y2 = (float)luaL_checknumber(L, 4);
|
||||
PolygonShape * shape = instance->newEdgeShape(x1, y1, x2, y2);
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void*)shape);
|
||||
EdgeShape * shape = instance->newEdgeShape(x1, y1, x2, y2);
|
||||
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, (void*)shape);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -215,6 +215,30 @@ namespace box2d
|
||||
luax_newtype(L, "FrictionJoint", PHYSICS_FRICTION_JOINT_T, (void*)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newWeldJoint(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 x = (float)luaL_checknumber(L, 3);
|
||||
float y = (float)luaL_checknumber(L, 4);
|
||||
WeldJoint * j = instance->newWeldJoint(body1, body2, x, y);
|
||||
luax_newtype(L, "WeldJoint", PHYSICS_WELD_JOINT_T, (void*)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_newWheelJoint(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 x = (float)luaL_checknumber(L, 3);
|
||||
float y = (float)luaL_checknumber(L, 4);
|
||||
float ax = (float)luaL_checknumber(L, 5);
|
||||
float ay = (float)luaL_checknumber(L, 6);
|
||||
WheelJoint * j = instance->newWheelJoint(body1, body2, x, y, ax, ay);
|
||||
luax_newtype(L, "WheelJoint", PHYSICS_WHEEL_JOINT_T, (void*)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
// List of functions to wrap.
|
||||
static const luaL_Reg functions[] = {
|
||||
@@ -223,6 +247,7 @@ namespace box2d
|
||||
{ "newCircleShape", w_newCircleShape },
|
||||
{ "newRectangleShape", w_newRectangleShape },
|
||||
{ "newPolygonShape", w_newPolygonShape },
|
||||
{ "newEdgeShape", w_newEdgeShape },
|
||||
{ "newDistanceJoint", w_newDistanceJoint },
|
||||
{ "newMouseJoint", w_newMouseJoint },
|
||||
{ "newRevoluteJoint", w_newRevoluteJoint },
|
||||
@@ -230,6 +255,8 @@ namespace box2d
|
||||
{ "newPulleyJoint", w_newPulleyJoint },
|
||||
{ "newGearJoint", w_newGearJoint },
|
||||
{ "newFrictionJoint", w_newFrictionJoint },
|
||||
{ "newWeldJoint", w_newWeldJoint },
|
||||
{ "newWheelJoint", w_newWheelJoint },
|
||||
{ 0, 0 },
|
||||
};
|
||||
|
||||
@@ -240,6 +267,7 @@ namespace box2d
|
||||
luaopen_shape,
|
||||
luaopen_circleshape,
|
||||
luaopen_polygonshape,
|
||||
luaopen_edgeshape,
|
||||
luaopen_joint,
|
||||
luaopen_mousejoint,
|
||||
luaopen_distancejoint,
|
||||
@@ -248,6 +276,7 @@ namespace box2d
|
||||
luaopen_pulleyjoint,
|
||||
luaopen_gearjoint,
|
||||
luaopen_frictionjoint,
|
||||
luaopen_weldjoint,
|
||||
0
|
||||
};
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
#include "wrap_Shape.h"
|
||||
#include "wrap_CircleShape.h"
|
||||
#include "wrap_PolygonShape.h"
|
||||
#include "wrap_EdgeShape.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "wrap_MouseJoint.h"
|
||||
#include "wrap_DistanceJoint.h"
|
||||
@@ -38,6 +39,8 @@
|
||||
#include "wrap_PulleyJoint.h"
|
||||
#include "wrap_GearJoint.h"
|
||||
#include "wrap_FrictionJoint.h"
|
||||
#include "wrap_WeldJoint.h"
|
||||
#include "wrap_WheelJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -49,8 +52,8 @@ namespace box2d
|
||||
int w_newBody(lua_State * L);
|
||||
int w_newCircleShape(lua_State * L);
|
||||
int w_newRectangleShape(lua_State * L);
|
||||
int w_newEdgeShape(lua_State * L);
|
||||
int w_newPolygonShape(lua_State * L);
|
||||
int w_newEdgeShape(lua_State * L);
|
||||
int w_newDistanceJoint(lua_State * L);
|
||||
int w_newMouseJoint(lua_State * L);
|
||||
int w_newRevoluteJoint(lua_State * L);
|
||||
@@ -58,6 +61,8 @@ namespace box2d
|
||||
int w_newPulleyJoint(lua_State * L);
|
||||
int w_newGearJoint(lua_State * L);
|
||||
int w_newFrictionJoint(lua_State * L);
|
||||
int w_newWeldJoint(lua_State * L);
|
||||
int w_newWheelJoint(lua_State * L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_physics(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#include "wrap_PrismaticJoint.h"
|
||||
#include "wrap_WheelJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -26,148 +26,122 @@ namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PrismaticJoint * luax_checkprismaticjoint(lua_State * L, int idx)
|
||||
WheelJoint * luax_checkwheeljoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<PrismaticJoint>(L, idx, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T);
|
||||
return luax_checktype<WheelJoint>(L, idx, "WheelJoint", PHYSICS_WHEEL_JOINT_T);
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getJointTranslation(lua_State * L)
|
||||
int w_WheelJoint_getJointTranslation(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointTranslation());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getJointSpeed(lua_State * L)
|
||||
int w_WheelJoint_getJointSpeed(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_enableMotor(lua_State * L)
|
||||
int w_WheelJoint_enableMotor(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_isMotorEnabled(lua_State * L)
|
||||
int w_WheelJoint_isMotorEnabled(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setMaxMotorForce(lua_State * L)
|
||||
int w_WheelJoint_setMotorSpeed(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxMotorForce(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setMotorSpeed(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMotorSpeed(lua_State * L)
|
||||
int w_WheelJoint_getMotorSpeed(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMotorForce(lua_State * L)
|
||||
|
||||
int w_WheelJoint_setMaxMotorTorque(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorForce());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_enableLimit(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_isLimitEnabled(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
luax_pushboolean(L, t->isLimitEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setUpperLimit(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setUpperLimit(arg1);
|
||||
t->setMaxMotorTorque(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setLowerLimit(lua_State * L)
|
||||
|
||||
int w_WheelJoint_getMaxMotorTorque(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLowerLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setLimits(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setLimits(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getLowerLimit(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getLowerLimit());
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getUpperLimit(lua_State * L)
|
||||
|
||||
int w_WheelJoint_getMotorTorque(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getUpperLimit());
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getMotorTorque(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getLimits(lua_State * L)
|
||||
|
||||
int w_WheelJoint_setSpringFrequencyHz(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getLimits(L);
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpringFrequencyHz(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getSpringFrequencyHz(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getSpringFrequencyHz());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setSpringDampingRatio(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setSpringDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getSpringDampingRatio(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getSpringDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getJointTranslation", w_PrismaticJoint_getJointTranslation },
|
||||
{ "getJointSpeed", w_PrismaticJoint_getJointSpeed },
|
||||
{ "enableMotor", w_PrismaticJoint_enableMotor },
|
||||
{ "isMotorEnabled", w_PrismaticJoint_isMotorEnabled },
|
||||
{ "setMaxMotorForce", w_PrismaticJoint_setMaxMotorForce },
|
||||
{ "setMotorSpeed", w_PrismaticJoint_setMotorSpeed },
|
||||
{ "getMotorSpeed", w_PrismaticJoint_getMotorSpeed },
|
||||
{ "getMotorForce", w_PrismaticJoint_getMotorForce },
|
||||
{ "enableLimit", w_PrismaticJoint_enableLimit },
|
||||
{ "isLimitEnabled", w_PrismaticJoint_isLimitEnabled },
|
||||
{ "setUpperLimit", w_PrismaticJoint_setUpperLimit },
|
||||
{ "setLowerLimit", w_PrismaticJoint_setLowerLimit },
|
||||
{ "setLimits", w_PrismaticJoint_setLimits },
|
||||
{ "getLowerLimit", w_PrismaticJoint_getLowerLimit },
|
||||
{ "getUpperLimit", w_PrismaticJoint_getUpperLimit },
|
||||
{ "getLimits", w_PrismaticJoint_getLimits },
|
||||
{ "getJointTranslation", w_WheelJoint_getJointTranslation },
|
||||
{ "getJointSpeed", w_WheelJoint_getJointSpeed },
|
||||
{ "enableMotor", w_WheelJoint_enableMotor },
|
||||
{ "isMotorEnabled", w_WheelJoint_isMotorEnabled },
|
||||
{ "setMotorSpeed", w_WheelJoint_setMotorSpeed },
|
||||
{ "getMotorSpeed", w_WheelJoint_getMotorSpeed },
|
||||
{ "setMaxMotorTorque", w_WheelJoint_setMaxMotorTorque },
|
||||
{ "getMaxMotorTorque", w_WheelJoint_getMaxMotorTorque },
|
||||
{ "getMotorTorque", w_WheelJoint_getMotorTorque },
|
||||
{ "setSpringFrequencyHz", w_WheelJoint_setSpringFrequencyHz },
|
||||
{ "getSpringFrequencyHz", w_WheelJoint_getSpringFrequencyHz },
|
||||
{ "setSpringDampingRatio", w_WheelJoint_setSpringDampingRatio },
|
||||
{ "getSpringDampingRatio", w_WheelJoint_getSpringDampingRatio },
|
||||
// From Joint.
|
||||
{ "getType", w_Joint_getType },
|
||||
{ "getAnchors", w_Joint_getAnchors },
|
||||
@@ -178,9 +152,9 @@ namespace box2d
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_prismaticjoint(lua_State * L)
|
||||
int luaopen_wheeljoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "PrismaticJoint", functions);
|
||||
return luax_register_type(L, "WheelJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
|
||||
@@ -18,13 +18,13 @@
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "PrismaticJoint.h"
|
||||
#include "WheelJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
@@ -32,27 +32,24 @@ namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PrismaticJoint * luax_checkprismaticjoint(lua_State * L, int idx);
|
||||
int w_PrismaticJoint_getJointTranslation(lua_State * L);
|
||||
int w_PrismaticJoint_getJointSpeed(lua_State * L);
|
||||
int w_PrismaticJoint_enableMotor(lua_State * L);
|
||||
int w_PrismaticJoint_isMotorEnabled(lua_State * L);
|
||||
int w_PrismaticJoint_setMaxMotorForce(lua_State * L);
|
||||
int w_PrismaticJoint_setMotorSpeed(lua_State * L);
|
||||
int w_PrismaticJoint_getMotorSpeed(lua_State * L);
|
||||
int w_PrismaticJoint_getMotorForce(lua_State * L);
|
||||
int w_PrismaticJoint_enableLimit(lua_State * L);
|
||||
int w_PrismaticJoint_isLimitEnabled(lua_State * L);
|
||||
int w_PrismaticJoint_setUpperLimit(lua_State * L);
|
||||
int w_PrismaticJoint_setLowerLimit(lua_State * L);
|
||||
int w_PrismaticJoint_setLimits(lua_State * L);
|
||||
int w_PrismaticJoint_getLowerLimit(lua_State * L);
|
||||
int w_PrismaticJoint_getUpperLimit(lua_State * L);
|
||||
int w_PrismaticJoint_getLimits(lua_State * L);
|
||||
int luaopen_prismaticjoint(lua_State * L);
|
||||
WheelJoint * luax_checkwheeljoint(lua_State * L, int idx);
|
||||
int w_WheelJoint_getJointTranslation(lua_State * L);
|
||||
int w_WheelJoint_getJointSpeed(lua_State * L);
|
||||
int w_WheelJoint_enableMotor(lua_State * L);
|
||||
int w_WheelJoint_isMotorEnabled(lua_State * L);
|
||||
int w_WheelJoint_setMotorSpeed(lua_State * L);
|
||||
int w_WheelJoint_getMotorSpeed(lua_State * L);
|
||||
int w_WheelJoint_setMaxMotorTorque(lua_State * L);
|
||||
int w_WheelJoint_getMaxMotorTorque(lua_State * L);
|
||||
int w_WheelJoint_getMotorTorque(lua_State * L);
|
||||
int w_WheelJoint_setSpringFrequencyHz(lua_State * L);
|
||||
int w_WheelJoint_getSpringFrequencyHz(lua_State * L);
|
||||
int w_WheelJoint_setSpringDampingRatio(lua_State * L);
|
||||
int w_WheelJoint_getSpringDampingRatio(lua_State * L);
|
||||
int luaopen_wheeljoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
|
||||
|
||||
Reference in New Issue
Block a user