| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- #include "SceneLoadSample.h"
- #include "SamplesGame.h"
- #if defined(ADD_SAMPLE)
- ADD_SAMPLE("Graphics", "Scene Loading", SceneLoadSample, 16);
- #endif
- SceneLoadSample::SceneLoadSample()
- : _font(NULL), _scene(NULL), _wireFrame(false)
- {
-
- }
- void SceneLoadSample::initialize()
- {
- // Create the font for drawing the framerate.
- _font = Font::create("res/ui/arial.gpb");
- _scene = Scene::load("res/common/sample.scene");
- // Update the aspect ratio for our scene's camera to match the current device resolution
- _scene->getActiveCamera()->setAspectRatio(getAspectRatio());
- // Visit all the nodes in the scene, drawing the models/mesh.
- _scene->visit(this, &SceneLoadSample::initializeMaterials);
- }
- bool SceneLoadSample::initializeMaterials(Node* node)
- {
- Model* model = node->getModel();
- if (model)
- {
- Material* material = model->getMaterial();
- // For this sample we will only bind a single light to each object in the scene.
- MaterialParameter* colorParam = material->getParameter("u_directionalLightColor[0]");
- colorParam->setValue(Vector3(0.75f, 0.75f, 0.75f));
- MaterialParameter* directionParam = material->getParameter("u_directionalLightDirection[0]");
- directionParam->setValue(Vector3(0, -1, 0));
- }
- return true;
- }
- void SceneLoadSample::finalize()
- {
- SAFE_RELEASE(_font);
- SAFE_RELEASE(_scene);
- }
- void SceneLoadSample::update(float elapsedTime)
- {
-
- }
- void SceneLoadSample::render(float elapsedTime)
- {
- // Clear the color and depth buffers
- clear(CLEAR_COLOR_DEPTH, 0.0f, 0.0f, 0.0f, 1.0f, 1.0f, 0);
- // Visit all the nodes in the scene, drawing the models/mesh.
- _scene->visit(this, &SceneLoadSample::drawScene);
- drawFrameRate(_font, Vector4(0, 0.5f, 1, 1), 5, 1, getFrameRate());
- }
- void SceneLoadSample::touchEvent(Touch::TouchEvent evt, int x, int y, unsigned int contactIndex)
- {
- switch (evt)
- {
- case Touch::TOUCH_PRESS:
- if (x < 75 && y < 50)
- {
- // Toggle Vsync if the user touches the top left corner
- setVsync(!isVsync());
- return;
- }
- break;
- case Touch::TOUCH_RELEASE:
- break;
- case Touch::TOUCH_MOVE:
- break;
- };
- }
- void SceneLoadSample::keyEvent(Keyboard::KeyEvent evt, int key)
- {
- if (evt == Keyboard::KEY_PRESS)
- {
- switch (key)
- {
- case Keyboard::KEY_W:
- case Keyboard::KEY_CAPITAL_W:
- _wireFrame = !_wireFrame;
- break;
- }
- }
- }
- bool SceneLoadSample::drawScene(Node* node)
- {
- Model* model = node->getModel();
- if (model)
- model->draw(_wireFrame);
- return true;
- }
|