renderer.cpp 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #include <WallpaperEngine/Irrlicht/Irrlicht.h>
  2. #include <WallpaperEngine/video/renderer.h>
  3. namespace WallpaperEngine
  4. {
  5. namespace video
  6. {
  7. void renderer::queueNode (node* node)
  8. {
  9. s_nodes.push_back (node);
  10. }
  11. void renderer::setupOrthographicCamera (WallpaperEngine::scene* scene)
  12. {
  13. setupOrthographicCamera (
  14. scene->getProjectionWidth (),
  15. scene->getProjectionHeight (),
  16. scene->getCamera ()->getCenter (),
  17. scene->getCamera ()->getEye (),
  18. scene->getCamera ()->getUp ().X,
  19. scene->getCamera ()->getUp ().Y
  20. );
  21. }
  22. void renderer::setupOrthographicCamera (irr::f32 width, irr::f32 height, irr::core::vector3df position, irr::core::vector3df lookat, irr::f32 znear, irr::f32 zfar)
  23. {
  24. irr::core::matrix4 identity; identity.makeIdentity ();
  25. irr::core::matrix4 orthoProjection; orthoProjection.buildProjectionMatrixOrthoLH(
  26. width,
  27. height,
  28. znear,
  29. zfar
  30. );
  31. WallpaperEngine::Irrlicht::camera = WallpaperEngine::Irrlicht::device->getSceneManager ()->addCameraSceneNode (0, position, lookat);
  32. WallpaperEngine::Irrlicht::camera->setProjectionMatrix (orthoProjection);
  33. WallpaperEngine::Irrlicht::driver->setTransform (irr::video::ETS_PROJECTION, orthoProjection);
  34. WallpaperEngine::Irrlicht::driver->setTransform (irr::video::ETS_VIEW, identity);
  35. WallpaperEngine::Irrlicht::driver->setTransform (irr::video::ETS_WORLD, identity);
  36. }
  37. void renderer::render ()
  38. {
  39. if (WallpaperEngine::Irrlicht::driver == nullptr) return;
  40. WallpaperEngine::Irrlicht::driver->beginScene(true, true, irr::video::SColor(0, 0, 0, 0));
  41. std::vector<node*>::const_iterator cur = s_nodes.begin ();
  42. std::vector<node*>::const_iterator end = s_nodes.end ();
  43. for(; cur != end; cur ++)
  44. {
  45. (*cur)->render ();
  46. }
  47. WallpaperEngine::Irrlicht::driver->endScene ();
  48. }
  49. std::vector<node*> renderer::s_nodes;
  50. }
  51. };