├── .gitattributes ├── .gitignore ├── .gitmodules ├── CMakeLists.txt ├── LICENSE ├── addClass.lua ├── addJoint.lua ├── addJoints.lua ├── dependencies └── Box2D │ ├── Box2D │ ├── Box2D │ │ ├── Box2D.h │ │ ├── Box2DConfig.cmake.in │ │ ├── CMakeLists.txt │ │ ├── Collision │ │ │ ├── Shapes │ │ │ │ ├── b2ChainShape.cpp │ │ │ │ ├── b2ChainShape.h │ │ │ │ ├── b2CircleShape.cpp │ │ │ │ ├── b2CircleShape.h │ │ │ │ ├── b2EdgeShape.cpp │ │ │ │ ├── b2EdgeShape.h │ │ │ │ ├── b2PolygonShape.cpp │ │ │ │ ├── b2PolygonShape.h │ │ │ │ └── b2Shape.h │ │ │ ├── b2BroadPhase.cpp │ │ │ ├── b2BroadPhase.h │ │ │ ├── b2CollideCircle.cpp │ │ │ ├── b2CollideEdge.cpp │ │ │ ├── b2CollidePolygon.cpp │ │ │ ├── b2Collision.cpp │ │ │ ├── b2Collision.h │ │ │ ├── b2Distance.cpp │ │ │ ├── b2Distance.h │ │ │ ├── b2DynamicTree.cpp │ │ │ ├── b2DynamicTree.h │ │ │ ├── b2TimeOfImpact.cpp │ │ │ └── b2TimeOfImpact.h │ │ ├── Common │ │ │ ├── b2BlockAllocator.cpp │ │ │ ├── b2BlockAllocator.h │ │ │ ├── b2Draw.cpp │ │ │ ├── b2Draw.h │ │ │ ├── b2GrowableStack.h │ │ │ ├── b2Math.cpp │ │ │ ├── b2Math.h │ │ │ ├── b2Settings.cpp │ │ │ ├── b2Settings.h │ │ │ ├── b2StackAllocator.cpp │ │ │ ├── b2StackAllocator.h │ │ │ ├── b2Timer.cpp │ │ │ └── b2Timer.h │ │ ├── Dynamics │ │ │ ├── Contacts │ │ │ │ ├── b2ChainAndCircleContact.cpp │ │ │ │ ├── b2ChainAndCircleContact.h │ │ │ │ ├── b2ChainAndPolygonContact.cpp │ │ │ │ ├── b2ChainAndPolygonContact.h │ │ │ │ ├── b2CircleContact.cpp │ │ │ │ ├── b2CircleContact.h │ │ │ │ ├── b2Contact.cpp │ │ │ │ ├── b2Contact.h │ │ │ │ ├── b2ContactSolver.cpp │ │ │ │ ├── b2ContactSolver.h │ │ │ │ ├── b2EdgeAndCircleContact.cpp │ │ │ │ ├── b2EdgeAndCircleContact.h │ │ │ │ ├── b2EdgeAndPolygonContact.cpp │ │ │ │ ├── b2EdgeAndPolygonContact.h │ │ │ │ ├── b2PolygonAndCircleContact.cpp │ │ │ │ ├── b2PolygonAndCircleContact.h │ │ │ │ ├── b2PolygonContact.cpp │ │ │ │ └── b2PolygonContact.h │ │ │ ├── Joints │ │ │ │ ├── b2DistanceJoint.cpp │ │ │ │ ├── b2DistanceJoint.h │ │ │ │ ├── b2FrictionJoint.cpp │ │ │ │ ├── b2FrictionJoint.h │ │ │ │ ├── b2GearJoint.cpp │ │ │ │ ├── b2GearJoint.h │ │ │ │ ├── b2Joint.cpp │ │ │ │ ├── b2Joint.h │ │ │ │ ├── b2MotorJoint.cpp │ │ │ │ ├── b2MotorJoint.h │ │ │ │ ├── b2MouseJoint.cpp │ │ │ │ ├── b2MouseJoint.h │ │ │ │ ├── b2PrismaticJoint.cpp │ │ │ │ ├── b2PrismaticJoint.h │ │ │ │ ├── b2PulleyJoint.cpp │ │ │ │ ├── b2PulleyJoint.h │ │ │ │ ├── b2RevoluteJoint.cpp │ │ │ │ ├── b2RevoluteJoint.h │ │ │ │ ├── b2RopeJoint.cpp │ │ │ │ ├── b2RopeJoint.h │ │ │ │ ├── b2WeldJoint.cpp │ │ │ │ ├── b2WeldJoint.h │ │ │ │ ├── b2WheelJoint.cpp │ │ │ │ └── b2WheelJoint.h │ │ │ ├── b2Body.cpp │ │ │ ├── b2Body.h │ │ │ ├── b2ContactManager.cpp │ │ │ ├── b2ContactManager.h │ │ │ ├── b2Fixture.cpp │ │ │ ├── b2Fixture.h │ │ │ ├── b2Island.cpp │ │ │ ├── b2Island.h │ │ │ ├── b2TimeStep.h │ │ │ ├── b2World.cpp │ │ │ ├── b2World.h │ │ │ ├── b2WorldCallbacks.cpp │ │ │ └── b2WorldCallbacks.h │ │ ├── Rope │ │ │ ├── b2Rope.cpp │ │ │ └── b2Rope.h │ │ └── UseBox2D.cmake │ ├── Building.txt │ ├── CMakeLists.txt │ ├── Changes.txt │ ├── Documentation │ │ ├── Doxyfile │ │ ├── images │ │ │ ├── Chain1.png │ │ │ ├── Chain1.svg │ │ │ ├── DebugDraw.png │ │ │ ├── GhostCollision.png │ │ │ ├── GhostCollision.svg │ │ │ ├── GhostVertices.png │ │ │ ├── GhostVertices.svg │ │ │ ├── SelfIntersect.png │ │ │ ├── SelfIntersect.svg │ │ │ ├── SkinCollision.png │ │ │ ├── SkinCollision.svg │ │ │ ├── SkinnedPolygon.png │ │ │ ├── SkinnedPolygon.svg │ │ │ ├── Tunnel1.png │ │ │ ├── Tunnel1.svg │ │ │ ├── WheelJoint.png │ │ │ ├── WheelJoint.svg │ │ │ ├── bodyOrigin.gif │ │ │ ├── captured.png │ │ │ ├── captured.svg │ │ │ ├── convex_concave.gif │ │ │ ├── distance.png │ │ │ ├── distance.svg │ │ │ ├── distanceJoint.gif │ │ │ ├── gearJoint.gif │ │ │ ├── manifolds.png │ │ │ ├── manifolds.svg │ │ │ ├── missed.png │ │ │ ├── missed.svg │ │ │ ├── modules.png │ │ │ ├── modules.svg │ │ │ ├── prismaticJoint.gif │ │ │ ├── pulleyJoint.gif │ │ │ ├── raycast.png │ │ │ ├── raycast.svg │ │ │ ├── regionquery.png │ │ │ ├── regionquery.svg │ │ │ ├── revoluteJoint.gif │ │ │ ├── testbed.gif │ │ │ ├── tunneling.png │ │ │ ├── tunneling.svg │ │ │ ├── winding.png │ │ │ └── winding.svg │ │ └── manual.docx │ ├── HelloWorld │ │ ├── CMakeLists.txt │ │ └── HelloWorld.cpp │ ├── License.txt │ ├── Readme.txt │ ├── Testbed │ │ ├── CMakeLists.txt │ │ ├── Framework │ │ │ ├── DebugDraw.cpp │ │ │ ├── DebugDraw.h │ │ │ ├── Main.cpp │ │ │ ├── RenderGL3.cpp │ │ │ ├── RenderGL3.h │ │ │ ├── Test.cpp │ │ │ ├── Test.h │ │ │ ├── imgui.cpp │ │ │ ├── imgui.h │ │ │ └── stb_truetype.h │ │ └── Tests │ │ │ ├── AddPair.h │ │ │ ├── ApplyForce.h │ │ │ ├── BasicSliderCrank.h │ │ │ ├── BodyTypes.h │ │ │ ├── Breakable.h │ │ │ ├── Bridge.h │ │ │ ├── BulletTest.h │ │ │ ├── Cantilever.h │ │ │ ├── Car.h │ │ │ ├── Chain.h │ │ │ ├── CharacterCollision.h │ │ │ ├── CollisionFiltering.h │ │ │ ├── CollisionProcessing.h │ │ │ ├── CompoundShapes.h │ │ │ ├── Confined.h │ │ │ ├── ContinuousTest.h │ │ │ ├── ConvexHull.h │ │ │ ├── ConveyorBelt.h │ │ │ ├── DistanceTest.h │ │ │ ├── Dominos.h │ │ │ ├── DumpShell.h │ │ │ ├── DynamicTreeTest.h │ │ │ ├── EdgeShapes.h │ │ │ ├── EdgeTest.h │ │ │ ├── Gears.h │ │ │ ├── HeavyOnLight.h │ │ │ ├── HeavyOnLightTwo.h │ │ │ ├── Mobile.h │ │ │ ├── MobileBalanced.h │ │ │ ├── MotorJoint.h │ │ │ ├── OneSidedPlatform.h │ │ │ ├── Pinball.h │ │ │ ├── PolyCollision.h │ │ │ ├── PolyShapes.h │ │ │ ├── Prismatic.h │ │ │ ├── Pulleys.h │ │ │ ├── Pyramid.h │ │ │ ├── RayCast.h │ │ │ ├── Revolute.h │ │ │ ├── Rope.h │ │ │ ├── RopeJoint.h │ │ │ ├── SensorTest.h │ │ │ ├── ShapeEditing.h │ │ │ ├── SliderCrank.h │ │ │ ├── SphereStack.h │ │ │ ├── TestEntries.cpp │ │ │ ├── TheoJansen.h │ │ │ ├── Tiles.h │ │ │ ├── TimeOfImpact.h │ │ │ ├── Tumbler.h │ │ │ ├── VaryingFriction.h │ │ │ ├── VaryingRestitution.h │ │ │ ├── VerticalStack.h │ │ │ └── Web.h │ ├── glew │ │ ├── glew.c │ │ ├── glew.h │ │ ├── glxew.h │ │ └── wglew.h │ ├── glfw │ │ ├── clipboard.c │ │ ├── cocoa_clipboard.m │ │ ├── cocoa_gamma.c │ │ ├── cocoa_init.m │ │ ├── cocoa_joystick.m │ │ ├── cocoa_monitor.m │ │ ├── cocoa_platform.h │ │ ├── cocoa_time.c │ │ ├── cocoa_window.m │ │ ├── config.h │ │ ├── context.c │ │ ├── egl_context.c │ │ ├── egl_platform.h │ │ ├── gamma.c │ │ ├── glext.h │ │ ├── glfw3.h │ │ ├── glfw3native.h │ │ ├── glx_context.c │ │ ├── glx_platform.h │ │ ├── glxext.h │ │ ├── init.c │ │ ├── input.c │ │ ├── internal.h │ │ ├── joystick.c │ │ ├── monitor.c │ │ ├── nsgl_context.m │ │ ├── nsgl_platform.h │ │ ├── time.c │ │ ├── wgl_context.c │ │ ├── wgl_platform.h │ │ ├── wglext.h │ │ ├── win32_clipboard.c │ │ ├── win32_gamma.c │ │ ├── win32_init.c │ │ ├── win32_joystick.c │ │ ├── win32_monitor.c │ │ ├── win32_platform.h │ │ ├── win32_time.c │ │ ├── win32_window.c │ │ ├── window.c │ │ ├── x11_clipboard.c │ │ ├── x11_gamma.c │ │ ├── x11_init.c │ │ ├── x11_joystick.c │ │ ├── x11_monitor.c │ │ ├── x11_platform.h │ │ ├── x11_time.c │ │ ├── x11_unicode.c │ │ └── x11_window.c │ └── premake4.lua │ └── Contributions │ ├── Enhancements │ ├── Controllers │ │ ├── b2BuoyancyController.cpp │ │ ├── b2BuoyancyController.h │ │ ├── b2ConstantAccelController.cpp │ │ ├── b2ConstantAccelController.h │ │ ├── b2ConstantForceController.cpp │ │ ├── b2ConstantForceController.h │ │ ├── b2Controller.cpp │ │ ├── b2Controller.h │ │ ├── b2GravityController.cpp │ │ ├── b2GravityController.h │ │ ├── b2TensorDampingController.cpp │ │ └── b2TensorDampingController.h │ ├── FixedPoint │ │ ├── Fixed.h │ │ └── jtypes.h │ └── Shapes │ │ └── capsule88.patch │ ├── Platforms │ ├── Box2D.Net │ │ ├── AABB.cpp │ │ ├── AssemblyInfo.cpp │ │ ├── Body.cpp │ │ ├── BodyDef.cpp │ │ ├── Box2D.Net.vcproj │ │ ├── Contact.cpp │ │ ├── Delegates.cpp │ │ ├── Joint.cpp │ │ ├── JointDef.cpp │ │ ├── Manifold.cpp │ │ ├── ManifoldPoint.cpp │ │ ├── MassData.cpp │ │ ├── Matrix.cpp │ │ ├── RevoluteJoint.cpp │ │ ├── Shape.cpp │ │ ├── Shape.h │ │ ├── ShapeDef.cpp │ │ ├── ShapeType.cpp │ │ ├── Stdafx.h │ │ ├── VariousImplementations.cpp │ │ ├── Vector.cpp │ │ ├── World.cpp │ │ └── XForm.cpp │ ├── Box2D.XNA.zip │ ├── TestBed.Net │ │ ├── MainWindow.Designer.cs │ │ ├── MainWindow.cs │ │ ├── MainWindow.resx │ │ ├── Program.cs │ │ ├── Properties │ │ │ └── AssemblyInfo.cs │ │ ├── Renderer.cs │ │ ├── Settings.cs │ │ ├── Test.cs │ │ ├── TestBed.Net.csproj │ │ └── Tests │ │ │ └── Bridge.cs │ ├── Tizen.zip │ └── iPhone │ │ ├── CMakeLists.txt │ │ ├── Classes │ │ ├── Box2DAppDelegate.h │ │ ├── Box2DAppDelegate.mm │ │ ├── Box2DView.h │ │ ├── Box2DView.mm │ │ ├── Delegates.h │ │ ├── GLES-Render.h │ │ ├── GLES-Render.mm │ │ ├── TestEntriesViewController.h │ │ ├── TestEntriesViewController.mm │ │ ├── iPhoneTest.h │ │ ├── iPhoneTest.mm │ │ └── iPhoneTestEntries.mm │ │ ├── Info.plist.in │ │ ├── MainWindow.xib │ │ ├── Resources │ │ └── Icon.png │ │ └── main.m │ ├── Readme.txt │ ├── Tests │ ├── Biped.cpp │ ├── Biped.h │ ├── BipedDef.cpp │ ├── BipedDef.h │ ├── BipedTest.h │ ├── BreakableBody.h │ ├── Car.h │ ├── ContactCallbackTest.h │ ├── DynamicEdges.h │ ├── ElasticBody.h │ ├── PyramidStaticEdges.h │ └── StaticEdges.h │ └── Utilities │ └── ConvexDecomposition │ ├── b2Polygon.cpp │ ├── b2Polygon.h │ ├── b2Triangle.cpp │ └── b2Triangle.h ├── src ├── CMakeLists.txt ├── LuaBox2D.version ├── array.hpp ├── common.hpp ├── main.cpp ├── main.hpp └── objects │ ├── AABB.cpp │ ├── AABB.hpp │ ├── Body.cpp │ ├── Body.hpp │ ├── BodyDef.cpp │ ├── BodyDef.hpp │ ├── ChainShape.cpp │ ├── ChainShape.hpp │ ├── CircleShape.cpp │ ├── CircleShape.hpp │ ├── Contact.cpp │ ├── Contact.hpp │ ├── ContactEdge.cpp │ ├── ContactEdge.hpp │ ├── ContactFeature.cpp │ ├── ContactFeature.hpp │ ├── ContactFilter.cpp │ ├── ContactFilter.hpp │ ├── ContactID.cpp │ ├── ContactID.hpp │ ├── ContactImpulse.cpp │ ├── ContactImpulse.hpp │ ├── ContactListener.cpp │ ├── ContactListener.hpp │ ├── ContactManager.cpp │ ├── ContactManager.hpp │ ├── DistanceJoint.cpp │ ├── DistanceJoint.hpp │ ├── DistanceJointDef.cpp │ ├── DistanceJointDef.hpp │ ├── EdgeShape.cpp │ ├── EdgeShape.hpp │ ├── Filter.cpp │ ├── Filter.hpp │ ├── Fixture.cpp │ ├── Fixture.hpp │ ├── FixtureDef.cpp │ ├── FixtureDef.hpp │ ├── FrictionJoint.cpp │ ├── FrictionJoint.hpp │ ├── FrictionJointDef.cpp │ ├── FrictionJointDef.hpp │ ├── GearJoint.cpp │ ├── GearJoint.hpp │ ├── GearJointDef.cpp │ ├── GearJointDef.hpp │ ├── Joint.cpp │ ├── Joint.hpp │ ├── JointDef.cpp │ ├── JointDef.hpp │ ├── JointEdge.cpp │ ├── JointEdge.hpp │ ├── Manifold.cpp │ ├── Manifold.hpp │ ├── ManifoldPoint.cpp │ ├── ManifoldPoint.hpp │ ├── MassData.cpp │ ├── MassData.hpp │ ├── MotorJoint.cpp │ ├── MotorJoint.hpp │ ├── MotorJointDef.cpp │ ├── MotorJointDef.hpp │ ├── MouseJoint.cpp │ ├── MouseJoint.hpp │ ├── MouseJointDef.cpp │ ├── MouseJointDef.hpp │ ├── PolygonShape.cpp │ ├── PolygonShape.hpp │ ├── PrismaticJoint.cpp │ ├── PrismaticJoint.hpp │ ├── PrismaticJointDef.cpp │ ├── PrismaticJointDef.hpp │ ├── PulleyJoint.cpp │ ├── PulleyJoint.hpp │ ├── PulleyJointDef.cpp │ ├── PulleyJointDef.hpp │ ├── QueryCallback.cpp │ ├── QueryCallback.hpp │ ├── RayCastCallback.cpp │ ├── RayCastCallback.hpp │ ├── RayCastInput.cpp │ ├── RayCastInput.hpp │ ├── RayCastOutput.cpp │ ├── RayCastOutput.hpp │ ├── RevoluteJoint.cpp │ ├── RevoluteJoint.hpp │ ├── RevoluteJointDef.cpp │ ├── RevoluteJointDef.hpp │ ├── RopeJoint.cpp │ ├── RopeJoint.hpp │ ├── RopeJointDef.cpp │ ├── RopeJointDef.hpp │ ├── Rot.cpp │ ├── Rot.hpp │ ├── Shape.cpp │ ├── Shape.hpp │ ├── Sweep.cpp │ ├── Sweep.hpp │ ├── Timer.cpp │ ├── Timer.hpp │ ├── Transform.cpp │ ├── Transform.hpp │ ├── Vec2.cpp │ ├── Vec2.hpp │ ├── VertexArray.cpp │ ├── VertexArray.hpp │ ├── WeldJoint.cpp │ ├── WeldJoint.hpp │ ├── WeldJointDef.cpp │ ├── WeldJointDef.hpp │ ├── WheelJoint.cpp │ ├── WheelJoint.hpp │ ├── WheelJointDef.cpp │ ├── WheelJointDef.hpp │ ├── World.cpp │ ├── World.hpp │ ├── WorldManifold.cpp │ └── WorldManifold.hpp └── test ├── test.lua ├── test_Body.lua ├── test_HelloWorld.lua ├── test_Vec2.lua ├── test_VertexArray.lua └── test_World.lua /.gitattributes: -------------------------------------------------------------------------------- 1 | * text=auto 2 | 3 | *.cpp text 4 | *.hpp text 5 | *.c text 6 | *.h text 7 | *.lua text 8 | *.txt text 9 | LICENSE text 10 | 11 | *.sln text eol=crlf 12 | *.vcxproj text eol=crlf 13 | *.props text eol=crlf 14 | *.filters text eol=crlf 15 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "dependencies/lutok2"] 2 | path = dependencies/lutok2 3 | url = https://github.com/soulik/lutok2.git 4 | -------------------------------------------------------------------------------- /CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.6) 2 | project (LuaBox2D) 3 | 4 | # Include Lua 5.1 5 | 6 | include(FindLua51) 7 | include_directories(SYSTEM 8 | ${LUA_INCLUDE_DIR} 9 | ${LUA_INCLUDE_DIR}/lua5.1 10 | ) 11 | 12 | 13 | # Setup Box2D 14 | 15 | set(BOX2D_INSTALL_BY_DEFAULT OFF CACHE BOOL "Install Box2D library") 16 | set(BOX2D_BUILD_STATIC ON CACHE BOOL "Build Box2D static library") 17 | set(BOX2D_BUILD_EXAMPLES OFF CACHE BOOL "Build Box2D examples") 18 | 19 | add_subdirectory(dependencies/Box2D/Box2D) 20 | include_directories(dependencies/Box2D/Box2D) 21 | 22 | set_target_properties(Box2D 23 | PROPERTIES 24 | ARCHIVE_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" 25 | LIBRARY_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/lib" 26 | RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/bin" 27 | ) 28 | 29 | include_directories(dependencies/lutok2/include) 30 | 31 | add_subdirectory(src) 32 | 33 | set_target_properties(LuaBox2D PROPERTIES PREFIX "") 34 | -------------------------------------------------------------------------------- /addClass.lua: -------------------------------------------------------------------------------- 1 | local templates = { 2 | hpp = 3 | [[#ifndef LUABOX2D_{{CNAME}}_H 4 | #define LUABOX2D_{{CNAME}}_H 5 | 6 | namespace LuaBox2D { 7 | class {{CLASS}} : public Object<{{ORIG_CLASS}}> { 8 | public: 9 | explicit {{CLASS}}(State * state) : Object<{{ORIG_CLASS}}>(state){ 10 | } 11 | 12 | {{ORIG_CLASS}} * constructor(State & state, bool & managed); 13 | 14 | void destructor(State & state, {{ORIG_CLASS}} * object); 15 | }; 16 | 17 | void init{{CLASS}}(State * ); 18 | }; 19 | 20 | #endif 21 | ]], 22 | cpp = 23 | [[#include "common.hpp" 24 | #include "objects/{{CLASS}}.hpp" 25 | 26 | namespace LuaBox2D { 27 | void init{{CLASS}}(State * state){ 28 | state->registerInterface<{{CLASS}}>("LuaBox2D_{{CLASS}}"); 29 | } 30 | 31 | {{ORIG_CLASS}} * {{CLASS}}::constructor(State & state, bool & managed){ 32 | return nullptr; 33 | } 34 | 35 | void {{CLASS}}::destructor(State & state, {{ORIG_CLASS}} * object){ 36 | delete object; 37 | } 38 | }; 39 | ]] 40 | } 41 | 42 | local function putFile(name, className, template, path) 43 | local f = io.open(path, "w") 44 | if f then 45 | f:write((template:gsub("{{([^{}]+)}}", { 46 | CNAME = name:upper(), 47 | CLASS = name, 48 | ORIG_CLASS = className, 49 | }))) 50 | f:close() 51 | return true 52 | else 53 | return false 54 | end 55 | end 56 | 57 | local genClassFile = function(name, orig_class_name) 58 | putFile(name, orig_class_name, templates.hpp, ('src/objects/%s.hpp'):format(name)) 59 | putFile(name, orig_class_name, templates.cpp, ('src/objects/%s.cpp'):format(name)) 60 | end 61 | 62 | if #arg>1 then 63 | genClassFile(tostring(arg[1]), tostring(arg[2])) 64 | else 65 | -- print(("lua %s "):format(arg[0])) 66 | return { 67 | genclassFile = genClassFile, 68 | putFile = putFile, 69 | } 70 | end -------------------------------------------------------------------------------- /addJoints.lua: -------------------------------------------------------------------------------- 1 | local aj = require 'addJoint' 2 | local genJoint = aj.genJoint 3 | 4 | for _, name in ipairs { 5 | 'Revolute', 6 | 'Prismatic', 7 | 'Distance', 8 | 'Pulley', 9 | 'Mouse', 10 | 'Gear', 11 | 'Wheel', 12 | 'Weld', 13 | 'Friction', 14 | 'Rope', 15 | 'Motor', 16 | } do 17 | genJoint(name) 18 | end -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Box2DConfig.cmake.in: -------------------------------------------------------------------------------- 1 | # -*- cmake -*- 2 | # 3 | # Box2dConfig.cmake(.in) 4 | # 5 | 6 | # Use the following variables to compile and link against Box2d: 7 | # BOX2D_FOUND - True if Box2d was found on your system 8 | # BOX2D_USE_FILE - The file making Box2d usable 9 | # BOX2D_DEFINITIONS - Definitions needed to build with Box2d 10 | # BOX2D_INCLUDE_DIR - Box2d headers location 11 | # BOX2D_INCLUDE_DIRS - List of directories where Box2d header file are 12 | # BOX2D_LIBRARY - Library name 13 | # BOX2D_LIBRARIES - List of libraries to link against 14 | # BOX2D_LIBRARY_DIRS - List of directories containing Box2d libraries 15 | # BOX2D_ROOT_DIR - The base directory of Box2d 16 | # BOX2D_VERSION_STRING - A human-readable string containing the version 17 | 18 | set ( BOX2D_FOUND 1 ) 19 | set ( BOX2D_USE_FILE "@BOX2D_USE_FILE@" ) 20 | 21 | set ( BOX2D_DEFINITIONS "@BOX2D_DEFINITIONS@" ) 22 | set ( BOX2D_INCLUDE_DIR "@BOX2D_INCLUDE_DIR@" ) 23 | set ( Box2D_INCLUDE_DIRS "@BOX2D_INCLUDE_DIRS@" ) # deprecated 24 | set ( BOX2D_INCLUDE_DIRS "@BOX2D_INCLUDE_DIRS@" ) 25 | set ( BOX2D_LIBRARY "@BOX2D_LIBRARY@" ) 26 | set ( BOX2D_LIBRARIES "@BOX2D_LIBRARIES@" ) 27 | set ( BOX2D_LIBRARY_DIRS "@BOX2D_LIBRARY_DIRS@" ) 28 | set ( BOX2D_ROOT_DIR "@CMAKE_INSTALL_PREFIX@" ) 29 | 30 | set ( BOX2D_VERSION_STRING "@BOX2D_VERSION@" ) 31 | 32 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Collision/b2TimeOfImpact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TIME_OF_IMPACT_H 20 | #define B2_TIME_OF_IMPACT_H 21 | 22 | #include 23 | #include 24 | 25 | /// Input parameters for b2TimeOfImpact 26 | struct b2TOIInput 27 | { 28 | b2DistanceProxy proxyA; 29 | b2DistanceProxy proxyB; 30 | b2Sweep sweepA; 31 | b2Sweep sweepB; 32 | float32 tMax; // defines sweep interval [0, tMax] 33 | }; 34 | 35 | // Output parameters for b2TimeOfImpact. 36 | struct b2TOIOutput 37 | { 38 | enum State 39 | { 40 | e_unknown, 41 | e_failed, 42 | e_overlapped, 43 | e_touching, 44 | e_separated 45 | }; 46 | 47 | State state; 48 | float32 t; 49 | }; 50 | 51 | /// Compute the upper bound on time before two shapes penetrate. Time is represented as 52 | /// a fraction between [0,tMax]. This uses a swept separating axis and may miss some intermediate, 53 | /// non-tunneling collision. If you change the time interval, you should call this function 54 | /// again. 55 | /// Note: use b2Distance to compute the contact point and normal at the time of impact. 56 | void b2TimeOfImpact(b2TOIOutput* output, const b2TOIInput* input); 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Common/b2BlockAllocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_BLOCK_ALLOCATOR_H 20 | #define B2_BLOCK_ALLOCATOR_H 21 | 22 | #include 23 | 24 | const int32 b2_chunkSize = 16 * 1024; 25 | const int32 b2_maxBlockSize = 640; 26 | const int32 b2_blockSizes = 14; 27 | const int32 b2_chunkArrayIncrement = 128; 28 | 29 | struct b2Block; 30 | struct b2Chunk; 31 | 32 | /// This is a small object allocator used for allocating small 33 | /// objects that persist for more than one time step. 34 | /// See: http://www.codeproject.com/useritems/Small_Block_Allocator.asp 35 | class b2BlockAllocator 36 | { 37 | public: 38 | b2BlockAllocator(); 39 | ~b2BlockAllocator(); 40 | 41 | /// Allocate memory. This will use b2Alloc if the size is larger than b2_maxBlockSize. 42 | void* Allocate(int32 size); 43 | 44 | /// Free memory. This will use b2Free if the size is larger than b2_maxBlockSize. 45 | void Free(void* p, int32 size); 46 | 47 | void Clear(); 48 | 49 | private: 50 | 51 | b2Chunk* m_chunks; 52 | int32 m_chunkCount; 53 | int32 m_chunkSpace; 54 | 55 | b2Block* m_freeLists[b2_blockSizes]; 56 | 57 | static int32 s_blockSizes[b2_blockSizes]; 58 | static uint8 s_blockSizeLookup[b2_maxBlockSize + 1]; 59 | static bool s_blockSizeLookupInitialized; 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Common/b2Draw.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Erin Catto http://box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | 21 | b2Draw::b2Draw() 22 | { 23 | m_drawFlags = 0; 24 | } 25 | 26 | void b2Draw::SetFlags(uint32 flags) 27 | { 28 | m_drawFlags = flags; 29 | } 30 | 31 | uint32 b2Draw::GetFlags() const 32 | { 33 | return m_drawFlags; 34 | } 35 | 36 | void b2Draw::AppendFlags(uint32 flags) 37 | { 38 | m_drawFlags |= flags; 39 | } 40 | 41 | void b2Draw::ClearFlags(uint32 flags) 42 | { 43 | m_drawFlags &= ~flags; 44 | } 45 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Common/b2GrowableStack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_GROWABLE_STACK_H 20 | #define B2_GROWABLE_STACK_H 21 | #include 22 | #include 23 | 24 | /// This is a growable LIFO stack with an initial capacity of N. 25 | /// If the stack size exceeds the initial capacity, the heap is used 26 | /// to increase the size of the stack. 27 | template 28 | class b2GrowableStack 29 | { 30 | public: 31 | b2GrowableStack() 32 | { 33 | m_stack = m_array; 34 | m_count = 0; 35 | m_capacity = N; 36 | } 37 | 38 | ~b2GrowableStack() 39 | { 40 | if (m_stack != m_array) 41 | { 42 | b2Free(m_stack); 43 | m_stack = NULL; 44 | } 45 | } 46 | 47 | void Push(const T& element) 48 | { 49 | if (m_count == m_capacity) 50 | { 51 | T* old = m_stack; 52 | m_capacity *= 2; 53 | m_stack = (T*)b2Alloc(m_capacity * sizeof(T)); 54 | memcpy(m_stack, old, m_count * sizeof(T)); 55 | if (old != m_array) 56 | { 57 | b2Free(old); 58 | } 59 | } 60 | 61 | m_stack[m_count] = element; 62 | ++m_count; 63 | } 64 | 65 | T Pop() 66 | { 67 | b2Assert(m_count > 0); 68 | --m_count; 69 | return m_stack[m_count]; 70 | } 71 | 72 | int32 GetCount() 73 | { 74 | return m_count; 75 | } 76 | 77 | private: 78 | T* m_stack; 79 | T m_array[N]; 80 | int32 m_count; 81 | int32 m_capacity; 82 | }; 83 | 84 | 85 | #endif 86 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Common/b2Settings.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | 24 | b2Version b2_version = {2, 3, 2}; 25 | 26 | // Memory allocators. Modify these to use your own allocator. 27 | void* b2Alloc(int32 size) 28 | { 29 | return malloc(size); 30 | } 31 | 32 | void b2Free(void* mem) 33 | { 34 | free(mem); 35 | } 36 | 37 | // You can modify this to use your logging facility. 38 | void b2Log(const char* string, ...) 39 | { 40 | va_list args; 41 | va_start(args, string); 42 | vprintf(string, args); 43 | va_end(args); 44 | } 45 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Common/b2StackAllocator.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_STACK_ALLOCATOR_H 20 | #define B2_STACK_ALLOCATOR_H 21 | 22 | #include 23 | 24 | const int32 b2_stackSize = 100 * 1024; // 100k 25 | const int32 b2_maxStackEntries = 32; 26 | 27 | struct b2StackEntry 28 | { 29 | char* data; 30 | int32 size; 31 | bool usedMalloc; 32 | }; 33 | 34 | // This is a stack allocator used for fast per step allocations. 35 | // You must nest allocate/free pairs. The code will assert 36 | // if you try to interleave multiple allocate/free pairs. 37 | class b2StackAllocator 38 | { 39 | public: 40 | b2StackAllocator(); 41 | ~b2StackAllocator(); 42 | 43 | void* Allocate(int32 size); 44 | void Free(void* p); 45 | 46 | int32 GetMaxAllocation() const; 47 | 48 | private: 49 | 50 | char m_data[b2_stackSize]; 51 | int32 m_index; 52 | 53 | int32 m_allocation; 54 | int32 m_maxAllocation; 55 | 56 | b2StackEntry m_entries[b2_maxStackEntries]; 57 | int32 m_entryCount; 58 | }; 59 | 60 | #endif 61 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Common/b2Timer.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011 Erin Catto http://box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TIMER_H 20 | #define B2_TIMER_H 21 | 22 | #include 23 | 24 | /// Timer for profiling. This has platform specific code and may 25 | /// not work on every platform. 26 | class b2Timer 27 | { 28 | public: 29 | 30 | /// Constructor 31 | b2Timer(); 32 | 33 | /// Reset the timer. 34 | void Reset(); 35 | 36 | /// Get the time since construction or the last reset. 37 | float32 GetMilliseconds() const; 38 | 39 | private: 40 | 41 | #if defined(_WIN32) 42 | float64 m_start; 43 | static float64 s_invFrequency; 44 | #elif defined(__linux__) || defined (__APPLE__) 45 | unsigned long m_start_sec; 46 | unsigned long m_start_usec; 47 | #endif 48 | }; 49 | 50 | #endif 51 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/Contacts/b2ChainAndCircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CHAIN_AND_CIRCLE_CONTACT_H 20 | #define B2_CHAIN_AND_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2ChainAndCircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2ChainAndCircleContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB); 34 | ~b2ChainAndCircleContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/Contacts/b2ChainAndPolygonContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CHAIN_AND_POLYGON_CONTACT_H 20 | #define B2_CHAIN_AND_POLYGON_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2ChainAndPolygonContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2ChainAndPolygonContact(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB); 34 | ~b2ChainAndPolygonContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/Contacts/b2CircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | b2Contact* b2CircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 29 | { 30 | void* mem = allocator->Allocate(sizeof(b2CircleContact)); 31 | return new (mem) b2CircleContact(fixtureA, fixtureB); 32 | } 33 | 34 | void b2CircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 35 | { 36 | ((b2CircleContact*)contact)->~b2CircleContact(); 37 | allocator->Free(contact, sizeof(b2CircleContact)); 38 | } 39 | 40 | b2CircleContact::b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 41 | : b2Contact(fixtureA, 0, fixtureB, 0) 42 | { 43 | b2Assert(m_fixtureA->GetType() == b2Shape::e_circle); 44 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 45 | } 46 | 47 | void b2CircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 48 | { 49 | b2CollideCircles(manifold, 50 | (b2CircleShape*)m_fixtureA->GetShape(), xfA, 51 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 52 | } 53 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/Contacts/b2CircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CIRCLE_CONTACT_H 20 | #define B2_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2CircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2CircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2CircleContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | b2Contact* b2EdgeAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 26 | { 27 | void* mem = allocator->Allocate(sizeof(b2EdgeAndCircleContact)); 28 | return new (mem) b2EdgeAndCircleContact(fixtureA, fixtureB); 29 | } 30 | 31 | void b2EdgeAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 32 | { 33 | ((b2EdgeAndCircleContact*)contact)->~b2EdgeAndCircleContact(); 34 | allocator->Free(contact, sizeof(b2EdgeAndCircleContact)); 35 | } 36 | 37 | b2EdgeAndCircleContact::b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 38 | : b2Contact(fixtureA, 0, fixtureB, 0) 39 | { 40 | b2Assert(m_fixtureA->GetType() == b2Shape::e_edge); 41 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 42 | } 43 | 44 | void b2EdgeAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 45 | { 46 | b2CollideEdgeAndCircle( manifold, 47 | (b2EdgeShape*)m_fixtureA->GetShape(), xfA, 48 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 49 | } 50 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/Contacts/b2EdgeAndCircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_EDGE_AND_CIRCLE_CONTACT_H 20 | #define B2_EDGE_AND_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2EdgeAndCircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2EdgeAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2EdgeAndCircleContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2010 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | b2Contact* b2EdgeAndPolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 26 | { 27 | void* mem = allocator->Allocate(sizeof(b2EdgeAndPolygonContact)); 28 | return new (mem) b2EdgeAndPolygonContact(fixtureA, fixtureB); 29 | } 30 | 31 | void b2EdgeAndPolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 32 | { 33 | ((b2EdgeAndPolygonContact*)contact)->~b2EdgeAndPolygonContact(); 34 | allocator->Free(contact, sizeof(b2EdgeAndPolygonContact)); 35 | } 36 | 37 | b2EdgeAndPolygonContact::b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 38 | : b2Contact(fixtureA, 0, fixtureB, 0) 39 | { 40 | b2Assert(m_fixtureA->GetType() == b2Shape::e_edge); 41 | b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon); 42 | } 43 | 44 | void b2EdgeAndPolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 45 | { 46 | b2CollideEdgeAndPolygon( manifold, 47 | (b2EdgeShape*)m_fixtureA->GetShape(), xfA, 48 | (b2PolygonShape*)m_fixtureB->GetShape(), xfB); 49 | } 50 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/Contacts/b2EdgeAndPolygonContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_EDGE_AND_POLYGON_CONTACT_H 20 | #define B2_EDGE_AND_POLYGON_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2EdgeAndPolygonContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2EdgeAndPolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2EdgeAndPolygonContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | 23 | #include 24 | 25 | b2Contact* b2PolygonAndCircleContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 26 | { 27 | void* mem = allocator->Allocate(sizeof(b2PolygonAndCircleContact)); 28 | return new (mem) b2PolygonAndCircleContact(fixtureA, fixtureB); 29 | } 30 | 31 | void b2PolygonAndCircleContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 32 | { 33 | ((b2PolygonAndCircleContact*)contact)->~b2PolygonAndCircleContact(); 34 | allocator->Free(contact, sizeof(b2PolygonAndCircleContact)); 35 | } 36 | 37 | b2PolygonAndCircleContact::b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 38 | : b2Contact(fixtureA, 0, fixtureB, 0) 39 | { 40 | b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon); 41 | b2Assert(m_fixtureB->GetType() == b2Shape::e_circle); 42 | } 43 | 44 | void b2PolygonAndCircleContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 45 | { 46 | b2CollidePolygonAndCircle( manifold, 47 | (b2PolygonShape*)m_fixtureA->GetShape(), xfA, 48 | (b2CircleShape*)m_fixtureB->GetShape(), xfB); 49 | } 50 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/Contacts/b2PolygonAndCircleContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_POLYGON_AND_CIRCLE_CONTACT_H 20 | #define B2_POLYGON_AND_CIRCLE_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2PolygonAndCircleContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create(b2Fixture* fixtureA, int32 indexA, b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 30 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 31 | 32 | b2PolygonAndCircleContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 33 | ~b2PolygonAndCircleContact() {} 34 | 35 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/Contacts/b2PolygonContact.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | #include 22 | #include 23 | #include 24 | #include 25 | 26 | #include 27 | 28 | b2Contact* b2PolygonContact::Create(b2Fixture* fixtureA, int32, b2Fixture* fixtureB, int32, b2BlockAllocator* allocator) 29 | { 30 | void* mem = allocator->Allocate(sizeof(b2PolygonContact)); 31 | return new (mem) b2PolygonContact(fixtureA, fixtureB); 32 | } 33 | 34 | void b2PolygonContact::Destroy(b2Contact* contact, b2BlockAllocator* allocator) 35 | { 36 | ((b2PolygonContact*)contact)->~b2PolygonContact(); 37 | allocator->Free(contact, sizeof(b2PolygonContact)); 38 | } 39 | 40 | b2PolygonContact::b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB) 41 | : b2Contact(fixtureA, 0, fixtureB, 0) 42 | { 43 | b2Assert(m_fixtureA->GetType() == b2Shape::e_polygon); 44 | b2Assert(m_fixtureB->GetType() == b2Shape::e_polygon); 45 | } 46 | 47 | void b2PolygonContact::Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB) 48 | { 49 | b2CollidePolygons( manifold, 50 | (b2PolygonShape*)m_fixtureA->GetShape(), xfA, 51 | (b2PolygonShape*)m_fixtureB->GetShape(), xfB); 52 | } 53 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/Contacts/b2PolygonContact.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_POLYGON_CONTACT_H 20 | #define B2_POLYGON_CONTACT_H 21 | 22 | #include 23 | 24 | class b2BlockAllocator; 25 | 26 | class b2PolygonContact : public b2Contact 27 | { 28 | public: 29 | static b2Contact* Create( b2Fixture* fixtureA, int32 indexA, 30 | b2Fixture* fixtureB, int32 indexB, b2BlockAllocator* allocator); 31 | static void Destroy(b2Contact* contact, b2BlockAllocator* allocator); 32 | 33 | b2PolygonContact(b2Fixture* fixtureA, b2Fixture* fixtureB); 34 | ~b2PolygonContact() {} 35 | 36 | void Evaluate(b2Manifold* manifold, const b2Transform& xfA, const b2Transform& xfB); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/b2ContactManager.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CONTACT_MANAGER_H 20 | #define B2_CONTACT_MANAGER_H 21 | 22 | #include 23 | 24 | class b2Contact; 25 | class b2ContactFilter; 26 | class b2ContactListener; 27 | class b2BlockAllocator; 28 | 29 | // Delegate of b2World. 30 | class b2ContactManager 31 | { 32 | public: 33 | b2ContactManager(); 34 | 35 | // Broad-phase callback. 36 | void AddPair(void* proxyUserDataA, void* proxyUserDataB); 37 | 38 | void FindNewContacts(); 39 | 40 | void Destroy(b2Contact* c); 41 | 42 | void Collide(); 43 | 44 | b2BroadPhase m_broadPhase; 45 | b2Contact* m_contactList; 46 | int32 m_contactCount; 47 | b2ContactFilter* m_contactFilter; 48 | b2ContactListener* m_contactListener; 49 | b2BlockAllocator* m_allocator; 50 | }; 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/b2TimeStep.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2011 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TIME_STEP_H 20 | #define B2_TIME_STEP_H 21 | 22 | #include 23 | 24 | /// Profiling data. Times are in milliseconds. 25 | struct b2Profile 26 | { 27 | float32 step; 28 | float32 collide; 29 | float32 solve; 30 | float32 solveInit; 31 | float32 solveVelocity; 32 | float32 solvePosition; 33 | float32 broadphase; 34 | float32 solveTOI; 35 | }; 36 | 37 | /// This is an internal structure. 38 | struct b2TimeStep 39 | { 40 | float32 dt; // time step 41 | float32 inv_dt; // inverse time step (0 if dt == 0). 42 | float32 dtRatio; // dt * inv_dt0 43 | int32 velocityIterations; 44 | int32 positionIterations; 45 | bool warmStarting; 46 | }; 47 | 48 | /// This is an internal structure. 49 | struct b2Position 50 | { 51 | b2Vec2 c; 52 | float32 a; 53 | }; 54 | 55 | /// This is an internal structure. 56 | struct b2Velocity 57 | { 58 | b2Vec2 v; 59 | float32 w; 60 | }; 61 | 62 | /// Solver Data 63 | struct b2SolverData 64 | { 65 | b2TimeStep step; 66 | b2Position* positions; 67 | b2Velocity* velocities; 68 | }; 69 | 70 | #endif 71 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/Dynamics/b2WorldCallbacks.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include 20 | #include 21 | 22 | // Return true if contact calculations should be performed between these two shapes. 23 | // If you implement your own collision filter you may want to build from this implementation. 24 | bool b2ContactFilter::ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB) 25 | { 26 | const b2Filter& filterA = fixtureA->GetFilterData(); 27 | const b2Filter& filterB = fixtureB->GetFilterData(); 28 | 29 | if (filterA.groupIndex == filterB.groupIndex && filterA.groupIndex != 0) 30 | { 31 | return filterA.groupIndex > 0; 32 | } 33 | 34 | bool collide = (filterA.maskBits & filterB.categoryBits) != 0 && (filterA.categoryBits & filterB.maskBits) != 0; 35 | return collide; 36 | } 37 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Box2D/UseBox2D.cmake: -------------------------------------------------------------------------------- 1 | # -*- cmake -*- 2 | # 3 | # UseBox2d.cmake 4 | # 5 | 6 | add_definitions ( ${BOX2D_DEFINITIONS} ) 7 | include_directories ( ${BOX2D_INCLUDE_DIRS} ) 8 | link_directories ( ${BOX2D_LIBRARY_DIRS} ) 9 | 10 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Building.txt: -------------------------------------------------------------------------------- 1 | The Build folder contains custom made project files for Visual Studio and XCode. 2 | 3 | =============== OLD METHOD 1 UNSUPPORTED ==================== 4 | 5 | For other platforms you need to run premake in this directory. You can get premake here: 6 | http://industriousone.com/premake 7 | 8 | For example, on Linux, you would type: 9 | premake4 gmake 10 | 11 | This will create a gmake folder in the Build directory. From there you can run: 12 | make config="debug" 13 | 14 | If you have build problems, you can post a question here: 15 | http://box2d.org/forum/viewforum.php?f=7 16 | 17 | =============== OLD METHOD 1 UNSUPPORTED ==================== 18 | 19 | Box2D uses CMake to describe the build in a platform independent manner. 20 | 21 | First download and install cmake from cmake.org 22 | 23 | For Microsoft Visual Studio: 24 | - Run the cmake-gui 25 | - Set the source directory to the path of Box2D on your PC (the folder that contains this file). 26 | - Set the build directory to be the path of Box2D/Build on your PC. 27 | - Press the Configure button and select your version of Visual Studio. 28 | - You may have to press the Configure button again. 29 | - Press the Generate button. 30 | - Open Box2D/Build/Box2D.sln. 31 | - Set the Testbed or HelloWorld as your startup project. 32 | - Press F5 or Ctrl-F5 to run. 33 | 34 | For Unix platforms, say the following on a terminal: (Replace $BOX2DPATH with the directory where this file is located.) 35 | cd $BOX2DPATH/Build 36 | cmake -DBOX2D_INSTALL=ON -DBOX2D_BUILD_SHARED=ON .. 37 | make 38 | make install 39 | You might want to add -DCMAKE_INSTALL_PREFIX=/opt/Box2D or similar to the cmake call to change the installation location. make install might need sudo. 40 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | project(Box2D) 4 | 5 | if(UNIX) 6 | set(BOX2D_INSTALL_BY_DEFAULT ON) 7 | else(UNIX) 8 | set(BOX2D_INSTALL_BY_DEFAULT OFF) 9 | endif(UNIX) 10 | 11 | option(BOX2D_INSTALL "Install Box2D libs, includes, and CMake scripts" ${BOX2D_INSTALL_BY_DEFAULT}) 12 | option(BOX2D_INSTALL_DOC "Install Box2D documentation" OFF) 13 | option(BOX2D_BUILD_SHARED "Build Box2D shared libraries" OFF) 14 | option(BOX2D_BUILD_STATIC "Build Box2D static libraries" ON) 15 | option(BOX2D_BUILD_EXAMPLES "Build Box2D examples" ON) 16 | 17 | set(BOX2D_VERSION 2.3.2) 18 | set(LIB_INSTALL_DIR lib${LIB_SUFFIX}) 19 | 20 | # The Box2D library. 21 | add_subdirectory(Box2D) 22 | 23 | if(BOX2D_BUILD_EXAMPLES) 24 | # HelloWorld console example. 25 | add_subdirectory(HelloWorld) 26 | 27 | # Testbed and dependencies. 28 | find_package(OpenGL REQUIRED) 29 | add_subdirectory(glew) 30 | add_subdirectory(glfw) 31 | add_subdirectory(Testbed) 32 | endif(BOX2D_BUILD_EXAMPLES) 33 | 34 | if(BOX2D_INSTALL_DOC) 35 | install(DIRECTORY Documentation DESTINATION share/doc/Box2D PATTERN ".svn" EXCLUDE) 36 | endif(BOX2D_INSTALL_DOC) 37 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Changes.txt: -------------------------------------------------------------------------------- 1 | Version 2.3.0 2 | Polygon creation now computes the convex hull. Vertices no longer need to be ordered. 3 | The convex hull code will merge vertices closer than dm_linearSlop. This may lead to failure on very small polygons. 4 | Added b2MotorJoint. 5 | Bug fixes. -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/Chain1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/Chain1.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/DebugDraw.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/DebugDraw.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/GhostCollision.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/GhostCollision.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/GhostVertices.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/GhostVertices.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/SelfIntersect.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/SelfIntersect.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/SkinCollision.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/SkinCollision.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/SkinnedPolygon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/SkinnedPolygon.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/Tunnel1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/Tunnel1.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/WheelJoint.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/WheelJoint.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/bodyOrigin.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/bodyOrigin.gif -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/captured.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/captured.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/convex_concave.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/convex_concave.gif -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/distance.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/distance.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/distanceJoint.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/distanceJoint.gif -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/gearJoint.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/gearJoint.gif -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/manifolds.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/manifolds.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/missed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/missed.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/modules.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/modules.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/prismaticJoint.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/prismaticJoint.gif -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/pulleyJoint.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/pulleyJoint.gif -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/raycast.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/raycast.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/regionquery.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/regionquery.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/revoluteJoint.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/revoluteJoint.gif -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/testbed.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/testbed.gif -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/tunneling.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/tunneling.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/images/winding.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/images/winding.png -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Documentation/manual.docx: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Box2D/Documentation/manual.docx -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/HelloWorld/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Hello World examples 2 | include_directories (${Box2D_SOURCE_DIR}) 3 | add_executable(HelloWorld HelloWorld.cpp) 4 | target_link_libraries (HelloWorld Box2D) 5 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/License.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2006-2013 Erin Catto http://www.gphysics.com 2 | 3 | This software is provided 'as-is', without any express or implied 4 | warranty. In no event will the authors be held liable for any damages 5 | arising from the use of this software. 6 | 7 | Permission is granted to anyone to use this software for any purpose, 8 | including commercial applications, and to alter it and redistribute it 9 | freely, subject to the following restrictions: 10 | 11 | 1. The origin of this software must not be misrepresented; you must not 12 | claim that you wrote the original software. If you use this software 13 | in a product, an acknowledgment in the product documentation would be 14 | appreciated but is not required. 15 | 2. Altered source versions must be plainly marked as such, and must not be 16 | misrepresented as being the original software. 17 | 3. This notice may not be removed or altered from any source distribution. 18 | 19 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Readme.txt: -------------------------------------------------------------------------------- 1 | Welcome to Box2D! 2 | 3 | Box2D is a 2D physics engine for games. 4 | 5 | For help with Box2D, please visit http://www.box2d.org. There is a forum there where you may post your questions. 6 | 7 | Please see Building.txt to learn how to build Box2D and run the testbed. 8 | 9 | To run the demos, set "Testbed" as your startup project and press F5. Some test bed commands are: 10 | - 'r' to reset the current test 11 | - SPACE to launch a bomb 12 | - arrow keys to pan 13 | - 'x' and 'z' to zoom in/out 14 | - use the mouse to click and drag objects 15 | 16 | Erin Catto 17 | http://www.box2d.org 18 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Testbed/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | # Some flags for Freeglut and GLUI. 2 | add_definitions( -DGLEW_STATIC -D_CRT_SECURE_NO_WARNINGS ) 3 | 4 | # Define the framework files. 5 | set(Testbed_Framework_SRCS 6 | Framework/Main.cpp 7 | Framework/Render.cpp 8 | Framework/Render.h 9 | Framework/Test.cpp 10 | Framework/Test.h 11 | ) 12 | 13 | #define the test files. 14 | set(Testbed_Tests_SRCS 15 | Tests/TestEntries.cpp 16 | Tests/AddPair.h 17 | Tests/ApplyForce.h 18 | Tests/BodyTypes.h 19 | Tests/Breakable.h 20 | Tests/Bridge.h 21 | Tests/BulletTest.h 22 | Tests/Cantilever.h 23 | Tests/Car.h 24 | Tests/Chain.h 25 | Tests/CharacterCollision.h 26 | Tests/CollisionFiltering.h 27 | Tests/CollisionProcessing.h 28 | Tests/CompoundShapes.h 29 | Tests/Confined.h 30 | Tests/ContinuousTest.h 31 | Tests/DistanceTest.h 32 | Tests/Dominos.h 33 | Tests/DumpShell.h 34 | Tests/DynamicTreeTest.h 35 | Tests/EdgeShapes.h 36 | Tests/EdgeTest.h 37 | Tests/Gears.h 38 | Tests/OneSidedPlatform.h 39 | Tests/Pinball.h 40 | Tests/PolyCollision.h 41 | Tests/PolyShapes.h 42 | Tests/Prismatic.h 43 | Tests/Pulleys.h 44 | Tests/Pyramid.h 45 | Tests/RayCast.h 46 | Tests/Revolute.h 47 | Tests/Rope.h 48 | Tests/RopeJoint.h 49 | Tests/SensorTest.h 50 | Tests/ShapeEditing.h 51 | Tests/SliderCrank.h 52 | Tests/SphereStack.h 53 | Tests/TheoJansen.h 54 | Tests/Tiles.h 55 | Tests/TimeOfImpact.h 56 | Tests/VaryingFriction.h 57 | Tests/VaryingRestitution.h 58 | Tests/VerticalStack.h 59 | Tests/Web.h 60 | ) 61 | 62 | # These are used to create visual studio folders. 63 | source_group(Framework FILES ${Testbed_Framework_SRCS}) 64 | source_group(Tests FILES ${Testbed_Tests_SRCS}) 65 | 66 | include_directories ( 67 | ${OPENGL_INCLUDE_DIR} 68 | ${Box2D_SOURCE_DIR} 69 | ) 70 | 71 | if(APPLE) 72 | # We are not using the Apple's framework version, but X11's 73 | include_directories( /usr/X11/include ) 74 | link_directories( /usr/X11/lib ) 75 | set (OPENGL_LIBRARIES GL GLU X11) 76 | elseif(WIN32) 77 | set (ADDITIONAL_LIBRARIES winmm) 78 | endif(APPLE) 79 | 80 | add_executable(Testbed 81 | ${Testbed_Framework_SRCS} 82 | ${Testbed_Tests_SRCS} 83 | ) 84 | 85 | target_link_libraries ( 86 | Testbed 87 | Box2D 88 | glew 89 | glfw 90 | ${ADDITIONAL_LIBRARIES} 91 | ${OPENGL_LIBRARIES} 92 | ) 93 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Testbed/Framework/imgui.h: -------------------------------------------------------------------------------- 1 | 2 | // 3 | // Copyright (c) 2009-2010 Mikko Mononen memon@inside.org 4 | // 5 | // This software is provided 'as-is', without any express or implied 6 | // warranty. In no event will the authors be held liable for any damages 7 | // arising from the use of this software. 8 | // Permission is granted to anyone to use this software for any purpose, 9 | // including commercial applications, and to alter it and redistribute it 10 | // freely, subject to the following restrictions: 11 | // 1. The origin of this software must not be misrepresented; you must not 12 | // claim that you wrote the original software. If you use this software 13 | // in a product, an acknowledgment in the product documentation would be 14 | // appreciated but is not required. 15 | // 2. Altered source versions must be plainly marked as such, and must not be 16 | // misrepresented as being the original software. 17 | // 3. This notice may not be removed or altered from any source distribution. 18 | // 19 | 20 | // Source altered and distributed from https://github.com/AdrienHerubel/imgui 21 | 22 | #ifndef IMGUI_H 23 | #define IMGUI_H 24 | 25 | enum imguiMouseButton 26 | { 27 | IMGUI_MBUT_LEFT = 0x01, 28 | IMGUI_MBUT_RIGHT = 0x02, 29 | }; 30 | 31 | void imguiBeginFrame(int mx, int my, unsigned char mbut, int scroll); 32 | void imguiEndFrame(); 33 | 34 | bool imguiBeginScrollArea(const char* name, int x, int y, int w, int h, int* scroll); 35 | void imguiEndScrollArea(); 36 | 37 | void imguiIndent(); 38 | void imguiUnindent(); 39 | void imguiSeparator(); 40 | void imguiSeparatorLine(); 41 | 42 | bool imguiButton(const char* text, bool enabled); 43 | bool imguiItem(const char* text, bool enabled); 44 | bool imguiCheck(const char* text, bool checked, bool enabled); 45 | bool imguiCollapse(const char* text, const char* subtext, bool checked, bool enabled); 46 | void imguiLabel(const char* text); 47 | void imguiValue(const char* text); 48 | bool imguiSlider(const char* text, float* val, float vmin, float vmax, float vinc, bool enabled); 49 | bool imguiSlider(const char* text, int* val, int vmin, int vmax, int vinc, bool enabled); 50 | 51 | #endif // IMGUI_H 52 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Testbed/Tests/AddPair.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2012 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef AddPair_H 20 | #define AddPair_H 21 | 22 | class AddPair : public Test 23 | { 24 | public: 25 | 26 | AddPair() 27 | { 28 | m_world->SetGravity(b2Vec2(0.0f,0.0f)); 29 | { 30 | b2CircleShape shape; 31 | shape.m_p.SetZero(); 32 | shape.m_radius = 0.1f; 33 | 34 | float minX = -6.0f; 35 | float maxX = 0.0f; 36 | float minY = 4.0f; 37 | float maxY = 6.0f; 38 | 39 | for (int32 i = 0; i < 400; ++i) 40 | { 41 | b2BodyDef bd; 42 | bd.type = b2_dynamicBody; 43 | bd.position = b2Vec2(RandomFloat(minX,maxX),RandomFloat(minY,maxY)); 44 | b2Body* body = m_world->CreateBody(&bd); 45 | body->CreateFixture(&shape, 0.01f); 46 | } 47 | } 48 | 49 | { 50 | b2PolygonShape shape; 51 | shape.SetAsBox(1.5f, 1.5f); 52 | b2BodyDef bd; 53 | bd.type = b2_dynamicBody; 54 | bd.position.Set(-40.0f,5.0f); 55 | bd.bullet = true; 56 | b2Body* body = m_world->CreateBody(&bd); 57 | body->CreateFixture(&shape, 1.0f); 58 | body->SetLinearVelocity(b2Vec2(150.0f, 0.0f)); 59 | } 60 | } 61 | 62 | static Test* Create() 63 | { 64 | return new AddPair; 65 | } 66 | }; 67 | 68 | #endif 69 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Testbed/Tests/Chain.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef CHAIN_H 20 | #define CHAIN_H 21 | 22 | class Chain : public Test 23 | { 24 | public: 25 | Chain() 26 | { 27 | b2Body* ground = NULL; 28 | { 29 | b2BodyDef bd; 30 | ground = m_world->CreateBody(&bd); 31 | 32 | b2EdgeShape shape; 33 | shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); 34 | ground->CreateFixture(&shape, 0.0f); 35 | } 36 | 37 | { 38 | b2PolygonShape shape; 39 | shape.SetAsBox(0.6f, 0.125f); 40 | 41 | b2FixtureDef fd; 42 | fd.shape = &shape; 43 | fd.density = 20.0f; 44 | fd.friction = 0.2f; 45 | 46 | b2RevoluteJointDef jd; 47 | jd.collideConnected = false; 48 | 49 | const float32 y = 25.0f; 50 | b2Body* prevBody = ground; 51 | for (int32 i = 0; i < 30; ++i) 52 | { 53 | b2BodyDef bd; 54 | bd.type = b2_dynamicBody; 55 | bd.position.Set(0.5f + i, y); 56 | b2Body* body = m_world->CreateBody(&bd); 57 | body->CreateFixture(&fd); 58 | 59 | b2Vec2 anchor(float32(i), y); 60 | jd.Initialize(prevBody, body, anchor); 61 | m_world->CreateJoint(&jd); 62 | 63 | prevBody = body; 64 | } 65 | } 66 | } 67 | 68 | static Test* Create() 69 | { 70 | return new Chain; 71 | } 72 | }; 73 | 74 | #endif 75 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Testbed/Tests/HeavyOnLight.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2008-2014 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef HEAVY_ON_LIGHT_H 20 | #define HEAVY_ON_LIGHT_H 21 | 22 | class HeavyOnLight : public Test 23 | { 24 | public: 25 | 26 | HeavyOnLight() 27 | { 28 | { 29 | b2BodyDef bd; 30 | b2Body* ground = m_world->CreateBody(&bd); 31 | 32 | b2EdgeShape shape; 33 | shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); 34 | ground->CreateFixture(&shape, 0.0f); 35 | } 36 | 37 | b2BodyDef bd; 38 | bd.type = b2_dynamicBody; 39 | bd.position.Set(0.0f, 0.5f); 40 | b2Body* body = m_world->CreateBody(&bd); 41 | 42 | b2CircleShape shape; 43 | shape.m_radius = 0.5f; 44 | body->CreateFixture(&shape, 10.0f); 45 | 46 | bd.position.Set(0.0f, 6.0f); 47 | body = m_world->CreateBody(&bd); 48 | shape.m_radius = 5.0f; 49 | body->CreateFixture(&shape, 10.0f); 50 | } 51 | 52 | static Test* Create() 53 | { 54 | return new HeavyOnLight; 55 | } 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Testbed/Tests/Pyramid.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef PYRAMID_H 20 | #define PYRAMID_H 21 | 22 | class Pyramid : public Test 23 | { 24 | public: 25 | enum 26 | { 27 | e_count = 20 28 | }; 29 | 30 | Pyramid() 31 | { 32 | { 33 | b2BodyDef bd; 34 | b2Body* ground = m_world->CreateBody(&bd); 35 | 36 | b2EdgeShape shape; 37 | shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); 38 | ground->CreateFixture(&shape, 0.0f); 39 | } 40 | 41 | { 42 | float32 a = 0.5f; 43 | b2PolygonShape shape; 44 | shape.SetAsBox(a, a); 45 | 46 | b2Vec2 x(-7.0f, 0.75f); 47 | b2Vec2 y; 48 | b2Vec2 deltaX(0.5625f, 1.25f); 49 | b2Vec2 deltaY(1.125f, 0.0f); 50 | 51 | for (int32 i = 0; i < e_count; ++i) 52 | { 53 | y = x; 54 | 55 | for (int32 j = i; j < e_count; ++j) 56 | { 57 | b2BodyDef bd; 58 | bd.type = b2_dynamicBody; 59 | bd.position = y; 60 | b2Body* body = m_world->CreateBody(&bd); 61 | body->CreateFixture(&shape, 5.0f); 62 | 63 | y += deltaY; 64 | } 65 | 66 | x += deltaX; 67 | } 68 | } 69 | } 70 | 71 | void Step(Settings* settings) 72 | { 73 | Test::Step(settings); 74 | 75 | //b2DynamicTree* tree = &m_world->m_contactManager.m_broadPhase.m_tree; 76 | 77 | //if (m_stepCount == 400) 78 | //{ 79 | // tree->RebuildBottomUp(); 80 | //} 81 | } 82 | 83 | static Test* Create() 84 | { 85 | return new Pyramid; 86 | } 87 | }; 88 | 89 | #endif 90 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Testbed/Tests/SphereStack.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef SPHERE_STACK_H 20 | #define SPHERE_STACK_H 21 | 22 | class SphereStack : public Test 23 | { 24 | public: 25 | 26 | enum 27 | { 28 | e_count = 10 29 | }; 30 | 31 | SphereStack() 32 | { 33 | { 34 | b2BodyDef bd; 35 | b2Body* ground = m_world->CreateBody(&bd); 36 | 37 | b2EdgeShape shape; 38 | shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); 39 | ground->CreateFixture(&shape, 0.0f); 40 | } 41 | 42 | { 43 | b2CircleShape shape; 44 | shape.m_radius = 1.0f; 45 | 46 | for (int32 i = 0; i < e_count; ++i) 47 | { 48 | b2BodyDef bd; 49 | bd.type = b2_dynamicBody; 50 | bd.position.Set(0.0, 4.0f + 3.0f * i); 51 | 52 | m_bodies[i] = m_world->CreateBody(&bd); 53 | 54 | m_bodies[i]->CreateFixture(&shape, 1.0f); 55 | 56 | m_bodies[i]->SetLinearVelocity(b2Vec2(0.0f, -50.0f)); 57 | } 58 | } 59 | } 60 | 61 | void Step(Settings* settings) 62 | { 63 | Test::Step(settings); 64 | 65 | //for (int32 i = 0; i < e_count; ++i) 66 | //{ 67 | // printf("%g ", m_bodies[i]->GetWorldCenter().y); 68 | //} 69 | 70 | //for (int32 i = 0; i < e_count; ++i) 71 | //{ 72 | // printf("%g ", m_bodies[i]->GetLinearVelocity().y); 73 | //} 74 | 75 | //printf("\n"); 76 | } 77 | 78 | static Test* Create() 79 | { 80 | return new SphereStack; 81 | } 82 | 83 | b2Body* m_bodies[e_count]; 84 | }; 85 | 86 | #endif 87 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/Testbed/Tests/VaryingRestitution.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2009 Erin Catto http://www.box2d.org 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef VARYING_RESTITUTION_H 20 | #define VARYING_RESTITUTION_H 21 | 22 | // Note: even with a restitution of 1.0, there is some energy change 23 | // due to position correction. 24 | class VaryingRestitution : public Test 25 | { 26 | public: 27 | 28 | VaryingRestitution() 29 | { 30 | { 31 | b2BodyDef bd; 32 | b2Body* ground = m_world->CreateBody(&bd); 33 | 34 | b2EdgeShape shape; 35 | shape.Set(b2Vec2(-40.0f, 0.0f), b2Vec2(40.0f, 0.0f)); 36 | ground->CreateFixture(&shape, 0.0f); 37 | } 38 | 39 | { 40 | b2CircleShape shape; 41 | shape.m_radius = 1.0f; 42 | 43 | b2FixtureDef fd; 44 | fd.shape = &shape; 45 | fd.density = 1.0f; 46 | 47 | float32 restitution[7] = {0.0f, 0.1f, 0.3f, 0.5f, 0.75f, 0.9f, 1.0f}; 48 | 49 | for (int32 i = 0; i < 7; ++i) 50 | { 51 | b2BodyDef bd; 52 | bd.type = b2_dynamicBody; 53 | bd.position.Set(-10.0f + 3.0f * i, 20.0f); 54 | 55 | b2Body* body = m_world->CreateBody(&bd); 56 | 57 | fd.restitution = restitution[i]; 58 | body->CreateFixture(&fd); 59 | } 60 | } 61 | } 62 | 63 | static Test* Create() 64 | { 65 | return new VaryingRestitution; 66 | } 67 | }; 68 | 69 | #endif 70 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/glfw/clipboard.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.0 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2010 Camilla Berglund 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | 27 | #include "internal.h" 28 | 29 | #include 30 | #include 31 | 32 | 33 | ////////////////////////////////////////////////////////////////////////// 34 | ////// GLFW public API ////// 35 | ////////////////////////////////////////////////////////////////////////// 36 | 37 | GLFWAPI void glfwSetClipboardString(GLFWwindow* handle, const char* string) 38 | { 39 | _GLFWwindow* window = (_GLFWwindow*) handle; 40 | _GLFW_REQUIRE_INIT(); 41 | _glfwPlatformSetClipboardString(window, string); 42 | } 43 | 44 | GLFWAPI const char* glfwGetClipboardString(GLFWwindow* handle) 45 | { 46 | _GLFWwindow* window = (_GLFWwindow*) handle; 47 | _GLFW_REQUIRE_INIT_OR_RETURN(NULL); 48 | return _glfwPlatformGetClipboardString(window); 49 | } 50 | 51 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/glfw/config.h: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.0 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2010 Camilla Berglund 5 | // 6 | // This software is provided 'as-is', without any express or implied 7 | // warranty. In no event will the authors be held liable for any damages 8 | // arising from the use of this software. 9 | // 10 | // Permission is granted to anyone to use this software for any purpose, 11 | // including commercial applications, and to alter it and redistribute it 12 | // freely, subject to the following restrictions: 13 | // 14 | // 1. The origin of this software must not be misrepresented; you must not 15 | // claim that you wrote the original software. If you use this software 16 | // in a product, an acknowledgment in the product documentation would 17 | // be appreciated but is not required. 18 | // 19 | // 2. Altered source versions must be plainly marked as such, and must not 20 | // be misrepresented as being the original software. 21 | // 22 | // 3. This notice may not be removed or altered from any source 23 | // distribution. 24 | // 25 | //======================================================================== 26 | // As config.h.in, this file is used by CMake to produce the config.h shared 27 | // configuration header file. If you are adding a feature requiring 28 | // conditional compilation, this is the proper place to add the macros. 29 | //======================================================================== 30 | // As config.h, this file defines compile-time build options and macros for 31 | // all platforms supported by GLFW. As this is a generated file, don't modify 32 | // it. Instead, you should modify the config.h.in file. 33 | //======================================================================== 34 | 35 | // GLFW doesn't like to be embedded as source, but that is what I'm doing. 36 | #if defined(WIN32) 37 | #define _GLFW_WIN32 38 | #define _GLFW_WGL 39 | #endif 40 | 41 | #if defined(__APPLE__) 42 | #define _GLFW_COCOA 43 | #define _GLFW_NSGL 44 | //#define _GLFW_USE_CHDIR 45 | #define _GLFW_USE_MENUBAR 46 | #endif 47 | 48 | // TODO get defines for other platforms 49 | 50 | #define _GLFW_USE_OPENGL 51 | #define _GLFW_VERSION_FULL "3.0.3" 52 | 53 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/glfw/time.c: -------------------------------------------------------------------------------- 1 | //======================================================================== 2 | // GLFW 3.0 - www.glfw.org 3 | //------------------------------------------------------------------------ 4 | // Copyright (c) 2002-2006 Marcus Geelnard 5 | // Copyright (c) 2006-2010 Camilla Berglund 6 | // 7 | // This software is provided 'as-is', without any express or implied 8 | // warranty. In no event will the authors be held liable for any damages 9 | // arising from the use of this software. 10 | // 11 | // Permission is granted to anyone to use this software for any purpose, 12 | // including commercial applications, and to alter it and redistribute it 13 | // freely, subject to the following restrictions: 14 | // 15 | // 1. The origin of this software must not be misrepresented; you must not 16 | // claim that you wrote the original software. If you use this software 17 | // in a product, an acknowledgment in the product documentation would 18 | // be appreciated but is not required. 19 | // 20 | // 2. Altered source versions must be plainly marked as such, and must not 21 | // be misrepresented as being the original software. 22 | // 23 | // 3. This notice may not be removed or altered from any source 24 | // distribution. 25 | // 26 | //======================================================================== 27 | 28 | #include "internal.h" 29 | 30 | 31 | ////////////////////////////////////////////////////////////////////////// 32 | ////// GLFW public API ////// 33 | ////////////////////////////////////////////////////////////////////////// 34 | 35 | GLFWAPI double glfwGetTime(void) 36 | { 37 | _GLFW_REQUIRE_INIT_OR_RETURN(0.0); 38 | return _glfwPlatformGetTime(); 39 | } 40 | 41 | GLFWAPI void glfwSetTime(double time) 42 | { 43 | _GLFW_REQUIRE_INIT(); 44 | _glfwPlatformSetTime(time); 45 | } 46 | 47 | -------------------------------------------------------------------------------- /dependencies/Box2D/Box2D/premake4.lua: -------------------------------------------------------------------------------- 1 | -- Box2D premake script. 2 | -- http://industriousone.com/premake 3 | 4 | local action = _ACTION or "" 5 | 6 | solution "Box2D" 7 | location ( "Build/" .. action ) 8 | configurations { "Debug", "Release" } 9 | 10 | configuration "vs*" 11 | defines { "_CRT_SECURE_NO_WARNINGS" } 12 | 13 | configuration "Debug" 14 | targetdir ( "Build/" .. action .. "/bin/Debug" ) 15 | flags { "Symbols" } 16 | 17 | configuration "Release" 18 | targetdir ( "Build/" .. action .. "/bin/Release" ) 19 | defines { "NDEBUG" } 20 | flags { "Optimize" } 21 | 22 | project "Box2D" 23 | kind "StaticLib" 24 | language "C++" 25 | files { "Box2D/**.h", "Box2D/**.cpp" } 26 | vpaths { [""] = "Box2D" } 27 | includedirs { "." } 28 | 29 | project "GLEW" 30 | kind "StaticLib" 31 | language "C++" 32 | files { "glew/*.h", "glew/*.c" } 33 | vpaths { ["Headers"] = "**.h", ["Sources"] = "**.c" } 34 | includedirs { "." } 35 | 36 | project "GLFW" 37 | kind "StaticLib" 38 | language "C" 39 | files { "glfw/*.h", "glfw/*.c" } 40 | vpaths { ["Headers"] = "**.h", ["Sources"] = "**.c" } 41 | 42 | project "HelloWorld" 43 | kind "ConsoleApp" 44 | language "C++" 45 | files { "HelloWorld/HelloWorld.cpp" } 46 | vpaths { [""] = "HelloWorld" } 47 | includedirs { "." } 48 | links { "Box2D" } 49 | 50 | project "Testbed" 51 | kind "ConsoleApp" 52 | language "C++" 53 | files { "Testbed/**.h", "Testbed/**.cpp" } 54 | vpaths { [""] = "Testbed" } 55 | includedirs { "." } 56 | links { "Box2D", "GLEW", "GLFW" } 57 | configuration { "windows" } 58 | links { "glu32", "opengl32", "winmm" } 59 | configuration { "macosx" } 60 | linkoptions { "-framework OpenGL -framework Cocoa" } 61 | configuration { "not windows", "not macosx" } 62 | links { "X11", "GL", "GLU" } 63 | 64 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Enhancements/Controllers/b2ConstantAccelController.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include "b2ConstantAccelController.h" 20 | 21 | b2ConstantAccelController::b2ConstantAccelController(const b2ConstantAccelControllerDef* def) : b2Controller(def) 22 | { 23 | A = def->A; 24 | } 25 | 26 | void b2ConstantAccelController::Step(const b2TimeStep& step) 27 | { 28 | for(b2ControllerEdge *i=m_bodyList;i;i=i->nextBody){ 29 | b2Body* body = i->body; 30 | if(body->IsSleeping()) 31 | continue; 32 | body->SetLinearVelocity(body->GetLinearVelocity()+step.dt*A); 33 | } 34 | } 35 | 36 | void b2ConstantAccelController::Destroy(b2BlockAllocator* allocator) 37 | { 38 | allocator->Free(this, sizeof(b2ConstantAccelController)); 39 | } 40 | 41 | 42 | b2ConstantAccelController* b2ConstantAccelControllerDef::Create(b2BlockAllocator* allocator) const 43 | { 44 | void* mem = allocator->Allocate(sizeof(b2ConstantAccelController)); 45 | return new (mem) b2ConstantAccelController(this); 46 | } 47 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Enhancements/Controllers/b2ConstantAccelController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CONSTANTACCELCONTROLLER_H 20 | #define B2_CONSTANTACCELCONTROLLER_H 21 | 22 | #include "b2Controller.h" 23 | 24 | class b2ConstantAccelControllerDef; 25 | 26 | /// Applies a force every frame 27 | class b2ConstantAccelController : public b2Controller{ 28 | public: 29 | /// The force to apply 30 | b2Vec2 A; 31 | 32 | /// @see b2Controller::Step 33 | void Step(const b2TimeStep& step); 34 | 35 | protected: 36 | void Destroy(b2BlockAllocator* allocator); 37 | 38 | private: 39 | friend class b2ConstantAccelControllerDef; 40 | b2ConstantAccelController(const b2ConstantAccelControllerDef* def); 41 | 42 | }; 43 | 44 | /// This class is used to build constant acceleration controllers 45 | class b2ConstantAccelControllerDef : public b2ControllerDef 46 | { 47 | public: 48 | /// The force to apply 49 | b2Vec2 A; 50 | private: 51 | b2ConstantAccelController* Create(b2BlockAllocator* allocator) const; 52 | }; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Enhancements/Controllers/b2ConstantForceController.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #include "b2ConstantForceController.h" 20 | 21 | b2ConstantForceController::b2ConstantForceController(const b2ConstantForceControllerDef* def) : b2Controller(def) 22 | { 23 | F = def->F; 24 | } 25 | 26 | void b2ConstantForceController::Step(const b2TimeStep& step) 27 | { 28 | B2_NOT_USED(step); 29 | for(b2ControllerEdge *i=m_bodyList;i;i=i->nextBody){ 30 | b2Body* body = i->body; 31 | if(body->IsSleeping()) 32 | continue; 33 | body->ApplyForce(F,body->GetWorldCenter()); 34 | } 35 | } 36 | 37 | void b2ConstantForceController::Destroy(b2BlockAllocator* allocator) 38 | { 39 | allocator->Free(this, sizeof(b2ConstantForceController)); 40 | } 41 | 42 | 43 | b2ConstantForceController* b2ConstantForceControllerDef::Create(b2BlockAllocator* allocator) const 44 | { 45 | void* mem = allocator->Allocate(sizeof(b2ConstantForceController)); 46 | return new (mem) b2ConstantForceController(this); 47 | } 48 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Enhancements/Controllers/b2ConstantForceController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_CONSTANTFORCECONTROLLER_H 20 | #define B2_CONSTANTFORCECONTROLLER_H 21 | 22 | #include "b2Controller.h" 23 | 24 | class b2ConstantForceControllerDef; 25 | 26 | /// Applies a force every frame 27 | class b2ConstantForceController : public b2Controller 28 | { 29 | public: 30 | /// The force to apply 31 | b2Vec2 F; 32 | 33 | /// @see b2Controller::Step 34 | void Step(const b2TimeStep& step); 35 | 36 | protected: 37 | void Destroy(b2BlockAllocator* allocator); 38 | 39 | private: 40 | friend class b2ConstantForceControllerDef; 41 | b2ConstantForceController(const b2ConstantForceControllerDef* def); 42 | }; 43 | 44 | /// This class is used to build constant force controllers 45 | class b2ConstantForceControllerDef : public b2ControllerDef 46 | { 47 | public: 48 | /// The force to apply 49 | b2Vec2 F; 50 | private: 51 | b2ConstantForceController* Create(b2BlockAllocator* allocator) const; 52 | }; 53 | 54 | #endif 55 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Enhancements/Controllers/b2GravityController.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_GRAVITYCONTROLLER_H 20 | #define B2_GRAVITYCONTROLLER_H 21 | 22 | #include "b2Controller.h" 23 | 24 | class b2GravityControllerDef; 25 | 26 | /// Applies simplified gravity between every pair of bodies 27 | class b2GravityController : public b2Controller{ 28 | public: 29 | /// Specifies the strength of the gravitiation force 30 | float32 G; 31 | /// If true, gravity is proportional to r^-2, otherwise r^-1 32 | bool invSqr; 33 | 34 | /// @see b2Controller::Step 35 | void Step(const b2TimeStep& step); 36 | 37 | protected: 38 | void Destroy(b2BlockAllocator* allocator); 39 | 40 | private: 41 | friend class b2GravityControllerDef; 42 | b2GravityController(const b2GravityControllerDef* def); 43 | 44 | 45 | }; 46 | 47 | /// This class is used to build gravity controllers 48 | class b2GravityControllerDef : public b2ControllerDef 49 | { 50 | public: 51 | /// Specifies the strength of the gravitiation force 52 | float32 G; 53 | /// If true, gravity is proportional to r^-2, otherwise r^-1 54 | bool invSqr; 55 | private: 56 | b2GravityController* Create(b2BlockAllocator* allocator) const; 57 | }; 58 | 59 | #endif 60 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/AABB.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | #include "Vector.cpp" 5 | 6 | namespace Box2D 7 | { 8 | namespace Net 9 | { 10 | public ref class AABB 11 | { 12 | public: 13 | Vector ^lowerBound, ^upperBound; 14 | 15 | bool IsValid() 16 | { 17 | return getAABB().IsValid(); 18 | } 19 | 20 | AABB(Vector^ min, Vector^ max) : lowerBound(gcnew Vector(min)), upperBound(gcnew Vector(max)) { } 21 | AABB() : lowerBound(gcnew Vector()), upperBound(gcnew Vector()) { } 22 | 23 | b2AABB getAABB() 24 | { 25 | b2AABB returnme; 26 | returnme.lowerBound = lowerBound->getVec2(); 27 | returnme.upperBound = upperBound->getVec2(); 28 | return returnme; 29 | } 30 | }; 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/AssemblyInfo.cpp: -------------------------------------------------------------------------------- 1 | #include "stdafx.h" 2 | 3 | using namespace System; 4 | using namespace System::Reflection; 5 | using namespace System::Runtime::CompilerServices; 6 | using namespace System::Runtime::InteropServices; 7 | using namespace System::Security::Permissions; 8 | 9 | // 10 | // General Information about an assembly is controlled through the following 11 | // set of attributes. Change these attribute values to modify the information 12 | // associated with an assembly. 13 | // 14 | [assembly:AssemblyTitleAttribute("Box2DNet")]; 15 | [assembly:AssemblyDescriptionAttribute("A .NET wrapper for the Box2D physics library")]; 16 | [assembly:AssemblyConfigurationAttribute("")]; 17 | [assembly:AssemblyCompanyAttribute("")]; 18 | [assembly:AssemblyProductAttribute("Box2DNet")]; 19 | [assembly:AssemblyCopyrightAttribute("Copyright (c) Jay Lemmon 2008")]; 20 | [assembly:AssemblyTrademarkAttribute("")]; 21 | [assembly:AssemblyCultureAttribute("")]; 22 | 23 | // 24 | // Version information for an assembly consists of the following four values: 25 | // 26 | // Major Version 27 | // Minor Version 28 | // Build Number 29 | // Revision 30 | // 31 | // You can specify all the value or you can default the Revision and Build Numbers 32 | // by using the '*' as shown below: 33 | 34 | [assembly:AssemblyVersionAttribute("1.0.*")]; 35 | 36 | [assembly:ComVisible(false)]; 37 | 38 | [assembly:CLSCompliantAttribute(true)]; 39 | 40 | [assembly:SecurityPermission(SecurityAction::RequestMinimum, UnmanagedCode = true)]; 41 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/Contact.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | #include "Shape.cpp" 5 | #include "Manifold.cpp" 6 | 7 | namespace Box2D 8 | { 9 | namespace Net 10 | { 11 | public ref class Contact 12 | { 13 | internal: 14 | b2Contact *contact; 15 | Contact(b2Contact *contactRef) : contact(contactRef) { } 16 | 17 | public: 18 | property Shape^ Shape1 19 | { 20 | Shape^ get() 21 | { 22 | return gcnew Shape(contact->GetShape1()); 23 | } 24 | } 25 | 26 | property Shape^ Shape2 27 | { 28 | Shape^ get() 29 | { 30 | return gcnew Shape(contact->GetShape2()); 31 | } 32 | } 33 | 34 | Contact^ GetNext() 35 | { 36 | return gcnew Contact(contact->GetNext()); 37 | } 38 | 39 | Manifold^ GetManifolds() 40 | { 41 | return gcnew Manifold(contact->GetManifolds()); 42 | } 43 | 44 | property int ManifoldCount 45 | { 46 | int get() 47 | { 48 | return contact->GetManifoldCount(); 49 | } 50 | } 51 | }; 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/Delegates.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | #include "Joint.cpp" 5 | #include "Body.cpp" 6 | 7 | namespace Box2D 8 | { 9 | namespace Net 10 | { 11 | /// 12 | /// If a body is destroyed, then any joints attached to it are also destroyed. 13 | /// This prevents memory leaks, but you may unexpectedly be left with an 14 | /// orphaned joint pointer. 15 | /// Box2D will notify you when a joint is implicitly destroyed. 16 | /// It is NOT called if you directly destroy a joint. 17 | /// DO NOT modify the Box2D world inside this callback. 18 | /// 19 | public delegate void NotifyJointDestroyed(Joint); 20 | 21 | /// 22 | /// Return true if collision calculations should be performed between shape1 and shape2 23 | /// Box2D has a default implementation for this, so only add a new delegate if you 24 | /// want to override the default behavior. 25 | /// 26 | public delegate bool CollisionFilter(Shape shape1, Shape shape2); 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/Manifold.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | #include "Vector.cpp" 5 | //#include "ContactPoint.cpp" 6 | #include "ManifoldPoint.cpp" 7 | 8 | using namespace System::Collections::Generic; 9 | 10 | namespace Box2D 11 | { 12 | namespace Net 13 | { 14 | public ref class Manifold 15 | { 16 | internal: 17 | b2Manifold *fold; 18 | Manifold(b2Manifold *foldRef) : fold(foldRef) { } 19 | 20 | public: 21 | property Vector^ Normal 22 | { 23 | Vector^ get() 24 | { 25 | return gcnew Vector(fold->normal); 26 | } 27 | } 28 | 29 | property IList^ Points 30 | { 31 | IList^ get() 32 | { 33 | //TODO: implement 34 | List^ list = gcnew List; 35 | 36 | for(int x = 0; x < fold->pointCount; ++x) 37 | list->Add(gcnew ManifoldPoint(&fold->points[x])); 38 | 39 | return list; 40 | } 41 | } 42 | }; 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/ManifoldPoint.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | #include "Vector.cpp" 5 | 6 | namespace Box2D 7 | { 8 | namespace Net 9 | { 10 | //TODO: is this class really necessary for the public interface? 11 | public ref class ManifoldPoint 12 | { 13 | internal: 14 | b2ManifoldPoint *point; 15 | ManifoldPoint(b2ManifoldPoint *pointRef) : point(pointRef) { } 16 | public: 17 | 18 | property Vector^ LocalPoint1 19 | { 20 | Vector^ get() 21 | { 22 | return gcnew Vector(point->localPoint1); 23 | } 24 | 25 | void set(Vector^ value) 26 | { 27 | point->localPoint1 = value->getVec2(); 28 | } 29 | } 30 | 31 | property Vector^ LocalPoint2 32 | { 33 | Vector^ get() 34 | { 35 | return gcnew Vector(point->localPoint2); 36 | } 37 | 38 | void set(Vector^ value) 39 | { 40 | point->localPoint2 = value->getVec2(); 41 | } 42 | } 43 | 44 | property float32 Separation 45 | { 46 | float32 get() 47 | { 48 | return point->separation; 49 | } 50 | 51 | void set(float32 value) 52 | { 53 | point->separation = value; 54 | } 55 | } 56 | 57 | property float32 NormalForce 58 | { 59 | float32 get() 60 | { 61 | return point->normalForce; 62 | } 63 | 64 | void set(float32 value) 65 | { 66 | point->normalForce = value; 67 | } 68 | } 69 | 70 | property float32 TangentForce 71 | { 72 | float32 get() 73 | { 74 | return point->tangentForce; 75 | } 76 | 77 | void set(float32 value) 78 | { 79 | point->tangentForce = value; 80 | } 81 | } 82 | 83 | //TODO: marshall b2ContactID 84 | /* 85 | property b2ContactID ID 86 | { 87 | b2ContactID get() 88 | { 89 | return point->id; 90 | } 91 | 92 | void set(b2ContactID value) 93 | { 94 | point->id = value; 95 | } 96 | } 97 | */ 98 | }; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/MassData.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | #include "Vector.cpp" 5 | 6 | namespace Box2D 7 | { 8 | namespace Net 9 | { 10 | public ref class MassData 11 | { 12 | internal: 13 | bool DeleteWhenDone; 14 | b2MassData *data; 15 | MassData(b2MassData *dataRef) : data(dataRef), DeleteWhenDone(false) { } 16 | public: 17 | MassData() : data(new b2MassData()), DeleteWhenDone(true) { } 18 | virtual ~MassData() 19 | { 20 | if(DeleteWhenDone) 21 | delete data; 22 | } 23 | 24 | property float32 Mass 25 | { 26 | float32 get() 27 | { 28 | return data->mass; 29 | } 30 | 31 | void set(float32 value) 32 | { 33 | data->mass = value; 34 | } 35 | } 36 | 37 | property float32 I 38 | { 39 | float32 get() 40 | { 41 | return data->I; 42 | } 43 | 44 | void set(float32 value) 45 | { 46 | data->I = value; 47 | } 48 | } 49 | 50 | property Vector^ Center 51 | { 52 | Vector^ get() 53 | { 54 | return gcnew Vector(data->center); 55 | } 56 | 57 | void set(Vector^ value) 58 | { 59 | data->center = value->getVec2(); 60 | } 61 | } 62 | }; 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/Matrix.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Stdafx.h" 4 | #include "Vector.cpp" 5 | 6 | namespace Box2D 7 | { 8 | namespace Net 9 | { 10 | public ref class Matrix 11 | { 12 | internal: 13 | Matrix(const b2Mat22 &matrix) : col1(gcnew Vector(matrix.col1)), col2(gcnew Vector(matrix.col2)) { } 14 | b2Mat22 getMat22() 15 | { 16 | return b2Mat22(col1->getVec2(), col2->getVec2()); 17 | } 18 | public: 19 | Vector ^col1, ^col2; 20 | 21 | Matrix() : col1(gcnew Vector()), col2(gcnew Vector()) {} 22 | Matrix(Vector^ c1, Vector^ c2) : col1(gcnew Vector(c1)), col2(gcnew Vector(c2)) { } 23 | explicit Matrix(float32 angle) 24 | { 25 | Set(angle); 26 | } 27 | 28 | void Set(Vector^ c1, Vector^ c2) 29 | { 30 | col1->X = c1->X; 31 | col1->Y = c1->Y; 32 | 33 | col2->X = c2->X; 34 | col2->Y = c2->Y; 35 | } 36 | 37 | void Set(float32 angle) 38 | { 39 | float32 c = cosf(angle), s = sinf(angle); 40 | col1->X = c; col2->X = -s; 41 | col1->Y = s; col2->Y = c; 42 | } 43 | 44 | void SetIdentity() 45 | { 46 | col1->X = 1; col2->X = 0; 47 | col1->Y = 0; col2->Y = 1; 48 | } 49 | 50 | static Vector^ operator * (Matrix^ mat, Vector^ a) 51 | { 52 | return gcnew Vector(b2Mul(mat->getMat22(), a->getVec2())); 53 | } 54 | }; 55 | } 56 | } 57 | 58 | /* 59 | struct b2Mat22 60 | { 61 | void SetZero() 62 | { 63 | col1.x = 0.0f; col2.x = 0.0f; 64 | col1.y = 0.0f; col2.y = 0.0f; 65 | } 66 | 67 | b2Mat22 Invert() const 68 | { 69 | float32 a = col1.x, b = col2.x, c = col1.y, d = col2.y; 70 | b2Mat22 B; 71 | float32 det = a * d - b * c; 72 | b2Assert(det != 0.0f); 73 | det = 1.0f / det; 74 | B.col1.x = det * d; B.col2.x = -det * b; 75 | B.col1.y = -det * c; B.col2.y = det * a; 76 | return B; 77 | } 78 | 79 | // Solve A * x = b 80 | b2Vec2 Solve(const b2Vec2& b) const 81 | { 82 | float32 a11 = col1.x, a12 = col2.x, a21 = col1.y, a22 = col2.y; 83 | float32 det = a11 * a22 - a12 * a21; 84 | b2Assert(det != 0.0f); 85 | det = 1.0f / det; 86 | b2Vec2 x; 87 | x.x = det * (a22 * b.x - a12 * b.y); 88 | x.y = det * (a11 * b.y - a21 * b.x); 89 | return x; 90 | } 91 | 92 | b2Vec2 col1, col2; 93 | }; 94 | */ 95 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/ShapeType.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | 5 | namespace Box2D 6 | { 7 | namespace Net 8 | { 9 | //TODO: is there a way to auto incorporate shape types? 10 | public enum class ShapeType 11 | { 12 | e_unknownShape = ::e_unknownShape, 13 | e_circleShape = ::e_circleShape, 14 | e_polygonShape = ::e_polygonShape, 15 | e_shapeTypeCount = ::e_shapeTypeCount 16 | }; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/Stdafx.h: -------------------------------------------------------------------------------- 1 | // stdafx.h : include file for standard system include files, 2 | // or project specific include files that are used frequently, 3 | // but are changed infrequently 4 | 5 | #pragma once 6 | 7 | 8 | #include "Box2D.h" 9 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/VariousImplementations.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | #include "Shape.cpp" 5 | #include "Body.cpp" 6 | 7 | namespace Box2D 8 | { 9 | namespace Net 10 | { 11 | Body^ Shape::Body::get() 12 | { 13 | return gcnew Box2D::Net::Body(shape->GetBody()); 14 | } 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/Vector.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "Stdafx.h" 4 | 5 | namespace Box2D 6 | { 7 | namespace Net 8 | { 9 | public ref class Vector 10 | { 11 | internal: 12 | b2Vec2 getVec2() 13 | { 14 | return b2Vec2(X, Y); 15 | } 16 | 17 | public: 18 | 19 | //TODO: this needs to be read only outside the class, 20 | //because if you have a vector as a get property, and 21 | //try to set the X,Y components, it won't take to the 22 | //original vector: 23 | // 24 | //ie: Shape.Extents.X += 10; 25 | //won't behave like you think it should (or will it?) 26 | float32 X, Y; 27 | 28 | Vector() : X(0), Y(0) { } 29 | Vector(float32 x, float32 y) : X(x), Y(y) { } 30 | Vector(Vector^ other) : X(other->X), Y(other->Y) { } 31 | Vector(const b2Vec2 &other) : X(other.x), Y(other.y) { } 32 | 33 | /* 34 | Vector^ Set(float32 x, float32 y) 35 | { 36 | X = x; 37 | Y = y; 38 | return this; 39 | } 40 | */ 41 | 42 | ///Defines basic vector addition 43 | static Vector^ operator +(Vector^ a, Vector^ b) 44 | { 45 | return gcnew Vector(a->X + b->X, a->Y + b->Y); 46 | } 47 | 48 | ///Negates a vector (that is, returns (-X, -Y) 49 | static Vector^ operator - (Vector^ a) 50 | { 51 | return gcnew Vector(-a->X, -a->Y); 52 | } 53 | 54 | ///Defines basic vector subtraction 55 | static Vector^ operator - (Vector^ a, Vector^ b) 56 | { 57 | return gcnew Vector(a->X - b->X, a->Y - b->Y); 58 | } 59 | 60 | ///Scalar multiplication for a vector 61 | static Vector^ operator * (Vector^ a, float32 b) 62 | { 63 | return gcnew Vector(a->X * b, a->Y * b); 64 | } 65 | 66 | /* 67 | static Vector^ operator = (Vector^ a, Vector^ b) 68 | { 69 | a.X = b.X; 70 | a.Y = b.Y; 71 | } 72 | */ 73 | 74 | ///Returns a string representation of this vector 75 | virtual System::String^ ToString() override 76 | { 77 | return gcnew System::String("<" + X + ", " + Y + ">"); 78 | } 79 | }; 80 | } 81 | } 82 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.Net/XForm.cpp: -------------------------------------------------------------------------------- 1 | #pragma once 2 | 3 | #include "stdafx.h" 4 | #include "Vector.cpp" 5 | #include "Matrix.cpp" 6 | 7 | namespace Box2D 8 | { 9 | namespace Net 10 | { 11 | public ref class XForm 12 | { 13 | internal: 14 | b2XForm *xform; 15 | bool DeleteOnDtor; 16 | XForm(b2XForm *XForm) : xform(XForm), DeleteOnDtor(false) { } 17 | XForm(b2XForm XForm) : xform(new b2XForm(XForm)), DeleteOnDtor(false) { } 18 | b2XForm getXForm() 19 | { 20 | return *xform; 21 | } 22 | public: 23 | XForm() : xform(new b2XForm()), DeleteOnDtor(true) { } 24 | ~XForm() 25 | { 26 | if(DeleteOnDtor) 27 | delete xform; 28 | } 29 | 30 | property Vector^ Position 31 | { 32 | Vector^ get() 33 | { 34 | return gcnew Vector(xform->position); 35 | } 36 | } 37 | 38 | property Matrix^ Rotation 39 | { 40 | Matrix^ get() 41 | { 42 | return gcnew Matrix(xform->R); 43 | } 44 | } 45 | }; 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Box2D.XNA.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Contributions/Platforms/Box2D.XNA.zip -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/TestBed.Net/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Box2D.Net; 5 | using System.Windows.Forms; 6 | 7 | namespace TestBed.Net 8 | { 9 | class Program 10 | { 11 | static void Main(string[] args) 12 | { 13 | Console.Title = "Box2D.Net Test Bed"; 14 | Application.EnableVisualStyles(); 15 | MainWindow win = new MainWindow(); 16 | 17 | Console.Write("Loading the OpenGL display window. Please be patient... "); 18 | 19 | //Show above the console 20 | win.Show(); 21 | win.BringToFront(); //Doesn't bring above the console? 22 | win.TopMost = true; //Hacky fix instead: 23 | win.TopMost = false; 24 | 25 | Console.WriteLine("DONE"); 26 | 27 | Application.Run(win); 28 | } 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/TestBed.Net/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle("TestBed.Net")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("TestBed.Net")] 13 | [assembly: AssemblyCopyright("Copyright © 2008")] 14 | [assembly: AssemblyTrademark("")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible(false)] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid("c08bf3be-733a-49ed-820b-ad4f13ff3a00")] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | [assembly: AssemblyVersion("1.0.0.0")] 33 | [assembly: AssemblyFileVersion("1.0.0.0")] 34 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/TestBed.Net/Settings.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | 5 | namespace TestBed.Net 6 | { 7 | public class Settings 8 | { 9 | public float Hz = 60; 10 | public int IterationCount = 10; 11 | public bool DrawStats = false; 12 | public bool DrawContacts = false; 13 | public bool DrawImpulses = false; 14 | public bool DrawAABBs = false; 15 | public bool DrawPairs = false; 16 | public bool WarmStarting = true; 17 | public bool PositionCorrection = true; 18 | public bool Pause = false; 19 | } 20 | } 21 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/TestBed.Net/Tests/Bridge.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Text; 4 | using Box2D.Net; 5 | 6 | namespace TestBed.Net.Tests 7 | { 8 | public class Bridge : TestBed.Net.Test 9 | { 10 | public Bridge() 11 | { 12 | Body ground; 13 | { 14 | PolygonDef sd = new PolygonDef(); 15 | sd.ShapeType = ShapeType.e_polygonShape; 16 | sd.SetAsBox(50.0f, 10.0f); 17 | 18 | BodyDef bd = new BodyDef(); 19 | bd.Position = new Vector(0, -10); 20 | 21 | ground = world.CreateBody(bd); 22 | ground.CreateShape(sd); 23 | } 24 | 25 | { 26 | PolygonDef sd = new PolygonDef(); 27 | sd.SetAsBox(0.5f, 0.125f); 28 | sd.Density = 20.0f; 29 | sd.Friction = 0.2f; 30 | 31 | BodyDef bd = new BodyDef(); 32 | bd.BodyType = BodyType.e_dynamicBody; 33 | 34 | RevoluteJointDef jd = new RevoluteJointDef(); 35 | const float numPlanks = 30; 36 | 37 | Body prevBody = ground; 38 | 39 | for (float i = 0; i < numPlanks; ++i) 40 | { 41 | bd.Position = new Vector(-14.5f + i, 5); 42 | Body body = world.CreateBody(bd); 43 | body.CreateShape(sd); 44 | body.SetMassFromShapes(); 45 | 46 | Vector anchor = new Vector(-15 + i, 5); 47 | jd.Initialize(prevBody, body, anchor); 48 | world.CreateJoint(jd); 49 | 50 | prevBody = body; 51 | } 52 | 53 | Vector anchor2 = new Vector(-15 + numPlanks, 5); 54 | jd.Initialize(prevBody, ground, anchor2); 55 | world.CreateJoint(jd); 56 | } 57 | } 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/Tizen.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Contributions/Platforms/Tizen.zip -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/iPhone/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 2.6) 2 | 3 | set(BOX2D_VERSION 2.1.0) 4 | set(BOX2D_BUILD_STATIC true) 5 | set(BOX2D_DIR ../../../Box2D) 6 | subdirs(${BOX2D_DIR}/Box2D) 7 | 8 | project(iPhoneTestbed) 9 | 10 | include_directories(${BOX2D_DIR} ${BOX2D_DIR}/Testbed/Tests) 11 | file(GLOB iPhoneTestbed_Classes_SRCS Classes/*.mm) 12 | source_group(Classes FILES ${iPhoneTestbed_Classes_SRCS}) 13 | 14 | set(CMAKE_OSX_SYSROOT iphoneos) 15 | set(CMAKE_OSX_DEPLOYMENT_TARGET "") 16 | set(CMAKE_OSX_ARCHITECTURES $(ARCHS_STANDARD_32_BIT)) 17 | set(CMAKE_EXE_LINKER_FLAGS "-framework Foundation -framework CoreGraphics -framework QuartzCore -framework OpenGLES -framework UIKit") 18 | set(MACOSX_BUNDLE_PRODUCT_NAME \${PRODUCT_NAME}) 19 | set(MACOSX_BUNDLE_GUI_IDENTIFIER "com.mycompany.\${PRODUCT_NAME:identifier}") 20 | 21 | add_executable(iPhoneTestbed MACOSX_BUNDLE 22 | ${iPhoneTestbed_Classes_SRCS} 23 | main.m 24 | ) 25 | 26 | target_link_libraries(iPhoneTestbed Box2D) 27 | 28 | set_target_properties(iPhoneTestbed PROPERTIES MACOSX_BUNDLE_INFO_PLIST Info.plist.in XCODE_ATTRIBUTE_CODE_SIGN_IDENTITY "iPhone Developer") 29 | 30 | set(APP_NAME \${TARGET_BUILD_DIR}/\${FULL_PRODUCT_NAME}) 31 | find_program(IBTOOL ibtool HINTS "/usr/bin" "${OSX_DEVELOPER_ROOT}/usr/bin") 32 | set(NIB MainWindow) 33 | add_custom_command(TARGET iPhoneTestbed POST_BUILD 34 | COMMAND /Developer/Library/PrivateFrameworks/DevToolsCore.framework/Resources/pbxcp -exclude .DS_Store -exclude CVS -exclude .svn -resolve-src-symlinks Resources/* ${APP_NAME} 35 | COMMAND ${IBTOOL} --errors --warnings --notices --output-format human-readable-text --compile ${iPhoneTestbed_BINARY_DIR}/\${CONFIGURATION}/${PROJECT_NAME}.app/${NIB}.nib ${NIB}.xib 36 | ) 37 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/iPhone/Classes/Box2DAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // Box2DAppDelegate.h 3 | // Box2D 4 | // 5 | // Box2D iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com 6 | // 7 | 8 | #import 9 | #import "TestEntriesViewController.h" 10 | #import "Delegates.h" 11 | 12 | @class Box2DView; 13 | 14 | @interface Box2DAppDelegate : NSObject { 15 | UIWindow *window; 16 | Box2DView *glView; 17 | TestEntriesViewController *testEntriesView; 18 | } 19 | 20 | @property (nonatomic, retain) IBOutlet UIWindow *window; 21 | @property (nonatomic, retain) IBOutlet Box2DView *glView; 22 | 23 | @end 24 | 25 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/iPhone/Classes/Box2DAppDelegate.mm: -------------------------------------------------------------------------------- 1 | // 2 | // Box2DAppDelegate.m 3 | // Box2D 4 | // 5 | // Box2D iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com 6 | // 7 | 8 | #import 9 | #import "Box2DAppDelegate.h" 10 | #import "Box2DView.h" 11 | 12 | @implementation Box2DAppDelegate 13 | 14 | @synthesize window; 15 | @synthesize glView; 16 | 17 | - (void)applicationDidFinishLaunching:(UIApplication *)application { 18 | [application setStatusBarHidden:true]; 19 | 20 | [glView removeFromSuperview]; 21 | 22 | glView.animationInterval = 1.0 / 60.0; 23 | 24 | testEntriesView=[[TestEntriesViewController alloc] initWithStyle:UITableViewStylePlain]; 25 | [testEntriesView setDelegate:self]; 26 | [glView setDelegate:self]; 27 | 28 | [window addSubview:[testEntriesView view]]; 29 | } 30 | 31 | -(void) selectTest:(int) testIndex 32 | { 33 | [[testEntriesView view] removeFromSuperview]; 34 | [window addSubview:glView]; 35 | [glView startAnimation]; 36 | [glView selectTestEntry:testIndex]; 37 | } 38 | 39 | -(void) leaveTest 40 | { 41 | [glView stopAnimation]; 42 | [glView removeFromSuperview]; 43 | [window addSubview:[testEntriesView view]]; 44 | } 45 | 46 | - (void)applicationWillResignActive:(UIApplication *)application { 47 | glView.animationInterval = 1.0 / 5.0; 48 | } 49 | 50 | 51 | - (void)applicationDidBecomeActive:(UIApplication *)application { 52 | glView.animationInterval = 1.0 / 60.0; 53 | } 54 | 55 | 56 | - (void)dealloc { 57 | [window release]; 58 | [glView release]; 59 | [super dealloc]; 60 | } 61 | 62 | @end 63 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/iPhone/Classes/Box2DView.h: -------------------------------------------------------------------------------- 1 | // 2 | // Box2DView.h 3 | // Box2D OpenGL View 4 | // 5 | // Box2D iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com 6 | // 7 | 8 | 9 | #import 10 | #import 11 | #import 12 | #import 13 | 14 | #import "iPhoneTest.h" 15 | #import "Delegates.h" 16 | 17 | /* 18 | This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass. 19 | The view content is basically an EAGL surface you render your OpenGL scene into. 20 | Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel. 21 | */ 22 | @interface Box2DView : UIView { 23 | 24 | @private 25 | /* The pixel dimensions of the backbuffer */ 26 | GLint backingWidth; 27 | GLint backingHeight; 28 | 29 | EAGLContext *context; 30 | 31 | /* OpenGL names for the renderbuffer and framebuffers used to render to this view */ 32 | GLuint viewRenderbuffer, viewFramebuffer; 33 | 34 | /* OpenGL name for the depth buffer that is attached to viewFramebuffer, if it exists (0 if it does not exist) */ 35 | GLuint depthRenderbuffer; 36 | 37 | NSTimer *animationTimer; 38 | NSTimeInterval animationInterval; 39 | 40 | TestEntry* entry; 41 | Test* test; 42 | 43 | // Position offset and scale 44 | float sceneScale; 45 | CGPoint positionOffset; 46 | CGPoint lastWorldTouch; 47 | CGPoint lastScreenTouch; 48 | 49 | bool panning; 50 | int doubleClickValidCountdown; 51 | 52 | id _delegate; 53 | 54 | } 55 | @property(assign) id delegate; 56 | @property NSTimeInterval animationInterval; 57 | 58 | - (void)startAnimation; 59 | - (void)stopAnimation; 60 | - (void)drawView; 61 | -(void) selectTestEntry:(int) testIndex; 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/iPhone/Classes/Delegates.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Delegates.h 3 | * Box2D 4 | * 5 | * Box2D iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com 6 | * 7 | * 8 | */ 9 | 10 | @protocol TestSelectDelegate 11 | -(void) selectTest:(int) testIndex; 12 | -(void) leaveTest; 13 | 14 | @end -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/iPhone/Classes/GLES-Render.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2006-2007 Erin Catto http://www.gphysics.com 3 | * 4 | * iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com 5 | * 6 | * This software is provided 'as-is', without any express or implied 7 | * warranty. In no event will the authors be held liable for any damages 8 | * arising from the use of this software. 9 | * Permission is granted to anyone to use this software for any purpose, 10 | * including commercial applications, and to alter it and redistribute it 11 | * freely, subject to the following restrictions: 12 | * 1. The origin of this software must not be misrepresented; you must not 13 | * claim that you wrote the original software. If you use this software 14 | * in a product, an acknowledgment in the product documentation would be 15 | * appreciated but is not required. 16 | * 2. Altered source versions must be plainly marked as such, and must not be 17 | * misrepresented as being the original software. 18 | * 3. This notice may not be removed or altered from any source distribution. 19 | */ 20 | 21 | #ifndef RENDER_H 22 | #define RENDER_H 23 | 24 | #import 25 | #import 26 | #import 27 | #import 28 | 29 | #include 30 | 31 | struct b2AABB; 32 | 33 | // This class implements debug drawing callbacks that are invoked 34 | // inside b2World::Step. 35 | class GLESDebugDraw : public b2Draw 36 | { 37 | public: 38 | void DrawPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color); 39 | 40 | void DrawSolidPolygon(const b2Vec2* vertices, int32 vertexCount, const b2Color& color); 41 | 42 | void DrawCircle(const b2Vec2& center, float32 radius, const b2Color& color); 43 | 44 | void DrawSolidCircle(const b2Vec2& center, float32 radius, const b2Vec2& axis, const b2Color& color); 45 | 46 | void DrawSegment(const b2Vec2& p1, const b2Vec2& p2, const b2Color& color); 47 | 48 | void DrawTransform(const b2Transform& xf); 49 | 50 | void DrawPoint(const b2Vec2& p, float32 size, const b2Color& color); 51 | 52 | void DrawString(int x, int y, const char* string, ...); 53 | 54 | void DrawAABB(b2AABB* aabb, const b2Color& color); 55 | }; 56 | 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/iPhone/Classes/TestEntriesViewController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TestEntriesViewController.h 3 | // Box2D 4 | // 5 | // Box2D iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com 6 | // 7 | 8 | #import 9 | #import "iPhoneTest.h" 10 | #import "Delegates.h" 11 | 12 | @interface TestEntriesViewController : UITableViewController { 13 | int32 testCount; 14 | id _delegate; 15 | } 16 | 17 | @property(assign) id delegate; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/iPhone/Classes/TestEntriesViewController.mm: -------------------------------------------------------------------------------- 1 | // 2 | // TestEntriesViewController.m 3 | // Box2D 4 | // 5 | // Box2D iPhone port by Simon Oliver - http://www.simonoliver.com - http://www.handcircus.com 6 | // 7 | 8 | #import "TestEntriesViewController.h" 9 | 10 | 11 | @implementation TestEntriesViewController 12 | 13 | @synthesize delegate=_delegate; 14 | 15 | - (id)initWithStyle:(UITableViewStyle)style { 16 | if (self = [super initWithStyle:style]) { 17 | testCount = 0; 18 | TestEntry* e = g_testEntries; 19 | while (e->createFcn) 20 | { 21 | ++testCount; 22 | ++e; 23 | } 24 | } 25 | return self; 26 | } 27 | 28 | - (void)didReceiveMemoryWarning { 29 | [super didReceiveMemoryWarning]; // Releases the view if it doesn't have a superview 30 | // Release anything that's not essential, such as cached data 31 | } 32 | 33 | #pragma mark Table view methods 34 | 35 | - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView { 36 | return 1; 37 | } 38 | 39 | 40 | // Customize the number of rows in the table view. 41 | - (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section { 42 | return testCount; 43 | } 44 | 45 | 46 | // Customize the appearance of table view cells. 47 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 48 | 49 | static NSString *CellIdentifier = @"Cell"; 50 | 51 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 52 | if (cell == nil) { 53 | cell = [[[UITableViewCell alloc] initWithFrame:CGRectZero reuseIdentifier:CellIdentifier] autorelease]; 54 | } 55 | 56 | // Set up the cell... 57 | TestEntry* e = g_testEntries; 58 | e+=indexPath.row; 59 | 60 | cell.textLabel.text = [NSString stringWithUTF8String:e->name]; 61 | return cell; 62 | } 63 | 64 | 65 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 66 | [_delegate selectTest:indexPath.row]; 67 | } 68 | 69 | - (void)dealloc { 70 | [super dealloc]; 71 | } 72 | 73 | 74 | @end 75 | 76 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/iPhone/Info.plist.in: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${MACOSX_BUNDLE_PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${MACOSX_BUNDLE_EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | ${MACOSX_BUNDLE_GUI_IDENTIFIER} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${MACOSX_BUNDLE_PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | 30 | 31 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/iPhone/Resources/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/soulik/LuaBox2D/6cb0f7fa3d6f506c3794e1eb32c454d535926329/dependencies/Box2D/Contributions/Platforms/iPhone/Resources/Icon.png -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Platforms/iPhone/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // Box2D 4 | // 5 | // Created by Simon Oliver on 14/01/2009. 6 | // Copyright HandCircus 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Readme.txt: -------------------------------------------------------------------------------- 1 | This folder contains user contributions. Contributions are _not_ supported by the Box2D project. 2 | 3 | Contributions may not compile or function correctly. -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Tests/Biped.h: -------------------------------------------------------------------------------- 1 | #ifndef BIPED_H 2 | #define BIPED_H 3 | 4 | #include "Box2D.h" 5 | 6 | // Ragdoll class thanks to darkzerox. 7 | class Biped 8 | { 9 | public: 10 | Biped(b2World*, const b2Vec2& position); 11 | ~Biped(); 12 | 13 | private: 14 | b2World* m_world; 15 | 16 | b2Body *LFoot, *RFoot, *LCalf, *RCalf, *LThigh, *RThigh, 17 | *Pelvis, *Stomach, *Chest, *Neck, *Head, 18 | *LUpperArm, *RUpperArm, *LForearm, *RForearm, *LHand, *RHand; 19 | 20 | b2RevoluteJoint *LAnkle, *RAnkle, *LKnee, *RKnee, *LHip, *RHip, 21 | *LowerAbs, *UpperAbs, *LowerNeck, *UpperNeck, 22 | *LShoulder, *RShoulder, *LElbow, *RElbow, *LWrist, *RWrist; 23 | }; 24 | 25 | #endif 26 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Tests/BipedDef.h: -------------------------------------------------------------------------------- 1 | #ifndef BIPED_DEF_H 2 | #define BIPED_DEF_H 3 | 4 | #include "Box2D.h" 5 | 6 | class BipedDef 7 | { 8 | public: 9 | BipedDef(); 10 | ~BipedDef(void); 11 | 12 | void SetMotorTorque(float); 13 | void SetMotorSpeed(float); 14 | void SetDensity(float); 15 | void SetFriction(float); 16 | void SetRestitution(float); 17 | void SetLinearDamping(float); 18 | void SetAngularDamping(float); 19 | void EnableLimit(); 20 | void DisableLimit(); 21 | void SetLimit(bool); 22 | void EnableMotor(); 23 | void DisableMotor(); 24 | void SetMotor(bool); 25 | void SetGroupIndex(int16); 26 | void SetPosition(float, float); 27 | void SetPosition(b2Vec2); 28 | void IsFast(bool); 29 | 30 | static int16 count; 31 | 32 | b2BodyDef LFootDef, RFootDef, LCalfDef, RCalfDef, LThighDef, RThighDef, 33 | PelvisDef, StomachDef, ChestDef, NeckDef, HeadDef, 34 | LUpperArmDef, RUpperArmDef, LForearmDef, RForearmDef, LHandDef, RHandDef; 35 | 36 | b2PolygonDef LFootPoly, RFootPoly, LCalfPoly, RCalfPoly, LThighPoly, RThighPoly, 37 | PelvisPoly, StomachPoly, ChestPoly, NeckPoly, 38 | LUpperArmPoly, RUpperArmPoly, LForearmPoly, RForearmPoly, LHandPoly, RHandPoly; 39 | 40 | b2CircleDef HeadCirc; 41 | 42 | b2RevoluteJointDef LAnkleDef, RAnkleDef, LKneeDef, RKneeDef, LHipDef, RHipDef, 43 | LowerAbsDef, UpperAbsDef, LowerNeckDef, UpperNeckDef, 44 | LShoulderDef, RShoulderDef, LElbowDef, RElbowDef, LWristDef, RWristDef; 45 | 46 | void DefaultVertices(); 47 | void DefaultPositions(); 48 | void DefaultJoints(); 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /dependencies/Box2D/Contributions/Utilities/ConvexDecomposition/b2Triangle.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007 Eric Jordan 3 | * 4 | * This software is provided 'as-is', without any express or implied 5 | * warranty. In no event will the authors be held liable for any damages 6 | * arising from the use of this software. 7 | * Permission is granted to anyone to use this software for any purpose, 8 | * including commercial applications, and to alter it and redistribute it 9 | * freely, subject to the following restrictions: 10 | * 1. The origin of this software must not be misrepresented; you must not 11 | * claim that you wrote the original software. If you use this software 12 | * in a product, an acknowledgment in the product documentation would be 13 | * appreciated but is not required. 14 | * 2. Altered source versions must be plainly marked as such, and must not be 15 | * misrepresented as being the original software. 16 | * 3. This notice may not be removed or altered from any source distribution. 17 | */ 18 | 19 | #ifndef B2_TRIANGLE_H 20 | #define B2_TRIANGLE_H 21 | 22 | #include "b2Math.h" 23 | 24 | class b2Triangle{ 25 | public: 26 | float* x; 27 | float* y; 28 | b2Triangle(); 29 | b2Triangle(float32 x1, float32 y1, float32 x2, float32 y2, float32 x3, float32 y3); 30 | ~b2Triangle(); 31 | bool IsInside(float32 _x, float32 _y); 32 | void Set(const b2Triangle& toMe); 33 | 34 | }; 35 | 36 | #endif -------------------------------------------------------------------------------- /src/LuaBox2D.version: -------------------------------------------------------------------------------- 1 | LuaBox2D { 2 | global: luaopen_LuaBox2D; 3 | local: *; 4 | }; 5 | -------------------------------------------------------------------------------- /src/array.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_ARRAY_H 2 | #define LUABOX2D_ARRAY_H 3 | 4 | #include 5 | 6 | namespace LuaBox2D { 7 | 8 | template 9 | class Array { 10 | private: 11 | C ** usedArray; 12 | size_t size; 13 | public: 14 | Array(){ 15 | usedArray = nullptr; 16 | size = 0; 17 | } 18 | 19 | Array(const Array & other){ 20 | usedArray = other.usedArray; 21 | size = other.size; 22 | } 23 | 24 | Array(const C ** arrayPtr, size_t arraySize = 0){ 25 | set(arrayPtr, size); 26 | } 27 | 28 | size_t getSize(){ 29 | return size; 30 | } 31 | 32 | void set(const C ** arrayPtr, size_t arraySize = 0){ 33 | usedArray = arrayPtr; 34 | size = arraySize; 35 | } 36 | 37 | void add(C * element){ 38 | size++; 39 | usedArray = static_cast(std::realloc(usedArray, sizeof(C*) * size)); 40 | (*usedArray)[size-1] = *element; 41 | } 42 | 43 | C & operator[](size_t index){ 44 | if (index>=0 && index 5 | #include 6 | 7 | using namespace lutok2; 8 | /* 9 | #define ADD_VALID_TYPE(NAME) validTypes.push_front("class lutok2::Object *") 10 | #define ADD_VALID_STRUCT(NAME) validTypes.push_front("class lutok2::Object *") 11 | */ 12 | #define ADD_VALID_TYPE(C) validTypes.push_front(typeid(C).name()) 13 | #define ADD_VALID_STRUCT(C) validTypes.push_front(typeid(C).name()) 14 | 15 | #if (BUILDING_LIBLUABOX2D || LuaBox2D_EXPORTS) && HAVE_VISIBILITY 16 | #define LIBLUABOX2D_DLL_EXPORTED __attribute__((visibility("default"))) 17 | #elif (BUILDING_LIBLUABOX2D || LuaBox2D_EXPORTS) && defined _MSC_VER 18 | #define LIBLUABOX2D_DLL_EXPORTED __declspec(dllexport) 19 | #elif defined _MSC_VER 20 | #define LIBLUABOX2D_DLL_EXPORTED __declspec(dllimport) 21 | #else 22 | #define LIBLUABOX2D_DLL_EXPORTED 23 | #endif 24 | 25 | #endif -------------------------------------------------------------------------------- /src/main.hpp: -------------------------------------------------------------------------------- 1 | namespace LuaBox2D { 2 | int version(State & state); 3 | 4 | //function declarations to speed up building process 5 | void initTimer(State *); 6 | 7 | void initVec2(State *); 8 | void initRot(State *); 9 | void initTransform(State *); 10 | void initSweep(State *); 11 | 12 | void initWorld(State *); 13 | void initBody(State *); 14 | void initBodyDef(State *); 15 | void initJoint(State *); 16 | void initJointDef(State *); 17 | void initFixture(State *); 18 | void initFixtureDef(State *); 19 | 20 | void initShape(State *); 21 | void initCircleShape(State *); 22 | void initChainShape(State *); 23 | void initEdgeShape(State *); 24 | void initPolygonShape(State *); 25 | 26 | void initFilter(State *); 27 | void initRayCastInput(State *); 28 | void initRayCastOutput(State *); 29 | void initAABB(State *); 30 | void initMassData(State *); 31 | void initVertexArray(State *); 32 | void initContact(State *); 33 | void initManifold(State *); 34 | void initManifoldPoint(State *); 35 | void initContactID(State *); 36 | void initContactFeature(State *); 37 | void initWorldManifold(State *); 38 | void initContactListener(State *); 39 | void initContactImpulse(State *); 40 | void initContactManager(State *); 41 | void initContactFilter(State *); 42 | 43 | void initQueryCallback(State *); 44 | void initRayCastCallback(State *); 45 | 46 | void initJointEdge(State *); 47 | void initContactEdge(State *); 48 | 49 | void initRevoluteJoint(State *); 50 | void initPrismaticJoint(State *); 51 | void initDistanceJoint(State *); 52 | void initPulleyJoint(State *); 53 | void initMouseJoint(State *); 54 | void initGearJoint(State *); 55 | void initWheelJoint(State *); 56 | void initWeldJoint(State *); 57 | void initFrictionJoint(State *); 58 | void initRopeJoint(State *); 59 | void initMotorJoint(State *); 60 | 61 | void initRevoluteJointDef(State *); 62 | void initPrismaticJointDef(State *); 63 | void initDistanceJointDef(State *); 64 | void initPulleyJointDef(State *); 65 | void initMouseJointDef(State *); 66 | void initGearJointDef(State *); 67 | void initWheelJointDef(State *); 68 | void initWeldJointDef(State *); 69 | void initFrictionJointDef(State *); 70 | void initRopeJointDef(State *); 71 | void initMotorJointDef(State *); 72 | } 73 | 74 | extern "C" LIBLUABOX2D_DLL_EXPORTED int luaopen_LuaBox2D(lua_State * L); 75 | -------------------------------------------------------------------------------- /src/objects/AABB.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_AABB_H 2 | #define LUABOX2D_AABB_H 3 | 4 | namespace LuaBox2D { 5 | class AABB : public Object { 6 | public: 7 | explicit AABB(State * state) : Object(state){ 8 | LUTOK_PROPERTY("lowerBound", &AABB::getLowerBound, &AABB::setLowerBound); 9 | LUTOK_PROPERTY("upperBound", &AABB::getLowerBound, &AABB::setLowerBound); 10 | LUTOK_PROPERTY("valid", &AABB::getValid, &AABB::nullMethod); 11 | 12 | LUTOK_PROPERTY("center", &AABB::getCenter, &AABB::nullMethod); 13 | LUTOK_PROPERTY("extens", &AABB::getExtens, &AABB::nullMethod); 14 | LUTOK_PROPERTY("perimeter", &AABB::getPerimeter, &AABB::nullMethod); 15 | 16 | LUTOK_METHOD("combine", &AABB::combine); 17 | LUTOK_METHOD("contains", &AABB::contains); 18 | } 19 | 20 | b2AABB * constructor(State & state, bool & managed); 21 | 22 | void destructor(State & state, b2AABB * object); 23 | 24 | int getLowerBound(State & state, b2AABB * object); 25 | 26 | int setLowerBound(State & state, b2AABB * object); 27 | 28 | int getUpperBound(State & state, b2AABB * object); 29 | 30 | int setUpperBound(State & state, b2AABB * object); 31 | 32 | int getValid(State & state, b2AABB * object); 33 | 34 | int getCenter(State & state, b2AABB * object); 35 | 36 | int getExtens(State & state, b2AABB * object); 37 | 38 | int getPerimeter(State & state, b2AABB * object); 39 | 40 | int operator_add(State & state, b2AABB * a, b2AABB * b); 41 | 42 | int combine(State & state, b2AABB * object); 43 | 44 | int contains(State & state, b2AABB * object); 45 | 46 | int rayCast(State & state, b2AABB * object); 47 | 48 | }; 49 | 50 | void initAABB(State * ); 51 | }; 52 | 53 | #endif 54 | -------------------------------------------------------------------------------- /src/objects/ChainShape.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_CHAINSHAPE_H 2 | #define LUABOX2D_CHAINSHAPE_H 3 | 4 | namespace LuaBox2D { 5 | class ChainShape : public Object { 6 | private: 7 | Shape * base; 8 | public: 9 | explicit ChainShape(State * state) : Object(state){ 10 | base = state->getInterface("LuaBox2D_Shape"); 11 | LUTOK_PROPERTY("type", &ChainShape::getType, &ChainShape::nullMethod); 12 | LUTOK_METHOD("testPoint", &ChainShape::testPoint); 13 | LUTOK_METHOD("rayCast", &ChainShape::rayCast); 14 | LUTOK_METHOD("computeAABB", &ChainShape::computeAABB); 15 | LUTOK_METHOD("computeMass", &ChainShape::computeMass); 16 | 17 | LUTOK_METHOD("createLoop", &ChainShape::createLoop); 18 | LUTOK_METHOD("createChain", &ChainShape::createChain); 19 | LUTOK_METHOD("childEdge", &ChainShape::getChildEdge); 20 | LUTOK_METHOD("prevVertex", &ChainShape::setPrevVertex); 21 | LUTOK_METHOD("nextVertex", &ChainShape::setNextVertex); 22 | } 23 | 24 | b2ChainShape * constructor(State & state, bool & managed); 25 | 26 | void destructor(State & state, b2ChainShape * object); 27 | 28 | int getType(State & state, b2ChainShape * object); 29 | 30 | int getRadius(State & state, b2ChainShape * object); 31 | 32 | int setRadius(State & state, b2ChainShape * object); 33 | 34 | int testPoint(State & state, b2ChainShape * object); 35 | 36 | int rayCast(State & state, b2ChainShape * object); 37 | 38 | int computeAABB(State & state, b2ChainShape * object); 39 | 40 | int computeMass(State & state, b2ChainShape * object); 41 | 42 | int operator_len(State & state, b2ChainShape * object); 43 | 44 | int getChildEdge(State & state, b2ChainShape * object); 45 | 46 | int createLoop(State & state, b2ChainShape * object); 47 | 48 | int createChain(State & state, b2ChainShape * object); 49 | 50 | int setPrevVertex(State & state, b2ChainShape * object); 51 | 52 | int setNextVertex(State & state, b2ChainShape * object); 53 | }; 54 | 55 | void initChainShape(State * ); 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/objects/CircleShape.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_CIRCLESHAPE_H 2 | #define LUABOX2D_CIRCLESHAPE_H 3 | 4 | namespace LuaBox2D { 5 | class CircleShape : public Object { 6 | private: 7 | Shape * base; 8 | public: 9 | explicit CircleShape(State * state) : Object(state){ 10 | base = state->getInterface("LuaBox2D_Shape"); 11 | LUTOK_PROPERTY("type", &CircleShape::getType, &CircleShape::nullMethod); 12 | LUTOK_PROPERTY("radius", &CircleShape::getRadius, &CircleShape::setRadius); 13 | LUTOK_PROPERTY("m_p", &CircleShape::getMP, &CircleShape::setMP); 14 | LUTOK_METHOD("testPoint", &CircleShape::testPoint); 15 | LUTOK_METHOD("rayCast", &CircleShape::rayCast); 16 | LUTOK_METHOD("computeAABB", &CircleShape::computeAABB); 17 | LUTOK_METHOD("computeMass", &CircleShape::computeMass); 18 | 19 | LUTOK_METHOD("support", &CircleShape::support); 20 | LUTOK_METHOD("supportVertex", &CircleShape::supportVertex); 21 | LUTOK_METHOD("vertex", &CircleShape::vertex); 22 | LUTOK_METHOD("vertexCount", &CircleShape::vertex); 23 | } 24 | 25 | b2CircleShape * constructor(State & state, bool & managed); 26 | 27 | void destructor(State & state, b2CircleShape * object); 28 | 29 | int getType(State & state, b2CircleShape * object); 30 | 31 | int getRadius(State & state, b2CircleShape * object); 32 | 33 | int setRadius(State & state, b2CircleShape * object); 34 | 35 | int testPoint(State & state, b2CircleShape * object); 36 | 37 | int rayCast(State & state, b2CircleShape * object); 38 | 39 | int computeAABB(State & state, b2CircleShape * object); 40 | 41 | int computeMass(State & state, b2CircleShape * object); 42 | 43 | int getMP(State & state, b2CircleShape * object); 44 | 45 | int setMP(State & state, b2CircleShape * object); 46 | 47 | int operator_len(State & state, b2CircleShape * object); 48 | 49 | int support(State & state, b2CircleShape * object); 50 | 51 | int supportVertex(State & state, b2CircleShape * object); 52 | 53 | int vertex(State & state, b2CircleShape * object); 54 | 55 | int vertexCount(State & state, b2CircleShape * object); 56 | }; 57 | 58 | void initCircleShape(State * ); 59 | }; 60 | 61 | #endif 62 | -------------------------------------------------------------------------------- /src/objects/ContactEdge.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/Body.hpp" 3 | #include "objects/Contact.hpp" 4 | #include "objects/ContactEdge.hpp" 5 | 6 | namespace LuaBox2D { 7 | void initContactEdge(State * state){ 8 | state->registerInterface("LuaBox2D_ContactEdge"); 9 | } 10 | 11 | b2ContactEdge * ContactEdge::constructor(State & state, bool & managed){ 12 | LUTOK2_NOT_USED(managed); 13 | b2ContactEdge * object = new b2ContactEdge(); 14 | 15 | object->contact = nullptr; 16 | object->other = nullptr; 17 | object->next = nullptr; 18 | object->prev = nullptr; 19 | 20 | return object; 21 | } 22 | 23 | void ContactEdge::destructor(State & state, b2ContactEdge * object){ 24 | delete object; 25 | } 26 | 27 | int ContactEdge::getOther(State & state, b2ContactEdge * object){ 28 | Body * interfaceBody = state.getInterface("LuaBox2D_Body"); 29 | if (object->other){ 30 | interfaceBody->push(object->other, false); 31 | return 1; 32 | }else{ 33 | return 0; 34 | } 35 | } 36 | 37 | int ContactEdge::getContact(State & state, b2ContactEdge * object){ 38 | Contact * interfaceContact = state.getInterface("LuaBox2D_Contact"); 39 | if (object->contact){ 40 | interfaceContact->push(object->contact, false); 41 | return 1; 42 | }else{ 43 | return 0; 44 | } 45 | } 46 | 47 | int ContactEdge::getPrev(State & state, b2ContactEdge * object){ 48 | ContactEdge * interfaceContactEdge = state.getInterface("LuaBox2D_ContactEdge"); 49 | if (object->prev){ 50 | interfaceContactEdge->push(object->prev, false); 51 | return 1; 52 | }else{ 53 | return 0; 54 | } 55 | } 56 | 57 | int ContactEdge::getNext(State & state, b2ContactEdge * object){ 58 | ContactEdge * interfaceContactEdge = state.getInterface("LuaBox2D_ContactEdge"); 59 | if (object->next){ 60 | interfaceContactEdge->push(object->next, false); 61 | return 1; 62 | }else{ 63 | return 0; 64 | } 65 | } 66 | }; 67 | -------------------------------------------------------------------------------- /src/objects/ContactEdge.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_CONTACTEDGE_H 2 | #define LUABOX2D_CONTACTEDGE_H 3 | 4 | namespace LuaBox2D { 5 | class ContactEdge : public Object { 6 | public: 7 | explicit ContactEdge(State * state) : Object(state){ 8 | LUTOK_PROPERTY("other", &ContactEdge::getOther, &ContactEdge::nullMethod); 9 | LUTOK_PROPERTY("contact", &ContactEdge::getContact, &ContactEdge::nullMethod); 10 | LUTOK_PROPERTY("prev", &ContactEdge::getPrev, &ContactEdge::nullMethod); 11 | LUTOK_PROPERTY("next", &ContactEdge::getNext, &ContactEdge::nullMethod); 12 | } 13 | 14 | b2ContactEdge * constructor(State & state, bool & managed); 15 | 16 | void destructor(State & state, b2ContactEdge * object); 17 | 18 | int getOther(State & state, b2ContactEdge * object); 19 | int getContact(State & state, b2ContactEdge * object); 20 | int getPrev(State & state, b2ContactEdge * object); 21 | int getNext(State & state, b2ContactEdge * object); 22 | 23 | }; 24 | 25 | void initContactEdge(State * ); 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/objects/ContactFeature.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/ContactFeature.hpp" 3 | 4 | namespace LuaBox2D { 5 | void initContactFeature(State * state){ 6 | state->registerInterface("LuaBox2D_ContactFeature"); 7 | } 8 | 9 | b2ContactFeature * ContactFeature::constructor(State & state, bool & managed){ 10 | LUTOK2_NOT_USED(managed); 11 | return new b2ContactFeature(); 12 | } 13 | 14 | void ContactFeature::destructor(State & state, b2ContactFeature * object){ 15 | delete object; 16 | } 17 | 18 | 19 | int ContactFeature::getIndexA(State & state, b2ContactFeature * object){ 20 | state.stack->push(static_cast(object->indexA)); 21 | return 1; 22 | } 23 | 24 | int ContactFeature::setIndexA(State & state, b2ContactFeature * object){ 25 | object->indexA = static_cast(state.stack->to(1)); 26 | return 0; 27 | } 28 | 29 | int ContactFeature::getIndexB(State & state, b2ContactFeature * object){ 30 | state.stack->push(static_cast(object->indexB)); 31 | return 1; 32 | } 33 | 34 | int ContactFeature::setIndexB(State & state, b2ContactFeature * object){ 35 | object->indexB = static_cast(state.stack->to(1)); 36 | return 0; 37 | } 38 | 39 | int ContactFeature::getTypeA(State & state, b2ContactFeature * object){ 40 | state.stack->push(static_cast(object->typeA)); 41 | return 1; 42 | } 43 | 44 | int ContactFeature::setTypeA(State & state, b2ContactFeature * object){ 45 | object->typeA = static_cast(state.stack->to(1)); 46 | return 0; 47 | } 48 | 49 | int ContactFeature::getTypeB(State & state, b2ContactFeature * object){ 50 | state.stack->push(static_cast(object->typeB)); 51 | return 1; 52 | } 53 | 54 | int ContactFeature::setTypeB(State & state, b2ContactFeature * object){ 55 | object->typeB = static_cast(state.stack->to(1)); 56 | return 0; 57 | } 58 | }; 59 | -------------------------------------------------------------------------------- /src/objects/ContactFeature.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_CONTACTFEATURE_H 2 | #define LUABOX2D_CONTACTFEATURE_H 3 | 4 | namespace LuaBox2D { 5 | class ContactFeature : public Object { 6 | public: 7 | explicit ContactFeature(State * state) : Object(state){ 8 | LUTOK_PROPERTY("indexA", &ContactFeature::getIndexA, &ContactFeature::setIndexA); 9 | LUTOK_PROPERTY("indexB", &ContactFeature::getIndexB, &ContactFeature::setIndexB); 10 | LUTOK_PROPERTY("typeA", &ContactFeature::getTypeA, &ContactFeature::setTypeA); 11 | LUTOK_PROPERTY("typeB", &ContactFeature::getTypeB, &ContactFeature::setTypeB); 12 | } 13 | 14 | b2ContactFeature * constructor(State & state, bool & managed); 15 | 16 | void destructor(State & state, b2ContactFeature * object); 17 | 18 | int getIndexA(State & state, b2ContactFeature * object); 19 | 20 | int setIndexA(State & state, b2ContactFeature * object); 21 | 22 | int getIndexB(State & state, b2ContactFeature * object); 23 | 24 | int setIndexB(State & state, b2ContactFeature * object); 25 | 26 | int getTypeA(State & state, b2ContactFeature * object); 27 | 28 | int setTypeA(State & state, b2ContactFeature * object); 29 | 30 | int getTypeB(State & state, b2ContactFeature * object); 31 | 32 | int setTypeB(State & state, b2ContactFeature * object); 33 | }; 34 | 35 | void initContactFeature(State * ); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/objects/ContactFilter.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/ContactFilter.hpp" 3 | #include "objects/Fixture.hpp" 4 | 5 | namespace LuaBox2D { 6 | void initContactFilter(State * state){ 7 | state->registerInterface("LuaBox2D_ContactFilter"); 8 | } 9 | 10 | inline bool LuaBox2DContactFilter::getCallBack(int ref){ 11 | if (ref != LUA_NOREF){ 12 | state->stack->regValue(ref); 13 | return true; 14 | }else{ 15 | return false; 16 | } 17 | } 18 | 19 | bool LuaBox2DContactFilter::ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB){ 20 | if (getCallBack(refShouldCollide)){ 21 | Fixture * interfaceFixture = state->getInterface("LuaBox2D_Fixture"); 22 | interfaceFixture->push(fixtureA, false); 23 | interfaceFixture->push(fixtureB, false); 24 | state->stack->call(2, 1); 25 | bool retVal = state->stack->to(); 26 | state->stack->pop(1); 27 | return retVal; 28 | }else{ 29 | return false; 30 | } 31 | } 32 | 33 | LuaBox2DContactFilter::~LuaBox2DContactFilter(){ 34 | if (refShouldCollide != LUA_NOREF){ 35 | state->stack->unref(refShouldCollide); 36 | } 37 | } 38 | 39 | LuaBox2DContactFilter * ContactFilter::constructor(State & state, bool & managed){ 40 | LUTOK2_NOT_USED(managed); 41 | return new LuaBox2DContactFilter(&state); 42 | } 43 | 44 | void ContactFilter::destructor(State & state, LuaBox2DContactFilter * object){ 45 | delete object; 46 | } 47 | 48 | int ContactFilter::getShouldCollide(State & state, LuaBox2DContactFilter * object){ 49 | if (object->refShouldCollide != LUA_NOREF){ 50 | state.stack->rawGet(object->refShouldCollide, LUA_REGISTRYINDEX); 51 | return 1; 52 | }else{ 53 | return 0; 54 | } 55 | } 56 | 57 | int ContactFilter::setShouldCollide(State & state, LuaBox2DContactFilter * object){ 58 | if (state.stack->is(1)){ 59 | if (object->refShouldCollide != LUA_NOREF){ 60 | state.stack->unref(object->refShouldCollide); 61 | } 62 | state.stack->pushValue(1); 63 | object->refShouldCollide = state.stack->ref(); 64 | }else{ 65 | if (state.stack->is(1)){ 66 | if (object->refShouldCollide != LUA_NOREF){ 67 | state.stack->unref(object->refShouldCollide); 68 | object->refShouldCollide = LUA_NOREF; 69 | } 70 | } 71 | } 72 | return 0; 73 | } 74 | }; 75 | -------------------------------------------------------------------------------- /src/objects/ContactFilter.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_CONTACTFILTER_H 2 | #define LUABOX2D_CONTACTFILTER_H 3 | 4 | namespace LuaBox2D { 5 | class LuaBox2DContactFilter : public b2ContactFilter { 6 | private: 7 | State * state; 8 | public: 9 | LuaBox2DContactFilter(State * state) : b2ContactFilter(){ 10 | this->state = state; 11 | refShouldCollide = LUA_NOREF; 12 | } 13 | ~LuaBox2DContactFilter(); 14 | 15 | bool ShouldCollide(b2Fixture* fixtureA, b2Fixture* fixtureB); 16 | 17 | bool getCallBack(int ref); 18 | 19 | int refShouldCollide; 20 | 21 | }; 22 | 23 | class ContactFilter : public Object { 24 | public: 25 | explicit ContactFilter(State * state) : Object(state){ 26 | LUTOK_PROPERTY("shouldCollide", &ContactFilter::getShouldCollide, &ContactFilter::setShouldCollide); 27 | } 28 | 29 | LuaBox2DContactFilter * constructor(State & state, bool & managed); 30 | 31 | void destructor(State & state, LuaBox2DContactFilter * object); 32 | 33 | int getShouldCollide(State & state, LuaBox2DContactFilter * object); 34 | 35 | int setShouldCollide(State & state, LuaBox2DContactFilter * object); 36 | }; 37 | 38 | void initContactFilter(State * ); 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/objects/ContactID.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/ContactID.hpp" 3 | #include "objects/ContactFeature.hpp" 4 | 5 | namespace LuaBox2D { 6 | void initContactID(State * state){ 7 | state->registerInterface("LuaBox2D_ContactID"); 8 | } 9 | 10 | b2ContactID * ContactID::constructor(State & state, bool & managed){ 11 | LUTOK2_NOT_USED(managed); 12 | return new b2ContactID(); 13 | } 14 | 15 | void ContactID::destructor(State & state, b2ContactID * object){ 16 | delete object; 17 | } 18 | 19 | int ContactID::getContactFeature(State & state, b2ContactID * object){ 20 | ContactFeature * interfaceContactFeature = state.getInterface("LuaBox2D_ContactFeature"); 21 | interfaceContactFeature->push(& object->cf, false); 22 | return 1; 23 | } 24 | 25 | int ContactID::setContactFeature(State & state, b2ContactID * object){ 26 | ContactFeature * interfaceContactFeature = state.getInterface("LuaBox2D_ContactFeature"); 27 | b2ContactFeature * cf = interfaceContactFeature->get(1); 28 | if (cf != nullptr){ 29 | object->cf = *cf; 30 | } 31 | return 0; 32 | } 33 | 34 | int ContactID::getKey(State & state, b2ContactID * object){ 35 | state.stack->push(static_cast(object->key)); 36 | return 1; 37 | } 38 | 39 | int ContactID::setKey(State & state, b2ContactID * object){ 40 | object->key = static_cast(state.stack->to(1)); 41 | return 0; 42 | } 43 | }; 44 | -------------------------------------------------------------------------------- /src/objects/ContactID.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_CONTACTID_H 2 | #define LUABOX2D_CONTACTID_H 3 | 4 | namespace LuaBox2D { 5 | class ContactID : public Object { 6 | public: 7 | explicit ContactID(State * state) : Object(state){ 8 | LUTOK_PROPERTY("cf", &ContactID::getContactFeature, &ContactID::setContactFeature); 9 | LUTOK_PROPERTY("key", &ContactID::getKey, &ContactID::setKey); 10 | } 11 | 12 | b2ContactID * constructor(State & state, bool & managed); 13 | 14 | void destructor(State & state, b2ContactID * object); 15 | 16 | int getContactFeature(State & state, b2ContactID * object); 17 | 18 | int setContactFeature(State & state, b2ContactID * object); 19 | 20 | int getKey(State & state, b2ContactID * object); 21 | 22 | int setKey(State & state, b2ContactID * object); 23 | }; 24 | 25 | void initContactID(State * ); 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/objects/ContactImpulse.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/ContactImpulse.hpp" 3 | 4 | namespace LuaBox2D { 5 | void initContactImpulse(State * state){ 6 | state->registerInterface("LuaBox2D_ContactImpulse"); 7 | } 8 | 9 | b2ContactImpulse * ContactImpulse::constructor(State & state, bool & managed){ 10 | LUTOK2_NOT_USED(managed); 11 | return nullptr; 12 | } 13 | 14 | void ContactImpulse::destructor(State & state, b2ContactImpulse * object){ 15 | delete object; 16 | } 17 | 18 | 19 | int ContactImpulse::operator_len(State & state, b2ContactImpulse * object){ 20 | state.stack->push(static_cast(object->count)); 21 | return 1; 22 | } 23 | 24 | int ContactImpulse::getNormalImpulse(State & state, b2ContactImpulse * object){ 25 | int index = state.stack->to(1) - 1; 26 | if (index>=0 && indexcount && indexpush( static_cast(object->normalImpulses[index]) ); 28 | return 1; 29 | }else{ 30 | return 0; 31 | } 32 | } 33 | 34 | int ContactImpulse::setNormalImpulse(State & state, b2ContactImpulse * object){ 35 | int index = state.stack->to(1) - 1; 36 | if (index>=0 && indexis(2)){ 38 | object->normalImpulses[index] = static_cast(state.stack->to(2)); 39 | } 40 | } 41 | return 0; 42 | } 43 | 44 | int ContactImpulse::getTangentImpulse(State & state, b2ContactImpulse * object){ 45 | int index = state.stack->to(1) - 1; 46 | if (index>=0 && indexcount && indexpush( static_cast(object->tangentImpulses[index]) ); 48 | return 1; 49 | }else{ 50 | return 0; 51 | } 52 | } 53 | 54 | int ContactImpulse::setTangentImpulse(State & state, b2ContactImpulse * object){ 55 | int index = state.stack->to(1) - 1; 56 | if (index>=0 && indexis(2)){ 58 | object->tangentImpulses[index] = static_cast(state.stack->to(2)); 59 | } 60 | } 61 | return 0; 62 | } 63 | }; 64 | -------------------------------------------------------------------------------- /src/objects/ContactImpulse.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_CONTACTIMPULSE_H 2 | #define LUABOX2D_CONTACTIMPULSE_H 3 | 4 | namespace LuaBox2D { 5 | class ContactImpulse : public Object { 6 | public: 7 | explicit ContactImpulse(State * state) : Object(state){ 8 | LUTOK_METHOD("getNormalImpulse", &ContactImpulse::getNormalImpulse); 9 | LUTOK_METHOD("setNormalImpulse", &ContactImpulse::setNormalImpulse); 10 | LUTOK_METHOD("getTangentImpulse", &ContactImpulse::getTangentImpulse); 11 | LUTOK_METHOD("setTangentImpulse", &ContactImpulse::setTangentImpulse); 12 | } 13 | 14 | b2ContactImpulse * constructor(State & state, bool & managed); 15 | 16 | void destructor(State & state, b2ContactImpulse * object); 17 | 18 | int operator_len(State & state, b2ContactImpulse * object); 19 | 20 | int getNormalImpulse(State & state, b2ContactImpulse * object); 21 | 22 | int setNormalImpulse(State & state, b2ContactImpulse * object); 23 | 24 | int getTangentImpulse(State & state, b2ContactImpulse * object); 25 | 26 | int setTangentImpulse(State & state, b2ContactImpulse * object); 27 | }; 28 | 29 | void initContactImpulse(State * ); 30 | }; 31 | 32 | #endif 33 | -------------------------------------------------------------------------------- /src/objects/ContactListener.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_CONTACTLISTENER_H 2 | #define LUABOX2D_CONTACTLISTENER_H 3 | 4 | namespace LuaBox2D { 5 | class LuaBox2DContactListener : public b2ContactListener { 6 | private: 7 | State * state; 8 | public: 9 | LuaBox2DContactListener(State * state) : b2ContactListener(){ 10 | this->state = state; 11 | refBeginContact = LUA_NOREF; 12 | refEndContact = LUA_NOREF; 13 | refPreSolve = LUA_NOREF; 14 | refPostSolve = LUA_NOREF; 15 | } 16 | ~LuaBox2DContactListener(); 17 | 18 | void BeginContact(b2Contact* contact); 19 | void EndContact(b2Contact* contact); 20 | void PreSolve(b2Contact* contact, const b2Manifold* oldManifold); 21 | void PostSolve(b2Contact* contact, const b2ContactImpulse* impulse); 22 | 23 | bool getCallBack(int ref); 24 | 25 | int refBeginContact; 26 | int refEndContact; 27 | int refPreSolve; 28 | int refPostSolve; 29 | }; 30 | 31 | class ContactListener : public Object { 32 | public: 33 | explicit ContactListener(State * state) : Object(state){ 34 | LUTOK_PROPERTY("beginContact", &ContactListener::getBeginContact, &ContactListener::setBeginContact); 35 | LUTOK_PROPERTY("endContact", &ContactListener::getEndContact, &ContactListener::setEndContact); 36 | LUTOK_PROPERTY("preSolve", &ContactListener::getPreSolve, &ContactListener::setPreSolve); 37 | LUTOK_PROPERTY("postSolve", &ContactListener::getPostSolve, &ContactListener::setPostSolve); 38 | } 39 | 40 | LuaBox2DContactListener * constructor(State & state, bool & managed); 41 | 42 | void destructor(State & state, LuaBox2DContactListener * object); 43 | 44 | int getBeginContact(State & state, LuaBox2DContactListener * object); 45 | 46 | int setBeginContact(State & state, LuaBox2DContactListener * object); 47 | 48 | int getEndContact(State & state, LuaBox2DContactListener * object); 49 | 50 | int setEndContact(State & state, LuaBox2DContactListener * object); 51 | 52 | int getPreSolve(State & state, LuaBox2DContactListener * object); 53 | 54 | int setPreSolve(State & state, LuaBox2DContactListener * object); 55 | 56 | int getPostSolve(State & state, LuaBox2DContactListener * object); 57 | 58 | int setPostSolve(State & state, LuaBox2DContactListener * object); 59 | }; 60 | 61 | void initContactListener(State * ); 62 | }; 63 | 64 | #endif 65 | -------------------------------------------------------------------------------- /src/objects/ContactManager.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/ContactManager.hpp" 3 | #include "objects/ContactListener.hpp" 4 | #include "objects/ContactFilter.hpp" 5 | 6 | namespace LuaBox2D { 7 | void initContactManager(State * state){ 8 | state->registerInterface("LuaBox2D_ContactManager"); 9 | } 10 | 11 | b2ContactManager * ContactManager::constructor(State & state, bool & managed){ 12 | LUTOK2_NOT_USED(managed); 13 | return new b2ContactManager(); 14 | } 15 | 16 | void ContactManager::destructor(State & state, b2ContactManager * object){ 17 | delete object; 18 | } 19 | 20 | int ContactManager::getContactListener(State & state, b2ContactManager * object){ 21 | ContactListener * interfaceContactListener = state.getInterface("LuaBox2D_ContactListener"); 22 | interfaceContactListener->push( dynamic_cast(object->m_contactListener), false); 23 | return 1; 24 | } 25 | 26 | int ContactManager::setContactListener(State & state, b2ContactManager * object){ 27 | ContactListener * interfaceContactListener = state.getInterface("LuaBox2D_ContactListener"); 28 | LuaBox2DContactListener * listener = interfaceContactListener->get(1); 29 | if (listener != nullptr){ 30 | object->m_contactListener = listener; 31 | } 32 | return 0; 33 | } 34 | 35 | int ContactManager::getContactFilter(State & state, b2ContactManager * object){ 36 | ContactFilter * interfaceContactFilter = state.getInterface("LuaBox2D_ContactFilter"); 37 | interfaceContactFilter->push( dynamic_cast(object->m_contactFilter), false); 38 | return 1; 39 | } 40 | 41 | int ContactManager::setContactFilter(State & state, b2ContactManager * object){ 42 | ContactFilter * interfaceContactFilter = state.getInterface("LuaBox2D_ContactFilter"); 43 | LuaBox2DContactFilter * filter = interfaceContactFilter->get(1); 44 | if (filter != nullptr){ 45 | object->m_contactFilter = filter; 46 | } 47 | return 0; 48 | } 49 | }; 50 | -------------------------------------------------------------------------------- /src/objects/ContactManager.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_CONTACTMANAGER_H 2 | #define LUABOX2D_CONTACTMANAGER_H 3 | 4 | namespace LuaBox2D { 5 | class ContactManager : public Object { 6 | public: 7 | explicit ContactManager(State * state) : Object(state){ 8 | LUTOK_PROPERTY("contactListener", &ContactManager::getContactListener, &ContactManager::setContactListener); 9 | LUTOK_PROPERTY("contactFilter", &ContactManager::getContactFilter, &ContactManager::setContactFilter); 10 | } 11 | 12 | b2ContactManager * constructor(State & state, bool & managed); 13 | 14 | void destructor(State & state, b2ContactManager * object); 15 | 16 | int getContactListener(State & state, b2ContactManager * object); 17 | 18 | int setContactListener(State & state, b2ContactManager * object); 19 | 20 | int getContactFilter(State & state, b2ContactManager * object); 21 | 22 | int setContactFilter(State & state, b2ContactManager * object); 23 | 24 | }; 25 | 26 | void initContactManager(State * ); 27 | }; 28 | 29 | #endif 30 | -------------------------------------------------------------------------------- /src/objects/Filter.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/Filter.hpp" 3 | 4 | namespace LuaBox2D { 5 | void initFilter(State * state){ 6 | state->registerInterface("LuaBox2D_Filter"); 7 | 8 | } 9 | 10 | b2Filter * Filter::constructor(State & state, bool & managed){ 11 | LUTOK2_NOT_USED(managed); 12 | return new b2Filter(); 13 | } 14 | 15 | void Filter::destructor(State & state, b2Filter * object){ 16 | delete object; 17 | } 18 | 19 | int Filter::getCategoryBits(State & state, b2Filter * object){ 20 | state.stack->push(static_cast(object->categoryBits)); 21 | return 1; 22 | } 23 | 24 | int Filter::setCategoryBits(State & state, b2Filter * object){ 25 | object->categoryBits = static_cast(state.stack->to(1)); 26 | return 0; 27 | } 28 | 29 | int Filter::getMaskBits(State & state, b2Filter * object){ 30 | state.stack->push(static_cast(object->maskBits)); 31 | return 1; 32 | } 33 | 34 | int Filter::setMaskBits(State & state, b2Filter * object){ 35 | object->maskBits = static_cast(state.stack->to(1)); 36 | return 0; 37 | } 38 | 39 | int Filter::getGroupIndex(State & state, b2Filter * object){ 40 | state.stack->push(static_cast(object->groupIndex)); 41 | return 1; 42 | } 43 | 44 | int Filter::setGroupIndex(State & state, b2Filter * object){ 45 | object->groupIndex = static_cast(state.stack->to(1)); 46 | return 0; 47 | } 48 | }; 49 | -------------------------------------------------------------------------------- /src/objects/Filter.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_FILTER_H 2 | #define LUABOX2D_FILTER_H 3 | 4 | namespace LuaBox2D { 5 | class Filter : public Object { 6 | public: 7 | explicit Filter(State * state) : Object(state){ 8 | LUTOK_PROPERTY("categoryBits", &Filter::getCategoryBits, &Filter::setCategoryBits); 9 | LUTOK_PROPERTY("maskBits", &Filter::getMaskBits, &Filter::setMaskBits); 10 | LUTOK_PROPERTY("groupIndex", &Filter::getGroupIndex, &Filter::setGroupIndex); 11 | } 12 | 13 | b2Filter * constructor(State & state, bool & managed); 14 | 15 | void destructor(State & state, b2Filter * object); 16 | 17 | int getCategoryBits(State & state, b2Filter * object); 18 | 19 | int setCategoryBits(State & state, b2Filter * object); 20 | 21 | int getMaskBits(State & state, b2Filter * object); 22 | 23 | int setMaskBits(State & state, b2Filter * object); 24 | 25 | int getGroupIndex(State & state, b2Filter * object); 26 | 27 | int setGroupIndex(State & state, b2Filter * object); 28 | }; 29 | 30 | void initFilter(State * ); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/objects/FixtureDef.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_FIXTUREDEF_H 2 | #define LUABOX2D_FIXTUREDEF_H 3 | 4 | namespace LuaBox2D { 5 | class FixtureDef : public Object { 6 | public: 7 | explicit FixtureDef(State * state) : Object(state){ 8 | LUTOK_PROPERTY("friction", &FixtureDef::getFriction, &FixtureDef::setFriction); 9 | LUTOK_PROPERTY("restitution", &FixtureDef::getRestitution, &FixtureDef::setRestitution); 10 | LUTOK_PROPERTY("density", &FixtureDef::getDensity, &FixtureDef::setDensity); 11 | LUTOK_PROPERTY("sensor", &FixtureDef::getSensor, &FixtureDef::setSensor); 12 | LUTOK_PROPERTY("filter", &FixtureDef::getFilter, &FixtureDef::setFilter); 13 | LUTOK_PROPERTY("shape", &FixtureDef::getShape, &FixtureDef::setShape); 14 | 15 | LUTOK_PROPERTY("userData", &FixtureDef::getUserData, &FixtureDef::setUserData); 16 | } 17 | 18 | b2FixtureDef * constructor(State & state, bool & managed); 19 | 20 | void destructor(State & state, b2FixtureDef * object); 21 | 22 | int getFriction(State & state, b2FixtureDef * object); 23 | 24 | int setFriction(State & state, b2FixtureDef * object); 25 | 26 | int getRestitution(State & state, b2FixtureDef * object); 27 | 28 | int setRestitution(State & state, b2FixtureDef * object); 29 | 30 | int getDensity(State & state, b2FixtureDef * object); 31 | 32 | int setDensity(State & state, b2FixtureDef * object); 33 | 34 | int getSensor(State & state, b2FixtureDef * object); 35 | 36 | int setSensor(State & state, b2FixtureDef * object); 37 | 38 | int getFilter(State & state, b2FixtureDef * object); 39 | 40 | int setFilter(State & state, b2FixtureDef * object); 41 | 42 | int getShape(State & state, b2FixtureDef * object); 43 | 44 | int setShape(State & state, b2FixtureDef * object); 45 | 46 | int getUserData(State & state, b2FixtureDef * object); 47 | 48 | int setUserData(State & state, b2FixtureDef * object); 49 | 50 | }; 51 | 52 | void initFixtureDef(State * ); 53 | 54 | }; 55 | 56 | #endif -------------------------------------------------------------------------------- /src/objects/GearJointDef.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_GEARJOINTDEF_H 2 | #define LUABOX2D_GEARJOINTDEF_H 3 | 4 | namespace LuaBox2D { 5 | class GearJointDef : public Object { 6 | private: 7 | JointDef * base; 8 | public: 9 | explicit GearJointDef(State * state) : Object(state){ 10 | base = state->getInterface("LuaBox2D_JointDef"); 11 | LUTOK_PROPERTY("type", &GearJointDef::getType, &GearJointDef::setType); 12 | LUTOK_PROPERTY("bodyA", &GearJointDef::getBodyA, &GearJointDef::setBodyA); 13 | LUTOK_PROPERTY("bodyB", &GearJointDef::getBodyB, &GearJointDef::setBodyB); 14 | LUTOK_PROPERTY("collideConnected", &GearJointDef::getCollideConnected, &GearJointDef::setCollideConnected); 15 | 16 | LUTOK_PROPERTY("joint1", &GearJointDef::getJoint1, &GearJointDef::setJoint1); 17 | LUTOK_PROPERTY("joint2", &GearJointDef::getJoint2, &GearJointDef::setJoint2); 18 | LUTOK_PROPERTY("ratio", &GearJointDef::getRatio, &GearJointDef::setRatio); 19 | LUTOK_PROPERTY("userData", &GearJointDef::getUserData, &GearJointDef::setUserData); 20 | } 21 | 22 | b2GearJointDef * constructor(State & state, bool & managed); 23 | 24 | void destructor(State & state, b2GearJointDef * object); 25 | 26 | int getBodyA(State & state, b2GearJointDef * ); 27 | 28 | int setBodyA(State & state, b2GearJointDef * ); 29 | 30 | int getBodyB(State & state, b2GearJointDef * ); 31 | 32 | int setBodyB(State & state, b2GearJointDef * ); 33 | 34 | int getType(State & state, b2GearJointDef * ); 35 | 36 | int setType(State & state, b2GearJointDef * ); 37 | 38 | int getCollideConnected(State & state, b2GearJointDef * ); 39 | 40 | int setCollideConnected(State & state, b2GearJointDef * ); 41 | 42 | int getJoint1(State & state, b2GearJointDef * object); 43 | 44 | int setJoint1(State & state, b2GearJointDef * object); 45 | 46 | int getJoint2(State & state, b2GearJointDef * object); 47 | 48 | int setJoint2(State & state, b2GearJointDef * object); 49 | 50 | int getRatio(State & state, b2GearJointDef * object); 51 | 52 | int setRatio(State & state, b2GearJointDef * object); 53 | 54 | int getUserData(State & state, b2GearJointDef * object); 55 | 56 | int setUserData(State & state, b2GearJointDef * object); 57 | }; 58 | 59 | void initGearJointDef(State * ); 60 | }; 61 | 62 | #endif 63 | -------------------------------------------------------------------------------- /src/objects/Joint.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_JOINT_H 2 | #define LUABOX2D_JOINT_H 3 | 4 | namespace LuaBox2D { 5 | class Joint : public Object { 6 | protected: 7 | std::forward_list validTypes; 8 | public: 9 | explicit Joint(State * state) : Object(state){ 10 | LUTOK_PROPERTY("type", &Joint::getType, &Joint::nullMethod); 11 | LUTOK_PROPERTY("bodyA", &Joint::getBodyA, &Joint::nullMethod); 12 | LUTOK_PROPERTY("bodyB", &Joint::getBodyB, &Joint::nullMethod); 13 | 14 | LUTOK_PROPERTY("anchorA", &Joint::getAnchorA, &Joint::nullMethod); 15 | LUTOK_PROPERTY("anchorB", &Joint::getAnchorB, &Joint::nullMethod); 16 | 17 | LUTOK_METHOD("reactionForce", &Joint::getReactionForce); 18 | LUTOK_METHOD("reactionTorque", &Joint::getReactionTorque); 19 | 20 | LUTOK_PROPERTY("active", &Joint::getActive, &Joint::nullMethod); 21 | LUTOK_PROPERTY("collideConnected", &Joint::getCollideConnected, &Joint::nullMethod); 22 | 23 | LUTOK_PROPERTY("next", &Joint::getNext, &Joint::nullMethod); 24 | LUTOK_PROPERTY("userData", &Joint::getUserData, &Joint::setUserData); 25 | 26 | initAllowedTypes(); 27 | } 28 | 29 | void initAllowedTypes(); 30 | 31 | b2Joint * constructor(State & state, bool & managed); 32 | 33 | b2Joint * get(const int index); 34 | 35 | void destructor(State & state, b2Joint * object); 36 | 37 | int getType(State & state, b2Joint * object); 38 | 39 | int getBodyA(State & state, b2Joint *); 40 | 41 | int getBodyB(State & state, b2Joint *); 42 | 43 | int getAnchorA(State & state, b2Joint *); 44 | 45 | int getAnchorB(State & state, b2Joint *); 46 | 47 | int getReactionForce(State & state, b2Joint *); 48 | 49 | int getReactionTorque(State & state, b2Joint *); 50 | 51 | int getActive(State & state, b2Joint * object); 52 | 53 | int getCollideConnected(State & state, b2Joint * object); 54 | 55 | int getNext(State & state, b2Joint * object); 56 | 57 | int getUserData(State & state, b2Joint * object); 58 | 59 | int setUserData(State & state, b2Joint * object); 60 | 61 | }; 62 | 63 | void initJoint(State * ); 64 | }; 65 | 66 | #endif 67 | -------------------------------------------------------------------------------- /src/objects/JointDef.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_JOINTDEF_H 2 | #define LUABOX2D_JOINTDEF_H 3 | 4 | namespace LuaBox2D { 5 | class JointDef : public Object { 6 | protected: 7 | std::forward_list validTypes; 8 | public: 9 | explicit JointDef(State * state) : Object(state){ 10 | LUTOK_PROPERTY("type", &JointDef::getType, &JointDef::setType); 11 | LUTOK_PROPERTY("bodyA", &JointDef::getBodyA, &JointDef::setBodyA); 12 | LUTOK_PROPERTY("bodyB", &JointDef::getBodyB, &JointDef::setBodyB); 13 | LUTOK_PROPERTY("collideConnected", &JointDef::getCollideConnected, &JointDef::setCollideConnected); 14 | LUTOK_PROPERTY("userData", &JointDef::getUserData, &JointDef::setUserData); 15 | 16 | initAllowedTypes(); 17 | } 18 | 19 | void initAllowedTypes(); 20 | 21 | b2JointDef * constructor(State & state, bool &); 22 | 23 | void destructor(State & state, b2JointDef * object); 24 | 25 | b2JointDef * get(const int index); 26 | 27 | int getBodyA(State & state, b2JointDef *); 28 | 29 | int setBodyA(State & state, b2JointDef *); 30 | 31 | int getBodyB(State & state, b2JointDef *); 32 | 33 | int setBodyB(State & state, b2JointDef *); 34 | 35 | int getType(State & state, b2JointDef * object); 36 | 37 | int setType(State & state, b2JointDef * object); 38 | 39 | int getCollideConnected(State & state, b2JointDef * object); 40 | 41 | int setCollideConnected(State & state, b2JointDef * object); 42 | 43 | int getUserData(State & state, b2JointDef * object); 44 | 45 | int setUserData(State & state, b2JointDef * object); 46 | }; 47 | 48 | void initJointDef(State * ); 49 | }; 50 | 51 | #endif 52 | -------------------------------------------------------------------------------- /src/objects/JointEdge.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/Body.hpp" 3 | #include "objects/Joint.hpp" 4 | #include "objects/JointEdge.hpp" 5 | 6 | namespace LuaBox2D { 7 | void initJointEdge(State * state){ 8 | state->registerInterface("LuaBox2D_JointEdge"); 9 | } 10 | 11 | b2JointEdge * JointEdge::constructor(State & state, bool & managed){ 12 | LUTOK2_NOT_USED(managed); 13 | b2JointEdge * object = new b2JointEdge(); 14 | 15 | object->joint = nullptr; 16 | object->other = nullptr; 17 | object->next = nullptr; 18 | object->prev = nullptr; 19 | 20 | return object; 21 | } 22 | 23 | void JointEdge::destructor(State & state, b2JointEdge * object){ 24 | delete object; 25 | } 26 | 27 | int JointEdge::getOther(State & state, b2JointEdge * object){ 28 | Body * interfaceBody = state.getInterface("LuaBox2D_Body"); 29 | if (object->other){ 30 | interfaceBody->push(object->other, false); 31 | return 1; 32 | }else{ 33 | return 0; 34 | } 35 | } 36 | 37 | int JointEdge::getJoint(State & state, b2JointEdge * object){ 38 | Joint * interfaceJoint = state.getInterface("LuaBox2D_Joint"); 39 | if (object->joint){ 40 | interfaceJoint->push(object->joint, false); 41 | return 1; 42 | }else{ 43 | return 0; 44 | } 45 | } 46 | 47 | int JointEdge::getPrev(State & state, b2JointEdge * object){ 48 | JointEdge * interfaceJointEdge = state.getInterface("LuaBox2D_JointEdge"); 49 | if (object->prev){ 50 | interfaceJointEdge->push(object->prev, false); 51 | return 1; 52 | }else{ 53 | return 0; 54 | } 55 | } 56 | 57 | int JointEdge::getNext(State & state, b2JointEdge * object){ 58 | JointEdge * interfaceJointEdge = state.getInterface("LuaBox2D_JointEdge"); 59 | if (object->next){ 60 | interfaceJointEdge->push(object->next, false); 61 | return 1; 62 | }else{ 63 | return 0; 64 | } 65 | } 66 | }; 67 | -------------------------------------------------------------------------------- /src/objects/JointEdge.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_JOINTEDGE_H 2 | #define LUABOX2D_JOINTEDGE_H 3 | 4 | namespace LuaBox2D { 5 | class JointEdge : public Object { 6 | public: 7 | explicit JointEdge(State * state) : Object(state){ 8 | LUTOK_PROPERTY("other", &JointEdge::getOther, &JointEdge::nullMethod); 9 | LUTOK_PROPERTY("joint", &JointEdge::getJoint, &JointEdge::nullMethod); 10 | LUTOK_PROPERTY("prev", &JointEdge::getPrev, &JointEdge::nullMethod); 11 | LUTOK_PROPERTY("next", &JointEdge::getNext, &JointEdge::nullMethod); 12 | } 13 | 14 | b2JointEdge * constructor(State & state, bool & managed); 15 | 16 | void destructor(State & state, b2JointEdge * object); 17 | 18 | int getOther(State & state, b2JointEdge * object); 19 | int getJoint(State & state, b2JointEdge * object); 20 | int getPrev(State & state, b2JointEdge * object); 21 | int getNext(State & state, b2JointEdge * object); 22 | 23 | }; 24 | 25 | void initJointEdge(State * ); 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/objects/Manifold.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_MANIFOLD_H 2 | #define LUABOX2D_MANIFOLD_H 3 | 4 | namespace LuaBox2D { 5 | class Manifold : public Object { 6 | public: 7 | explicit Manifold(State * state) : Object(state){ 8 | LUTOK_PROPERTY("localNormal", &Manifold::getLocalNormal, &Manifold::setLocalNormal); 9 | LUTOK_PROPERTY("localPoint", &Manifold::getLocalPoint, &Manifold::setLocalPoint); 10 | LUTOK_PROPERTY("type", &Manifold::getType, &Manifold::setType); 11 | } 12 | 13 | b2Manifold * constructor(State & state, bool & managed); 14 | 15 | void destructor(State & state, b2Manifold * object); 16 | 17 | int operator_len(State & state, b2Manifold * object); 18 | 19 | int getLocalNormal(State & state, b2Manifold * object); 20 | 21 | int setLocalNormal(State & state, b2Manifold * object); 22 | 23 | int getLocalPoint(State & state, b2Manifold * object); 24 | 25 | int setLocalPoint(State & state, b2Manifold * object); 26 | 27 | int getType(State & state, b2Manifold * object); 28 | 29 | int setType(State & state, b2Manifold * object); 30 | 31 | int operator_getArray(State & state, b2Manifold * object); 32 | 33 | void operator_setArray(State & state, b2Manifold * object); 34 | }; 35 | 36 | void initManifold(State * ); 37 | }; 38 | 39 | #endif 40 | -------------------------------------------------------------------------------- /src/objects/ManifoldPoint.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_MANIFOLDPOINT_H 2 | #define LUABOX2D_MANIFOLDPOINT_H 3 | 4 | namespace LuaBox2D { 5 | class ManifoldPoint : public Object { 6 | public: 7 | explicit ManifoldPoint(State * state) : Object(state){ 8 | LUTOK_PROPERTY("localPoint", &ManifoldPoint::getLocalPoint, &ManifoldPoint::setLocalPoint); 9 | LUTOK_PROPERTY("normalImpulse", &ManifoldPoint::getNormalImpulse, &ManifoldPoint::setNormalImpulse); 10 | LUTOK_PROPERTY("tangentImpulse", &ManifoldPoint::getTangentImpulse, &ManifoldPoint::setTangentImpulse); 11 | LUTOK_PROPERTY("contactID", &ManifoldPoint::getContactID, &ManifoldPoint::setContactID); 12 | } 13 | 14 | b2ManifoldPoint * constructor(State & state, bool & managed); 15 | 16 | void destructor(State & state, b2ManifoldPoint * object); 17 | 18 | int getLocalPoint(State & state, b2ManifoldPoint * object); 19 | 20 | int setLocalPoint(State & state, b2ManifoldPoint * object); 21 | 22 | int getNormalImpulse(State & state, b2ManifoldPoint * object); 23 | 24 | int setNormalImpulse(State & state, b2ManifoldPoint * object); 25 | 26 | int getTangentImpulse(State & state, b2ManifoldPoint * object); 27 | 28 | int setTangentImpulse(State & state, b2ManifoldPoint * object); 29 | 30 | int getContactID(State & state, b2ManifoldPoint * object); 31 | 32 | int setContactID(State & state, b2ManifoldPoint * object); 33 | }; 34 | 35 | void initManifoldPoint(State * ); 36 | }; 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/objects/MassData.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/Vec2.hpp" 3 | #include "objects/MassData.hpp" 4 | 5 | namespace LuaBox2D { 6 | void initMassData(State * state){ 7 | state->registerInterface("LuaBox2D_MassData"); 8 | } 9 | 10 | b2MassData * MassData::constructor(State & state, bool & managed){ 11 | LUTOK2_NOT_USED(managed); 12 | b2MassData * object = new b2MassData(); 13 | return object; 14 | } 15 | 16 | void MassData::destructor(State & state, b2MassData * object){ 17 | delete object; 18 | } 19 | 20 | int MassData::getCenter(State & state, b2MassData * object){ 21 | Vec2 * interfaceVec2 = state.getInterface("LuaBox2D_Vec2"); 22 | interfaceVec2->push(&object->center, false); 23 | return 1; 24 | } 25 | 26 | int MassData::setCenter(State & state, b2MassData * object){ 27 | Vec2 * interfaceVec2 = state.getInterface("LuaBox2D_Vec2"); 28 | b2Vec2 * bound = interfaceVec2->get(1); 29 | if (bound != nullptr){ 30 | object->center = *bound; 31 | } 32 | return 0; 33 | } 34 | 35 | int MassData::getMass(State & state, b2MassData * object){ 36 | state.stack->push(static_cast(object->mass)); 37 | return 1; 38 | } 39 | 40 | int MassData::setMass(State & state, b2MassData * object){ 41 | object->mass = static_cast(state.stack->to(1)); 42 | return 0; 43 | } 44 | 45 | int MassData::getI(State & state, b2MassData * object){ 46 | state.stack->push(static_cast(object->I)); 47 | return 1; 48 | } 49 | 50 | int MassData::setI(State & state, b2MassData * object){ 51 | object->I = static_cast(state.stack->to(1)); 52 | return 0; 53 | } 54 | }; 55 | -------------------------------------------------------------------------------- /src/objects/MassData.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_MASSDATA_H 2 | #define LUABOX2D_MASSDATA_H 3 | 4 | namespace LuaBox2D { 5 | class MassData : public Object { 6 | public: 7 | explicit MassData(State * state) : Object(state){ 8 | LUTOK_PROPERTY("center", &MassData::getCenter, &MassData::setCenter); 9 | LUTOK_PROPERTY("mass", &MassData::getMass, &MassData::setMass); 10 | LUTOK_PROPERTY("I", &MassData::getI, &MassData::setI); 11 | } 12 | 13 | b2MassData * constructor(State & state, bool & managed); 14 | 15 | void destructor(State & state, b2MassData * object); 16 | 17 | int getCenter(State & state, b2MassData * object); 18 | 19 | int setCenter(State & state, b2MassData * object); 20 | 21 | int getMass(State & state, b2MassData * object); 22 | 23 | int setMass(State & state, b2MassData * object); 24 | 25 | int getI(State & state, b2MassData * object); 26 | 27 | int setI(State & state, b2MassData * object); 28 | }; 29 | 30 | void initMassData(State * ); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/objects/PolygonShape.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_POLYGONSHAPE_H 2 | #define LUABOX2D_POLYGONSHAPE_H 3 | 4 | namespace LuaBox2D { 5 | class PolygonShape : public Object { 6 | private: 7 | Shape * base; 8 | public: 9 | explicit PolygonShape(State * state) : Object(state){ 10 | base = state->getInterface("LuaBox2D_Shape"); 11 | LUTOK_PROPERTY("type", &PolygonShape::getType, &PolygonShape::nullMethod); 12 | LUTOK_METHOD("testPoint", &PolygonShape::testPoint); 13 | LUTOK_METHOD("rayCast", &PolygonShape::rayCast); 14 | LUTOK_METHOD("computeAABB", &PolygonShape::computeAABB); 15 | LUTOK_METHOD("computeMass", &PolygonShape::computeMass); 16 | 17 | LUTOK_METHOD("set", &PolygonShape::set); 18 | LUTOK_METHOD("setAsBox", &PolygonShape::setAsBox); 19 | LUTOK_PROPERTY("vertexCount", &PolygonShape::getVertexCount, &PolygonShape::nullMethod); 20 | LUTOK_METHOD("vertex", &PolygonShape::getVertex); 21 | LUTOK_METHOD("validate", &PolygonShape::validate); 22 | } 23 | 24 | b2PolygonShape * constructor(State & state, bool & managed); 25 | 26 | void destructor(State & state, b2PolygonShape * object); 27 | 28 | int getType(State & state, b2PolygonShape * object); 29 | 30 | int getRadius(State & state, b2PolygonShape * object); 31 | 32 | int setRadius(State & state, b2PolygonShape * object); 33 | 34 | int testPoint(State & state, b2PolygonShape * object); 35 | 36 | int rayCast(State & state, b2PolygonShape * object); 37 | 38 | int computeAABB(State & state, b2PolygonShape * object); 39 | 40 | int computeMass(State & state, b2PolygonShape * object); 41 | 42 | int operator_len(State & state, b2PolygonShape * object); 43 | 44 | int set(State & state, b2PolygonShape * object); 45 | 46 | int setAsBox(State & state, b2PolygonShape * object); 47 | 48 | int getVertexCount(State & state, b2PolygonShape * object); 49 | 50 | int getVertex(State & state, b2PolygonShape * object); 51 | 52 | int validate(State & state, b2PolygonShape * object); 53 | }; 54 | 55 | void initPolygonShape(State * ); 56 | }; 57 | 58 | #endif 59 | -------------------------------------------------------------------------------- /src/objects/QueryCallback.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/QueryCallback.hpp" 3 | #include "objects/Fixture.hpp" 4 | 5 | namespace LuaBox2D { 6 | void initQueryCallback(State * state){ 7 | state->registerInterface("LuaBox2D_QueryCallback"); 8 | } 9 | 10 | LuaBox2DQueryCallback * QueryCallback::constructor(State & state, bool & managed){ 11 | LUTOK2_NOT_USED(managed); 12 | return new LuaBox2DQueryCallback(&state); 13 | } 14 | 15 | void QueryCallback::destructor(State & state, LuaBox2DQueryCallback * object){ 16 | delete object; 17 | } 18 | 19 | int QueryCallback::getReportFixture(State & state, LuaBox2DQueryCallback * object){ 20 | if (object->refReportFixture != LUA_NOREF){ 21 | state.stack->rawGet(object->refReportFixture, LUA_REGISTRYINDEX); 22 | return 1; 23 | }else{ 24 | return 0; 25 | } 26 | } 27 | 28 | int QueryCallback::setReportFixture(State & state, LuaBox2DQueryCallback * object){ 29 | if (state.stack->is(1)){ 30 | if (object->refReportFixture != LUA_NOREF){ 31 | state.stack->unref(object->refReportFixture); 32 | } 33 | state.stack->pushValue(1); 34 | object->refReportFixture = state.stack->ref(); 35 | }else{ 36 | if (state.stack->is(1)){ 37 | if (object->refReportFixture != LUA_NOREF){ 38 | state.stack->unref(object->refReportFixture); 39 | object->refReportFixture = LUA_NOREF; 40 | } 41 | } 42 | } 43 | return 0; 44 | } 45 | 46 | inline bool LuaBox2DQueryCallback::getCallBack(int ref){ 47 | if (ref != LUA_NOREF){ 48 | state->stack->regValue(ref); 49 | if (state->stack->is()){ 50 | return true; 51 | }else{ 52 | return false; 53 | } 54 | }else{ 55 | return false; 56 | } 57 | } 58 | 59 | bool LuaBox2DQueryCallback::ReportFixture(b2Fixture* fixture){ 60 | if (getCallBack(refReportFixture)){ 61 | Fixture * interfaceFixture = state->getInterface("LuaBox2D_Fixture"); 62 | interfaceFixture->push(fixture, false); 63 | state->stack->call(1, 1); 64 | bool retVal = state->stack->to(); 65 | state->stack->pop(1); 66 | return retVal; 67 | }else{ 68 | return false; 69 | } 70 | } 71 | 72 | LuaBox2DQueryCallback::~LuaBox2DQueryCallback(){ 73 | if (refReportFixture != LUA_NOREF){ 74 | state->stack->unref(refReportFixture); 75 | } 76 | } 77 | }; 78 | -------------------------------------------------------------------------------- /src/objects/QueryCallback.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_QUERYCALLBACK_H 2 | #define LUABOX2D_QUERYCALLBACK_H 3 | 4 | namespace LuaBox2D { 5 | class LuaBox2DQueryCallback : public b2QueryCallback { 6 | private: 7 | State * state; 8 | public: 9 | LuaBox2DQueryCallback(State * state) : b2QueryCallback(){ 10 | this->state = state; 11 | refReportFixture = LUA_NOREF; 12 | } 13 | ~LuaBox2DQueryCallback(); 14 | 15 | bool ReportFixture(b2Fixture* fixture); 16 | 17 | bool getCallBack(int ref); 18 | 19 | int refReportFixture; 20 | 21 | }; 22 | 23 | class QueryCallback : public Object { 24 | public: 25 | explicit QueryCallback(State * state) : Object(state){ 26 | LUTOK_PROPERTY("reportFixture", &QueryCallback::getReportFixture, &QueryCallback::setReportFixture); 27 | } 28 | 29 | LuaBox2DQueryCallback * constructor(State & state, bool & managed); 30 | 31 | void destructor(State & state, LuaBox2DQueryCallback * object); 32 | 33 | int getReportFixture(State & state, LuaBox2DQueryCallback * object); 34 | 35 | int setReportFixture(State & state, LuaBox2DQueryCallback * object); 36 | }; 37 | 38 | void initQueryCallback(State * ); 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/objects/RayCastCallback.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_RAYCASTCALLBACK_H 2 | #define LUABOX2D_RAYCASTCALLBACK_H 3 | 4 | namespace LuaBox2D { 5 | class LuaBox2DRayCastCallback : public b2RayCastCallback { 6 | private: 7 | State * state; 8 | public: 9 | LuaBox2DRayCastCallback(State * state) : b2RayCastCallback(){ 10 | this->state = state; 11 | refReportFixture = LUA_NOREF; 12 | } 13 | ~LuaBox2DRayCastCallback(); 14 | 15 | float32 ReportFixture( b2Fixture* fixture, const b2Vec2& point, const b2Vec2& normal, float32 fraction); 16 | 17 | bool getCallBack(int ref); 18 | 19 | int refReportFixture; 20 | 21 | }; 22 | 23 | class RayCastCallback : public Object { 24 | public: 25 | explicit RayCastCallback(State * state) : Object(state){ 26 | LUTOK_PROPERTY("reportFixture", &RayCastCallback::getReportFixture, &RayCastCallback::setReportFixture); 27 | } 28 | 29 | LuaBox2DRayCastCallback * constructor(State & state, bool & managed); 30 | 31 | void destructor(State & state, LuaBox2DRayCastCallback * object); 32 | 33 | int getReportFixture(State & state, LuaBox2DRayCastCallback * object); 34 | 35 | int setReportFixture(State & state, LuaBox2DRayCastCallback * object); 36 | }; 37 | 38 | void initRayCastCallback(State * ); 39 | }; 40 | 41 | #endif 42 | -------------------------------------------------------------------------------- /src/objects/RayCastInput.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/Vec2.hpp" 3 | #include "objects/RayCastInput.hpp" 4 | 5 | namespace LuaBox2D { 6 | void initRayCastInput(State * state){ 7 | state->registerInterface("LuaBox2D_RayCastInput"); 8 | } 9 | 10 | b2RayCastInput * RayCastInput::constructor(State & state, bool & managed){ 11 | LUTOK2_NOT_USED(managed); 12 | b2RayCastInput * object = nullptr; 13 | Vec2 * interfaceVec2 = state.getInterface("LuaBox2D_Vec2"); 14 | b2Vec2 * p1 = interfaceVec2->get(1); 15 | b2Vec2 * p2 = interfaceVec2->get(2); 16 | 17 | object = new b2RayCastInput(); 18 | 19 | if (p1 != nullptr && p2 != nullptr && state.stack->is(3)){ 20 | object->p1 = *p1; 21 | object->p2 = *p2; 22 | object->maxFraction = static_cast(state.stack->to(3)); 23 | } 24 | return object; 25 | } 26 | 27 | void RayCastInput::destructor(State & state, b2RayCastInput * object){ 28 | delete object; 29 | } 30 | 31 | int RayCastInput::getP1(State & state, b2RayCastInput * object){ 32 | Vec2 * interfaceVec2 = state.getInterface("LuaBox2D_Vec2"); 33 | interfaceVec2->push(&object->p1, false); 34 | return 1; 35 | } 36 | 37 | int RayCastInput::setP1(State & state, b2RayCastInput * object){ 38 | Vec2 * interfaceVec2 = state.getInterface("LuaBox2D_Vec2"); 39 | b2Vec2 * point = interfaceVec2->get(1); 40 | if (point != nullptr){ 41 | object->p1 = *point; 42 | } 43 | return 0; 44 | } 45 | 46 | int RayCastInput::getP2(State & state, b2RayCastInput * object){ 47 | Vec2 * interfaceVec2 = state.getInterface("LuaBox2D_Vec2"); 48 | interfaceVec2->push(&object->p2, false); 49 | return 1; 50 | } 51 | 52 | int RayCastInput::setP2(State & state, b2RayCastInput * object){ 53 | Vec2 * interfaceVec2 = state.getInterface("LuaBox2D_Vec2"); 54 | b2Vec2 * point = interfaceVec2->get(1); 55 | if (point != nullptr){ 56 | object->p2 = *point; 57 | } 58 | return 0; 59 | } 60 | 61 | int RayCastInput::getMaxFraction(State & state, b2RayCastInput * object){ 62 | state.stack->push(static_cast(object->maxFraction)); 63 | return 1; 64 | } 65 | 66 | int RayCastInput::setMaxFraction(State & state, b2RayCastInput * object){ 67 | object->maxFraction = static_cast(state.stack->to(1)); 68 | return 0; 69 | } 70 | }; 71 | -------------------------------------------------------------------------------- /src/objects/RayCastInput.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_RAYCASTINPUT_H 2 | #define LUABOX2D_RAYCASTINPUT_H 3 | 4 | namespace LuaBox2D { 5 | class RayCastInput : public Object { 6 | public: 7 | explicit RayCastInput(State * state) : Object(state){ 8 | LUTOK_PROPERTY("p1", &RayCastInput::getP1, &RayCastInput::setP1); 9 | LUTOK_PROPERTY("p2", &RayCastInput::getP2, &RayCastInput::setP2); 10 | LUTOK_PROPERTY("maxFraction", &RayCastInput::getMaxFraction, &RayCastInput::setMaxFraction); 11 | } 12 | 13 | b2RayCastInput * constructor(State & state, bool & managed); 14 | 15 | void destructor(State & state, b2RayCastInput * object); 16 | 17 | int getP1(State & state, b2RayCastInput * object); 18 | 19 | int setP1(State & state, b2RayCastInput * object); 20 | 21 | int getP2(State & state, b2RayCastInput * object); 22 | 23 | int setP2(State & state, b2RayCastInput * object); 24 | 25 | int getMaxFraction(State & state, b2RayCastInput * object); 26 | 27 | int setMaxFraction(State & state, b2RayCastInput * object); 28 | }; 29 | 30 | void initRayCastInput(State * ); 31 | }; 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/objects/RayCastOutput.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/Vec2.hpp" 3 | #include "objects/RayCastOutput.hpp" 4 | 5 | namespace LuaBox2D { 6 | void initRayCastOutput(State * state){ 7 | state->registerInterface("LuaBox2D_RayCastOutput"); 8 | } 9 | 10 | b2RayCastOutput * RayCastOutput::constructor(State & state, bool & managed){ 11 | LUTOK2_NOT_USED(managed); 12 | b2RayCastOutput * object = new b2RayCastOutput(); 13 | return object; 14 | } 15 | 16 | void RayCastOutput::destructor(State & state, b2RayCastOutput * object){ 17 | delete object; 18 | } 19 | 20 | int RayCastOutput::getNormal(State & state, b2RayCastOutput * object){ 21 | Vec2 * interfaceVec2 = state.getInterface("LuaBox2D_Vec2"); 22 | interfaceVec2->push(&object->normal, false); 23 | return 1; 24 | } 25 | 26 | int RayCastOutput::setNormal(State & state, b2RayCastOutput * object){ 27 | Vec2 * interfaceVec2 = state.getInterface("LuaBox2D_Vec2"); 28 | b2Vec2 * point = interfaceVec2->get(1); 29 | if (point != nullptr){ 30 | object->normal = *point; 31 | } 32 | return 0; 33 | } 34 | 35 | int RayCastOutput::getFraction(State & state, b2RayCastOutput * object){ 36 | state.stack->push(static_cast(object->fraction)); 37 | return 1; 38 | } 39 | 40 | int RayCastOutput::setFraction(State & state, b2RayCastOutput * object){ 41 | object->fraction = static_cast(state.stack->to(1)); 42 | return 0; 43 | } 44 | }; 45 | -------------------------------------------------------------------------------- /src/objects/RayCastOutput.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_RAYCASTOUTPUT_H 2 | #define LUABOX2D_RAYCASTOUTPUT_H 3 | 4 | namespace LuaBox2D { 5 | class RayCastOutput : public Object { 6 | public: 7 | explicit RayCastOutput(State * state) : Object(state){ 8 | LUTOK_PROPERTY("normal", &RayCastOutput::getNormal, &RayCastOutput::setNormal); 9 | LUTOK_PROPERTY("fraction", &RayCastOutput::getFraction, &RayCastOutput::setFraction); 10 | } 11 | 12 | b2RayCastOutput * constructor(State & state, bool & managed); 13 | 14 | void destructor(State & state, b2RayCastOutput * object); 15 | 16 | int getNormal(State & state, b2RayCastOutput * object); 17 | 18 | int setNormal(State & state, b2RayCastOutput * object); 19 | 20 | int getFraction(State & state, b2RayCastOutput * object); 21 | 22 | int setFraction(State & state, b2RayCastOutput * object); 23 | }; 24 | 25 | void initRayCastOutput(State * ); 26 | }; 27 | 28 | #endif 29 | -------------------------------------------------------------------------------- /src/objects/Rot.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/Vec2.hpp" 3 | #include "objects/Rot.hpp" 4 | 5 | namespace LuaBox2D { 6 | void initRot(State * state){ 7 | state->registerInterface("LuaBox2D_Rot"); 8 | } 9 | 10 | b2Rot * Rot::constructor(State & state, bool & managed){ 11 | LUTOK2_NOT_USED(managed); 12 | b2Rot * obj = nullptr; 13 | 14 | Stack * stack = state.stack; 15 | if (stack->is(1)){ 16 | obj = new b2Rot( 17 | static_cast(stack->to(1)) 18 | ); 19 | }else{ 20 | obj = new b2Rot(); 21 | } 22 | 23 | return obj; 24 | } 25 | 26 | void Rot::destructor(State & state, b2Rot * object){ 27 | delete object; 28 | } 29 | 30 | int Rot::getXAxis(State & state, b2Rot * object){ 31 | Vec2 * interfaceVec2 = state.getInterface("LuaBox2D_Vec2"); 32 | interfaceVec2->push(new b2Vec2(object->GetXAxis())); 33 | return 1; 34 | } 35 | 36 | int Rot::getYAxis(State & state, b2Rot * object){ 37 | Vec2 * interfaceVec2 = state.getInterface("LuaBox2D_Vec2"); 38 | interfaceVec2->push(new b2Vec2(object->GetYAxis())); 39 | return 1; 40 | } 41 | 42 | int Rot::getAngle(State & state, b2Rot * object){ 43 | state.stack->push(static_cast(object->GetAngle())); 44 | return 1; 45 | } 46 | 47 | int Rot::setAngle(State & state, b2Rot * object){ 48 | if (state.stack->is(1)){ 49 | object->Set(static_cast(state.stack->to(1))); 50 | } 51 | return 0; 52 | } 53 | 54 | int Rot::identity(State & state, b2Rot * object){ 55 | object->SetIdentity(); 56 | return 0; 57 | } 58 | }; 59 | 60 | -------------------------------------------------------------------------------- /src/objects/Rot.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_ROT_H 2 | #define LUABOX2D_ROT_H 3 | 4 | namespace LuaBox2D { 5 | class Rot : public Object { 6 | public: 7 | explicit Rot(State * state) : Object(state){ 8 | LUTOK_PROPERTY("x", &Rot::getXAxis, &Rot::nullMethod); 9 | LUTOK_PROPERTY("y", &Rot::getYAxis, &Rot::nullMethod); 10 | LUTOK_PROPERTY("angle", &Rot::getAngle, &Rot::setAngle); 11 | 12 | LUTOK_METHOD("identity", &Rot::identity); 13 | } 14 | 15 | b2Rot * constructor(State & state, bool & managed); 16 | 17 | void destructor(State & state, b2Rot * object); 18 | 19 | int getXAxis(State & state, b2Rot * object); 20 | 21 | int getYAxis(State & state, b2Rot * object); 22 | 23 | int getAngle(State & state, b2Rot * object); 24 | 25 | int setAngle(State & state, b2Rot * object); 26 | 27 | int identity(State & state, b2Rot * object); 28 | 29 | }; 30 | 31 | void initRot(State *); 32 | }; 33 | 34 | #endif -------------------------------------------------------------------------------- /src/objects/Shape.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_SHAPE_H 2 | #define LUABOX2D_SHAPE_H 3 | 4 | namespace LuaBox2D { 5 | class Shape : public Object { 6 | protected: 7 | std::forward_list validTypes; 8 | public: 9 | explicit Shape(State * state) : Object(state){ 10 | LUTOK_PROPERTY("type", &Shape::getType, &Shape::nullMethod); 11 | LUTOK_PROPERTY("radius", &Shape::getRadius, &Shape::setRadius); 12 | 13 | LUTOK_METHOD("testPoint", &Shape::testPoint); 14 | LUTOK_METHOD("rayCast", &Shape::rayCast); 15 | LUTOK_METHOD("computeAABB", &Shape::computeAABB); 16 | LUTOK_METHOD("computeMass", &Shape::computeMass); 17 | 18 | initAllowedTypes(); 19 | } 20 | 21 | void initAllowedTypes(); 22 | 23 | b2Shape * constructor(State & state, bool & managed); 24 | 25 | void destructor(State & state, b2Shape * object); 26 | 27 | b2Shape * get(const int index); 28 | 29 | int getType(State & state, b2Shape * object); 30 | 31 | int getRadius(State & state, b2Shape * object); 32 | 33 | int setRadius(State & state, b2Shape * object); 34 | 35 | int operator_len(State & state, b2Shape * object); 36 | 37 | int testPoint(State & state, b2Shape * object); 38 | 39 | int rayCast(State & state, b2Shape * object); 40 | 41 | int computeAABB(State & state, b2Shape * object); 42 | 43 | int computeMass(State & state, b2Shape * object); 44 | }; 45 | 46 | void initShape(State * ); 47 | 48 | }; 49 | 50 | #endif -------------------------------------------------------------------------------- /src/objects/Sweep.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/Transform.hpp" 3 | #include "objects/Sweep.hpp" 4 | 5 | namespace LuaBox2D { 6 | void initSweep(State * state){ 7 | state->registerInterface("LuaBox2D_Sweep"); 8 | } 9 | 10 | b2Sweep * Sweep::constructor(State & state, bool & managed){ 11 | LUTOK2_NOT_USED(managed); 12 | b2Sweep * obj = nullptr; 13 | obj = new b2Sweep(); 14 | return obj; 15 | } 16 | 17 | void Sweep::destructor(State & state, b2Sweep * object){ 18 | delete object; 19 | } 20 | 21 | int Sweep::getTransform(State & state, b2Sweep * object){ 22 | if (state.stack->is(1)){ 23 | Transform * interfaceTransform = state.getInterface("LuaBox2D_Transform"); 24 | b2Transform * transform = new b2Transform(); 25 | object->GetTransform(transform, static_cast(state.stack->to(1))); 26 | interfaceTransform->push(transform, true); 27 | return 1; 28 | }else{ 29 | return 0; 30 | } 31 | } 32 | 33 | int Sweep::advance(State & state, b2Sweep * object){ 34 | if (state.stack->is(1)){ 35 | object->Advance(static_cast(state.stack->to(1))); 36 | } 37 | return 0; 38 | } 39 | 40 | int Sweep::normalize(State & state, b2Sweep * object){ 41 | object->Normalize(); 42 | return 0; 43 | } 44 | }; 45 | 46 | -------------------------------------------------------------------------------- /src/objects/Sweep.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_SWEEP_H 2 | #define LUABOX2D_SWEEP_H 3 | 4 | namespace LuaBox2D { 5 | class Sweep : public Object { 6 | public: 7 | explicit Sweep(State * state) : Object(state){ 8 | /* 9 | LUTOK_PROPERTY("x", &b2Sweep::getXAxis, &b2Sweep::nullMethod); 10 | LUTOK_PROPERTY("y", &b2Sweep::getYAxis, &b2Sweep::nullMethod); 11 | LUTOK_PROPERTY("angle", &b2Sweep::getAngle, &b2Sweep::setAngle); 12 | 13 | 14 | */ 15 | LUTOK_METHOD("transform", &Sweep::getTransform); 16 | LUTOK_METHOD("advance", &Sweep::advance); 17 | LUTOK_METHOD("normalize", &Sweep::normalize); 18 | } 19 | 20 | b2Sweep * constructor(State & state, bool & managed); 21 | 22 | void destructor(State & state, b2Sweep * object); 23 | 24 | int getTransform(State & state, b2Sweep * object); 25 | 26 | int advance(State & state, b2Sweep * object); 27 | 28 | int normalize(State & state, b2Sweep * object); 29 | }; 30 | 31 | void initSweep(State *); 32 | }; 33 | 34 | #endif 35 | -------------------------------------------------------------------------------- /src/objects/Timer.cpp: -------------------------------------------------------------------------------- 1 | #include "common.hpp" 2 | #include "objects/Timer.hpp" 3 | 4 | namespace LuaBox2D { 5 | void initTimer(State * state){ 6 | state->registerInterface("LuaBox2D_Timer"); 7 | } 8 | 9 | b2Timer * Timer::constructor(State & state, bool & managed){ 10 | LUTOK2_NOT_USED(managed); 11 | b2Timer * obj = nullptr; 12 | obj = new b2Timer(); 13 | return obj; 14 | } 15 | 16 | void Timer::destructor(State & state, b2Timer * object){ 17 | delete object; 18 | } 19 | 20 | int Timer::getMiliseconds(State & state, b2Timer * object){ 21 | state.stack->push(static_cast(object->GetMilliseconds())); 22 | return 1; 23 | } 24 | 25 | int Timer::reset(State & state, b2Timer * object){ 26 | object->Reset(); 27 | return 0; 28 | } 29 | }; 30 | -------------------------------------------------------------------------------- /src/objects/Timer.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_TIMER_H 2 | #define LUABOX2D_TIMER_H 3 | 4 | namespace LuaBox2D { 5 | class Timer : public Object { 6 | public: 7 | explicit Timer(State * state) : Object(state){ 8 | LUTOK_PROPERTY("ms", &Timer::getMiliseconds, &Timer::nullMethod); 9 | 10 | LUTOK_METHOD("reset", &Timer::reset); 11 | } 12 | 13 | b2Timer * constructor(State & state, bool & managed); 14 | 15 | void destructor(State & state, b2Timer * object); 16 | 17 | int getMiliseconds(State & state, b2Timer * object); 18 | 19 | int reset(State & state, b2Timer * object); 20 | }; 21 | 22 | void initTimer(State *); 23 | }; 24 | 25 | #endif -------------------------------------------------------------------------------- /src/objects/Transform.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_TRANSFORM_H 2 | #define LUABOX2D_TRANSFORM_H 3 | 4 | namespace LuaBox2D { 5 | class Transform : public Object { 6 | public: 7 | explicit Transform(State * state) : Object(state){ 8 | LUTOK_METHOD("identity", &Transform::identity); 9 | LUTOK_METHOD("set", &Transform::set); 10 | LUTOK_PROPERTY("p", &Transform::getP, &Transform::setP); 11 | LUTOK_PROPERTY("q", &Transform::getQ, &Transform::setQ); 12 | } 13 | 14 | b2Transform * constructor(State & state, bool & managed); 15 | 16 | void destructor(State & state, b2Transform * object); 17 | 18 | int identity(State & state, b2Transform * object); 19 | 20 | int set(State & state, b2Transform * object); 21 | 22 | int getP(State & state, b2Transform * object); 23 | 24 | int setP(State & state, b2Transform * object); 25 | 26 | int getQ(State & state, b2Transform * object); 27 | 28 | int setQ(State & state, b2Transform * object); 29 | 30 | }; 31 | 32 | void initTransform(State *); 33 | }; 34 | 35 | #endif -------------------------------------------------------------------------------- /src/objects/VertexArray.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_VERTEXARRAY_H 2 | #define LUABOX2D_VERTEXARRAY_H 3 | 4 | namespace LuaBox2D { 5 | typedef std::vector b2VertexArray; 6 | 7 | class VertexArray : public Object { 8 | public: 9 | explicit VertexArray(State * state) : Object(state){ 10 | LUTOK_PROPERTY("vertices", &VertexArray::nullMethod, &VertexArray::setVertices); 11 | } 12 | 13 | b2VertexArray * constructor(State & state, bool & managed); 14 | 15 | b2VertexArray * constructor(State & state, const int index); 16 | 17 | b2VertexArray * constructor(State & state, b2Vec2 * array, b2VertexArray::size_type size); 18 | 19 | void destructor(State & state, b2VertexArray * object){ 20 | LUTOK2_NOT_USED(state); 21 | delete object; 22 | } 23 | 24 | int operator_len(State & state, b2VertexArray * object); 25 | 26 | int operator_concat(State & state, b2VertexArray * a, b2VertexArray * b); 27 | 28 | int operator_getArray(State & state, b2VertexArray * object); 29 | 30 | void operator_setArray(State & state, b2VertexArray * object); 31 | 32 | int setVertices(State & state, b2VertexArray * object); 33 | 34 | int setVertices(State & state, b2VertexArray * object, const int tableIndex); 35 | }; 36 | 37 | void initVertexArray(State * ); 38 | }; 39 | 40 | #endif 41 | -------------------------------------------------------------------------------- /src/objects/WorldManifold.hpp: -------------------------------------------------------------------------------- 1 | #ifndef LUABOX2D_WORLDMANIFOLD_H 2 | #define LUABOX2D_WORLDMANIFOLD_H 3 | 4 | namespace LuaBox2D { 5 | class WorldManifold : public Object { 6 | public: 7 | explicit WorldManifold(State * state) : Object(state){ 8 | LUTOK_PROPERTY("normal", &WorldManifold::getNormal, &WorldManifold::setNormal); 9 | LUTOK_METHOD("initialize", &WorldManifold::initialize); 10 | LUTOK_METHOD("getSeparation", &WorldManifold::getSeparation); 11 | LUTOK_METHOD("setSeparation", &WorldManifold::setSeparation); 12 | } 13 | 14 | b2WorldManifold * constructor(State & state, bool & managed); 15 | 16 | void destructor(State & state, b2WorldManifold * object); 17 | 18 | int getNormal(State & state, b2WorldManifold * object); 19 | 20 | int setNormal(State & state, b2WorldManifold * object); 21 | 22 | int initialize(State & state, b2WorldManifold * object); 23 | 24 | int getSeparation(State & state, b2WorldManifold * object); 25 | 26 | int setSeparation(State & state, b2WorldManifold * object); 27 | 28 | int operator_getArray(State & state, b2WorldManifold * object); 29 | 30 | void operator_setArray(State & state, b2WorldManifold * object); 31 | }; 32 | 33 | void initWorldManifold(State * ); 34 | }; 35 | 36 | #endif 37 | -------------------------------------------------------------------------------- /test/test.lua: -------------------------------------------------------------------------------- 1 | local function testFile(name) 2 | local fname = ("test_%s.lua"):format(name) 3 | return pcall(loadfile(fname)) 4 | end 5 | 6 | --print(testFile('Vec2')) 7 | --print(testFile('VertexArray')) 8 | --print(testFile('World')) 9 | print(testFile('Body')) 10 | -------------------------------------------------------------------------------- /test/test_Body.lua: -------------------------------------------------------------------------------- 1 | local box2d = require 'LuaBox2D' 2 | local Vec2 = box2d.Vec2 3 | local VA = box2d.VertexArray 4 | local W = box2d.World 5 | local BD = box2d.BodyDef 6 | local ES = box2d.EdgeShape 7 | local PS = box2d.PolygonShape 8 | local FD = box2d.FixtureDef 9 | 10 | do 11 | local w1 = W(Vec2(0, -1)) 12 | 13 | local ground = (function() 14 | local bd1 = BD() 15 | local b1 = w1.createBody(bd1) 16 | 17 | local s1 = ES(Vec2(-20, 0), Vec2(20, 0)) 18 | 19 | local fd1 = FD() 20 | fd1.shape = s1 21 | local mt = getmetatable(fd1) 22 | 23 | print("OK", mt.typename) 24 | local f1 = b1.createFixture(fd1) 25 | return b1 26 | end) 27 | 28 | local attachment = (function() 29 | local bd1 = BD() 30 | bd1.type = 'dynamic' 31 | bd1.position = Vec2(0, 3) 32 | local b1 = w1.createBody(bd1) 33 | 34 | local s1 = PS(0.5, 2) 35 | 36 | local f1 = b1.createFixture(s1, 2) 37 | return b1 38 | end) 39 | 40 | local platform = (function() 41 | local bd1 = BD() 42 | bd1.type = 'dynamic' 43 | bd1.position = Vec2(-4, 5) 44 | local b1 = w1.createBody(bd1) 45 | 46 | local s1 = PS(0.5, 4, Vec2(4, 0), 0.5 * math.pi) 47 | 48 | local fd = FD() 49 | fd.shape = s1 50 | fd.friction = 0.6 51 | fd.density = 2 52 | local f1 = b1.createFixture(fd) 53 | 54 | local jd1 = box2d.RevoluteJointDef() 55 | jd1.initialize(attachment, b1, Vec2(0, 5)) 56 | jd1.maxMotorTorque = 50 57 | jd1.enableMotor = true 58 | local j1 = w1.createJoint(jd1) 59 | 60 | local jd2 = box2d.PrismaticJointDef() 61 | jd2.initialize(ground, b1, Vec2(0, 5), Vec2(1, 0)) 62 | 63 | jd2.maxMotorForce = 1000 64 | jd2.enableMotor = true 65 | jd2.lowerTranslation = -10 66 | jd2.upperTranslation = 10 67 | jd2.enableLimit = true 68 | 69 | local j2 = w1.createJoint(jd2) 70 | 71 | return b1 72 | end) 73 | 74 | --[[ 75 | local step = function() 76 | if platform.type == 'kinematicBody' then 77 | local p = platform.getTransform().p 78 | local v = platform.getLinearVelocity() 79 | 80 | if ((p.x < -10 and v.x < 0) or (p.x > 10 and v.x > 0)) then 81 | v.x = -v.x; 82 | platform.linearVelocity = v; 83 | end 84 | end 85 | 86 | w1.step(30, 4, 4) 87 | end 88 | 89 | for i=1,30 do 90 | step() 91 | end 92 | ]]-- 93 | local G = ground() 94 | end 95 | -------------------------------------------------------------------------------- /test/test_HelloWorld.lua: -------------------------------------------------------------------------------- 1 | local box2d = require 'LuaBox2D' 2 | local Vec2 = box2d.Vec2 3 | 4 | local gravity = Vec2(0, -10) 5 | 6 | local world = box2d.World(gravity) 7 | 8 | local bodyDef = box2d.BodyDef() 9 | bodyDef.position = Vec2(0, -1) 10 | local groundBody = world.createBody(bodyDef) 11 | local groundBox = box2d.PolygonShape() 12 | groundBox.setAsBox(50, 2) 13 | local groundFixture = groundBody.createFixture(groundBox, 0) 14 | 15 | local bodyDef = box2d.BodyDef() 16 | bodyDef.type = 'dynamic' 17 | bodyDef.position = Vec2(0, 4) 18 | local body = world.createBody(bodyDef) 19 | local dynamicBox = box2d.PolygonShape() 20 | dynamicBox.setAsBox(1, 1) 21 | local fixtureDef = box2d.FixtureDef() 22 | fixtureDef.shape = dynamicBox 23 | fixtureDef.density = 1 24 | fixtureDef.friction = 0.3 25 | local dynamicFixture = groundBody.createFixture(fixtureDef) 26 | 27 | local timeStep = 1/30 28 | local velocityIterations = 6 29 | local positionIterations = 2 30 | 31 | for i=1,60 do 32 | world.step(timeStep, velocityIterations, positionIterations) 33 | local position = body.position 34 | local angle = body.angle 35 | io.write(("%4.2f %4.2f %4.2f\n"):format(position.x, position.y, angle)) 36 | end 37 | -------------------------------------------------------------------------------- /test/test_Vec2.lua: -------------------------------------------------------------------------------- 1 | local box2d = require 'LuaBox2D' 2 | local Vec2 = box2d.Vec2 3 | 4 | local v1 = Vec2(1,2) 5 | local v2 = Vec2(3,5) 6 | local v3 = v1 + v2 7 | local v4 = v1 - v2 8 | local v5 = v1 * v2 9 | local v6 = v1 / v2 10 | local v7 = v1 * 5 11 | local v8 = 5 * v2 12 | local v9 = v1.normalizeTo() 13 | local v10 = v1.skew() 14 | local v11 = v1.clamp(Vec2(0,0), Vec2(1,1)) 15 | local v12 = v1 % v2 16 | 17 | print(v1, v1.x, v1.y) 18 | print(v2, v2.x, v2.y) 19 | print(v3, v3.x, v3.y) 20 | print(v4, v4.x, v4.y) 21 | print(v5) 22 | print(v6) 23 | print(v7, v7.x, v7.y) 24 | print(v8, v8.x, v8.y) 25 | print(v9, v9.x, v9.y) 26 | v1.normalize() 27 | print(v1, v1.x, v1.y) 28 | print(v10, v10.x, v10.y) 29 | print(v1.valid) 30 | v2.zero() 31 | print(v2, v2.x, v2.y) 32 | print(#v1, v1.length, v1.lengthSquared) 33 | print(v11, v11.x, v11.y) 34 | print(v12) 35 | 36 | local v0 = Vec2(1,1) 37 | for i=1,100000 do 38 | local v = Vec2(i, i) 39 | local vOut = v0 + v 40 | vOut.x = v0.x 41 | end -------------------------------------------------------------------------------- /test/test_VertexArray.lua: -------------------------------------------------------------------------------- 1 | local box2d = require 'LuaBox2D' 2 | local Vec2 = box2d.Vec2 3 | local VA = box2d.VertexArray 4 | 5 | do 6 | print('Array 1') 7 | local a = VA({ 8 | {123.45, 67.89}, {2, 4} 9 | }) 10 | 11 | a[4] = {7, 8} 12 | 13 | print(#a) 14 | 15 | local v1 = a[1] 16 | local v2 = a[2] 17 | local v3 = a[3] 18 | 19 | print(v1.x, v1.y) 20 | print(v2.x, v2.y) 21 | print(v3.x, v3.y) 22 | end 23 | 24 | do 25 | print('Array 2') 26 | local a = VA({ 27 | Vec2(123.45, 67.89), 28 | Vec2(2, 4), 29 | }) 30 | a[4] = Vec2 {7, 8} 31 | 32 | print(#a) 33 | 34 | local v1 = a[1] 35 | local v2 = a[2] 36 | local v3 = a[3] 37 | 38 | print(v1.x, v1.y) 39 | print(v2.x, v2.y) 40 | print(v3.x, v3.y) 41 | end -------------------------------------------------------------------------------- /test/test_World.lua: -------------------------------------------------------------------------------- 1 | local box2d = require 'LuaBox2D' 2 | local Vec2 = box2d.Vec2 3 | local VA = box2d.VertexArray 4 | local W = box2d.World 5 | 6 | do 7 | local w1 = W(Vec2(0, -1)) 8 | print(w1) 9 | print(w1.treeHeight, w1.treeQuality, w1.treeBalance) 10 | end 11 | --------------------------------------------------------------------------------