--- /dev/null
+#include <gmath/gmath.h>
+#include "camera.h"
+
+Camera::Camera()
+{
+ phi = theta = distance = 0;
+ fov = 0;
+ m_projection = Mat4::identity;
+}
+
+Camera::Camera(float phi, float theta, float distance, float fov)
+{
+ this->phi = phi;
+ this->theta = theta;
+ this->distance = distance;
+
+ this->fov = fov;
+}
+
+Camera::~Camera() {}
\ No newline at end of file
#include <string.h>
#include <vector>
-#include "object.h"
+/* TODO: fix those */
+#include "camera.h"
#include "mesh.h"
+#include "object.h"
#include "scene.h"
#include "opengl/opengl.h"
/* glfw callbacks */
static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mods);
+static void motion_clbk(GLFWwindow *win, double x, double y);
+static void mouse_clbk(GLFWwindow *win, int button, int action, int mods);
/* global variables */
bool use_vulkan;
+
GLFWwindow *win;
+int win_w = 800;
+int win_h = 600;
+
+Camera *camera;
/* variables */
+// TODO: remove just for test:
static Scene scene;
int main(int argc, char **argv)
}
glfwSetKeyCallback(win, key_clbk);
+ glfwSetCursorPosCallback(win, motion_clbk);
+ glfwSetMouseButtonCallback(win, mouse_clbk);
while(!glfwWindowShouldClose(win)) {
display();
return false;
}
+ camera = new Camera(25, 25, 4, 45);
+
if(!scene.load("data/spot/spot_control_mesh.obj")) {
fprintf(stderr, "Failed to load scene.\n");
return false;
else {
cleanup_opengl();
}
+
+ delete camera;
}
static void key_clbk(GLFWwindow *win, int key, int scancode, int action, int mods)
}
}
+static double prev_x, prev_y;
+static int bnstate[8];
+
+static void motion_clbk(GLFWwindow *win, double x, double y)
+{
+ int dx = x - prev_x;
+ int dy = y - prev_y;
+
+ prev_x = x;
+ prev_y = y;
+
+ if(!dx && !dy) return;
+
+ if(bnstate[0]) {
+ camera->theta += dx * 0.5;
+ camera->phi += dy * 0.5;
+
+ if(camera->phi < -90) camera->phi = -90;
+ if(camera->phi > 90) camera->phi = 90;
+ }
+ if(bnstate[2]) {
+ camera->distance += dy * 0.1;
+ if(camera->distance < 0.0) camera->distance = 0.0;
+ }
+}
+
+static void mouse_clbk(GLFWwindow *win, int bn, int action, int mods)
+{
+ bnstate[bn - GLFW_MOUSE_BUTTON_LEFT] = action == GLFW_PRESS ? 1 : 0;
+ glfwGetCursorPos(win, &prev_x, &prev_y);
+}
+
static void display()
{
if(use_vulkan) {
#include <stdio.h>
#include "opengl/opengl.h"
-#include "common-ui.h"
extern GLFWwindow *win;
+extern int win_h;
+extern int win_w;
+
+/* static test_* functions are going to be removed: just to test the shaders */
+static void test_draw();
+static void test_torus();
+
bool init_opengl()
{
if(!glfwInit()) {
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glClearColor(0.5, 0.5, 0.5, 1.0);
+
+}
+
+static void test_draw()
+{
+ /* this function is going to be removed, it's here only to test the shaders */
+
}
\ No newline at end of file
virtual void add_shader(Shader *sdr);
virtual bool link() = 0;
virtual bool load(const char *vfname, const char *ffname) = 0;
+ virtual void use() = 0;
+
+ /* THIS PART IS GOING TO BE CHANGED: on vulkan we set the uniforms
+ using descriptor sets. The current design is suitable for OpenGL and
+ it has to become more generic to work with both APIs later. */
};
#endif // SHADER_H_