forked from Redacted/Re3D
Big cleanup.
This commit is contained in:
@@ -62,7 +62,6 @@ public:
|
||||
void quit (ENGINE_ERROR_CODE code);
|
||||
static float getGLVersion();
|
||||
void initGL();
|
||||
void debugInfo() const;
|
||||
void loadConfig();
|
||||
|
||||
void init();
|
||||
|
@@ -1,6 +1,5 @@
|
||||
#pragma once
|
||||
#include <types/entity/moby.h>
|
||||
#include <types/entity/renderPlane.h>
|
||||
#include <engine/engine.h>
|
||||
#include <glad/glad.h>
|
||||
#include <J3ML/Geometry.h>
|
||||
@@ -8,41 +7,17 @@
|
||||
using J3ML::LinearAlgebra::Matrix4x4;
|
||||
using J3ML::Geometry::Frustum;
|
||||
|
||||
enum class CameraMode: uint8_t {
|
||||
THIRD_PERSON = 0,
|
||||
FREECAM = 1,
|
||||
SCRIPTED_MOVE = 2
|
||||
};
|
||||
|
||||
const Vector3 UP = {0, 1, 0};
|
||||
class Camera : public Moby {
|
||||
private:
|
||||
void modeBinds();
|
||||
void thirdPerson();
|
||||
void freeCam();
|
||||
protected:
|
||||
public:
|
||||
CameraMode cameraMode = CameraMode::FREECAM;
|
||||
bool takingScreenshot = false;
|
||||
RenderPlane headsUpDisplay;
|
||||
Matrix4x4 GetViewMatrix();
|
||||
bool raycast(Entity* entity);
|
||||
Frustum getFrustum();
|
||||
void MoveForward(float dist);
|
||||
void StrafeLeft(float dist);
|
||||
void StrafeRight(float dist);
|
||||
void TurnLeft(float deg = 90);
|
||||
void TurnRight(float deg = 90);
|
||||
void LookAt(Vector3 pos, Vector3 target, Vector3 upaxis = UP) {}
|
||||
void Rotate(float amt, Vector3 axis) { }
|
||||
void Translate(Vector3 dir) { }
|
||||
void update();
|
||||
void pre_render() override;
|
||||
void pre_render() override {};
|
||||
void render() override;
|
||||
void post_render() override;
|
||||
void hMove(Vector3 a, float vel) override;
|
||||
void SetMode(CameraMode mode)
|
||||
{
|
||||
cameraMode = mode;
|
||||
}
|
||||
};
|
@@ -1,11 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <types/entity/entity.h>
|
||||
|
||||
class RenderPlane : public Entity {
|
||||
private:
|
||||
VertexArray geometry;
|
||||
public:
|
||||
[[nodiscard]] VertexArray getGeometry() const;
|
||||
void update(float elapsed) override;
|
||||
};
|
7
src/demo/RuntimeTest/include/demoSky.h
Normal file
7
src/demo/RuntimeTest/include/demoSky.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <types/entity/skybox.h>
|
||||
#pragma once
|
||||
|
||||
class DemoSkybox : public Skybox {
|
||||
public:
|
||||
DemoSkybox();
|
||||
};
|
7
src/demo/RuntimeTest/include/freeCam.h
Normal file
7
src/demo/RuntimeTest/include/freeCam.h
Normal file
@@ -0,0 +1,7 @@
|
||||
#pragma once
|
||||
#include <types/entity/camera.h>
|
||||
|
||||
class FreeCam : public Camera {
|
||||
public:
|
||||
void pre_render() override;
|
||||
};
|
@@ -2,14 +2,24 @@
|
||||
#include <engine/engine.h>
|
||||
#include <cube.h>
|
||||
#include <sphere.h>
|
||||
#include <freeCam.h>
|
||||
#include <demoSky.h>
|
||||
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
|
||||
engine->window = new ReWindow::RWindow("Re3D Test Application", 1152, 864, RenderingAPI::OPENGL);
|
||||
engine->world = new World();
|
||||
engine->world = new(World);
|
||||
engine->init();
|
||||
engine->window->setVsyncEnabled(false);
|
||||
engine->window->setResizable(false);
|
||||
engine->world->setAmbientLightColor(1.0f, 1.0f, 1.0f, 0.0f);
|
||||
Shader test("test", engine->workingDir + "/assets/shaders/defaultVertex.glsl", engine->workingDir + "/assets/shaders/defaultFragment.glsl");
|
||||
|
||||
auto* camera = new(FreeCam);
|
||||
camera->SetPos({0.0f, -2.0f, -5.0f});
|
||||
camera->angle.y = 0.0f;
|
||||
camera->SetParent(engine->world);
|
||||
|
||||
auto* cube1 = new(Cube);
|
||||
cube1->name = "cube1";
|
||||
cube1->SetPos({-5, -2, 0});
|
||||
@@ -22,6 +32,10 @@ int main(int argc, char** argv)
|
||||
cube2->velAngle = cube2->rAngle();
|
||||
cube2->SetParent(engine->world);
|
||||
|
||||
auto *skybox = new(DemoSkybox);
|
||||
skybox->angle = {0,0,0};
|
||||
skybox->SetParent(engine->world);
|
||||
|
||||
engine->renderLoop();
|
||||
}
|
||||
|
||||
|
9
src/demo/RuntimeTest/src/demoSky.cpp
Normal file
9
src/demo/RuntimeTest/src/demoSky.cpp
Normal file
@@ -0,0 +1,9 @@
|
||||
#include <demoSky.h>
|
||||
#include <engine/engine.h>
|
||||
|
||||
DemoSkybox::DemoSkybox() {
|
||||
name = "skybox";
|
||||
modelPath = engine->workingDir + "/assets/models/sphere_vlo.obj";
|
||||
texturePath = engine->workingDir + "/assets/textures/skybox.png";
|
||||
setScale(engine->farPlane);
|
||||
}
|
33
src/demo/RuntimeTest/src/freeCam.cpp
Normal file
33
src/demo/RuntimeTest/src/freeCam.cpp
Normal file
@@ -0,0 +1,33 @@
|
||||
#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);
|
||||
|
||||
if (engine->window->isKeyDown(Keys::A))
|
||||
hMove(lAngle(), 4);
|
||||
|
||||
if (engine->window->isKeyDown(Keys::D))
|
||||
hMove(rAngle(), 4);
|
||||
|
||||
if (engine->window->isKeyDown(Keys::Z))
|
||||
vMove(4);
|
||||
|
||||
if (engine->window->isKeyDown(Keys::X))
|
||||
vMove(-4);
|
||||
|
||||
if (engine->window->isKeyDown(Keys::Q))
|
||||
this->angle.y -=75.0f*engine->frameDelta;
|
||||
|
||||
if (engine->window->isKeyDown(Keys::E))
|
||||
this->angle.y +=75.0f*engine->frameDelta;
|
||||
|
||||
if (engine->window->isKeyDown(Keys::UpArrow))
|
||||
this->angle.x -=75.0f*engine->frameDelta;
|
||||
|
||||
if (engine->window->isKeyDown(Keys::DownArrow))
|
||||
this->angle.x +=75.0f*engine->frameDelta;
|
||||
}
|
@@ -97,23 +97,9 @@ void Engine::initGL()
|
||||
void Engine::init()
|
||||
{
|
||||
engine->window->Open();
|
||||
engine->window->setResizable(false);
|
||||
engine->initGL();
|
||||
engine->loadConfig();
|
||||
engine->world->setAmbientLightColor(1.0f, 1.0f, 1.0f, 0.0f);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
|
||||
|
||||
auto* camera = new Camera();
|
||||
camera->SetPos({0.0f, -2.0f, -5.0f});
|
||||
camera->angle.y = 0.0f;
|
||||
camera->SetParent(engine->world);
|
||||
|
||||
auto *skybox = new Skybox();
|
||||
skybox->draw = true;
|
||||
skybox->angle = {0,0,0};
|
||||
skybox->SetParent(engine->world);
|
||||
|
||||
Shader test("test", engine->workingDir + "/assets/shaders/defaultVertex.glsl", engine->workingDir + "/assets/shaders/defaultFragment.glsl");
|
||||
}
|
||||
|
||||
void Engine::preRender()
|
||||
@@ -138,7 +124,6 @@ void Engine::initGL()
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
|
||||
//TODO: *Always* render the camera first.
|
||||
glCullFace(GL_BACK);
|
||||
for (auto& e : engine->world->GetChildren()) {
|
||||
if (e->draw)
|
||||
@@ -196,19 +181,6 @@ void Engine::initGL()
|
||||
}
|
||||
}
|
||||
|
||||
void Engine::debugInfo() const {
|
||||
//if (this->debug) {
|
||||
//placeholder
|
||||
//if (engine->frameCount % 1000 == 0) {
|
||||
std::cout << "Last frame dT: " << this->frameDelta << std::endl;
|
||||
std::cout << "Framerate: " << framerate() << std::endl;
|
||||
//std::cout << "EntityCount: " << entityList.list.size() << std::endl;
|
||||
//std::cout << "Camera Position: " << "X " << entityList.getCamera()->position.x << " Y " << entityList.getCamera()->position.y << " Z " << entityList.getCamera()->position.z << std::endl;
|
||||
|
||||
//}
|
||||
//}
|
||||
}
|
||||
|
||||
float Engine::framerate() const
|
||||
{
|
||||
return 1.f / this->frameDelta;
|
||||
|
@@ -2,120 +2,24 @@
|
||||
#include <engine/occlusion.h>
|
||||
#include <GL/glu.h>
|
||||
|
||||
// Even tho CLion reports this as const-qualifiable
|
||||
// It is not in "intent" (obviously the gametick changes gamestate)
|
||||
void Camera::update()
|
||||
{
|
||||
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 Camera::modeBinds() {
|
||||
if (engine->window->isKeyDown(Keys::Zero)) {
|
||||
//takingScreenshot = true;
|
||||
engine->debugInfo();
|
||||
}
|
||||
|
||||
if (engine->window->isKeyDown(Keys::One))
|
||||
cameraMode = CameraMode::FREECAM;
|
||||
|
||||
if (engine->window->isKeyDown(Keys::Two))
|
||||
cameraMode = CameraMode::THIRD_PERSON;
|
||||
|
||||
if (engine->window->isKeyDown(Keys::Three))
|
||||
cameraMode = CameraMode::SCRIPTED_MOVE;
|
||||
}
|
||||
void Camera::freeCam() {
|
||||
if (engine->window->isKeyDown(Keys::S)) {
|
||||
hMove(bAngle(), 4);
|
||||
}
|
||||
if (engine->window->isKeyDown(Keys::W)) {
|
||||
hMove(fAngle(), 4);
|
||||
}
|
||||
if (engine->window->isKeyDown(Keys::A)) {
|
||||
hMove(lAngle(), 4);
|
||||
}
|
||||
if (engine->window->isKeyDown(Keys::D)) {
|
||||
hMove(rAngle(), 4);
|
||||
}
|
||||
|
||||
if (engine->window->isKeyDown(Keys::Z))
|
||||
{
|
||||
vMove(4);
|
||||
}
|
||||
|
||||
if (engine->window->isKeyDown(Keys::X)) {
|
||||
vMove(-4);
|
||||
}
|
||||
|
||||
if (engine->window->isKeyDown(Keys::Q)) {
|
||||
this->angle.y -=75.0f*engine->frameDelta;
|
||||
}
|
||||
if (engine->window->isKeyDown(Keys::E)) {
|
||||
this->angle.y +=75.0f*engine->frameDelta;
|
||||
}
|
||||
if (engine->window->isKeyDown(Keys::UpArrow)) {
|
||||
this->angle.x -=75.0f*engine->frameDelta;
|
||||
}
|
||||
if (engine->window->isKeyDown(Keys::DownArrow)) {
|
||||
this->angle.x +=75.0f*engine->frameDelta;
|
||||
}
|
||||
}
|
||||
void Camera::thirdPerson() {
|
||||
//Player* player;
|
||||
//for (auto& e : engine->world->GetChildren())
|
||||
//if (auto* p = dynamic_cast<Player*>(e) )
|
||||
//player = p;
|
||||
|
||||
//if (engine->debug)
|
||||
//std::cout << "Calculated Pitch: " << VectorMath::calcAngle(position,player->GetPos()).x << " Calculated Yaw: " << VectorMath::calcAngle(position,player->GetPos()).y << std::endl;
|
||||
//position = //player->cameraPoint(5);
|
||||
//Make the camera pitch down a little bit.
|
||||
//this->position.y += 0.5;
|
||||
//this->angle.x = VectorMath::calcAngle(position,player->GetPos()).x;
|
||||
//this->angle.y = VectorMath::calcAngle(position,player->GetPos()).y;
|
||||
}
|
||||
void Camera::pre_render() {
|
||||
modeBinds();
|
||||
if (cameraMode == CameraMode::FREECAM)
|
||||
freeCam();
|
||||
if (cameraMode == CameraMode::THIRD_PERSON)
|
||||
thirdPerson();
|
||||
}
|
||||
void Camera::render() {
|
||||
// Preferrably: Camera would return a coordinate system that GameEngine
|
||||
// would set gluLookAt() with, this helps keep objects self contained
|
||||
//TODO
|
||||
//this->angle.clamp();
|
||||
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);
|
||||
|
||||
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.
|
||||
upVector.x,upVector.y,upVector.z);
|
||||
}
|
||||
|
||||
void Camera::post_render() {
|
||||
this->ticksAlive++;
|
||||
ticksAlive++;
|
||||
}
|
||||
|
||||
//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(Vector3 a, float vel) {
|
||||
if (cameraMode == CameraMode::FREECAM) {
|
||||
Moby::hMove(a,vel);
|
||||
}
|
||||
}
|
||||
|
||||
bool Camera::raycast(Entity *entity) {
|
||||
Vector3 rayOrigin = position;
|
||||
Vector3 rayAngle = angle;
|
||||
|
||||
}
|
||||
|
@@ -121,6 +121,8 @@ void Entity::render() {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cameraInside)
|
||||
glCullFace(GL_FRONT);
|
||||
|
||||
//Done to avoid using the dynamic cast more than once because it's comparatively slow.
|
||||
if (auto* t = dynamic_cast<MultiTexture*>(this->getTexture()))
|
||||
@@ -203,6 +205,8 @@ void Entity::render() {
|
||||
glDisableClientState(GL_VERTEX_ARRAY);
|
||||
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
|
||||
}
|
||||
if (cameraInside)
|
||||
glCullFace(GL_BACK);
|
||||
}
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
glClientActiveTexture(GL_TEXTURE0);
|
||||
|
@@ -1,14 +0,0 @@
|
||||
#include <types/entity/renderPlane.h>
|
||||
|
||||
VertexArray RenderPlane::getGeometry() const{
|
||||
return geometry;
|
||||
}
|
||||
|
||||
void RenderPlane::update(float elapsed) {
|
||||
//TODO:
|
||||
//Teleport this engine->nearPlane + float min in front of the camera.
|
||||
//Calculate the size of the near plane.
|
||||
//Allow image rendering to the plane using UV's. (The resolution and fovY will probably need to be taken into account).
|
||||
//It's also probably possible to render to this using OpenGL and glOrtho.
|
||||
|
||||
}
|
@@ -10,7 +10,6 @@ void Skybox::pre_render() {
|
||||
}
|
||||
|
||||
void Skybox::render() {
|
||||
glColor3f(0.75,0.75,0.75);
|
||||
glPushMatrix();
|
||||
glTranslatef(position.x ,position.y, position.z);
|
||||
glBindTexture(GL_TEXTURE_2D, getTexture()->id);
|
||||
@@ -25,6 +24,6 @@ void Skybox::render() {
|
||||
Skybox::Skybox() {
|
||||
name = "skybox";
|
||||
modelPath = engine->workingDir + "/assets/models/sphere_vlo.obj";
|
||||
texturePath = engine->workingDir + "/assets/textures/skybox.png";
|
||||
texturePath = engine->workingDir + "/assets/textures/missing.png";
|
||||
setScale(engine->farPlane);
|
||||
}
|
Reference in New Issue
Block a user