LoadSceneSample.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. #include "LoadSceneSample.h"
  2. #include "SamplesGame.h"
  3. #if defined(ADD_SAMPLE)
  4. ADD_SAMPLE("Scene", "Load Scene", LoadSceneSample, 2);
  5. #endif
  6. LoadSceneSample::LoadSceneSample()
  7. : _font(NULL), _scene(NULL), _wireFrame(false)
  8. {
  9. }
  10. void LoadSceneSample::initialize()
  11. {
  12. // Create the font for drawing the framerate.
  13. _font = Font::create("res/common/arial.gpb");
  14. _scene = Scene::load("res/common/sample.scene");
  15. // Update the aspect ratio for our scene's camera to match the current device resolution
  16. _scene->getActiveCamera()->setAspectRatio(getAspectRatio());
  17. }
  18. void LoadSceneSample::finalize()
  19. {
  20. SAFE_RELEASE(_font);
  21. SAFE_RELEASE(_scene);
  22. }
  23. void LoadSceneSample::update(float elapsedTime)
  24. {
  25. }
  26. void LoadSceneSample::render(float elapsedTime)
  27. {
  28. // Clear the color and depth buffers
  29. clear(CLEAR_COLOR_DEPTH, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0);
  30. // Visit all the nodes in the scene, drawing the models/mesh.
  31. _scene->visit(this, &LoadSceneSample::drawScene);
  32. drawFrameRate(_font, Vector4(0, 0.5f, 1, 1), 5, 1, getFrameRate());
  33. }
  34. void LoadSceneSample::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
  35. {
  36. switch (evt)
  37. {
  38. case Touch::TOUCH_PRESS:
  39. if (x < 75 && y < 50)
  40. {
  41. // Toggle Vsync if the user touches the top left corner
  42. setVsync(!isVsync());
  43. return;
  44. }
  45. break;
  46. case Touch::TOUCH_RELEASE:
  47. break;
  48. case Touch::TOUCH_MOVE:
  49. break;
  50. };
  51. }
  52. void LoadSceneSample::keyEvent(Keyboard::KeyEvent evt, int key)
  53. {
  54. if (evt == Keyboard::KEY_PRESS)
  55. {
  56. switch (key)
  57. {
  58. case Keyboard::KEY_W:
  59. case Keyboard::KEY_CAPITAL_W:
  60. _wireFrame = !_wireFrame;
  61. break;
  62. }
  63. }
  64. }
  65. bool LoadSceneSample::drawScene(Node* node)
  66. {
  67. Model* model = node->getModel();
  68. if (model)
  69. model->draw(_wireFrame);
  70. return true;
  71. }