simplify move & update j3ml

This commit is contained in:
2024-01-15 15:24:27 -05:00
parent b552bf2baf
commit 1855fd5739
6 changed files with 30 additions and 15 deletions

View File

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

View File

@@ -38,4 +38,6 @@ public:
void pre_render() override;
void render() override;
void post_render() override;
void hMove(LinearAlgebra::Vector3 a, float vel) override;
};

View File

@@ -16,7 +16,8 @@ public:
float vVelocity;
LinearAlgebra::Vector3 upVector = {0.0f,1.0f,0.0f};
ScriptedMove sMove;
void move(LinearAlgebra::Vector3 a, float vel);
virtual void hMove(LinearAlgebra::Vector3 a, float vel);
void vMove(float vel);
LinearAlgebra::Vector3 simulateMove(LinearAlgebra::Vector3 a, float speed);
void doSMove();
LinearAlgebra::Vector3 fAngle(); // forward angle

View File

@@ -17,6 +17,7 @@ void Camera::update()
//GLfloat matrix[16];
//glGetFloatv(GL_MODELVIEW_MATRIX, matrix);
//}
void Camera::modeBinds() {
if (engine->window->keyDown(SCANCODE::ZERO)) {
takingScreenshot = true;
@@ -38,24 +39,24 @@ void Camera::modeBinds() {
}
void Camera::freeCam() {
if (engine->window->keyDown(SCANCODE::S)) {
move(bAngle(), 4);
hMove(bAngle(), 4);
}
if (engine->window->keyDown(SCANCODE::W)) {
move(fAngle(), 4);
hMove(fAngle(), 4);
}
if (engine->window->keyDown(SCANCODE::A)) {
move(lAngle(), 4);
hMove(lAngle(), 4);
}
if (engine->window->keyDown(SCANCODE::D)) {
move(rAngle(), 4);
hMove(rAngle(), 4);
}
if (engine->window->keyDown(SCANCODE::SPACE)) {
move(upVector, 4);
vMove(4);
}
if (engine->window->keyDown(SCANCODE::LEFT_SHIFT)) {
move(-upVector, 4);
vMove(-4);
}
if (engine->window->keyDown(SCANCODE::LEFT)) {
@@ -115,4 +116,14 @@ void Camera::post_render() {
Geometry::Frustum Camera::getFrustum() {
Geometry::Camera cam = {this->position,this->fAngle(),this->rAngle(),this->upVector};
return Geometry::CreateFrustumFromCamera(cam, engine->window->getSize()[0] / engine->window->getSize()[1], engine->fov, engine->nearPlane, engine->farPlane);
}
}
void Camera::hMove(LinearAlgebra::Vector3 a, float vel) {
if (cameraMode == CameraMode::FREECAM) {
position.z += (vel * engine->frameDelta) * a.x;
position.x += (vel * engine->frameDelta) * a.z;
position.y += (vel * engine->frameDelta) * a.y;
}
position.z += (vel*engine->frameDelta) * a.x;
position.x += (vel*engine->frameDelta) * a.z;
}

View File

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

View File

@@ -8,8 +8,8 @@ void Player::pre_render() {
hVelocity = 2;
this->angle.y += 96*engine->frameDelta;
velAngle = -angle;
move(LinearAlgebra::Vector3::Direction(velAngle), hVelocity);
move(upVector, vVelocity);
hMove(LinearAlgebra::Vector3::Direction(velAngle), hVelocity);
vMove(vVelocity);
//this->angle.x -= 64*engine->frameDelta;
//this->angle.x = 1;
}