This commit is contained in:
2024-01-15 11:14:19 -05:00
parent 2f01c1f0eb
commit b552bf2baf
9 changed files with 30 additions and 32 deletions

View File

@@ -42,7 +42,7 @@ CPMAddPackage(
CPMAddPackage(
NAME J3ML
URL https://git.redacted.cc/josh/j3ml/archive/test.zip
URL https://git.redacted.cc/josh/j3ml/archive/direction.zip
)
# BSD 2-clause license.

View File

@@ -11,5 +11,7 @@ public:
std::string name;
[[nodiscard]] static int getEntityCount();
[[nodiscard]] static int getMobyCount();
//TODO: Store these more elegantly of course.
VertexArray getPlayerBaseGeometry();
};

View File

@@ -12,15 +12,16 @@ public:
}
LinearAlgebra::Vector3 angle = {0,0,0}; //Pitch Yaw Roll, The orientation of the entity in the world,
LinearAlgebra::Vector3 velAngle = {0,0,0}; //The angle of an entities velocity.
LinearAlgebra::Vector3 Velocity;
float hVelocity;
float vVelocity;
LinearAlgebra::Vector3 upVector = {0.0f,1.0f,0.0f};
ScriptedMove sMove;
void move(LinearAlgebra::Vector3 a, float speed);
void move(LinearAlgebra::Vector3 a, float vel);
LinearAlgebra::Vector3 simulateMove(LinearAlgebra::Vector3 a, float speed);
void doSMove();
LinearAlgebra::Vector3 fAngle(); // forward angle
LinearAlgebra::Vector3 bAngle(); // back angle
LinearAlgebra::Vector3 lAngle(); // left angle
LinearAlgebra::Vector3 rAngle(); // right angle
void doSMove();
LinearAlgebra::Vector3 simulateMove(LinearAlgebra::Vector3 a, float speed);
};

View File

@@ -1,25 +1,13 @@
#pragma once
#include <cstdint>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <functional>
#include <J3ML/LinearAlgebra.h>
#include <J3ML/LinearAlgebra/Matrix4x4.h>
#include <J3ML/LinearAlgebra/Vector3.h>
#include <cassert>
struct Movement {
LinearAlgebra::Vector3 angle;
LinearAlgebra::Vector3 position;
};
inline namespace VectorMath {
//Basically an aimbot.
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

@@ -23,6 +23,7 @@ void Render::pre_render() {
engine->world->entityList()->storeEntity(skybox);
auto *player = new Player();
player->angle = {0, 0, 0};
player->SetPos({0,-2,0});
player->draw = true;
engine->world->entityList()->storeEntity(player);
}

View File

@@ -38,24 +38,24 @@ void Camera::modeBinds() {
}
void Camera::freeCam() {
if (engine->window->keyDown(SCANCODE::S)) {
move(bAngle(),2);
move(bAngle(), 4);
}
if (engine->window->keyDown(SCANCODE::W)) {
move(fAngle(),2);
move(fAngle(), 4);
}
if (engine->window->keyDown(SCANCODE::A)) {
move(lAngle(), 2);
move(lAngle(), 4);
}
if (engine->window->keyDown(SCANCODE::D)) {
move(rAngle(),2);
move(rAngle(), 4);
}
if (engine->window->keyDown(SCANCODE::SPACE)) {
this->position.y += 5*engine->frameDelta;
move(upVector, 4);
}
if (engine->window->keyDown(SCANCODE::LEFT_SHIFT)) {
this->position.y -= 5*engine->frameDelta;
move(-upVector, 4);
}
if (engine->window->keyDown(SCANCODE::LEFT)) {

View File

@@ -1,10 +1,11 @@
#include <types/moby.h>
void Moby::move(LinearAlgebra::Vector3 a, float speed)
{
this->position.z += (speed*engine->frameDelta) * a.x;
this->position.y += (speed*engine->frameDelta) * a.y;
this->position.x += (speed*engine->frameDelta) * a.z;
void Moby::move(LinearAlgebra::Vector3 a, float vel) {
if (a == upVector || a == -upVector) {
position.y += (vel*engine->frameDelta) * a.y;
}
position.z += (vel*engine->frameDelta) * a.x;
position.x += (vel*engine->frameDelta) * a.z;
}
//Returns the position we'd be at *if* we did a movement.

View File

@@ -4,9 +4,13 @@ void Player::pre_render() {
geometry = engine->world->getPlayerBaseGeometry();
geometry.scale(0.75f);
boundingBox = Collision::calculateBoundingBox(&geometry, angle);
position = {0,-2,0};
//std::cout << "Occluded: " << occluded << std::endl;
this->angle.y += 64*engine->frameDelta;
hVelocity = 2;
this->angle.y += 96*engine->frameDelta;
velAngle = -angle;
move(LinearAlgebra::Vector3::Direction(velAngle), hVelocity);
move(upVector, vVelocity);
//this->angle.x -= 64*engine->frameDelta;
//this->angle.x = 1;
}

View File

@@ -1,7 +1,8 @@
#include <engine/engine.h>
#include <types/vertex.h>
#include <cmath>
#include "J3ML/LinearAlgebra/EulerAngle.h"
#include <J3ML/LinearAlgebra/EulerAngle.h>
#include <J3ML/LinearAlgebra/Quaternion.h>
void VertexArray::scale(GLfloat multiplier) {
for (auto & vertex : vertices) {