Allow changing the fov and render distance
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 4m30s
All checks were successful
Run ReCI Build Test / Explore-Gitea-Actions (push) Successful in 4m30s
This commit is contained in:
34
main.cpp
34
main.cpp
@@ -71,17 +71,6 @@ private:
|
||||
|
||||
|
||||
Texture* image;
|
||||
//The Re3D style base projection.
|
||||
std::vector<GLfloat> perspective(float fov, float aspect, float nearPlane, float farPlane) {
|
||||
std::vector<float> result(16);
|
||||
float f = 1.0f / tan(fov * 0.5f * M_PI / 180.0f);
|
||||
result[0] = f / aspect;
|
||||
result[5] = f;
|
||||
result[10] = (farPlane + nearPlane) / (nearPlane - farPlane);
|
||||
result[11] = -1.0f;
|
||||
result[14] = (2.0f * farPlane * nearPlane) / (nearPlane - farPlane);
|
||||
return result;
|
||||
}
|
||||
|
||||
class Camera {
|
||||
public:
|
||||
@@ -133,22 +122,15 @@ class JGLDemoWindow : public ReWindow::RWindow
|
||||
public:
|
||||
void initGL() {
|
||||
camera = new Camera;
|
||||
auto window_size = getSize();
|
||||
auto aspect = (float) window_size[0] / (float) window_size[1];
|
||||
|
||||
gladLoadGL();
|
||||
JGL::InitTextEngine();
|
||||
JGL::Update(getSize());
|
||||
J3D::Init(getSize(), 90, 100);
|
||||
FreeSans = JGL::Font("assets/fonts/FreeSans.ttf");
|
||||
Jupiteroid = JGL::Font("assets/fonts/Jupiteroid.ttf");
|
||||
|
||||
glMatrixMode(GL_PROJECTION);
|
||||
glLoadIdentity();
|
||||
glMultMatrixf(perspective(75, aspect, 0.001, 100).data());
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
glLoadIdentity();
|
||||
glClearColor(0.f, 0.f, 0.f, 0.f);
|
||||
glViewport(0,0,window_size.x,window_size.y);
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glDepthFunc(GL_LESS);
|
||||
glDepthMask(GL_TRUE);
|
||||
@@ -156,8 +138,22 @@ public:
|
||||
}
|
||||
|
||||
Vector3 textAngle = {0,0,0};
|
||||
float fov = 90;
|
||||
bool fov_increasing = true;
|
||||
|
||||
void display() {
|
||||
JGL::Update(getSize());
|
||||
if (fov_increasing)
|
||||
fov += 0.25;
|
||||
else
|
||||
fov -= 0.50;
|
||||
|
||||
if (fov >= 120)
|
||||
fov_increasing = false;
|
||||
else if (fov <= 75)
|
||||
fov_increasing = true;
|
||||
J3D::ChangeFOV(fov);
|
||||
|
||||
textAngle.y += 2.0f;
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
glMatrixMode(GL_MODELVIEW);
|
||||
|
Reference in New Issue
Block a user