diff --git a/platform/macosx/love.xcodeproj/project.pbxproj b/platform/macosx/love.xcodeproj/project.pbxproj index befd5e9e1..501020983 100644 --- a/platform/macosx/love.xcodeproj/project.pbxproj +++ b/platform/macosx/love.xcodeproj/project.pbxproj @@ -139,6 +139,7 @@ A946D85510425002002BF36C /* wrap_Timer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6B9110420ACC007D418B /* wrap_Timer.cpp */; }; A946D85610425002002BF36C /* Timer.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A93E6B8F10420ACC007D418B /* Timer.cpp */; }; A95684F7125D3555001B276B /* b64.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A95684F5125D3555001B276B /* b64.cpp */; }; + A958F911142D364C007F320F /* wrap_Fixture.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A958F910142D3627007F320F /* wrap_Fixture.cpp */; }; A968F0CF1083A9A900A895AA /* Event.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A968F0CE1083A9A900A895AA /* Event.cpp */; }; A968F0D11083A9B900A895AA /* File.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A968F0D01083A9B900A895AA /* File.cpp */; }; A968F0D31083A9D400A895AA /* Graphics.cpp in Sources */ = {isa = PBXBuildFile; fileRef = A968F0D21083A9D400A895AA /* Graphics.cpp */; }; @@ -535,6 +536,8 @@ A946D4421176AC42005E1462 /* Font.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = Font.h; sourceTree = ""; }; A95684F5125D3555001B276B /* b64.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = b64.cpp; sourceTree = ""; }; A95684F6125D3555001B276B /* b64.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = b64.h; sourceTree = ""; }; + A958F910142D3627007F320F /* wrap_Fixture.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = wrap_Fixture.cpp; sourceTree = ""; }; + A958F912142D3687007F320F /* wrap_Fixture.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = wrap_Fixture.h; sourceTree = ""; }; A968F0C61083A07B00A895AA /* EnumMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = EnumMap.h; sourceTree = ""; }; A968F0C71083A07C00A895AA /* StringMap.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StringMap.h; sourceTree = ""; }; A968F0CE1083A9A900A895AA /* Event.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = Event.cpp; sourceTree = ""; }; @@ -1260,6 +1263,8 @@ A93E6B5710420ACA007D418B /* wrap_DistanceJoint.h */, A96F41A51412C92B0067FE9A /* wrap_EdgeShape.cpp */, A96F41A61412C92B0067FE9A /* wrap_EdgeShape.h */, + A958F910142D3627007F320F /* wrap_Fixture.cpp */, + A958F912142D3687007F320F /* wrap_Fixture.h */, A9B6432D13BF87E400DC3C7E /* wrap_FrictionJoint.cpp */, A9B6432E13BF87EA00DC3C7E /* wrap_FrictionJoint.h */, A93E6B5810420ACA007D418B /* wrap_GearJoint.cpp */, @@ -1822,6 +1827,7 @@ A9D1D2041422578C00A8BC2F /* wrap_RopeJoint.cpp in Sources */, A9D1D20A1422959100A8BC2F /* ChainShape.cpp in Sources */, A9D1D20D14229B6500A8BC2F /* wrap_ChainShape.cpp in Sources */, + A958F911142D364C007F320F /* wrap_Fixture.cpp in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/src/common/types.h b/src/common/types.h index 567d93744..876aac852 100644 --- a/src/common/types.h +++ b/src/common/types.h @@ -69,6 +69,7 @@ namespace love PHYSICS_WORLD_ID, PHYSICS_CONTACT_ID, PHYSICS_BODY_ID, + PHYSICS_FIXTURE_ID, PHYSICS_SHAPE_ID, PHYSICS_CIRCLE_SHAPE_ID, PHYSICS_POLYGON_SHAPE_ID, @@ -140,6 +141,7 @@ namespace love const bits PHYSICS_WORLD_T = (bits(1) << PHYSICS_WORLD_ID) | OBJECT_T; const bits PHYSICS_CONTACT_T = (bits(1) << PHYSICS_CONTACT_ID) | OBJECT_T; const bits PHYSICS_BODY_T = (bits(1) << PHYSICS_BODY_ID) | OBJECT_T; + const bits PHYSICS_FIXTURE_T = (bits(1) << PHYSICS_FIXTURE_ID) | OBJECT_T; const bits PHYSICS_SHAPE_T = (bits(1) << PHYSICS_SHAPE_ID) | OBJECT_T; const bits PHYSICS_CIRCLE_SHAPE_T = (bits(1) << PHYSICS_CIRCLE_SHAPE_ID) | PHYSICS_SHAPE_T; const bits PHYSICS_POLYGON_SHAPE_T = (bits(1) << PHYSICS_POLYGON_SHAPE_ID) | PHYSICS_SHAPE_T; diff --git a/src/modules/physics/box2d/Fixture.cpp b/src/modules/physics/box2d/Fixture.cpp index fca250b11..47d2461a3 100644 --- a/src/modules/physics/box2d/Fixture.cpp +++ b/src/modules/physics/box2d/Fixture.cpp @@ -1,9 +1,290 @@ -// -// Fixture.cpp -// love -// -// Created by Bill Meltsner on 3/13/11. -// Copyright 2011 Bill Meltsner. All rights reserved. -// +/** +* 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 "Fixture.h" + +// Module +#include "Body.h" +#include "World.h" +#include "Physics.h" + +// STD +#include + +namespace love +{ +namespace physics +{ +namespace box2d +{ + Fixture::Fixture(Body * body, Shape * shape) + : body(body), shape(shape), fixture(NULL) + { + body->retain(); + shape->retain(); + data = new fixtureudata(); + data->ref = 0; + b2FixtureDef def; + def.shape = shape->shape; + def.userData = (void *)data; + fixture = body->body->CreateFixture(&def); + } + + Fixture::~Fixture() + { + if(data->ref != 0) + delete data->ref; + + delete data; + data = 0; + + if (fixture) + body->body->DestroyFixture(fixture); + fixture = 0; + + body->release(); + } + + Shape::Type Fixture::getType() const + { + return shape->getType(); + } + + void Fixture::setFriction(float friction) + { + fixture->SetFriction(friction); + } + + void Fixture::setRestitution(float restitution) + { + fixture->SetRestitution(restitution); + } + + void Fixture::setDensity(float density) + { + fixture->SetDensity(density); + } + + void Fixture::setSensor(bool sensor) + { + fixture->SetSensor(sensor); + } + + float Fixture::getFriction() const + { + return fixture->GetFriction(); + } + + float Fixture::getRestitution() const + { + return fixture->GetRestitution(); + } + + float Fixture::getDensity() const + { + return fixture->GetDensity(); + } + + bool Fixture::isSensor() const + { + return fixture->IsSensor(); + } + + Body * Fixture::getBody() const + { + return body; + } + + Shape * Fixture::getShape() const + { + return shape; + } + + void Fixture::setFilterData(int * v) + { + b2Filter f; + f.categoryBits = (unsigned short)v[0]; + f.maskBits = (unsigned short)v[1]; + f.groupIndex = v[2]; + fixture->SetFilterData(f); + } + + void Fixture::getFilterData(int * v) + { + b2Filter f = fixture->GetFilterData(); + v[0] = (int)f.categoryBits; + v[1] = (int)f.maskBits; + v[2] = f.groupIndex; + } + + int Fixture::setCategory(lua_State * L) + { + b2Filter f = fixture->GetFilterData(); + f.categoryBits = (uint16)getBits(L); + fixture->SetFilterData(f); + return 0; + } + + int Fixture::setMask(lua_State * L) + { + b2Filter f = fixture->GetFilterData(); + f.maskBits = ~(uint16)getBits(L); + fixture->SetFilterData(f); + return 0; + } + + void Fixture::setGroupIndex(int index) + { + b2Filter f = fixture->GetFilterData(); + f.groupIndex = (uint16)index; + fixture->SetFilterData(f); + } + + int Fixture::getGroupIndex() const + { + b2Filter f = fixture->GetFilterData(); + return f.groupIndex; + } + + int Fixture::getCategory(lua_State * L) + { + return pushBits(L, fixture->GetFilterData().categoryBits); + } + + int Fixture::getMask(lua_State * L) + { + return pushBits(L, ~(fixture->GetFilterData().maskBits)); + } + + uint16 Fixture::getBits(lua_State * L) + { + // Get number of args. + int argc = lua_gettop(L); + + // The new bitset. + std::bitset<16> b; + + for(int i = 1;i<=argc;i++) + { + size_t bpos = (size_t)(lua_tointeger(L, i)-1); + if(bpos > 16) + return luaL_error(L, "Values must be in range 1-16."); + b.set(bpos, true); + } + + return (uint16)b.to_ulong(); + } + + int Fixture::pushBits(lua_State * L, uint16 bits) + { + // Create a bitset. + std::bitset<16> b((int)bits); + + // Push all set bits. + for(int i = 0;i<16;i++) + if(b.test(i)) + lua_pushinteger(L, i+1); + + // Count number of set bits. + return (int)b.count(); + } + + int Fixture::setUserData(lua_State * L) + { + love::luax_assert_argc(L, 1, 1); + + if(data->ref != 0) + { + delete data->ref; + data->ref = 0; + } + + data->ref = new Reference(L); + return 0; + } + + int Fixture::getUserData(lua_State * L) + { + love::luax_assert_argc(L, 0, 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)); + 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; + fixture->RayCast(&output, input, 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 Fixture::getBoundingBox(lua_State * L) const + { + int childIndex = (int)luaL_optint(L, 1, 0); + b2AABB box = fixture->GetAABB(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 Fixture::getMassData(lua_State * L) const + { + b2MassData data; + fixture->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; + } + + +} // box2d +} // physics +} // love diff --git a/src/modules/physics/box2d/Fixture.h b/src/modules/physics/box2d/Fixture.h index 76760b5d7..c06d9d8ca 100644 --- a/src/modules/physics/box2d/Fixture.h +++ b/src/modules/physics/box2d/Fixture.h @@ -59,6 +59,8 @@ namespace box2d { protected: + Body * body; + Shape * shape; b2Fixture * fixture; fixtureudata * data; @@ -76,6 +78,64 @@ namespace box2d * debug drawing. **/ Shape::Type getType() const; + + /** + * Gets the Shape attached to this Fixture. + **/ + Shape * getShape() const; + + /** + * Checks whether this Fixture acts as a sensor. + * @return True if sensor, false otherwise. + **/ + bool isSensor() const; + + /** + * Set whether this Fixture should be a sensor or not. + * @param sensor True if sensor, false if not. + **/ + void setSensor(bool sensor); + + /** + * Gets the Body this Fixture is attached to. + **/ + Body * getBody() const; + + /** + * Gets the next Fixture attached to the parent Body. + **/ + Fixture * getNext() 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. + * + * The data set here will be passed to the collision + * handler when collisions occur. + **/ + int setUserData(lua_State * L); + + /** + * Gets the data set with setData. If no + * data is set, nil is returned. + **/ + int getUserData(lua_State * L); /** * Sets the friction of the Fixture. @@ -95,12 +155,6 @@ namespace box2d **/ void setDensity(float density); - /** - * Set whether this Fixture should be a sensor or not. - * @param sensor True if sensor, false if not. - **/ - void setSensor(bool sensor); - /** * Gets the friction of the Fixture. * @returns The friction. @@ -118,45 +172,19 @@ namespace box2d * @return The density. **/ float getDensity() const; - - /** - * Checks whether this Fixture acts as a sensor. - * @return True if sensor, false otherwise. - **/ - bool isSensor() const; - - /** - * Get the body attatched to this Fixture. - * @return The parent Body. - **/ - Body * getBody() const; - + /** * Checks if a point is inside the Fixture. - * @param x The x-component of the Fixture. - * @param y The y-component of 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; - + /** - * Tests whether a line segment intersects a Fixture. + * Cast a ray against this Fixture. **/ - int testSegment(lua_State * L); - - /** - * 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); - + int rayCast(lua_State * L) const; + void setGroupIndex(int index); int getGroupIndex() const; @@ -167,27 +195,18 @@ namespace box2d uint16 getBits(lua_State * L); int pushBits(lua_State * L, uint16 bits); - /** - * This function stores an in-C reference to - * arbitrary Lua data in the Box2D Fixture object. - * - * The data set here will be passed to the collision - * handler when collisions occur. - **/ - int setData(lua_State * L); - - /** - * Gets the data set with setData. If no - * data is set, nil is returned. - **/ - int getData(lua_State * L); - /** * Gets the bounding box for this Fixture. * The function returns eight values which can be * passed directly to love.graphics.polygon. **/ - int getBoundingBox(lua_State * L); + int getBoundingBox(lua_State * L) const; + + /** + * Gets the mass data for this Fixture. + * This operation may be expensive. + **/ + int getMassData(lua_State * L) const; }; } // box2d diff --git a/src/modules/physics/box2d/Physics.cpp b/src/modules/physics/box2d/Physics.cpp index 5c7c59361..3aee9e050 100644 --- a/src/modules/physics/box2d/Physics.cpp +++ b/src/modules/physics/box2d/Physics.cpp @@ -59,6 +59,11 @@ namespace box2d { return new Body(world, b2Vec2(0, 0), 1, 1); } + + Fixture * Physics::newFixture(Body * body, Shape * shape) + { + return new Fixture(body, shape); + } CircleShape * Physics::newCircleShape(float radius) { diff --git a/src/modules/physics/box2d/Physics.h b/src/modules/physics/box2d/Physics.h index 2cca64dec..342eae8de 100644 --- a/src/modules/physics/box2d/Physics.h +++ b/src/modules/physics/box2d/Physics.h @@ -26,6 +26,7 @@ #include "World.h" #include "Contact.h" #include "Body.h" +#include "Fixture.h" #include "Shape.h" #include "CircleShape.h" #include "PolygonShape.h" @@ -98,6 +99,13 @@ namespace box2d * @param world The world to create the Body in. **/ Body * newBody(World * world); + + /** + * Creates a new Fixture. + * @param body The body to attach the Fixture to. + * @param shape The shape to attach to the Fixture. + **/ + Fixture * newFixture(Body * body, Shape * shape); /** * Creates a new CircleShape at (0, 0). diff --git a/src/modules/physics/box2d/Shape.h b/src/modules/physics/box2d/Shape.h index d388088c3..78334a6f7 100644 --- a/src/modules/physics/box2d/Shape.h +++ b/src/modules/physics/box2d/Shape.h @@ -44,6 +44,7 @@ namespace box2d **/ class Shape : public love::physics::Shape { + friend class Fixture; protected: diff --git a/src/modules/physics/box2d/wrap_Fixture.cpp b/src/modules/physics/box2d/wrap_Fixture.cpp new file mode 100644 index 000000000..bc758f4db --- /dev/null +++ b/src/modules/physics/box2d/wrap_Fixture.cpp @@ -0,0 +1,284 @@ +/** +* 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_Fixture.h" +#include + +namespace love +{ +namespace physics +{ +namespace box2d +{ + Fixture * luax_checkfixture(lua_State * L, int idx) + { + return luax_checktype(L, idx, "Fixture", PHYSICS_FIXTURE_T); + } + + int w_Fixture_getType(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + const char * type = ""; + Shape::getConstant(t->getType(), type); + lua_pushstring(L, type); + return 1; + } + + int w_Fixture_setFriction(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + float arg1 = (float)luaL_checknumber(L, 2); + t->setFriction(arg1); + return 0; + } + + int w_Fixture_setRestitution(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + float arg1 = (float)luaL_checknumber(L, 2); + t->setRestitution(arg1); + return 0; + } + + int w_Fixture_setDensity(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + float arg1 = (float)luaL_checknumber(L, 2); + t->setDensity(arg1); + return 0; + } + + int w_Fixture_setSensor(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + bool arg1 = luax_toboolean(L, 2); + t->setSensor(arg1); + return 0; + } + + int w_Fixture_getFriction(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + lua_pushnumber(L, t->getFriction()); + return 1; + } + + int w_Fixture_getRestitution(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + lua_pushnumber(L, t->getRestitution()); + return 1; + } + + int w_Fixture_getDensity(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + lua_pushnumber(L, t->getDensity()); + return 1; + } + + int w_Fixture_isSensor(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + luax_pushboolean(L, t->isSensor()); + return 1; + } + + int w_Fixture_getBody(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + Body * body = t->getBody(); + 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) + return 0; + shape->retain(); + luax_newtype(L, "Shape", PHYSICS_SHAPE_T, (void*)shape); + return 1; + } + + int w_Fixture_testPoint(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + float x = (float)luaL_checknumber(L, 2); + float y = (float)luaL_checknumber(L, 3); + luax_pushboolean(L, t->testPoint(x, y)); + return 1; + } + + int w_Fixture_rayCast(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + lua_remove(L, 1); + return t->rayCast(L); + } + + int w_Fixture_setFilterData(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + int v[3]; + v[0] = luaL_checkint(L, 2); + v[1] = luaL_checkint(L, 3); + v[2] = luaL_checkint(L, 4); + t->setFilterData(v); + return 0; + } + + int w_Fixture_getFilterData(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + int v[3]; + t->getFilterData(v); + lua_pushinteger(L, v[0]); + lua_pushinteger(L, v[1]); + lua_pushinteger(L, v[2]); + return 3; + } + + int w_Fixture_setCategory(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + lua_remove(L, 1); + return t->setCategory(L); + } + + int w_Fixture_getCategory(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + lua_remove(L, 1); + return t->getCategory(L); + } + + int w_Fixture_setMask(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + lua_remove(L, 1); + return t->setMask(L); + } + + int w_Fixture_getMask(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + lua_remove(L, 1); + return t->getMask(L); + } + + int w_Fixture_setUserData(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + lua_remove(L, 1); + return t->setUserData(L); + } + + int w_Fixture_getUserData(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + lua_remove(L, 1); + return t->getUserData(L); + } + + int w_Fixture_getBoundingBox(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + lua_remove(L, 1); + return t->getBoundingBox(L); + } + + int w_Fixture_getMassData(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + lua_remove(L, 1); + return t->getMassData(L); + } + + int w_Fixture_getGroupIndex(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + int i = t->getGroupIndex(); + lua_pushinteger(L, i); + return 1; + } + + int w_Fixture_setGroupIndex(lua_State * L) + { + Fixture * t = luax_checkfixture(L, 1); + int i = luaL_checkint(L, 2); + t->setGroupIndex(i); + return 0; + } + + int w_Fixture_destroy(lua_State * L) + { + Proxy * p = (Proxy *)lua_touserdata(L, 1); + p->own = false; + + Fixture * t = (Fixture *)p->data; + t->release(); + return 0; + } + + static const luaL_Reg functions[] = { + { "getType", w_Fixture_getType }, + { "setFriction", w_Fixture_setFriction }, + { "setRestitution", w_Fixture_setRestitution }, + { "setDensity", w_Fixture_setDensity }, + { "setSensor", w_Fixture_setSensor }, + { "getFriction", w_Fixture_getFriction }, + { "getRestitution", w_Fixture_getRestitution }, + { "getDensity", w_Fixture_getDensity }, + { "getBody", w_Fixture_getBody }, + { "getShape", w_Fixture_getShape }, + { "isSensor", w_Fixture_isSensor }, + { "testPoint", w_Fixture_testPoint }, + { "rayCast", w_Fixture_rayCast }, + { "setFilterData", w_Fixture_setFilterData }, + { "getFilterData", w_Fixture_getFilterData }, + { "setCategory", w_Fixture_setCategory }, + { "getCategory", w_Fixture_getCategory }, + { "setMask", w_Fixture_setMask }, + { "getMask", w_Fixture_getMask }, + { "setUserData", w_Fixture_setUserData }, + { "getUserData", w_Fixture_getUserData }, + { "getBoundingBox", w_Fixture_getBoundingBox }, + { "getMassData", w_Fixture_getMassData }, + { "getGroupIndex", w_Fixture_getGroupIndex }, + { "setGroupIndex", w_Fixture_setGroupIndex }, + { "destroy", w_Fixture_destroy }, + { 0, 0 } + }; + + int luaopen_fixture(lua_State * L) + { + return luax_register_type(L, "Fixture", functions); + } + +} // box2d +} // physics +} // love + diff --git a/src/modules/physics/box2d/wrap_Fixture.h b/src/modules/physics/box2d/wrap_Fixture.h new file mode 100644 index 000000000..d41f6b25a --- /dev/null +++ b/src/modules/physics/box2d/wrap_Fixture.h @@ -0,0 +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_WRAP_FIXTURE_H +#define LOVE_PHYSICS_BOX2D_WRAP_FIXTURE_H + +// LOVE +#include +#include "Fixture.h" + +namespace love +{ +namespace physics +{ +namespace box2d +{ + Fixture * luax_checkfixture(lua_State * L, int idx); + int w_Fixture_getType(lua_State * L); + int w_Fixture_setFriction(lua_State * L); + int w_Fixture_setRestitution(lua_State * L); + int w_Fixture_setDensity(lua_State * L); + int w_Fixture_setSensor(lua_State * L); + int w_Fixture_getFriction(lua_State * L); + int w_Fixture_getRestitution(lua_State * L); + int w_Fixture_getDensity(lua_State * L); + int w_Fixture_isSensor(lua_State * L); + int w_Fixture_getBody(lua_State * L); + int w_Fixture_getShape(lua_State * L); + int w_Fixture_testPoint(lua_State * L); + int w_Fixture_rayCast(lua_State * L); + int w_Fixture_setFilterData(lua_State * L); + int w_Fixture_getFilterData(lua_State * L); + int w_Fixture_setCategory(lua_State * L); + int w_Fixture_getCategory(lua_State * L); + int w_Fixture_setMask(lua_State * L); + int w_Fixture_getMask(lua_State * L); + int w_Fixture_setUserData(lua_State * L); + int w_Fixture_getUserData(lua_State * L); + int w_Fixture_getBoundingBox(lua_State * L); + int w_Fixture_getMassData(lua_State * L); + int w_Fixture_getGroupIndex(lua_State * L); + int w_Fixture_setGroupIndex(lua_State * L); + int w_Fixture_destroy(lua_State * L); + int luaopen_fixture(lua_State * L); + +} // box2d +} // physics +} // love + +#endif // LOVE_PHYSICS_BOX2D_WRAP_FIXTURE_H diff --git a/src/modules/physics/box2d/wrap_Physics.cpp b/src/modules/physics/box2d/wrap_Physics.cpp index e5bab7518..928706dde 100644 --- a/src/modules/physics/box2d/wrap_Physics.cpp +++ b/src/modules/physics/box2d/wrap_Physics.cpp @@ -53,6 +53,15 @@ 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); + Shape * shape = luax_checkshape(L, 2); + Fixture * fixture = instance->newFixture(body, shape); + luax_newtype(L, "Fixture", PHYSICS_FIXTURE_T, (void*)fixture); + return 1; + } int w_newCircleShape(lua_State * L) { diff --git a/src/modules/physics/box2d/wrap_Physics.h b/src/modules/physics/box2d/wrap_Physics.h index 29d7e2e58..09cf0b4cf 100644 --- a/src/modules/physics/box2d/wrap_Physics.h +++ b/src/modules/physics/box2d/wrap_Physics.h @@ -52,6 +52,7 @@ 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);