bugfixes
This commit is contained in:
@@ -15,8 +15,8 @@ add_executable(SDL3D src/main.cpp
|
||||
src/engine/tick.h
|
||||
src/types/vertex.h
|
||||
src/types/skybox.h
|
||||
src/types/geometry.h
|
||||
src/types/moby.h
|
||||
src/types/animationSequence.h
|
||||
)
|
||||
|
||||
find_package(OpenGL)
|
||||
|
1990
models/sphere.obj
1990
models/sphere.obj
File diff suppressed because it is too large
Load Diff
3
run.sh
3
run.sh
@@ -1,2 +1,3 @@
|
||||
sleep 0.2
|
||||
vblank_mode=0 mangohud --dlsym ./cmake-build-debug/SDL3D
|
||||
cd /home/william/Documents/GitHub/SDL3D/cmake-build-debug
|
||||
vblank_mode=0 mangohud --dlsym ./SDL3D
|
||||
|
@@ -46,7 +46,11 @@ void pre_render() {
|
||||
storeEntity(camera);
|
||||
getCamera()->position.set(0.0f,0.0f,5.0f);
|
||||
auto skybox = new(Skybox);
|
||||
skybox->draw = true;
|
||||
storeEntity(skybox);
|
||||
auto player = new(Player);
|
||||
player->angle = {0,0,0};
|
||||
storeEntity(player);
|
||||
}
|
||||
engine->frameCount++;
|
||||
process_sdl_events();
|
||||
@@ -60,46 +64,7 @@ void render() {
|
||||
//*Always* render the camera first.
|
||||
getCamera()->render();
|
||||
getSkybox()->render();
|
||||
glPushMatrix();
|
||||
glBegin(GL_QUADS);
|
||||
glColor3f(1,0.5,1);
|
||||
// Front face
|
||||
glVertex3f(-0.5f, -0.5f, 0.5f);
|
||||
glVertex3f(0.5f, -0.5f, 0.5f);
|
||||
glVertex3f(0.5f, 0.5f, 0.5f);
|
||||
glVertex3f(-0.5f, 0.5f, 0.5f);
|
||||
|
||||
// Back face
|
||||
glVertex3f(-0.5f, -0.5f, -0.5f);
|
||||
glVertex3f(0.5f, -0.5f, -0.5f);
|
||||
glVertex3f(0.5f, 0.5f, -0.5f);
|
||||
glVertex3f(-0.5f, 0.5f, -0.5f);
|
||||
|
||||
// Left face
|
||||
glVertex3f(-0.5f, -0.5f, -0.5f);
|
||||
glVertex3f(-0.5f, -0.5f, 0.5f);
|
||||
glVertex3f(-0.5f, 0.5f, 0.5f);
|
||||
glVertex3f(-0.5f, 0.5f, -0.5f);
|
||||
|
||||
// Right face
|
||||
glVertex3f(0.5f, -0.5f, -0.5f);
|
||||
glVertex3f(0.5f, -0.5f, 0.5f);
|
||||
glVertex3f(0.5f, 0.5f, 0.5f);
|
||||
glVertex3f(0.5f, 0.5f, -0.5f);
|
||||
|
||||
// Top face
|
||||
glVertex3f(-0.5f, 0.5f, -0.5f);
|
||||
glVertex3f(0.5f, 0.5f, -0.5f);
|
||||
glVertex3f(0.5f, 0.5f, 0.5f);
|
||||
glVertex3f(-0.5f, 0.5f, 0.5f);
|
||||
|
||||
// Bottom face
|
||||
glVertex3f(-0.5f, -0.5f, -0.5f);
|
||||
glVertex3f(0.5f, -0.5f, -0.5f);
|
||||
glVertex3f(0.5f, -0.5f, 0.5f);
|
||||
glVertex3f(-0.5f, -0.5f, 0.5f);
|
||||
glEnd();
|
||||
glPopMatrix();
|
||||
getPlayer()->render();
|
||||
|
||||
|
||||
//glBegin(GL_QUADS);
|
||||
|
@@ -14,7 +14,7 @@
|
||||
switch (engine->gameState) {
|
||||
case GAMESTATE::NORMAL:
|
||||
if(engine->frameCount > 0)
|
||||
//getCamera()->update();
|
||||
getCamera()->update();
|
||||
break;
|
||||
case GAMESTATE::IN_MAIN_MENU:
|
||||
break;
|
||||
|
3
src/types/animationSequence.h
Normal file
3
src/types/animationSequence.h
Normal file
@@ -0,0 +1,3 @@
|
||||
#include <vector>
|
||||
#include "vector3.h"
|
||||
#include "vertex.h"
|
@@ -1,28 +1,46 @@
|
||||
#pragma once
|
||||
#include "moby.h"
|
||||
#include "player.h"
|
||||
#include "../engine/engine.h"
|
||||
#include <glm/glm.hpp>
|
||||
#include "entityList.h"
|
||||
|
||||
enum class CameraMode: uint8_t {
|
||||
FREECAM = 0,
|
||||
FOLLOW_PLAYER = 1
|
||||
THIRD_PERSON = 0,
|
||||
FREECAM = 1
|
||||
};
|
||||
class Camera : public Moby {
|
||||
public:
|
||||
CameraMode mode = CameraMode::FREECAM;
|
||||
CameraMode cameraMode = CameraMode::FREECAM;
|
||||
bool takingScreenshot = false;
|
||||
|
||||
void update() {
|
||||
|
||||
if (engine->debug && engine->tickCount %64 == 0) {
|
||||
std::cout << "Camera:" << std::endl;
|
||||
std::cout << "X: " << position.x << " Y: " << position.y << " Z: " << position.z << std::endl;
|
||||
std::cout << "Pitch: " << angle.x << " Yaw: " << angle.y << " Roll: " << angle.z << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void render() {
|
||||
|
||||
if (engine->keyState[SDL_SCANCODE_0] == 1) {
|
||||
this->takingScreenshot = true;
|
||||
}
|
||||
|
||||
if (mode == CameraMode::FREECAM) {
|
||||
if (engine->keyState[SDL_SCANCODE_1] == 1)
|
||||
this->cameraMode = CameraMode::FREECAM;
|
||||
|
||||
if (engine->keyState[SDL_SCANCODE_2] == 1)
|
||||
this->cameraMode = CameraMode::THIRD_PERSON;
|
||||
|
||||
if (cameraMode == CameraMode::THIRD_PERSON) {
|
||||
this->position = getPlayer()->cameraPoint(2);
|
||||
}
|
||||
|
||||
//if (engine->frameCount == 5000)
|
||||
//getPlayer()->thirdPersonCameraPoints();
|
||||
|
||||
if (cameraMode == CameraMode::FREECAM) {
|
||||
if (engine->keyState[SDL_SCANCODE_S] == 1) {
|
||||
move(bAngle(),2);
|
||||
}
|
||||
@@ -63,14 +81,8 @@ public:
|
||||
|
||||
glTranslatef(0.0f, 0.0f, 0.0f);
|
||||
gluLookAt(position.x, position.y, position.z, // camera position
|
||||
position.x, position.y, -engine->farPlane+position.z, // target position, We're always *looking at* the far plane straight ahead so the camera never turns around.
|
||||
position.x, position.y, engine->farPlane+position.z, // target position, We're always *looking at* the far plane straight ahead so the camera never turns around.
|
||||
upVector.x,upVector.y,upVector.z);
|
||||
|
||||
if (engine->debug && engine->tickCount %64 == 0) {
|
||||
std::cout << "Camera:" << std::endl;
|
||||
std::cout << "X: " << position.x << " Y: " << position.y << " Z: " << position.z << std::endl;
|
||||
std::cout << "Pitch: " << angle.x << " Yaw: " << angle.y << " Roll: " << angle.z << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
void post_render() {
|
||||
@@ -78,6 +90,7 @@ public:
|
||||
engine->takeScreenshot();
|
||||
takingScreenshot = false;
|
||||
}
|
||||
this->ticksAlive++;
|
||||
}
|
||||
};
|
||||
|
||||
|
@@ -1,10 +0,0 @@
|
||||
#pragma once
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
#include <vector>
|
||||
class Geometry {
|
||||
public:
|
||||
//I would use array for this, But from what I've read array of unknown size
|
||||
//as a member of class was removed after c++99.
|
||||
std::vector<GLfloat> vertices;
|
||||
std::vector<GLuint> indices;
|
||||
};
|
@@ -18,18 +18,18 @@ public:
|
||||
//forward angle
|
||||
Angle fAngle() {
|
||||
Angle a;
|
||||
a.x = -(cos(glm::radians(this->angle.y)) * cos(glm::radians(this->angle.x)));
|
||||
a.x = (cos(glm::radians(this->angle.y)) * cos(glm::radians(this->angle.x)));
|
||||
a.y = sin(glm::radians(this->angle.x));
|
||||
a.z = -(sin(glm::radians(this->angle.y)) * cos(glm::radians(this->angle.x)));
|
||||
a.z = (sin(glm::radians(this->angle.y)) * cos(glm::radians(this->angle.x)));
|
||||
return a;
|
||||
}
|
||||
|
||||
//back angle
|
||||
Angle bAngle() {
|
||||
Angle a;
|
||||
a.x = cos(glm::radians(this->angle.y)) * cos(glm::radians(this->angle.x));
|
||||
a.x = -cos(glm::radians(this->angle.y)) * cos(glm::radians(this->angle.x));
|
||||
a.y = -(sin(glm::radians(this->angle.x)));
|
||||
a.z = sin(glm::radians(this->angle.y)) * cos(glm::radians(this->angle.x));
|
||||
a.z = -sin(glm::radians(this->angle.y)) * cos(glm::radians(this->angle.x));
|
||||
return a;
|
||||
}
|
||||
|
||||
|
@@ -1,25 +1,52 @@
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include <cmath>
|
||||
#include "moby.h"
|
||||
#include "entityList.h"
|
||||
#include "../engine/engine.h"
|
||||
|
||||
#include "vertex.h"
|
||||
class Player : public Moby {
|
||||
public:
|
||||
bool alive;
|
||||
uint8_t health;
|
||||
uint8_t state;
|
||||
Position cameraTarget; //The point where the 3rd-person camera will want to look at.
|
||||
|
||||
Position cameraTarget;//The point where the 3rd-person camera will want to look at.
|
||||
VertexArray geometry;
|
||||
//Each type of entity will have an "update" function and a "render" function.
|
||||
//These will be declared in each type of entity and not in the base entity because
|
||||
//It'll be different for each one.
|
||||
|
||||
Position cameraPoint (float distance) {
|
||||
Position behindPosition = this->position;
|
||||
Angle reverseDirection = this->bAngle();
|
||||
|
||||
behindPosition.x -= reverseDirection.x * distance;
|
||||
behindPosition.y -= reverseDirection.y * distance;
|
||||
behindPosition.z -= reverseDirection.z * distance;
|
||||
|
||||
return behindPosition;
|
||||
}
|
||||
|
||||
void update() {
|
||||
|
||||
}
|
||||
|
||||
void render() {
|
||||
if (engine->frameCount == 1) {
|
||||
geometry.load("../models/cube.obj");
|
||||
geometry.scale(0.25f);
|
||||
position.set(0,0,0);
|
||||
}
|
||||
this->angle.y += 75.0*engine->frameDelta;
|
||||
//this->angle.y = this->angle.y + 75.0f*engine->frameDelta;
|
||||
glColor3f(0.75,0.75,0.75);
|
||||
glPushMatrix();
|
||||
glRotatef(-angle.x,1.0f, 0.0f, 0.0f);
|
||||
glRotatef(-angle.y,0.0f, 1.0f, 0.0f);
|
||||
glTranslatef(position.x ,position.y,position.z);
|
||||
geometry.draw();
|
||||
glPopMatrix();
|
||||
|
||||
}
|
||||
};
|
||||
|
@@ -1,7 +1,6 @@
|
||||
#pragma once
|
||||
|
||||
#include <SDL2/SDL_opengl.h>
|
||||
#include "geometry.h"
|
||||
#include "entityList.h"
|
||||
#include "moby.h"
|
||||
#include "camera.h"
|
||||
@@ -11,16 +10,15 @@ class Skybox : public Entity {
|
||||
public:
|
||||
VertexArray geometry;
|
||||
void render() {
|
||||
|
||||
//TODO
|
||||
if (engine->frameCount == 1) {
|
||||
geometry.load("../models/sphere.obj");
|
||||
std::this_thread::sleep_for(std::chrono::microseconds(1000));
|
||||
geometry.load("../models/cube.obj");
|
||||
}
|
||||
glPushMatrix();
|
||||
|
||||
glColor3f(0.75,0.75,0.75);
|
||||
//this->position.set(getCamera()->position);
|
||||
glTranslatef(position.x,position.y+2,position.z);
|
||||
geometry.draw();
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x + 4,position.y,position.z);
|
||||
//geometry.draw();
|
||||
glPopMatrix();
|
||||
}
|
||||
|
||||
@@ -28,7 +26,7 @@ public:
|
||||
|
||||
inline Skybox* getSkybox() {
|
||||
for (auto& e : entityList)
|
||||
if (auto* s = dynamic_cast<Skybox*>(e) )
|
||||
if (auto* s = dynamic_cast<Skybox*>(e))
|
||||
return s;
|
||||
std::cerr << "Attempt to get Skybox pointer while not in scene." << std::endl;
|
||||
engine->quit();
|
||||
|
@@ -46,6 +46,18 @@ public:
|
||||
if (this->z >= 180.01f)
|
||||
this->z = -179.9f;
|
||||
}
|
||||
|
||||
[[nodiscard]] float length() const {
|
||||
return sqrt(x * x + y * y + z * z);
|
||||
}
|
||||
|
||||
void normalize() {
|
||||
if (this->length() != 0.0f) {
|
||||
x /= this->length();
|
||||
y /= this->length();
|
||||
z /= this->length();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Position : public vector3 {
|
||||
@@ -79,4 +91,8 @@ public:
|
||||
this->y = y;
|
||||
this->z = z;
|
||||
}
|
||||
|
||||
float distanceFrom(Position p) {
|
||||
return sqrt(pow(this->x - p.x, 2) + pow(this->y - p.y, 2) + pow(this->z - p.z, 2));
|
||||
}
|
||||
};
|
@@ -18,6 +18,14 @@ public:
|
||||
std::vector<Vertex> vertices;
|
||||
std::vector<unsigned int> indices;
|
||||
|
||||
void scale(GLfloat multiplier) {
|
||||
for (auto & vertice : vertices) {
|
||||
vertice.x *= multiplier;
|
||||
vertice.y *= multiplier;
|
||||
vertice.z *= multiplier;
|
||||
}
|
||||
}
|
||||
|
||||
void load(const std::string& filename) {
|
||||
std::ifstream file(filename);
|
||||
if (!file.is_open()) {
|
||||
|
Reference in New Issue
Block a user