add hello world example and edit source tree
This commit is contained in:
parent
ed0159f4b5
commit
71ee97aaa0
128
examples/hello_world/main.cpp
Normal file
128
examples/hello_world/main.cpp
Normal file
@ -0,0 +1,128 @@
|
||||
/*
|
||||
* Copyright (c) 2016-2016 Irlan Robson http://www.irlan.net
|
||||
*
|
||||
* This software is provided 'as-is', without any express or implied
|
||||
* warranty. In no event will the authors be held liable for any damages
|
||||
* arising from the use of this software.
|
||||
* Permission is granted to anyone to use this software for any purpose,
|
||||
* including commercial applications, and to alter it and redistribute it
|
||||
* freely, subject to the following restrictions:
|
||||
* 1. The origin of this software must not be misrepresented; you must not
|
||||
* claim that you wrote the original software. If you use this software
|
||||
* in a product, an acknowledgment in the product documentation would be
|
||||
* appreciated but is not required.
|
||||
* 2. Altered source versions must be plainly marked as such, and must not be
|
||||
* misrepresented as being the original software.
|
||||
* 3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
#include <bounce\bounce.h>
|
||||
|
||||
// We don't care for a profiler. This definition does nothing.
|
||||
bool b3PushProfileScope(const char* name)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// We don't care for a profiler. This definition does nothing.
|
||||
void b3PopProfileScope()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
// This example shows how to setup and run a simple simulation
|
||||
// using Bounce.
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
// The world gravity.
|
||||
const b3Vec3 gravity(0.0f, -9.8f, 0.0f);
|
||||
|
||||
// The fixed time step size.
|
||||
const float32 timeStep = 1.0f / 60.0f;
|
||||
|
||||
// Number of iterations for the velocity constraint solver.
|
||||
const u32 velocityIterations = 8;
|
||||
|
||||
// Number of iterations for the position constraint solver.
|
||||
const u32 positionIterations = 2;
|
||||
|
||||
// The world-> We allocate it using the heap but you can to it
|
||||
// on the stack if the stack is sufficiently large.
|
||||
b3World* world = new b3World();
|
||||
world->SetGravity(gravity);
|
||||
|
||||
// Create a static ground body at the world origin.
|
||||
b3BodyDef groundDef;
|
||||
b3Body* ground = world->CreateBody(groundDef);
|
||||
|
||||
// Create a box positioned at the world origin and
|
||||
// aligned with the world frame.
|
||||
b3BoxHull groundBox;
|
||||
|
||||
// Set the ground box dimensions using a linear scale transform.
|
||||
b3Transform scale;
|
||||
scale.position.SetZero();
|
||||
scale.rotation = b3Diagonal(10.0f, 1.0f, 10.0f);
|
||||
groundBox.SetTransform(scale);
|
||||
|
||||
// Create the box physics wrapper.
|
||||
b3HullShape groundShape;
|
||||
groundShape.m_hull = &groundBox;
|
||||
|
||||
// Add the box to the ground body.
|
||||
b3ShapeDef groundBoxDef;
|
||||
groundBoxDef.shape = &groundShape;
|
||||
ground->CreateShape(groundBoxDef);
|
||||
|
||||
// Create a dynamic body.
|
||||
b3BodyDef bodyDef;
|
||||
bodyDef.type = e_dynamicBody;
|
||||
|
||||
// Position the body 10 meters high from the world origin.
|
||||
bodyDef.position.Set(0.0f, 10.0f, 0.0f);
|
||||
|
||||
// Set the initial angular velocity to pi radians (180 degrees) per second.
|
||||
bodyDef.angularVelocity.Set(0.0f, B3_PI, 0.0f);
|
||||
|
||||
b3Body* body = world->CreateBody(bodyDef);
|
||||
|
||||
// Create a unit box positioned at the world origin and
|
||||
// aligned with the world frame.
|
||||
b3BoxHull bodyBox;
|
||||
bodyBox.SetIdentity();
|
||||
|
||||
// Create the box physics wrapper.
|
||||
b3HullShape bodyShape;
|
||||
bodyShape.m_hull = &bodyBox;
|
||||
|
||||
// Add the box to the body.
|
||||
b3ShapeDef bodyBoxDef;
|
||||
bodyBoxDef.shape = &bodyShape;
|
||||
bodyBoxDef.density = 1.0f;
|
||||
body->CreateShape(bodyBoxDef);
|
||||
|
||||
// Run a small game loop of 60 frames length.
|
||||
for (u32 i = 0; i < 60; ++i)
|
||||
{
|
||||
// Perform a time step of the world in this frame.
|
||||
world->Step(timeStep, velocityIterations, positionIterations);
|
||||
|
||||
// Read the body position and orientation in this frame.
|
||||
b3Vec3 position = body->GetPosition();
|
||||
b3Quat orientation = body->GetOrientation();
|
||||
|
||||
// Decode the axis and angle of rotation about it from the quaternion.
|
||||
b3Vec3 axis;
|
||||
float32 angle;
|
||||
orientation.GetAxisAngle(&axis, &angle);
|
||||
|
||||
// Visualize the body state in this frame.
|
||||
printf("position = %.2f %.2f %.2f\n", position.x, position.y, position.z);
|
||||
printf("axis = %.2f %.2f %.2f, angle = %.2f\n\n", axis.x, axis.y, axis.z, angle);
|
||||
}
|
||||
|
||||
// Now destroy the bodies since the world manages their lifetime.
|
||||
delete world;
|
||||
|
||||
return 0;
|
||||
}
|
@ -21,9 +21,9 @@
|
||||
|
||||
#include <bounce/common/settings.h>
|
||||
|
||||
// Allocate 10 MiB from the stack.
|
||||
// Allocate 1 MiB from the stack.
|
||||
// Increase as you want.
|
||||
const u32 b3_maxStackSize = B3_MiB(10);
|
||||
const u32 b3_maxStackSize = B3_MiB(1);
|
||||
|
||||
// A stack allocator.
|
||||
class b3StackAllocator
|
||||
|
@ -116,6 +116,12 @@ public:
|
||||
// However, manipulating a body transform during the simulation may cause non-physical behaviour.
|
||||
void SetTransform(const b3Vec3& position, const b3Vec3& axis, float32 angle);
|
||||
|
||||
// Get the position of the world body origin.
|
||||
b3Vec3 GetPosition() const;
|
||||
|
||||
// Get the orientation of the world body frame.
|
||||
b3Quat GetOrientation() const;
|
||||
|
||||
// Get the gravity scale of the body. One is used by default.
|
||||
float32 GetGravityScale() const;
|
||||
|
||||
@ -382,6 +388,16 @@ inline void b3Body::SetTransform(const b3Vec3& position, const b3Vec3& axis, flo
|
||||
SynchronizeShapes();
|
||||
}
|
||||
|
||||
inline b3Vec3 b3Body::GetPosition() const
|
||||
{
|
||||
return m_sweep.worldCenter;
|
||||
}
|
||||
|
||||
inline b3Quat b3Body::GetOrientation() const
|
||||
{
|
||||
return m_sweep.orientation;
|
||||
}
|
||||
|
||||
inline b3Vec3 b3Body::GetLocalVector(const b3Vec3& vector) const
|
||||
{
|
||||
return b3MulT(m_xf.rotation, vector);
|
||||
|
@ -53,7 +53,7 @@ enum b3LimitState
|
||||
|
||||
// Return the Steiner's matrix given the displacement vector from the old
|
||||
// center of rotation to the new center of rotation.
|
||||
// The result equals to transpose( skew(v) ) * skew(v) or diagonal(v^2) - outer(v)
|
||||
// The result equals to transpose( skew(v) ) * skew(v) or diagonal(v^2) - outer(v, v)
|
||||
inline b3Mat33 b3Steiner(const b3Vec3& v)
|
||||
{
|
||||
float32 xx = v.x * v.x;
|
||||
|
39
premake5.lua
39
premake5.lua
@ -7,8 +7,12 @@ solution_name = "bounce"
|
||||
working_dir = "."
|
||||
solution_dir = "build/"
|
||||
external_dir = "external/"
|
||||
inc_dir = "include/"
|
||||
src_dir = "src/"
|
||||
bounce_inc_dir = "include/"
|
||||
bounce_src_dir = "src/"
|
||||
examples_inc_dir = "examples/"
|
||||
examples_src_dir = "examples/"
|
||||
tests_inc_dir = "tests/"
|
||||
tests_src_dir = "tests/"
|
||||
obj_dir = "/obj/"
|
||||
bin_dir = "/bin/"
|
||||
|
||||
@ -48,15 +52,15 @@ solution (solution_name)
|
||||
kind "StaticLib"
|
||||
language "C++"
|
||||
location ( solution_dir .. action )
|
||||
includedirs { inc_dir }
|
||||
includedirs { bounce_inc_dir }
|
||||
vpaths { [""] = "bounce" }
|
||||
buildoptions { "-std=c++11" } -- require C++11
|
||||
|
||||
files
|
||||
{
|
||||
inc_dir .. "/bounce/**.h",
|
||||
inc_dir .. "/bounce/**.inl",
|
||||
src_dir .. "/bounce/**.cpp"
|
||||
bounce_inc_dir .. "/bounce/**.h",
|
||||
bounce_inc_dir .. "/bounce/**.inl",
|
||||
bounce_src_dir .. "/bounce/**.cpp"
|
||||
}
|
||||
project "glad"
|
||||
kind "StaticLib"
|
||||
@ -178,14 +182,14 @@ solution (solution_name)
|
||||
kind "ConsoleApp"
|
||||
language "C++"
|
||||
location ( solution_dir .. action )
|
||||
includedirs { external_dir, inc_dir }
|
||||
includedirs { external_dir, bounce_inc_dir, examples_inc_dir }
|
||||
vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" }
|
||||
buildoptions { "-std=c++11" } -- GNU/GCC C++11
|
||||
|
||||
files
|
||||
{
|
||||
inc_dir .. "/testbed/**.h",
|
||||
src_dir .. "/testbed/**.cpp"
|
||||
examples_inc_dir .. "/testbed/**.h",
|
||||
examples_src_dir .. "/testbed/**.cpp"
|
||||
}
|
||||
|
||||
links { "glfw", "glad", "imgui", "bounce" }
|
||||
@ -201,7 +205,22 @@ solution (solution_name)
|
||||
"xcb-dri2", "xcb-dri3", "xcb-present", "xcb-sync", "xshmfence",
|
||||
"Xxf86vm", "Xfixes", "Xext", "X11", "pthread", "xcb", "Xau", "Xdmcp"
|
||||
}
|
||||
|
||||
|
||||
project "hello_world"
|
||||
kind "ConsoleApp"
|
||||
language "C++"
|
||||
location ( solution_dir .. action )
|
||||
includedirs { bounce_inc_dir, examples_inc_dir }
|
||||
vpaths { ["Headers"] = "**.h", ["Sources"] = "**.cpp" }
|
||||
buildoptions { "-std=c++11" } -- GNU/GCC C++11
|
||||
|
||||
files
|
||||
{
|
||||
examples_inc_dir .. "/hello_world/**.h",
|
||||
examples_src_dir .. "/hello_world/**.cpp"
|
||||
}
|
||||
|
||||
links { "bounce" }
|
||||
-- build
|
||||
if os.is "windows" then
|
||||
|
||||
|
@ -4,7 +4,7 @@ Bounce is a 3D physics engine for games and interactive applications.
|
||||
|
||||
To get started with Bounce see readme.txt.
|
||||
|
||||
Here is how to control the Testbed. The Testbed is a collection of tests and examples that helps the author debug features and is not part of the library.
|
||||
Here is how to control the Testbed. The Testbed is a collection of non-unit tests and examples that helps the author debug features and is not part of the library.
|
||||
|
||||
Camera (as in Maya):
|
||||
|
||||
|
0
tests/ignore.txt
Normal file
0
tests/ignore.txt
Normal file
Loading…
x
Reference in New Issue
Block a user