mirror of
https://github.com/love2d/love.git
synced 2026-08-16 08:11:02 +02:00
Automated formatting fix
This commit is contained in:
+439
-439
@@ -1,439 +1,439 @@
|
||||
/**
|
||||
* 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 "Body.h"
|
||||
|
||||
#include <common/math.h>
|
||||
#include <common/Memoizer.h>
|
||||
|
||||
#include "Shape.h"
|
||||
#include "Fixture.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Body::Body(World * world, b2Vec2 p, Body::Type type)
|
||||
: world(world)
|
||||
{
|
||||
world->retain();
|
||||
b2BodyDef def;
|
||||
def.position = Physics::scaleDown(p);
|
||||
body = world->world->CreateBody(&def);
|
||||
this->setType(type);
|
||||
Memoizer::add(body, this);
|
||||
}
|
||||
|
||||
Body::Body(b2Body * b)
|
||||
: body(b)
|
||||
{
|
||||
world = (World *)Memoizer::find(b->GetWorld());
|
||||
world->retain();
|
||||
Memoizer::add(body, this);
|
||||
}
|
||||
|
||||
Body::~Body()
|
||||
{
|
||||
Memoizer::remove(body);
|
||||
world->world->DestroyBody(body);
|
||||
world->release();
|
||||
body = 0;
|
||||
}
|
||||
|
||||
float Body::getX()
|
||||
{
|
||||
return Physics::scaleUp(body->GetPosition().x);
|
||||
}
|
||||
|
||||
float Body::getY()
|
||||
{
|
||||
return Physics::scaleUp(body->GetPosition().y);
|
||||
}
|
||||
|
||||
void Body::getPosition(float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetPosition());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLinearVelocity(float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocity());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
float Body::getAngle()
|
||||
{
|
||||
return body->GetAngle();
|
||||
}
|
||||
|
||||
void Body::getWorldCenter(float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetWorldCenter());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLocalCenter(float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLocalCenter());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
float Body::getAngularVelocity() const
|
||||
{
|
||||
return body->GetAngularVelocity();
|
||||
}
|
||||
|
||||
float Body::getMass() const
|
||||
{
|
||||
return body->GetMass();
|
||||
}
|
||||
|
||||
float Body::getInertia() const
|
||||
{
|
||||
return body->GetInertia();
|
||||
}
|
||||
|
||||
int Body::getMassData(lua_State * L)
|
||||
{
|
||||
b2MassData data;
|
||||
body->GetMassData(&data);
|
||||
b2Vec2 center = Physics::scaleUp(data.center);
|
||||
lua_pushnumber(L, center.x);
|
||||
lua_pushnumber(L, center.y);
|
||||
lua_pushnumber(L, data.mass);
|
||||
lua_pushnumber(L, data.I);
|
||||
return 4;
|
||||
}
|
||||
|
||||
float Body::getAngularDamping() const
|
||||
{
|
||||
return body->GetAngularDamping();
|
||||
}
|
||||
|
||||
float Body::getLinearDamping() const
|
||||
{
|
||||
return body->GetLinearDamping();
|
||||
}
|
||||
|
||||
float Body::getGravityScale() const
|
||||
{
|
||||
return body->GetGravityScale();
|
||||
}
|
||||
|
||||
Body::Type Body::getType() const
|
||||
{
|
||||
switch (body->GetType()) {
|
||||
case b2_staticBody:
|
||||
return BODY_STATIC;
|
||||
break;
|
||||
case b2_dynamicBody:
|
||||
return BODY_DYNAMIC;
|
||||
break;
|
||||
case b2_kinematicBody:
|
||||
return BODY_KINEMATIC;
|
||||
break;
|
||||
default:
|
||||
return BODY_INVALID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Body::applyLinearImpulse(float jx, float jy)
|
||||
{
|
||||
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), body->GetWorldCenter());
|
||||
}
|
||||
|
||||
void Body::applyLinearImpulse(float jx, float jy, float rx, float ry)
|
||||
{
|
||||
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), Physics::scaleDown(b2Vec2(rx, ry)));
|
||||
}
|
||||
|
||||
void Body::applyAngularImpulse(float impulse)
|
||||
{
|
||||
// Angular impulse is in kg*m^2/s, meaning it needs to be scaled twice
|
||||
body->ApplyAngularImpulse(Physics::scaleDown(Physics::scaleDown(impulse)));
|
||||
}
|
||||
|
||||
void Body::applyTorque(float t)
|
||||
{
|
||||
// Torque is in N*m, or kg*m^2/s^2, meaning it also needs to be scaled twice
|
||||
body->ApplyTorque(Physics::scaleDown(Physics::scaleDown(t)));
|
||||
}
|
||||
|
||||
void Body::applyForce(float fx, float fy, float rx, float ry)
|
||||
{
|
||||
body->ApplyForce(Physics::scaleDown(b2Vec2(fx, fy)), Physics::scaleDown(b2Vec2(rx, ry)));
|
||||
}
|
||||
|
||||
void Body::applyForce(float fx, float fy)
|
||||
{
|
||||
body->ApplyForce(Physics::scaleDown(b2Vec2(fx, fy)), body->GetWorldCenter());
|
||||
}
|
||||
|
||||
void Body::setX(float x)
|
||||
{
|
||||
body->SetTransform(Physics::scaleDown(b2Vec2(x, getY())), getAngle());
|
||||
}
|
||||
|
||||
void Body::setY(float y)
|
||||
{
|
||||
body->SetTransform(Physics::scaleDown(b2Vec2(getX(), y)), getAngle());
|
||||
}
|
||||
|
||||
void Body::setLinearVelocity(float x, float y)
|
||||
{
|
||||
body->SetLinearVelocity(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
void Body::setAngle(float d)
|
||||
{
|
||||
body->SetTransform(body->GetPosition(), d);
|
||||
}
|
||||
|
||||
void Body::setAngularVelocity(float r)
|
||||
{
|
||||
body->SetAngularVelocity(r);
|
||||
}
|
||||
|
||||
void Body::setPosition(float x, float y)
|
||||
{
|
||||
body->SetTransform(Physics::scaleDown(b2Vec2(x, y)), body->GetAngle());
|
||||
}
|
||||
|
||||
void Body::setAngularDamping(float d)
|
||||
{
|
||||
body->SetAngularDamping(d);
|
||||
}
|
||||
|
||||
void Body::setLinearDamping(float d)
|
||||
{
|
||||
body->SetLinearDamping(d);
|
||||
}
|
||||
|
||||
void Body::resetMassData()
|
||||
{
|
||||
body->ResetMassData();
|
||||
}
|
||||
|
||||
void Body::setMassData(float x, float y, float m, float i)
|
||||
{
|
||||
b2MassData massData;
|
||||
massData.center = Physics::scaleDown(b2Vec2(x, y));
|
||||
massData.mass = m;
|
||||
massData.I = i;
|
||||
body->SetMassData(&massData);
|
||||
}
|
||||
|
||||
void Body::setInertia(float i)
|
||||
{
|
||||
b2MassData massData;
|
||||
massData.center = body->GetLocalCenter();
|
||||
massData.mass = body->GetMass();
|
||||
massData.I = i;
|
||||
body->SetMassData(&massData);
|
||||
}
|
||||
|
||||
void Body::setGravityScale(float scale)
|
||||
{
|
||||
body->SetGravityScale(scale);
|
||||
}
|
||||
|
||||
void Body::setType(Body::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case Body::BODY_STATIC:
|
||||
body->SetType(b2_staticBody);
|
||||
break;
|
||||
case Body::BODY_DYNAMIC:
|
||||
body->SetType(b2_dynamicBody);
|
||||
break;
|
||||
case Body::BODY_KINEMATIC:
|
||||
body->SetType(b2_kinematicBody);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Body::getWorldPoint(float x, float y, float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getWorldVector(float x, float y, float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetWorldVector(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
int Body::getWorldPoints(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
int vcount = (int)argc/2;
|
||||
// at least one point
|
||||
love::luax_assert_argc(L, 2);
|
||||
|
||||
for(int i = 0;i<vcount;i++)
|
||||
{
|
||||
float x = (float)lua_tonumber(L, i*2+1);
|
||||
float y = (float)lua_tonumber(L, i*2+2);
|
||||
b2Vec2 point = Physics::scaleUp(body->GetWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
lua_pushnumber(L, point.x);
|
||||
lua_pushnumber(L, point.y);
|
||||
}
|
||||
|
||||
return argc;
|
||||
}
|
||||
|
||||
void Body::getLocalPoint(float x, float y, float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLocalPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLocalVector(float x, float y, float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLocalVector(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLinearVelocityFromWorldPoint(float x, float y, float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocityFromWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLinearVelocityFromLocalPoint(float x, float y, float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocityFromLocalPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
bool Body::isBullet() const
|
||||
{
|
||||
return body->IsBullet();
|
||||
}
|
||||
|
||||
void Body::setBullet(bool bullet)
|
||||
{
|
||||
return body->SetBullet(bullet);
|
||||
}
|
||||
|
||||
bool Body::isActive() const
|
||||
{
|
||||
return body->IsActive();
|
||||
}
|
||||
|
||||
bool Body::isAwake() const
|
||||
{
|
||||
return body->IsAwake();
|
||||
}
|
||||
|
||||
void Body::setSleepingAllowed(bool allow)
|
||||
{
|
||||
body->SetSleepingAllowed(allow);
|
||||
}
|
||||
|
||||
bool Body::isSleepingAllowed() const
|
||||
{
|
||||
return body->IsSleepingAllowed();
|
||||
}
|
||||
|
||||
void Body::setActive(bool active)
|
||||
{
|
||||
body->SetActive(active);
|
||||
}
|
||||
|
||||
void Body::setAwake(bool awake)
|
||||
{
|
||||
body->SetAwake(awake);
|
||||
}
|
||||
|
||||
void Body::setFixedRotation(bool fixed)
|
||||
{
|
||||
body->SetFixedRotation(fixed);
|
||||
}
|
||||
|
||||
bool Body::isFixedRotation() const
|
||||
{
|
||||
return body->IsFixedRotation();
|
||||
}
|
||||
|
||||
World * Body::getWorld() const
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
int Body::getFixtureList(lua_State * L) const
|
||||
{
|
||||
lua_newtable(L);
|
||||
b2Fixture * f = body->GetFixtureList();
|
||||
int i = 1;
|
||||
do {
|
||||
if (!f) break;
|
||||
Fixture * fixture = (Fixture *)Memoizer::find(f);
|
||||
if (!fixture) throw love::Exception("A fixture has escaped Memoizer!");
|
||||
fixture->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)fixture);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
} while ((f = f->GetNext()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
b2Vec2 Body::getVector(lua_State * L)
|
||||
{
|
||||
love::luax_assert_argc(L, 2, 2);
|
||||
b2Vec2 v((float)lua_tonumber(L, 1), (float)lua_tonumber(L, 2));
|
||||
lua_pop(L, 2);
|
||||
return v;
|
||||
}
|
||||
|
||||
int Body::pushVector(lua_State * L, const b2Vec2 & v)
|
||||
{
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
void Body::destroy()
|
||||
{
|
||||
world->destroyBody(this);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "Body.h"
|
||||
|
||||
#include <common/math.h>
|
||||
#include <common/Memoizer.h>
|
||||
|
||||
#include "Shape.h"
|
||||
#include "Fixture.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Body::Body(World * world, b2Vec2 p, Body::Type type)
|
||||
: world(world)
|
||||
{
|
||||
world->retain();
|
||||
b2BodyDef def;
|
||||
def.position = Physics::scaleDown(p);
|
||||
body = world->world->CreateBody(&def);
|
||||
this->setType(type);
|
||||
Memoizer::add(body, this);
|
||||
}
|
||||
|
||||
Body::Body(b2Body * b)
|
||||
: body(b)
|
||||
{
|
||||
world = (World *)Memoizer::find(b->GetWorld());
|
||||
world->retain();
|
||||
Memoizer::add(body, this);
|
||||
}
|
||||
|
||||
Body::~Body()
|
||||
{
|
||||
Memoizer::remove(body);
|
||||
world->world->DestroyBody(body);
|
||||
world->release();
|
||||
body = 0;
|
||||
}
|
||||
|
||||
float Body::getX()
|
||||
{
|
||||
return Physics::scaleUp(body->GetPosition().x);
|
||||
}
|
||||
|
||||
float Body::getY()
|
||||
{
|
||||
return Physics::scaleUp(body->GetPosition().y);
|
||||
}
|
||||
|
||||
void Body::getPosition(float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetPosition());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLinearVelocity(float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocity());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
float Body::getAngle()
|
||||
{
|
||||
return body->GetAngle();
|
||||
}
|
||||
|
||||
void Body::getWorldCenter(float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetWorldCenter());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLocalCenter(float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLocalCenter());
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
float Body::getAngularVelocity() const
|
||||
{
|
||||
return body->GetAngularVelocity();
|
||||
}
|
||||
|
||||
float Body::getMass() const
|
||||
{
|
||||
return body->GetMass();
|
||||
}
|
||||
|
||||
float Body::getInertia() const
|
||||
{
|
||||
return body->GetInertia();
|
||||
}
|
||||
|
||||
int Body::getMassData(lua_State * L)
|
||||
{
|
||||
b2MassData data;
|
||||
body->GetMassData(&data);
|
||||
b2Vec2 center = Physics::scaleUp(data.center);
|
||||
lua_pushnumber(L, center.x);
|
||||
lua_pushnumber(L, center.y);
|
||||
lua_pushnumber(L, data.mass);
|
||||
lua_pushnumber(L, data.I);
|
||||
return 4;
|
||||
}
|
||||
|
||||
float Body::getAngularDamping() const
|
||||
{
|
||||
return body->GetAngularDamping();
|
||||
}
|
||||
|
||||
float Body::getLinearDamping() const
|
||||
{
|
||||
return body->GetLinearDamping();
|
||||
}
|
||||
|
||||
float Body::getGravityScale() const
|
||||
{
|
||||
return body->GetGravityScale();
|
||||
}
|
||||
|
||||
Body::Type Body::getType() const
|
||||
{
|
||||
switch (body->GetType()) {
|
||||
case b2_staticBody:
|
||||
return BODY_STATIC;
|
||||
break;
|
||||
case b2_dynamicBody:
|
||||
return BODY_DYNAMIC;
|
||||
break;
|
||||
case b2_kinematicBody:
|
||||
return BODY_KINEMATIC;
|
||||
break;
|
||||
default:
|
||||
return BODY_INVALID;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Body::applyLinearImpulse(float jx, float jy)
|
||||
{
|
||||
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), body->GetWorldCenter());
|
||||
}
|
||||
|
||||
void Body::applyLinearImpulse(float jx, float jy, float rx, float ry)
|
||||
{
|
||||
body->ApplyLinearImpulse(Physics::scaleDown(b2Vec2(jx, jy)), Physics::scaleDown(b2Vec2(rx, ry)));
|
||||
}
|
||||
|
||||
void Body::applyAngularImpulse(float impulse)
|
||||
{
|
||||
// Angular impulse is in kg*m^2/s, meaning it needs to be scaled twice
|
||||
body->ApplyAngularImpulse(Physics::scaleDown(Physics::scaleDown(impulse)));
|
||||
}
|
||||
|
||||
void Body::applyTorque(float t)
|
||||
{
|
||||
// Torque is in N*m, or kg*m^2/s^2, meaning it also needs to be scaled twice
|
||||
body->ApplyTorque(Physics::scaleDown(Physics::scaleDown(t)));
|
||||
}
|
||||
|
||||
void Body::applyForce(float fx, float fy, float rx, float ry)
|
||||
{
|
||||
body->ApplyForce(Physics::scaleDown(b2Vec2(fx, fy)), Physics::scaleDown(b2Vec2(rx, ry)));
|
||||
}
|
||||
|
||||
void Body::applyForce(float fx, float fy)
|
||||
{
|
||||
body->ApplyForce(Physics::scaleDown(b2Vec2(fx, fy)), body->GetWorldCenter());
|
||||
}
|
||||
|
||||
void Body::setX(float x)
|
||||
{
|
||||
body->SetTransform(Physics::scaleDown(b2Vec2(x, getY())), getAngle());
|
||||
}
|
||||
|
||||
void Body::setY(float y)
|
||||
{
|
||||
body->SetTransform(Physics::scaleDown(b2Vec2(getX(), y)), getAngle());
|
||||
}
|
||||
|
||||
void Body::setLinearVelocity(float x, float y)
|
||||
{
|
||||
body->SetLinearVelocity(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
void Body::setAngle(float d)
|
||||
{
|
||||
body->SetTransform(body->GetPosition(), d);
|
||||
}
|
||||
|
||||
void Body::setAngularVelocity(float r)
|
||||
{
|
||||
body->SetAngularVelocity(r);
|
||||
}
|
||||
|
||||
void Body::setPosition(float x, float y)
|
||||
{
|
||||
body->SetTransform(Physics::scaleDown(b2Vec2(x, y)), body->GetAngle());
|
||||
}
|
||||
|
||||
void Body::setAngularDamping(float d)
|
||||
{
|
||||
body->SetAngularDamping(d);
|
||||
}
|
||||
|
||||
void Body::setLinearDamping(float d)
|
||||
{
|
||||
body->SetLinearDamping(d);
|
||||
}
|
||||
|
||||
void Body::resetMassData()
|
||||
{
|
||||
body->ResetMassData();
|
||||
}
|
||||
|
||||
void Body::setMassData(float x, float y, float m, float i)
|
||||
{
|
||||
b2MassData massData;
|
||||
massData.center = Physics::scaleDown(b2Vec2(x, y));
|
||||
massData.mass = m;
|
||||
massData.I = i;
|
||||
body->SetMassData(&massData);
|
||||
}
|
||||
|
||||
void Body::setInertia(float i)
|
||||
{
|
||||
b2MassData massData;
|
||||
massData.center = body->GetLocalCenter();
|
||||
massData.mass = body->GetMass();
|
||||
massData.I = i;
|
||||
body->SetMassData(&massData);
|
||||
}
|
||||
|
||||
void Body::setGravityScale(float scale)
|
||||
{
|
||||
body->SetGravityScale(scale);
|
||||
}
|
||||
|
||||
void Body::setType(Body::Type type)
|
||||
{
|
||||
switch (type) {
|
||||
case Body::BODY_STATIC:
|
||||
body->SetType(b2_staticBody);
|
||||
break;
|
||||
case Body::BODY_DYNAMIC:
|
||||
body->SetType(b2_dynamicBody);
|
||||
break;
|
||||
case Body::BODY_KINEMATIC:
|
||||
body->SetType(b2_kinematicBody);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Body::getWorldPoint(float x, float y, float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getWorldVector(float x, float y, float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetWorldVector(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
int Body::getWorldPoints(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
int vcount = (int)argc/2;
|
||||
// at least one point
|
||||
love::luax_assert_argc(L, 2);
|
||||
|
||||
for (int i = 0;i<vcount;i++)
|
||||
{
|
||||
float x = (float)lua_tonumber(L, i*2+1);
|
||||
float y = (float)lua_tonumber(L, i*2+2);
|
||||
b2Vec2 point = Physics::scaleUp(body->GetWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
lua_pushnumber(L, point.x);
|
||||
lua_pushnumber(L, point.y);
|
||||
}
|
||||
|
||||
return argc;
|
||||
}
|
||||
|
||||
void Body::getLocalPoint(float x, float y, float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLocalPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLocalVector(float x, float y, float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLocalVector(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLinearVelocityFromWorldPoint(float x, float y, float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocityFromWorldPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
void Body::getLinearVelocityFromLocalPoint(float x, float y, float & x_o, float & y_o)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(body->GetLinearVelocityFromLocalPoint(Physics::scaleDown(b2Vec2(x, y))));
|
||||
x_o = v.x;
|
||||
y_o = v.y;
|
||||
}
|
||||
|
||||
bool Body::isBullet() const
|
||||
{
|
||||
return body->IsBullet();
|
||||
}
|
||||
|
||||
void Body::setBullet(bool bullet)
|
||||
{
|
||||
return body->SetBullet(bullet);
|
||||
}
|
||||
|
||||
bool Body::isActive() const
|
||||
{
|
||||
return body->IsActive();
|
||||
}
|
||||
|
||||
bool Body::isAwake() const
|
||||
{
|
||||
return body->IsAwake();
|
||||
}
|
||||
|
||||
void Body::setSleepingAllowed(bool allow)
|
||||
{
|
||||
body->SetSleepingAllowed(allow);
|
||||
}
|
||||
|
||||
bool Body::isSleepingAllowed() const
|
||||
{
|
||||
return body->IsSleepingAllowed();
|
||||
}
|
||||
|
||||
void Body::setActive(bool active)
|
||||
{
|
||||
body->SetActive(active);
|
||||
}
|
||||
|
||||
void Body::setAwake(bool awake)
|
||||
{
|
||||
body->SetAwake(awake);
|
||||
}
|
||||
|
||||
void Body::setFixedRotation(bool fixed)
|
||||
{
|
||||
body->SetFixedRotation(fixed);
|
||||
}
|
||||
|
||||
bool Body::isFixedRotation() const
|
||||
{
|
||||
return body->IsFixedRotation();
|
||||
}
|
||||
|
||||
World * Body::getWorld() const
|
||||
{
|
||||
return world;
|
||||
}
|
||||
|
||||
int Body::getFixtureList(lua_State * L) const
|
||||
{
|
||||
lua_newtable(L);
|
||||
b2Fixture * f = body->GetFixtureList();
|
||||
int i = 1;
|
||||
do {
|
||||
if (!f) break;
|
||||
Fixture * fixture = (Fixture *)Memoizer::find(f);
|
||||
if (!fixture) throw love::Exception("A fixture has escaped Memoizer!");
|
||||
fixture->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)fixture);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
} while ((f = f->GetNext()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
b2Vec2 Body::getVector(lua_State * L)
|
||||
{
|
||||
love::luax_assert_argc(L, 2, 2);
|
||||
b2Vec2 v((float)lua_tonumber(L, 1), (float)lua_tonumber(L, 2));
|
||||
lua_pop(L, 2);
|
||||
return v;
|
||||
}
|
||||
|
||||
int Body::pushVector(lua_State * L, const b2Vec2 & v)
|
||||
{
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
void Body::destroy()
|
||||
{
|
||||
world->destroyBody(this);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+411
-411
@@ -1,411 +1,411 @@
|
||||
/**
|
||||
* 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_BODY_H
|
||||
#define LOVE_PHYSICS_BOX2D_BODY_H
|
||||
|
||||
// LOVE
|
||||
#include <common/math.h>
|
||||
#include <common/runtime.h>
|
||||
#include <common/Object.h>
|
||||
#include <physics/Body.h>
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
// Forward declarations.
|
||||
class World;
|
||||
class Shape;
|
||||
class Fixture;
|
||||
|
||||
/**
|
||||
* A Body is an entity which has position and orientation
|
||||
* in world space. A Body does have collision geometry
|
||||
* by itself, but depend on an arbitrary number of child Shape objects
|
||||
* which together constitute the final geometry for the Body.
|
||||
**/
|
||||
class Body : public love::physics::Body
|
||||
{
|
||||
// Friends.
|
||||
friend class Joint;
|
||||
friend class DistanceJoint;
|
||||
friend class MouseJoint;
|
||||
friend class CircleShape;
|
||||
friend class PolygonShape;
|
||||
friend class Shape;
|
||||
|
||||
private:
|
||||
|
||||
// We need a shared_ptr to the parent World,
|
||||
// because World can not be destroyed as long as
|
||||
// bodies exists in it.
|
||||
//
|
||||
// This ensures that a World only can be destroyed
|
||||
// once all bodies have been destroyed too.
|
||||
World * world;
|
||||
|
||||
public:
|
||||
|
||||
// The Box2D body. (Should not be public?)
|
||||
b2Body * body;
|
||||
|
||||
/**
|
||||
* Create a Body at position p.
|
||||
**/
|
||||
Body(World * world, b2Vec2 p, Type type);
|
||||
|
||||
/**
|
||||
* Create a Body from an extant b2Body.
|
||||
**/
|
||||
Body(b2Body * b);
|
||||
|
||||
virtual ~Body();
|
||||
|
||||
/**
|
||||
* Gets the current x-position of the Body.
|
||||
**/
|
||||
float getX();
|
||||
|
||||
/**
|
||||
* Gets the current y-position of the Body.
|
||||
**/
|
||||
float getY();
|
||||
|
||||
/**
|
||||
* Gets the current angle (deg) of the Body.
|
||||
**/
|
||||
float getAngle();
|
||||
|
||||
/**
|
||||
* Gets the current position of the Body.
|
||||
* @returns The current position.
|
||||
**/
|
||||
void getPosition(float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Gets the velocity in the current center of mass.
|
||||
* @returns The velocity in the current center of mass.
|
||||
**/
|
||||
void getLinearVelocity(float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* The current center of mass for the Body in world
|
||||
* coordinates.
|
||||
* @returns The x-component of the point.
|
||||
* @returns The y-component of the point.
|
||||
**/
|
||||
void getWorldCenter(float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* The current center of mass for the Body in local
|
||||
* coordinates.
|
||||
* @returns The x-component of the point.
|
||||
* @returns The y-component of the point.
|
||||
**/
|
||||
void getLocalCenter(float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Get the current Body spin. (Angular velocity).
|
||||
**/
|
||||
float getAngularVelocity() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's mass.
|
||||
**/
|
||||
float getMass() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's intertia.
|
||||
**/
|
||||
float getInertia() const;
|
||||
|
||||
/**
|
||||
* Gets mass properties.
|
||||
**/
|
||||
int getMassData(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the Body's angular damping.
|
||||
**/
|
||||
float getAngularDamping() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's linear damping.
|
||||
**/
|
||||
float getLinearDamping() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's gravity scale.
|
||||
**/
|
||||
float getGravityScale() const;
|
||||
|
||||
/**
|
||||
* Gets the type of body this is.
|
||||
**/
|
||||
Type getType() const;
|
||||
|
||||
/**
|
||||
* Apply an impulse (jx, jy) with offset (0, 0).
|
||||
**/
|
||||
void applyLinearImpulse(float jx, float jy);
|
||||
|
||||
/**
|
||||
* Apply an impulse (jx, jy) with offset (rx, ry).
|
||||
**/
|
||||
void applyLinearImpulse(float jx, float jy, float rx, float ry);
|
||||
|
||||
/**
|
||||
* Apply an angular impulse to the body.
|
||||
**/
|
||||
void applyAngularImpulse(float impulse);
|
||||
|
||||
/**
|
||||
* Apply torque (t).
|
||||
**/
|
||||
void applyTorque(float t);
|
||||
|
||||
/**
|
||||
* Apply force (fx, fy) with offset (0, 0).
|
||||
**/
|
||||
void applyForce(float fx, float fy);
|
||||
|
||||
/**
|
||||
* Apply force (fx, fy) with offset (rx, ry).
|
||||
**/
|
||||
void applyForce(float fx, float fy, float rx, float ry);
|
||||
|
||||
/**
|
||||
* Sets the x-position of the Body.
|
||||
**/
|
||||
void setX(float x);
|
||||
|
||||
/**
|
||||
* Sets the Y-position of the Body.
|
||||
**/
|
||||
void setY(float y);
|
||||
|
||||
/**
|
||||
* Sets the current velocity of the Body.
|
||||
**/
|
||||
void setLinearVelocity(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the angle of the Body.
|
||||
**/
|
||||
void setAngle(float d);
|
||||
|
||||
/**
|
||||
* Sets the current spin of the Body.
|
||||
**/
|
||||
void setAngularVelocity(float r);
|
||||
|
||||
/**
|
||||
* Sets the current position of the Body.
|
||||
**/
|
||||
void setPosition(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the mass from the currently attatched shapes.
|
||||
**/
|
||||
void resetMassData();
|
||||
|
||||
/**
|
||||
* Sets mass properties.
|
||||
* @param x The x-coordinate for the local center of mass.
|
||||
* @param y The y-coordinate for the local center of mass.
|
||||
* @param m The mass.
|
||||
* @param i The inertia.
|
||||
**/
|
||||
void setMassData(float x, float y, float m, float i);
|
||||
|
||||
/**
|
||||
* Sets the inertia while keeping the other properties
|
||||
* (mass and local center).
|
||||
* @param i The inertia.
|
||||
**/
|
||||
void setInertia(float i);
|
||||
|
||||
/**
|
||||
* Sets the Body's angular damping.
|
||||
**/
|
||||
void setAngularDamping(float d);
|
||||
|
||||
/**
|
||||
* Sets the Body's linear damping.
|
||||
**/
|
||||
void setLinearDamping(float d);
|
||||
|
||||
/**
|
||||
* Sets the Body's gravity scale.
|
||||
**/
|
||||
void setGravityScale(float scale);
|
||||
|
||||
/**
|
||||
* Sets the type of body this is.
|
||||
**/
|
||||
void setType(Type type);
|
||||
|
||||
/**
|
||||
* Transforms a point (x, y) from local coordinates
|
||||
* to world coordinates.
|
||||
* @param x The x-coordinate of the local point.
|
||||
* @param y The y-coordinate of the local point.
|
||||
* @returns The x-coordinate of the point in world coordinates.
|
||||
* @returns The y-coordinate of the point in world coordinates.
|
||||
**/
|
||||
void getWorldPoint(float x, float y, float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Transforms a vector (x, y) from local coordinates
|
||||
* to world coordinates.
|
||||
* @param x The x-coordinate of the local vector.
|
||||
* @param y The y-coordinate of the local vector.
|
||||
* @returns The x-coordinate of the vector in world coordinates.
|
||||
* @returns The y-coordinate of the vector in world coordinates.
|
||||
**/
|
||||
void getWorldVector(float x, float y, float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Transforms a series of points (x, y) from local coordinates
|
||||
* to world coordinates.
|
||||
**/
|
||||
int getWorldPoints(lua_State * L);
|
||||
|
||||
/**
|
||||
* Transforms a point (x, y) from world coordinates
|
||||
* to local coordinates.
|
||||
* @param x The x-coordinate of the world point.
|
||||
* @param y The y-coordinate of the world point.
|
||||
* @returns The x-coordinate of the point in local coordinates.
|
||||
* @returns The y-coordinate of the point in local coordinates.
|
||||
**/
|
||||
void getLocalPoint(float x, float y, float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Transforms a vector (x, y) from world coordinates
|
||||
* to local coordinates.
|
||||
* @param x The x-coordinate of the world vector.
|
||||
* @param y The y-coordinate of the world vector.
|
||||
* @returns The x-coordinate of the vector in local coordinates.
|
||||
* @returns The y-coordinate of the vector in local coordinates.
|
||||
**/
|
||||
void getLocalVector(float x, float y, float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Gets the velocity on the Body for the given world point.
|
||||
* @param x The x-coordinate of the world point.
|
||||
* @param y The y-coordinate of the world point.
|
||||
* @returns The x-component of the velocity vector.
|
||||
* @returns The y-component of the velocity vector.
|
||||
**/
|
||||
void getLinearVelocityFromWorldPoint(float x, float y, float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Gets the velocity on the Body for the given local point.
|
||||
* @param x The x-coordinate of the local point.
|
||||
* @param y The y-coordinate of the local point.
|
||||
* @returns The x-component of the velocity vector.
|
||||
* @returns The y-component of the velocity vector.
|
||||
**/
|
||||
void getLinearVelocityFromLocalPoint(float x, float y, float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Returns true if the Body is a bullet, false otherwise.
|
||||
**/
|
||||
bool isBullet() const;
|
||||
|
||||
/**
|
||||
* Set whether this Body should be treated as a bullet.
|
||||
* Bullets require more processing power than normal shapes.
|
||||
**/
|
||||
void setBullet(bool bullet);
|
||||
|
||||
/**
|
||||
* Checks whether a Body is active or not. An inactive body
|
||||
* cannot be interacted with.
|
||||
**/
|
||||
bool isActive() const;
|
||||
|
||||
/**
|
||||
* Checks whether a Body is awake or not. A Body
|
||||
* will fall to sleep if nothing happens to it for while.
|
||||
**/
|
||||
bool isAwake() const;
|
||||
|
||||
/**
|
||||
* Controls whether this Body should be allowed to sleep.
|
||||
**/
|
||||
void setSleepingAllowed(bool allow);
|
||||
bool isSleepingAllowed() const;
|
||||
|
||||
/**
|
||||
* Changes the body's active state.
|
||||
**/
|
||||
void setActive(bool active);
|
||||
|
||||
/**
|
||||
* Changes the body's sleep state.
|
||||
**/
|
||||
void setAwake(bool awake);
|
||||
|
||||
void setFixedRotation(bool fixed);
|
||||
bool isFixedRotation() const;
|
||||
|
||||
/**
|
||||
* Get the World this Body resides in.
|
||||
*/
|
||||
World * getWorld() const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Fixtures attached to this Body.
|
||||
* @return An array of Fixtures.
|
||||
**/
|
||||
int getFixtureList(lua_State * L) const;
|
||||
|
||||
/**
|
||||
* Mark the body for destruction
|
||||
**/
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Gets a 2d vector from the arguments on the stack.
|
||||
**/
|
||||
b2Vec2 getVector(lua_State * L);
|
||||
|
||||
/**
|
||||
* Pushed the x- and y-components of a vector on
|
||||
* the stack.
|
||||
**/
|
||||
int pushVector(lua_State * L, const b2Vec2 & v);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_BODY_H
|
||||
/**
|
||||
* 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_BODY_H
|
||||
#define LOVE_PHYSICS_BOX2D_BODY_H
|
||||
|
||||
// LOVE
|
||||
#include <common/math.h>
|
||||
#include <common/runtime.h>
|
||||
#include <common/Object.h>
|
||||
#include <physics/Body.h>
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
// Forward declarations.
|
||||
class World;
|
||||
class Shape;
|
||||
class Fixture;
|
||||
|
||||
/**
|
||||
* A Body is an entity which has position and orientation
|
||||
* in world space. A Body does have collision geometry
|
||||
* by itself, but depend on an arbitrary number of child Shape objects
|
||||
* which together constitute the final geometry for the Body.
|
||||
**/
|
||||
class Body : public love::physics::Body
|
||||
{
|
||||
// Friends.
|
||||
friend class Joint;
|
||||
friend class DistanceJoint;
|
||||
friend class MouseJoint;
|
||||
friend class CircleShape;
|
||||
friend class PolygonShape;
|
||||
friend class Shape;
|
||||
|
||||
private:
|
||||
|
||||
// We need a shared_ptr to the parent World,
|
||||
// because World can not be destroyed as long as
|
||||
// bodies exists in it.
|
||||
//
|
||||
// This ensures that a World only can be destroyed
|
||||
// once all bodies have been destroyed too.
|
||||
World * world;
|
||||
|
||||
public:
|
||||
|
||||
// The Box2D body. (Should not be public?)
|
||||
b2Body * body;
|
||||
|
||||
/**
|
||||
* Create a Body at position p.
|
||||
**/
|
||||
Body(World * world, b2Vec2 p, Type type);
|
||||
|
||||
/**
|
||||
* Create a Body from an extant b2Body.
|
||||
**/
|
||||
Body(b2Body * b);
|
||||
|
||||
virtual ~Body();
|
||||
|
||||
/**
|
||||
* Gets the current x-position of the Body.
|
||||
**/
|
||||
float getX();
|
||||
|
||||
/**
|
||||
* Gets the current y-position of the Body.
|
||||
**/
|
||||
float getY();
|
||||
|
||||
/**
|
||||
* Gets the current angle (deg) of the Body.
|
||||
**/
|
||||
float getAngle();
|
||||
|
||||
/**
|
||||
* Gets the current position of the Body.
|
||||
* @returns The current position.
|
||||
**/
|
||||
void getPosition(float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Gets the velocity in the current center of mass.
|
||||
* @returns The velocity in the current center of mass.
|
||||
**/
|
||||
void getLinearVelocity(float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* The current center of mass for the Body in world
|
||||
* coordinates.
|
||||
* @returns The x-component of the point.
|
||||
* @returns The y-component of the point.
|
||||
**/
|
||||
void getWorldCenter(float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* The current center of mass for the Body in local
|
||||
* coordinates.
|
||||
* @returns The x-component of the point.
|
||||
* @returns The y-component of the point.
|
||||
**/
|
||||
void getLocalCenter(float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Get the current Body spin. (Angular velocity).
|
||||
**/
|
||||
float getAngularVelocity() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's mass.
|
||||
**/
|
||||
float getMass() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's intertia.
|
||||
**/
|
||||
float getInertia() const;
|
||||
|
||||
/**
|
||||
* Gets mass properties.
|
||||
**/
|
||||
int getMassData(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the Body's angular damping.
|
||||
**/
|
||||
float getAngularDamping() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's linear damping.
|
||||
**/
|
||||
float getLinearDamping() const;
|
||||
|
||||
/**
|
||||
* Gets the Body's gravity scale.
|
||||
**/
|
||||
float getGravityScale() const;
|
||||
|
||||
/**
|
||||
* Gets the type of body this is.
|
||||
**/
|
||||
Type getType() const;
|
||||
|
||||
/**
|
||||
* Apply an impulse (jx, jy) with offset (0, 0).
|
||||
**/
|
||||
void applyLinearImpulse(float jx, float jy);
|
||||
|
||||
/**
|
||||
* Apply an impulse (jx, jy) with offset (rx, ry).
|
||||
**/
|
||||
void applyLinearImpulse(float jx, float jy, float rx, float ry);
|
||||
|
||||
/**
|
||||
* Apply an angular impulse to the body.
|
||||
**/
|
||||
void applyAngularImpulse(float impulse);
|
||||
|
||||
/**
|
||||
* Apply torque (t).
|
||||
**/
|
||||
void applyTorque(float t);
|
||||
|
||||
/**
|
||||
* Apply force (fx, fy) with offset (0, 0).
|
||||
**/
|
||||
void applyForce(float fx, float fy);
|
||||
|
||||
/**
|
||||
* Apply force (fx, fy) with offset (rx, ry).
|
||||
**/
|
||||
void applyForce(float fx, float fy, float rx, float ry);
|
||||
|
||||
/**
|
||||
* Sets the x-position of the Body.
|
||||
**/
|
||||
void setX(float x);
|
||||
|
||||
/**
|
||||
* Sets the Y-position of the Body.
|
||||
**/
|
||||
void setY(float y);
|
||||
|
||||
/**
|
||||
* Sets the current velocity of the Body.
|
||||
**/
|
||||
void setLinearVelocity(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the angle of the Body.
|
||||
**/
|
||||
void setAngle(float d);
|
||||
|
||||
/**
|
||||
* Sets the current spin of the Body.
|
||||
**/
|
||||
void setAngularVelocity(float r);
|
||||
|
||||
/**
|
||||
* Sets the current position of the Body.
|
||||
**/
|
||||
void setPosition(float x, float y);
|
||||
|
||||
/**
|
||||
* Sets the mass from the currently attatched shapes.
|
||||
**/
|
||||
void resetMassData();
|
||||
|
||||
/**
|
||||
* Sets mass properties.
|
||||
* @param x The x-coordinate for the local center of mass.
|
||||
* @param y The y-coordinate for the local center of mass.
|
||||
* @param m The mass.
|
||||
* @param i The inertia.
|
||||
**/
|
||||
void setMassData(float x, float y, float m, float i);
|
||||
|
||||
/**
|
||||
* Sets the inertia while keeping the other properties
|
||||
* (mass and local center).
|
||||
* @param i The inertia.
|
||||
**/
|
||||
void setInertia(float i);
|
||||
|
||||
/**
|
||||
* Sets the Body's angular damping.
|
||||
**/
|
||||
void setAngularDamping(float d);
|
||||
|
||||
/**
|
||||
* Sets the Body's linear damping.
|
||||
**/
|
||||
void setLinearDamping(float d);
|
||||
|
||||
/**
|
||||
* Sets the Body's gravity scale.
|
||||
**/
|
||||
void setGravityScale(float scale);
|
||||
|
||||
/**
|
||||
* Sets the type of body this is.
|
||||
**/
|
||||
void setType(Type type);
|
||||
|
||||
/**
|
||||
* Transforms a point (x, y) from local coordinates
|
||||
* to world coordinates.
|
||||
* @param x The x-coordinate of the local point.
|
||||
* @param y The y-coordinate of the local point.
|
||||
* @returns The x-coordinate of the point in world coordinates.
|
||||
* @returns The y-coordinate of the point in world coordinates.
|
||||
**/
|
||||
void getWorldPoint(float x, float y, float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Transforms a vector (x, y) from local coordinates
|
||||
* to world coordinates.
|
||||
* @param x The x-coordinate of the local vector.
|
||||
* @param y The y-coordinate of the local vector.
|
||||
* @returns The x-coordinate of the vector in world coordinates.
|
||||
* @returns The y-coordinate of the vector in world coordinates.
|
||||
**/
|
||||
void getWorldVector(float x, float y, float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Transforms a series of points (x, y) from local coordinates
|
||||
* to world coordinates.
|
||||
**/
|
||||
int getWorldPoints(lua_State * L);
|
||||
|
||||
/**
|
||||
* Transforms a point (x, y) from world coordinates
|
||||
* to local coordinates.
|
||||
* @param x The x-coordinate of the world point.
|
||||
* @param y The y-coordinate of the world point.
|
||||
* @returns The x-coordinate of the point in local coordinates.
|
||||
* @returns The y-coordinate of the point in local coordinates.
|
||||
**/
|
||||
void getLocalPoint(float x, float y, float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Transforms a vector (x, y) from world coordinates
|
||||
* to local coordinates.
|
||||
* @param x The x-coordinate of the world vector.
|
||||
* @param y The y-coordinate of the world vector.
|
||||
* @returns The x-coordinate of the vector in local coordinates.
|
||||
* @returns The y-coordinate of the vector in local coordinates.
|
||||
**/
|
||||
void getLocalVector(float x, float y, float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Gets the velocity on the Body for the given world point.
|
||||
* @param x The x-coordinate of the world point.
|
||||
* @param y The y-coordinate of the world point.
|
||||
* @returns The x-component of the velocity vector.
|
||||
* @returns The y-component of the velocity vector.
|
||||
**/
|
||||
void getLinearVelocityFromWorldPoint(float x, float y, float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Gets the velocity on the Body for the given local point.
|
||||
* @param x The x-coordinate of the local point.
|
||||
* @param y The y-coordinate of the local point.
|
||||
* @returns The x-component of the velocity vector.
|
||||
* @returns The y-component of the velocity vector.
|
||||
**/
|
||||
void getLinearVelocityFromLocalPoint(float x, float y, float & x_o, float & y_o);
|
||||
|
||||
/**
|
||||
* Returns true if the Body is a bullet, false otherwise.
|
||||
**/
|
||||
bool isBullet() const;
|
||||
|
||||
/**
|
||||
* Set whether this Body should be treated as a bullet.
|
||||
* Bullets require more processing power than normal shapes.
|
||||
**/
|
||||
void setBullet(bool bullet);
|
||||
|
||||
/**
|
||||
* Checks whether a Body is active or not. An inactive body
|
||||
* cannot be interacted with.
|
||||
**/
|
||||
bool isActive() const;
|
||||
|
||||
/**
|
||||
* Checks whether a Body is awake or not. A Body
|
||||
* will fall to sleep if nothing happens to it for while.
|
||||
**/
|
||||
bool isAwake() const;
|
||||
|
||||
/**
|
||||
* Controls whether this Body should be allowed to sleep.
|
||||
**/
|
||||
void setSleepingAllowed(bool allow);
|
||||
bool isSleepingAllowed() const;
|
||||
|
||||
/**
|
||||
* Changes the body's active state.
|
||||
**/
|
||||
void setActive(bool active);
|
||||
|
||||
/**
|
||||
* Changes the body's sleep state.
|
||||
**/
|
||||
void setAwake(bool awake);
|
||||
|
||||
void setFixedRotation(bool fixed);
|
||||
bool isFixedRotation() const;
|
||||
|
||||
/**
|
||||
* Get the World this Body resides in.
|
||||
*/
|
||||
World * getWorld() const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Fixtures attached to this Body.
|
||||
* @return An array of Fixtures.
|
||||
**/
|
||||
int getFixtureList(lua_State * L) const;
|
||||
|
||||
/**
|
||||
* Mark the body for destruction
|
||||
**/
|
||||
void destroy();
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Gets a 2d vector from the arguments on the stack.
|
||||
**/
|
||||
b2Vec2 getVector(lua_State * L);
|
||||
|
||||
/**
|
||||
* Pushed the x- and y-components of a vector on
|
||||
* the stack.
|
||||
**/
|
||||
int pushVector(lua_State * L, const b2Vec2 & v);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_BODY_H
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -44,10 +44,11 @@ namespace box2d
|
||||
delete shape;
|
||||
shape = NULL;
|
||||
}
|
||||
|
||||
|
||||
void ChainShape::setNextVertex(float x, float y)
|
||||
{
|
||||
if (loop) {
|
||||
if (loop)
|
||||
{
|
||||
throw love::Exception("Physics error: Can't call setNextVertex on a loop ChainShape");
|
||||
return;
|
||||
}
|
||||
@@ -55,10 +56,11 @@ namespace box2d
|
||||
b2ChainShape * c = (b2ChainShape *)shape;
|
||||
c->SetNextVertex(Physics::scaleDown(v));
|
||||
}
|
||||
|
||||
|
||||
void ChainShape::setPrevVertex(float x, float y)
|
||||
{
|
||||
if (loop) {
|
||||
if (loop)
|
||||
{
|
||||
throw love::Exception("Physics error: Can't call setPrevVertex on a loop ChainShape");
|
||||
return;
|
||||
}
|
||||
@@ -66,39 +68,41 @@ namespace box2d
|
||||
b2ChainShape * c = (b2ChainShape *)shape;
|
||||
c->SetNextVertex(Physics::scaleDown(v));
|
||||
}
|
||||
|
||||
|
||||
EdgeShape * ChainShape::getChildEdge(int index) const
|
||||
{
|
||||
b2ChainShape * c = (b2ChainShape *)shape;
|
||||
b2EdgeShape e;
|
||||
c->GetChildEdge(&e, index);
|
||||
EdgeShape * edge = (EdgeShape *)Memoizer::find(&e);
|
||||
if (!edge) return new EdgeShape(&e);
|
||||
else {
|
||||
if (!edge)
|
||||
return new EdgeShape(&e);
|
||||
else
|
||||
{
|
||||
edge->retain();
|
||||
return edge;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ChainShape::getChildCount() const
|
||||
{
|
||||
b2ChainShape * c = (b2ChainShape *)shape;
|
||||
return c->GetChildCount();
|
||||
}
|
||||
|
||||
|
||||
int ChainShape::getVertexCount() const
|
||||
{
|
||||
b2ChainShape * c = (b2ChainShape *)shape;
|
||||
return c->m_count;
|
||||
}
|
||||
|
||||
|
||||
b2Vec2 ChainShape::getPoint(int index) const
|
||||
{
|
||||
b2ChainShape * c = (b2ChainShape *)shape;
|
||||
const b2Vec2 & v = c->m_vertices[index];
|
||||
return Physics::scaleUp(v);
|
||||
}
|
||||
|
||||
|
||||
const b2Vec2 * ChainShape::getPoints() const
|
||||
{
|
||||
b2ChainShape * c = (b2ChainShape *)shape;
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -39,7 +39,7 @@ namespace box2d
|
||||
private:
|
||||
// True if this ChainShape is a loop.
|
||||
bool loop;
|
||||
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
@@ -49,7 +49,7 @@ namespace box2d
|
||||
ChainShape(b2ChainShape * c, bool loop = false);
|
||||
|
||||
virtual ~ChainShape();
|
||||
|
||||
|
||||
/**
|
||||
* Establish connectivity to a vertex that follows
|
||||
* the last vertex. Fails if called on a loop.
|
||||
@@ -57,7 +57,7 @@ namespace box2d
|
||||
* @param y The y-coordinate of the vertex.
|
||||
**/
|
||||
void setNextVertex(float x, float y);
|
||||
|
||||
|
||||
/**
|
||||
* Establish connectivity to a vertex that precedes
|
||||
* the first vertex. Fails if called on a loop.
|
||||
@@ -65,38 +65,38 @@ namespace box2d
|
||||
* @param y The y-coordinate of the vertex.
|
||||
**/
|
||||
void setPrevVertex(float x, float y);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the number of children shapes.
|
||||
**/
|
||||
int getChildCount() const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns a child EdgeShape.
|
||||
* @param index The index of the child shape.
|
||||
* @returns The specified child.
|
||||
**/
|
||||
EdgeShape * getChildEdge(int index) const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the number of vertices in the shape.
|
||||
* @returns The number of vertices in the shape.
|
||||
**/
|
||||
int getVertexCount() const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns the vertex at the given index.
|
||||
* @param index The index of the vertex.
|
||||
* @returns The specified vertex.
|
||||
**/
|
||||
b2Vec2 getPoint(int index) const;
|
||||
|
||||
|
||||
/**
|
||||
* Returns all of the vertices.
|
||||
* @returns The vertices the shape comprises.
|
||||
**/
|
||||
const b2Vec2 * getPoints() const;
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
|
||||
@@ -1,60 +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 "CircleShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include <common/Memoizer.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
CircleShape::CircleShape(b2CircleShape * c)
|
||||
: Shape(c)
|
||||
{
|
||||
}
|
||||
|
||||
CircleShape::~CircleShape()
|
||||
{
|
||||
Memoizer::remove(shape);
|
||||
delete shape;
|
||||
shape = NULL;
|
||||
}
|
||||
|
||||
float CircleShape::getRadius() const
|
||||
{
|
||||
return Physics::scaleUp(shape->m_radius);
|
||||
}
|
||||
|
||||
void CircleShape::setRadius(float r)
|
||||
{
|
||||
shape->m_radius = Physics::scaleDown(r);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "CircleShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include <common/Memoizer.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
CircleShape::CircleShape(b2CircleShape * c)
|
||||
: Shape(c)
|
||||
{
|
||||
}
|
||||
|
||||
CircleShape::~CircleShape()
|
||||
{
|
||||
Memoizer::remove(shape);
|
||||
delete shape;
|
||||
shape = NULL;
|
||||
}
|
||||
|
||||
float CircleShape::getRadius() const
|
||||
{
|
||||
return Physics::scaleUp(shape->m_radius);
|
||||
}
|
||||
|
||||
void CircleShape::setRadius(float r)
|
||||
{
|
||||
shape->m_radius = Physics::scaleDown(r);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
/**
|
||||
* 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_CIRCLE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_CIRCLE_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* A CircleShape represent a Circle which can
|
||||
* be used for collision detection and physics.
|
||||
*
|
||||
* The CircleShape is much faster than the PolygonShape,
|
||||
* and should generally be used where possible.
|
||||
**/
|
||||
class CircleShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new CircleShape from the parent body and a
|
||||
* Box2D CircleShape definition.
|
||||
* @param body The parent body.
|
||||
* @param def The CircleShape definition.
|
||||
**/
|
||||
CircleShape(b2CircleShape * c);
|
||||
|
||||
virtual ~CircleShape();
|
||||
|
||||
/**
|
||||
* Gets the radius for the circle.
|
||||
**/
|
||||
float getRadius() const;
|
||||
|
||||
/**
|
||||
* Sets the radius for the circle.
|
||||
**/
|
||||
void setRadius(float r);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_CIRCLE_SHAPE_H
|
||||
/**
|
||||
* 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_CIRCLE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_CIRCLE_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* A CircleShape represent a Circle which can
|
||||
* be used for collision detection and physics.
|
||||
*
|
||||
* The CircleShape is much faster than the PolygonShape,
|
||||
* and should generally be used where possible.
|
||||
**/
|
||||
class CircleShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new CircleShape from the parent body and a
|
||||
* Box2D CircleShape definition.
|
||||
* @param body The parent body.
|
||||
* @param def The CircleShape definition.
|
||||
**/
|
||||
CircleShape(b2CircleShape * c);
|
||||
|
||||
virtual ~CircleShape();
|
||||
|
||||
/**
|
||||
* Gets the radius for the circle.
|
||||
**/
|
||||
float getRadius() const;
|
||||
|
||||
/**
|
||||
* Sets the radius for the circle.
|
||||
**/
|
||||
void setRadius(float r);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_CIRCLE_SHAPE_H
|
||||
|
||||
@@ -1,115 +1,116 @@
|
||||
/**
|
||||
* 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 "Contact.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include <common/Memoizer.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Contact::Contact(b2Contact * contact)
|
||||
: contact(contact)
|
||||
{
|
||||
Memoizer::add(contact, this);
|
||||
}
|
||||
|
||||
Contact::~Contact()
|
||||
{
|
||||
Memoizer::remove(contact);
|
||||
}
|
||||
|
||||
int Contact::getPositions(lua_State * L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
b2WorldManifold manifold;
|
||||
contact->GetWorldManifold(&manifold);
|
||||
int points = contact->GetManifold()->pointCount;
|
||||
for (int i = 0; i < points; i++) {
|
||||
b2Vec2 position = Physics::scaleUp(manifold.points[i]);
|
||||
lua_pushnumber(L, position.x);
|
||||
lua_pushnumber(L, position.y);
|
||||
}
|
||||
return points*2;
|
||||
}
|
||||
|
||||
int Contact::getNormal(lua_State * L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
b2WorldManifold manifold;
|
||||
contact->GetWorldManifold(&manifold);
|
||||
lua_pushnumber(L, Physics::scaleUp(manifold.normal.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(manifold.normal.y));
|
||||
return 2;
|
||||
}
|
||||
|
||||
float Contact::getFriction() const
|
||||
{
|
||||
return contact->GetFriction();
|
||||
}
|
||||
|
||||
float Contact::getRestitution() const
|
||||
{
|
||||
return contact->GetRestitution();
|
||||
}
|
||||
|
||||
bool Contact::isEnabled() const
|
||||
{
|
||||
return contact->IsEnabled();
|
||||
}
|
||||
|
||||
bool Contact::isTouching() const
|
||||
{
|
||||
return contact->IsTouching();
|
||||
}
|
||||
|
||||
void Contact::setFriction(float friction)
|
||||
{
|
||||
contact->SetFriction(friction);
|
||||
}
|
||||
|
||||
void Contact::setRestitution(float restitution)
|
||||
{
|
||||
contact->SetRestitution(restitution);
|
||||
}
|
||||
|
||||
void Contact::setEnabled(bool enabled)
|
||||
{
|
||||
contact->SetEnabled(enabled);
|
||||
}
|
||||
|
||||
void Contact::resetFriction()
|
||||
{
|
||||
contact->ResetFriction();
|
||||
}
|
||||
|
||||
void Contact::resetRestitution()
|
||||
{
|
||||
contact->ResetRestitution();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "Contact.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include <common/Memoizer.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Contact::Contact(b2Contact * contact)
|
||||
: contact(contact)
|
||||
{
|
||||
Memoizer::add(contact, this);
|
||||
}
|
||||
|
||||
Contact::~Contact()
|
||||
{
|
||||
Memoizer::remove(contact);
|
||||
}
|
||||
|
||||
int Contact::getPositions(lua_State * L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
b2WorldManifold manifold;
|
||||
contact->GetWorldManifold(&manifold);
|
||||
int points = contact->GetManifold()->pointCount;
|
||||
for (int i = 0; i < points; i++)
|
||||
{
|
||||
b2Vec2 position = Physics::scaleUp(manifold.points[i]);
|
||||
lua_pushnumber(L, position.x);
|
||||
lua_pushnumber(L, position.y);
|
||||
}
|
||||
return points*2;
|
||||
}
|
||||
|
||||
int Contact::getNormal(lua_State * L)
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
b2WorldManifold manifold;
|
||||
contact->GetWorldManifold(&manifold);
|
||||
lua_pushnumber(L, Physics::scaleUp(manifold.normal.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(manifold.normal.y));
|
||||
return 2;
|
||||
}
|
||||
|
||||
float Contact::getFriction() const
|
||||
{
|
||||
return contact->GetFriction();
|
||||
}
|
||||
|
||||
float Contact::getRestitution() const
|
||||
{
|
||||
return contact->GetRestitution();
|
||||
}
|
||||
|
||||
bool Contact::isEnabled() const
|
||||
{
|
||||
return contact->IsEnabled();
|
||||
}
|
||||
|
||||
bool Contact::isTouching() const
|
||||
{
|
||||
return contact->IsTouching();
|
||||
}
|
||||
|
||||
void Contact::setFriction(float friction)
|
||||
{
|
||||
contact->SetFriction(friction);
|
||||
}
|
||||
|
||||
void Contact::setRestitution(float restitution)
|
||||
{
|
||||
contact->SetRestitution(restitution);
|
||||
}
|
||||
|
||||
void Contact::setEnabled(bool enabled)
|
||||
{
|
||||
contact->SetEnabled(enabled);
|
||||
}
|
||||
|
||||
void Contact::resetFriction()
|
||||
{
|
||||
contact->ResetFriction();
|
||||
}
|
||||
|
||||
void Contact::resetRestitution()
|
||||
{
|
||||
contact->ResetRestitution();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+138
-138
@@ -1,138 +1,138 @@
|
||||
/**
|
||||
* 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_CONTACT_H
|
||||
#define LOVE_PHYSICS_BOX2D_CONTACT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
#include <common/runtime.h>
|
||||
#include "World.h"
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
class World;
|
||||
|
||||
/**
|
||||
* A Contact represents a collision point between
|
||||
* two shapes.
|
||||
**/
|
||||
class Contact : public Object
|
||||
{
|
||||
// Friends.
|
||||
friend class World;
|
||||
friend class World::ContactCallback;
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D contact.
|
||||
b2Contact* contact;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new Contact by copying a Box2D contact
|
||||
* point. It does not store the pointer, but copy the
|
||||
* data pointed to.
|
||||
* @param point Pointer to the Box2D contact.
|
||||
**/
|
||||
Contact(b2Contact * contact);
|
||||
|
||||
virtual ~Contact();
|
||||
|
||||
/**
|
||||
* Gets the position of each point of contact.
|
||||
* @return The position along the x-axis.
|
||||
* @return The position along the y-axis.
|
||||
**/
|
||||
int getPositions(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the collision normal.
|
||||
* @return The x-component of the normal.
|
||||
* @return The y-component of the normal.
|
||||
**/
|
||||
int getNormal(lua_State * L);
|
||||
|
||||
/**
|
||||
* The mixed friction between the two fixtures at
|
||||
* the point of impact.
|
||||
**/
|
||||
float getFriction() const;
|
||||
|
||||
/**
|
||||
* The mixed restitution of the two fixtures
|
||||
* at the point of impact.
|
||||
**/
|
||||
float getRestitution() const;
|
||||
|
||||
/**
|
||||
* Check if the contact is enabled.
|
||||
**/
|
||||
bool isEnabled() const;
|
||||
|
||||
/**
|
||||
* Check if the contact is touching.
|
||||
**/
|
||||
bool isTouching() const;
|
||||
|
||||
// Only call the setters in PreSolve
|
||||
|
||||
/**
|
||||
* Override the default friction mixture.
|
||||
**/
|
||||
void setFriction(float friction);
|
||||
|
||||
/**
|
||||
* Override the default restitution mixture.
|
||||
**/
|
||||
void setRestitution(float restitution);
|
||||
|
||||
/**
|
||||
* Enable/disable this contact.
|
||||
**/
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
/**
|
||||
* Reset the friction mixture to the default
|
||||
* value.
|
||||
**/
|
||||
void resetFriction();
|
||||
|
||||
/**
|
||||
* Reset the restitution mixture to the default
|
||||
* value.
|
||||
**/
|
||||
void resetRestitution();
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_CONTACT_H
|
||||
/**
|
||||
* 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_CONTACT_H
|
||||
#define LOVE_PHYSICS_BOX2D_CONTACT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
#include <common/runtime.h>
|
||||
#include "World.h"
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
class World;
|
||||
|
||||
/**
|
||||
* A Contact represents a collision point between
|
||||
* two shapes.
|
||||
**/
|
||||
class Contact : public Object
|
||||
{
|
||||
// Friends.
|
||||
friend class World;
|
||||
friend class World::ContactCallback;
|
||||
|
||||
private:
|
||||
|
||||
// The Box2D contact.
|
||||
b2Contact* contact;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new Contact by copying a Box2D contact
|
||||
* point. It does not store the pointer, but copy the
|
||||
* data pointed to.
|
||||
* @param point Pointer to the Box2D contact.
|
||||
**/
|
||||
Contact(b2Contact * contact);
|
||||
|
||||
virtual ~Contact();
|
||||
|
||||
/**
|
||||
* Gets the position of each point of contact.
|
||||
* @return The position along the x-axis.
|
||||
* @return The position along the y-axis.
|
||||
**/
|
||||
int getPositions(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the collision normal.
|
||||
* @return The x-component of the normal.
|
||||
* @return The y-component of the normal.
|
||||
**/
|
||||
int getNormal(lua_State * L);
|
||||
|
||||
/**
|
||||
* The mixed friction between the two fixtures at
|
||||
* the point of impact.
|
||||
**/
|
||||
float getFriction() const;
|
||||
|
||||
/**
|
||||
* The mixed restitution of the two fixtures
|
||||
* at the point of impact.
|
||||
**/
|
||||
float getRestitution() const;
|
||||
|
||||
/**
|
||||
* Check if the contact is enabled.
|
||||
**/
|
||||
bool isEnabled() const;
|
||||
|
||||
/**
|
||||
* Check if the contact is touching.
|
||||
**/
|
||||
bool isTouching() const;
|
||||
|
||||
// Only call the setters in PreSolve
|
||||
|
||||
/**
|
||||
* Override the default friction mixture.
|
||||
**/
|
||||
void setFriction(float friction);
|
||||
|
||||
/**
|
||||
* Override the default restitution mixture.
|
||||
**/
|
||||
void setRestitution(float restitution);
|
||||
|
||||
/**
|
||||
* Enable/disable this contact.
|
||||
**/
|
||||
void setEnabled(bool enabled);
|
||||
|
||||
/**
|
||||
* Reset the friction mixture to the default
|
||||
* value.
|
||||
**/
|
||||
void resetFriction();
|
||||
|
||||
/**
|
||||
* Reset the restitution mixture to the default
|
||||
* value.
|
||||
**/
|
||||
void resetRestitution();
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_CONTACT_H
|
||||
|
||||
@@ -1,82 +1,82 @@
|
||||
/**
|
||||
* 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 "DistanceJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
DistanceJoint::DistanceJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, bool collideConnected)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
b2DistanceJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x1,y1)), Physics::scaleDown(b2Vec2(x2,y2)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2DistanceJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
DistanceJoint::~DistanceJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
void DistanceJoint::setLength(float length)
|
||||
{
|
||||
joint->SetLength(Physics::scaleDown(length));
|
||||
}
|
||||
|
||||
float DistanceJoint::getLength() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLength());
|
||||
}
|
||||
|
||||
void DistanceJoint::setFrequency(float hz)
|
||||
{
|
||||
joint->SetFrequency(hz);
|
||||
}
|
||||
|
||||
float DistanceJoint::getFrequency() const
|
||||
{
|
||||
return joint->GetFrequency();
|
||||
}
|
||||
|
||||
void DistanceJoint::setDampingRatio(float d)
|
||||
{
|
||||
joint->SetDampingRatio(d);
|
||||
}
|
||||
|
||||
float DistanceJoint::getDampingRatio() const
|
||||
{
|
||||
return joint->GetDampingRatio();
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "DistanceJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
DistanceJoint::DistanceJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, bool collideConnected)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
b2DistanceJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x1,y1)), Physics::scaleDown(b2Vec2(x2,y2)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2DistanceJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
DistanceJoint::~DistanceJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
void DistanceJoint::setLength(float length)
|
||||
{
|
||||
joint->SetLength(Physics::scaleDown(length));
|
||||
}
|
||||
|
||||
float DistanceJoint::getLength() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLength());
|
||||
}
|
||||
|
||||
void DistanceJoint::setFrequency(float hz)
|
||||
{
|
||||
joint->SetFrequency(hz);
|
||||
}
|
||||
|
||||
float DistanceJoint::getFrequency() const
|
||||
{
|
||||
return joint->GetFrequency();
|
||||
}
|
||||
|
||||
void DistanceJoint::setDampingRatio(float d)
|
||||
{
|
||||
joint->SetDampingRatio(d);
|
||||
}
|
||||
|
||||
float DistanceJoint::getDampingRatio() const
|
||||
{
|
||||
return joint->GetDampingRatio();
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,89 +1,89 @@
|
||||
/**
|
||||
* 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_DISTANCE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_DISTANCE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* The DistanceJoint keeps Bodies at a fixed distance
|
||||
* from eachother.
|
||||
**/
|
||||
class DistanceJoint : public Joint
|
||||
{
|
||||
private:
|
||||
// The Box2D DistanceJoint object.
|
||||
b2DistanceJoint * joint;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a DistanceJoint connecting body1 to body2.
|
||||
**/
|
||||
DistanceJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, bool collideConnected);
|
||||
|
||||
virtual ~DistanceJoint();
|
||||
|
||||
/**
|
||||
* Sets the equilibrium distance between the two bodies.
|
||||
**/
|
||||
void setLength(float length);
|
||||
|
||||
/**
|
||||
* Gets the equilibrium distance between the two bodies.
|
||||
**/
|
||||
float getLength() const;
|
||||
|
||||
/**
|
||||
* Sets the response speed.
|
||||
**/
|
||||
void setFrequency(float hz);
|
||||
|
||||
/**
|
||||
* Gets the response speed.
|
||||
**/
|
||||
float getFrequency() const;
|
||||
|
||||
/**
|
||||
* Sets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
void setDampingRatio(float d);
|
||||
|
||||
/**
|
||||
* Gets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
float getDampingRatio() const;
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_DISTANCE_JOINT_H
|
||||
/**
|
||||
* 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_DISTANCE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_DISTANCE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* The DistanceJoint keeps Bodies at a fixed distance
|
||||
* from eachother.
|
||||
**/
|
||||
class DistanceJoint : public Joint
|
||||
{
|
||||
private:
|
||||
// The Box2D DistanceJoint object.
|
||||
b2DistanceJoint * joint;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a DistanceJoint connecting body1 to body2.
|
||||
**/
|
||||
DistanceJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, bool collideConnected);
|
||||
|
||||
virtual ~DistanceJoint();
|
||||
|
||||
/**
|
||||
* Sets the equilibrium distance between the two bodies.
|
||||
**/
|
||||
void setLength(float length);
|
||||
|
||||
/**
|
||||
* Gets the equilibrium distance between the two bodies.
|
||||
**/
|
||||
float getLength() const;
|
||||
|
||||
/**
|
||||
* Sets the response speed.
|
||||
**/
|
||||
void setFrequency(float hz);
|
||||
|
||||
/**
|
||||
* Gets the response speed.
|
||||
**/
|
||||
float getFrequency() const;
|
||||
|
||||
/**
|
||||
* Sets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
void setDampingRatio(float d);
|
||||
|
||||
/**
|
||||
* Gets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
float getDampingRatio() const;
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_DISTANCE_JOINT_H
|
||||
|
||||
@@ -1,63 +1,63 @@
|
||||
/**
|
||||
* 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"
|
||||
#include "Physics.h"
|
||||
|
||||
#include <common/Memoizer.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
EdgeShape::EdgeShape(b2EdgeShape * e)
|
||||
: Shape(e)
|
||||
{
|
||||
}
|
||||
|
||||
EdgeShape::~EdgeShape()
|
||||
{
|
||||
Memoizer::remove(shape);
|
||||
delete shape;
|
||||
shape = NULL;
|
||||
}
|
||||
|
||||
int EdgeShape::getPoints(lua_State * L)
|
||||
{
|
||||
b2EdgeShape * e = (b2EdgeShape *)shape;
|
||||
b2Vec2 v1 = Physics::scaleUp(e->m_vertex1);
|
||||
b2Vec2 v2 = Physics::scaleUp(e->m_vertex2);
|
||||
lua_pushnumber(L, v1.x);
|
||||
lua_pushnumber(L, v1.y);
|
||||
lua_pushnumber(L, v2.x);
|
||||
lua_pushnumber(L, v2.y);
|
||||
return 4;
|
||||
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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"
|
||||
#include "Physics.h"
|
||||
|
||||
#include <common/Memoizer.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
EdgeShape::EdgeShape(b2EdgeShape * e)
|
||||
: Shape(e)
|
||||
{
|
||||
}
|
||||
|
||||
EdgeShape::~EdgeShape()
|
||||
{
|
||||
Memoizer::remove(shape);
|
||||
delete shape;
|
||||
shape = NULL;
|
||||
}
|
||||
|
||||
int EdgeShape::getPoints(lua_State * L)
|
||||
{
|
||||
b2EdgeShape * e = (b2EdgeShape *)shape;
|
||||
b2Vec2 v1 = Physics::scaleUp(e->m_vertex1);
|
||||
b2Vec2 v2 = Physics::scaleUp(e->m_vertex2);
|
||||
lua_pushnumber(L, v1.x);
|
||||
lua_pushnumber(L, v1.y);
|
||||
lua_pushnumber(L, v2.x);
|
||||
lua_pushnumber(L, v2.y);
|
||||
return 4;
|
||||
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,62 +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_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();
|
||||
|
||||
/**
|
||||
* Returns the transformed points of the edge shape.
|
||||
* This function is useful for debug drawing and such.
|
||||
*
|
||||
* The result can be directly passed into love.graphics.line().
|
||||
**/
|
||||
int getPoints(lua_State * L);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_EDGE_SHAPE_H
|
||||
/**
|
||||
* 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();
|
||||
|
||||
/**
|
||||
* Returns the transformed points of the edge shape.
|
||||
* This function is useful for debug drawing and such.
|
||||
*
|
||||
* The result can be directly passed into love.graphics.line().
|
||||
**/
|
||||
int getPoints(lua_State * L);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_EDGE_SHAPE_H
|
||||
|
||||
@@ -49,7 +49,7 @@ namespace box2d
|
||||
fixture = body->body->CreateFixture(&def);
|
||||
Memoizer::add(fixture, this);
|
||||
}
|
||||
|
||||
|
||||
Fixture::Fixture(b2Fixture * f)
|
||||
: fixture(f)
|
||||
{
|
||||
@@ -62,7 +62,7 @@ namespace box2d
|
||||
|
||||
Fixture::~Fixture()
|
||||
{
|
||||
if(data->ref != 0)
|
||||
if (data->ref != 0)
|
||||
delete data->ref;
|
||||
|
||||
delete data;
|
||||
@@ -124,7 +124,7 @@ namespace box2d
|
||||
{
|
||||
return body;
|
||||
}
|
||||
|
||||
|
||||
Shape * Fixture::getShape() const
|
||||
{
|
||||
if (!fixture->GetShape()) return NULL;
|
||||
@@ -197,10 +197,10 @@ namespace box2d
|
||||
// The new bitset.
|
||||
std::bitset<16> b;
|
||||
|
||||
for(int i = 1;i<=argc;i++)
|
||||
for (int i = 1;i<=argc;i++)
|
||||
{
|
||||
size_t bpos = (size_t)(lua_tointeger(L, i)-1);
|
||||
if(bpos > 16)
|
||||
if (bpos > 16)
|
||||
return luaL_error(L, "Values must be in range 1-16.");
|
||||
b.set(bpos, true);
|
||||
}
|
||||
@@ -214,8 +214,8 @@ namespace box2d
|
||||
std::bitset<16> b((int)bits);
|
||||
|
||||
// Push all set bits.
|
||||
for(int i = 0;i<16;i++)
|
||||
if(b.test(i))
|
||||
for (int i = 0;i<16;i++)
|
||||
if (b.test(i))
|
||||
lua_pushinteger(L, i+1);
|
||||
|
||||
// Count number of set bits.
|
||||
@@ -226,7 +226,7 @@ namespace box2d
|
||||
{
|
||||
love::luax_assert_argc(L, 1, 1);
|
||||
|
||||
if(data->ref != 0)
|
||||
if (data->ref != 0)
|
||||
{
|
||||
delete data->ref;
|
||||
data->ref = 0;
|
||||
@@ -239,19 +239,19 @@ namespace box2d
|
||||
int Fixture::getUserData(lua_State * L)
|
||||
{
|
||||
love::luax_assert_argc(L, 0, 0);
|
||||
if(data->ref != 0)
|
||||
if (data->ref != 0)
|
||||
data->ref->push();
|
||||
else
|
||||
lua_pushnil(L);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
bool Fixture::testPoint(float x, float y) const
|
||||
{
|
||||
return fixture->TestPoint(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
|
||||
int Fixture::rayCast(lua_State * L) const
|
||||
{
|
||||
float p1x = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
@@ -275,7 +275,7 @@ namespace box2d
|
||||
lua_pushnumber(L, output.fraction);
|
||||
return 3;
|
||||
}
|
||||
|
||||
|
||||
int Fixture::getBoundingBox(lua_State * L) const
|
||||
{
|
||||
int childIndex = (int)luaL_optint(L, 1, 0);
|
||||
@@ -287,7 +287,7 @@ namespace box2d
|
||||
lua_pushnumber(L, box.upperBound.y);
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
int Fixture::getMassData(lua_State * L) const
|
||||
{
|
||||
b2MassData data;
|
||||
@@ -299,8 +299,8 @@ namespace box2d
|
||||
lua_pushnumber(L, data.I);
|
||||
return 4;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -58,9 +58,9 @@ namespace box2d
|
||||
class Fixture : public Object
|
||||
{
|
||||
friend class Physics;
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
Body * body;
|
||||
b2Fixture * fixture;
|
||||
fixtureudata * data;
|
||||
@@ -71,7 +71,7 @@ namespace box2d
|
||||
* Creates a Fixture.
|
||||
**/
|
||||
Fixture(Body * body, Shape * shape, float density);
|
||||
|
||||
|
||||
/**
|
||||
* Creates a Fixture.
|
||||
**/
|
||||
@@ -84,7 +84,7 @@ namespace box2d
|
||||
* debug drawing.
|
||||
**/
|
||||
Shape::Type getType() const;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the Shape attached to this Fixture.
|
||||
**/
|
||||
@@ -101,26 +101,26 @@ namespace box2d
|
||||
* @param sensor True if sensor, false if not.
|
||||
**/
|
||||
void setSensor(bool sensor);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the Body this Fixture is attached to.
|
||||
**/
|
||||
Body * getBody() const;
|
||||
|
||||
|
||||
/**
|
||||
* Sets the filter data. An integer array is used even though the
|
||||
* first two elements are unsigned shorts. The elements are:
|
||||
* category (16-bits), mask (16-bits) and group (32-bits/int).
|
||||
**/
|
||||
void setFilterData(int * v);
|
||||
|
||||
|
||||
/**
|
||||
* Gets the filter data. An integer array is used even though the
|
||||
* first two elements are unsigned shorts. The elements are:
|
||||
* category (16-bits), mask (16-bits) and group (32-bits/int).
|
||||
**/
|
||||
void getFilterData(int * v);
|
||||
|
||||
|
||||
/**
|
||||
* This function stores an in-C reference to
|
||||
* arbitrary Lua data in the Box2D Fixture object.
|
||||
@@ -171,19 +171,19 @@ namespace box2d
|
||||
* @return The density.
|
||||
**/
|
||||
float getDensity() const;
|
||||
|
||||
|
||||
/**
|
||||
* Checks if a point is inside the Fixture.
|
||||
* @param x The x-component of the point.
|
||||
* @param y The y-component of the point.
|
||||
**/
|
||||
bool testPoint(float x, float y) const;
|
||||
|
||||
|
||||
/**
|
||||
* Cast a ray against this Fixture.
|
||||
**/
|
||||
int rayCast(lua_State * L) const;
|
||||
|
||||
|
||||
void setGroupIndex(int index);
|
||||
int getGroupIndex() const;
|
||||
|
||||
@@ -200,7 +200,7 @@ namespace box2d
|
||||
* passed directly to love.graphics.polygon.
|
||||
**/
|
||||
int getBoundingBox(lua_State * L) const;
|
||||
|
||||
|
||||
/**
|
||||
* Gets the mass data for this Fixture.
|
||||
* This operation may be expensive.
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -35,7 +35,7 @@ namespace box2d
|
||||
{
|
||||
FrictionJoint::FrictionJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
{
|
||||
b2FrictionJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
@@ -48,7 +48,7 @@ namespace box2d
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
|
||||
void FrictionJoint::setMaxForce(float force)
|
||||
{
|
||||
joint->SetMaxForce(Physics::scaleDown(force));
|
||||
@@ -58,12 +58,12 @@ namespace box2d
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxForce());
|
||||
}
|
||||
|
||||
|
||||
void FrictionJoint::setMaxTorque(float torque)
|
||||
{
|
||||
joint->SetMaxTorque(Physics::scaleDown(Physics::scaleDown(torque)));
|
||||
}
|
||||
|
||||
|
||||
float FrictionJoint::getMaxTorque() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMaxTorque()));
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -46,7 +46,7 @@ namespace box2d
|
||||
* Creates a new FrictionJoint connecting body1 and body2.
|
||||
**/
|
||||
FrictionJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
|
||||
virtual ~FrictionJoint();
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,65 +1,65 @@
|
||||
/**
|
||||
* 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 "GearJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
GearJoint::GearJoint(Joint * joint1, Joint * joint2, float ratio, bool collideConnected)
|
||||
: Joint(joint1->body2, joint2->body2), joint(NULL)
|
||||
{
|
||||
b2GearJointDef def;
|
||||
def.joint1 = joint1->joint;
|
||||
def.joint2 = joint2->joint;
|
||||
def.bodyA = joint1->body2->body;
|
||||
def.bodyB = joint2->body2->body;
|
||||
def.ratio = ratio;
|
||||
def.collideConnected = collideConnected;
|
||||
|
||||
joint = (b2GearJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
GearJoint::~GearJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
void GearJoint::setRatio(float ratio)
|
||||
{
|
||||
joint->SetRatio(ratio);
|
||||
}
|
||||
|
||||
float GearJoint::getRatio() const
|
||||
{
|
||||
return joint->GetRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "GearJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
GearJoint::GearJoint(Joint * joint1, Joint * joint2, float ratio, bool collideConnected)
|
||||
: Joint(joint1->body2, joint2->body2), joint(NULL)
|
||||
{
|
||||
b2GearJointDef def;
|
||||
def.joint1 = joint1->joint;
|
||||
def.joint2 = joint2->joint;
|
||||
def.bodyA = joint1->body2->body;
|
||||
def.bodyB = joint2->body2->body;
|
||||
def.ratio = ratio;
|
||||
def.collideConnected = collideConnected;
|
||||
|
||||
joint = (b2GearJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
GearJoint::~GearJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
void GearJoint::setRatio(float ratio)
|
||||
{
|
||||
joint->SetRatio(ratio);
|
||||
}
|
||||
|
||||
float GearJoint::getRatio() const
|
||||
{
|
||||
return joint->GetRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,75 +1,75 @@
|
||||
/**
|
||||
* 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_GEAR_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_GEAR_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* A gear joint is used to connect two joints together. Either joint
|
||||
* can be a revolute or prismatic joint. You specify a gear ratio
|
||||
* to bind the motions together:
|
||||
* coordinate1 + ratio * coordinate2 = constant
|
||||
*
|
||||
* The ratio can be negative or positive. If one joint is a revolute joint
|
||||
* and the other joint is a prismatic joint, then the ratio will have units
|
||||
* of length or units of 1/length.
|
||||
* Warning: The revolute and prismatic joints must be attached to
|
||||
* fixed bodies (which must be body1 on those joints).
|
||||
**/
|
||||
class GearJoint : public Joint
|
||||
{
|
||||
private:
|
||||
// The Box2D GearJoint object.
|
||||
b2GearJoint * joint;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a GearJoint connecting joint1 to joint2.
|
||||
**/
|
||||
GearJoint(Joint * joint1, Joint * joint2, float ratio, bool collideConnected);
|
||||
|
||||
virtual ~GearJoint();
|
||||
|
||||
/**
|
||||
* Sets the ratio.
|
||||
**/
|
||||
void setRatio(float ratio);
|
||||
|
||||
/**
|
||||
* Gets the ratio.
|
||||
**/
|
||||
float getRatio() const;
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_GEAR_JOINT_H
|
||||
/**
|
||||
* 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_GEAR_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_GEAR_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* A gear joint is used to connect two joints together. Either joint
|
||||
* can be a revolute or prismatic joint. You specify a gear ratio
|
||||
* to bind the motions together:
|
||||
* coordinate1 + ratio * coordinate2 = constant
|
||||
*
|
||||
* The ratio can be negative or positive. If one joint is a revolute joint
|
||||
* and the other joint is a prismatic joint, then the ratio will have units
|
||||
* of length or units of 1/length.
|
||||
* Warning: The revolute and prismatic joints must be attached to
|
||||
* fixed bodies (which must be body1 on those joints).
|
||||
**/
|
||||
class GearJoint : public Joint
|
||||
{
|
||||
private:
|
||||
// The Box2D GearJoint object.
|
||||
b2GearJoint * joint;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a GearJoint connecting joint1 to joint2.
|
||||
**/
|
||||
GearJoint(Joint * joint1, Joint * joint2, float ratio, bool collideConnected);
|
||||
|
||||
virtual ~GearJoint();
|
||||
|
||||
/**
|
||||
* Sets the ratio.
|
||||
**/
|
||||
void setRatio(float ratio);
|
||||
|
||||
/**
|
||||
* Gets the ratio.
|
||||
**/
|
||||
float getRatio() const;
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_GEAR_JOINT_H
|
||||
|
||||
+136
-136
@@ -1,136 +1,136 @@
|
||||
/**
|
||||
* 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 "Joint.h"
|
||||
|
||||
// STD
|
||||
#include <bitset>
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Joint::Joint(Body * body1)
|
||||
: body1(body1), body2(0), world(body1->world)
|
||||
{
|
||||
body1->retain();
|
||||
}
|
||||
|
||||
Joint::Joint(Body * body1, Body * body2)
|
||||
: body1(body1), body2(body2), world(body1->world)
|
||||
{
|
||||
body1->retain();
|
||||
body2->retain();
|
||||
}
|
||||
|
||||
Joint::~Joint()
|
||||
{
|
||||
if(body1 != 0)
|
||||
body1->release();
|
||||
if(body2 != 0)
|
||||
body2->release();
|
||||
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
Joint::Type Joint::getType() const
|
||||
{
|
||||
switch(joint->GetType())
|
||||
{
|
||||
case e_revoluteJoint:
|
||||
return JOINT_REVOLUTE;
|
||||
case e_prismaticJoint:
|
||||
return JOINT_PRISMATIC;
|
||||
case e_distanceJoint:
|
||||
return JOINT_DISTANCE;
|
||||
case e_pulleyJoint:
|
||||
return JOINT_PULLEY;
|
||||
case e_mouseJoint:
|
||||
return JOINT_MOUSE;
|
||||
case e_gearJoint:
|
||||
return JOINT_GEAR;
|
||||
case e_frictionJoint:
|
||||
return JOINT_FRICTION;
|
||||
case e_weldJoint:
|
||||
return JOINT_WELD;
|
||||
case e_wheelJoint:
|
||||
return JOINT_WHEEL;
|
||||
case e_ropeJoint:
|
||||
return JOINT_ROPE;
|
||||
default:
|
||||
return JOINT_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
int Joint::getAnchors(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorA().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorA().y));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorB().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorB().y));
|
||||
return 4;
|
||||
}
|
||||
|
||||
int Joint::getReactionForce(lua_State * L)
|
||||
{
|
||||
float dt = (float)luaL_checknumber(L, 1);
|
||||
b2Vec2 v = Physics::scaleUp(joint->GetReactionForce(dt));
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
float Joint::getReactionTorque(float dt)
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetReactionTorque(dt)));
|
||||
}
|
||||
|
||||
b2Joint * Joint::createJoint(b2JointDef * def)
|
||||
{
|
||||
joint = world->world->CreateJoint(def);
|
||||
return joint;
|
||||
}
|
||||
|
||||
void Joint::destroyJoint(b2Joint * joint)
|
||||
{
|
||||
if (joint != NULL)
|
||||
world->world->DestroyJoint(joint);
|
||||
}
|
||||
|
||||
bool Joint::isActive() const
|
||||
{
|
||||
return joint->IsActive();
|
||||
}
|
||||
|
||||
bool Joint::getCollideConnected() const
|
||||
{
|
||||
return joint->GetCollideConnected();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "Joint.h"
|
||||
|
||||
// STD
|
||||
#include <bitset>
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Joint::Joint(Body * body1)
|
||||
: body1(body1), body2(0), world(body1->world)
|
||||
{
|
||||
body1->retain();
|
||||
}
|
||||
|
||||
Joint::Joint(Body * body1, Body * body2)
|
||||
: body1(body1), body2(body2), world(body1->world)
|
||||
{
|
||||
body1->retain();
|
||||
body2->retain();
|
||||
}
|
||||
|
||||
Joint::~Joint()
|
||||
{
|
||||
if (body1 != 0)
|
||||
body1->release();
|
||||
if (body2 != 0)
|
||||
body2->release();
|
||||
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
Joint::Type Joint::getType() const
|
||||
{
|
||||
switch(joint->GetType())
|
||||
{
|
||||
case e_revoluteJoint:
|
||||
return JOINT_REVOLUTE;
|
||||
case e_prismaticJoint:
|
||||
return JOINT_PRISMATIC;
|
||||
case e_distanceJoint:
|
||||
return JOINT_DISTANCE;
|
||||
case e_pulleyJoint:
|
||||
return JOINT_PULLEY;
|
||||
case e_mouseJoint:
|
||||
return JOINT_MOUSE;
|
||||
case e_gearJoint:
|
||||
return JOINT_GEAR;
|
||||
case e_frictionJoint:
|
||||
return JOINT_FRICTION;
|
||||
case e_weldJoint:
|
||||
return JOINT_WELD;
|
||||
case e_wheelJoint:
|
||||
return JOINT_WHEEL;
|
||||
case e_ropeJoint:
|
||||
return JOINT_ROPE;
|
||||
default:
|
||||
return JOINT_INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
int Joint::getAnchors(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorA().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorA().y));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorB().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetAnchorB().y));
|
||||
return 4;
|
||||
}
|
||||
|
||||
int Joint::getReactionForce(lua_State * L)
|
||||
{
|
||||
float dt = (float)luaL_checknumber(L, 1);
|
||||
b2Vec2 v = Physics::scaleUp(joint->GetReactionForce(dt));
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
float Joint::getReactionTorque(float dt)
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetReactionTorque(dt)));
|
||||
}
|
||||
|
||||
b2Joint * Joint::createJoint(b2JointDef * def)
|
||||
{
|
||||
joint = world->world->CreateJoint(def);
|
||||
return joint;
|
||||
}
|
||||
|
||||
void Joint::destroyJoint(b2Joint * joint)
|
||||
{
|
||||
if (joint != NULL)
|
||||
world->world->DestroyJoint(joint);
|
||||
}
|
||||
|
||||
bool Joint::isActive() const
|
||||
{
|
||||
return joint->IsActive();
|
||||
}
|
||||
|
||||
bool Joint::getCollideConnected() const
|
||||
{
|
||||
return joint->GetCollideConnected();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+131
-131
@@ -1,131 +1,131 @@
|
||||
/**
|
||||
* 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_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include <physics/Joint.h>
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
// Forward declarations.
|
||||
class Body;
|
||||
class World;
|
||||
|
||||
/**
|
||||
* A Joint acts as positioning constraints on Bodies.
|
||||
* A Joint can be used to prevent Bodies from going to
|
||||
* far apart, or coming too close together.
|
||||
**/
|
||||
class Joint : public love::physics::Joint
|
||||
{
|
||||
friend class GearJoint;
|
||||
|
||||
private:
|
||||
|
||||
// A Joint must be destroyed *before* the bodies it acts upon,
|
||||
// and the world they reside in. We therefore need refs
|
||||
// parents and associations to prevent wrong destruction order.
|
||||
Body * body1, * body2;
|
||||
|
||||
|
||||
// The Box2D joint object.
|
||||
b2Joint * joint;
|
||||
|
||||
protected:
|
||||
World * world;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* This constructor will connect one end of the joint to body1,
|
||||
* and the other one to the default ground body.
|
||||
*
|
||||
* This constructor is mainly used by MouseJoint.
|
||||
**/
|
||||
Joint(Body * body1);
|
||||
|
||||
/**
|
||||
* Create a joint between body1 and body2.
|
||||
**/
|
||||
Joint(Body * body1, Body * body2);
|
||||
|
||||
virtual ~Joint();
|
||||
|
||||
/**
|
||||
* Gets the type of joint.
|
||||
**/
|
||||
Type getType() const;
|
||||
|
||||
/**
|
||||
* Gets the anchor positions of the Joint in world
|
||||
* coordinates. This is useful for debugdrawing the joint.
|
||||
**/
|
||||
int getAnchors(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the reaction force on body2 at the joint anchor.
|
||||
**/
|
||||
int getReactionForce(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the reaction torque on body2.
|
||||
**/
|
||||
float getReactionTorque(float dt);
|
||||
|
||||
bool isActive() const;
|
||||
|
||||
bool getCollideConnected() const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Joints require pointers to a Box2D joint objects at
|
||||
* different polymorphic levels, which is why these function
|
||||
* were created.
|
||||
**/
|
||||
|
||||
/**
|
||||
* Creates a Joint, and ensures that the parent class
|
||||
* gets a copy of the pointer.
|
||||
**/
|
||||
b2Joint * createJoint(b2JointDef * def);
|
||||
|
||||
/**
|
||||
* Destroys the joint. This function was created just to
|
||||
* get some cinsistency.
|
||||
**/
|
||||
void destroyJoint(b2Joint * joint);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_JOINT_H
|
||||
/**
|
||||
* 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_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include <physics/Joint.h>
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
// Forward declarations.
|
||||
class Body;
|
||||
class World;
|
||||
|
||||
/**
|
||||
* A Joint acts as positioning constraints on Bodies.
|
||||
* A Joint can be used to prevent Bodies from going to
|
||||
* far apart, or coming too close together.
|
||||
**/
|
||||
class Joint : public love::physics::Joint
|
||||
{
|
||||
friend class GearJoint;
|
||||
|
||||
private:
|
||||
|
||||
// A Joint must be destroyed *before* the bodies it acts upon,
|
||||
// and the world they reside in. We therefore need refs
|
||||
// parents and associations to prevent wrong destruction order.
|
||||
Body * body1, * body2;
|
||||
|
||||
|
||||
// The Box2D joint object.
|
||||
b2Joint * joint;
|
||||
|
||||
protected:
|
||||
World * world;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* This constructor will connect one end of the joint to body1,
|
||||
* and the other one to the default ground body.
|
||||
*
|
||||
* This constructor is mainly used by MouseJoint.
|
||||
**/
|
||||
Joint(Body * body1);
|
||||
|
||||
/**
|
||||
* Create a joint between body1 and body2.
|
||||
**/
|
||||
Joint(Body * body1, Body * body2);
|
||||
|
||||
virtual ~Joint();
|
||||
|
||||
/**
|
||||
* Gets the type of joint.
|
||||
**/
|
||||
Type getType() const;
|
||||
|
||||
/**
|
||||
* Gets the anchor positions of the Joint in world
|
||||
* coordinates. This is useful for debugdrawing the joint.
|
||||
**/
|
||||
int getAnchors(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the reaction force on body2 at the joint anchor.
|
||||
**/
|
||||
int getReactionForce(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the reaction torque on body2.
|
||||
**/
|
||||
float getReactionTorque(float dt);
|
||||
|
||||
bool isActive() const;
|
||||
|
||||
bool getCollideConnected() const;
|
||||
|
||||
protected:
|
||||
|
||||
/**
|
||||
* Joints require pointers to a Box2D joint objects at
|
||||
* different polymorphic levels, which is why these function
|
||||
* were created.
|
||||
**/
|
||||
|
||||
/**
|
||||
* Creates a Joint, and ensures that the parent class
|
||||
* gets a copy of the pointer.
|
||||
**/
|
||||
b2Joint * createJoint(b2JointDef * def);
|
||||
|
||||
/**
|
||||
* Destroys the joint. This function was created just to
|
||||
* get some cinsistency.
|
||||
**/
|
||||
void destroyJoint(b2Joint * joint);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_JOINT_H
|
||||
|
||||
@@ -1,96 +1,96 @@
|
||||
/**
|
||||
* 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 "MouseJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
MouseJoint::MouseJoint(Body * body1, float x, float y)
|
||||
: Joint(body1), joint(NULL)
|
||||
{
|
||||
b2MouseJointDef def;
|
||||
|
||||
def.bodyA = body1->world->getGroundBody();
|
||||
def.bodyB = body1->body;
|
||||
def.maxForce = 1000.0f * body1->body->GetMass();
|
||||
def.target = Physics::scaleDown(b2Vec2(x,y));
|
||||
joint = (b2MouseJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
MouseJoint::~MouseJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
void MouseJoint::setTarget(float x, float y)
|
||||
{
|
||||
joint->SetTarget(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
int MouseJoint::getTarget(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetTarget().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetTarget().y));
|
||||
return 2;
|
||||
}
|
||||
|
||||
void MouseJoint::setMaxForce(float force)
|
||||
{
|
||||
joint->SetMaxForce(Physics::scaleDown(force));
|
||||
}
|
||||
|
||||
float MouseJoint::getMaxForce() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxForce());
|
||||
}
|
||||
|
||||
void MouseJoint::setFrequency(float hz)
|
||||
{
|
||||
joint->SetFrequency(hz);
|
||||
}
|
||||
|
||||
float MouseJoint::getFrequency() const
|
||||
{
|
||||
return joint->GetFrequency();
|
||||
}
|
||||
|
||||
void MouseJoint::setDampingRatio(float d)
|
||||
{
|
||||
joint->SetDampingRatio(d);
|
||||
}
|
||||
|
||||
float MouseJoint::getDampingRatio() const
|
||||
{
|
||||
return joint->GetDampingRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "MouseJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
MouseJoint::MouseJoint(Body * body1, float x, float y)
|
||||
: Joint(body1), joint(NULL)
|
||||
{
|
||||
b2MouseJointDef def;
|
||||
|
||||
def.bodyA = body1->world->getGroundBody();
|
||||
def.bodyB = body1->body;
|
||||
def.maxForce = 1000.0f * body1->body->GetMass();
|
||||
def.target = Physics::scaleDown(b2Vec2(x,y));
|
||||
joint = (b2MouseJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
MouseJoint::~MouseJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
void MouseJoint::setTarget(float x, float y)
|
||||
{
|
||||
joint->SetTarget(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
int MouseJoint::getTarget(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetTarget().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetTarget().y));
|
||||
return 2;
|
||||
}
|
||||
|
||||
void MouseJoint::setMaxForce(float force)
|
||||
{
|
||||
joint->SetMaxForce(Physics::scaleDown(force));
|
||||
}
|
||||
|
||||
float MouseJoint::getMaxForce() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxForce());
|
||||
}
|
||||
|
||||
void MouseJoint::setFrequency(float hz)
|
||||
{
|
||||
joint->SetFrequency(hz);
|
||||
}
|
||||
|
||||
float MouseJoint::getFrequency() const
|
||||
{
|
||||
return joint->GetFrequency();
|
||||
}
|
||||
|
||||
void MouseJoint::setDampingRatio(float d)
|
||||
{
|
||||
joint->SetDampingRatio(d);
|
||||
}
|
||||
|
||||
float MouseJoint::getDampingRatio() const
|
||||
{
|
||||
return joint->GetDampingRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,106 +1,106 @@
|
||||
/**
|
||||
* 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_MOUSE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_MOUSE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* The MouseJoint is a joint type that
|
||||
* is suitable for controlling objects with the mouse.
|
||||
*
|
||||
* One end is anchored in the dynamic body, and the other id
|
||||
* anchor to a static ground body. The anchor offset can then be
|
||||
* moved to the current mouse position.
|
||||
**/
|
||||
class MouseJoint : public Joint
|
||||
{
|
||||
private:
|
||||
// The Box2D MouseJoint object.
|
||||
b2MouseJoint * joint;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a MouseJoint which connects body1 to the target point.
|
||||
**/
|
||||
MouseJoint(Body * body1, float x, float y);
|
||||
|
||||
virtual ~MouseJoint();
|
||||
|
||||
/**
|
||||
* Sets the target of anchor2. (You usually want
|
||||
* to set this to the current mouse.)
|
||||
**/
|
||||
void setTarget(float x, float y);
|
||||
|
||||
/**
|
||||
* Gets the current anchor2 target.
|
||||
**/
|
||||
int getTarget(lua_State * L);
|
||||
|
||||
/**
|
||||
* Sets the maximum constraint force that can be exerted
|
||||
* to move the candidate body.
|
||||
**/
|
||||
void setMaxForce(float force);
|
||||
|
||||
/**
|
||||
* Gets the maximum constraint force that can be exerted
|
||||
* to move the candidate body.
|
||||
**/
|
||||
float getMaxForce() const;
|
||||
|
||||
/**
|
||||
* Sets the response speed.
|
||||
**/
|
||||
void setFrequency(float hz);
|
||||
|
||||
/**
|
||||
* Gets the response speed.
|
||||
**/
|
||||
float getFrequency() const;
|
||||
|
||||
/**
|
||||
* Sets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
void setDampingRatio(float d);
|
||||
|
||||
/**
|
||||
* Gets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
float getDampingRatio() const;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_MOUSE_JOINT_H
|
||||
/**
|
||||
* 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_MOUSE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_MOUSE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* The MouseJoint is a joint type that
|
||||
* is suitable for controlling objects with the mouse.
|
||||
*
|
||||
* One end is anchored in the dynamic body, and the other id
|
||||
* anchor to a static ground body. The anchor offset can then be
|
||||
* moved to the current mouse position.
|
||||
**/
|
||||
class MouseJoint : public Joint
|
||||
{
|
||||
private:
|
||||
// The Box2D MouseJoint object.
|
||||
b2MouseJoint * joint;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a MouseJoint which connects body1 to the target point.
|
||||
**/
|
||||
MouseJoint(Body * body1, float x, float y);
|
||||
|
||||
virtual ~MouseJoint();
|
||||
|
||||
/**
|
||||
* Sets the target of anchor2. (You usually want
|
||||
* to set this to the current mouse.)
|
||||
**/
|
||||
void setTarget(float x, float y);
|
||||
|
||||
/**
|
||||
* Gets the current anchor2 target.
|
||||
**/
|
||||
int getTarget(lua_State * L);
|
||||
|
||||
/**
|
||||
* Sets the maximum constraint force that can be exerted
|
||||
* to move the candidate body.
|
||||
**/
|
||||
void setMaxForce(float force);
|
||||
|
||||
/**
|
||||
* Gets the maximum constraint force that can be exerted
|
||||
* to move the candidate body.
|
||||
**/
|
||||
float getMaxForce() const;
|
||||
|
||||
/**
|
||||
* Sets the response speed.
|
||||
**/
|
||||
void setFrequency(float hz);
|
||||
|
||||
/**
|
||||
* Gets the response speed.
|
||||
**/
|
||||
float getFrequency() const;
|
||||
|
||||
/**
|
||||
* Sets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
void setDampingRatio(float d);
|
||||
|
||||
/**
|
||||
* Gets the damping ratio.
|
||||
* 0 = no damping, 1 = critical damping.
|
||||
**/
|
||||
float getDampingRatio() const;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_MOUSE_JOINT_H
|
||||
|
||||
@@ -1,300 +1,300 @@
|
||||
/**
|
||||
* 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 "Physics.h"
|
||||
|
||||
// LOVE
|
||||
#include <common/math.h>
|
||||
#include "wrap_Body.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
int Physics::meter = Physics::DEFAULT_METER;
|
||||
|
||||
const char * Physics::getName() const
|
||||
{
|
||||
return "love.physics.box2d";
|
||||
}
|
||||
|
||||
World * Physics::newWorld(float gx, float gy, bool sleep)
|
||||
{
|
||||
return new World(b2Vec2(gx, gy), sleep);
|
||||
}
|
||||
|
||||
Body * Physics::newBody(World * world, float x, float y, Body::Type type)
|
||||
{
|
||||
return new Body(world, b2Vec2(x, y), type);
|
||||
}
|
||||
|
||||
Body * Physics::newBody(World * world, Body::Type type)
|
||||
{
|
||||
return new Body(world, b2Vec2(0, 0), type);
|
||||
}
|
||||
|
||||
CircleShape * Physics::newCircleShape(float radius)
|
||||
{
|
||||
return newCircleShape(0, 0, radius);
|
||||
}
|
||||
|
||||
CircleShape * Physics::newCircleShape(float x, float y, float radius)
|
||||
{
|
||||
b2CircleShape *s = new b2CircleShape();
|
||||
s->m_p = Physics::scaleDown(b2Vec2(x, y));
|
||||
s->m_radius = Physics::scaleDown(radius);
|
||||
return new CircleShape(s);
|
||||
}
|
||||
|
||||
PolygonShape * Physics::newRectangleShape(float w, float h)
|
||||
{
|
||||
return newRectangleShape(0, 0, w, h, 0);
|
||||
}
|
||||
|
||||
PolygonShape * Physics::newRectangleShape(float x, float y, float w, float h)
|
||||
{
|
||||
return newRectangleShape(x, y, w, h, 0);
|
||||
}
|
||||
|
||||
PolygonShape * Physics::newRectangleShape(float x, float y, float w, float h, float angle)
|
||||
{
|
||||
b2PolygonShape* s = new b2PolygonShape();
|
||||
s->SetAsBox(Physics::scaleDown(w/2.0f), Physics::scaleDown(h/2.0f), Physics::scaleDown(b2Vec2(x, y)), angle);
|
||||
return new PolygonShape(s);
|
||||
}
|
||||
|
||||
EdgeShape * Physics::newEdgeShape(float x1, float y1, float x2, float y2)
|
||||
{
|
||||
b2EdgeShape* s = new b2EdgeShape();
|
||||
s->Set(Physics::scaleDown(b2Vec2(x1, y1)), Physics::scaleDown(b2Vec2(x2, y2)));
|
||||
return new EdgeShape(s);
|
||||
}
|
||||
|
||||
int Physics::newPolygonShape(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
int vcount = (int)argc/2;
|
||||
// 3 vertices
|
||||
love::luax_assert_argc(L, 2 * 3);
|
||||
|
||||
b2PolygonShape* s = new b2PolygonShape();
|
||||
|
||||
b2Vec2 * vecs = new b2Vec2[vcount];
|
||||
|
||||
for(int i = 0;i<vcount;i++)
|
||||
{
|
||||
float x = (float)lua_tonumber(L, -2);
|
||||
float y = (float)lua_tonumber(L, -1);
|
||||
vecs[i] = (Physics::scaleDown(b2Vec2(x, y)));
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
s->Set(vecs, vcount);
|
||||
|
||||
PolygonShape * p = new PolygonShape(s);
|
||||
delete[] vecs;
|
||||
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void*)p);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Physics::newChainShape(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L)-1; // first argument is looping
|
||||
int vcount = (int)argc/2;
|
||||
|
||||
b2ChainShape* s = new b2ChainShape();
|
||||
|
||||
bool loop = luax_toboolean(L, 1);
|
||||
|
||||
b2Vec2 * vecs = new b2Vec2[vcount];
|
||||
|
||||
for(int i = 0;i<vcount;i++)
|
||||
{
|
||||
float x = (float)lua_tonumber(L, -2);
|
||||
float y = (float)lua_tonumber(L, -1);
|
||||
vecs[i].Set(x, y);
|
||||
vecs[i] = Physics::scaleDown(vecs[i]);
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
if (loop)
|
||||
s->CreateLoop(vecs, vcount);
|
||||
else
|
||||
s->CreateChain(vecs, vcount);
|
||||
|
||||
ChainShape * c = new ChainShape(s);
|
||||
delete[] vecs;
|
||||
|
||||
luax_newtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, (void*)c);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
DistanceJoint * Physics::newDistanceJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, bool collideConnected)
|
||||
{
|
||||
return new DistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);
|
||||
}
|
||||
|
||||
MouseJoint * Physics::newMouseJoint(Body * body, float x, float y)
|
||||
{
|
||||
return new MouseJoint(body, x, y);
|
||||
}
|
||||
|
||||
RevoluteJoint * Physics::newRevoluteJoint(Body * body1, Body * body2, float x, float y, bool collideConnected)
|
||||
{
|
||||
return new RevoluteJoint(body1, body2, x, y, collideConnected);
|
||||
}
|
||||
|
||||
PrismaticJoint * Physics::newPrismaticJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
{
|
||||
return new PrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
|
||||
}
|
||||
|
||||
PulleyJoint * Physics::newPulleyJoint(Body * body1, Body * body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio, bool collideConnected)
|
||||
{
|
||||
return new PulleyJoint(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, ratio, collideConnected);
|
||||
}
|
||||
|
||||
GearJoint * Physics::newGearJoint(Joint * joint1, Joint * joint2, float ratio, bool collideConnected)
|
||||
{
|
||||
return new GearJoint(joint1, joint2, ratio, collideConnected);
|
||||
}
|
||||
|
||||
FrictionJoint * Physics::newFrictionJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
{
|
||||
return new FrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
}
|
||||
|
||||
WeldJoint * Physics::newWeldJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
{
|
||||
return new WeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
}
|
||||
|
||||
WheelJoint * Physics::newWheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
{
|
||||
return new WheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
|
||||
}
|
||||
|
||||
RopeJoint * Physics::newRopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected)
|
||||
{
|
||||
return new RopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);
|
||||
}
|
||||
|
||||
Fixture * Physics::newFixture(Body * body, Shape * shape, float density)
|
||||
{
|
||||
return new Fixture(body, shape, density);
|
||||
}
|
||||
|
||||
int Physics::getDistance(lua_State * L)
|
||||
{
|
||||
Fixture * fixtureA = luax_checktype<Fixture>(L, 1, "Fixture", PHYSICS_FIXTURE_T);
|
||||
Fixture * fixtureB = luax_checktype<Fixture>(L, 2, "Fixture", PHYSICS_FIXTURE_T);
|
||||
b2DistanceInput i;
|
||||
b2DistanceProxy pA;
|
||||
pA.Set(fixtureA->fixture->GetShape(), 0);
|
||||
b2DistanceProxy pB;
|
||||
pB.Set(fixtureB->fixture->GetShape(), 0);
|
||||
i.proxyA = pA;
|
||||
i.proxyB = pB;
|
||||
i.transformA = fixtureA->fixture->GetBody()->GetTransform();
|
||||
i.transformB = fixtureB->fixture->GetBody()->GetTransform();
|
||||
i.useRadii = true;
|
||||
b2DistanceOutput o;
|
||||
b2SimplexCache c;
|
||||
b2Distance(&o, &c, &i);
|
||||
lua_pushnumber(L, Physics::scaleUp(o.distance));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointA.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointA.y));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointB.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointB.y));
|
||||
return 5;
|
||||
}
|
||||
|
||||
void Physics::setMeter(int meter)
|
||||
{
|
||||
if (meter < 1) throw love::Exception("Physics error: invalid meter");
|
||||
Physics::meter = meter;
|
||||
}
|
||||
|
||||
int Physics::getMeter()
|
||||
{
|
||||
return meter;
|
||||
}
|
||||
|
||||
void Physics::scaleDown(float & x, float & y)
|
||||
{
|
||||
x /= (float)meter;
|
||||
y /= (float)meter;
|
||||
}
|
||||
|
||||
void Physics::scaleUp(float & x, float & y)
|
||||
{
|
||||
x *= (float)meter;
|
||||
y *= (float)meter;
|
||||
}
|
||||
|
||||
float Physics::scaleDown(float f)
|
||||
{
|
||||
return f/(float)meter;
|
||||
}
|
||||
|
||||
float Physics::scaleUp(float f)
|
||||
{
|
||||
return f*(float)meter;
|
||||
}
|
||||
|
||||
b2Vec2 Physics::scaleDown(const b2Vec2 & v)
|
||||
{
|
||||
b2Vec2 t = v;
|
||||
scaleDown(t.x, t.y);
|
||||
return t;
|
||||
}
|
||||
|
||||
b2Vec2 Physics::scaleUp(const b2Vec2 & v)
|
||||
{
|
||||
b2Vec2 t = v;
|
||||
scaleUp(t.x, t.y);
|
||||
return t;
|
||||
}
|
||||
|
||||
b2AABB Physics::scaleDown(const b2AABB & aabb)
|
||||
{
|
||||
b2AABB t;
|
||||
t.lowerBound = scaleDown(aabb.lowerBound);
|
||||
t.upperBound = scaleDown(aabb.upperBound);
|
||||
return t;
|
||||
}
|
||||
|
||||
b2AABB Physics::scaleUp(const b2AABB & aabb)
|
||||
{
|
||||
b2AABB t;
|
||||
t.lowerBound = scaleUp(aabb.lowerBound);
|
||||
t.upperBound = scaleUp(aabb.upperBound);
|
||||
return t;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "Physics.h"
|
||||
|
||||
// LOVE
|
||||
#include <common/math.h>
|
||||
#include "wrap_Body.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
int Physics::meter = Physics::DEFAULT_METER;
|
||||
|
||||
const char * Physics::getName() const
|
||||
{
|
||||
return "love.physics.box2d";
|
||||
}
|
||||
|
||||
World * Physics::newWorld(float gx, float gy, bool sleep)
|
||||
{
|
||||
return new World(b2Vec2(gx, gy), sleep);
|
||||
}
|
||||
|
||||
Body * Physics::newBody(World * world, float x, float y, Body::Type type)
|
||||
{
|
||||
return new Body(world, b2Vec2(x, y), type);
|
||||
}
|
||||
|
||||
Body * Physics::newBody(World * world, Body::Type type)
|
||||
{
|
||||
return new Body(world, b2Vec2(0, 0), type);
|
||||
}
|
||||
|
||||
CircleShape * Physics::newCircleShape(float radius)
|
||||
{
|
||||
return newCircleShape(0, 0, radius);
|
||||
}
|
||||
|
||||
CircleShape * Physics::newCircleShape(float x, float y, float radius)
|
||||
{
|
||||
b2CircleShape *s = new b2CircleShape();
|
||||
s->m_p = Physics::scaleDown(b2Vec2(x, y));
|
||||
s->m_radius = Physics::scaleDown(radius);
|
||||
return new CircleShape(s);
|
||||
}
|
||||
|
||||
PolygonShape * Physics::newRectangleShape(float w, float h)
|
||||
{
|
||||
return newRectangleShape(0, 0, w, h, 0);
|
||||
}
|
||||
|
||||
PolygonShape * Physics::newRectangleShape(float x, float y, float w, float h)
|
||||
{
|
||||
return newRectangleShape(x, y, w, h, 0);
|
||||
}
|
||||
|
||||
PolygonShape * Physics::newRectangleShape(float x, float y, float w, float h, float angle)
|
||||
{
|
||||
b2PolygonShape* s = new b2PolygonShape();
|
||||
s->SetAsBox(Physics::scaleDown(w/2.0f), Physics::scaleDown(h/2.0f), Physics::scaleDown(b2Vec2(x, y)), angle);
|
||||
return new PolygonShape(s);
|
||||
}
|
||||
|
||||
EdgeShape * Physics::newEdgeShape(float x1, float y1, float x2, float y2)
|
||||
{
|
||||
b2EdgeShape* s = new b2EdgeShape();
|
||||
s->Set(Physics::scaleDown(b2Vec2(x1, y1)), Physics::scaleDown(b2Vec2(x2, y2)));
|
||||
return new EdgeShape(s);
|
||||
}
|
||||
|
||||
int Physics::newPolygonShape(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L);
|
||||
int vcount = (int)argc/2;
|
||||
// 3 vertices
|
||||
love::luax_assert_argc(L, 2 * 3);
|
||||
|
||||
b2PolygonShape* s = new b2PolygonShape();
|
||||
|
||||
b2Vec2 * vecs = new b2Vec2[vcount];
|
||||
|
||||
for (int i = 0;i<vcount;i++)
|
||||
{
|
||||
float x = (float)lua_tonumber(L, -2);
|
||||
float y = (float)lua_tonumber(L, -1);
|
||||
vecs[i] = (Physics::scaleDown(b2Vec2(x, y)));
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
s->Set(vecs, vcount);
|
||||
|
||||
PolygonShape * p = new PolygonShape(s);
|
||||
delete[] vecs;
|
||||
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void*)p);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int Physics::newChainShape(lua_State * L)
|
||||
{
|
||||
int argc = lua_gettop(L)-1; // first argument is looping
|
||||
int vcount = (int)argc/2;
|
||||
|
||||
b2ChainShape* s = new b2ChainShape();
|
||||
|
||||
bool loop = luax_toboolean(L, 1);
|
||||
|
||||
b2Vec2 * vecs = new b2Vec2[vcount];
|
||||
|
||||
for (int i = 0;i<vcount;i++)
|
||||
{
|
||||
float x = (float)lua_tonumber(L, -2);
|
||||
float y = (float)lua_tonumber(L, -1);
|
||||
vecs[i].Set(x, y);
|
||||
vecs[i] = Physics::scaleDown(vecs[i]);
|
||||
lua_pop(L, 2);
|
||||
}
|
||||
|
||||
if (loop)
|
||||
s->CreateLoop(vecs, vcount);
|
||||
else
|
||||
s->CreateChain(vecs, vcount);
|
||||
|
||||
ChainShape * c = new ChainShape(s);
|
||||
delete[] vecs;
|
||||
|
||||
luax_newtype(L, "ChainShape", PHYSICS_CHAIN_SHAPE_T, (void*)c);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
DistanceJoint * Physics::newDistanceJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, bool collideConnected)
|
||||
{
|
||||
return new DistanceJoint(body1, body2, x1, y1, x2, y2, collideConnected);
|
||||
}
|
||||
|
||||
MouseJoint * Physics::newMouseJoint(Body * body, float x, float y)
|
||||
{
|
||||
return new MouseJoint(body, x, y);
|
||||
}
|
||||
|
||||
RevoluteJoint * Physics::newRevoluteJoint(Body * body1, Body * body2, float x, float y, bool collideConnected)
|
||||
{
|
||||
return new RevoluteJoint(body1, body2, x, y, collideConnected);
|
||||
}
|
||||
|
||||
PrismaticJoint * Physics::newPrismaticJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
{
|
||||
return new PrismaticJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
|
||||
}
|
||||
|
||||
PulleyJoint * Physics::newPulleyJoint(Body * body1, Body * body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio, bool collideConnected)
|
||||
{
|
||||
return new PulleyJoint(body1, body2, groundAnchor1, groundAnchor2, anchor1, anchor2, ratio, collideConnected);
|
||||
}
|
||||
|
||||
GearJoint * Physics::newGearJoint(Joint * joint1, Joint * joint2, float ratio, bool collideConnected)
|
||||
{
|
||||
return new GearJoint(joint1, joint2, ratio, collideConnected);
|
||||
}
|
||||
|
||||
FrictionJoint * Physics::newFrictionJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
{
|
||||
return new FrictionJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
}
|
||||
|
||||
WeldJoint * Physics::newWeldJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
{
|
||||
return new WeldJoint(body1, body2, xA, yA, xB, yB, collideConnected);
|
||||
}
|
||||
|
||||
WheelJoint * Physics::newWheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
{
|
||||
return new WheelJoint(body1, body2, xA, yA, xB, yB, ax, ay, collideConnected);
|
||||
}
|
||||
|
||||
RopeJoint * Physics::newRopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected)
|
||||
{
|
||||
return new RopeJoint(body1, body2, x1, y1, x2, y2, maxLength, collideConnected);
|
||||
}
|
||||
|
||||
Fixture * Physics::newFixture(Body * body, Shape * shape, float density)
|
||||
{
|
||||
return new Fixture(body, shape, density);
|
||||
}
|
||||
|
||||
int Physics::getDistance(lua_State * L)
|
||||
{
|
||||
Fixture * fixtureA = luax_checktype<Fixture>(L, 1, "Fixture", PHYSICS_FIXTURE_T);
|
||||
Fixture * fixtureB = luax_checktype<Fixture>(L, 2, "Fixture", PHYSICS_FIXTURE_T);
|
||||
b2DistanceInput i;
|
||||
b2DistanceProxy pA;
|
||||
pA.Set(fixtureA->fixture->GetShape(), 0);
|
||||
b2DistanceProxy pB;
|
||||
pB.Set(fixtureB->fixture->GetShape(), 0);
|
||||
i.proxyA = pA;
|
||||
i.proxyB = pB;
|
||||
i.transformA = fixtureA->fixture->GetBody()->GetTransform();
|
||||
i.transformB = fixtureB->fixture->GetBody()->GetTransform();
|
||||
i.useRadii = true;
|
||||
b2DistanceOutput o;
|
||||
b2SimplexCache c;
|
||||
b2Distance(&o, &c, &i);
|
||||
lua_pushnumber(L, Physics::scaleUp(o.distance));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointA.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointA.y));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointB.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(o.pointB.y));
|
||||
return 5;
|
||||
}
|
||||
|
||||
void Physics::setMeter(int meter)
|
||||
{
|
||||
if (meter < 1) throw love::Exception("Physics error: invalid meter");
|
||||
Physics::meter = meter;
|
||||
}
|
||||
|
||||
int Physics::getMeter()
|
||||
{
|
||||
return meter;
|
||||
}
|
||||
|
||||
void Physics::scaleDown(float & x, float & y)
|
||||
{
|
||||
x /= (float)meter;
|
||||
y /= (float)meter;
|
||||
}
|
||||
|
||||
void Physics::scaleUp(float & x, float & y)
|
||||
{
|
||||
x *= (float)meter;
|
||||
y *= (float)meter;
|
||||
}
|
||||
|
||||
float Physics::scaleDown(float f)
|
||||
{
|
||||
return f/(float)meter;
|
||||
}
|
||||
|
||||
float Physics::scaleUp(float f)
|
||||
{
|
||||
return f*(float)meter;
|
||||
}
|
||||
|
||||
b2Vec2 Physics::scaleDown(const b2Vec2 & v)
|
||||
{
|
||||
b2Vec2 t = v;
|
||||
scaleDown(t.x, t.y);
|
||||
return t;
|
||||
}
|
||||
|
||||
b2Vec2 Physics::scaleUp(const b2Vec2 & v)
|
||||
{
|
||||
b2Vec2 t = v;
|
||||
scaleUp(t.x, t.y);
|
||||
return t;
|
||||
}
|
||||
|
||||
b2AABB Physics::scaleDown(const b2AABB & aabb)
|
||||
{
|
||||
b2AABB t;
|
||||
t.lowerBound = scaleDown(aabb.lowerBound);
|
||||
t.upperBound = scaleDown(aabb.upperBound);
|
||||
return t;
|
||||
}
|
||||
|
||||
b2AABB Physics::scaleUp(const b2AABB & aabb)
|
||||
{
|
||||
b2AABB t;
|
||||
t.lowerBound = scaleUp(aabb.lowerBound);
|
||||
t.upperBound = scaleUp(aabb.upperBound);
|
||||
return t;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+351
-351
@@ -1,351 +1,351 @@
|
||||
/**
|
||||
* 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_PHYSICS_H
|
||||
#define LOVE_PHYSICS_BOX2D_PHYSICS_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Module.h>
|
||||
#include "World.h"
|
||||
#include "Contact.h"
|
||||
#include "Body.h"
|
||||
#include "Fixture.h"
|
||||
#include "Shape.h"
|
||||
#include "CircleShape.h"
|
||||
#include "PolygonShape.h"
|
||||
#include "EdgeShape.h"
|
||||
#include "ChainShape.h"
|
||||
#include "Joint.h"
|
||||
#include "MouseJoint.h"
|
||||
#include "DistanceJoint.h"
|
||||
#include "PrismaticJoint.h"
|
||||
#include "RevoluteJoint.h"
|
||||
#include "PulleyJoint.h"
|
||||
#include "GearJoint.h"
|
||||
#include "FrictionJoint.h"
|
||||
#include "WeldJoint.h"
|
||||
#include "WheelJoint.h"
|
||||
#include "RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
class Physics : public Module
|
||||
{
|
||||
private:
|
||||
|
||||
// The length of one meter in pixels.
|
||||
static int meter;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* 30 pixels in one meter by default.
|
||||
**/
|
||||
static const int DEFAULT_METER = 30;
|
||||
|
||||
// Implements Module.
|
||||
const char * getName() const;
|
||||
|
||||
/**
|
||||
* Creates a new World.
|
||||
* @param gx Gravity along x-axis.
|
||||
* @param gy Gravity along y-axis.
|
||||
* @param sleep Whether the World allows sleep.
|
||||
**/
|
||||
World * newWorld(float gx, float gy, bool sleep);
|
||||
|
||||
/**
|
||||
* Creates a new Body at the specified position.
|
||||
* @param world The world to create the Body in.
|
||||
* @param x The position along the x-axis.
|
||||
* @param x The position along the y-axis.
|
||||
* @param type The type of body to create.
|
||||
**/
|
||||
Body * newBody(World * world, float x, float y, Body::Type type);
|
||||
|
||||
/**
|
||||
* Creates a new Body at (0, 0)
|
||||
* @param world The world to create the Body in.
|
||||
* @param type The type of Body to create.
|
||||
**/
|
||||
Body * newBody(World * world, Body::Type type);
|
||||
|
||||
/**
|
||||
* 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 coordinates.
|
||||
* @param x The offset along the x-axis.
|
||||
* @param y The offset along the y-axis.
|
||||
* @param radius The radius of the circle.
|
||||
**/
|
||||
CircleShape * newCircleShape(float x, float y, float radius);
|
||||
|
||||
/**
|
||||
* Shorthand for creating rectangular PolygonShapes. The rectangle
|
||||
* will be created at the local origin.
|
||||
* @param w The width of the rectangle.
|
||||
* @param h The height of the rectangle.
|
||||
**/
|
||||
PolygonShape * newRectangleShape(float w, float h);
|
||||
|
||||
/**
|
||||
* Shorthand for creating rectangular PolygonShapes. The rectangle
|
||||
* 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.
|
||||
**/
|
||||
PolygonShape * newRectangleShape(float x, float y, float w, float h);
|
||||
|
||||
/**
|
||||
* Shorthand for creating rectangular PolygonShapes. The rectangle
|
||||
* 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 * newRectangleShape(float x, float y, float w, float h, float angle);
|
||||
|
||||
/**
|
||||
* 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 ... A variable number of vertices.
|
||||
**/
|
||||
int newPolygonShape(lua_State * L);
|
||||
|
||||
/**
|
||||
* Creates a new ChainShape.
|
||||
* @param ... A variable number of vertices.
|
||||
**/
|
||||
int newChainShape(lua_State * L);
|
||||
|
||||
/**
|
||||
* Creates a new DistanceJoint connecting body1 with body2.
|
||||
* @param x1 Anchor1 along the x-axis. (World coordinates)
|
||||
* @param y1 Anchor1 along the y-axis. (World coordinates)
|
||||
* @param x2 Anchor2 along the x-axis. (World coordinates)
|
||||
* @param y2 Anchor2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
DistanceJoint * newDistanceJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new MouseJoint connecting the body with an arbitrary point.
|
||||
* @param x Anchor along the x-axis. (World coordinates)
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
**/
|
||||
MouseJoint * newMouseJoint(Body * body, float x, float y);
|
||||
|
||||
/**
|
||||
* Creates a new RevoluteJoint connecting body1 with body2.
|
||||
* @param x Anchor along the x-axis. (World coordinates)
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
RevoluteJoint * newRevoluteJoint(Body * body1, Body * body2, float x, float y, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new PrismaticJoint connecting body1 with body2.
|
||||
* @param xA World-anchor for body1 along the x-axis.
|
||||
* @param yA World-anchor for body1 along the y-axis.
|
||||
* @param xB World-anchor for body2 along the x-axis.
|
||||
* @param yB World-anchor for body2 along the y-axis.
|
||||
* @param ax The x-component of the world-axis.
|
||||
* @param ay The y-component of the world-axis.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
PrismaticJoint * newPrismaticJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new PulleyJoint connecting body1 with body2.
|
||||
* @param groundAnchor1 World ground-anchor for body1.
|
||||
* @param groundAnchor2 World ground-anchor for body2.
|
||||
* @param anchor1 World anchor on body1.
|
||||
* @param anchor2 World anchor on body2.
|
||||
* @param ratio The pulley ratio.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to true.
|
||||
**/
|
||||
PulleyJoint * newPulleyJoint(Body * body1, Body * body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new GearJoint connecting joint1 with joint2.
|
||||
* @param joint1 The first joint.
|
||||
* @param joint2 The second joint.
|
||||
* @param ratio The gear ratio.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
GearJoint * newGearJoint(Joint * joint1, Joint * joint2, float ratio, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new FrictionJoint connecting body1 with body2.
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
FrictionJoint * newFrictionJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new WeldJoint connecting body1 with body2.
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
WeldJoint * newWeldJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new WheelJoint connecting body1 with body2.
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param ax The x-component of the world-axis.
|
||||
* @param ay The y-component of the world-axis.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
WheelJoint * newWheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
RopeJoint * newRopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new Fixture attaching shape to body.
|
||||
* @param body The body to attach the Fixture to.
|
||||
* @param shape The shape to attach to the Fixture,
|
||||
* @param density The density of the Fixture.
|
||||
**/
|
||||
|
||||
Fixture * newFixture(Body * body, Shape * shape, float density);
|
||||
|
||||
/**
|
||||
* Calculates the distance between two Fixtures.
|
||||
* @param fixtureA The first Fixture.
|
||||
* @param fixtureB The sceond Fixture.
|
||||
* @return The distance between them, and the two points closest
|
||||
* to each other.
|
||||
**/
|
||||
int getDistance(lua_State * L);
|
||||
|
||||
/**
|
||||
* Sets the number of pixels in one meter.
|
||||
* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
|
||||
**/
|
||||
static void setMeter(int meter);
|
||||
|
||||
/**
|
||||
* Gets the number of pixels in one meter.
|
||||
* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
|
||||
**/
|
||||
static int getMeter();
|
||||
|
||||
/**
|
||||
* Scales a value down according to the current meter in pixels.
|
||||
* @param f The unscaled input value.
|
||||
**/
|
||||
static float scaleDown(float f);
|
||||
|
||||
/**
|
||||
* Scales a value up according to the current meter in pixels.
|
||||
* @param f The unscaled input value.
|
||||
**/
|
||||
static float scaleUp(float f);
|
||||
|
||||
/**
|
||||
* Scales a point down according to the current meter
|
||||
* in pixels, for instance x = x0/meter, y = x0/meter.
|
||||
* @param x The x-coordinate of the point to scale.
|
||||
* @param y The y-coordinate of the point to scale.
|
||||
**/
|
||||
static void scaleDown(float & x, float & y);
|
||||
|
||||
/**
|
||||
* Scales a point up according to the current meter
|
||||
* in pixels, for instance x = x0/meter, y = x0/meter.
|
||||
* @param x The x-coordinate of the point to scale.
|
||||
* @param y The y-coordinate of the point to scale.
|
||||
**/
|
||||
static void scaleUp(float & x, float & y);
|
||||
|
||||
/**
|
||||
* Scales a b2Vec2 down according to the current meter in pixels.
|
||||
* @param v The unscaled input vector.
|
||||
* @return The scaled vector.
|
||||
**/
|
||||
static b2Vec2 scaleDown(const b2Vec2 & v);
|
||||
|
||||
/**
|
||||
* Scales a b2Vec up according to the current meter in pixels.
|
||||
* @param v The unscaled input vector.
|
||||
* @return The scaled vector.
|
||||
**/
|
||||
static b2Vec2 scaleUp(const b2Vec2 & v);
|
||||
|
||||
/**
|
||||
* Scales a b2AABB down according to the current meter in pixels.
|
||||
* @param v The unscaled input AABB.
|
||||
* @return The scaled AABB.
|
||||
**/
|
||||
static b2AABB scaleDown(const b2AABB & aabb);
|
||||
|
||||
/**
|
||||
* Scales a b2AABB up according to the current meter in pixels.
|
||||
* @param v The unscaled input AABB.
|
||||
* @return The scaled AABB.
|
||||
**/
|
||||
static b2AABB scaleUp(const b2AABB & aabb);
|
||||
|
||||
}; // Physics
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_PHYSICS_H
|
||||
/**
|
||||
* 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_PHYSICS_H
|
||||
#define LOVE_PHYSICS_BOX2D_PHYSICS_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Module.h>
|
||||
#include "World.h"
|
||||
#include "Contact.h"
|
||||
#include "Body.h"
|
||||
#include "Fixture.h"
|
||||
#include "Shape.h"
|
||||
#include "CircleShape.h"
|
||||
#include "PolygonShape.h"
|
||||
#include "EdgeShape.h"
|
||||
#include "ChainShape.h"
|
||||
#include "Joint.h"
|
||||
#include "MouseJoint.h"
|
||||
#include "DistanceJoint.h"
|
||||
#include "PrismaticJoint.h"
|
||||
#include "RevoluteJoint.h"
|
||||
#include "PulleyJoint.h"
|
||||
#include "GearJoint.h"
|
||||
#include "FrictionJoint.h"
|
||||
#include "WeldJoint.h"
|
||||
#include "WheelJoint.h"
|
||||
#include "RopeJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
class Physics : public Module
|
||||
{
|
||||
private:
|
||||
|
||||
// The length of one meter in pixels.
|
||||
static int meter;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* 30 pixels in one meter by default.
|
||||
**/
|
||||
static const int DEFAULT_METER = 30;
|
||||
|
||||
// Implements Module.
|
||||
const char * getName() const;
|
||||
|
||||
/**
|
||||
* Creates a new World.
|
||||
* @param gx Gravity along x-axis.
|
||||
* @param gy Gravity along y-axis.
|
||||
* @param sleep Whether the World allows sleep.
|
||||
**/
|
||||
World * newWorld(float gx, float gy, bool sleep);
|
||||
|
||||
/**
|
||||
* Creates a new Body at the specified position.
|
||||
* @param world The world to create the Body in.
|
||||
* @param x The position along the x-axis.
|
||||
* @param x The position along the y-axis.
|
||||
* @param type The type of body to create.
|
||||
**/
|
||||
Body * newBody(World * world, float x, float y, Body::Type type);
|
||||
|
||||
/**
|
||||
* Creates a new Body at (0, 0)
|
||||
* @param world The world to create the Body in.
|
||||
* @param type The type of Body to create.
|
||||
**/
|
||||
Body * newBody(World * world, Body::Type type);
|
||||
|
||||
/**
|
||||
* 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 coordinates.
|
||||
* @param x The offset along the x-axis.
|
||||
* @param y The offset along the y-axis.
|
||||
* @param radius The radius of the circle.
|
||||
**/
|
||||
CircleShape * newCircleShape(float x, float y, float radius);
|
||||
|
||||
/**
|
||||
* Shorthand for creating rectangular PolygonShapes. The rectangle
|
||||
* will be created at the local origin.
|
||||
* @param w The width of the rectangle.
|
||||
* @param h The height of the rectangle.
|
||||
**/
|
||||
PolygonShape * newRectangleShape(float w, float h);
|
||||
|
||||
/**
|
||||
* Shorthand for creating rectangular PolygonShapes. The rectangle
|
||||
* 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.
|
||||
**/
|
||||
PolygonShape * newRectangleShape(float x, float y, float w, float h);
|
||||
|
||||
/**
|
||||
* Shorthand for creating rectangular PolygonShapes. The rectangle
|
||||
* 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 * newRectangleShape(float x, float y, float w, float h, float angle);
|
||||
|
||||
/**
|
||||
* 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 ... A variable number of vertices.
|
||||
**/
|
||||
int newPolygonShape(lua_State * L);
|
||||
|
||||
/**
|
||||
* Creates a new ChainShape.
|
||||
* @param ... A variable number of vertices.
|
||||
**/
|
||||
int newChainShape(lua_State * L);
|
||||
|
||||
/**
|
||||
* Creates a new DistanceJoint connecting body1 with body2.
|
||||
* @param x1 Anchor1 along the x-axis. (World coordinates)
|
||||
* @param y1 Anchor1 along the y-axis. (World coordinates)
|
||||
* @param x2 Anchor2 along the x-axis. (World coordinates)
|
||||
* @param y2 Anchor2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
DistanceJoint * newDistanceJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new MouseJoint connecting the body with an arbitrary point.
|
||||
* @param x Anchor along the x-axis. (World coordinates)
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
**/
|
||||
MouseJoint * newMouseJoint(Body * body, float x, float y);
|
||||
|
||||
/**
|
||||
* Creates a new RevoluteJoint connecting body1 with body2.
|
||||
* @param x Anchor along the x-axis. (World coordinates)
|
||||
* @param y Anchor along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
RevoluteJoint * newRevoluteJoint(Body * body1, Body * body2, float x, float y, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new PrismaticJoint connecting body1 with body2.
|
||||
* @param xA World-anchor for body1 along the x-axis.
|
||||
* @param yA World-anchor for body1 along the y-axis.
|
||||
* @param xB World-anchor for body2 along the x-axis.
|
||||
* @param yB World-anchor for body2 along the y-axis.
|
||||
* @param ax The x-component of the world-axis.
|
||||
* @param ay The y-component of the world-axis.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
PrismaticJoint * newPrismaticJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new PulleyJoint connecting body1 with body2.
|
||||
* @param groundAnchor1 World ground-anchor for body1.
|
||||
* @param groundAnchor2 World ground-anchor for body2.
|
||||
* @param anchor1 World anchor on body1.
|
||||
* @param anchor2 World anchor on body2.
|
||||
* @param ratio The pulley ratio.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to true.
|
||||
**/
|
||||
PulleyJoint * newPulleyJoint(Body * body1, Body * body2, b2Vec2 groundAnchor1, b2Vec2 groundAnchor2, b2Vec2 anchor1, b2Vec2 anchor2, float ratio, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new GearJoint connecting joint1 with joint2.
|
||||
* @param joint1 The first joint.
|
||||
* @param joint2 The second joint.
|
||||
* @param ratio The gear ratio.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
GearJoint * newGearJoint(Joint * joint1, Joint * joint2, float ratio, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new FrictionJoint connecting body1 with body2.
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
FrictionJoint * newFrictionJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new WeldJoint connecting body1 with body2.
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
WeldJoint * newWeldJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new WheelJoint connecting body1 with body2.
|
||||
* @param xA Anchor for body 1 along the x-axis. (World coordinates)
|
||||
* @param yA Anchor for body 1 along the y-axis. (World coordinates)
|
||||
* @param xB Anchor for body 2 along the x-axis. (World coordinates)
|
||||
* @param yB Anchor for body 2 along the y-axis. (World coordinates)
|
||||
* @param ax The x-component of the world-axis.
|
||||
* @param ay The y-component of the world-axis.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
WheelJoint * newWheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* @param collideConnected Whether the connected bodies should collide with each other. Defaults to false.
|
||||
**/
|
||||
RopeJoint * newRopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected);
|
||||
|
||||
/**
|
||||
* Creates a new Fixture attaching shape to body.
|
||||
* @param body The body to attach the Fixture to.
|
||||
* @param shape The shape to attach to the Fixture,
|
||||
* @param density The density of the Fixture.
|
||||
**/
|
||||
|
||||
Fixture * newFixture(Body * body, Shape * shape, float density);
|
||||
|
||||
/**
|
||||
* Calculates the distance between two Fixtures.
|
||||
* @param fixtureA The first Fixture.
|
||||
* @param fixtureB The sceond Fixture.
|
||||
* @return The distance between them, and the two points closest
|
||||
* to each other.
|
||||
**/
|
||||
int getDistance(lua_State * L);
|
||||
|
||||
/**
|
||||
* Sets the number of pixels in one meter.
|
||||
* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
|
||||
**/
|
||||
static void setMeter(int meter);
|
||||
|
||||
/**
|
||||
* Gets the number of pixels in one meter.
|
||||
* @param pixels The number of pixels in one meter. (1m ~= 3.3ft).
|
||||
**/
|
||||
static int getMeter();
|
||||
|
||||
/**
|
||||
* Scales a value down according to the current meter in pixels.
|
||||
* @param f The unscaled input value.
|
||||
**/
|
||||
static float scaleDown(float f);
|
||||
|
||||
/**
|
||||
* Scales a value up according to the current meter in pixels.
|
||||
* @param f The unscaled input value.
|
||||
**/
|
||||
static float scaleUp(float f);
|
||||
|
||||
/**
|
||||
* Scales a point down according to the current meter
|
||||
* in pixels, for instance x = x0/meter, y = x0/meter.
|
||||
* @param x The x-coordinate of the point to scale.
|
||||
* @param y The y-coordinate of the point to scale.
|
||||
**/
|
||||
static void scaleDown(float & x, float & y);
|
||||
|
||||
/**
|
||||
* Scales a point up according to the current meter
|
||||
* in pixels, for instance x = x0/meter, y = x0/meter.
|
||||
* @param x The x-coordinate of the point to scale.
|
||||
* @param y The y-coordinate of the point to scale.
|
||||
**/
|
||||
static void scaleUp(float & x, float & y);
|
||||
|
||||
/**
|
||||
* Scales a b2Vec2 down according to the current meter in pixels.
|
||||
* @param v The unscaled input vector.
|
||||
* @return The scaled vector.
|
||||
**/
|
||||
static b2Vec2 scaleDown(const b2Vec2 & v);
|
||||
|
||||
/**
|
||||
* Scales a b2Vec up according to the current meter in pixels.
|
||||
* @param v The unscaled input vector.
|
||||
* @return The scaled vector.
|
||||
**/
|
||||
static b2Vec2 scaleUp(const b2Vec2 & v);
|
||||
|
||||
/**
|
||||
* Scales a b2AABB down according to the current meter in pixels.
|
||||
* @param v The unscaled input AABB.
|
||||
* @return The scaled AABB.
|
||||
**/
|
||||
static b2AABB scaleDown(const b2AABB & aabb);
|
||||
|
||||
/**
|
||||
* Scales a b2AABB up according to the current meter in pixels.
|
||||
* @param v The unscaled input AABB.
|
||||
* @return The scaled AABB.
|
||||
**/
|
||||
static b2AABB scaleUp(const b2AABB & aabb);
|
||||
|
||||
}; // Physics
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_PHYSICS_H
|
||||
|
||||
@@ -1,64 +1,64 @@
|
||||
/**
|
||||
* 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 "PolygonShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include <common/Memoizer.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PolygonShape::PolygonShape(b2PolygonShape * p)
|
||||
: Shape(p)
|
||||
{
|
||||
}
|
||||
|
||||
PolygonShape::~PolygonShape()
|
||||
{
|
||||
Memoizer::remove(shape);
|
||||
delete shape;
|
||||
shape = NULL;
|
||||
}
|
||||
|
||||
int PolygonShape::getPoints(lua_State * L)
|
||||
{
|
||||
love::luax_assert_argc(L, 0);
|
||||
b2PolygonShape * p = (b2PolygonShape *)shape;
|
||||
int count = p->GetVertexCount();
|
||||
for(int i = 0;i<count; i++)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(p->GetVertex(i));
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
}
|
||||
return count*2;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "PolygonShape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include <common/Memoizer.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PolygonShape::PolygonShape(b2PolygonShape * p)
|
||||
: Shape(p)
|
||||
{
|
||||
}
|
||||
|
||||
PolygonShape::~PolygonShape()
|
||||
{
|
||||
Memoizer::remove(shape);
|
||||
delete shape;
|
||||
shape = NULL;
|
||||
}
|
||||
|
||||
int PolygonShape::getPoints(lua_State * L)
|
||||
{
|
||||
love::luax_assert_argc(L, 0);
|
||||
b2PolygonShape * p = (b2PolygonShape *)shape;
|
||||
int count = p->GetVertexCount();
|
||||
for (int i = 0;i<count; i++)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(p->GetVertex(i));
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
}
|
||||
return count*2;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,67 +1,67 @@
|
||||
/**
|
||||
* 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_POLYGON_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_POLYGON_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* You should know what a Polygon is. :)
|
||||
*
|
||||
* This class is needed so that we can easily get
|
||||
* the transformed points in Lua. By calling shape:getPoints(),
|
||||
* the result can be passed directly to love.graphics.polygon().
|
||||
**/
|
||||
class PolygonShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new PolygonShape from the parent Body and
|
||||
* a Box2D polygon definition.
|
||||
* @param body The parent Body.
|
||||
* @param def The polygon definition.
|
||||
**/
|
||||
PolygonShape(b2PolygonShape * p);
|
||||
|
||||
virtual ~PolygonShape();
|
||||
|
||||
/**
|
||||
* Returns the transformed points of the polygon.
|
||||
* This function is useful for debug drawing and such.
|
||||
*
|
||||
* The result can be directly passed into love.graphics.polygon().
|
||||
**/
|
||||
int getPoints(lua_State * L);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_POLYGON_SHAPE_H
|
||||
/**
|
||||
* 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_POLYGON_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_POLYGON_SHAPE_H
|
||||
|
||||
// Module
|
||||
#include "Shape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* You should know what a Polygon is. :)
|
||||
*
|
||||
* This class is needed so that we can easily get
|
||||
* the transformed points in Lua. By calling shape:getPoints(),
|
||||
* the result can be passed directly to love.graphics.polygon().
|
||||
**/
|
||||
class PolygonShape : public Shape
|
||||
{
|
||||
public:
|
||||
|
||||
/**
|
||||
* Create a new PolygonShape from the parent Body and
|
||||
* a Box2D polygon definition.
|
||||
* @param body The parent Body.
|
||||
* @param def The polygon definition.
|
||||
**/
|
||||
PolygonShape(b2PolygonShape * p);
|
||||
|
||||
virtual ~PolygonShape();
|
||||
|
||||
/**
|
||||
* Returns the transformed points of the polygon.
|
||||
* This function is useful for debug drawing and such.
|
||||
*
|
||||
* The result can be directly passed into love.graphics.polygon().
|
||||
**/
|
||||
int getPoints(lua_State * L);
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_POLYGON_SHAPE_H
|
||||
|
||||
@@ -1,144 +1,144 @@
|
||||
/**
|
||||
* 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 "PrismaticJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PrismaticJoint::PrismaticJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
b2PrismaticJointDef def;
|
||||
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)), b2Vec2(ax,ay));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.lowerTranslation = 0.0f;
|
||||
def.upperTranslation = 100.0f;
|
||||
def.enableLimit = true;
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2PrismaticJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
PrismaticJoint::~PrismaticJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
float PrismaticJoint::getJointTranslation() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointTranslation());
|
||||
}
|
||||
|
||||
float PrismaticJoint::getJointSpeed() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointSpeed());
|
||||
}
|
||||
|
||||
void PrismaticJoint::enableMotor(bool motor)
|
||||
{
|
||||
return joint->EnableMotor(motor);
|
||||
}
|
||||
|
||||
bool PrismaticJoint::isMotorEnabled() const
|
||||
{
|
||||
return joint->IsMotorEnabled();
|
||||
}
|
||||
|
||||
void PrismaticJoint::setMaxMotorForce(float force)
|
||||
{
|
||||
joint->SetMaxMotorForce(Physics::scaleDown(force));
|
||||
}
|
||||
|
||||
void PrismaticJoint::setMotorSpeed(float speed)
|
||||
{
|
||||
joint->SetMotorSpeed(Physics::scaleDown(speed));
|
||||
}
|
||||
|
||||
float PrismaticJoint::getMotorSpeed() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMotorSpeed());
|
||||
}
|
||||
|
||||
float PrismaticJoint::getMotorForce(float inv_dt) const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMotorForce(inv_dt));
|
||||
}
|
||||
|
||||
float PrismaticJoint::getMaxMotorForce() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxMotorForce());
|
||||
}
|
||||
|
||||
void PrismaticJoint::enableLimit(bool limit)
|
||||
{
|
||||
joint->EnableLimit(limit);
|
||||
}
|
||||
|
||||
bool PrismaticJoint::isLimitEnabled() const
|
||||
{
|
||||
return joint->IsLimitEnabled();
|
||||
}
|
||||
|
||||
void PrismaticJoint::setUpperLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(joint->GetLowerLimit(), Physics::scaleDown(limit));
|
||||
}
|
||||
|
||||
void PrismaticJoint::setLowerLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(Physics::scaleDown(limit), joint->GetUpperLimit());
|
||||
}
|
||||
|
||||
void PrismaticJoint::setLimits(float lower, float upper)
|
||||
{
|
||||
joint->SetLimits(Physics::scaleDown(lower), Physics::scaleDown(upper));
|
||||
}
|
||||
|
||||
float PrismaticJoint::getLowerLimit() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLowerLimit());
|
||||
}
|
||||
|
||||
float PrismaticJoint::getUpperLimit() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetUpperLimit());
|
||||
}
|
||||
|
||||
int PrismaticJoint::getLimits(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetLowerLimit()));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetUpperLimit()));
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "PrismaticJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PrismaticJoint::PrismaticJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
b2PrismaticJointDef def;
|
||||
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)), b2Vec2(ax,ay));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.lowerTranslation = 0.0f;
|
||||
def.upperTranslation = 100.0f;
|
||||
def.enableLimit = true;
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2PrismaticJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
PrismaticJoint::~PrismaticJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
float PrismaticJoint::getJointTranslation() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointTranslation());
|
||||
}
|
||||
|
||||
float PrismaticJoint::getJointSpeed() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointSpeed());
|
||||
}
|
||||
|
||||
void PrismaticJoint::enableMotor(bool motor)
|
||||
{
|
||||
return joint->EnableMotor(motor);
|
||||
}
|
||||
|
||||
bool PrismaticJoint::isMotorEnabled() const
|
||||
{
|
||||
return joint->IsMotorEnabled();
|
||||
}
|
||||
|
||||
void PrismaticJoint::setMaxMotorForce(float force)
|
||||
{
|
||||
joint->SetMaxMotorForce(Physics::scaleDown(force));
|
||||
}
|
||||
|
||||
void PrismaticJoint::setMotorSpeed(float speed)
|
||||
{
|
||||
joint->SetMotorSpeed(Physics::scaleDown(speed));
|
||||
}
|
||||
|
||||
float PrismaticJoint::getMotorSpeed() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMotorSpeed());
|
||||
}
|
||||
|
||||
float PrismaticJoint::getMotorForce(float inv_dt) const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMotorForce(inv_dt));
|
||||
}
|
||||
|
||||
float PrismaticJoint::getMaxMotorForce() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetMaxMotorForce());
|
||||
}
|
||||
|
||||
void PrismaticJoint::enableLimit(bool limit)
|
||||
{
|
||||
joint->EnableLimit(limit);
|
||||
}
|
||||
|
||||
bool PrismaticJoint::isLimitEnabled() const
|
||||
{
|
||||
return joint->IsLimitEnabled();
|
||||
}
|
||||
|
||||
void PrismaticJoint::setUpperLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(joint->GetLowerLimit(), Physics::scaleDown(limit));
|
||||
}
|
||||
|
||||
void PrismaticJoint::setLowerLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(Physics::scaleDown(limit), joint->GetUpperLimit());
|
||||
}
|
||||
|
||||
void PrismaticJoint::setLimits(float lower, float upper)
|
||||
{
|
||||
joint->SetLimits(Physics::scaleDown(lower), Physics::scaleDown(upper));
|
||||
}
|
||||
|
||||
float PrismaticJoint::getLowerLimit() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLowerLimit());
|
||||
}
|
||||
|
||||
float PrismaticJoint::getUpperLimit() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetUpperLimit());
|
||||
}
|
||||
|
||||
int PrismaticJoint::getLimits(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetLowerLimit()));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetUpperLimit()));
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,147 +1,147 @@
|
||||
/**
|
||||
* 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_PRISMATIC_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_PRISMATIC_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* PrismaticJoints allow shapes to move in relation to eachother
|
||||
* along a defined axis.
|
||||
**/
|
||||
class PrismaticJoint : public Joint
|
||||
{
|
||||
private:
|
||||
|
||||
// The Box2D prismatic joint object.
|
||||
b2PrismaticJoint * joint;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new PrismaticJoint connecting body1 and body2.
|
||||
**/
|
||||
PrismaticJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
virtual ~PrismaticJoint();
|
||||
|
||||
/**
|
||||
* Get the current joint translation, usually in meters.
|
||||
**/
|
||||
float getJointTranslation() const;
|
||||
|
||||
/**
|
||||
* Get the current joint translation speed, usually in meters per second.
|
||||
**/
|
||||
float getJointSpeed() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint motor.
|
||||
**/
|
||||
void enableMotor(bool motor);
|
||||
|
||||
/**
|
||||
* Checks whether the motor is enabled.
|
||||
**/
|
||||
bool isMotorEnabled() const;
|
||||
|
||||
/**
|
||||
* Set the maximum motor force, usually in N.
|
||||
**/
|
||||
void setMaxMotorForce(float force);
|
||||
|
||||
/**
|
||||
* Set the motor speed, usually in meters per second.
|
||||
**/
|
||||
void setMotorSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Get the motor speed, usually in meters per second.
|
||||
**/
|
||||
float getMotorSpeed() const;
|
||||
|
||||
/**
|
||||
* Get the current motor force, usually in N.
|
||||
* @param inv_dt The inverse time step.
|
||||
**/
|
||||
float getMotorForce(float inv_dt) const;
|
||||
|
||||
/**
|
||||
* Get the maximum motor force, usually in N.
|
||||
**/
|
||||
float getMaxMotorForce() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint limit.
|
||||
**/
|
||||
void enableLimit(bool limit);
|
||||
|
||||
/**
|
||||
* Checks whether limits are enabled.
|
||||
**/
|
||||
bool isLimitEnabled() const;
|
||||
|
||||
/**
|
||||
* Sets the upper limit, usually in meters.
|
||||
**/
|
||||
void setUpperLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the lower limit, usually in meters.
|
||||
**/
|
||||
void setLowerLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the limits, usually in meters.
|
||||
**/
|
||||
void setLimits(float lower, float upper);
|
||||
|
||||
/**
|
||||
* Gets the lower limit, usually in meters.
|
||||
**/
|
||||
float getLowerLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the upper limit, usually in meters.
|
||||
**/
|
||||
float getUpperLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the limits, usually in meters.
|
||||
* @returns The upper limit.
|
||||
* @returns The lower limit.
|
||||
**/
|
||||
int getLimits(lua_State * L);
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_PRISMATIC_JOINT_H
|
||||
/**
|
||||
* 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_PRISMATIC_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_PRISMATIC_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* PrismaticJoints allow shapes to move in relation to eachother
|
||||
* along a defined axis.
|
||||
**/
|
||||
class PrismaticJoint : public Joint
|
||||
{
|
||||
private:
|
||||
|
||||
// The Box2D prismatic joint object.
|
||||
b2PrismaticJoint * joint;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new PrismaticJoint connecting body1 and body2.
|
||||
**/
|
||||
PrismaticJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
virtual ~PrismaticJoint();
|
||||
|
||||
/**
|
||||
* Get the current joint translation, usually in meters.
|
||||
**/
|
||||
float getJointTranslation() const;
|
||||
|
||||
/**
|
||||
* Get the current joint translation speed, usually in meters per second.
|
||||
**/
|
||||
float getJointSpeed() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint motor.
|
||||
**/
|
||||
void enableMotor(bool motor);
|
||||
|
||||
/**
|
||||
* Checks whether the motor is enabled.
|
||||
**/
|
||||
bool isMotorEnabled() const;
|
||||
|
||||
/**
|
||||
* Set the maximum motor force, usually in N.
|
||||
**/
|
||||
void setMaxMotorForce(float force);
|
||||
|
||||
/**
|
||||
* Set the motor speed, usually in meters per second.
|
||||
**/
|
||||
void setMotorSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Get the motor speed, usually in meters per second.
|
||||
**/
|
||||
float getMotorSpeed() const;
|
||||
|
||||
/**
|
||||
* Get the current motor force, usually in N.
|
||||
* @param inv_dt The inverse time step.
|
||||
**/
|
||||
float getMotorForce(float inv_dt) const;
|
||||
|
||||
/**
|
||||
* Get the maximum motor force, usually in N.
|
||||
**/
|
||||
float getMaxMotorForce() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint limit.
|
||||
**/
|
||||
void enableLimit(bool limit);
|
||||
|
||||
/**
|
||||
* Checks whether limits are enabled.
|
||||
**/
|
||||
bool isLimitEnabled() const;
|
||||
|
||||
/**
|
||||
* Sets the upper limit, usually in meters.
|
||||
**/
|
||||
void setUpperLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the lower limit, usually in meters.
|
||||
**/
|
||||
void setLowerLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the limits, usually in meters.
|
||||
**/
|
||||
void setLimits(float lower, float upper);
|
||||
|
||||
/**
|
||||
* Gets the lower limit, usually in meters.
|
||||
**/
|
||||
float getLowerLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the upper limit, usually in meters.
|
||||
**/
|
||||
float getUpperLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the limits, usually in meters.
|
||||
* @returns The upper limit.
|
||||
* @returns The lower limit.
|
||||
**/
|
||||
int getLimits(lua_State * L);
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_PRISMATIC_JOINT_H
|
||||
|
||||
@@ -1,77 +1,77 @@
|
||||
/**
|
||||
* 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 "PulleyJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PulleyJoint::PulleyJoint(Body * bodyA, Body * bodyB, b2Vec2 groundAnchorA, b2Vec2 groundAnchorB, b2Vec2 anchorA, b2Vec2 anchorB, float ratio, bool collideConnected)
|
||||
: Joint(bodyA, bodyB), joint(NULL)
|
||||
{
|
||||
b2PulleyJointDef def;
|
||||
def.Initialize(bodyA->body, bodyB->body, Physics::scaleDown(groundAnchorA), Physics::scaleDown(groundAnchorB), \
|
||||
Physics::scaleDown(anchorA), Physics::scaleDown(anchorB), ratio);
|
||||
def.collideConnected = collideConnected;
|
||||
|
||||
joint = (b2PulleyJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
PulleyJoint::~PulleyJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
int PulleyJoint::getGroundAnchors(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorA().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorA().y));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorB().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorB().y));
|
||||
return 4;
|
||||
}
|
||||
|
||||
float PulleyJoint::getLengthA() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLengthA());
|
||||
}
|
||||
|
||||
float PulleyJoint::getLengthB() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLengthB());
|
||||
}
|
||||
|
||||
float PulleyJoint::getRatio() const
|
||||
{
|
||||
return joint->GetRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "PulleyJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PulleyJoint::PulleyJoint(Body * bodyA, Body * bodyB, b2Vec2 groundAnchorA, b2Vec2 groundAnchorB, b2Vec2 anchorA, b2Vec2 anchorB, float ratio, bool collideConnected)
|
||||
: Joint(bodyA, bodyB), joint(NULL)
|
||||
{
|
||||
b2PulleyJointDef def;
|
||||
def.Initialize(bodyA->body, bodyB->body, Physics::scaleDown(groundAnchorA), Physics::scaleDown(groundAnchorB), \
|
||||
Physics::scaleDown(anchorA), Physics::scaleDown(anchorB), ratio);
|
||||
def.collideConnected = collideConnected;
|
||||
|
||||
joint = (b2PulleyJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
PulleyJoint::~PulleyJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
int PulleyJoint::getGroundAnchors(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorA().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorA().y));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorB().x));
|
||||
lua_pushnumber(L, Physics::scaleUp(joint->GetGroundAnchorB().y));
|
||||
return 4;
|
||||
}
|
||||
|
||||
float PulleyJoint::getLengthA() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLengthA());
|
||||
}
|
||||
|
||||
float PulleyJoint::getLengthB() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetLengthB());
|
||||
}
|
||||
|
||||
float PulleyJoint::getRatio() const
|
||||
{
|
||||
return joint->GetRatio();
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,80 +1,80 @@
|
||||
/**
|
||||
* 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_PULLEY_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_PULLEY_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* The PulleyJoint The pulley connects two bodies to ground and
|
||||
* to each other. As one body goes up, the other goes down. The
|
||||
* total length of the pulley rope is conserved according to the
|
||||
* initial configuration: length1 + ratio * length2 <= constant.
|
||||
**/
|
||||
class PulleyJoint : public Joint
|
||||
{
|
||||
private:
|
||||
// The Box2D DistanceJoint object.
|
||||
b2PulleyJoint * joint;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a PulleyJoint connecting bodyA to bodyB.
|
||||
**/
|
||||
PulleyJoint(Body * bodyA, Body * bodyB, b2Vec2 groundAnchorA, b2Vec2 groundAnchorB, b2Vec2 anchorA, b2Vec2 anchorB, float ratio, bool collideConnected);
|
||||
|
||||
virtual ~PulleyJoint();
|
||||
|
||||
/**
|
||||
* Gets the ground anchors position in world
|
||||
* coordinates.
|
||||
**/
|
||||
int getGroundAnchors(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the current length of the segment attached to bodyA.
|
||||
**/
|
||||
float getLengthA() const;
|
||||
|
||||
/**
|
||||
* Gets the current length of the segment attached to bodyB.
|
||||
**/
|
||||
float getLengthB() const;
|
||||
|
||||
/**
|
||||
* Gets the pulley ratio.
|
||||
**/
|
||||
float getRatio() const;
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_PULLEY_JOINT_H
|
||||
/**
|
||||
* 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_PULLEY_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_PULLEY_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* The PulleyJoint The pulley connects two bodies to ground and
|
||||
* to each other. As one body goes up, the other goes down. The
|
||||
* total length of the pulley rope is conserved according to the
|
||||
* initial configuration: length1 + ratio * length2 <= constant.
|
||||
**/
|
||||
class PulleyJoint : public Joint
|
||||
{
|
||||
private:
|
||||
// The Box2D DistanceJoint object.
|
||||
b2PulleyJoint * joint;
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a PulleyJoint connecting bodyA to bodyB.
|
||||
**/
|
||||
PulleyJoint(Body * bodyA, Body * bodyB, b2Vec2 groundAnchorA, b2Vec2 groundAnchorB, b2Vec2 anchorA, b2Vec2 anchorB, float ratio, bool collideConnected);
|
||||
|
||||
virtual ~PulleyJoint();
|
||||
|
||||
/**
|
||||
* Gets the ground anchors position in world
|
||||
* coordinates.
|
||||
**/
|
||||
int getGroundAnchors(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the current length of the segment attached to bodyA.
|
||||
**/
|
||||
float getLengthA() const;
|
||||
|
||||
/**
|
||||
* Gets the current length of the segment attached to bodyB.
|
||||
**/
|
||||
float getLengthB() const;
|
||||
|
||||
/**
|
||||
* Gets the pulley ratio.
|
||||
**/
|
||||
float getRatio() const;
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_PULLEY_JOINT_H
|
||||
|
||||
@@ -1,140 +1,140 @@
|
||||
/**
|
||||
* 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 "RevoluteJoint.h"
|
||||
|
||||
#include <common/math.h>
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
RevoluteJoint::RevoluteJoint(Body * body1, Body * body2, float x, float y, bool collideConnected)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
b2RevoluteJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x,y)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2RevoluteJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
RevoluteJoint::~RevoluteJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
float RevoluteJoint::getJointAngle() const
|
||||
{
|
||||
return joint->GetJointAngle();
|
||||
}
|
||||
|
||||
float RevoluteJoint::getJointSpeed() const
|
||||
{
|
||||
return joint->GetJointSpeed();
|
||||
}
|
||||
|
||||
void RevoluteJoint::enableMotor(bool motor)
|
||||
{
|
||||
return joint->EnableMotor(motor);
|
||||
}
|
||||
|
||||
bool RevoluteJoint::isMotorEnabled() const
|
||||
{
|
||||
return joint->IsMotorEnabled();
|
||||
}
|
||||
|
||||
void RevoluteJoint::setMaxMotorTorque(float torque)
|
||||
{
|
||||
joint->SetMaxMotorTorque(Physics::scaleDown(Physics::scaleDown(torque)));
|
||||
}
|
||||
|
||||
void RevoluteJoint::setMotorSpeed(float speed)
|
||||
{
|
||||
joint->SetMotorSpeed(speed);
|
||||
}
|
||||
|
||||
float RevoluteJoint::getMotorSpeed() const
|
||||
{
|
||||
return joint->GetMotorSpeed();
|
||||
}
|
||||
|
||||
float RevoluteJoint::getMotorTorque(float inv_dt) const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMotorTorque(inv_dt)));
|
||||
}
|
||||
|
||||
float RevoluteJoint::getMaxMotorTorque() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMaxMotorTorque()));
|
||||
}
|
||||
|
||||
void RevoluteJoint::enableLimit(bool limit)
|
||||
{
|
||||
joint->EnableLimit(limit);
|
||||
}
|
||||
|
||||
bool RevoluteJoint::isLimitEnabled() const
|
||||
{
|
||||
return joint->IsLimitEnabled();
|
||||
}
|
||||
|
||||
void RevoluteJoint::setUpperLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(joint->GetLowerLimit(), limit);
|
||||
}
|
||||
|
||||
void RevoluteJoint::setLowerLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(limit, joint->GetUpperLimit());
|
||||
}
|
||||
|
||||
void RevoluteJoint::setLimits(float lower, float upper)
|
||||
{
|
||||
joint->SetLimits(lower, upper);
|
||||
}
|
||||
|
||||
float RevoluteJoint::getLowerLimit() const
|
||||
{
|
||||
return joint->GetLowerLimit();
|
||||
}
|
||||
|
||||
float RevoluteJoint::getUpperLimit() const
|
||||
{
|
||||
return joint->GetUpperLimit();
|
||||
}
|
||||
|
||||
int RevoluteJoint::getLimits(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, joint->GetLowerLimit());
|
||||
lua_pushnumber(L, joint->GetUpperLimit());
|
||||
return 2;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "RevoluteJoint.h"
|
||||
|
||||
#include <common/math.h>
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
RevoluteJoint::RevoluteJoint(Body * body1, Body * body2, float x, float y, bool collideConnected)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
b2RevoluteJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(x,y)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2RevoluteJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
RevoluteJoint::~RevoluteJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
float RevoluteJoint::getJointAngle() const
|
||||
{
|
||||
return joint->GetJointAngle();
|
||||
}
|
||||
|
||||
float RevoluteJoint::getJointSpeed() const
|
||||
{
|
||||
return joint->GetJointSpeed();
|
||||
}
|
||||
|
||||
void RevoluteJoint::enableMotor(bool motor)
|
||||
{
|
||||
return joint->EnableMotor(motor);
|
||||
}
|
||||
|
||||
bool RevoluteJoint::isMotorEnabled() const
|
||||
{
|
||||
return joint->IsMotorEnabled();
|
||||
}
|
||||
|
||||
void RevoluteJoint::setMaxMotorTorque(float torque)
|
||||
{
|
||||
joint->SetMaxMotorTorque(Physics::scaleDown(Physics::scaleDown(torque)));
|
||||
}
|
||||
|
||||
void RevoluteJoint::setMotorSpeed(float speed)
|
||||
{
|
||||
joint->SetMotorSpeed(speed);
|
||||
}
|
||||
|
||||
float RevoluteJoint::getMotorSpeed() const
|
||||
{
|
||||
return joint->GetMotorSpeed();
|
||||
}
|
||||
|
||||
float RevoluteJoint::getMotorTorque(float inv_dt) const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMotorTorque(inv_dt)));
|
||||
}
|
||||
|
||||
float RevoluteJoint::getMaxMotorTorque() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMaxMotorTorque()));
|
||||
}
|
||||
|
||||
void RevoluteJoint::enableLimit(bool limit)
|
||||
{
|
||||
joint->EnableLimit(limit);
|
||||
}
|
||||
|
||||
bool RevoluteJoint::isLimitEnabled() const
|
||||
{
|
||||
return joint->IsLimitEnabled();
|
||||
}
|
||||
|
||||
void RevoluteJoint::setUpperLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(joint->GetLowerLimit(), limit);
|
||||
}
|
||||
|
||||
void RevoluteJoint::setLowerLimit(float limit)
|
||||
{
|
||||
joint->SetLimits(limit, joint->GetUpperLimit());
|
||||
}
|
||||
|
||||
void RevoluteJoint::setLimits(float lower, float upper)
|
||||
{
|
||||
joint->SetLimits(lower, upper);
|
||||
}
|
||||
|
||||
float RevoluteJoint::getLowerLimit() const
|
||||
{
|
||||
return joint->GetLowerLimit();
|
||||
}
|
||||
|
||||
float RevoluteJoint::getUpperLimit() const
|
||||
{
|
||||
return joint->GetUpperLimit();
|
||||
}
|
||||
|
||||
int RevoluteJoint::getLimits(lua_State * L)
|
||||
{
|
||||
lua_pushnumber(L, joint->GetLowerLimit());
|
||||
lua_pushnumber(L, joint->GetUpperLimit());
|
||||
return 2;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,147 +1,147 @@
|
||||
/**
|
||||
* 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_REVOLUTE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* A RevoluteJoint allows two bodies relative rotation
|
||||
* around a single point.
|
||||
**/
|
||||
class RevoluteJoint : public Joint
|
||||
{
|
||||
private:
|
||||
|
||||
// The Box2D revolute joint object.
|
||||
b2RevoluteJoint * joint;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new RevoluteJoint connecting body1 and body2.
|
||||
**/
|
||||
RevoluteJoint(Body * body1, Body * body2, float x, float y, bool collideConnected);
|
||||
|
||||
virtual ~RevoluteJoint();
|
||||
|
||||
/**
|
||||
* Get the current joint angle in degrees.
|
||||
**/
|
||||
float getJointAngle() const;
|
||||
|
||||
/**
|
||||
* Get the current joint angle speed in degrees per second.
|
||||
**/
|
||||
float getJointSpeed() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint motor.
|
||||
**/
|
||||
void enableMotor(bool motor);
|
||||
|
||||
/**
|
||||
* Checks whether the motor is enabled.
|
||||
**/
|
||||
bool isMotorEnabled() const;
|
||||
|
||||
/**
|
||||
* Set the maximum motor torque, usually in N-m.
|
||||
**/
|
||||
void setMaxMotorTorque(float torque);
|
||||
|
||||
/**
|
||||
* Sets the motor speed in radians per second.
|
||||
**/
|
||||
void setMotorSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Gets the motor speed in radians per second.
|
||||
**/
|
||||
float getMotorSpeed() const;
|
||||
|
||||
/**
|
||||
* Get the current motor torque, usually in N-m.
|
||||
* @param inv_dt The inverse timestep.
|
||||
**/
|
||||
float getMotorTorque(float inv_dt) const;
|
||||
|
||||
/**
|
||||
* Get the maximum motor torque, usually in N-m.
|
||||
**/
|
||||
float getMaxMotorTorque() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint limit.
|
||||
**/
|
||||
void enableLimit(bool limit);
|
||||
|
||||
/**
|
||||
* Checks whether limits are enabled.
|
||||
**/
|
||||
bool isLimitEnabled() const;
|
||||
|
||||
/**
|
||||
* Sets the upper limit in degrees.
|
||||
**/
|
||||
void setUpperLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the lower limit in degrees.
|
||||
**/
|
||||
void setLowerLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the limits in degrees.
|
||||
**/
|
||||
void setLimits(float lower, float upper);
|
||||
|
||||
/**
|
||||
* Gets the lower limit in degrees.
|
||||
**/
|
||||
float getLowerLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the upper limit in degrees.
|
||||
**/
|
||||
float getUpperLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the limits in degrees.
|
||||
* @returns The lower limit.
|
||||
* @returns The upper limit.
|
||||
**/
|
||||
int getLimits(lua_State * L);
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H
|
||||
/**
|
||||
* 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_REVOLUTE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* A RevoluteJoint allows two bodies relative rotation
|
||||
* around a single point.
|
||||
**/
|
||||
class RevoluteJoint : public Joint
|
||||
{
|
||||
private:
|
||||
|
||||
// The Box2D revolute joint object.
|
||||
b2RevoluteJoint * joint;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new RevoluteJoint connecting body1 and body2.
|
||||
**/
|
||||
RevoluteJoint(Body * body1, Body * body2, float x, float y, bool collideConnected);
|
||||
|
||||
virtual ~RevoluteJoint();
|
||||
|
||||
/**
|
||||
* Get the current joint angle in degrees.
|
||||
**/
|
||||
float getJointAngle() const;
|
||||
|
||||
/**
|
||||
* Get the current joint angle speed in degrees per second.
|
||||
**/
|
||||
float getJointSpeed() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint motor.
|
||||
**/
|
||||
void enableMotor(bool motor);
|
||||
|
||||
/**
|
||||
* Checks whether the motor is enabled.
|
||||
**/
|
||||
bool isMotorEnabled() const;
|
||||
|
||||
/**
|
||||
* Set the maximum motor torque, usually in N-m.
|
||||
**/
|
||||
void setMaxMotorTorque(float torque);
|
||||
|
||||
/**
|
||||
* Sets the motor speed in radians per second.
|
||||
**/
|
||||
void setMotorSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Gets the motor speed in radians per second.
|
||||
**/
|
||||
float getMotorSpeed() const;
|
||||
|
||||
/**
|
||||
* Get the current motor torque, usually in N-m.
|
||||
* @param inv_dt The inverse timestep.
|
||||
**/
|
||||
float getMotorTorque(float inv_dt) const;
|
||||
|
||||
/**
|
||||
* Get the maximum motor torque, usually in N-m.
|
||||
**/
|
||||
float getMaxMotorTorque() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint limit.
|
||||
**/
|
||||
void enableLimit(bool limit);
|
||||
|
||||
/**
|
||||
* Checks whether limits are enabled.
|
||||
**/
|
||||
bool isLimitEnabled() const;
|
||||
|
||||
/**
|
||||
* Sets the upper limit in degrees.
|
||||
**/
|
||||
void setUpperLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the lower limit in degrees.
|
||||
**/
|
||||
void setLowerLimit(float limit);
|
||||
|
||||
/**
|
||||
* Sets the limits in degrees.
|
||||
**/
|
||||
void setLimits(float lower, float upper);
|
||||
|
||||
/**
|
||||
* Gets the lower limit in degrees.
|
||||
**/
|
||||
float getLowerLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the upper limit in degrees.
|
||||
**/
|
||||
float getUpperLimit() const;
|
||||
|
||||
/**
|
||||
* Gets the limits in degrees.
|
||||
* @returns The lower limit.
|
||||
* @returns The upper limit.
|
||||
**/
|
||||
int getLimits(lua_State * L);
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_REVOLUTE_JOINT_H
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -31,7 +31,7 @@ namespace physics
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* The RopeJoint enforces a maximum distance between two points
|
||||
* The RopeJoint enforces a maximum distance between two points
|
||||
* on two bodies. It has no other effect.
|
||||
**/
|
||||
class RopeJoint : public Joint
|
||||
@@ -42,17 +42,17 @@ namespace box2d
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a RopeJoint connecting body1 to body2.
|
||||
* Creates a RopeJoint connecting body1 to body2.
|
||||
**/
|
||||
RopeJoint(Body * body1, Body * body2, float x1, float y1, float x2, float y2, float maxLength, bool collideConnected);
|
||||
|
||||
|
||||
virtual ~RopeJoint();
|
||||
|
||||
|
||||
/**
|
||||
* Gets the maximum length of the rope.
|
||||
**/
|
||||
float getMaxLength() const;
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
|
||||
+149
-148
@@ -1,148 +1,149 @@
|
||||
/**
|
||||
* 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 "Shape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include <common/Memoizer.h>
|
||||
|
||||
// STD
|
||||
#include <bitset>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Shape::Shape()
|
||||
: shape(NULL)
|
||||
{
|
||||
}
|
||||
Shape::Shape(b2Shape * shape)
|
||||
: shape(shape)
|
||||
{
|
||||
Memoizer::add(shape, this);
|
||||
}
|
||||
|
||||
Shape::~Shape()
|
||||
{
|
||||
if (shape) {
|
||||
Memoizer::remove(shape);
|
||||
delete shape;
|
||||
}
|
||||
shape = 0;
|
||||
}
|
||||
|
||||
Shape::Type Shape::getType() const
|
||||
{
|
||||
switch(shape->GetType())
|
||||
{
|
||||
case b2Shape::e_circle:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
float Shape::getRadius() const
|
||||
{
|
||||
return Physics::scaleUp(shape->m_radius);
|
||||
}
|
||||
|
||||
int Shape::getChildCount() const
|
||||
{
|
||||
return shape->GetChildCount();
|
||||
}
|
||||
|
||||
bool Shape::testPoint(float x, float y, float r, float px, float py) const
|
||||
{
|
||||
b2Vec2 point(px, py);
|
||||
b2Transform transform(Physics::scaleDown(b2Vec2(x, y)), b2Rot(r));
|
||||
return shape->TestPoint(transform, Physics::scaleDown(point));
|
||||
}
|
||||
|
||||
int Shape::rayCast(lua_State * L) const
|
||||
{
|
||||
float p1x = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
float p1y = Physics::scaleDown((float)luaL_checknumber(L, 2));
|
||||
float p2x = Physics::scaleDown((float)luaL_checknumber(L, 3));
|
||||
float p2y = Physics::scaleDown((float)luaL_checknumber(L, 4));
|
||||
float maxFraction = (float)luaL_checknumber(L, 5);
|
||||
float x = Physics::scaleDown((float)luaL_checknumber(L, 6));
|
||||
float y = Physics::scaleDown((float)luaL_checknumber(L, 7));
|
||||
float r = (float)luaL_checknumber(L, 8);
|
||||
int childIndex = (int)luaL_optint(L, 9, 0);
|
||||
b2RayCastInput input;
|
||||
input.p1.Set(p1x, p1y);
|
||||
input.p2.Set(p2x, p2y);
|
||||
input.maxFraction = maxFraction;
|
||||
b2Transform transform(b2Vec2(x, y), b2Rot(r));
|
||||
b2RayCastOutput output;
|
||||
shape->RayCast(&output, input, transform, childIndex);
|
||||
lua_pushnumber(L, Physics::scaleUp(output.normal.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(output.normal.y));
|
||||
lua_pushnumber(L, output.fraction);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int Shape::computeAABB(lua_State * L) const
|
||||
{
|
||||
float x = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
float y = Physics::scaleDown((float)luaL_checknumber(L, 2));
|
||||
float r = (float)luaL_checknumber(L, 3);
|
||||
int childIndex = (int)luaL_optint(L, 4, 0);
|
||||
b2Transform transform(b2Vec2(x, y), b2Rot(r));
|
||||
b2AABB box;
|
||||
shape->ComputeAABB(&box, transform, childIndex);
|
||||
box = Physics::scaleUp(box);
|
||||
lua_pushnumber(L, box.lowerBound.x);
|
||||
lua_pushnumber(L, box.lowerBound.y);
|
||||
lua_pushnumber(L, box.upperBound.x);
|
||||
lua_pushnumber(L, box.upperBound.y);
|
||||
return 4;
|
||||
}
|
||||
|
||||
int Shape::computeMass(lua_State * L) const
|
||||
{
|
||||
float density = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
b2MassData data;
|
||||
shape->ComputeMass(&data, density);
|
||||
b2Vec2 center = Physics::scaleUp(data.center);
|
||||
lua_pushnumber(L, center.x);
|
||||
lua_pushnumber(L, center.y);
|
||||
lua_pushnumber(L, data.mass);
|
||||
lua_pushnumber(L, data.I);
|
||||
return 4;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "Shape.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
#include <common/Memoizer.h>
|
||||
|
||||
// STD
|
||||
#include <bitset>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Shape::Shape()
|
||||
: shape(NULL)
|
||||
{
|
||||
}
|
||||
Shape::Shape(b2Shape * shape)
|
||||
: shape(shape)
|
||||
{
|
||||
Memoizer::add(shape, this);
|
||||
}
|
||||
|
||||
Shape::~Shape()
|
||||
{
|
||||
if (shape)
|
||||
{
|
||||
Memoizer::remove(shape);
|
||||
delete shape;
|
||||
}
|
||||
shape = 0;
|
||||
}
|
||||
|
||||
Shape::Type Shape::getType() const
|
||||
{
|
||||
switch(shape->GetType())
|
||||
{
|
||||
case b2Shape::e_circle:
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
float Shape::getRadius() const
|
||||
{
|
||||
return Physics::scaleUp(shape->m_radius);
|
||||
}
|
||||
|
||||
int Shape::getChildCount() const
|
||||
{
|
||||
return shape->GetChildCount();
|
||||
}
|
||||
|
||||
bool Shape::testPoint(float x, float y, float r, float px, float py) const
|
||||
{
|
||||
b2Vec2 point(px, py);
|
||||
b2Transform transform(Physics::scaleDown(b2Vec2(x, y)), b2Rot(r));
|
||||
return shape->TestPoint(transform, Physics::scaleDown(point));
|
||||
}
|
||||
|
||||
int Shape::rayCast(lua_State * L) const
|
||||
{
|
||||
float p1x = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
float p1y = Physics::scaleDown((float)luaL_checknumber(L, 2));
|
||||
float p2x = Physics::scaleDown((float)luaL_checknumber(L, 3));
|
||||
float p2y = Physics::scaleDown((float)luaL_checknumber(L, 4));
|
||||
float maxFraction = (float)luaL_checknumber(L, 5);
|
||||
float x = Physics::scaleDown((float)luaL_checknumber(L, 6));
|
||||
float y = Physics::scaleDown((float)luaL_checknumber(L, 7));
|
||||
float r = (float)luaL_checknumber(L, 8);
|
||||
int childIndex = (int)luaL_optint(L, 9, 0);
|
||||
b2RayCastInput input;
|
||||
input.p1.Set(p1x, p1y);
|
||||
input.p2.Set(p2x, p2y);
|
||||
input.maxFraction = maxFraction;
|
||||
b2Transform transform(b2Vec2(x, y), b2Rot(r));
|
||||
b2RayCastOutput output;
|
||||
shape->RayCast(&output, input, transform, childIndex);
|
||||
lua_pushnumber(L, Physics::scaleUp(output.normal.x));
|
||||
lua_pushnumber(L, Physics::scaleUp(output.normal.y));
|
||||
lua_pushnumber(L, output.fraction);
|
||||
return 3;
|
||||
}
|
||||
|
||||
int Shape::computeAABB(lua_State * L) const
|
||||
{
|
||||
float x = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
float y = Physics::scaleDown((float)luaL_checknumber(L, 2));
|
||||
float r = (float)luaL_checknumber(L, 3);
|
||||
int childIndex = (int)luaL_optint(L, 4, 0);
|
||||
b2Transform transform(b2Vec2(x, y), b2Rot(r));
|
||||
b2AABB box;
|
||||
shape->ComputeAABB(&box, transform, childIndex);
|
||||
box = Physics::scaleUp(box);
|
||||
lua_pushnumber(L, box.lowerBound.x);
|
||||
lua_pushnumber(L, box.lowerBound.y);
|
||||
lua_pushnumber(L, box.upperBound.x);
|
||||
lua_pushnumber(L, box.upperBound.y);
|
||||
return 4;
|
||||
}
|
||||
|
||||
int Shape::computeMass(lua_State * L) const
|
||||
{
|
||||
float density = Physics::scaleDown((float)luaL_checknumber(L, 1));
|
||||
b2MassData data;
|
||||
shape->ComputeMass(&data, density);
|
||||
b2Vec2 center = Physics::scaleUp(data.center);
|
||||
lua_pushnumber(L, center.x);
|
||||
lua_pushnumber(L, center.y);
|
||||
lua_pushnumber(L, data.mass);
|
||||
lua_pushnumber(L, data.I);
|
||||
return 4;
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,81 +1,81 @@
|
||||
/**
|
||||
* 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_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include <physics/Shape.h>
|
||||
#include <physics/box2d/Body.h>
|
||||
#include <common/Reference.h>
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A Shape is geometry, attached to a Body via a Fixture.
|
||||
* A Body has position and orientation, and
|
||||
* a Shape's geometry will be affected by the parent
|
||||
* body's transformation.
|
||||
**/
|
||||
class Shape : public love::physics::Shape
|
||||
{
|
||||
friend class Fixture;
|
||||
|
||||
protected:
|
||||
|
||||
// The Box2D shape.
|
||||
b2Shape * shape;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a Shape.
|
||||
**/
|
||||
Shape();
|
||||
Shape(b2Shape * shape);
|
||||
|
||||
virtual ~Shape();
|
||||
|
||||
/**
|
||||
* Gets the type of Shape. Useful for
|
||||
* debug drawing.
|
||||
**/
|
||||
Type getType() const;
|
||||
float getRadius() const;
|
||||
int getChildCount() const;
|
||||
bool testPoint(float x, float y, float r, float px, float py) const;
|
||||
int rayCast(lua_State * L) const;
|
||||
int computeAABB(lua_State * L) const;
|
||||
int computeMass(lua_State * L) const;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_SHAPE_H
|
||||
/**
|
||||
* 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_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include <physics/Shape.h>
|
||||
#include <physics/box2d/Body.h>
|
||||
#include <common/Reference.h>
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
/**
|
||||
* A Shape is geometry, attached to a Body via a Fixture.
|
||||
* A Body has position and orientation, and
|
||||
* a Shape's geometry will be affected by the parent
|
||||
* body's transformation.
|
||||
**/
|
||||
class Shape : public love::physics::Shape
|
||||
{
|
||||
friend class Fixture;
|
||||
|
||||
protected:
|
||||
|
||||
// The Box2D shape.
|
||||
b2Shape * shape;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a Shape.
|
||||
**/
|
||||
Shape();
|
||||
Shape(b2Shape * shape);
|
||||
|
||||
virtual ~Shape();
|
||||
|
||||
/**
|
||||
* Gets the type of Shape. Useful for
|
||||
* debug drawing.
|
||||
**/
|
||||
Type getType() const;
|
||||
float getRadius() const;
|
||||
int getChildCount() const;
|
||||
bool testPoint(float x, float y, float r, float px, float py) const;
|
||||
int rayCast(lua_State * L) const;
|
||||
int computeAABB(lua_State * L) const;
|
||||
int computeMass(lua_State * L) const;
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_SHAPE_H
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -35,7 +35,7 @@ namespace box2d
|
||||
{
|
||||
WeldJoint::WeldJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, bool collideConnected)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
{
|
||||
b2WeldJointDef def;
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
@@ -48,7 +48,7 @@ namespace box2d
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
|
||||
void WeldJoint::setFrequency(float hz)
|
||||
{
|
||||
joint->SetFrequency(hz);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -46,7 +46,7 @@ namespace box2d
|
||||
* Creates a new WeldJoint connecting body1 and body2.
|
||||
**/
|
||||
WeldJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, bool collideConnected);
|
||||
|
||||
|
||||
virtual ~WeldJoint();
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,119 +1,119 @@
|
||||
/**
|
||||
* 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 "WheelJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
WheelJoint::WheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
b2WheelJointDef def;
|
||||
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)), b2Vec2(ax,ay));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2WheelJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
WheelJoint::~WheelJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
float WheelJoint::getJointTranslation() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointTranslation());
|
||||
}
|
||||
|
||||
float WheelJoint::getJointSpeed() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointSpeed());
|
||||
}
|
||||
|
||||
void WheelJoint::enableMotor(bool motor)
|
||||
{
|
||||
return joint->EnableMotor(motor);
|
||||
}
|
||||
|
||||
bool WheelJoint::isMotorEnabled() const
|
||||
{
|
||||
return joint->IsMotorEnabled();
|
||||
}
|
||||
|
||||
void WheelJoint::setMotorSpeed(float speed)
|
||||
{
|
||||
joint->SetMotorSpeed(speed);
|
||||
}
|
||||
|
||||
float WheelJoint::getMotorSpeed() const
|
||||
{
|
||||
return joint->GetMotorSpeed();
|
||||
}
|
||||
|
||||
void WheelJoint::setMaxMotorTorque(float torque)
|
||||
{
|
||||
joint->SetMaxMotorTorque(Physics::scaleDown(Physics::scaleDown(torque)));
|
||||
}
|
||||
|
||||
float WheelJoint::getMaxMotorTorque() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMaxMotorTorque()));
|
||||
}
|
||||
|
||||
float WheelJoint::getMotorTorque(float inv_dt) const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMotorTorque(inv_dt)));
|
||||
}
|
||||
|
||||
void WheelJoint::setSpringFrequencyHz(float hz)
|
||||
{
|
||||
joint->SetSpringFrequencyHz(hz);
|
||||
}
|
||||
|
||||
float WheelJoint::getSpringFrequencyHz() const
|
||||
{
|
||||
return joint->GetSpringFrequencyHz();
|
||||
}
|
||||
|
||||
void WheelJoint::setSpringDampingRatio(float ratio)
|
||||
{
|
||||
joint->SetSpringDampingRatio(ratio);
|
||||
}
|
||||
|
||||
float WheelJoint::getSpringDampingRatio() const
|
||||
{
|
||||
return joint->GetSpringDampingRatio();
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "WheelJoint.h"
|
||||
|
||||
// Module
|
||||
#include "Body.h"
|
||||
#include "World.h"
|
||||
#include "Physics.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
WheelJoint::WheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected)
|
||||
: Joint(body1, body2), joint(NULL)
|
||||
{
|
||||
b2WheelJointDef def;
|
||||
|
||||
def.Initialize(body1->body, body2->body, Physics::scaleDown(b2Vec2(xA,yA)), b2Vec2(ax,ay));
|
||||
def.localAnchorB = body2->body->GetLocalPoint(Physics::scaleDown(b2Vec2(xB, yB)));
|
||||
def.collideConnected = collideConnected;
|
||||
joint = (b2WheelJoint*)createJoint(&def);
|
||||
}
|
||||
|
||||
WheelJoint::~WheelJoint()
|
||||
{
|
||||
destroyJoint(joint);
|
||||
joint = 0;
|
||||
}
|
||||
|
||||
float WheelJoint::getJointTranslation() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointTranslation());
|
||||
}
|
||||
|
||||
float WheelJoint::getJointSpeed() const
|
||||
{
|
||||
return Physics::scaleUp(joint->GetJointSpeed());
|
||||
}
|
||||
|
||||
void WheelJoint::enableMotor(bool motor)
|
||||
{
|
||||
return joint->EnableMotor(motor);
|
||||
}
|
||||
|
||||
bool WheelJoint::isMotorEnabled() const
|
||||
{
|
||||
return joint->IsMotorEnabled();
|
||||
}
|
||||
|
||||
void WheelJoint::setMotorSpeed(float speed)
|
||||
{
|
||||
joint->SetMotorSpeed(speed);
|
||||
}
|
||||
|
||||
float WheelJoint::getMotorSpeed() const
|
||||
{
|
||||
return joint->GetMotorSpeed();
|
||||
}
|
||||
|
||||
void WheelJoint::setMaxMotorTorque(float torque)
|
||||
{
|
||||
joint->SetMaxMotorTorque(Physics::scaleDown(Physics::scaleDown(torque)));
|
||||
}
|
||||
|
||||
float WheelJoint::getMaxMotorTorque() const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMaxMotorTorque()));
|
||||
}
|
||||
|
||||
float WheelJoint::getMotorTorque(float inv_dt) const
|
||||
{
|
||||
return Physics::scaleUp(Physics::scaleUp(joint->GetMotorTorque(inv_dt)));
|
||||
}
|
||||
|
||||
void WheelJoint::setSpringFrequencyHz(float hz)
|
||||
{
|
||||
joint->SetSpringFrequencyHz(hz);
|
||||
}
|
||||
|
||||
float WheelJoint::getSpringFrequencyHz() const
|
||||
{
|
||||
return joint->GetSpringFrequencyHz();
|
||||
}
|
||||
|
||||
void WheelJoint::setSpringDampingRatio(float ratio)
|
||||
{
|
||||
joint->SetSpringDampingRatio(ratio);
|
||||
}
|
||||
|
||||
float WheelJoint::getSpringDampingRatio() const
|
||||
{
|
||||
return joint->GetSpringDampingRatio();
|
||||
}
|
||||
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,127 +1,127 @@
|
||||
/**
|
||||
* 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_WHEEL_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WHEEL_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* WheelJoints provide two degrees of freedom: translation
|
||||
* along a defined axis and rotation in the plane. Designed
|
||||
* for vehicle suspensions.
|
||||
**/
|
||||
class WheelJoint : public Joint
|
||||
{
|
||||
private:
|
||||
|
||||
// The Box2D wheel joint object.
|
||||
b2WheelJoint * joint;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new WheelJoint connecting body1 and body2.
|
||||
**/
|
||||
WheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
virtual ~WheelJoint();
|
||||
|
||||
/**
|
||||
* Get the current joint translation, usually in meters.
|
||||
**/
|
||||
float getJointTranslation() const;
|
||||
|
||||
/**
|
||||
* Get the current joint translation speed, usually in meters per second.
|
||||
**/
|
||||
float getJointSpeed() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint motor.
|
||||
**/
|
||||
void enableMotor(bool motor);
|
||||
|
||||
/**
|
||||
* Checks whether the motor is enabled.
|
||||
**/
|
||||
bool isMotorEnabled() const;
|
||||
|
||||
/**
|
||||
* Set the motor speed, usually in meters per second.
|
||||
**/
|
||||
void setMotorSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Get the motor speed, usually in meters per second.
|
||||
**/
|
||||
float getMotorSpeed() const;
|
||||
|
||||
/**
|
||||
* Set the maximum motor torque, usually in N.
|
||||
**/
|
||||
void setMaxMotorTorque(float torque);
|
||||
|
||||
/**
|
||||
* Get the maximum motor torque, usually in N.
|
||||
**/
|
||||
float getMaxMotorTorque() const;
|
||||
|
||||
/**
|
||||
* Get the current motor torque, usually in N.
|
||||
* @param inv_dt The inverse time step.
|
||||
**/
|
||||
float getMotorTorque(float inv_dt) const;
|
||||
|
||||
/**
|
||||
* Set the spring frequency, in hertz. Setting the frequency to 0
|
||||
* disables the spring.
|
||||
**/
|
||||
void setSpringFrequencyHz(float hz);
|
||||
|
||||
/**
|
||||
* Get the spring frequency, in hertz.
|
||||
**/
|
||||
float getSpringFrequencyHz() const;
|
||||
|
||||
/**
|
||||
* Set the spring damping ratio.
|
||||
**/
|
||||
void setSpringDampingRatio(float ratio);
|
||||
|
||||
/**
|
||||
* Get the spring damping ratio.
|
||||
**/
|
||||
float getSpringDampingRatio() const;
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WHEEL_JOINT_H
|
||||
/**
|
||||
* 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_WHEEL_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WHEEL_JOINT_H
|
||||
|
||||
// Module
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
/**
|
||||
* WheelJoints provide two degrees of freedom: translation
|
||||
* along a defined axis and rotation in the plane. Designed
|
||||
* for vehicle suspensions.
|
||||
**/
|
||||
class WheelJoint : public Joint
|
||||
{
|
||||
private:
|
||||
|
||||
// The Box2D wheel joint object.
|
||||
b2WheelJoint * joint;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new WheelJoint connecting body1 and body2.
|
||||
**/
|
||||
WheelJoint(Body * body1, Body * body2, float xA, float yA, float xB, float yB, float ax, float ay, bool collideConnected);
|
||||
|
||||
virtual ~WheelJoint();
|
||||
|
||||
/**
|
||||
* Get the current joint translation, usually in meters.
|
||||
**/
|
||||
float getJointTranslation() const;
|
||||
|
||||
/**
|
||||
* Get the current joint translation speed, usually in meters per second.
|
||||
**/
|
||||
float getJointSpeed() const;
|
||||
|
||||
/**
|
||||
* Enable/disable the joint motor.
|
||||
**/
|
||||
void enableMotor(bool motor);
|
||||
|
||||
/**
|
||||
* Checks whether the motor is enabled.
|
||||
**/
|
||||
bool isMotorEnabled() const;
|
||||
|
||||
/**
|
||||
* Set the motor speed, usually in meters per second.
|
||||
**/
|
||||
void setMotorSpeed(float speed);
|
||||
|
||||
/**
|
||||
* Get the motor speed, usually in meters per second.
|
||||
**/
|
||||
float getMotorSpeed() const;
|
||||
|
||||
/**
|
||||
* Set the maximum motor torque, usually in N.
|
||||
**/
|
||||
void setMaxMotorTorque(float torque);
|
||||
|
||||
/**
|
||||
* Get the maximum motor torque, usually in N.
|
||||
**/
|
||||
float getMaxMotorTorque() const;
|
||||
|
||||
/**
|
||||
* Get the current motor torque, usually in N.
|
||||
* @param inv_dt The inverse time step.
|
||||
**/
|
||||
float getMotorTorque(float inv_dt) const;
|
||||
|
||||
/**
|
||||
* Set the spring frequency, in hertz. Setting the frequency to 0
|
||||
* disables the spring.
|
||||
**/
|
||||
void setSpringFrequencyHz(float hz);
|
||||
|
||||
/**
|
||||
* Get the spring frequency, in hertz.
|
||||
**/
|
||||
float getSpringFrequencyHz() const;
|
||||
|
||||
/**
|
||||
* Set the spring damping ratio.
|
||||
**/
|
||||
void setSpringDampingRatio(float ratio);
|
||||
|
||||
/**
|
||||
* Get the spring damping ratio.
|
||||
**/
|
||||
float getSpringDampingRatio() const;
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WHEEL_JOINT_H
|
||||
|
||||
+445
-441
@@ -1,441 +1,445 @@
|
||||
/**
|
||||
* 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 "World.h"
|
||||
|
||||
#include "Fixture.h"
|
||||
#include "Shape.h"
|
||||
#include "Contact.h"
|
||||
#include "Physics.h"
|
||||
#include <common/Memoizer.h>
|
||||
#include <common/Reference.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
World::ContactCallback::ContactCallback()
|
||||
: ref(0)
|
||||
{
|
||||
}
|
||||
|
||||
World::ContactCallback::~ContactCallback()
|
||||
{
|
||||
if(ref != 0)
|
||||
delete ref;
|
||||
}
|
||||
|
||||
void World::ContactCallback::process(b2Contact* contact, const b2ContactImpulse* impulse)
|
||||
{
|
||||
// Process contacts.
|
||||
if(ref != 0)
|
||||
{
|
||||
lua_State * L = ref->getL();
|
||||
ref->push();
|
||||
|
||||
// Push first fixture.
|
||||
{
|
||||
Fixture * a = (Fixture *)Memoizer::find(contact->GetFixtureA());
|
||||
if(a != 0) {
|
||||
a->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)a);
|
||||
}
|
||||
else
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
}
|
||||
|
||||
// Push second userdata.
|
||||
{
|
||||
Fixture * b = (Fixture *)Memoizer::find(contact->GetFixtureB());
|
||||
if(b != 0) {
|
||||
b->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)b);
|
||||
}
|
||||
else
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
}
|
||||
|
||||
Contact * c = new Contact(contact);
|
||||
|
||||
luax_newtype(L, "Contact", (PHYSICS_CONTACT_T), (void*)c, true);
|
||||
|
||||
int args = 3;
|
||||
if (impulse) {
|
||||
for (int c = 0; c < impulse->count; c++) {
|
||||
lua_pushnumber(L, Physics::scaleUp(impulse->normalImpulses[c]));
|
||||
lua_pushnumber(L, Physics::scaleUp(impulse->tangentImpulses[c]));
|
||||
args += 2;
|
||||
}
|
||||
}
|
||||
lua_call(L, args, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
World::ContactFilter::ContactFilter()
|
||||
: ref(0)
|
||||
{
|
||||
}
|
||||
|
||||
World::ContactFilter::~ContactFilter()
|
||||
{
|
||||
if(ref != 0)
|
||||
delete ref;
|
||||
}
|
||||
|
||||
bool World::ContactFilter::process(Fixture * a, Fixture * b)
|
||||
{
|
||||
if (ref != 0)
|
||||
{
|
||||
lua_State * L = ref->getL();
|
||||
ref->push();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)a);
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)b);
|
||||
lua_call(L, 2, 1);
|
||||
return luax_toboolean(L, -1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
World::QueryCallback::QueryCallback()
|
||||
: ref(0)
|
||||
{
|
||||
}
|
||||
|
||||
World::QueryCallback::~QueryCallback()
|
||||
{
|
||||
if(ref != 0)
|
||||
delete ref;
|
||||
}
|
||||
|
||||
bool World::QueryCallback::ReportFixture(b2Fixture * fixture)
|
||||
{
|
||||
if (ref != 0)
|
||||
{
|
||||
lua_State * L = ref->getL();
|
||||
ref->push();
|
||||
Fixture * f = (Fixture *)Memoizer::find(fixture);
|
||||
if (!f) throw love::Exception("A fixture has escaped Memoizer!");
|
||||
f->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)f);
|
||||
lua_call(L, 1, 1);
|
||||
return luax_toboolean(L, -1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
World::RayCastCallback::RayCastCallback()
|
||||
: ref(0)
|
||||
{
|
||||
}
|
||||
|
||||
World::RayCastCallback::~RayCastCallback()
|
||||
{
|
||||
if(ref != 0)
|
||||
delete ref;
|
||||
}
|
||||
|
||||
float32 World::RayCastCallback::ReportFixture(b2Fixture * fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction)
|
||||
{
|
||||
if (ref != 0)
|
||||
{
|
||||
lua_State * L = ref->getL();
|
||||
ref->push();
|
||||
Fixture * f = (Fixture *)Memoizer::find(fixture);
|
||||
if (!f) throw love::Exception("A fixture has escaped Memoizer!");
|
||||
f->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)f);
|
||||
b2Vec2 scaledPoint = Physics::scaleUp(point);
|
||||
lua_pushnumber(L, scaledPoint.x);
|
||||
lua_pushnumber(L, scaledPoint.y);
|
||||
b2Vec2 scaledNormal = Physics::scaleUp(normal);
|
||||
lua_pushnumber(L, scaledNormal.x);
|
||||
lua_pushnumber(L, scaledNormal.y);
|
||||
lua_pushnumber(L, fraction);
|
||||
lua_call(L, 6, 1);
|
||||
return (float32)luaL_checknumber(L, -1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
World::World()
|
||||
: world(NULL)
|
||||
{
|
||||
world = new b2World(b2Vec2(0,0));
|
||||
world->SetAllowSleeping(true);
|
||||
world->SetContactListener(this);
|
||||
b2BodyDef def;
|
||||
groundBody = world->CreateBody(&def);
|
||||
Memoizer::add(world, this);
|
||||
}
|
||||
|
||||
World::World(b2Vec2 gravity, bool sleep)
|
||||
: world(NULL)
|
||||
{
|
||||
world = new b2World(Physics::scaleDown(gravity));
|
||||
world->SetAllowSleeping(sleep);
|
||||
world->SetContactListener(this);
|
||||
b2BodyDef def;
|
||||
groundBody = world->CreateBody(&def);
|
||||
Memoizer::add(world, this);
|
||||
}
|
||||
|
||||
World::~World()
|
||||
{
|
||||
world->DestroyBody(groundBody);
|
||||
Memoizer::remove(world);
|
||||
delete world;
|
||||
}
|
||||
|
||||
void World::update(float dt)
|
||||
{
|
||||
world->Step(dt, 8, 6);
|
||||
|
||||
// Really destroy all marked bodies.
|
||||
for (std::vector<Body*>::iterator i = destructBodies.begin(); i < destructBodies.end(); i++)
|
||||
{
|
||||
Body * b = *i;
|
||||
b->release();
|
||||
}
|
||||
destructBodies.clear();
|
||||
}
|
||||
|
||||
void World::BeginContact(b2Contact* contact)
|
||||
{
|
||||
begin.process(contact);
|
||||
}
|
||||
|
||||
void World::EndContact(b2Contact* contact)
|
||||
{
|
||||
end.process(contact);
|
||||
}
|
||||
|
||||
void World::PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
|
||||
{
|
||||
B2_NOT_USED(oldManifold); // not sure what to do with this
|
||||
presolve.process(contact);
|
||||
}
|
||||
|
||||
void World::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
|
||||
{
|
||||
postsolve.process(contact, impulse);
|
||||
}
|
||||
|
||||
bool World::ShouldCollide(b2Fixture * fixtureA, b2Fixture * fixtureB)
|
||||
{
|
||||
// Fixtures should be memoized, if we created them
|
||||
Fixture * a = (Fixture *)Memoizer::find(fixtureA);
|
||||
if (!a) throw love::Exception("A fixture has escaped Memoizer!");
|
||||
a->retain();
|
||||
Fixture * b = (Fixture *)Memoizer::find(fixtureB);
|
||||
if (!b) throw love::Exception("A fixture has escaped Memoizer!");
|
||||
b->retain();
|
||||
return filter.process(a, b);
|
||||
}
|
||||
|
||||
int World::setCallbacks(lua_State * L)
|
||||
{
|
||||
int n = lua_gettop(L);
|
||||
luax_assert_argc(L, 1, 4);
|
||||
|
||||
switch(n)
|
||||
{
|
||||
case 4:
|
||||
if (postsolve.ref) delete postsolve.ref;
|
||||
postsolve.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
case 3:
|
||||
if (presolve.ref) delete presolve.ref;
|
||||
presolve.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
case 2:
|
||||
if (end.ref) delete end.ref;
|
||||
end.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
case 1:
|
||||
if (begin.ref) delete begin.ref;
|
||||
begin.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int World::getCallbacks(lua_State * L)
|
||||
{
|
||||
begin.ref ? begin.ref->push() : lua_pushnil(L);
|
||||
end.ref ? end.ref->push() : lua_pushnil(L);
|
||||
presolve.ref ? presolve.ref->push() : lua_pushnil(L);
|
||||
postsolve.ref ? postsolve.ref->push() : lua_pushnil(L);
|
||||
return 4;
|
||||
}
|
||||
|
||||
int World::setContactFilter(lua_State * L)
|
||||
{
|
||||
luax_assert_argc(L, 1);
|
||||
if (filter.ref) delete filter.ref;
|
||||
filter.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int World::getContactFilter(lua_State * L)
|
||||
{
|
||||
filter.ref ? filter.ref->push() : lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void World::setGravity(float x, float y)
|
||||
{
|
||||
world->SetGravity(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
int World::getGravity(lua_State * L)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(world->GetGravity());
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
void World::setAllowSleeping(bool allow)
|
||||
{
|
||||
world->SetAllowSleeping(allow);
|
||||
}
|
||||
|
||||
bool World::getAllowSleeping() const
|
||||
{
|
||||
return world->GetAllowSleeping();
|
||||
}
|
||||
|
||||
bool World::isLocked() const
|
||||
{
|
||||
return world->IsLocked();
|
||||
}
|
||||
|
||||
int World::getBodyCount() const
|
||||
{
|
||||
return world->GetBodyCount()-1; // ignore the ground body
|
||||
}
|
||||
|
||||
int World::getJointCount() const
|
||||
{
|
||||
return world->GetJointCount();
|
||||
}
|
||||
|
||||
int World::getContactCount() const
|
||||
{
|
||||
return world->GetContactCount();
|
||||
}
|
||||
|
||||
int World::getBodyList(lua_State * L) const
|
||||
{
|
||||
lua_newtable(L);
|
||||
b2Body * b = world->GetBodyList();
|
||||
int i = 1;
|
||||
do {
|
||||
if (!b) break;
|
||||
if (b == groundBody) continue;
|
||||
Body * body = (Body *)Memoizer::find(b);
|
||||
if (!body) throw love::Exception("A body has escaped Memoizer!");
|
||||
body->retain();
|
||||
luax_newtype(L, "Body", PHYSICS_BODY_T, (void*)body);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
} while ((b = b->GetNext()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int World::getJointList(lua_State * L) const
|
||||
{
|
||||
lua_newtable(L);
|
||||
b2Joint * j = world->GetJointList();
|
||||
int i = 1;
|
||||
do {
|
||||
if (!j) break;
|
||||
Joint * joint = (Joint *)Memoizer::find(j);
|
||||
if (!joint) throw love::Exception("A joint has escaped Memoizer!");
|
||||
joint->retain();
|
||||
luax_newtype(L, "Joint", PHYSICS_JOINT_T, (void*)joint);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
} while ((j = j->GetNext()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int World::getContactList(lua_State * L) const
|
||||
{
|
||||
lua_newtable(L);
|
||||
b2Contact * c = world->GetContactList();
|
||||
int i = 1;
|
||||
do {
|
||||
if (!c) break;
|
||||
Contact * contact = (Contact *)Memoizer::find(c);
|
||||
if (!contact) throw love::Exception("A contact has escaped Memoizer!");
|
||||
contact->retain();
|
||||
luax_newtype(L, "Contact", PHYSICS_CONTACT_T, (void*)contact);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
} while ((c = c->GetNext()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
b2Body * World::getGroundBody() const
|
||||
{
|
||||
return groundBody;
|
||||
}
|
||||
|
||||
int World::queryBoundingBox(lua_State * L)
|
||||
{
|
||||
luax_assert_argc(L, 5);
|
||||
b2AABB box;
|
||||
float lx = (float)luaL_checknumber(L, 1);
|
||||
float ly = (float)luaL_checknumber(L, 2);
|
||||
float ux = (float)luaL_checknumber(L, 3);
|
||||
float uy = (float)luaL_checknumber(L, 4);
|
||||
box.lowerBound = Physics::scaleDown(b2Vec2(lx, ly));
|
||||
box.upperBound = Physics::scaleDown(b2Vec2(ux, uy));
|
||||
if (query.ref) delete query.ref;
|
||||
query.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
world->QueryAABB(&query, box);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int World::rayCast(lua_State * L)
|
||||
{
|
||||
luax_assert_argc(L, 5);
|
||||
float x1 = (float)luaL_checknumber(L, 1);
|
||||
float y1 = (float)luaL_checknumber(L, 2);
|
||||
float x2 = (float)luaL_checknumber(L, 3);
|
||||
float y2 = (float)luaL_checknumber(L, 4);
|
||||
b2Vec2 v1 = Physics::scaleDown(b2Vec2(x1, y1));
|
||||
b2Vec2 v2 = Physics::scaleDown(b2Vec2(x2, y2));
|
||||
if (raycast.ref) delete raycast.ref;
|
||||
raycast.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
world->RayCast(&raycast, v1, v2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void World::destroyBody(Body * b)
|
||||
{
|
||||
destructBodies.push_back(b);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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 "World.h"
|
||||
|
||||
#include "Fixture.h"
|
||||
#include "Shape.h"
|
||||
#include "Contact.h"
|
||||
#include "Physics.h"
|
||||
#include <common/Memoizer.h>
|
||||
#include <common/Reference.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
World::ContactCallback::ContactCallback()
|
||||
: ref(0)
|
||||
{
|
||||
}
|
||||
|
||||
World::ContactCallback::~ContactCallback()
|
||||
{
|
||||
if (ref != 0)
|
||||
delete ref;
|
||||
}
|
||||
|
||||
void World::ContactCallback::process(b2Contact* contact, const b2ContactImpulse* impulse)
|
||||
{
|
||||
// Process contacts.
|
||||
if (ref != 0)
|
||||
{
|
||||
lua_State * L = ref->getL();
|
||||
ref->push();
|
||||
|
||||
// Push first fixture.
|
||||
{
|
||||
Fixture * a = (Fixture *)Memoizer::find(contact->GetFixtureA());
|
||||
if (a != 0)
|
||||
{
|
||||
a->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)a);
|
||||
}
|
||||
else
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
}
|
||||
|
||||
// Push second userdata.
|
||||
{
|
||||
Fixture * b = (Fixture *)Memoizer::find(contact->GetFixtureB());
|
||||
if (b != 0)
|
||||
{
|
||||
b->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)b);
|
||||
}
|
||||
else
|
||||
throw love::Exception("A fixture has escaped Memoizer!");
|
||||
}
|
||||
|
||||
Contact * c = new Contact(contact);
|
||||
|
||||
luax_newtype(L, "Contact", (PHYSICS_CONTACT_T), (void*)c, true);
|
||||
|
||||
int args = 3;
|
||||
if (impulse)
|
||||
{
|
||||
for (int c = 0; c < impulse->count; c++)
|
||||
{
|
||||
lua_pushnumber(L, Physics::scaleUp(impulse->normalImpulses[c]));
|
||||
lua_pushnumber(L, Physics::scaleUp(impulse->tangentImpulses[c]));
|
||||
args += 2;
|
||||
}
|
||||
}
|
||||
lua_call(L, args, 0);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
World::ContactFilter::ContactFilter()
|
||||
: ref(0)
|
||||
{
|
||||
}
|
||||
|
||||
World::ContactFilter::~ContactFilter()
|
||||
{
|
||||
if (ref != 0)
|
||||
delete ref;
|
||||
}
|
||||
|
||||
bool World::ContactFilter::process(Fixture * a, Fixture * b)
|
||||
{
|
||||
if (ref != 0)
|
||||
{
|
||||
lua_State * L = ref->getL();
|
||||
ref->push();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)a);
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)b);
|
||||
lua_call(L, 2, 1);
|
||||
return luax_toboolean(L, -1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
World::QueryCallback::QueryCallback()
|
||||
: ref(0)
|
||||
{
|
||||
}
|
||||
|
||||
World::QueryCallback::~QueryCallback()
|
||||
{
|
||||
if (ref != 0)
|
||||
delete ref;
|
||||
}
|
||||
|
||||
bool World::QueryCallback::ReportFixture(b2Fixture * fixture)
|
||||
{
|
||||
if (ref != 0)
|
||||
{
|
||||
lua_State * L = ref->getL();
|
||||
ref->push();
|
||||
Fixture * f = (Fixture *)Memoizer::find(fixture);
|
||||
if (!f) throw love::Exception("A fixture has escaped Memoizer!");
|
||||
f->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)f);
|
||||
lua_call(L, 1, 1);
|
||||
return luax_toboolean(L, -1);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
World::RayCastCallback::RayCastCallback()
|
||||
: ref(0)
|
||||
{
|
||||
}
|
||||
|
||||
World::RayCastCallback::~RayCastCallback()
|
||||
{
|
||||
if (ref != 0)
|
||||
delete ref;
|
||||
}
|
||||
|
||||
float32 World::RayCastCallback::ReportFixture(b2Fixture * fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction)
|
||||
{
|
||||
if (ref != 0)
|
||||
{
|
||||
lua_State * L = ref->getL();
|
||||
ref->push();
|
||||
Fixture * f = (Fixture *)Memoizer::find(fixture);
|
||||
if (!f) throw love::Exception("A fixture has escaped Memoizer!");
|
||||
f->retain();
|
||||
luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)f);
|
||||
b2Vec2 scaledPoint = Physics::scaleUp(point);
|
||||
lua_pushnumber(L, scaledPoint.x);
|
||||
lua_pushnumber(L, scaledPoint.y);
|
||||
b2Vec2 scaledNormal = Physics::scaleUp(normal);
|
||||
lua_pushnumber(L, scaledNormal.x);
|
||||
lua_pushnumber(L, scaledNormal.y);
|
||||
lua_pushnumber(L, fraction);
|
||||
lua_call(L, 6, 1);
|
||||
return (float32)luaL_checknumber(L, -1);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
World::World()
|
||||
: world(NULL)
|
||||
{
|
||||
world = new b2World(b2Vec2(0,0));
|
||||
world->SetAllowSleeping(true);
|
||||
world->SetContactListener(this);
|
||||
b2BodyDef def;
|
||||
groundBody = world->CreateBody(&def);
|
||||
Memoizer::add(world, this);
|
||||
}
|
||||
|
||||
World::World(b2Vec2 gravity, bool sleep)
|
||||
: world(NULL)
|
||||
{
|
||||
world = new b2World(Physics::scaleDown(gravity));
|
||||
world->SetAllowSleeping(sleep);
|
||||
world->SetContactListener(this);
|
||||
b2BodyDef def;
|
||||
groundBody = world->CreateBody(&def);
|
||||
Memoizer::add(world, this);
|
||||
}
|
||||
|
||||
World::~World()
|
||||
{
|
||||
world->DestroyBody(groundBody);
|
||||
Memoizer::remove(world);
|
||||
delete world;
|
||||
}
|
||||
|
||||
void World::update(float dt)
|
||||
{
|
||||
world->Step(dt, 8, 6);
|
||||
|
||||
// Really destroy all marked bodies.
|
||||
for (std::vector<Body*>::iterator i = destructBodies.begin(); i < destructBodies.end(); i++)
|
||||
{
|
||||
Body * b = *i;
|
||||
b->release();
|
||||
}
|
||||
destructBodies.clear();
|
||||
}
|
||||
|
||||
void World::BeginContact(b2Contact* contact)
|
||||
{
|
||||
begin.process(contact);
|
||||
}
|
||||
|
||||
void World::EndContact(b2Contact* contact)
|
||||
{
|
||||
end.process(contact);
|
||||
}
|
||||
|
||||
void World::PreSolve(b2Contact* contact, const b2Manifold* oldManifold)
|
||||
{
|
||||
B2_NOT_USED(oldManifold); // not sure what to do with this
|
||||
presolve.process(contact);
|
||||
}
|
||||
|
||||
void World::PostSolve(b2Contact* contact, const b2ContactImpulse* impulse)
|
||||
{
|
||||
postsolve.process(contact, impulse);
|
||||
}
|
||||
|
||||
bool World::ShouldCollide(b2Fixture * fixtureA, b2Fixture * fixtureB)
|
||||
{
|
||||
// Fixtures should be memoized, if we created them
|
||||
Fixture * a = (Fixture *)Memoizer::find(fixtureA);
|
||||
if (!a) throw love::Exception("A fixture has escaped Memoizer!");
|
||||
a->retain();
|
||||
Fixture * b = (Fixture *)Memoizer::find(fixtureB);
|
||||
if (!b) throw love::Exception("A fixture has escaped Memoizer!");
|
||||
b->retain();
|
||||
return filter.process(a, b);
|
||||
}
|
||||
|
||||
int World::setCallbacks(lua_State * L)
|
||||
{
|
||||
int n = lua_gettop(L);
|
||||
luax_assert_argc(L, 1, 4);
|
||||
|
||||
switch(n)
|
||||
{
|
||||
case 4:
|
||||
if (postsolve.ref) delete postsolve.ref;
|
||||
postsolve.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
case 3:
|
||||
if (presolve.ref) delete presolve.ref;
|
||||
presolve.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
case 2:
|
||||
if (end.ref) delete end.ref;
|
||||
end.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
case 1:
|
||||
if (begin.ref) delete begin.ref;
|
||||
begin.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int World::getCallbacks(lua_State * L)
|
||||
{
|
||||
begin.ref ? begin.ref->push() : lua_pushnil(L);
|
||||
end.ref ? end.ref->push() : lua_pushnil(L);
|
||||
presolve.ref ? presolve.ref->push() : lua_pushnil(L);
|
||||
postsolve.ref ? postsolve.ref->push() : lua_pushnil(L);
|
||||
return 4;
|
||||
}
|
||||
|
||||
int World::setContactFilter(lua_State * L)
|
||||
{
|
||||
luax_assert_argc(L, 1);
|
||||
if (filter.ref) delete filter.ref;
|
||||
filter.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int World::getContactFilter(lua_State * L)
|
||||
{
|
||||
filter.ref ? filter.ref->push() : lua_pushnil(L);
|
||||
return 1;
|
||||
}
|
||||
|
||||
void World::setGravity(float x, float y)
|
||||
{
|
||||
world->SetGravity(Physics::scaleDown(b2Vec2(x, y)));
|
||||
}
|
||||
|
||||
int World::getGravity(lua_State * L)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(world->GetGravity());
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
void World::setAllowSleeping(bool allow)
|
||||
{
|
||||
world->SetAllowSleeping(allow);
|
||||
}
|
||||
|
||||
bool World::getAllowSleeping() const
|
||||
{
|
||||
return world->GetAllowSleeping();
|
||||
}
|
||||
|
||||
bool World::isLocked() const
|
||||
{
|
||||
return world->IsLocked();
|
||||
}
|
||||
|
||||
int World::getBodyCount() const
|
||||
{
|
||||
return world->GetBodyCount()-1; // ignore the ground body
|
||||
}
|
||||
|
||||
int World::getJointCount() const
|
||||
{
|
||||
return world->GetJointCount();
|
||||
}
|
||||
|
||||
int World::getContactCount() const
|
||||
{
|
||||
return world->GetContactCount();
|
||||
}
|
||||
|
||||
int World::getBodyList(lua_State * L) const
|
||||
{
|
||||
lua_newtable(L);
|
||||
b2Body * b = world->GetBodyList();
|
||||
int i = 1;
|
||||
do {
|
||||
if (!b) break;
|
||||
if (b == groundBody) continue;
|
||||
Body * body = (Body *)Memoizer::find(b);
|
||||
if (!body) throw love::Exception("A body has escaped Memoizer!");
|
||||
body->retain();
|
||||
luax_newtype(L, "Body", PHYSICS_BODY_T, (void*)body);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
} while ((b = b->GetNext()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int World::getJointList(lua_State * L) const
|
||||
{
|
||||
lua_newtable(L);
|
||||
b2Joint * j = world->GetJointList();
|
||||
int i = 1;
|
||||
do {
|
||||
if (!j) break;
|
||||
Joint * joint = (Joint *)Memoizer::find(j);
|
||||
if (!joint) throw love::Exception("A joint has escaped Memoizer!");
|
||||
joint->retain();
|
||||
luax_newtype(L, "Joint", PHYSICS_JOINT_T, (void*)joint);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
} while ((j = j->GetNext()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int World::getContactList(lua_State * L) const
|
||||
{
|
||||
lua_newtable(L);
|
||||
b2Contact * c = world->GetContactList();
|
||||
int i = 1;
|
||||
do {
|
||||
if (!c) break;
|
||||
Contact * contact = (Contact *)Memoizer::find(c);
|
||||
if (!contact) throw love::Exception("A contact has escaped Memoizer!");
|
||||
contact->retain();
|
||||
luax_newtype(L, "Contact", PHYSICS_CONTACT_T, (void*)contact);
|
||||
lua_rawseti(L, -2, i);
|
||||
i++;
|
||||
} while ((c = c->GetNext()));
|
||||
return 1;
|
||||
}
|
||||
|
||||
b2Body * World::getGroundBody() const
|
||||
{
|
||||
return groundBody;
|
||||
}
|
||||
|
||||
int World::queryBoundingBox(lua_State * L)
|
||||
{
|
||||
luax_assert_argc(L, 5);
|
||||
b2AABB box;
|
||||
float lx = (float)luaL_checknumber(L, 1);
|
||||
float ly = (float)luaL_checknumber(L, 2);
|
||||
float ux = (float)luaL_checknumber(L, 3);
|
||||
float uy = (float)luaL_checknumber(L, 4);
|
||||
box.lowerBound = Physics::scaleDown(b2Vec2(lx, ly));
|
||||
box.upperBound = Physics::scaleDown(b2Vec2(ux, uy));
|
||||
if (query.ref) delete query.ref;
|
||||
query.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
world->QueryAABB(&query, box);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int World::rayCast(lua_State * L)
|
||||
{
|
||||
luax_assert_argc(L, 5);
|
||||
float x1 = (float)luaL_checknumber(L, 1);
|
||||
float y1 = (float)luaL_checknumber(L, 2);
|
||||
float x2 = (float)luaL_checknumber(L, 3);
|
||||
float y2 = (float)luaL_checknumber(L, 4);
|
||||
b2Vec2 v1 = Physics::scaleDown(b2Vec2(x1, y1));
|
||||
b2Vec2 v2 = Physics::scaleDown(b2Vec2(x2, y2));
|
||||
if (raycast.ref) delete raycast.ref;
|
||||
raycast.ref = luax_refif(L, LUA_TFUNCTION);
|
||||
world->RayCast(&raycast, v1, v2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void World::destroyBody(Body * b)
|
||||
{
|
||||
destructBodies.push_back(b);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
+275
-275
@@ -1,275 +1,275 @@
|
||||
/**
|
||||
* 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_WORLD_H
|
||||
#define LOVE_PHYSICS_BOX2D_WORLD_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
#include <common/runtime.h>
|
||||
#include <common/Reference.h>
|
||||
|
||||
// STD
|
||||
#include <vector>
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
class Contact;
|
||||
class Body;
|
||||
class Fixture;
|
||||
|
||||
/**
|
||||
* The World is the "God" container class,
|
||||
* which contains all Bodies and Joints. Shapes
|
||||
* are contained in their associated Body.
|
||||
*
|
||||
* Bodies in different worlds can obviously not
|
||||
* collide.
|
||||
*
|
||||
* The world also controls global parameters, like
|
||||
* gravity.
|
||||
**/
|
||||
class World : public Object, public b2ContactListener, public b2ContactFilter
|
||||
{
|
||||
// Friends.
|
||||
friend class Joint;
|
||||
friend class DistanceJoint;
|
||||
friend class MouseJoint;
|
||||
friend class Body;
|
||||
|
||||
public:
|
||||
|
||||
class ContactCallback
|
||||
{
|
||||
public:
|
||||
Reference * ref;
|
||||
ContactCallback();
|
||||
~ContactCallback();
|
||||
void process(b2Contact* contact, const b2ContactImpulse* impulse = NULL);
|
||||
};
|
||||
|
||||
class ContactFilter
|
||||
{
|
||||
public:
|
||||
Reference * ref;
|
||||
ContactFilter();
|
||||
~ContactFilter();
|
||||
bool process(Fixture * a, Fixture * b);
|
||||
};
|
||||
|
||||
class QueryCallback : public b2QueryCallback
|
||||
{
|
||||
public:
|
||||
Reference * ref;
|
||||
QueryCallback();
|
||||
~QueryCallback();
|
||||
virtual bool ReportFixture(b2Fixture * fixture);
|
||||
};
|
||||
|
||||
class RayCastCallback : public b2RayCastCallback
|
||||
{
|
||||
public:
|
||||
Reference * ref;
|
||||
RayCastCallback();
|
||||
~RayCastCallback();
|
||||
virtual float32 ReportFixture(b2Fixture * fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction);
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
// Pointer to the Box2D world.
|
||||
b2World * world;
|
||||
|
||||
// Ground body
|
||||
b2Body * groundBody;
|
||||
|
||||
// The list of to be destructed bodies.
|
||||
std::vector<Body*> destructBodies;
|
||||
|
||||
// Contact callbacks.
|
||||
ContactCallback begin, end, presolve, postsolve;
|
||||
ContactFilter filter;
|
||||
QueryCallback query;
|
||||
RayCastCallback raycast;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new world.
|
||||
**/
|
||||
World();
|
||||
|
||||
/**
|
||||
* Creates a new world with the given gravity
|
||||
* and whether or not the bodies should sleep when appropriate.
|
||||
* @param gravity The gravity of the World.
|
||||
* @param sleep True if the bodies should be able to sleep,
|
||||
* false otherwise.
|
||||
**/
|
||||
World(b2Vec2 gravity, bool sleep);
|
||||
|
||||
virtual ~World();
|
||||
|
||||
/**
|
||||
* Updates everything in the world one timestep.
|
||||
* This is called update() and not step() to conform
|
||||
* with all other objects in LOVE.
|
||||
* @param dt The timestep.
|
||||
**/
|
||||
void update(float dt);
|
||||
|
||||
// From b2ContactListener
|
||||
void BeginContact(b2Contact* contact);
|
||||
void EndContact(b2Contact* contact);
|
||||
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);
|
||||
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
|
||||
|
||||
// From b2ContactFilter
|
||||
bool ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB);
|
||||
|
||||
/**
|
||||
* Receives up to four Lua functions as arguments. Each function is
|
||||
* collision callback for the four events (in order): begin, end,
|
||||
* presolve and postsolve. The value "nil" is accepted if one or
|
||||
* more events are uninteresting.
|
||||
**/
|
||||
int setCallbacks(lua_State * L);
|
||||
|
||||
/**
|
||||
* Returns the functions previously set by setCallbacks.
|
||||
**/
|
||||
int getCallbacks(lua_State * L);
|
||||
|
||||
/**
|
||||
* Sets the ContactFilter callback.
|
||||
**/
|
||||
int setContactFilter(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the ContactFilter callback.
|
||||
**/
|
||||
int getContactFilter(lua_State * L);
|
||||
|
||||
/**
|
||||
* Sets the current gravity of the World.
|
||||
* @param x Gravity in the x-direction.
|
||||
* @param y Gravity in the y-direction.
|
||||
**/
|
||||
void setGravity(float x, float y);
|
||||
|
||||
/**
|
||||
* Gets the current gravity.
|
||||
* @returns Gravity in the x-direction.
|
||||
* @returns Gravity in the y-direction.
|
||||
**/
|
||||
int getGravity(lua_State * L);
|
||||
|
||||
/**
|
||||
* Sets whether this World allows sleep.
|
||||
* @param allow True to allow, false to disallow.
|
||||
**/
|
||||
void setAllowSleeping(bool allow);
|
||||
|
||||
/**
|
||||
* Returns whether this World allows sleep.
|
||||
* @return True if allowed, false if disallowed.
|
||||
**/
|
||||
bool getAllowSleeping() const;
|
||||
|
||||
/**
|
||||
* Returns whether this World is currently locked.
|
||||
* If it's locked, it's in the middle of a timestep.
|
||||
* @return Whether the World is locked.
|
||||
**/
|
||||
bool isLocked() const;
|
||||
|
||||
/**
|
||||
* Get the current body count.
|
||||
* @return The number of bodies.
|
||||
**/
|
||||
int getBodyCount() const;
|
||||
|
||||
/**
|
||||
* Get the current joint count.
|
||||
* @return The number of joints.
|
||||
**/
|
||||
int getJointCount() const;
|
||||
|
||||
/**
|
||||
* Get the current contact count.
|
||||
* @return The number of contacts.
|
||||
**/
|
||||
int getContactCount() const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Bodies in the World.
|
||||
* @return An array of Bodies.
|
||||
**/
|
||||
int getBodyList(lua_State * L) const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Joints in the World.
|
||||
* @return An array of Joints.
|
||||
**/
|
||||
int getJointList(lua_State * L) const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Contacts in the World.
|
||||
* @return An array of Contacts.
|
||||
**/
|
||||
int getContactList(lua_State * L) const;
|
||||
|
||||
/**
|
||||
* Gets the ground body.
|
||||
* @return The ground body.
|
||||
**/
|
||||
b2Body * getGroundBody() const;
|
||||
|
||||
/**
|
||||
* Gets all fixtures that overlap a given bounding box.
|
||||
**/
|
||||
int queryBoundingBox(lua_State * L);
|
||||
|
||||
/**
|
||||
* Raycasts the World for all Fixtures in the path of the ray.
|
||||
**/
|
||||
int rayCast(lua_State * L);
|
||||
|
||||
/**
|
||||
* Mark a body for destruction.
|
||||
* To be called from Body
|
||||
**/
|
||||
void destroyBody(Body * b);
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WORLD_H
|
||||
/**
|
||||
* 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_WORLD_H
|
||||
#define LOVE_PHYSICS_BOX2D_WORLD_H
|
||||
|
||||
// LOVE
|
||||
#include <common/Object.h>
|
||||
#include <common/runtime.h>
|
||||
#include <common/Reference.h>
|
||||
|
||||
// STD
|
||||
#include <vector>
|
||||
|
||||
// Box2D
|
||||
#include <Box2D/Box2D.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
class Contact;
|
||||
class Body;
|
||||
class Fixture;
|
||||
|
||||
/**
|
||||
* The World is the "God" container class,
|
||||
* which contains all Bodies and Joints. Shapes
|
||||
* are contained in their associated Body.
|
||||
*
|
||||
* Bodies in different worlds can obviously not
|
||||
* collide.
|
||||
*
|
||||
* The world also controls global parameters, like
|
||||
* gravity.
|
||||
**/
|
||||
class World : public Object, public b2ContactListener, public b2ContactFilter
|
||||
{
|
||||
// Friends.
|
||||
friend class Joint;
|
||||
friend class DistanceJoint;
|
||||
friend class MouseJoint;
|
||||
friend class Body;
|
||||
|
||||
public:
|
||||
|
||||
class ContactCallback
|
||||
{
|
||||
public:
|
||||
Reference * ref;
|
||||
ContactCallback();
|
||||
~ContactCallback();
|
||||
void process(b2Contact* contact, const b2ContactImpulse* impulse = NULL);
|
||||
};
|
||||
|
||||
class ContactFilter
|
||||
{
|
||||
public:
|
||||
Reference * ref;
|
||||
ContactFilter();
|
||||
~ContactFilter();
|
||||
bool process(Fixture * a, Fixture * b);
|
||||
};
|
||||
|
||||
class QueryCallback : public b2QueryCallback
|
||||
{
|
||||
public:
|
||||
Reference * ref;
|
||||
QueryCallback();
|
||||
~QueryCallback();
|
||||
virtual bool ReportFixture(b2Fixture * fixture);
|
||||
};
|
||||
|
||||
class RayCastCallback : public b2RayCastCallback
|
||||
{
|
||||
public:
|
||||
Reference * ref;
|
||||
RayCastCallback();
|
||||
~RayCastCallback();
|
||||
virtual float32 ReportFixture(b2Fixture * fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction);
|
||||
};
|
||||
|
||||
private:
|
||||
|
||||
// Pointer to the Box2D world.
|
||||
b2World * world;
|
||||
|
||||
// Ground body
|
||||
b2Body * groundBody;
|
||||
|
||||
// The list of to be destructed bodies.
|
||||
std::vector<Body*> destructBodies;
|
||||
|
||||
// Contact callbacks.
|
||||
ContactCallback begin, end, presolve, postsolve;
|
||||
ContactFilter filter;
|
||||
QueryCallback query;
|
||||
RayCastCallback raycast;
|
||||
|
||||
public:
|
||||
|
||||
/**
|
||||
* Creates a new world.
|
||||
**/
|
||||
World();
|
||||
|
||||
/**
|
||||
* Creates a new world with the given gravity
|
||||
* and whether or not the bodies should sleep when appropriate.
|
||||
* @param gravity The gravity of the World.
|
||||
* @param sleep True if the bodies should be able to sleep,
|
||||
* false otherwise.
|
||||
**/
|
||||
World(b2Vec2 gravity, bool sleep);
|
||||
|
||||
virtual ~World();
|
||||
|
||||
/**
|
||||
* Updates everything in the world one timestep.
|
||||
* This is called update() and not step() to conform
|
||||
* with all other objects in LOVE.
|
||||
* @param dt The timestep.
|
||||
**/
|
||||
void update(float dt);
|
||||
|
||||
// From b2ContactListener
|
||||
void BeginContact(b2Contact* contact);
|
||||
void EndContact(b2Contact* contact);
|
||||
void PreSolve(b2Contact* contact, const b2Manifold* oldManifold);
|
||||
void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse);
|
||||
|
||||
// From b2ContactFilter
|
||||
bool ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB);
|
||||
|
||||
/**
|
||||
* Receives up to four Lua functions as arguments. Each function is
|
||||
* collision callback for the four events (in order): begin, end,
|
||||
* presolve and postsolve. The value "nil" is accepted if one or
|
||||
* more events are uninteresting.
|
||||
**/
|
||||
int setCallbacks(lua_State * L);
|
||||
|
||||
/**
|
||||
* Returns the functions previously set by setCallbacks.
|
||||
**/
|
||||
int getCallbacks(lua_State * L);
|
||||
|
||||
/**
|
||||
* Sets the ContactFilter callback.
|
||||
**/
|
||||
int setContactFilter(lua_State * L);
|
||||
|
||||
/**
|
||||
* Gets the ContactFilter callback.
|
||||
**/
|
||||
int getContactFilter(lua_State * L);
|
||||
|
||||
/**
|
||||
* Sets the current gravity of the World.
|
||||
* @param x Gravity in the x-direction.
|
||||
* @param y Gravity in the y-direction.
|
||||
**/
|
||||
void setGravity(float x, float y);
|
||||
|
||||
/**
|
||||
* Gets the current gravity.
|
||||
* @returns Gravity in the x-direction.
|
||||
* @returns Gravity in the y-direction.
|
||||
**/
|
||||
int getGravity(lua_State * L);
|
||||
|
||||
/**
|
||||
* Sets whether this World allows sleep.
|
||||
* @param allow True to allow, false to disallow.
|
||||
**/
|
||||
void setAllowSleeping(bool allow);
|
||||
|
||||
/**
|
||||
* Returns whether this World allows sleep.
|
||||
* @return True if allowed, false if disallowed.
|
||||
**/
|
||||
bool getAllowSleeping() const;
|
||||
|
||||
/**
|
||||
* Returns whether this World is currently locked.
|
||||
* If it's locked, it's in the middle of a timestep.
|
||||
* @return Whether the World is locked.
|
||||
**/
|
||||
bool isLocked() const;
|
||||
|
||||
/**
|
||||
* Get the current body count.
|
||||
* @return The number of bodies.
|
||||
**/
|
||||
int getBodyCount() const;
|
||||
|
||||
/**
|
||||
* Get the current joint count.
|
||||
* @return The number of joints.
|
||||
**/
|
||||
int getJointCount() const;
|
||||
|
||||
/**
|
||||
* Get the current contact count.
|
||||
* @return The number of contacts.
|
||||
**/
|
||||
int getContactCount() const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Bodies in the World.
|
||||
* @return An array of Bodies.
|
||||
**/
|
||||
int getBodyList(lua_State * L) const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Joints in the World.
|
||||
* @return An array of Joints.
|
||||
**/
|
||||
int getJointList(lua_State * L) const;
|
||||
|
||||
/**
|
||||
* Get an array of all the Contacts in the World.
|
||||
* @return An array of Contacts.
|
||||
**/
|
||||
int getContactList(lua_State * L) const;
|
||||
|
||||
/**
|
||||
* Gets the ground body.
|
||||
* @return The ground body.
|
||||
**/
|
||||
b2Body * getGroundBody() const;
|
||||
|
||||
/**
|
||||
* Gets all fixtures that overlap a given bounding box.
|
||||
**/
|
||||
int queryBoundingBox(lua_State * L);
|
||||
|
||||
/**
|
||||
* Raycasts the World for all Fixtures in the path of the ray.
|
||||
**/
|
||||
int rayCast(lua_State * L);
|
||||
|
||||
/**
|
||||
* Mark a body for destruction.
|
||||
* To be called from Body
|
||||
**/
|
||||
void destroyBody(Body * b);
|
||||
|
||||
};
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WORLD_H
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,93 +1,93 @@
|
||||
/**
|
||||
* 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_BODY_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_BODY_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Body.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Body * luax_checkbody(lua_State * L, int idx);
|
||||
int w_Body_getX(lua_State * L);
|
||||
int w_Body_getY(lua_State * L);
|
||||
int w_Body_getAngle(lua_State * L);
|
||||
int w_Body_getPosition(lua_State * L);
|
||||
int w_Body_getLinearVelocity(lua_State * L);
|
||||
int w_Body_getWorldCenter(lua_State * L);
|
||||
int w_Body_getLocalCenter(lua_State * L);
|
||||
int w_Body_getAngularVelocity(lua_State * L);
|
||||
int w_Body_getMass(lua_State * L);
|
||||
int w_Body_getInertia(lua_State * L);
|
||||
int w_Body_getMassData(lua_State * L);
|
||||
int w_Body_getAngularDamping(lua_State * L);
|
||||
int w_Body_getLinearDamping(lua_State * L);
|
||||
int w_Body_getGravityScale(lua_State * L);
|
||||
int w_Body_getType(lua_State * L);
|
||||
int w_Body_applyLinearImpulse(lua_State * L);
|
||||
int w_Body_applyAngularImpulse(lua_State * L);
|
||||
int w_Body_applyTorque(lua_State * L);
|
||||
int w_Body_applyForce(lua_State * L);
|
||||
int w_Body_setX(lua_State * L);
|
||||
int w_Body_setY(lua_State * L);
|
||||
int w_Body_setLinearVelocity(lua_State * L);
|
||||
int w_Body_setAngle(lua_State * L);
|
||||
int w_Body_setAngularVelocity(lua_State * L);
|
||||
int w_Body_setPosition(lua_State * L);
|
||||
int w_Body_resetMassData(lua_State * L);
|
||||
int w_Body_setMassData(lua_State * L);
|
||||
int w_Body_setInertia(lua_State * L);
|
||||
int w_Body_setAngularDamping(lua_State * L);
|
||||
int w_Body_setLinearDamping(lua_State * L);
|
||||
int w_Body_setGravityScale(lua_State * L);
|
||||
int w_Body_setType(lua_State * L);
|
||||
int w_Body_getWorldPoint(lua_State * L);
|
||||
int w_Body_getWorldVector(lua_State * L);
|
||||
int w_Body_getWorldPoints(lua_State * L);
|
||||
int w_Body_getLocalPoint(lua_State * L);
|
||||
int w_Body_getLocalVector(lua_State * L);
|
||||
int w_Body_getLinearVelocityFromWorldPoint(lua_State * L);
|
||||
int w_Body_getLinearVelocityFromLocalPoint(lua_State * L);
|
||||
int w_Body_isBullet(lua_State * L);
|
||||
int w_Body_setBullet(lua_State * L);
|
||||
int w_Body_isActive(lua_State * L);
|
||||
int w_Body_isAwake(lua_State * L);
|
||||
int w_Body_setSleepingAllowed(lua_State * L);
|
||||
int w_Body_isSleepingAllowed(lua_State * L);
|
||||
int w_Body_setActive(lua_State * L);
|
||||
int w_Body_setAwake(lua_State * L);
|
||||
int w_Body_setFixedRotation(lua_State * L);
|
||||
int w_Body_isFixedRotation(lua_State * L);
|
||||
int w_Body_getFixtureList(lua_State * L);
|
||||
int w_Body_destroy(lua_State * L);
|
||||
int luaopen_body(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_BODY_H
|
||||
/**
|
||||
* 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_BODY_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_BODY_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Body.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Body * luax_checkbody(lua_State * L, int idx);
|
||||
int w_Body_getX(lua_State * L);
|
||||
int w_Body_getY(lua_State * L);
|
||||
int w_Body_getAngle(lua_State * L);
|
||||
int w_Body_getPosition(lua_State * L);
|
||||
int w_Body_getLinearVelocity(lua_State * L);
|
||||
int w_Body_getWorldCenter(lua_State * L);
|
||||
int w_Body_getLocalCenter(lua_State * L);
|
||||
int w_Body_getAngularVelocity(lua_State * L);
|
||||
int w_Body_getMass(lua_State * L);
|
||||
int w_Body_getInertia(lua_State * L);
|
||||
int w_Body_getMassData(lua_State * L);
|
||||
int w_Body_getAngularDamping(lua_State * L);
|
||||
int w_Body_getLinearDamping(lua_State * L);
|
||||
int w_Body_getGravityScale(lua_State * L);
|
||||
int w_Body_getType(lua_State * L);
|
||||
int w_Body_applyLinearImpulse(lua_State * L);
|
||||
int w_Body_applyAngularImpulse(lua_State * L);
|
||||
int w_Body_applyTorque(lua_State * L);
|
||||
int w_Body_applyForce(lua_State * L);
|
||||
int w_Body_setX(lua_State * L);
|
||||
int w_Body_setY(lua_State * L);
|
||||
int w_Body_setLinearVelocity(lua_State * L);
|
||||
int w_Body_setAngle(lua_State * L);
|
||||
int w_Body_setAngularVelocity(lua_State * L);
|
||||
int w_Body_setPosition(lua_State * L);
|
||||
int w_Body_resetMassData(lua_State * L);
|
||||
int w_Body_setMassData(lua_State * L);
|
||||
int w_Body_setInertia(lua_State * L);
|
||||
int w_Body_setAngularDamping(lua_State * L);
|
||||
int w_Body_setLinearDamping(lua_State * L);
|
||||
int w_Body_setGravityScale(lua_State * L);
|
||||
int w_Body_setType(lua_State * L);
|
||||
int w_Body_getWorldPoint(lua_State * L);
|
||||
int w_Body_getWorldVector(lua_State * L);
|
||||
int w_Body_getWorldPoints(lua_State * L);
|
||||
int w_Body_getLocalPoint(lua_State * L);
|
||||
int w_Body_getLocalVector(lua_State * L);
|
||||
int w_Body_getLinearVelocityFromWorldPoint(lua_State * L);
|
||||
int w_Body_getLinearVelocityFromLocalPoint(lua_State * L);
|
||||
int w_Body_isBullet(lua_State * L);
|
||||
int w_Body_setBullet(lua_State * L);
|
||||
int w_Body_isActive(lua_State * L);
|
||||
int w_Body_isAwake(lua_State * L);
|
||||
int w_Body_setSleepingAllowed(lua_State * L);
|
||||
int w_Body_isSleepingAllowed(lua_State * L);
|
||||
int w_Body_setActive(lua_State * L);
|
||||
int w_Body_setAwake(lua_State * L);
|
||||
int w_Body_setFixedRotation(lua_State * L);
|
||||
int w_Body_isFixedRotation(lua_State * L);
|
||||
int w_Body_getFixtureList(lua_State * L);
|
||||
int w_Body_destroy(lua_State * L);
|
||||
int luaopen_body(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_BODY_H
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace box2d
|
||||
{
|
||||
return luax_checktype<ChainShape>(L, idx, "ChainShape", PHYSICS_CHAIN_SHAPE_T);
|
||||
}
|
||||
|
||||
|
||||
int w_ChainShape_setNextVertex(lua_State * L)
|
||||
{
|
||||
ChainShape * c = luax_checkchainshape(L, 1);
|
||||
@@ -40,7 +40,7 @@ namespace box2d
|
||||
c->setNextVertex(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int w_ChainShape_setPrevVertex(lua_State * L)
|
||||
{
|
||||
ChainShape * c = luax_checkchainshape(L, 1);
|
||||
@@ -49,14 +49,14 @@ namespace box2d
|
||||
c->setPrevVertex(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int w_ChainShape_getChildCount(lua_State * L)
|
||||
{
|
||||
ChainShape * c = luax_checkchainshape(L, 1);
|
||||
lua_pushinteger(L, c->getChildCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int w_ChainShape_getChildEdge(lua_State * L)
|
||||
{
|
||||
ChainShape * c = luax_checkchainshape(L, 1);
|
||||
@@ -65,7 +65,7 @@ namespace box2d
|
||||
luax_newtype(L, "EdgeShape", PHYSICS_EDGE_SHAPE_T, e);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int w_ChainShape_getVertexCount(lua_State * L)
|
||||
{
|
||||
ChainShape * c = luax_checkchainshape(L, 1);
|
||||
@@ -73,7 +73,7 @@ namespace box2d
|
||||
lua_pushinteger(L, count);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int w_ChainShape_getPoint(lua_State * L)
|
||||
{
|
||||
ChainShape * c = luax_checkchainshape(L, 1);
|
||||
@@ -83,13 +83,14 @@ namespace box2d
|
||||
lua_pushnumber(L, v.y);
|
||||
return 2;
|
||||
}
|
||||
|
||||
|
||||
int w_ChainShape_getPoints(lua_State * L)
|
||||
{
|
||||
ChainShape * c = luax_checkchainshape(L, 1);
|
||||
const b2Vec2 * verts = c->getPoints();
|
||||
int count = c->getVertexCount();
|
||||
for (int i = 0; i < count; i++) {
|
||||
for (int i = 0; i < count; i++)
|
||||
{
|
||||
b2Vec2 v = Physics::scaleUp(verts[i]);
|
||||
lua_pushnumber(L, v.x);
|
||||
lua_pushnumber(L, v.y);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -33,7 +33,7 @@ namespace physics
|
||||
namespace box2d
|
||||
{
|
||||
ChainShape * luax_checkchainshape(lua_State * L, int idx);
|
||||
|
||||
|
||||
int w_ChainShape_setNextVertex(lua_State * L);
|
||||
int w_ChainShape_setPrevVertex(lua_State * L);
|
||||
int w_ChainShape_getChildCount(lua_State * L);
|
||||
@@ -41,7 +41,7 @@ namespace box2d
|
||||
int w_ChainShape_getVertexCount(lua_State * L);
|
||||
int w_ChainShape_getPoint(lua_State * L);
|
||||
int w_ChainShape_getPoints(lua_State * L);
|
||||
|
||||
|
||||
int luaopen_chainshape(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
|
||||
@@ -1,71 +1,71 @@
|
||||
/**
|
||||
* 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_CircleShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
CircleShape * luax_checkcircleshape(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<CircleShape>(L, idx, "CircleShape", PHYSICS_CIRCLE_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_CircleShape_getRadius(lua_State * L)
|
||||
{
|
||||
CircleShape * c = luax_checkcircleshape(L, 1);
|
||||
lua_pushnumber(L, c->getRadius());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_CircleShape_setRadius(lua_State * L)
|
||||
{
|
||||
CircleShape * c = luax_checkcircleshape(L, 1);
|
||||
float r = (float)luaL_checknumber(L, 2);
|
||||
c->setRadius(r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getRadius", w_CircleShape_getRadius },
|
||||
{ "setRadius", w_CircleShape_setRadius },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ "destroy", w_Shape_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_circleshape(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "CircleShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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_CircleShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
CircleShape * luax_checkcircleshape(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<CircleShape>(L, idx, "CircleShape", PHYSICS_CIRCLE_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_CircleShape_getRadius(lua_State * L)
|
||||
{
|
||||
CircleShape * c = luax_checkcircleshape(L, 1);
|
||||
lua_pushnumber(L, c->getRadius());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_CircleShape_setRadius(lua_State * L)
|
||||
{
|
||||
CircleShape * c = luax_checkcircleshape(L, 1);
|
||||
float r = (float)luaL_checknumber(L, 2);
|
||||
c->setRadius(r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getRadius", w_CircleShape_getRadius },
|
||||
{ "setRadius", w_CircleShape_setRadius },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ "destroy", w_Shape_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_circleshape(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "CircleShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,44 +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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_CIRCLE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_CIRCLE_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Shape.h"
|
||||
#include "CircleShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
CircleShape * luax_checkcircleshape(lua_State * L, int idx);
|
||||
int w_CircleShape_getRadius(lua_State * L);
|
||||
int w_CircleShape_setRadius(lua_State * L);
|
||||
int luaopen_circleshape(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_CIRCLE_SHAPE_H
|
||||
/**
|
||||
* 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_CIRCLE_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_CIRCLE_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Shape.h"
|
||||
#include "CircleShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
CircleShape * luax_checkcircleshape(lua_State * L, int idx);
|
||||
int w_CircleShape_getRadius(lua_State * L);
|
||||
int w_CircleShape_setRadius(lua_State * L);
|
||||
int luaopen_circleshape(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_CIRCLE_SHAPE_H
|
||||
|
||||
@@ -1,135 +1,135 @@
|
||||
/**
|
||||
* 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_Contact.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Contact * luax_checkcontact(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Contact>(L, idx, "Contact", PHYSICS_CONTACT_T);
|
||||
}
|
||||
|
||||
int w_Contact_getPositions(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
return t->getPositions(L);
|
||||
}
|
||||
|
||||
int w_Contact_getNormal(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
return t->getNormal(L);
|
||||
}
|
||||
|
||||
int w_Contact_getFriction(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
lua_pushnumber(L, t->getFriction());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_getRestitution(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
lua_pushnumber(L, t->getRestitution());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_isEnabled(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
lua_pushboolean(L, t->isEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_isTouching(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
lua_pushboolean(L, t->isTouching());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_setFriction(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
float f = (float)luaL_checknumber(L, 2);
|
||||
t->setFriction(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_setRestitution(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
float r = (float)luaL_checknumber(L, 2);
|
||||
t->setRestitution(r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_setEnabled(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
bool e = luax_toboolean(L, 2);
|
||||
t->setEnabled(e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_resetFriction(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
t->resetFriction();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_resetRestitution(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
t->resetRestitution();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luaopen_contact(lua_State * L)
|
||||
{
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getPositions", w_Contact_getPositions },
|
||||
{ "getNormal", w_Contact_getNormal },
|
||||
{ "getFriction", w_Contact_getFriction },
|
||||
{ "getRestitution", w_Contact_getRestitution },
|
||||
{ "isEnabled", w_Contact_isEnabled },
|
||||
{ "isTouching", w_Contact_isTouching },
|
||||
{ "setFriction", w_Contact_setFriction },
|
||||
{ "setRestitution", w_Contact_setRestitution },
|
||||
{ "setEnabled", w_Contact_setEnabled },
|
||||
{ "resetFriction", w_Contact_resetFriction },
|
||||
{ "resetRestitution", w_Contact_resetRestitution },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
return luax_register_type(L, "Contact", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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_Contact.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
Contact * luax_checkcontact(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Contact>(L, idx, "Contact", PHYSICS_CONTACT_T);
|
||||
}
|
||||
|
||||
int w_Contact_getPositions(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
return t->getPositions(L);
|
||||
}
|
||||
|
||||
int w_Contact_getNormal(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
return t->getNormal(L);
|
||||
}
|
||||
|
||||
int w_Contact_getFriction(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
lua_pushnumber(L, t->getFriction());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_getRestitution(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
lua_pushnumber(L, t->getRestitution());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_isEnabled(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
lua_pushboolean(L, t->isEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_isTouching(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
lua_pushboolean(L, t->isTouching());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Contact_setFriction(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
float f = (float)luaL_checknumber(L, 2);
|
||||
t->setFriction(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_setRestitution(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
float r = (float)luaL_checknumber(L, 2);
|
||||
t->setRestitution(r);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_setEnabled(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
bool e = luax_toboolean(L, 2);
|
||||
t->setEnabled(e);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_resetFriction(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
t->resetFriction();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_Contact_resetRestitution(lua_State * L)
|
||||
{
|
||||
Contact * t = luax_checkcontact(L, 1);
|
||||
t->resetRestitution();
|
||||
return 0;
|
||||
}
|
||||
|
||||
int luaopen_contact(lua_State * L)
|
||||
{
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getPositions", w_Contact_getPositions },
|
||||
{ "getNormal", w_Contact_getNormal },
|
||||
{ "getFriction", w_Contact_getFriction },
|
||||
{ "getRestitution", w_Contact_getRestitution },
|
||||
{ "isEnabled", w_Contact_isEnabled },
|
||||
{ "isTouching", w_Contact_isTouching },
|
||||
{ "setFriction", w_Contact_setFriction },
|
||||
{ "setRestitution", w_Contact_setRestitution },
|
||||
{ "setEnabled", w_Contact_setEnabled },
|
||||
{ "resetFriction", w_Contact_resetFriction },
|
||||
{ "resetRestitution", w_Contact_resetRestitution },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
return luax_register_type(L, "Contact", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,52 +1,52 @@
|
||||
/**
|
||||
* 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_CONTACT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_CONTACT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Contact.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Contact * luax_checkcontact(lua_State * L, int idx);
|
||||
int w_Contact_getPositions(lua_State * L);
|
||||
int w_Contact_getNormal(lua_State * L);
|
||||
int w_Contact_getFriction(lua_State * L);
|
||||
int w_Contact_getRestitution(lua_State * L);
|
||||
int w_Contact_isEnabled(lua_State * L);
|
||||
int w_Contact_isTouching(lua_State * L);
|
||||
int w_Contact_setFriction(lua_State * L);
|
||||
int w_Contact_setRestitution(lua_State * L);
|
||||
int w_Contact_setEnabled(lua_State * L);
|
||||
int w_Contact_resetFriction(lua_State * L);
|
||||
int w_Contact_resetRestitution(lua_State * L);
|
||||
int luaopen_contact(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_CONTACT_H
|
||||
/**
|
||||
* 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_CONTACT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_CONTACT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Contact.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Contact * luax_checkcontact(lua_State * L, int idx);
|
||||
int w_Contact_getPositions(lua_State * L);
|
||||
int w_Contact_getNormal(lua_State * L);
|
||||
int w_Contact_getFriction(lua_State * L);
|
||||
int w_Contact_getRestitution(lua_State * L);
|
||||
int w_Contact_isEnabled(lua_State * L);
|
||||
int w_Contact_isTouching(lua_State * L);
|
||||
int w_Contact_setFriction(lua_State * L);
|
||||
int w_Contact_setRestitution(lua_State * L);
|
||||
int w_Contact_setEnabled(lua_State * L);
|
||||
int w_Contact_resetFriction(lua_State * L);
|
||||
int w_Contact_resetRestitution(lua_State * L);
|
||||
int luaopen_contact(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_CONTACT_H
|
||||
|
||||
@@ -1,103 +1,103 @@
|
||||
/**
|
||||
* 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_DistanceJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
DistanceJoint * luax_checkdistancejoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<DistanceJoint>(L, idx, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T);
|
||||
}
|
||||
|
||||
int w_DistanceJoint_setLength(lua_State * L)
|
||||
{
|
||||
DistanceJoint * t = luax_checkdistancejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLength(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_getLength(lua_State * L)
|
||||
{
|
||||
DistanceJoint * t = luax_checkdistancejoint(L, 1);
|
||||
lua_pushnumber(L, t->getLength());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_setFrequency(lua_State * L)
|
||||
{
|
||||
DistanceJoint * t = luax_checkdistancejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setFrequency(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_getFrequency(lua_State * L)
|
||||
{
|
||||
DistanceJoint * t = luax_checkdistancejoint(L, 1);
|
||||
lua_pushnumber(L, t->getFrequency());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_setDampingRatio(lua_State * L)
|
||||
{
|
||||
DistanceJoint * t = luax_checkdistancejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_getDampingRatio(lua_State * L)
|
||||
{
|
||||
DistanceJoint * t = luax_checkdistancejoint(L, 1);
|
||||
lua_pushnumber(L, t->getDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "setLength", w_DistanceJoint_setLength },
|
||||
{ "getLength", w_DistanceJoint_getLength },
|
||||
{ "setFrequency", w_DistanceJoint_setFrequency },
|
||||
{ "getFrequency", w_DistanceJoint_getFrequency },
|
||||
{ "setDampingRatio", w_DistanceJoint_setDampingRatio },
|
||||
{ "getDampingRatio", w_DistanceJoint_getDampingRatio },
|
||||
// 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_distancejoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "DistanceJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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_DistanceJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
DistanceJoint * luax_checkdistancejoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<DistanceJoint>(L, idx, "DistanceJoint", PHYSICS_DISTANCE_JOINT_T);
|
||||
}
|
||||
|
||||
int w_DistanceJoint_setLength(lua_State * L)
|
||||
{
|
||||
DistanceJoint * t = luax_checkdistancejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLength(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_getLength(lua_State * L)
|
||||
{
|
||||
DistanceJoint * t = luax_checkdistancejoint(L, 1);
|
||||
lua_pushnumber(L, t->getLength());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_setFrequency(lua_State * L)
|
||||
{
|
||||
DistanceJoint * t = luax_checkdistancejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setFrequency(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_getFrequency(lua_State * L)
|
||||
{
|
||||
DistanceJoint * t = luax_checkdistancejoint(L, 1);
|
||||
lua_pushnumber(L, t->getFrequency());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_setDampingRatio(lua_State * L)
|
||||
{
|
||||
DistanceJoint * t = luax_checkdistancejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_DistanceJoint_getDampingRatio(lua_State * L)
|
||||
{
|
||||
DistanceJoint * t = luax_checkdistancejoint(L, 1);
|
||||
lua_pushnumber(L, t->getDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "setLength", w_DistanceJoint_setLength },
|
||||
{ "getLength", w_DistanceJoint_getLength },
|
||||
{ "setFrequency", w_DistanceJoint_setFrequency },
|
||||
{ "getFrequency", w_DistanceJoint_getFrequency },
|
||||
{ "setDampingRatio", w_DistanceJoint_setDampingRatio },
|
||||
{ "getDampingRatio", w_DistanceJoint_getDampingRatio },
|
||||
// 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_distancejoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "DistanceJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,48 +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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_DISTANCE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_DISTANCE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "DistanceJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
DistanceJoint * luax_checkdistancejoint(lua_State * L, int idx);
|
||||
int w_DistanceJoint_setLength(lua_State * L);
|
||||
int w_DistanceJoint_getLength(lua_State * L);
|
||||
int w_DistanceJoint_setFrequency(lua_State * L);
|
||||
int w_DistanceJoint_getFrequency(lua_State * L);
|
||||
int w_DistanceJoint_setDampingRatio(lua_State * L);
|
||||
int w_DistanceJoint_getDampingRatio(lua_State * L);
|
||||
int luaopen_distancejoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_DISTANCE_JOINT_H
|
||||
/**
|
||||
* 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_DISTANCE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_DISTANCE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "DistanceJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
DistanceJoint * luax_checkdistancejoint(lua_State * L, int idx);
|
||||
int w_DistanceJoint_setLength(lua_State * L);
|
||||
int w_DistanceJoint_getLength(lua_State * L);
|
||||
int w_DistanceJoint_setFrequency(lua_State * L);
|
||||
int w_DistanceJoint_getFrequency(lua_State * L);
|
||||
int w_DistanceJoint_setDampingRatio(lua_State * L);
|
||||
int w_DistanceJoint_getDampingRatio(lua_State * L);
|
||||
int luaopen_distancejoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_DISTANCE_JOINT_H
|
||||
|
||||
@@ -1,62 +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.
|
||||
**/
|
||||
|
||||
#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);
|
||||
}
|
||||
|
||||
int w_EdgeShape_getPoints(lua_State * L)
|
||||
{
|
||||
EdgeShape * t = luax_checkedgeshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getPoints(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getPoints", w_EdgeShape_getPoints },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ "destroy", w_Shape_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_edgeshape(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "EdgeShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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);
|
||||
}
|
||||
|
||||
int w_EdgeShape_getPoints(lua_State * L)
|
||||
{
|
||||
EdgeShape * t = luax_checkedgeshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getPoints(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getPoints", w_EdgeShape_getPoints },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ "destroy", w_Shape_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_edgeshape(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "EdgeShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,43 +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_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 w_EdgeShape_getPoints(lua_State * L);
|
||||
int luaopen_edgeshape(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_EDGE_SHAPE_H
|
||||
/**
|
||||
* 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 w_EdgeShape_getPoints(lua_State * L);
|
||||
int luaopen_edgeshape(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_EDGE_SHAPE_H
|
||||
|
||||
@@ -105,18 +105,18 @@ namespace box2d
|
||||
{
|
||||
Fixture * t = luax_checkfixture(L, 1);
|
||||
Body * body = t->getBody();
|
||||
if(body == 0)
|
||||
if (body == 0)
|
||||
return 0;
|
||||
body->retain();
|
||||
luax_newtype(L, "Body", PHYSICS_BODY_T, (void*)body);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int w_Fixture_getShape(lua_State * L)
|
||||
{
|
||||
Fixture * t = luax_checkfixture(L, 1);
|
||||
Shape * shape = t->getShape();
|
||||
if(shape == 0)
|
||||
if (shape == 0)
|
||||
return 0;
|
||||
shape->retain();
|
||||
switch (shape->getType()) {
|
||||
@@ -225,7 +225,7 @@ namespace box2d
|
||||
lua_remove(L, 1);
|
||||
return t->getBoundingBox(L);
|
||||
}
|
||||
|
||||
|
||||
int w_Fixture_getMassData(lua_State * L)
|
||||
{
|
||||
Fixture * t = luax_checkfixture(L, 1);
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -45,7 +45,7 @@ namespace box2d
|
||||
lua_pushnumber(L, t->getMaxForce());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int w_FrictionJoint_setMaxTorque(lua_State * L)
|
||||
{
|
||||
FrictionJoint * t = luax_checkfrictionjoint(L, 1);
|
||||
@@ -53,14 +53,14 @@ namespace box2d
|
||||
t->setMaxTorque(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
int w_FrictionJoint_getMaxTorque(lua_State * L)
|
||||
{
|
||||
FrictionJoint * t = luax_checkfrictionjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "setMaxForce", w_FrictionJoint_setMaxForce },
|
||||
{ "getMaxForce", w_FrictionJoint_getMaxForce },
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -1,69 +1,69 @@
|
||||
/**
|
||||
* 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_GearJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
GearJoint * luax_checkgearjoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<GearJoint>(L, idx, "GearJoint", PHYSICS_GEAR_JOINT_T);
|
||||
}
|
||||
|
||||
int w_GearJoint_setRatio(lua_State * L)
|
||||
{
|
||||
GearJoint * t = luax_checkgearjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_GearJoint_getRatio(lua_State * L)
|
||||
{
|
||||
GearJoint * t = luax_checkgearjoint(L, 1);
|
||||
lua_pushnumber(L, t->getRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "setRatio", w_GearJoint_setRatio },
|
||||
{ "getRatio", w_GearJoint_getRatio },
|
||||
// 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_gearjoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "GearJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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_GearJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
GearJoint * luax_checkgearjoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<GearJoint>(L, idx, "GearJoint", PHYSICS_GEAR_JOINT_T);
|
||||
}
|
||||
|
||||
int w_GearJoint_setRatio(lua_State * L)
|
||||
{
|
||||
GearJoint * t = luax_checkgearjoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_GearJoint_getRatio(lua_State * L)
|
||||
{
|
||||
GearJoint * t = luax_checkgearjoint(L, 1);
|
||||
lua_pushnumber(L, t->getRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "setRatio", w_GearJoint_setRatio },
|
||||
{ "getRatio", w_GearJoint_getRatio },
|
||||
// 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_gearjoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "GearJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,44 +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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_GEAR_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_GEAR_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "GearJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
GearJoint * luax_checkgearjoint(lua_State * L, int idx);
|
||||
int w_GearJoint_setRatio(lua_State * L);
|
||||
int w_GearJoint_getRatio(lua_State * L);
|
||||
int luaopen_gearjoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_GEAR_JOINT_H
|
||||
/**
|
||||
* 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_GEAR_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_GEAR_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "GearJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
GearJoint * luax_checkgearjoint(lua_State * L, int idx);
|
||||
int w_GearJoint_setRatio(lua_State * L);
|
||||
int w_GearJoint_getRatio(lua_State * L);
|
||||
int luaopen_gearjoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_GEAR_JOINT_H
|
||||
|
||||
@@ -1,102 +1,102 @@
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Joint.h"
|
||||
#include <common/StringMap.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Joint * luax_checkjoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Joint>(L, idx, "Joint", PHYSICS_JOINT_T);
|
||||
}
|
||||
|
||||
int w_Joint_getType(lua_State * L)
|
||||
{
|
||||
Joint * t = luax_checkjoint(L, 1);
|
||||
const char * type = "";
|
||||
Joint::getConstant(t->getType(), type);
|
||||
lua_pushstring(L, type);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_getAnchors(lua_State * L)
|
||||
{
|
||||
Joint * t = luax_checkjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getAnchors(L);
|
||||
}
|
||||
|
||||
int w_Joint_getReactionForce(lua_State * L)
|
||||
{
|
||||
Joint * t = luax_checkjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getReactionForce(L);
|
||||
}
|
||||
|
||||
int w_Joint_getReactionTorque(lua_State * L)
|
||||
{
|
||||
Joint * t = luax_checkjoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getReactionTorque(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_getCollideConnected(lua_State * L)
|
||||
{
|
||||
Joint * t = luax_checkjoint(L, 1);
|
||||
luax_pushboolean(L, t->getCollideConnected());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_destroy(lua_State * L)
|
||||
{
|
||||
Proxy * p = (Proxy *)lua_touserdata(L, 1);
|
||||
p->own = false;
|
||||
|
||||
Joint * t = (Joint *)p->data;
|
||||
t->release();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "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_joint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "Joint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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.
|
||||
**/
|
||||
|
||||
// LOVE
|
||||
#include "wrap_Joint.h"
|
||||
#include <common/StringMap.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Joint * luax_checkjoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Joint>(L, idx, "Joint", PHYSICS_JOINT_T);
|
||||
}
|
||||
|
||||
int w_Joint_getType(lua_State * L)
|
||||
{
|
||||
Joint * t = luax_checkjoint(L, 1);
|
||||
const char * type = "";
|
||||
Joint::getConstant(t->getType(), type);
|
||||
lua_pushstring(L, type);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_getAnchors(lua_State * L)
|
||||
{
|
||||
Joint * t = luax_checkjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getAnchors(L);
|
||||
}
|
||||
|
||||
int w_Joint_getReactionForce(lua_State * L)
|
||||
{
|
||||
Joint * t = luax_checkjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getReactionForce(L);
|
||||
}
|
||||
|
||||
int w_Joint_getReactionTorque(lua_State * L)
|
||||
{
|
||||
Joint * t = luax_checkjoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getReactionTorque(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_getCollideConnected(lua_State * L)
|
||||
{
|
||||
Joint * t = luax_checkjoint(L, 1);
|
||||
luax_pushboolean(L, t->getCollideConnected());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Joint_destroy(lua_State * L)
|
||||
{
|
||||
Proxy * p = (Proxy *)lua_touserdata(L, 1);
|
||||
p->own = false;
|
||||
|
||||
Joint * t = (Joint *)p->data;
|
||||
t->release();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "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_joint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "Joint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,47 +1,47 @@
|
||||
/**
|
||||
* 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_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Joint * luax_checkjoint(lua_State * L, int idx);
|
||||
int w_Joint_getType(lua_State * L);
|
||||
int w_Joint_getAnchors(lua_State * L);
|
||||
int w_Joint_getReactionForce(lua_State * L);
|
||||
int w_Joint_getReactionTorque(lua_State * L);
|
||||
int w_Joint_getCollideConnected(lua_State * L);
|
||||
int w_Joint_destroy(lua_State * L);
|
||||
int luaopen_joint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_JOINT_H
|
||||
/**
|
||||
* 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_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Joint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Joint * luax_checkjoint(lua_State * L, int idx);
|
||||
int w_Joint_getType(lua_State * L);
|
||||
int w_Joint_getAnchors(lua_State * L);
|
||||
int w_Joint_getReactionForce(lua_State * L);
|
||||
int w_Joint_getReactionTorque(lua_State * L);
|
||||
int w_Joint_getCollideConnected(lua_State * L);
|
||||
int w_Joint_destroy(lua_State * L);
|
||||
int luaopen_joint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_JOINT_H
|
||||
|
||||
@@ -1,121 +1,121 @@
|
||||
/**
|
||||
* 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_MouseJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
MouseJoint * luax_checkmousejoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<MouseJoint>(L, idx, "MouseJoint", PHYSICS_MOUSE_JOINT_T);
|
||||
}
|
||||
|
||||
int w_MouseJoint_setTarget(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
t->setTarget(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getTarget(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getTarget(L);
|
||||
}
|
||||
|
||||
int w_MouseJoint_setMaxForce(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
float f = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxForce(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getMaxForce(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxForce());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_MouseJoint_setFrequency(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setFrequency(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getFrequency(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
lua_pushnumber(L, t->getFrequency());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_MouseJoint_setDampingRatio(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getDampingRatio(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
lua_pushnumber(L, t->getDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "setTarget", w_MouseJoint_setTarget },
|
||||
{ "getTarget", w_MouseJoint_getTarget },
|
||||
{ "setMaxForce", w_MouseJoint_setMaxForce },
|
||||
{ "getMaxForce", w_MouseJoint_getMaxForce },
|
||||
{ "setFrequency", w_MouseJoint_setFrequency },
|
||||
{ "getFrequency", w_MouseJoint_getFrequency },
|
||||
{ "setDampingRatio", w_MouseJoint_setDampingRatio },
|
||||
{ "getDampingRatio", w_MouseJoint_getDampingRatio },
|
||||
// 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_mousejoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "MouseJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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_MouseJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
MouseJoint * luax_checkmousejoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<MouseJoint>(L, idx, "MouseJoint", PHYSICS_MOUSE_JOINT_T);
|
||||
}
|
||||
|
||||
int w_MouseJoint_setTarget(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 2);
|
||||
float y = (float)luaL_checknumber(L, 3);
|
||||
t->setTarget(x, y);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getTarget(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getTarget(L);
|
||||
}
|
||||
|
||||
int w_MouseJoint_setMaxForce(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
float f = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxForce(f);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getMaxForce(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxForce());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_MouseJoint_setFrequency(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setFrequency(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getFrequency(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
lua_pushnumber(L, t->getFrequency());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_MouseJoint_setDampingRatio(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setDampingRatio(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_MouseJoint_getDampingRatio(lua_State * L)
|
||||
{
|
||||
MouseJoint * t = luax_checkmousejoint(L, 1);
|
||||
lua_pushnumber(L, t->getDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "setTarget", w_MouseJoint_setTarget },
|
||||
{ "getTarget", w_MouseJoint_getTarget },
|
||||
{ "setMaxForce", w_MouseJoint_setMaxForce },
|
||||
{ "getMaxForce", w_MouseJoint_getMaxForce },
|
||||
{ "setFrequency", w_MouseJoint_setFrequency },
|
||||
{ "getFrequency", w_MouseJoint_getFrequency },
|
||||
{ "setDampingRatio", w_MouseJoint_setDampingRatio },
|
||||
{ "getDampingRatio", w_MouseJoint_getDampingRatio },
|
||||
// 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_mousejoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "MouseJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,50 +1,50 @@
|
||||
/**
|
||||
* 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_MOUSE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_MOUSE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "MouseJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
MouseJoint * luax_checkmousejoint(lua_State * L, int idx);
|
||||
int w_MouseJoint_setTarget(lua_State * L);
|
||||
int w_MouseJoint_getTarget(lua_State * L);
|
||||
int w_MouseJoint_setMaxForce(lua_State * L);
|
||||
int w_MouseJoint_getMaxForce(lua_State * L);
|
||||
int w_MouseJoint_setFrequency(lua_State * L);
|
||||
int w_MouseJoint_getFrequency(lua_State * L);
|
||||
int w_MouseJoint_setDampingRatio(lua_State * L);
|
||||
int w_MouseJoint_getDampingRatio(lua_State * L);
|
||||
int luaopen_mousejoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_MOUSE_JOINT_H
|
||||
/**
|
||||
* 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_MOUSE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_MOUSE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "MouseJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
MouseJoint * luax_checkmousejoint(lua_State * L, int idx);
|
||||
int w_MouseJoint_setTarget(lua_State * L);
|
||||
int w_MouseJoint_getTarget(lua_State * L);
|
||||
int w_MouseJoint_setMaxForce(lua_State * L);
|
||||
int w_MouseJoint_getMaxForce(lua_State * L);
|
||||
int w_MouseJoint_setFrequency(lua_State * L);
|
||||
int w_MouseJoint_getFrequency(lua_State * L);
|
||||
int w_MouseJoint_setDampingRatio(lua_State * L);
|
||||
int w_MouseJoint_getDampingRatio(lua_State * L);
|
||||
int luaopen_mousejoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_MOUSE_JOINT_H
|
||||
|
||||
@@ -55,7 +55,7 @@ namespace box2d
|
||||
luax_newtype(L, "Body", PHYSICS_BODY_T, (void*)body);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int w_newFixture(lua_State * L)
|
||||
{
|
||||
Body * body = luax_checkbody(L, 1);
|
||||
@@ -71,7 +71,7 @@ namespace box2d
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
|
||||
if(top == 1)
|
||||
if (top == 1)
|
||||
{
|
||||
float radius = (float)luaL_checknumber(L, 1);
|
||||
CircleShape * shape;
|
||||
@@ -79,7 +79,7 @@ namespace box2d
|
||||
luax_newtype(L, "CircleShape", PHYSICS_CIRCLE_SHAPE_T, (void*)shape);
|
||||
return 1;
|
||||
}
|
||||
else if(top == 3)
|
||||
else if (top == 3)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
@@ -97,7 +97,7 @@ namespace box2d
|
||||
{
|
||||
int top = lua_gettop(L);
|
||||
|
||||
if(top == 2)
|
||||
if (top == 2)
|
||||
{
|
||||
float w = (float)luaL_checknumber(L, 1);
|
||||
float h = (float)luaL_checknumber(L, 2);
|
||||
@@ -106,7 +106,7 @@ namespace box2d
|
||||
luax_newtype(L, "PolygonShape", PHYSICS_POLYGON_SHAPE_T, (void*)shape);
|
||||
return 1;
|
||||
}
|
||||
else if(top == 4 || top == 5)
|
||||
else if (top == 4 || top == 5)
|
||||
{
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
@@ -121,7 +121,7 @@ namespace box2d
|
||||
else
|
||||
return luaL_error(L, "Incorrect number of parameters");
|
||||
}
|
||||
|
||||
|
||||
int w_newEdgeShape(lua_State * L)
|
||||
{
|
||||
float x1 = (float)luaL_checknumber(L, 1);
|
||||
@@ -138,7 +138,7 @@ namespace box2d
|
||||
{
|
||||
ASSERT_GUARD(return instance->newPolygonShape(L);)
|
||||
}
|
||||
|
||||
|
||||
int w_newChainShape(lua_State * L)
|
||||
{
|
||||
ASSERT_GUARD(return instance->newChainShape(L);)
|
||||
@@ -191,13 +191,16 @@ namespace box2d
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB, ax, ay;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 8) {
|
||||
if (lua_gettop(L) >= 8)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
ax = (float)luaL_checknumber(L, 7);
|
||||
ay = (float)luaL_checknumber(L, 8);
|
||||
collideConnected = luax_optboolean(L, 9, false);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
ax = (float)luaL_checknumber(L, 5);
|
||||
@@ -243,7 +246,7 @@ namespace box2d
|
||||
luax_newtype(L, "GearJoint", PHYSICS_GEAR_JOINT_T, (void*)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int w_newFrictionJoint(lua_State * L)
|
||||
{
|
||||
Body * body1 = luax_checktype<Body>(L, 1, "Body", PHYSICS_BODY_T);
|
||||
@@ -252,11 +255,14 @@ namespace box2d
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 6) {
|
||||
if (lua_gettop(L) >= 6)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
collideConnected = luax_optboolean(L, 7, false);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
collideConnected = luax_optboolean(L, 5, false);
|
||||
@@ -266,7 +272,7 @@ 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);
|
||||
@@ -275,11 +281,14 @@ namespace box2d
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 6) {
|
||||
if (lua_gettop(L) >= 6)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
collideConnected = luax_optboolean(L, 7, false);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
collideConnected = luax_optboolean(L, 5, false);
|
||||
@@ -289,7 +298,7 @@ namespace box2d
|
||||
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);
|
||||
@@ -298,13 +307,16 @@ namespace box2d
|
||||
float yA = (float)luaL_checknumber(L, 4);
|
||||
float xB, yB, ax, ay;
|
||||
bool collideConnected;
|
||||
if (lua_gettop(L) >= 8) {
|
||||
if (lua_gettop(L) >= 8)
|
||||
{
|
||||
xB = (float)luaL_checknumber(L, 5);
|
||||
yB = (float)luaL_checknumber(L, 6);
|
||||
ax = (float)luaL_checknumber(L, 7);
|
||||
ay = (float)luaL_checknumber(L, 8);
|
||||
collideConnected = luax_optboolean(L, 9, false);
|
||||
} else {
|
||||
}
|
||||
else
|
||||
{
|
||||
xB = xA;
|
||||
yB = yA;
|
||||
ax = (float)luaL_checknumber(L, 5);
|
||||
@@ -317,7 +329,7 @@ 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);
|
||||
@@ -333,22 +345,25 @@ namespace box2d
|
||||
luax_newtype(L, "RopeJoint", PHYSICS_ROPE_JOINT_T, (void*)j);
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int w_getDistance(lua_State * L)
|
||||
{
|
||||
return instance->getDistance(L);
|
||||
}
|
||||
|
||||
|
||||
int w_setMeter(lua_State * L)
|
||||
{
|
||||
int arg1 = luaL_checkint(L, 1);
|
||||
try {
|
||||
try
|
||||
{
|
||||
Physics::setMeter(arg1);
|
||||
} catch (love::Exception e) {
|
||||
}
|
||||
catch (love::Exception e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
return 0;
|
||||
|
||||
|
||||
}
|
||||
int w_getMeter(lua_State * L)
|
||||
{
|
||||
@@ -408,13 +423,13 @@ namespace box2d
|
||||
|
||||
int luaopen_love_physics(lua_State * L)
|
||||
{
|
||||
if(instance == 0)
|
||||
if (instance == 0)
|
||||
{
|
||||
try
|
||||
{
|
||||
instance = new Physics();
|
||||
}
|
||||
catch(Exception & e)
|
||||
catch (Exception & e)
|
||||
{
|
||||
return luaL_error(L, e.what());
|
||||
}
|
||||
|
||||
@@ -1,83 +1,83 @@
|
||||
/**
|
||||
* 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_PHYSICS_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PHYSICS_H
|
||||
|
||||
// LOVE
|
||||
#include <common/config.h>
|
||||
#include "Physics.h"
|
||||
#include "wrap_World.h"
|
||||
#include "wrap_Contact.h"
|
||||
#include "wrap_Body.h"
|
||||
#include "wrap_Fixture.h"
|
||||
#include "wrap_Shape.h"
|
||||
#include "wrap_CircleShape.h"
|
||||
#include "wrap_PolygonShape.h"
|
||||
#include "wrap_EdgeShape.h"
|
||||
#include "wrap_ChainShape.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "wrap_MouseJoint.h"
|
||||
#include "wrap_DistanceJoint.h"
|
||||
#include "wrap_PrismaticJoint.h"
|
||||
#include "wrap_RevoluteJoint.h"
|
||||
#include "wrap_PulleyJoint.h"
|
||||
#include "wrap_GearJoint.h"
|
||||
#include "wrap_FrictionJoint.h"
|
||||
#include "wrap_WeldJoint.h"
|
||||
#include "wrap_WheelJoint.h"
|
||||
#include "wrap_RopeJoint.h"
|
||||
|
||||
#define ASSERT_GUARD(A) try { A } catch (love::Exception & e) { return luaL_error(L, "%s", e.what()); }
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
int w_newWorld(lua_State * L);
|
||||
int w_newBody(lua_State * L);
|
||||
int w_newFixture(lua_State * L);
|
||||
int w_newCircleShape(lua_State * L);
|
||||
int w_newRectangleShape(lua_State * L);
|
||||
int w_newPolygonShape(lua_State * L);
|
||||
int w_newEdgeShape(lua_State * L);
|
||||
int w_newChainShape(lua_State * L);
|
||||
int w_newDistanceJoint(lua_State * L);
|
||||
int w_newMouseJoint(lua_State * L);
|
||||
int w_newRevoluteJoint(lua_State * L);
|
||||
int w_newPrismaticJoint(lua_State * L);
|
||||
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);
|
||||
int w_newRopeJoint(lua_State * L);
|
||||
int w_getDistance(lua_State * L);
|
||||
int w_setMeter(lua_State * L);
|
||||
int w_getMeter(lua_State * L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_physics(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PHYSICS_H
|
||||
/**
|
||||
* 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_PHYSICS_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PHYSICS_H
|
||||
|
||||
// LOVE
|
||||
#include <common/config.h>
|
||||
#include "Physics.h"
|
||||
#include "wrap_World.h"
|
||||
#include "wrap_Contact.h"
|
||||
#include "wrap_Body.h"
|
||||
#include "wrap_Fixture.h"
|
||||
#include "wrap_Shape.h"
|
||||
#include "wrap_CircleShape.h"
|
||||
#include "wrap_PolygonShape.h"
|
||||
#include "wrap_EdgeShape.h"
|
||||
#include "wrap_ChainShape.h"
|
||||
#include "wrap_Joint.h"
|
||||
#include "wrap_MouseJoint.h"
|
||||
#include "wrap_DistanceJoint.h"
|
||||
#include "wrap_PrismaticJoint.h"
|
||||
#include "wrap_RevoluteJoint.h"
|
||||
#include "wrap_PulleyJoint.h"
|
||||
#include "wrap_GearJoint.h"
|
||||
#include "wrap_FrictionJoint.h"
|
||||
#include "wrap_WeldJoint.h"
|
||||
#include "wrap_WheelJoint.h"
|
||||
#include "wrap_RopeJoint.h"
|
||||
|
||||
#define ASSERT_GUARD(A) try { A } catch (love::Exception & e) { return luaL_error(L, "%s", e.what()); }
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
int w_newWorld(lua_State * L);
|
||||
int w_newBody(lua_State * L);
|
||||
int w_newFixture(lua_State * L);
|
||||
int w_newCircleShape(lua_State * L);
|
||||
int w_newRectangleShape(lua_State * L);
|
||||
int w_newPolygonShape(lua_State * L);
|
||||
int w_newEdgeShape(lua_State * L);
|
||||
int w_newChainShape(lua_State * L);
|
||||
int w_newDistanceJoint(lua_State * L);
|
||||
int w_newMouseJoint(lua_State * L);
|
||||
int w_newRevoluteJoint(lua_State * L);
|
||||
int w_newPrismaticJoint(lua_State * L);
|
||||
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);
|
||||
int w_newRopeJoint(lua_State * L);
|
||||
int w_getDistance(lua_State * L);
|
||||
int w_setMeter(lua_State * L);
|
||||
int w_getMeter(lua_State * L);
|
||||
extern "C" LOVE_EXPORT int luaopen_love_physics(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PHYSICS_H
|
||||
|
||||
@@ -1,62 +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.
|
||||
**/
|
||||
|
||||
#include "wrap_PolygonShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PolygonShape * luax_checkpolygonshape(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<PolygonShape>(L, idx, "PolygonShape", PHYSICS_POLYGON_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_PolygonShape_getPoints(lua_State * L)
|
||||
{
|
||||
PolygonShape * t = luax_checkpolygonshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getPoints(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getPoints", w_PolygonShape_getPoints },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ "destroy", w_Shape_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_polygonshape(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "PolygonShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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_PolygonShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PolygonShape * luax_checkpolygonshape(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<PolygonShape>(L, idx, "PolygonShape", PHYSICS_POLYGON_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_PolygonShape_getPoints(lua_State * L)
|
||||
{
|
||||
PolygonShape * t = luax_checkpolygonshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getPoints(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getPoints", w_PolygonShape_getPoints },
|
||||
// From Shape.
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ "destroy", w_Shape_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_polygonshape(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "PolygonShape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,43 +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_POLYGON_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_POLYGON_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Shape.h"
|
||||
#include "PolygonShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PolygonShape * luax_checkpolygonshape(lua_State * L, int idx);
|
||||
int w_PolygonShape_getPoints(lua_State * L);
|
||||
int luaopen_polygonshape(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_POLYGON_SHAPE_H
|
||||
/**
|
||||
* 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_POLYGON_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_POLYGON_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Shape.h"
|
||||
#include "PolygonShape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PolygonShape * luax_checkpolygonshape(lua_State * L, int idx);
|
||||
int w_PolygonShape_getPoints(lua_State * L);
|
||||
int luaopen_polygonshape(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_POLYGON_SHAPE_H
|
||||
|
||||
@@ -1,197 +1,197 @@
|
||||
/**
|
||||
* 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_PrismaticJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PrismaticJoint * luax_checkprismaticjoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<PrismaticJoint>(L, idx, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T);
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getJointTranslation(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointTranslation());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getJointSpeed(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_enableMotor(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_isMotorEnabled(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setMaxMotorForce(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);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMotorSpeed(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMotorForce(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getMotorForce(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMaxMotorForce(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorForce());
|
||||
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);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setUpperLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setLowerLimit(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());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getUpperLimit(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getUpperLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getLimits(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getLimits(L);
|
||||
}
|
||||
|
||||
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 },
|
||||
{ "getMaxMotorForce", w_PrismaticJoint_getMaxMotorForce },
|
||||
{ "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 },
|
||||
// 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_prismaticjoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "PrismaticJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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_PrismaticJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PrismaticJoint * luax_checkprismaticjoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<PrismaticJoint>(L, idx, "PrismaticJoint", PHYSICS_PRISMATIC_JOINT_T);
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getJointTranslation(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointTranslation());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getJointSpeed(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_enableMotor(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_isMotorEnabled(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setMaxMotorForce(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);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMotorSpeed(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMotorForce(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getMotorForce(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getMaxMotorForce(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorForce());
|
||||
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);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setUpperLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_setLowerLimit(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());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getUpperLimit(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_pushnumber(L, t->getUpperLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PrismaticJoint_getLimits(lua_State * L)
|
||||
{
|
||||
PrismaticJoint * t = luax_checkprismaticjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getLimits(L);
|
||||
}
|
||||
|
||||
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 },
|
||||
{ "getMaxMotorForce", w_PrismaticJoint_getMaxMotorForce },
|
||||
{ "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 },
|
||||
// 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_prismaticjoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "PrismaticJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,59 +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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "PrismaticJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
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_getMaxMotorForce(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);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
/**
|
||||
* 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_PRISMATIC_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "PrismaticJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
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_getMaxMotorForce(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);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PRISMATIC_JOINT_H
|
||||
|
||||
@@ -1,84 +1,84 @@
|
||||
/**
|
||||
* 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_PulleyJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PulleyJoint * luax_checkpulleyjoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<PulleyJoint>(L, idx, "PulleyJoint", PHYSICS_PULLEY_JOINT_T);
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getGroundAnchors(lua_State * L)
|
||||
{
|
||||
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getGroundAnchors(L);
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getLengthA(lua_State * L)
|
||||
{
|
||||
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
|
||||
lua_pushnumber(L, t->getLengthA());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getLengthB(lua_State * L)
|
||||
{
|
||||
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
|
||||
lua_pushnumber(L, t->getLengthB());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getRatio(lua_State * L)
|
||||
{
|
||||
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
|
||||
lua_pushnumber(L, t->getRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getGroundAnchors", w_PulleyJoint_getGroundAnchors },
|
||||
{ "getLengthA", w_PulleyJoint_getLengthA },
|
||||
{ "getLengthB", w_PulleyJoint_getLengthB },
|
||||
{ "getRatio", w_PulleyJoint_getRatio },
|
||||
// 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_pulleyjoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "PulleyJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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_PulleyJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PulleyJoint * luax_checkpulleyjoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<PulleyJoint>(L, idx, "PulleyJoint", PHYSICS_PULLEY_JOINT_T);
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getGroundAnchors(lua_State * L)
|
||||
{
|
||||
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getGroundAnchors(L);
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getLengthA(lua_State * L)
|
||||
{
|
||||
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
|
||||
lua_pushnumber(L, t->getLengthA());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getLengthB(lua_State * L)
|
||||
{
|
||||
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
|
||||
lua_pushnumber(L, t->getLengthB());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_PulleyJoint_getRatio(lua_State * L)
|
||||
{
|
||||
PulleyJoint * t = luax_checkpulleyjoint(L, 1);
|
||||
lua_pushnumber(L, t->getRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getGroundAnchors", w_PulleyJoint_getGroundAnchors },
|
||||
{ "getLengthA", w_PulleyJoint_getLengthA },
|
||||
{ "getLengthB", w_PulleyJoint_getLengthB },
|
||||
{ "getRatio", w_PulleyJoint_getRatio },
|
||||
// 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_pulleyjoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "PulleyJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,46 +1,46 @@
|
||||
/**
|
||||
* 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_PULLEY_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PULLEY_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "PulleyJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PulleyJoint * luax_checkpulleyjoint(lua_State * L, int idx);
|
||||
int w_PulleyJoint_getGroundAnchors(lua_State * L);
|
||||
int w_PulleyJoint_getLengthA(lua_State * L);
|
||||
int w_PulleyJoint_getLengthB(lua_State * L);
|
||||
int w_PulleyJoint_getRatio(lua_State * L);
|
||||
int luaopen_pulleyjoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PULLEY_JOINT_H
|
||||
/**
|
||||
* 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_PULLEY_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_PULLEY_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "PulleyJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
PulleyJoint * luax_checkpulleyjoint(lua_State * L, int idx);
|
||||
int w_PulleyJoint_getGroundAnchors(lua_State * L);
|
||||
int w_PulleyJoint_getLengthA(lua_State * L);
|
||||
int w_PulleyJoint_getLengthB(lua_State * L);
|
||||
int w_PulleyJoint_getRatio(lua_State * L);
|
||||
int luaopen_pulleyjoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_PULLEY_JOINT_H
|
||||
|
||||
@@ -1,197 +1,197 @@
|
||||
/**
|
||||
* 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_RevoluteJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
RevoluteJoint * luax_checkrevolutejoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<RevoluteJoint>(L, idx, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T);
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getJointAngle(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointAngle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getJointSpeed(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_enableMotor(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_isMotorEnabled(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setMaxMotorTorque(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxMotorTorque(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setMotorSpeed(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getMotorSpeed(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getMotorTorque(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getMotorTorque(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getMaxMotorTorque(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_enableLimit(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_isLimitEnabled(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
luax_pushboolean(L, t->isLimitEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setUpperLimit(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setUpperLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setLowerLimit(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLowerLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setLimits(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setLimits(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getLowerLimit(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getLowerLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getUpperLimit(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getUpperLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getLimits(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getLimits(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getJointAngle", w_RevoluteJoint_getJointAngle },
|
||||
{ "getJointSpeed", w_RevoluteJoint_getJointSpeed },
|
||||
{ "enableMotor", w_RevoluteJoint_enableMotor },
|
||||
{ "isMotorEnabled", w_RevoluteJoint_isMotorEnabled },
|
||||
{ "setMaxMotorTorque", w_RevoluteJoint_setMaxMotorTorque },
|
||||
{ "setMotorSpeed", w_RevoluteJoint_setMotorSpeed },
|
||||
{ "getMotorSpeed", w_RevoluteJoint_getMotorSpeed },
|
||||
{ "getMotorTorque", w_RevoluteJoint_getMotorTorque },
|
||||
{ "getMaxMotorTorque", w_RevoluteJoint_getMaxMotorTorque },
|
||||
{ "enableLimit", w_RevoluteJoint_enableLimit },
|
||||
{ "isLimitEnabled", w_RevoluteJoint_isLimitEnabled },
|
||||
{ "setUpperLimit", w_RevoluteJoint_setUpperLimit },
|
||||
{ "setLowerLimit", w_RevoluteJoint_setLowerLimit },
|
||||
{ "setLimits", w_RevoluteJoint_setLimits },
|
||||
{ "getLowerLimit", w_RevoluteJoint_getLowerLimit },
|
||||
{ "getUpperLimit", w_RevoluteJoint_getUpperLimit },
|
||||
{ "getLimits", w_RevoluteJoint_getLimits },
|
||||
// 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_revolutejoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "RevoluteJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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_RevoluteJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
RevoluteJoint * luax_checkrevolutejoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<RevoluteJoint>(L, idx, "RevoluteJoint", PHYSICS_REVOLUTE_JOINT_T);
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getJointAngle(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointAngle());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getJointSpeed(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_enableMotor(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_isMotorEnabled(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setMaxMotorTorque(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxMotorTorque(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setMotorSpeed(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getMotorSpeed(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getMotorTorque(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
float inv_dt = (float)luaL_checknumber(L, 2);
|
||||
lua_pushnumber(L, t->getMotorTorque(inv_dt));
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getMaxMotorTorque(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_enableLimit(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_isLimitEnabled(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
luax_pushboolean(L, t->isLimitEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setUpperLimit(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setUpperLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setLowerLimit(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setLowerLimit(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_setLimits(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setLimits(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getLowerLimit(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getLowerLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getUpperLimit(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_pushnumber(L, t->getUpperLimit());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_RevoluteJoint_getLimits(lua_State * L)
|
||||
{
|
||||
RevoluteJoint * t = luax_checkrevolutejoint(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getLimits(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getJointAngle", w_RevoluteJoint_getJointAngle },
|
||||
{ "getJointSpeed", w_RevoluteJoint_getJointSpeed },
|
||||
{ "enableMotor", w_RevoluteJoint_enableMotor },
|
||||
{ "isMotorEnabled", w_RevoluteJoint_isMotorEnabled },
|
||||
{ "setMaxMotorTorque", w_RevoluteJoint_setMaxMotorTorque },
|
||||
{ "setMotorSpeed", w_RevoluteJoint_setMotorSpeed },
|
||||
{ "getMotorSpeed", w_RevoluteJoint_getMotorSpeed },
|
||||
{ "getMotorTorque", w_RevoluteJoint_getMotorTorque },
|
||||
{ "getMaxMotorTorque", w_RevoluteJoint_getMaxMotorTorque },
|
||||
{ "enableLimit", w_RevoluteJoint_enableLimit },
|
||||
{ "isLimitEnabled", w_RevoluteJoint_isLimitEnabled },
|
||||
{ "setUpperLimit", w_RevoluteJoint_setUpperLimit },
|
||||
{ "setLowerLimit", w_RevoluteJoint_setLowerLimit },
|
||||
{ "setLimits", w_RevoluteJoint_setLimits },
|
||||
{ "getLowerLimit", w_RevoluteJoint_getLowerLimit },
|
||||
{ "getUpperLimit", w_RevoluteJoint_getUpperLimit },
|
||||
{ "getLimits", w_RevoluteJoint_getLimits },
|
||||
// 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_revolutejoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "RevoluteJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,59 +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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_REVOLUTE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_REVOLUTE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "RevoluteJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
RevoluteJoint * luax_checkrevolutejoint(lua_State * L, int idx);
|
||||
int w_RevoluteJoint_getJointAngle(lua_State * L);
|
||||
int w_RevoluteJoint_getJointSpeed(lua_State * L);
|
||||
int w_RevoluteJoint_enableMotor(lua_State * L);
|
||||
int w_RevoluteJoint_isMotorEnabled(lua_State * L);
|
||||
int w_RevoluteJoint_setMaxMotorTorque(lua_State * L);
|
||||
int w_RevoluteJoint_setMotorSpeed(lua_State * L);
|
||||
int w_RevoluteJoint_getMotorSpeed(lua_State * L);
|
||||
int w_RevoluteJoint_getMotorTorque(lua_State * L);
|
||||
int w_RevoluteJoint_getMaxMotorTorque(lua_State * L);
|
||||
int w_RevoluteJoint_enableLimit(lua_State * L);
|
||||
int w_RevoluteJoint_isLimitEnabled(lua_State * L);
|
||||
int w_RevoluteJoint_setUpperLimit(lua_State * L);
|
||||
int w_RevoluteJoint_setLowerLimit(lua_State * L);
|
||||
int w_RevoluteJoint_setLimits(lua_State * L);
|
||||
int w_RevoluteJoint_getLowerLimit(lua_State * L);
|
||||
int w_RevoluteJoint_getUpperLimit(lua_State * L);
|
||||
int w_RevoluteJoint_getLimits(lua_State * L);
|
||||
int luaopen_revolutejoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_REVOLUTE_JOINT_H
|
||||
/**
|
||||
* 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_REVOLUTE_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_REVOLUTE_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "RevoluteJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
RevoluteJoint * luax_checkrevolutejoint(lua_State * L, int idx);
|
||||
int w_RevoluteJoint_getJointAngle(lua_State * L);
|
||||
int w_RevoluteJoint_getJointSpeed(lua_State * L);
|
||||
int w_RevoluteJoint_enableMotor(lua_State * L);
|
||||
int w_RevoluteJoint_isMotorEnabled(lua_State * L);
|
||||
int w_RevoluteJoint_setMaxMotorTorque(lua_State * L);
|
||||
int w_RevoluteJoint_setMotorSpeed(lua_State * L);
|
||||
int w_RevoluteJoint_getMotorSpeed(lua_State * L);
|
||||
int w_RevoluteJoint_getMotorTorque(lua_State * L);
|
||||
int w_RevoluteJoint_getMaxMotorTorque(lua_State * L);
|
||||
int w_RevoluteJoint_enableLimit(lua_State * L);
|
||||
int w_RevoluteJoint_isLimitEnabled(lua_State * L);
|
||||
int w_RevoluteJoint_setUpperLimit(lua_State * L);
|
||||
int w_RevoluteJoint_setLowerLimit(lua_State * L);
|
||||
int w_RevoluteJoint_setLimits(lua_State * L);
|
||||
int w_RevoluteJoint_getLowerLimit(lua_State * L);
|
||||
int w_RevoluteJoint_getUpperLimit(lua_State * L);
|
||||
int w_RevoluteJoint_getLimits(lua_State * L);
|
||||
int luaopen_revolutejoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_REVOLUTE_JOINT_H
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
|
||||
@@ -1,124 +1,124 @@
|
||||
/**
|
||||
* 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_Shape.h"
|
||||
#include <common/StringMap.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Shape * luax_checkshape(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Shape>(L, idx, "Shape", PHYSICS_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_Shape_getType(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
const char * type = "";
|
||||
Shape::getConstant(t->getType(), type);
|
||||
lua_pushstring(L, type);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_getRadius(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
float radius = t->getRadius();
|
||||
lua_pushnumber(L, radius);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_getChildCount(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
int childCount = t->getChildCount();
|
||||
lua_pushinteger(L, childCount);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_testPoint(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
float r = (float)luaL_checknumber(L, 3);
|
||||
float px = (float)luaL_checknumber(L, 4);
|
||||
float py = (float)luaL_checknumber(L, 5);
|
||||
bool result = t->testPoint(x, y, r, px, py);
|
||||
lua_pushboolean(L, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_rayCast(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->rayCast(L);
|
||||
}
|
||||
|
||||
int w_Shape_computeAABB(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->computeAABB(L);
|
||||
}
|
||||
|
||||
int w_Shape_computeMass(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->computeMass(L);
|
||||
}
|
||||
|
||||
int w_Shape_destroy(lua_State * L)
|
||||
{
|
||||
Proxy * p = (Proxy *)lua_touserdata(L, 1);
|
||||
p->own = false;
|
||||
|
||||
Shape * t = (Shape *)p->data;
|
||||
t->release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ "destroy", w_Shape_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_shape(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "Shape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
/**
|
||||
* 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_Shape.h"
|
||||
#include <common/StringMap.h>
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Shape * luax_checkshape(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<Shape>(L, idx, "Shape", PHYSICS_SHAPE_T);
|
||||
}
|
||||
|
||||
int w_Shape_getType(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
const char * type = "";
|
||||
Shape::getConstant(t->getType(), type);
|
||||
lua_pushstring(L, type);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_getRadius(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
float radius = t->getRadius();
|
||||
lua_pushnumber(L, radius);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_getChildCount(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
int childCount = t->getChildCount();
|
||||
lua_pushinteger(L, childCount);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_testPoint(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
float x = (float)luaL_checknumber(L, 1);
|
||||
float y = (float)luaL_checknumber(L, 2);
|
||||
float r = (float)luaL_checknumber(L, 3);
|
||||
float px = (float)luaL_checknumber(L, 4);
|
||||
float py = (float)luaL_checknumber(L, 5);
|
||||
bool result = t->testPoint(x, y, r, px, py);
|
||||
lua_pushboolean(L, result);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_Shape_rayCast(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->rayCast(L);
|
||||
}
|
||||
|
||||
int w_Shape_computeAABB(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->computeAABB(L);
|
||||
}
|
||||
|
||||
int w_Shape_computeMass(lua_State * L)
|
||||
{
|
||||
Shape * t = luax_checkshape(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->computeMass(L);
|
||||
}
|
||||
|
||||
int w_Shape_destroy(lua_State * L)
|
||||
{
|
||||
Proxy * p = (Proxy *)lua_touserdata(L, 1);
|
||||
p->own = false;
|
||||
|
||||
Shape * t = (Shape *)p->data;
|
||||
t->release();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "getType", w_Shape_getType },
|
||||
{ "getRadius", w_Shape_getRadius },
|
||||
{ "getChildCount", w_Shape_getChildCount },
|
||||
{ "testPoint", w_Shape_testPoint },
|
||||
{ "rayCast", w_Shape_rayCast },
|
||||
{ "computeAABB", w_Shape_computeAABB },
|
||||
{ "computeMass", w_Shape_computeMass },
|
||||
{ "destroy", w_Shape_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_shape(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "Shape", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
|
||||
@@ -1,51 +1,51 @@
|
||||
/**
|
||||
* 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_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Shape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Shape * luax_checkshape(lua_State * L, int idx);
|
||||
int w_Shape_getType(lua_State * L);
|
||||
int w_Shape_getRadius(lua_State * L);
|
||||
|
||||
int w_Shape_getChildCount(lua_State * L);
|
||||
int w_Shape_testPoint(lua_State * L);
|
||||
int w_Shape_rayCast(lua_State * L);
|
||||
int w_Shape_computeAABB(lua_State * L);
|
||||
int w_Shape_computeMass(lua_State * L);
|
||||
|
||||
int w_Shape_destroy(lua_State * L);
|
||||
int luaopen_shape(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_SHAPE_H
|
||||
/**
|
||||
* 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_SHAPE_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_SHAPE_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "Shape.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
Shape * luax_checkshape(lua_State * L, int idx);
|
||||
int w_Shape_getType(lua_State * L);
|
||||
int w_Shape_getRadius(lua_State * L);
|
||||
|
||||
int w_Shape_getChildCount(lua_State * L);
|
||||
int w_Shape_testPoint(lua_State * L);
|
||||
int w_Shape_rayCast(lua_State * L);
|
||||
int w_Shape_computeAABB(lua_State * L);
|
||||
int w_Shape_computeMass(lua_State * L);
|
||||
|
||||
int w_Shape_destroy(lua_State * L);
|
||||
int luaopen_shape(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_SHAPE_H
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -30,7 +30,7 @@ namespace box2d
|
||||
{
|
||||
return luax_checktype<WeldJoint>(L, idx, "WeldJoint", PHYSICS_WELD_JOINT_T);
|
||||
}
|
||||
|
||||
|
||||
int w_WeldJoint_setFrequency(lua_State * L)
|
||||
{
|
||||
WeldJoint * t = luax_checkweldjoint(L, 1);
|
||||
@@ -60,7 +60,7 @@ namespace box2d
|
||||
lua_pushnumber(L, t->getDampingRatio());
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "setFrequency", w_WeldJoint_setFrequency },
|
||||
{ "getFrequency", w_WeldJoint_getFrequency },
|
||||
|
||||
@@ -1,14 +1,14 @@
|
||||
/**
|
||||
* 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
|
||||
@@ -33,12 +33,12 @@ namespace physics
|
||||
namespace box2d
|
||||
{
|
||||
WeldJoint * luax_checkweldjoint(lua_State * L, int idx);
|
||||
|
||||
|
||||
int w_WeldJoint_setFrequency(lua_State * L);
|
||||
int w_WeldJoint_getFrequency(lua_State * L);
|
||||
int w_WeldJoint_setDampingRatio(lua_State * L);
|
||||
int w_WeldJoint_getDampingRatio(lua_State * L);
|
||||
|
||||
|
||||
int luaopen_weldjoint(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
|
||||
@@ -1,162 +1,162 @@
|
||||
/**
|
||||
* 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_WheelJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
WheelJoint * luax_checkwheeljoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<WheelJoint>(L, idx, "WheelJoint", PHYSICS_WHEEL_JOINT_T);
|
||||
}
|
||||
|
||||
int w_WheelJoint_getJointTranslation(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointTranslation());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getJointSpeed(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_enableMotor(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_isMotorEnabled(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setMotorSpeed(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getMotorSpeed(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setMaxMotorTorque(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxMotorTorque(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getMaxMotorTorque(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getMotorTorque(lua_State * L)
|
||||
{
|
||||
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_WheelJoint_setSpringFrequencyHz(lua_State * 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_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 },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_wheeljoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "WheelJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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_WheelJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
WheelJoint * luax_checkwheeljoint(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<WheelJoint>(L, idx, "WheelJoint", PHYSICS_WHEEL_JOINT_T);
|
||||
}
|
||||
|
||||
int w_WheelJoint_getJointTranslation(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointTranslation());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getJointSpeed(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getJointSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_enableMotor(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
bool arg1 = luax_toboolean(L, 2);
|
||||
t->enableMotor(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_isMotorEnabled(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
luax_pushboolean(L, t->isMotorEnabled());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setMotorSpeed(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMotorSpeed(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getMotorSpeed(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getMotorSpeed());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_setMaxMotorTorque(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
t->setMaxMotorTorque(arg1);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getMaxMotorTorque(lua_State * L)
|
||||
{
|
||||
WheelJoint * t = luax_checkwheeljoint(L, 1);
|
||||
lua_pushnumber(L, t->getMaxMotorTorque());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_WheelJoint_getMotorTorque(lua_State * L)
|
||||
{
|
||||
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_WheelJoint_setSpringFrequencyHz(lua_State * 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_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 },
|
||||
{ "getReactionForce", w_Joint_getReactionForce },
|
||||
{ "getReactionTorque", w_Joint_getReactionTorque },
|
||||
{ "getCollideConnected", w_Joint_getCollideConnected },
|
||||
{ "destroy", w_Joint_destroy },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_wheeljoint(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "WheelJoint", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,55 +1,55 @@
|
||||
/**
|
||||
* 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_WHEEL_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "WheelJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
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_WHEEL_JOINT_H
|
||||
/**
|
||||
* 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_WHEEL_JOINT_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_WHEEL_JOINT_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "wrap_Joint.h"
|
||||
#include "WheelJoint.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
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_WHEEL_JOINT_H
|
||||
|
||||
@@ -1,194 +1,194 @@
|
||||
/**
|
||||
* 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_World.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
World * luax_checkworld(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<World>(L, idx, "World", PHYSICS_WORLD_T);
|
||||
}
|
||||
|
||||
int w_World_update(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
float dt = (float)luaL_checknumber(L, 2);
|
||||
t->update(dt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_setCallbacks(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setCallbacks(L);
|
||||
}
|
||||
|
||||
int w_World_getCallbacks(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getCallbacks(L);
|
||||
}
|
||||
|
||||
int w_World_setContactFilter(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setContactFilter(L);
|
||||
}
|
||||
|
||||
int w_World_getContactFilter(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getContactFilter(L);
|
||||
}
|
||||
|
||||
int w_World_setGravity(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setGravity(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_getGravity(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getGravity(L);
|
||||
}
|
||||
|
||||
int w_World_setAllowSleeping(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
bool b = luax_toboolean(L, 2);
|
||||
t->setAllowSleeping(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_getAllowSleeping(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
luax_pushboolean(L, t->getAllowSleeping());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_isLocked(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
luax_pushboolean(L, t->isLocked());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getBodyCount(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_pushinteger(L, t->getBodyCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getJointCount(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_pushinteger(L, t->getJointCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getContactCount(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_pushinteger(L, t->getContactCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getBodyList(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getBodyList(L);
|
||||
}
|
||||
|
||||
int w_World_getJointList(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getJointList(L);
|
||||
}
|
||||
|
||||
int w_World_getContactList(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getContactList(L);
|
||||
}
|
||||
|
||||
int w_World_queryBoundingBox(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->queryBoundingBox(L);
|
||||
}
|
||||
|
||||
int w_World_rayCast(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->rayCast(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "update", w_World_update },
|
||||
{ "setCallbacks", w_World_setCallbacks },
|
||||
{ "getCallbacks", w_World_getCallbacks },
|
||||
{ "setContactFilter", w_World_setContactFilter },
|
||||
{ "getContactFilter", w_World_getContactFilter },
|
||||
{ "setGravity", w_World_setGravity },
|
||||
{ "getGravity", w_World_getGravity },
|
||||
{ "setAllowSleeping", w_World_setAllowSleeping },
|
||||
{ "getAllowSleeping", w_World_getAllowSleeping },
|
||||
{ "isLocked", w_World_isLocked },
|
||||
{ "getBodyCount", w_World_getBodyCount },
|
||||
{ "getJointCount", w_World_getJointCount },
|
||||
{ "getContactCount", w_World_getContactCount },
|
||||
{ "getBodyList", w_World_getBodyList },
|
||||
{ "getJointList", w_World_getJointList },
|
||||
{ "getContactList", w_World_getContactList },
|
||||
{ "queryBoundingBox", w_World_queryBoundingBox },
|
||||
{ "rayCast", w_World_rayCast },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_world(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "World", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
/**
|
||||
* 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_World.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
|
||||
World * luax_checkworld(lua_State * L, int idx)
|
||||
{
|
||||
return luax_checktype<World>(L, idx, "World", PHYSICS_WORLD_T);
|
||||
}
|
||||
|
||||
int w_World_update(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
float dt = (float)luaL_checknumber(L, 2);
|
||||
t->update(dt);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_setCallbacks(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setCallbacks(L);
|
||||
}
|
||||
|
||||
int w_World_getCallbacks(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getCallbacks(L);
|
||||
}
|
||||
|
||||
int w_World_setContactFilter(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->setContactFilter(L);
|
||||
}
|
||||
|
||||
int w_World_getContactFilter(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getContactFilter(L);
|
||||
}
|
||||
|
||||
int w_World_setGravity(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
float arg1 = (float)luaL_checknumber(L, 2);
|
||||
float arg2 = (float)luaL_checknumber(L, 3);
|
||||
t->setGravity(arg1, arg2);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_getGravity(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getGravity(L);
|
||||
}
|
||||
|
||||
int w_World_setAllowSleeping(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
bool b = luax_toboolean(L, 2);
|
||||
t->setAllowSleeping(b);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int w_World_getAllowSleeping(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
luax_pushboolean(L, t->getAllowSleeping());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_isLocked(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
luax_pushboolean(L, t->isLocked());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getBodyCount(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_pushinteger(L, t->getBodyCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getJointCount(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_pushinteger(L, t->getJointCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getContactCount(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_pushinteger(L, t->getContactCount());
|
||||
return 1;
|
||||
}
|
||||
|
||||
int w_World_getBodyList(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getBodyList(L);
|
||||
}
|
||||
|
||||
int w_World_getJointList(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getJointList(L);
|
||||
}
|
||||
|
||||
int w_World_getContactList(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->getContactList(L);
|
||||
}
|
||||
|
||||
int w_World_queryBoundingBox(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->queryBoundingBox(L);
|
||||
}
|
||||
|
||||
int w_World_rayCast(lua_State * L)
|
||||
{
|
||||
World * t = luax_checkworld(L, 1);
|
||||
lua_remove(L, 1);
|
||||
return t->rayCast(L);
|
||||
}
|
||||
|
||||
static const luaL_Reg functions[] = {
|
||||
{ "update", w_World_update },
|
||||
{ "setCallbacks", w_World_setCallbacks },
|
||||
{ "getCallbacks", w_World_getCallbacks },
|
||||
{ "setContactFilter", w_World_setContactFilter },
|
||||
{ "getContactFilter", w_World_getContactFilter },
|
||||
{ "setGravity", w_World_setGravity },
|
||||
{ "getGravity", w_World_getGravity },
|
||||
{ "setAllowSleeping", w_World_setAllowSleeping },
|
||||
{ "getAllowSleeping", w_World_getAllowSleeping },
|
||||
{ "isLocked", w_World_isLocked },
|
||||
{ "getBodyCount", w_World_getBodyCount },
|
||||
{ "getJointCount", w_World_getJointCount },
|
||||
{ "getContactCount", w_World_getContactCount },
|
||||
{ "getBodyList", w_World_getBodyList },
|
||||
{ "getJointList", w_World_getJointList },
|
||||
{ "getContactList", w_World_getContactList },
|
||||
{ "queryBoundingBox", w_World_queryBoundingBox },
|
||||
{ "rayCast", w_World_rayCast },
|
||||
{ 0, 0 }
|
||||
};
|
||||
|
||||
int luaopen_world(lua_State * L)
|
||||
{
|
||||
return luax_register_type(L, "World", functions);
|
||||
}
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
@@ -1,59 +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.
|
||||
**/
|
||||
|
||||
#ifndef LOVE_PHYSICS_BOX2D_WRAP_WORLD_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_WORLD_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "World.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
World * luax_checkworld(lua_State * L, int idx);
|
||||
int w_World_update(lua_State * L);
|
||||
int w_World_setCallbacks(lua_State * L);
|
||||
int w_World_getCallbacks(lua_State * L);
|
||||
int w_World_setContactFilter(lua_State * L);
|
||||
int w_World_getContactFilter(lua_State * L);
|
||||
int w_World_setGravity(lua_State * L);
|
||||
int w_World_getGravity(lua_State * L);
|
||||
int w_World_setAllowSleeping(lua_State * L);
|
||||
int w_World_getAllowSleeping(lua_State * L);
|
||||
int w_World_isLocked(lua_State * L);
|
||||
int w_World_getBodyCount(lua_State * L);
|
||||
int w_World_getJointCount(lua_State * L);
|
||||
int w_World_getContactCount(lua_State * L);
|
||||
int w_World_getBodyList(lua_State * L);
|
||||
int w_World_getJointList(lua_State * L);
|
||||
int w_World_getContactList(lua_State * L);
|
||||
int w_World_queryBoundingBox(lua_State * L);
|
||||
int w_World_rayCast(lua_State * L);
|
||||
int luaopen_world(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_WORLD_H
|
||||
/**
|
||||
* 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_WORLD_H
|
||||
#define LOVE_PHYSICS_BOX2D_WRAP_WORLD_H
|
||||
|
||||
// LOVE
|
||||
#include <common/runtime.h>
|
||||
#include "World.h"
|
||||
|
||||
namespace love
|
||||
{
|
||||
namespace physics
|
||||
{
|
||||
namespace box2d
|
||||
{
|
||||
World * luax_checkworld(lua_State * L, int idx);
|
||||
int w_World_update(lua_State * L);
|
||||
int w_World_setCallbacks(lua_State * L);
|
||||
int w_World_getCallbacks(lua_State * L);
|
||||
int w_World_setContactFilter(lua_State * L);
|
||||
int w_World_getContactFilter(lua_State * L);
|
||||
int w_World_setGravity(lua_State * L);
|
||||
int w_World_getGravity(lua_State * L);
|
||||
int w_World_setAllowSleeping(lua_State * L);
|
||||
int w_World_getAllowSleeping(lua_State * L);
|
||||
int w_World_isLocked(lua_State * L);
|
||||
int w_World_getBodyCount(lua_State * L);
|
||||
int w_World_getJointCount(lua_State * L);
|
||||
int w_World_getContactCount(lua_State * L);
|
||||
int w_World_getBodyList(lua_State * L);
|
||||
int w_World_getJointList(lua_State * L);
|
||||
int w_World_getContactList(lua_State * L);
|
||||
int w_World_queryBoundingBox(lua_State * L);
|
||||
int w_World_rayCast(lua_State * L);
|
||||
int luaopen_world(lua_State * L);
|
||||
|
||||
} // box2d
|
||||
} // physics
|
||||
} // love
|
||||
|
||||
#endif // LOVE_PHYSICS_BOX2D_WRAP_WORLD_H
|
||||
|
||||
Reference in New Issue
Block a user