text
Some checks failed
Run ReCI Build Test / Explore-Gitea-Actions (push) Failing after 1m20s

This commit is contained in:
2024-07-08 19:12:16 -04:00
parent a8145cb926
commit 652626b2e4
3 changed files with 63 additions and 13 deletions

View File

@@ -19,6 +19,35 @@ std::vector<GLfloat> perspective(float fov, float aspect, float nearPlane, float
return result;
}
class Camera {
public:
Vector3 position = {0,0,0};
Vector3 angle = {0,0,0};
std::array<GLfloat, 16> lookAt(const Vector3& eye, const Vector3& center, const Vector3& up) {
Vector3 f = Vector3::Normalized((center - eye));
Vector3 upN = Vector3::Normalized(up);
Vector3 s = Vector3::Normalized(f.Cross(upN));
Vector3 u = Vector3::Normalized(s.Cross(f));
std::array<GLfloat, 16> result = {
s.x, u.x, -f.x, 0.0f,
s.y, u.y, -f.y, 0.0f,
s.z, u.z, -f.z, 0.0f,
-s.Dot(eye), -u.Dot(eye), f.Dot(eye), 1.0f
};
return result;
}
void 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);
glMultMatrixf(lookAt({position.x, position.y, position.z}, {position.x, position.y, 100.f + position.z}, {0,1,0}).data());
}
};
Camera* camera;
using J3ML::LinearAlgebra::Matrix4x4;
struct point {
@@ -35,6 +64,7 @@ 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];
@@ -56,17 +86,19 @@ public:
glDepthMask(GL_TRUE);
}
Vector3 textAngle = {0,0,0};
void display() {
textAngle.y += 1.0f;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
//camera->angle.y += 1;
camera->render();
///All 3D elements of the scene and JGL elements *must* be rendered before the 2d stuff.
J3D::Begin();
J3D::DrawLine(JGL::Colors::Red, {0,0,-1}, {1,0,-1.5});
J3D::DrawLine(JGL::Colors::Red, {0,0.0,-1}, {0,0.5,-1});
J3D::DrawString(JGL::Colors::Red, "JGL Sample Text", {-13, 1, -10.0f}, 0.0225, 32, FreeSans);
J3D::DrawLine(JGL::Colors::Red, {-0.33,-0.125,1}, {-1,-0.125,1});
J3D::DrawLine(JGL::Colors::Red, {-0.33,-0.125,1}, {-0.33,0.25,1});
J3D::DrawString(JGL::Colors::Red, "JGL Sample Text", {-0.33, -0.1, 1.0f},textAngle , 1.f, 32, FreeSans);
J3D::End();
J2D::Begin();
@@ -74,6 +106,8 @@ public:
J2D::FillTriangle(JGL::Colors::Yellow, {{140, 200},{135, 100},{105, 100}});
J2D::DrawLine(JGL::Colors::Greens::DarkGreen, {10, 10}, {200, 300});
J2D::DrawString(JGL::Colors::Green, "Jupteroid Font", 0.f, -48.f, 1.f, 16, Jupiteroid);
J2D::DrawString(JGL::Colors::White, "Position: " + std::to_string(camera->position.x) + " " + std::to_string(camera->position.y) + " " + std::to_string(camera->position.z), 0, -65, 1,16, Jupiteroid);
J2D::DrawString(JGL::Colors::White, "ViewAngle: " + std::to_string(camera->angle.x) + " " + std::to_string(camera->angle.y) + " " + std::to_string(camera->angle.z), 0, -82, 1,16, Jupiteroid);
J2D::End();
}