This commit is contained in:
2023-12-05 14:12:10 -05:00
parent 1cf1e11d4f
commit 826ec8e744
5 changed files with 19 additions and 22 deletions

View File

@@ -17,7 +17,6 @@ add_executable(SDL3D src/main.cpp
src/types/skybox.h
src/types/moby.h
src/types/animationSequence.h
src/engine/math.h
)
find_package(OpenGL)

View File

@@ -1,16 +0,0 @@
#pragma once
#include <cmath>
#include "../types/vector3.h"
namespace math {
float distance(Position sP, Position eP) {
return sqrt(pow(eP.x - sP.x, 2) + pow(eP.y - sP.y, 2) + pow(eP.z - sP.z, 2));
}
Angle calcAngle(Position sP, Position eP) {
Angle returned;
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 returned;
}
}

View File

@@ -2,7 +2,6 @@
#include "moby.h"
#include "player.h"
#include "../engine/engine.h"
#include "../engine/math.h"
#include <glm/glm.hpp>
#include "entityList.h"
@@ -35,11 +34,11 @@ public:
this->cameraMode = CameraMode::THIRD_PERSON;
if (cameraMode == CameraMode::THIRD_PERSON) {
std::cout << "Calculated Pitch: " << math::calcAngle(position,getPlayer()->position).x << " Calculated Yaw: " << math::calcAngle(position,getPlayer()->position).y << std::endl;
std::cout << "Calculated Pitch: " << VectorMath::calcAngle(position,getPlayer()->position).x << " Calculated Yaw: " << VectorMath::calcAngle(position,getPlayer()->position).y << std::endl;
this->position = getPlayer()->cameraPoint(2);
this->position.y += 0.5;
this->angle.x = math::calcAngle(position,getPlayer()->position).x;
this->angle.y = math::calcAngle(position,getPlayer()->position).y;
this->angle.x = VectorMath::calcAngle(position,getPlayer()->position).x;
this->angle.y = VectorMath::calcAngle(position,getPlayer()->position).y;
}
//if (engine->frameCount == 5000)

View File

@@ -17,6 +17,7 @@ public:
//These will be declared in each type of entity and not in the base entity because
//It'll be different for each one.
//The "camera point" is the position the camera will want to be while following the player.
Position cameraPoint (float distance) {
Position behindPosition = this->position;
Angle reverseDirection = this->bAngle();

View File

@@ -69,4 +69,18 @@ public:
float distanceFrom(Position p) {
return sqrt(pow(this->x - p.x, 2) + pow(this->y - p.y, 2) + pow(this->z - p.z, 2));
}
};
};
namespace VectorMath {
float distance(Position sP, Position eP) {
return sqrt(pow(eP.x - sP.x, 2) + pow(eP.y - sP.y, 2) + pow(eP.z - sP.z, 2));
}
//Basically an aimbot.
Angle calcAngle(Position sP, Position 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) / distance(sP, eP)) * 180.0f / M_PI))),static_cast<float>((atan2f(eP.x - sP.x,eP.z - sP.z) / M_PI * 180.0f)),0};
}
}