64 lines
1.8 KiB
C++
64 lines
1.8 KiB
C++
#include "Player.h"
|
|
#include "Camera.h"
|
|
#include <iostream>
|
|
|
|
Player::Player(glm::vec3 Position, glm::vec3 Rotation)
|
|
: GameObject(Position, Rotation, glm::vec3(1.0f, 1.0f, 1.0f)),
|
|
PlayerCamera(new Camera(glm::vec3(0.0f, 1.0f, 0.0f)))
|
|
{
|
|
|
|
PlayerCamera->Position = Position + PlayerCamera->CameraOffset;
|
|
PlayerCamera->WorldUp = this->WorldUp;
|
|
std::cout << "{" << Position.x << ", " << Position.y << ", " << Position.z << "}" << std::endl;
|
|
std::cout << "{" << PlayerCamera->Position.x << ", " << PlayerCamera->Position.y << ", " << PlayerCamera->Position.z << "}" << std::endl;
|
|
}
|
|
|
|
void Player::Update()
|
|
{
|
|
|
|
}
|
|
|
|
void Player::ProcessKeyboard(EInputDirection Direction, float Delta)
|
|
{
|
|
float Velocity = bIsRunning ? RunSpeed : WalkSpeed;
|
|
Velocity = Velocity * Delta;
|
|
if (Direction == FORWARD)
|
|
Position += Front * Velocity;
|
|
if (Direction == BACKWARD)
|
|
Position -= Front * Velocity;
|
|
if (Direction == LEFT)
|
|
Position -= Right * Velocity;
|
|
if (Direction == RIGHT)
|
|
Position += Right * Velocity;
|
|
|
|
PlayerCamera->Position = Position + PlayerCamera->CameraOffset;
|
|
PlayerCamera->WorldUp = this->WorldUp;
|
|
}
|
|
|
|
void Player::ProcessMouseMovement(float XOffset, float YOffset, GLboolean bConstrainPitch)
|
|
{
|
|
XOffset *= MOUSE_SENSITIVITY;
|
|
YOffset *= MOUSE_SENSITIVITY;
|
|
|
|
Yaw += XOffset;
|
|
PlayerCamera->Yaw = Yaw;
|
|
|
|
PlayerCamera->ProcessMouseMovement(XOffset, YOffset);
|
|
UpdatePlayerVectors();
|
|
}
|
|
|
|
glm::mat4 Player::GetViewMatrix() const
|
|
{
|
|
return PlayerCamera->GetViewMatrix();
|
|
}
|
|
|
|
void Player::UpdatePlayerVectors()
|
|
{
|
|
glm::vec3 UpdatedFront;
|
|
UpdatedFront.x = cos(glm::radians(Yaw)) * cos(0);
|
|
UpdatedFront.y = sin(0);
|
|
UpdatedFront.z = sin(glm::radians(Yaw)) * cos(0);
|
|
Front = glm::normalize(UpdatedFront);
|
|
Right = glm::normalize(glm::cross(Front, WorldUp));
|
|
Up = glm::normalize(glm::cross(Right, Front));
|
|
} |