This commit is contained in:
2023-12-05 16:41:05 -05:00
parent 826ec8e744
commit 3ed2a03e1e
6 changed files with 30 additions and 26 deletions

View File

@@ -16,7 +16,6 @@ enum class GAMESTATE: uint8_t {
IN_PAUSE_MENU = 2,
IN_LEVEL_ANIMATION = 3, //A cutscene which moves entities in the world and cannot be interrupted.
IN_QUIT = 4, //The game should close.
NULL_ = 7
};
class Engine {

View File

@@ -45,6 +45,7 @@ void pre_render() {
auto camera = new(Camera);
storeEntity(camera);
getCamera()->position.set(0.0f,0.0f,5.0f);
getCamera()->angle.y = 180.0f;
auto skybox = new(Skybox);
skybox->draw = true;
storeEntity(skybox);
@@ -56,6 +57,9 @@ void pre_render() {
process_sdl_events();
engine->keyState = const_cast<Uint8 *>(SDL_GetKeyboardState(nullptr));
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
getCamera()->pre_render();
getPlayer()->pre_render();
getSkybox()->pre_render();
}
void render() {
@@ -65,15 +69,6 @@ void render() {
getCamera()->render();
getSkybox()->render();
getPlayer()->render();
//glBegin(GL_QUADS);
//glColor3f(0,1,0);
//glVertex3f(-0.25f, -0.75f,0.0);
//glVertex3f(0.25f, -0.75f,0.0);
//glVertex3f(0.25f, 0.75f,0.0);
//glVertex3f(-0.25f, 0.75f,0.0);
//glEnd();
}
void post_render() {

View File

@@ -25,9 +25,6 @@
case GAMESTATE::IN_QUIT:
engine->quit();
break;
case GAMESTATE::NULL_:
engine->quit();
break;
}
//The compiler and/or the cpu would probably fix this on it's own anyways.

View File

@@ -7,7 +7,8 @@
enum class CameraMode: uint8_t {
THIRD_PERSON = 0,
FREECAM = 1
FREECAM = 1,
SCRIPTED_MOVE = 2
};
class Camera : public Moby {
public:
@@ -22,7 +23,7 @@ public:
}
}
void render() {
void pre_render() {
if (engine->keyState[SDL_SCANCODE_0] == 1) {
this->takingScreenshot = true;
}
@@ -34,15 +35,17 @@ public:
this->cameraMode = CameraMode::THIRD_PERSON;
if (cameraMode == CameraMode::THIRD_PERSON) {
std::cout << "Calculated Pitch: " << VectorMath::calcAngle(position,getPlayer()->position).x << " Calculated Yaw: " << VectorMath::calcAngle(position,getPlayer()->position).y << std::endl;
if (engine->debug)
std::cout << "Calculated Pitch: " << VectorMath::calcAngle(position,getPlayer()->position).x << " Calculated Yaw: " << VectorMath::calcAngle(position,getPlayer()->position).y << std::endl;
this->position = getPlayer()->cameraPoint(2);
//Make the camera pitch down a little bit.
this->position.y += 0.5;
this->angle.x = VectorMath::calcAngle(position,getPlayer()->position).x;
this->angle.y = VectorMath::calcAngle(position,getPlayer()->position).y;
}
//if (engine->frameCount == 5000)
//getPlayer()->thirdPersonCameraPoints();
//getPlayer()->thirdPersonCameraPoints();
if (cameraMode == CameraMode::FREECAM) {
if (engine->keyState[SDL_SCANCODE_S] == 1) {
@@ -59,11 +62,11 @@ public:
}
if (engine->keyState[SDL_SCANCODE_SPACE] == 1) {
this->position.y -= 5*engine->frameDelta;
this->position.y += 5*engine->frameDelta;
}
if (engine->keyState[SDL_SCANCODE_LSHIFT] == 1) {
this->position.y += 5*engine->frameDelta;
this->position.y -= 5*engine->frameDelta;
}
if (engine->keyState[SDL_SCANCODE_LEFT] == 1) {
@@ -79,6 +82,9 @@ public:
this->angle.x +=75.0f*engine->frameDelta;
}
}
}
void render() {
this->angle.clamp();
glRotatef(angle.x,1.0f, 0.0f, 0.0f);
glRotatef(-angle.y,0.0f, 1.0f, 0.0f);

View File

@@ -18,6 +18,7 @@ public:
//It'll be different for each one.
//The "camera point" is the position the camera will want to be while following the player.
//We will probably end up having a different camera point class controlled by the "world".
Position cameraPoint (float distance) {
Position behindPosition = this->position;
Angle reverseDirection = this->bAngle();
@@ -33,14 +34,17 @@ public:
}
void render() {
void pre_render() {
//PLACEHOLDER LOL.
if (engine->frameCount == 1) {
geometry.load("../models/cube.obj");
geometry.scale(0.25f);
position.set(0,-2,0);
}
//Rotate
this->angle.y += 75.0*engine->frameDelta;
//this->angle.y = this->angle.y + 75.0f*engine->frameDelta;
}
void render() {
glColor3f(0.75,0.75,0.75);
glPushMatrix();
glRotatef(-angle.x,1.0f, 0.0f, 0.0f);

View File

@@ -9,12 +9,15 @@
class Skybox : public Entity {
public:
VertexArray geometry;
void render() {
//TODO
if (engine->frameCount == 1) {
geometry.load("../models/cube.obj");
}
void pre_render() {
//PLACEHOLDER.
if (engine->frameCount == 1) {
geometry.load("../models/cube.obj");
}
}
void render() {
glColor3f(0.75,0.75,0.75);
glPushMatrix();
glTranslatef(position.x + 4,position.y,position.z);