Better Differentiate between different angle types.
This commit is contained in:
@@ -10,9 +10,13 @@
|
||||
using J3ML::LinearAlgebra::Matrix4x4;
|
||||
using J3ML::LinearAlgebra::Vector3;
|
||||
|
||||
typedef Vector3 Direction;
|
||||
|
||||
///Base entity type.
|
||||
class Entity {
|
||||
private:
|
||||
///Pitch Yaw Roll, The orientation of the entity in the world,
|
||||
Vector3 angle = {0,0,0};
|
||||
///Loads the texture for the entity.
|
||||
virtual void loadTexture();
|
||||
///Loads the geometry for it.
|
||||
@@ -45,9 +49,6 @@ public:
|
||||
SerializeMemberData(archive);
|
||||
archive & GetEntityUUIDList();
|
||||
}
|
||||
|
||||
///Pitch Yaw Roll, The orientation of the entity in the world,
|
||||
Vector3 angle = {0,0,0};
|
||||
///Whether an entity is solid. Entities are solid by default.
|
||||
bool collidable = true;
|
||||
|
||||
@@ -101,10 +102,15 @@ protected:
|
||||
public:
|
||||
std::string uuid;
|
||||
u32 ticksAlive; //At 64tps it'd take 776 days to overflow.
|
||||
[[nodiscard]] Vector3 GetPos() const;
|
||||
void SetPos(const Vector3& rhs);
|
||||
[[nodiscard]] Position GetPos() const;
|
||||
void SetPos(const Position& rhs);
|
||||
Matrix4x4 GetMatrix() const;
|
||||
void SetMatrix(const Matrix4x4& rhs);
|
||||
Direction getAngleDirection();
|
||||
Vector3 getAngle();
|
||||
void setAngle(const Vector3& a);
|
||||
void setAngle(float pitch, float yaw, float roll);
|
||||
|
||||
///Removes an entity from the list, Checks if the assets are being used by any other entity. Removes them from their lists & deletes. Then deletes the entity.
|
||||
void erase();
|
||||
bool draw = true;
|
||||
|
@@ -4,29 +4,39 @@
|
||||
|
||||
///A "Movable Object". Things that will move often are derived from this.
|
||||
class Moby : public Entity {
|
||||
public:
|
||||
Moby(): Entity(), velAngle({0,0,0})
|
||||
{
|
||||
|
||||
}
|
||||
private:
|
||||
///The angle of velocity.
|
||||
Vector3 velAngle = {0,0,0};
|
||||
///Horizontal speed.
|
||||
float hVelocity;
|
||||
///Vertical speed.
|
||||
float vVelocity;
|
||||
///Speed.
|
||||
float velocity;
|
||||
public:
|
||||
Vector3 upVector = {0.0f,1.0f,0.0f};
|
||||
virtual void hMove(Vector3 a, float vel);
|
||||
Moby(): Entity(), upVector(0, 1, 0){}
|
||||
|
||||
///Move
|
||||
void move(Direction a, float speed);
|
||||
|
||||
///Horizontal Move.
|
||||
virtual void hMove(Direction a, float speed);
|
||||
///Vertical Move.
|
||||
void vMove(float vel);
|
||||
Vector3 simulateHMove(Vector3 a, float speed);
|
||||
Vector3 simulateVMove(Vector3 position, float speed);
|
||||
/// forward angle
|
||||
Vector3 fAngle();
|
||||
/// back angle
|
||||
Vector3 bAngle();
|
||||
/// left angle
|
||||
Vector3 lAngle();
|
||||
/// right angle
|
||||
Vector3 rAngle();
|
||||
///The position we would be at if we did a horizontal movement.
|
||||
Position simulateHMove(Direction a, float speed);
|
||||
///The position we would be at if we did a vertical movement.
|
||||
Position simulateVMove(float speed);
|
||||
float getVelocity();
|
||||
void setVelocity(float vel);
|
||||
void setVelocityAngle(const Vector3& a);
|
||||
void setVelocityAngle(float pitch, float yaw, float roll);
|
||||
Vector3 getVelocityAngle();
|
||||
Direction getVelocityAngleDirection();
|
||||
/// Forward angle
|
||||
Direction fAngle();
|
||||
/// Backwards angle
|
||||
Direction bAngle();
|
||||
/// Left angle
|
||||
Direction lAngle();
|
||||
/// Right angle
|
||||
Direction rAngle();
|
||||
};
|
||||
|
||||
|
@@ -3,11 +3,11 @@
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <Collage/types/animation.h>
|
||||
#include <J3ML/LinearAlgebra/Vector3.h>
|
||||
#include <J3ML/LinearAlgebra/Vector2.h>
|
||||
#include <glad/glad.h>
|
||||
#include <J3ML/Geometry/OBB.h>
|
||||
#include <glad/glad.h>
|
||||
|
||||
///Forward declaration of entity.
|
||||
class Entity;
|
||||
@@ -28,20 +28,22 @@ private:
|
||||
///It's faster to create an OBB when loading and then apply the rotation of the entity at the time, then create the other collider you want.
|
||||
OBB cachedOBB;
|
||||
public:
|
||||
///A list of the models animations.
|
||||
std::vector<Animation> animations;
|
||||
///A list of points in 3d space that make up the model.
|
||||
std::vector<Vertex> vertices;
|
||||
///A list specifying how to connect the vertices together to make triangular faces.
|
||||
std::vector<unsigned int> indices;
|
||||
///A list containing texture coordinates, how the texture is to be wrapped around the model.
|
||||
std::vector<TextureCoordinate> texCoords;
|
||||
///Reference counter
|
||||
///Reference list.
|
||||
std::vector<Entity*> usedBy;
|
||||
///Id OpenGL uses to keep track of where the vertices are in vram.
|
||||
///Id OpenGL uses to keep track of where the vertices are in v-ram.
|
||||
GLuint vbo = 0;
|
||||
///Id OpenGL uses to keep track of where the indices are in vram.
|
||||
///Id OpenGL uses to keep track of where the indices are in v-ram.
|
||||
GLuint ebo = 0;
|
||||
///Id OpenGL uses to keep track of where the texture coordinates are in vram.
|
||||
///Id OpenGL uses to keep track of where the texture coordinates are in v-ram.
|
||||
GLuint tbo = 0;
|
||||
|
||||
///Loads a model of a given filename.
|
||||
void load(const std::string& filename);
|
||||
[[nodiscard]] OBB getCachedOBB(const Matrix3x3& rotation) const;
|
||||
|
@@ -19,24 +19,21 @@ int main()
|
||||
|
||||
auto* camera = new(FreeCam);
|
||||
camera->SetPos({0.0f, -2.0f, -5.0f});
|
||||
camera->angle.y = 0.0f;
|
||||
camera->SetParent(engine->world);
|
||||
engine->world->setActiveCamera(camera);
|
||||
|
||||
auto* cube = new(Cube);
|
||||
cube->name = "cube";
|
||||
cube->SetPos({-5, -2, 0});
|
||||
cube->velAngle = cube->lAngle();
|
||||
cube->SetParent(engine->world);
|
||||
|
||||
auto* ball = new(Ball);
|
||||
ball->name = "sphere";
|
||||
ball->SetPos({5, -2, 0});
|
||||
ball->velAngle = ball->rAngle();
|
||||
ball->SetParent(engine->world);
|
||||
|
||||
auto* skybox = new(DemoSkybox);
|
||||
skybox->angle = {0,0,0};
|
||||
skybox->setAngle(0,0,0);
|
||||
skybox->SetParent(engine->world);
|
||||
|
||||
engine->renderLoop();
|
||||
|
@@ -1,8 +1,6 @@
|
||||
#include <ball.h>
|
||||
void Ball::pre_render() {
|
||||
hVelocity = 0;
|
||||
hMove(velAngle, hVelocity);
|
||||
vMove(vVelocity);
|
||||
setVelocity(0);
|
||||
}
|
||||
|
||||
void Ball::update(float elapsed) {
|
||||
@@ -15,6 +13,4 @@ Ball::Ball() {
|
||||
modelPath = "assets/models/sphere_lo.obj";
|
||||
texturePath = "assets/textures/missing.png";
|
||||
setScale(1.0f);
|
||||
hVelocity = 0;
|
||||
vVelocity = 0;
|
||||
}
|
||||
|
@@ -3,14 +3,8 @@
|
||||
#include <ball.h>
|
||||
|
||||
void Cube::pre_render() {
|
||||
//hVelocity = 1;
|
||||
getGeometry();
|
||||
hMove(velAngle, hVelocity);
|
||||
vMove(vVelocity);
|
||||
|
||||
angle.x = angle.x + 24*engine->frameDelta;
|
||||
angle.y = angle.y + 24*engine->frameDelta;
|
||||
angle.z = angle.z + 24*engine->frameDelta;
|
||||
setAngle(getAngle().Add(24 * engine->frameDelta));
|
||||
}
|
||||
|
||||
void Cube::update(float elapsed) {
|
||||
@@ -21,8 +15,6 @@ Cube::Cube() {
|
||||
modelPath = "assets/models/cube.obj";
|
||||
texturePath = "assets/textures/multi/";
|
||||
setScale(0.5f);
|
||||
hVelocity = 0;
|
||||
vVelocity = 0;
|
||||
}
|
||||
|
||||
void Cube::loadTexture() {
|
||||
|
@@ -20,14 +20,14 @@ void FreeCam::pre_render() {
|
||||
vMove(-4);
|
||||
|
||||
if (engine->window->isKeyDown(Keys::Q))
|
||||
this->angle.y -=75.0f*engine->frameDelta;
|
||||
setAngle(getAngle().x, getAngle().y - 75.0f * engine->frameDelta, getAngle().z);
|
||||
|
||||
if (engine->window->isKeyDown(Keys::E))
|
||||
this->angle.y +=75.0f*engine->frameDelta;
|
||||
setAngle(getAngle().x, getAngle().y + 75.0f * engine->frameDelta, getAngle().z);
|
||||
|
||||
if (engine->window->isKeyDown(Keys::UpArrow))
|
||||
this->angle.x -=75.0f*engine->frameDelta;
|
||||
setAngle(getAngle().x - 75.0f * engine->frameDelta, getAngle().y, getAngle().z);
|
||||
|
||||
if (engine->window->isKeyDown(Keys::DownArrow))
|
||||
this->angle.x +=75.0f*engine->frameDelta;
|
||||
setAngle(getAngle().x + 75.0f * engine->frameDelta, getAngle().y, getAngle().z);
|
||||
}
|
@@ -17,9 +17,9 @@ std::array<GLfloat, 16> lookAt(const Vector3& eye, const Vector3& center, const
|
||||
}
|
||||
|
||||
void Camera::render() {
|
||||
glRotatef(angle.x,1.0f, 0.0f, 0.0f);
|
||||
glRotatef(angle.y,0.0f, 1.0f, 0.0f);
|
||||
glRotatef(angle.z,0.0f, 0.0f, 1.0f);
|
||||
glRotatef(getAngle().x,1.0f, 0.0f, 0.0f);
|
||||
glRotatef(getAngle().y,0.0f, 1.0f, 0.0f);
|
||||
glRotatef(getAngle().z,0.0f, 0.0f, 1.0f);
|
||||
|
||||
glMultMatrixf(lookAt({position.x, position.y, position.z}, {position.x, position.y, engine->farPlane+position.z}, upVector).data());
|
||||
}
|
||||
@@ -31,5 +31,5 @@ void Camera::post_render() {
|
||||
|
||||
bool Camera::raycast(Entity *entity) {
|
||||
Vector3 rayOrigin = position;
|
||||
Vector3 rayAngle = angle;
|
||||
Vector3 rayAngle = getAngle();
|
||||
}
|
||||
|
@@ -239,3 +239,19 @@ Sphere Entity::getSphere() {
|
||||
OBB Entity::getOBB() {
|
||||
return getGeometry()->getCachedOBB(angle);
|
||||
}
|
||||
|
||||
Vector3 Entity::getAngle() {
|
||||
return angle;
|
||||
}
|
||||
|
||||
void Entity::setAngle(const Vector3 &a) {
|
||||
angle = a;
|
||||
}
|
||||
|
||||
void Entity::setAngle(float pitch, float yaw, float roll) {
|
||||
angle = {pitch, yaw, roll};
|
||||
}
|
||||
|
||||
Direction Entity::getAngleDirection() {
|
||||
return Vector3::Direction(angle);
|
||||
}
|
||||
|
@@ -2,7 +2,7 @@
|
||||
#include <Redacted3D/engine/engine.h>
|
||||
using namespace J3ML;
|
||||
|
||||
void Moby::hMove(Vector3 a, float vel) {
|
||||
void Moby::hMove(Direction a, float vel) {
|
||||
position.z -= (vel*engine->frameDelta) * a.x;
|
||||
position.x += (vel*engine->frameDelta) * a.z;
|
||||
}
|
||||
@@ -11,48 +11,74 @@ void Moby::vMove(float vel) {
|
||||
position.y += (vel*engine->frameDelta);
|
||||
}
|
||||
|
||||
//TODO
|
||||
void Moby::move(Direction a, float speed) {
|
||||
|
||||
}
|
||||
|
||||
//Returns the position we'd be at *if* we did a movement.
|
||||
Vector3 Moby::simulateHMove(Vector3 a, float vel) {
|
||||
Vector3 p;
|
||||
Direction Moby::simulateHMove(Vector3 a, float vel) {
|
||||
Position p;
|
||||
p.z -= (vel*engine->frameDelta) * a.x;
|
||||
p.x += (vel*engine->frameDelta) * a.z;
|
||||
return p;
|
||||
}
|
||||
|
||||
Vector3 Moby::fAngle()
|
||||
Direction Moby::fAngle()
|
||||
{
|
||||
Vector3 a;
|
||||
a.x = -(cos(Math::Radians(this->angle.y)) * cos(Math::Radians(this->angle.x)));
|
||||
a.y = -sin(Math::Radians(this->angle.x));
|
||||
a.z = -(sin(Math::Radians(this->angle.y)) * cos(Math::Radians(this->angle.x)));
|
||||
Direction a;
|
||||
a.x = -(cos(Math::Radians(getAngle().y)) * cos(Math::Radians(getAngle().x)));
|
||||
a.y = -sin(Math::Radians(getAngle().x));
|
||||
a.z = -(sin(Math::Radians(getAngle().y)) * cos(Math::Radians(getAngle().x)));
|
||||
return a;
|
||||
}
|
||||
|
||||
Vector3 Moby::bAngle()
|
||||
{
|
||||
Direction Moby::bAngle() {
|
||||
return -fAngle();
|
||||
}
|
||||
|
||||
Vector3 Moby::rAngle()
|
||||
{
|
||||
Vector3 f = fAngle();
|
||||
Vector3 a;
|
||||
Direction Moby::rAngle() {
|
||||
Direction f = fAngle();
|
||||
Direction a;
|
||||
a.x = f.x * upVector.z - f.z * upVector.y;
|
||||
a.y = f.z * upVector.x - f.x * upVector.z;
|
||||
a.z = f.x * upVector.y - f.y * upVector.x;
|
||||
return a;
|
||||
}
|
||||
|
||||
Vector3 Moby::lAngle()
|
||||
{
|
||||
Vector3 f = fAngle();
|
||||
Vector3 a;
|
||||
Direction Moby::lAngle() {
|
||||
Direction f = fAngle();
|
||||
Direction a;
|
||||
a.x = -(f.y * upVector.z - f.z * upVector.y);
|
||||
a.y = (f.z * upVector.x - f.x * upVector.z);
|
||||
a.z = -(f.x * upVector.y - f.y * upVector.x);
|
||||
return a;
|
||||
}
|
||||
|
||||
Vector3 Moby::simulateVMove(Vector3 position, float speed) {
|
||||
Position Moby::simulateVMove(float speed) {
|
||||
return {position.x, position.y += (speed*engine->frameDelta), position.z};
|
||||
}
|
||||
|
||||
float Moby::getVelocity() {
|
||||
return velocity;
|
||||
}
|
||||
|
||||
void Moby::setVelocity(float vel) {
|
||||
velocity = vel;
|
||||
}
|
||||
|
||||
Direction Moby::getVelocityAngleDirection() {
|
||||
return Vector3::Direction(velAngle);
|
||||
}
|
||||
|
||||
Vector3 Moby::getVelocityAngle() {
|
||||
return velAngle;
|
||||
}
|
||||
|
||||
void Moby::setVelocityAngle(const Vector3 &a) {
|
||||
velAngle = a;
|
||||
}
|
||||
|
||||
void Moby::setVelocityAngle(float pitch, float yaw, float roll) {
|
||||
velAngle = {pitch, yaw, roll};
|
||||
}
|
||||
|
Reference in New Issue
Block a user