Fix third person

This commit is contained in:
2024-01-24 13:43:17 -05:00
parent 73c9d074f8
commit 397819e727
4 changed files with 11 additions and 11 deletions

View File

@@ -7,7 +7,7 @@ inline namespace VectorMath {
inline LinearAlgebra::Vector3 calcAngle(LinearAlgebra::Vector3 sP, LinearAlgebra::Vector3 eP) {
//returned.x = -(asinf((eP.y - sP.y) / distance(sP, eP)) * 180.0f / M_PI);
//returned.y = (atan2f(eP.x - sP.x,eP.z - sP.z) / M_PI * 180.0f);
return {static_cast<float>((-(asinf((eP.y - sP.y) / LinearAlgebra::Vector3::Distance(sP, eP)) * 180.0f / Math::Pi))),static_cast<float>((atan2f(eP.x - sP.x,eP.z - sP.z) / Math::Pi * 180.0f)),0};
return {static_cast<float>((-(asinf((eP.y - sP.y) / LinearAlgebra::Vector3::Distance(sP, eP)) * 180.0f / Math::Pi))),static_cast<float>(-(atan2f(eP.x - sP.x,eP.z - sP.z) / Math::Pi * 180.0f)),0};
}
}

View File

@@ -80,11 +80,11 @@ void Camera::thirdPerson() {
if (engine->debug)
std::cout << "Calculated Pitch: " << VectorMath::calcAngle(position,player->GetPos()).x << " Calculated Yaw: " << VectorMath::calcAngle(position,player->GetPos()).y << std::endl;
position = player->cameraPoint(2);
position = player->cameraPoint(5);
//Make the camera pitch down a little bit.
this->position.y += 0.5;
this->angle.x = VectorMath::calcAngle(position,player->GetPos()).x;
this->angle.y = VectorMath::calcAngle(position,player->GetPos()).y;
this->angle.y = VectorMath::calcAngle(position,player->GetPos()).y;
}
void Camera::pre_render() {
modeBinds();
@@ -101,7 +101,7 @@ void Camera::render() {
//TODO
//this->angle.clamp();
glRotatef(angle.x,1.0f, 0.0f, 0.0f);
glRotatef(-angle.y,0.0f, 1.0f, 0.0f);
glRotatef(angle.y,0.0f, 1.0f, 0.0f);
glRotatef(angle.z,0.0f, 0.0f, 1.0f);
glTranslatef(0.0f, 0.0f, 0.0f);

View File

@@ -3,7 +3,6 @@
//This is in the local space.
VertexArray Collision::calculateBoundingBox(VertexArray* vArray, const LinearAlgebra::Vector3& angle) {
VertexArray input = VertexArray::rotate(vArray, angle);
VertexArray output;
float minX = std::numeric_limits<float>::max();
float minY = std::numeric_limits<float>::max();
@@ -12,7 +11,7 @@ VertexArray Collision::calculateBoundingBox(VertexArray* vArray, const LinearAlg
float maxY = -std::numeric_limits<float>::max();
float maxZ = -std::numeric_limits<float>::max();
for (const auto& vertex : input.vertices) {
for (const auto& vertex : vArray->vertices) {
if (vertex.x < minX)
minX = vertex.x;
if (vertex.y < minY)
@@ -36,6 +35,7 @@ VertexArray Collision::calculateBoundingBox(VertexArray* vArray, const LinearAlg
output.vertices.push_back(Vertex(maxX, minY, maxZ));
output.vertices.push_back(Vertex(minX, maxY, maxZ));
output.vertices.push_back(Vertex(maxX, maxY, maxZ));
output.rotate(angle);
//std::cout << "Bounding Box: " << std::endl;
//for (auto vertex : output.vertices)

View File

@@ -3,11 +3,11 @@
void Player::pre_render() {
boundingBox = Collision::calculateBoundingBox(getGeometry(), angle);
hVelocity = 2;
this->angle.y += 96*engine->frameDelta;
//this->angle.y += 96*engine->frameDelta;
velAngle = angle;
hMove(LinearAlgebra::Vector3::Direction({0, velAngle.y, 0}), hVelocity);
//hMove(LinearAlgebra::Vector3::Direction({0, velAngle.y, 0}), hVelocity);
//vMove(vVelocity);
this->angle.x += 96*engine->frameDelta;
this->angle.y += 96*engine->frameDelta;
}
void Player::render() {
@@ -31,8 +31,8 @@ void Player::render() {
LinearAlgebra::Vector3 Player::cameraPoint(float distance) {
LinearAlgebra::Vector3 behindPosition = this->position;
LinearAlgebra::Vector3 reverseDirection = this->bAngle();
behindPosition.x -= reverseDirection.x * distance;
behindPosition.y -= reverseDirection.y * distance;
behindPosition.x += reverseDirection.x * distance;
behindPosition.y += reverseDirection.y * distance;
behindPosition.z -= reverseDirection.z * distance;
return behindPosition;