Code Monkey home page Code Monkey logo

planeworld's Introduction

branch state
master Build Status Codacy Badge Last commit
dev Build Status Codacy Badge Last commit

license

Head over to Planeworld Next Generation

This project evolved over round about two decades, one of them revisioned with svn and eventually git. But time went on, I made a lot of experiences, with Planeworld and with 3rdparty libraries, so head over to Planeworld Next Generation (PWNG)

planeworld

planeworld is a 2D simulation engine and a passion project. The main goal of its development is best explained by the following examplary scenerio: Start a rocket from a plantery surface with simulated physics, such as rigid body dynamics, fuel system, planetary atmosphere, etc. Reach another celestial body, like a moon, using realistic trajectory planning, incorporating n-Body dynamics for the star system. Land on the target body and drive around with a rover, which is also simulated with springs and dampers, suspension, tire flex and more. The engine should allow for (Lua) scripting and remote missions with simulated communication and patchable onboard computers.

Features

  • Universe
    • n-Body dynamics (done)
    • Procedurally generated planetary surfaces using noise functions (done)
    • Simulation of planetary atmosphere (done)
    • Different surface types, biomes,... (wip)
    • Procedurally generated universe (wip)
  • Components
    • Thrusters (done)
    • Fuel system (planned)
    • Hydraulics (planned)
    • Control units (planned)
  • Physics
    • Basic dynamics (done)
    • Automatic online calculation of inertia and center of mass (done)
    • Particle system and emitters (done)
    • Springs and Dampers (wip)
    • Continuous collision detection (wip)
    • Hard connections between objects (wip)
    • Constraint-based physics with several different joints (planned)
    • Rope physics (planned)
    • 2D tire physics (planned)
    • Drag and lift (planned)
    • Data communication (planned)
  • Graphics
    • OpenGL Core Profile (done)
    • Font manager (done)
    • Simple deferred-like rendering (done)
    • Different render targets, render-to-texture (done)
    • Different light sources, such as thrusters, headlights, stars (wip)
    • Shadow mapping (planned)
  • UI
    • Simple Window management (done)
    • Command console (done)
    • Virtual cameras (done)
    • Further widgets (planned)
  • System
    • Multi-threading (done)
    • Command interface with thread safe command queues (done)
    • Scripting API for command interface (done)
    • Separation of simulation and visualisation (done)
    • Handle manager (wip)
    • Client-server architecture (planned)

Dependencies

Installation

> git clone https://github.com/planeworld/planeworld.git
> mkdir planeworld/build
> cd planeworld/build
> cmake ../
> ccmake .
(To configure compile and install details)
> make install

Usage

> planeworld example.lua

Default Commands (see pw_input_default.lua)

Key/Mouse Description
0 Toggle timers on/off
1 Toggle timer 1 start/stop
2 Toggle timer 2 start/stop
3 Toggle timer 3 start/stop
f Toggle fullscreen
g Show grid
b Show bounding boxes
k Show kinematics states
c Cycle through cameras
l Load game state
m Show center of mass (COM)
n Show names
s Save game state
t Show object trajectories
u and LCTRL Toggle UID visuals on/off
w and LCTRL Show all windows
w and LALT Hide all windows
Home Toggle command console
TAB Tab completion in console mode
F2 Toggle debug info
F3 Toggle debug render
ESC Quit
+ / a Accelerate time (only key-pad +)
+ / a and CTRL ... and allow timestep increment
- / d Decelarate time
RETURN/ENTER Reset time
p Pause physics
SPACE Stepwise physics (when paused)
Mouse-Wheel Zoom
Right-Mouse + Move Up Zoom in
Right-Mouse + Move Down Zoom out
Right-Mouse + Move Left Rotate clockwise
Right-Mouse + Move Right Rotate counterclockwise
Left-Mouse + Move Translate

planeworld's People

Contributors

avanc avatar bfeldpw avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

linecode

planeworld's Issues

Implement camera bound grid visualisation

The current grid is bound to world coordinates. Thus, it is hard to use the grid when the camera is hooked to a moving object, especially when zooming in close to this particular object. Alternativaly, a camera bound grid should be implemented. Activation can be done by pressing the accordant key a second time, hence toggling the different states.

Set angle of local coordinate system

It is possible to set the origin of the local coordinate system in the core section of the xml file using

origin_x
origin_y

However, it is not possible to rotate the local coordinate system.

Lua package pw does not work as expected

In Lua, pw is a table which points to universe, etc. The table can be extended as expected:

pw.myvar=42;

However, pw.universe is an VarAccessMetaTable. Thus, the following fails:

pw.universe.myvar=42;   --[warning] Physics Manager: Unknown variable myvar.

The same behaviour for pw.sim and pw.system.

The problem was observed, as I wanted to extend the functionality as mentioned in https://gist.github.com/avanc/9107c2a9c862d31f195852a4cb78df95#file-example-lua-L110

pw.universe.get_object = function(object_name)
  local object = {};
  object.mass = pw.universe.get_mass(object_name);
  object.inertia = pw.universe.get_inertia(object_name);

  object.get_position = function()
    return pw.universe.get_position(object_name);
  end

  object.get_velocity = function()
    return pw.universe.get_velocity(object_name);
  end

  object.get_angle = function()
    return pw.universe.get_angle(object_name);
  end

  object.get_angle_vel = function()
    return pw.universe.get_angle_vel(object_name);
  end

  return object;
end

Compile error: m_pDBShape was not declared

pw_graphics/visuals/planet_visuals.cpp: In member function ‘virtual void CPlanetVisuals::draw(CCamera*, const IObject*) const’:
pw_graphics/visuals/planet_visuals.cpp:78:46: error: ‘m_pDBShape’ was not declared in this scope
 CPlanet* pPlanet = static_cast<CPlanet*>(m_pDBShape->getShapeCur());

Automatic calculation of inertia and center of mass

The mass moment of inertia and the center of mass should be automatically calculated by default. This should be done considering a homogeneous density distribution per shape, thus, calculation is based on objects geometry.

Initial behaviour of thrusters should be configurable

Currently, if a thruster is defined in XML, it is activated with the maximum force on startup. However, if used within lua, it should be deactivated on startup and activated in lua. Thus, an XML parameter "activated=false" would be helpfull.

Lua script shouldn't be a hardcoded dependency

If the lua script is not available, PW fails with an error message:

File ./sputnik/physics_interface.lua could not be loaded.

However, if no script is defined in the config section of the xml, the program should run normally.

Working directory not set correctly in Lua

The working directory of Lua is set to the directory, where planeworld was started instead of the directory, where physics_interface.lua is located.
This can be easily tested with

io.open("testfile.txt", "w")

which creates a new file.

The major problem is, that the Lua function require searches in the working directory. This results in similar problems as in #14

Lua functions missing

Following functions are missing in lua:

  • get_angle and get_angle_ref
  • get_angle_velocity and get_angle_velocity_ref
  • get_time

In addition, functions to get static parameters of objects would be very helpful:

  • get_mass
  • get_inertia

Small objects are not drawn too early

In the sputnik example, the sputnik is not drawn as small dot at a zoom level of about 10km. This is far to early. The small dot should be visible at least until the earth comes into the screen.

Lua file should not be mandatory

If the Lua file is not configured using

<config
    physics_interface="../physics_interface.lua"
/>

planeworld complains that the Lua file couldn't be loaded. However, some examples like Sputnik do not need a Lua file. Thus, defining physics_interface should be optional.

Key + for accelerating time does not work

SFML does only recognize the plus key from the key pad. Thus, it is not possible to accelerate time if key pad is not available (e.g. laptop keyboard).
An alternative key is needed.

Lua should be called before first physics calculation

pw.universe.get_time() returns 0.3 on first run. This means that simulation has already started.
However, if something has to be initialised on startup, it would be helpful if Lua is run before first physics calculation.

Cell handling doesn't work correctly

When moving the camera out of the initial cell, it's bounding box doesn't follow but jumps back to cell(0,0). Cells probably also won't work for objects. This is related to the introduction of kinematics states. Cell information should be implemented there.

Provide functions within Lua as packages

In Lua, functions are grouped in so called packages: http://www.lua.org/pil/15.html
An example is the package math, which contains among other functions math.pow() and math.sin().
I imagine a similar packaging of planeworld related functions:

  • pw: Main namespace for all planeworld related functions
  • pw.system: Package for system related functions like set_frequency(), pause(), save()
  • pw.universe: Package for all functions related to the internal universe like get_position(), get_velocity()

Wrong relative path while parsing xml

The following example reads two files as expected:

<object file="foo.xml" />
<object file="folder/bar.xml"/>

However, if the lines are switched:

<object file="folder/bar.xml"/>
<object file="foo.xml" />

foo.xml is searched at folder/foo.xml.

[warning]     []        XML Importer: XML file ./folder/foo.xml parsed with errors.                                                                                  
[warning]     []        XML Importer: Error description: File was not found

Add lua function to output text on window

To create an interactive tutorial as described in planeworld/examples#3, a function to show text on the graphics window is needed. In addition, the parameters of the camera also need to be accessible. With this, a lua script can be written which gives instructions to the user depending on the viewport.

Following lua functions are needed:
* show text / clear text
* get camera position (relative or absolute)
* get camera viewport (m_per_px)

Following lua functions would be nice to have:
* set camera position
* set camera viewport (m_per_px)
* set object to which the camera is hooked

Misleading notice message while importing xml

First, the xml importer sets a default value for inertia, if no value is found.
But then, the importer complains, that the value is no longer needed:

[notice]      []        XML Importer: Attribute inertia not found. Using default value 0.
[notice]      [var]     XML Importer: Inertia is be calculated automatically now, value 0 ignored.

This output was done using sunlight example.

Add exit function to quit planeworld

As I use pw also to simulate the simulation a function like

pw.system.quit()

would be helpful, as I'm only interested in the text output.

In addition, a function to set the acceleration:

pw.system.set_acceleration(1024, false);

The second Boolean parameter can be used to change also accuracy (similar to Strg+a).

Add camera object as new physical entity

Implement a server-side camera representation to allow for simulation queries and optimisations based on camera viewport. This might include a "physical scope" which defines the area where objects are fully simulated.

Add function to calculate orbit parameters for a 2-body problem

For 2-body problems, the satellite orbits can be represented as conic sections (circle, ellipse, parabola, hyperbola).
A function should be provided, which calculates the following orbit parameters:

  • eccentricity vector e (vector with length of the eccentricity pointing into direction of the semi-major axis)
  • semi-latus rectum l
  • position of main focal point f
    The IDs of the two bodies are given to the function as input parameters.

In a second step, this information can be used by the graphics engine to show orbits.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.