-
install CMake
-
install a C++ compiler (if you don't have one already), for example:
- Windows: Visual Studio
- macOS: Xcode
- Linux: GCC
... or whatever you prefer
-
install Git
-
clone this repository
git clone https://github.com/tum-pbs/game-physics-template.git
-
Open the project in your IDE, for example [Visual Studio Code] (https://code.visualstudio.com/), and add src and thirdparty to the include directories. This is just for autocomplete. The build will work without it.
Note that currently WSL2 on Windows is not supported as there are issues with using webGPU on it, however, both Visual Studio 17 (2022) directly on Windows and MinGW are supported as alternatives. If you are facing issues on Windows in general, try cloning the repository again into a path without any spaces and retry the build process. We will be adding a compatibility and common issues list soon.
- Everytime you add new files, and once in the beginning, run
cmake . -B build
- Build the project
cmake --build build
The output will tel you where the executable is located. You can run it from the command line or from your IDE.
Each exercise has its own branch, usually only providing some additional code needed for the exercise.
The intro branch already has the completed tutorial code, so you can start from the main branch to go along.
The relevant directories:
- Scenes should contain all code relevant to your submission.
- src contains the engine source code. Feel free to take a look and play around with it. Make sure your submissions run without changes to theses files.
- thirdparty contains external libraries, including
glm
for vector math andimgui
for UI. - resources contains all resources loaded at runtime, such as shaders and colormaps. Especially the postprocessing shader is fun to play with.
This library is used for all vector, matrix and quaternion math.
Include <glm/glm.hpp>
to get started.
All vectors and matrices have loads of useful overloads, such as glm::vec3(0)
for a zero vector. vec4
can be implicitly cast to vec3
and vec2
, and so on.
- The quaternion constructor is
glm::quat(w,x,y,z)
, while the list initializer isglm::quat test = {x,y,z,w}
- You can include
<glm/gtx/string_cast.hpp>
to print vectors, matrices and quaternions withglm::to_string(vec)
- The
glm::
namespace contains many useful functions, such asglm::length(vec)
,glm::normalize(vec)
,glm::dot(vec1, vec2)
,glm::cross(vec1, vec2)
,glm::inverse(matrix)
,glm::transpose(matrix)
and many more. glm
has math functions that work on vectors, e.g.glm::sin(vec)
- Instead of
using namespace glm
, you can use privateusing vec3 = glm::vec3
in your class header to avoid conflicts with other libraries.
This library is used for all UI elements. It should only be used in the onGui
method of a scene.
Include <imgui.h>
to get started.
- You can use logarithmic sliders with
ImGui::SliderFloat("Slider", &value, min, max, "%.3f", ImGuiSliderFlags_Logarithmic)
- ImGui has many functions for interactiviy, such as
ImGui::IsKeyDown()
,ImGui::GetMousePos()
and many more. ImGui::GetIO()
contains more information about the input, evenPenPressure
andDisplaySize
.- Use
using namespace ImGui::
inside theonGui
method to avoid writingImGui::
all the time.
The draw methods are documented in the Renderer documantation.
The renderer
object is provided in the onDraw method of a scene.
You can use it to draw lines, ellipsoids, spheres, cubes, quads, and images.
How you do this is up to you.
A memory safe way to do this would be to store the objects in a vector in your scene class. Initialize the objects in init()
, modify them in the simulateStep()
method, and visualize them in the onDraw()
method.
#include <vector>
#include <glm/glm.hpp>
std::vector<YourObject> objects;
// or
std::vector<glm::vec3> positions;
// ... or whatever you need
You can draw Images with the drawImage
method.
void onDraw(Renderer &renderer) override {
// the data should not be declared in the draw method
std::vector<float> data = {1,0,0,0,1,0};
int width = 3;
int height = 2;
renderer.drawImage(data, height, width);
// This will draw an image to the full screen looking like this:
// 1 0 0
// 0 1 0
// The colors are defined by the optional colormap parameter.
// Note that the pixels will be stretched, if the aspect ratio of the image does not match the aspect ratio of the screen.
}
- Create a new class that inherits from
Scene
in the Scenes directory. - Add the scene to the
SceneIndex
in Scenes/SceneIndex.h.
{"The Scene's Name", creator<TheSceneClass>()},
- Run
cmake . -B build
again before building the project. - override only the functions you need and implement them in the scene's source file.
...
public:
void onDraw(Renderer &renderer) override;
void onGui() override;
- After building, you can select the scene in the UI.
- Add the source file to the Scenes directory.
- Run
cmake . -B build
again before building the project.
If you would like to know more, or work through a demo example look at our guide in this repository, which you can find in the guide.md file. This guide works through input handling, extending scenes and further details like adaptive timestepping and will be updated over time too.