All Projects → alexesDev → magnum-tips

alexesDev / magnum-tips

Licence: Unlicense license
Collection of useful snippets for https://magnum.graphics

Programming Languages

C++
36643 projects - #6 most used programming language
c
50402 projects - #5 most used programming language

Projects that are alternatives of or similar to magnum-tips

magnum-integration
Integration libraries for the Magnum C++11/C++14 graphics engine
Stars: ✭ 75 (+177.78%)
Mutual labels:  gamedev, magnum
Magnum
Lightweight and modular C++11 graphics middleware for games and data visualization
Stars: ✭ 3,728 (+13707.41%)
Mutual labels:  gamedev, magnum
Stdpack.c
Collection of small public domain de/compressors in plain C.
Stars: ✭ 73 (+170.37%)
Mutual labels:  snippets, gamedev
cog
Macro powered ECS Framework written in Haxe
Stars: ✭ 29 (+7.41%)
Mutual labels:  gamedev
ggrs
GGRS is a reimagination of GGPO, enabling P2P rollback networking in Rust. Rollback to the future!
Stars: ✭ 209 (+674.07%)
Mutual labels:  gamedev
minigdx-game-template
Basic template to create a game using minigdx
Stars: ✭ 16 (-40.74%)
Mutual labels:  gamedev
cl-sdl2-tutorial
SDL2 examples in Common Lisp based on Lazy Foo tutorials.
Stars: ✭ 55 (+103.7%)
Mutual labels:  gamedev
ts-nextjs-tailwind-starter
🔋 Next.js + Tailwind CSS + TypeScript starter packed with useful development features
Stars: ✭ 880 (+3159.26%)
Mutual labels:  snippets
30-seconds-of-csharp
Short C# code snippets for all your development needs
Stars: ✭ 132 (+388.89%)
Mutual labels:  snippets
deffx
A collection of useful shader effects made ready to be used with the Defold game engine
Stars: ✭ 33 (+22.22%)
Mutual labels:  gamedev
UnityHFSM
A simple yet powerful class based hierarchical finite state machine for Unity3D
Stars: ✭ 243 (+800%)
Mutual labels:  gamedev
susse
super ültra sweet sprite editor
Stars: ✭ 22 (-18.52%)
Mutual labels:  gamedev
OpenHSP
Hot Soup Processor (HSP3)
Stars: ✭ 120 (+344.44%)
Mutual labels:  gamedev
moon-cheeser
Moon Cheeser is an infinite runner where the player plays as a mouse gathering cheese pieces and avoiding craters and other astronomical objects, such as comets and planets, on a moon made of cheese.
Stars: ✭ 32 (+18.52%)
Mutual labels:  gamedev
faur
⚒️✨ My personal C games framework. 2D graphics, sound, inputs, states, ECS, and misc utils for data, files, math, memory, strings, time, and more. Builds for Linux, Windows, Web, and embedded devices.
Stars: ✭ 55 (+103.7%)
Mutual labels:  gamedev
codesnip
A code bank designed with Pascal in mind
Stars: ✭ 62 (+129.63%)
Mutual labels:  snippets
Deadrop
Deadrop is a small game engine that was made as part of the Afterback project.
Stars: ✭ 17 (-37.04%)
Mutual labels:  gamedev
MedievalWar
A simple turn-based strategy game using Phaser 3
Stars: ✭ 22 (-18.52%)
Mutual labels:  gamedev
awesome-playdate
A list of awesome resources for Playdate (https://play.date) game development and the Playdate SDK (https://play.date/dev/)
Stars: ✭ 149 (+451.85%)
Mutual labels:  gamedev
agones-event-broadcaster
Broadcast Agones GameServers and Fleets states to the external world
Stars: ✭ 22 (-18.52%)
Mutual labels:  gamedev

Magnum tips

TranslateController

_translateController = new TranslateController{&_scene, &_debugDrawables};

// controller only works if it has children
Object3D *cube = new Object3D{_translateController};
new CubeDrawable{*_cube, &_drawables};

// disable controller
cube->setParent(&_scene);

// handle mouse events
void MyApplication::mouseMoveEvent(MouseMoveEvent& event) {
  Vector2 screenPoint = Vector2{event.position()} / Vector2{windowSize()};
  Ray cameraRay = getCameraToViewportRay(*_camera, screenPoint);

  _translateController->move(cameraRay);
}

void MyApplication::mousePressEvent(MouseEvent& event) {
  if (event.button() == MouseEvent::Button::Left) {
    Vector2 screenPoint = Vector2{event.position()} / Vector2{windowSize()};
    Ray cameraRay = getCameraToViewportRay(*_camera, screenPoint);

    _translateController->grab(cameraRay);
  }
}

void MyApplication::mouseReleaseEvent(MouseEvent& event) {
  if (event.button() == MouseEvent::Button::Left) {
    _translateController->release();
  }
}

TranslateController

LineRenderer

_lineRenderer = new LineRenderer{_scene, &_debugDrawables};

// static lines (from, to, color)
_lineRenderer->add({ 0, 0, 0 }, { 1, 1, 1 }, { 1, 0, 0 });
_lineRenderer->add({ -1, 2, 0 }, { 1, 1, 1 }, { 0, 1, 0 });

// dynamic line
auto line = _lineRenderer->add({ 0, 0, 0 }, { 1, 1, 1 });
line->setTo({ -1, 2, 0 });

LineRenderer

ThirdPersonCameraController

_cameraController = new ThirdPersonCameraController{_scene};
_cameraController->camera()
  .setAspectRatioPolicy(SceneGraph::AspectRatioPolicy::Extend)
  .setProjectionMatrix(Matrix4::perspectiveProjection(Deg(60.0f), 4.0f/3.0f, 0.01f, 200.0f))
  .setViewport(GL::defaultFramebuffer.viewport().size());

// ...

_cameraController->translate({ 5, 0, 0 });

// ...

void MyApplication::drawEvent() {
  GL::defaultFramebuffer.clear(GL::FramebufferClear::Color|GL::FramebufferClear::Depth);

  _cameraController->camera().draw(_drawables);

  // ...
}

void MyApplication::mouseMoveEvent(MouseMoveEvent& event) {
  if (event.buttons() == MouseMoveEvent::Button::Left) {
    _cameraController->move(event.relativePosition());
  }
}

ThirdPersonCameraController

GridRenderer

DebugTools::ResourceManager _debugManager;
SceneGraph::DrawableGroup3D _debugDrawables;

Scene3D _scene;

new GridRenderer{_scene, &_debugDrawables};

_camera->draw(_debugDrawables);

GridRenderer

MathUtils

getCameraToViewportRay:

Vector2 screenPoint = Vector2{_mousePosition} / Vector2{windowSize()};
Ray cameraRay = getCameraToViewportRay(_cameraController->camera(), screenPoint);

Vector4 ground = Math::planeEquation(Vector3{0, 1, 0}, Vector3(0));
Float t = Math::Intersection::planeLine(ground, cameraRay.origin, cameraRay.direction);

if (!Magnum::Math::isInf(t) && !Magnum::Math::isNan(t)) {
  Vector3 point = cameraRay.origin + cameraRay.direction * t;
  _line->setTo(point);
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].