You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

127 lines
3.5 KiB

  1. //
  2. // Lol Engine — BtPhys tutorial
  3. //
  4. // Copyright © 2009—2015 Benjamin “Touky” Huet <huet.benjamin@gmail.com>
  5. // © 2012—2015 Sam Hocevar <sam@hocevar.net>
  6. //
  7. // Lol Engine is free software. It comes without any warranty, to
  8. // the extent permitted by applicable law. You can redistribute it
  9. // and/or modify it under the terms of the Do What the Fuck You Want
  10. // to Public License, Version 2, as published by the WTFPL Task Force.
  11. // See http://www.wtfpl.net/ for more details.
  12. //
  13. #if HAVE_CONFIG_H
  14. # include "config.h"
  15. #endif
  16. #include <lol/engine.h>
  17. #include "loldebug.h"
  18. using namespace lol;
  19. //#include "physics/lolphysics.h"
  20. //#include "physics/easyphysics.h"
  21. #include "nacl_phystest.h"
  22. //using namespace lol::phys;
  23. int gNumObjects = 64;
  24. Nacl_PhysTest::Nacl_PhysTest(bool editor)
  25. {
  26. /* Register an input controller for the keyboard */
  27. m_controller = new Controller("Default");
  28. m_controller->GetKey(KEY_MOVE_FORWARD).Bind("Keyboard", "Up");
  29. m_controller->GetKey(KEY_MOVE_BACK).Bind("Keyboard", "Down");
  30. m_controller->GetKey(KEY_MOVE_LEFT).Bind("Keyboard", "Left");
  31. m_controller->GetKey(KEY_MOVE_RIGHT).Bind("Keyboard", "Right");
  32. m_controller->GetKey(KEY_MOVE_JUMP).Bind("Keyboard", "Space");
  33. m_controller->GetKey(KEY_MOVE_UP).Bind("Keyboard", "PageUp");
  34. m_controller->GetKey(KEY_MOVE_DOWN).Bind("Keyboard", "PageDown");
  35. m_controller->GetKey(KEY_QUIT).Bind("Keyboard", "Escape");
  36. /* Create a camera that matches the settings of XNA BtPhysTest */
  37. m_camera = new Camera();
  38. m_camera->SetView(vec3(50.f, 50.f, 0.f),
  39. vec3(0.f, 0.f, 0.f),
  40. vec3(0, 1, 0));
  41. m_camera->SetProjection(radians(45.f), .1f, 1000.f, (float)Video::GetSize().x, (float)Video::GetSize().y / (float)Video::GetSize().x);
  42. Scene::GetScene().PushCamera(m_camera);
  43. m_ready = false;
  44. /*
  45. m_simulation = new Simulation();
  46. m_simulation->SetWorldLimit(vec3(-1000.0f, -1000.0f, -1000.0f), vec3(1000.0f, 1000.0f, 1000.0f));
  47. m_simulation->Init();
  48. vec3 NewGravity = vec3(.0f, -10.0f, .0f);
  49. m_simulation->SetGravity(NewGravity);
  50. m_simulation->SetContinuousDetection(true);
  51. m_simulation->SetTimestep(1.f / 120.f);
  52. Ticker::Ref(m_simulation);
  53. */
  54. /* Add a white directional light */
  55. m_light1 = new Light();
  56. m_light1->SetPosition(vec3(0.2f, 0.2f, 0.f));
  57. m_light1->SetColor(vec4(0.5f, 0.5f, 0.5f, 1.f));
  58. m_light1->SetType(LightType::Directional);
  59. Ticker::Ref(m_light1);
  60. /* Add an orangeish point light */
  61. m_light2 = new Light();
  62. m_light2->SetPosition(vec3(-15.f, 15.f, 15.f));
  63. m_light2->SetColor(vec4(0.4f, 0.3f, 0.2f, 1.f));
  64. m_light2->SetType(LightType::Point);
  65. Ticker::Ref(m_light2);
  66. }
  67. void Nacl_PhysTest::TickGame(float seconds)
  68. {
  69. WorldEntity::TickGame(seconds);
  70. if (m_controller->IsKeyReleased(KEY_QUIT))
  71. Ticker::Shutdown();
  72. }
  73. void Nacl_PhysTest::TickDraw(float seconds, Scene &scene)
  74. {
  75. WorldEntity::TickDraw(seconds, scene);
  76. if (!m_ready)
  77. {
  78. /* FIXME: this object never cleans up */
  79. m_ready = true;
  80. }
  81. else
  82. {
  83. }
  84. }
  85. Nacl_PhysTest::~Nacl_PhysTest()
  86. {
  87. Scene::GetScene().PopCamera(m_camera);
  88. Ticker::Unref(m_light1);
  89. Ticker::Unref(m_light2);
  90. //Ticker::Unref(m_simulation);
  91. }
  92. int main(int argc, char **argv)
  93. {
  94. sys::init(argc, argv);
  95. Application app("Nacl_PhysTest", ivec2(1280, 960), 60.0f);
  96. new Nacl_PhysTest(argc > 1);
  97. app.ShowPointer(false);
  98. app.Run();
  99. return EXIT_SUCCESS;
  100. }