|
|
|
@ -10,7 +10,6 @@ |
|
|
|
|
// because I am not a friend of orthogonal projections)
|
|
|
|
|
//========================================================================
|
|
|
|
|
|
|
|
|
|
#define GLFW_INCLUDE_GLU |
|
|
|
|
#define GLFW_INCLUDE_GLEXT |
|
|
|
|
#include <GLFW/glfw3.h> |
|
|
|
|
|
|
|
|
@ -23,6 +22,8 @@ |
|
|
|
|
#include <stdio.h> |
|
|
|
|
#include <stdlib.h> |
|
|
|
|
|
|
|
|
|
#include <linmath.h> |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//========================================================================
|
|
|
|
|
// Global variables
|
|
|
|
@ -151,6 +152,7 @@ static void drawGrid(float scale, int steps) |
|
|
|
|
{ |
|
|
|
|
int i; |
|
|
|
|
float x, y; |
|
|
|
|
mat4x4 view; |
|
|
|
|
|
|
|
|
|
glPushMatrix(); |
|
|
|
|
|
|
|
|
@ -159,10 +161,13 @@ static void drawGrid(float scale, int steps) |
|
|
|
|
glClear(GL_COLOR_BUFFER_BIT); |
|
|
|
|
|
|
|
|
|
// Setup modelview matrix (flat XY view)
|
|
|
|
|
glLoadIdentity(); |
|
|
|
|
gluLookAt(0.0, 0.0, 1.0, |
|
|
|
|
0.0, 0.0, 0.0, |
|
|
|
|
0.0, 1.0, 0.0); |
|
|
|
|
{ |
|
|
|
|
vec3 eye = { 0.f, 0.f, 1.f }; |
|
|
|
|
vec3 center = { 0.f, 0.f, 0.f }; |
|
|
|
|
vec3 up = { 0.f, 1.f, 0.f }; |
|
|
|
|
mat4x4_look_at(view, eye, center, up); |
|
|
|
|
} |
|
|
|
|
glLoadMatrixf((const GLfloat*) view); |
|
|
|
|
|
|
|
|
|
// We don't want to update the Z-buffer
|
|
|
|
|
glDepthMask(GL_FALSE); |
|
|
|
@ -211,13 +216,14 @@ static void drawAllViews(void) |
|
|
|
|
const GLfloat light_diffuse[4] = {1.0f, 1.0f, 1.0f, 1.0f}; |
|
|
|
|
const GLfloat light_specular[4] = {1.0f, 1.0f, 1.0f, 1.0f}; |
|
|
|
|
const GLfloat light_ambient[4] = {0.2f, 0.2f, 0.3f, 1.0f}; |
|
|
|
|
double aspect; |
|
|
|
|
float aspect; |
|
|
|
|
mat4x4 view, projection; |
|
|
|
|
|
|
|
|
|
// Calculate aspect of window
|
|
|
|
|
if (height > 0) |
|
|
|
|
aspect = (double) width / (double) height; |
|
|
|
|
aspect = (float) width / (float) height; |
|
|
|
|
else |
|
|
|
|
aspect = 1.0; |
|
|
|
|
aspect = 1.f; |
|
|
|
|
|
|
|
|
|
// Clear screen
|
|
|
|
|
glClearColor(0.0f, 0.0f, 0.0f, 0.0f); |
|
|
|
@ -249,10 +255,13 @@ static void drawAllViews(void) |
|
|
|
|
glViewport(0, height / 2, width / 2, height / 2); |
|
|
|
|
glScissor(0, height / 2, width / 2, height / 2); |
|
|
|
|
glMatrixMode(GL_MODELVIEW); |
|
|
|
|
glLoadIdentity(); |
|
|
|
|
gluLookAt(0.0f, 10.0f, 1e-3f, // Eye-position (above)
|
|
|
|
|
0.0f, 0.0f, 0.0f, // View-point
|
|
|
|
|
0.0f, 1.0f, 0.0f); // Up-vector
|
|
|
|
|
{ |
|
|
|
|
vec3 eye = { 0.f, 10.f, 1e-3f }; |
|
|
|
|
vec3 center = { 0.f, 0.f, 0.f }; |
|
|
|
|
vec3 up = { 0.f, 1.f, 0.f }; |
|
|
|
|
mat4x4_look_at( view, eye, center, up ); |
|
|
|
|
} |
|
|
|
|
glLoadMatrixf((const GLfloat*) view); |
|
|
|
|
drawGrid(0.5, 12); |
|
|
|
|
drawScene(); |
|
|
|
|
|
|
|
|
@ -260,10 +269,13 @@ static void drawAllViews(void) |
|
|
|
|
glViewport(0, 0, width / 2, height / 2); |
|
|
|
|
glScissor(0, 0, width / 2, height / 2); |
|
|
|
|
glMatrixMode(GL_MODELVIEW); |
|
|
|
|
glLoadIdentity(); |
|
|
|
|
gluLookAt(0.0f, 0.0f, 10.0f, // Eye-position (in front of)
|
|
|
|
|
0.0f, 0.0f, 0.0f, // View-point
|
|
|
|
|
0.0f, 1.0f, 0.0f); // Up-vector
|
|
|
|
|
{ |
|
|
|
|
vec3 eye = { 0.f, 0.f, 10.f }; |
|
|
|
|
vec3 center = { 0.f, 0.f, 0.f }; |
|
|
|
|
vec3 up = { 0.f, 1.f, 0.f }; |
|
|
|
|
mat4x4_look_at( view, eye, center, up ); |
|
|
|
|
} |
|
|
|
|
glLoadMatrixf((const GLfloat*) view); |
|
|
|
|
drawGrid(0.5, 12); |
|
|
|
|
drawScene(); |
|
|
|
|
|
|
|
|
@ -271,10 +283,13 @@ static void drawAllViews(void) |
|
|
|
|
glViewport(width / 2, 0, width / 2, height / 2); |
|
|
|
|
glScissor(width / 2, 0, width / 2, height / 2); |
|
|
|
|
glMatrixMode(GL_MODELVIEW); |
|
|
|
|
glLoadIdentity(); |
|
|
|
|
gluLookAt(10.0f, 0.0f, 0.0f, // Eye-position (to the right)
|
|
|
|
|
0.0f, 0.0f, 0.0f, // View-point
|
|
|
|
|
0.0f, 1.0f, 0.0f); // Up-vector
|
|
|
|
|
{ |
|
|
|
|
vec3 eye = { 10.f, 0.f, 0.f }; |
|
|
|
|
vec3 center = { 0.f, 0.f, 0.f }; |
|
|
|
|
vec3 up = { 0.f, 1.f, 0.f }; |
|
|
|
|
mat4x4_look_at( view, eye, center, up ); |
|
|
|
|
} |
|
|
|
|
glLoadMatrixf((const GLfloat*) view); |
|
|
|
|
drawGrid(0.5, 12); |
|
|
|
|
drawScene(); |
|
|
|
|
|
|
|
|
@ -294,17 +309,23 @@ static void drawAllViews(void) |
|
|
|
|
|
|
|
|
|
// Setup perspective projection matrix
|
|
|
|
|
glMatrixMode(GL_PROJECTION); |
|
|
|
|
glLoadIdentity(); |
|
|
|
|
gluPerspective(65.0f, aspect, 1.0f, 50.0f); |
|
|
|
|
mat4x4_perspective(projection, |
|
|
|
|
65.f * (float) M_PI / 180.f, |
|
|
|
|
aspect, |
|
|
|
|
1.f, 50.f); |
|
|
|
|
glLoadMatrixf((const GLfloat*) projection); |
|
|
|
|
|
|
|
|
|
// Upper right view (PERSPECTIVE VIEW)
|
|
|
|
|
glViewport(width / 2, height / 2, width / 2, height / 2); |
|
|
|
|
glScissor(width / 2, height / 2, width / 2, height / 2); |
|
|
|
|
glMatrixMode(GL_MODELVIEW); |
|
|
|
|
glLoadIdentity(); |
|
|
|
|
gluLookAt(3.0f, 1.5f, 3.0f, // Eye-position
|
|
|
|
|
0.0f, 0.0f, 0.0f, // View-point
|
|
|
|
|
0.0f, 1.0f, 0.0f); // Up-vector
|
|
|
|
|
{ |
|
|
|
|
vec3 eye = { 3.f, 1.5f, 3.f }; |
|
|
|
|
vec3 center = { 0.f, 0.f, 0.f }; |
|
|
|
|
vec3 up = { 0.f, 1.f, 0.f }; |
|
|
|
|
mat4x4_look_at( view, eye, center, up ); |
|
|
|
|
} |
|
|
|
|
glLoadMatrixf((const GLfloat*) view); |
|
|
|
|
|
|
|
|
|
// Configure and enable light source 1
|
|
|
|
|
glLightfv(GL_LIGHT1, GL_POSITION, light_position); |
|
|
|
|