PlayRho
1.1.0
An Interactive Real-Time-Oriented C++ Physics Engine & Library
|
|
This is the source file for the HelloWorld
application that demonstrates use of the playrho::d2::World
class and more. After instantiating a world, the code creates a body and its fixture to act as the ground, creates another body and a fixture for it to act like a ball, then steps the world using the world playrho::d2::World::Step(const StepConf&)
function which simulates a ball falling to the ground and outputs the position of the ball after each step.
#include <PlayRho/PlayRho.hpp>
#include <iostream>
#include <iomanip>
int main()
{
std::cout << std::fixed << std::setprecision(2);
for (auto i = 0; i < 60; ++i)
{
const auto angle =
GetAngle(transformation);
std::cout << std::setw(5) <<
GetX(location);
std::cout << std::setw(5) <<
GetY(location);
std::cout << std::setw(5) << angle;
std::cout << '\n';
}
return 0;
}
@ Static
Static body type.
BodyID CreateBody(World &world, const BodyConf &def)
Creates a rigid body with the given configuration.
Definition: WorldBody.cpp:58
PolygonShapeConf & SetAsBox(Length hx, Length hy) noexcept
Sets the vertices to represent an axis-aligned box centered on the local origin.
Definition: PolygonShapeConf.cpp:42
Name space for 2-dimensionally related PlayRho names.
Definition: AABB.cpp:34
constexpr auto & GetX(T &value)
Gets the "X" element of the given value - i.e. the first element.
Definition: Math.hpp:66
Name space for all PlayRho related names.
Definition: AABB.cpp:33
Definition of an independent and simulatable "world".
Definition: World.hpp:129
Fixture definition.
Definition: FixtureConf.hpp:46
constexpr BodyConf & UseLocation(Length2 l) noexcept
Use the given location.
Definition: BodyConf.hpp:172
Polygon shape configuration.
Definition: PolygonShapeConf.hpp:42
Angle GetAngle(const UnitVec value)
Gets the angle of the given unit vector.
Definition: Math.hpp:718
constexpr auto EarthlyGravity
Earthly gravity in 2-dimensions.
Definition: Vector2.hpp:154
FixtureConf & UseBody(BodyID value) noexcept
Uses the given value for the body member variable.
Definition: FixtureConf.hpp:66
FixtureID CreateFixture(World &world, FixtureConf def, bool resetMassData)
Creates a fixture within the specified world.
Definition: WorldFixture.cpp:48
constexpr DiskShapeConf & UseRadius(NonNegative< Length > r) noexcept
Uses the given value as the radius.
Definition: DiskShapeConf.hpp:65
Configuration for a body.
Definition: BodyConf.hpp:50
constexpr Length2 GetLocation(const Transformation &value) noexcept
Gets the location information from the given transformation.
Definition: Transformation.hpp:69
Vector.
Definition: Vector.hpp:49
constexpr Transformation GetTransformation(const Length2 ctr, const UnitVec rot, const Length2 localCtr) noexcept
Gets the transformation for the given values.
Definition: Math.hpp:875
Shape.
Definition: Shape.hpp:183
constexpr auto & GetY(T &value)
Gets the "Y" element of the given value - i.e. the second element.
Definition: Math.hpp:73
StepStats Step(WorldImpl &world, const StepConf &conf)
Steps the given world the specified amount.
Definition: WorldImplMisc.cpp:85
Disk shape configuration.
Definition: DiskShapeConf.hpp:42