Framework.cpp 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. // Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
  2. // All rights reserved.
  3. // Code licensed under the BSD License.
  4. // http://www.anki3d.org/LICENSE
  5. #include "Framework.h"
  6. using namespace anki;
  7. Error SampleApp::init(int argc, char** argv)
  8. {
  9. // Init the super class
  10. Config config;
  11. config.set("fullscreenDesktopResolution", true);
  12. config.set("dataPaths", ".:../..");
  13. config.set("debugContext", 0);
  14. ANKI_CHECK(config.setFromCommandLineArguments(argc, argv));
  15. ANKI_CHECK(App::init(config, allocAligned, nullptr));
  16. // Input
  17. getInput().lockCursor(true);
  18. getInput().hideCursor(true);
  19. getInput().moveCursor(Vec2(0.0));
  20. // Some renderer stuff
  21. getMainRenderer().getOffscreenRenderer().getVolumetric().setFogParticleColor(Vec3(1.0, 0.9, 0.9) * 0.0001);
  22. ANKI_CHECK(sampleExtraInit());
  23. return ErrorCode::NONE;
  24. }
  25. Error SampleApp::userMainLoop(Bool& quit)
  26. {
  27. const F32 MOVE_DISTANCE = 0.1;
  28. const F32 ROTATE_ANGLE = toRad(2.5);
  29. const F32 MOUSE_SENSITIVITY = 9.0;
  30. quit = false;
  31. SceneGraph& scene = getSceneGraph();
  32. Renderer& renderer = getMainRenderer().getOffscreenRenderer();
  33. Input& in = getInput();
  34. if(in.getKey(KeyCode::ESCAPE))
  35. {
  36. quit = true;
  37. return ErrorCode::NONE;
  38. }
  39. // move the camera
  40. static MoveComponent* mover = &scene.getActiveCamera().getComponent<MoveComponent>();
  41. if(in.getKey(KeyCode::_1) == 1)
  42. {
  43. mover = &scene.getActiveCamera().getComponent<MoveComponent>();
  44. }
  45. if(in.getKey(KeyCode::F1) == 1)
  46. {
  47. renderer.getDbg().setEnabled(!renderer.getDbg().getEnabled());
  48. }
  49. if(in.getKey(KeyCode::F2) == 1)
  50. {
  51. renderer.getDbg().flipFlags(DbgFlag::SPATIAL_COMPONENT);
  52. }
  53. if(in.getKey(KeyCode::F6) == 1)
  54. {
  55. renderer.getDbg().switchDepthTestEnabled();
  56. }
  57. if(in.getKey(KeyCode::UP))
  58. {
  59. mover->rotateLocalX(ROTATE_ANGLE);
  60. }
  61. if(in.getKey(KeyCode::DOWN))
  62. {
  63. mover->rotateLocalX(-ROTATE_ANGLE);
  64. }
  65. if(in.getKey(KeyCode::LEFT))
  66. {
  67. mover->rotateLocalY(ROTATE_ANGLE);
  68. }
  69. if(in.getKey(KeyCode::RIGHT))
  70. {
  71. mover->rotateLocalY(-ROTATE_ANGLE);
  72. }
  73. if(in.getKey(KeyCode::A))
  74. {
  75. mover->moveLocalX(-MOVE_DISTANCE);
  76. }
  77. if(in.getKey(KeyCode::D))
  78. {
  79. mover->moveLocalX(MOVE_DISTANCE);
  80. }
  81. if(in.getKey(KeyCode::Z))
  82. {
  83. mover->moveLocalY(MOVE_DISTANCE);
  84. }
  85. if(in.getKey(KeyCode::SPACE))
  86. {
  87. mover->moveLocalY(-MOVE_DISTANCE);
  88. }
  89. if(in.getKey(KeyCode::W))
  90. {
  91. mover->moveLocalZ(-MOVE_DISTANCE);
  92. }
  93. if(in.getKey(KeyCode::S))
  94. {
  95. mover->moveLocalZ(MOVE_DISTANCE);
  96. }
  97. if(in.getKey(KeyCode::Q))
  98. {
  99. mover->rotateLocalZ(ROTATE_ANGLE);
  100. }
  101. if(in.getKey(KeyCode::E))
  102. {
  103. mover->rotateLocalZ(-ROTATE_ANGLE);
  104. }
  105. if(in.getMousePosition() != Vec2(0.0))
  106. {
  107. F32 angY = -ROTATE_ANGLE * in.getMousePosition().x() * MOUSE_SENSITIVITY * getMainRenderer().getAspectRatio();
  108. mover->rotateLocalY(angY);
  109. mover->rotateLocalX(ROTATE_ANGLE * in.getMousePosition().y() * MOUSE_SENSITIVITY);
  110. }
  111. return ErrorCode::NONE;
  112. }