// ---------------------------------------------------------------- // From Game Programming in C++ by Sanjay Madhav // Copyright (C) 2017 Sanjay Madhav. All rights reserved. // // Released under the BSD License // See LICENSE in root directory for full details. // ---------------------------------------------------------------- #include "CameraActor.h" #include "MoveComponent.h" #include "SDL/SDL_scancode.h" #include "Renderer.h" #include "Game.h" CameraActor::CameraActor(Game* game) :Actor(game) { mMoveComp = new MoveComponent(this); } void CameraActor::UpdateActor(float deltaTime) { Actor::UpdateActor(deltaTime); // Compute new camera from this actor Vector3 cameraPos = GetPosition(); Vector3 target = GetPosition() + GetForward() * 100.0f; Vector3 up = Vector3::UnitZ; Matrix4 view = Matrix4::CreateLookAt(cameraPos, target, up); GetGame()->GetRenderer()->SetViewMatrix(view); } void CameraActor::ActorInput(const uint8_t* keys) { float forwardSpeed = 0.0f; float angularSpeed = 0.0f; // wasd movement if (keys[SDL_SCANCODE_W]) { forwardSpeed += 300.0f; } if (keys[SDL_SCANCODE_S]) { forwardSpeed -= 300.0f; } if (keys[SDL_SCANCODE_A]) { angularSpeed -= Math::TwoPi; } if (keys[SDL_SCANCODE_D]) { angularSpeed += Math::TwoPi; } mMoveComp->SetForwardSpeed(forwardSpeed); mMoveComp->SetAngularSpeed(angularSpeed); }