Skip to content

Physics

ural89 edited this page Dec 27, 2025 · 1 revision

Physics

Creating physics polygon

First create an empty project as explained in [Create Your First Project] https://github.com/ural89/ConsoleCraftEngine/wiki/Quick-Start-Guide

in EntryScene.h add polygon creator ptr:

private:
  void OnInput(int input);
  PolygonCreator* m_PolygonCreator; //Add this line

in EntryScene.cpp write these lines into Init() method:

void EntryScene::Init()
{
    // AddGameObject(new ExampleGameObject(*this), Vector2(5,5)); //delete or comment out this line
    m_PolygonCreator = new PolygonCreator(*this); 
    m_PolygonCreator->SetEditingActive(true); //this will enable polygon creation mode.


    Vector2 rectPos = Vector2(5,5);
    Vector2 rectSize = Vector2(6, 6);
    float rectRotation = 0;
    int color = 2;
    m_PolygonCreator->CreateRectanglePolygon({rectPos, rectSize, rectRotation}, color); //place a polygon into scene

This code will add a rectangle into the scene. It will move with physics.

    m_PolygonCreator->SetEditingActive(true);

This line will give you ability to draw polygons into the scene. You can move cursor with WASD keys. Press E to place a point.

Press Space Bar to confirm your polygon:

To Be Continued...

Clone this wiki locally