| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149 |
- // Copyright (C) 2009-2017, Panagiotis Christopoulos Charitos and contributors.
- // All rights reserved.
- // Code licensed under the BSD License.
- // http://www.anki3d.org/LICENSE
- #include "Framework.h"
- using namespace anki;
- Error SampleApp::init(int argc, char** argv, CString sampleName)
- {
- if(!directoryExists("assets"))
- {
- ANKI_LOGE("Cannot find directory \"assets\". YOU ARE RUNNING THE SAMPLE FROM THE WRONG DIRECTORY. "
- "To run %s you have to navigate to the /path/to/anki/samples/%s and then execute it",
- argv[0],
- &sampleName[0]);
- return Error::USER_DATA;
- }
- // Init the super class
- Config config;
- config.set("window.fullscreenDesktopResolution", true);
- config.set("rsrc.dataPaths", ".:../..");
- config.set("window.debugContext", 0);
- ANKI_CHECK(config.setFromCommandLineArguments(argc, argv));
- ANKI_CHECK(App::init(config, allocAligned, nullptr));
- // Input
- getInput().lockCursor(true);
- getInput().hideCursor(true);
- getInput().moveCursor(Vec2(0.0f));
- // Some renderer stuff
- getMainRenderer().getOffscreenRenderer().getVolumetric().setFogParticleColor(Vec3(1.0f, 0.9f, 0.9f) * 0.0001f);
- ANKI_CHECK(sampleExtraInit());
- return Error::NONE;
- }
- Error SampleApp::userMainLoop(Bool& quit)
- {
- const F32 MOVE_DISTANCE = 0.1f;
- const F32 ROTATE_ANGLE = toRad(2.5f);
- const F32 MOUSE_SENSITIVITY = 9.0f;
- quit = false;
- SceneGraph& scene = getSceneGraph();
- Renderer& renderer = getMainRenderer().getOffscreenRenderer();
- Input& in = getInput();
- if(in.getKey(KeyCode::ESCAPE))
- {
- quit = true;
- return Error::NONE;
- }
- // move the camera
- static MoveComponent* mover = &scene.getActiveCamera().getComponent<MoveComponent>();
- if(in.getKey(KeyCode::_1) == 1)
- {
- mover = &scene.getActiveCamera().getComponent<MoveComponent>();
- }
- if(in.getKey(KeyCode::F1) == 1)
- {
- renderer.getDbg().setEnabled(!renderer.getDbg().getEnabled());
- }
- if(in.getKey(KeyCode::F2) == 1)
- {
- renderer.getDbg().flipFlags(DbgFlag::SPATIAL_COMPONENT);
- }
- if(in.getKey(KeyCode::F6) == 1)
- {
- renderer.getDbg().switchDepthTestEnabled();
- }
- if(in.getKey(KeyCode::UP))
- {
- mover->rotateLocalX(ROTATE_ANGLE);
- }
- if(in.getKey(KeyCode::DOWN))
- {
- mover->rotateLocalX(-ROTATE_ANGLE);
- }
- if(in.getKey(KeyCode::LEFT))
- {
- mover->rotateLocalY(ROTATE_ANGLE);
- }
- if(in.getKey(KeyCode::RIGHT))
- {
- mover->rotateLocalY(-ROTATE_ANGLE);
- }
- if(in.getKey(KeyCode::A))
- {
- mover->moveLocalX(-MOVE_DISTANCE);
- }
- if(in.getKey(KeyCode::D))
- {
- mover->moveLocalX(MOVE_DISTANCE);
- }
- if(in.getKey(KeyCode::Z))
- {
- mover->moveLocalY(MOVE_DISTANCE);
- }
- if(in.getKey(KeyCode::SPACE))
- {
- mover->moveLocalY(-MOVE_DISTANCE);
- }
- if(in.getKey(KeyCode::W))
- {
- mover->moveLocalZ(-MOVE_DISTANCE);
- }
- if(in.getKey(KeyCode::S))
- {
- mover->moveLocalZ(MOVE_DISTANCE);
- }
- if(in.getKey(KeyCode::Q))
- {
- mover->rotateLocalZ(ROTATE_ANGLE);
- }
- if(in.getKey(KeyCode::E))
- {
- mover->rotateLocalZ(-ROTATE_ANGLE);
- }
- if(in.getMousePosition() != Vec2(0.0))
- {
- F32 angY = -ROTATE_ANGLE * in.getMousePosition().x() * MOUSE_SENSITIVITY * getMainRenderer().getAspectRatio();
- mover->rotateLocalY(angY);
- mover->rotateLocalX(ROTATE_ANGLE * in.getMousePosition().y() * MOUSE_SENSITIVITY);
- }
- return Error::NONE;
- }
|