Regular move

This commit is contained in:
2024-06-23 19:47:07 -04:00
parent d8dc4d9b82
commit 146b19c4d1
4 changed files with 53 additions and 20 deletions

View File

@@ -15,15 +15,17 @@ public:
///Move
void move(Direction a, float speed);
///Move in the direction a moby is facing.
void move(float speed);
///Horizontal Move.
virtual void hMove(Direction a, float speed);
///Vertical Move.
void vMove(float vel);
///The position we would be at if we did a horizontal movement.
Position simulateHMove(Direction a, float speed);
Position projectedHorizontalMove(Direction a, float speed);
///The position we would be at if we did a vertical movement.
Position simulateVMove(float speed);
Position projectedVerticalMove(float speed);
float getVelocity();
void setVelocity(float vel);
void setVelocityAngle(const Vector3& a);
@@ -38,5 +40,7 @@ public:
Direction lAngle();
/// Right angle
Direction rAngle();
void vAngleMove(float speed);
};

View File

@@ -1,28 +1,28 @@
#include <freeCam.h>
void FreeCam::pre_render() {
if (engine->window->isKeyDown(Keys::S))
hMove(bAngle(), 4);
if (engine->window->isKeyDown(Keys::W))
hMove(fAngle(), 4);
move(getAngleDirection(), 4);
if (engine->window->isKeyDown(Keys::S))
move(bAngle(), 4);
if (engine->window->isKeyDown(Keys::A))
hMove(lAngle(), 4);
move(lAngle(), 4);
if (engine->window->isKeyDown(Keys::D))
hMove(rAngle(), 4);
move(rAngle(), 4);
if (engine->window->isKeyDown(Keys::Z))
if (engine->window->isKeyDown(Keys::Space))
vMove(4);
if (engine->window->isKeyDown(Keys::X))
if (engine->window->isKeyDown(Keys::LShift))
vMove(-4);
if (engine->window->isKeyDown(Keys::Q))
if (engine->window->isKeyDown(Keys::LeftArrow))
setAngle(getAngle().x, getAngle().y - 75.0f * engine->frameDelta, getAngle().z);
if (engine->window->isKeyDown(Keys::E))
if (engine->window->isKeyDown(Keys::RightArrow))
setAngle(getAngle().x, getAngle().y + 75.0f * engine->frameDelta, getAngle().z);
if (engine->window->isKeyDown(Keys::UpArrow))

View File

@@ -253,5 +253,10 @@ void Entity::setAngle(float pitch, float yaw, float roll) {
}
Direction Entity::getAngleDirection() {
return Vector3::Direction(angle);
Direction a = Vector3::Direction(angle);
//These two are reversed when moving things in the Re3D scene.
//-Z is forward.
a.x = -a.x;
a.z = -a.z;
return a;
}

View File

@@ -2,28 +2,52 @@
#include <Redacted3D/engine/engine.h>
using namespace J3ML;
///Moves the moby horizontally only.
void Moby::hMove(Direction a, float vel) {
position.z -= (vel*engine->frameDelta) * a.x;
position.x += (vel*engine->frameDelta) * a.z;
}
///Moves the moby vertically only.
void Moby::vMove(float vel) {
position.y += (vel*engine->frameDelta);
}
//TODO
///Moves the moby in a given Direction Vector with a given speed.
void Moby::move(Direction a, float speed) {
position.x += a.z * (speed * engine->frameDelta);
position.z -= a.x * (speed * engine->frameDelta);
position.y += a.y * (speed * engine->frameDelta);
}
///Moves the moby in the direction it's facing without having to pass it in.
void Moby::move(float speed) {
Direction a = getAngleDirection();
position.x += a.z * (speed * engine->frameDelta);
position.z -= a.x * (speed * engine->frameDelta);
position.y += a.y * (speed * engine->frameDelta);
}
///Moves the moby in the direction of it's velocity without having to pass it in.
void Moby::vAngleMove(float speed) {
Direction a = getVelocityAngleDirection();
position.x += a.z * (speed * engine->frameDelta);
position.z -= a.x * (speed * engine->frameDelta);
position.y += a.y * (speed * engine->frameDelta);
}
//Returns the position we'd be at *if* we did a movement.
Direction Moby::simulateHMove(Vector3 a, float vel) {
Direction Moby::projectedHorizontalMove(Vector3 a, float vel) {
Position p;
p.z -= (vel*engine->frameDelta) * a.x;
p.x += (vel*engine->frameDelta) * a.z;
return p;
}
Position Moby::projectedVerticalMove(float speed) {
return {position.x, position.y += (speed*engine->frameDelta), position.z};
}
Direction Moby::fAngle()
{
Direction a;
@@ -55,10 +79,6 @@ Direction Moby::lAngle() {
return a;
}
Position Moby::simulateVMove(float speed) {
return {position.x, position.y += (speed*engine->frameDelta), position.z};
}
float Moby::getVelocity() {
return velocity;
}
@@ -68,7 +88,11 @@ void Moby::setVelocity(float vel) {
}
Direction Moby::getVelocityAngleDirection() {
return Vector3::Direction(velAngle);
Direction a = Vector3::Direction(velAngle);
///X and Z are reversed in the Re3D scene.
a.x = -a.x;
a.z = -a.z;
return a;
}
Vector3 Moby::getVelocityAngle() {