2019-10-29 18:20:36 +01:00
|
|
|
#include <GL/glut.h>
|
|
|
|
#include <GL/gl.h>
|
2019-09-24 09:34:53 +02:00
|
|
|
|
2019-11-02 16:25:02 +01:00
|
|
|
#include "Engine.h"
|
2019-09-24 11:34:40 +02:00
|
|
|
#include "displayers.h"
|
2019-09-30 16:52:04 +02:00
|
|
|
#include "DataHandling/Texture.h"
|
|
|
|
#include "DataHandling/Model3D.h"
|
2019-10-28 23:45:44 +01:00
|
|
|
#include "InputStatus.h"
|
|
|
|
#include "Camera.h"
|
2019-09-24 09:34:53 +02:00
|
|
|
|
|
|
|
volatile unsigned long long int timer_ticks = 0;
|
2019-09-25 00:36:57 +02:00
|
|
|
static Texture tree_texture;
|
2019-09-30 16:52:04 +02:00
|
|
|
static Model3D raptor;
|
2019-09-30 19:20:10 +02:00
|
|
|
static Texture raptor_texture;
|
2019-09-24 09:34:53 +02:00
|
|
|
|
2019-10-07 18:46:35 +02:00
|
|
|
void manage_inputs()
|
|
|
|
{
|
2019-10-28 23:45:44 +01:00
|
|
|
if (InputStatus::is_mouse_button_pressed(GLUT_LEFT_BUTTON))
|
2019-10-14 21:48:49 +02:00
|
|
|
{
|
|
|
|
glClearColor(0,0,0.5,1);
|
|
|
|
}
|
2019-10-28 23:45:44 +01:00
|
|
|
else if (InputStatus::is_key_pressed(' '))
|
2019-10-07 18:46:35 +02:00
|
|
|
{
|
|
|
|
glClearColor(0.5,0,0,1);
|
|
|
|
}
|
2019-10-28 23:45:44 +01:00
|
|
|
else if (InputStatus::is_key_pressed(0x1B))
|
2019-10-19 04:24:08 +02:00
|
|
|
{
|
|
|
|
glutDestroyWindow(glutGetWindow());
|
|
|
|
exit(EXIT_SUCCESS);
|
|
|
|
}
|
2019-10-07 18:46:35 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
glClearColor(0,0,0,1);
|
|
|
|
}
|
|
|
|
|
2019-10-28 23:45:44 +01:00
|
|
|
if (InputStatus::is_special_key_pressed(GLUT_KEY_RIGHT))
|
2019-10-07 18:46:35 +02:00
|
|
|
{
|
|
|
|
timer_ticks += 5;
|
2019-11-03 15:31:45 +01:00
|
|
|
OGLE::camera.local_translate({0, 0, 0.1});
|
2019-10-07 18:46:35 +02:00
|
|
|
}
|
2019-10-28 23:45:44 +01:00
|
|
|
if (InputStatus::is_special_key_pressed(GLUT_KEY_LEFT))
|
2019-10-07 18:46:35 +02:00
|
|
|
{
|
|
|
|
timer_ticks -= 5;
|
2019-11-03 15:31:45 +01:00
|
|
|
OGLE::camera.local_translate({0, 0, -0.1});
|
2019-10-28 23:45:44 +01:00
|
|
|
}
|
|
|
|
if (InputStatus::is_key_pressed(' '))
|
|
|
|
{
|
2019-11-03 15:31:45 +01:00
|
|
|
OGLE::camera.local_translate({0, 0.1, 0});
|
2019-10-28 23:45:44 +01:00
|
|
|
}
|
|
|
|
if (InputStatus::is_special_key_pressed(GLUT_KEY_PAGE_DOWN))
|
|
|
|
{
|
2019-11-03 15:31:45 +01:00
|
|
|
OGLE::camera.local_translate({0, -0.1, 0});
|
2019-10-28 23:45:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (InputStatus::is_special_key_pressed(GLUT_KEY_UP))
|
|
|
|
{
|
2019-11-03 15:31:45 +01:00
|
|
|
OGLE::camera.local_translate({0.1, 0, 0});
|
2019-10-28 23:45:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (InputStatus::is_special_key_pressed(GLUT_KEY_DOWN))
|
|
|
|
{
|
2019-11-03 15:31:45 +01:00
|
|
|
OGLE::camera.local_translate({-0.1, 0, 0});
|
2019-10-28 23:45:44 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Get mouse delta since last frame
|
|
|
|
static Vec2i mouse_delta;
|
|
|
|
mouse_delta = InputStatus::get_mouse_delta(true);
|
|
|
|
if (mouse_delta.x != 0 || mouse_delta.y != 0)
|
|
|
|
{
|
2019-11-02 16:25:02 +01:00
|
|
|
OGLE::camera.rotate({0,
|
2019-10-28 23:45:44 +01:00
|
|
|
-mouse_delta.x / InputStatus::mouse_sensitivity.x,
|
|
|
|
-mouse_delta.y / InputStatus::mouse_sensitivity.y});
|
2019-10-07 18:46:35 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-24 09:34:53 +02:00
|
|
|
void display()
|
|
|
|
{
|
2019-10-07 18:46:35 +02:00
|
|
|
manage_inputs();
|
|
|
|
|
2019-09-24 09:34:53 +02:00
|
|
|
float angleY = 1*timer_ticks;
|
|
|
|
|
2019-09-24 11:34:40 +02:00
|
|
|
display_rotating_pyramid(-5,-2,-5,2,4,angleY);
|
|
|
|
display_rotating_pyramid(5,-2,0,1,5,angleY);
|
2019-09-24 09:34:53 +02:00
|
|
|
display_rotating_pyramid(-2,-2,4,3,2,angleY);
|
|
|
|
|
2019-09-25 00:36:57 +02:00
|
|
|
display_tree(0,-5,0,3,5,tree_texture);
|
|
|
|
|
2019-09-30 19:20:10 +02:00
|
|
|
glPushMatrix();
|
|
|
|
glRotatef(angleY,0,-1,0);
|
2019-09-30 16:52:04 +02:00
|
|
|
raptor.draw_model();
|
2019-09-30 19:20:10 +02:00
|
|
|
glPopMatrix();
|
2019-10-28 23:45:44 +01:00
|
|
|
}
|
|
|
|
|
2019-09-24 09:34:53 +02:00
|
|
|
void update_angle(int value)
|
|
|
|
{
|
|
|
|
timer_ticks++;
|
|
|
|
glutTimerFunc(50,update_angle,0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2019-11-02 16:25:02 +01:00
|
|
|
OGLE::setup(argc,argv,display);
|
2019-09-25 00:36:57 +02:00
|
|
|
|
|
|
|
// Load and generate tree texture
|
2019-09-25 13:02:24 +02:00
|
|
|
tree_texture.load_rgba_tga("resources/arbre.tga","resources/arbre_masque.tga");
|
2019-09-25 00:36:57 +02:00
|
|
|
|
2019-09-30 19:20:10 +02:00
|
|
|
// Load and generate raptor texture
|
|
|
|
raptor_texture.load_rgb_tga("resources/RAPTOR.tga");
|
|
|
|
|
2019-11-02 16:25:02 +01:00
|
|
|
// Load raptor model
|
2019-09-30 16:52:04 +02:00
|
|
|
raptor.load_ascii_off_file("resources/RAPTOR.off");
|
2019-09-30 19:20:10 +02:00
|
|
|
raptor.assign_texture(raptor_texture);
|
2019-09-30 16:52:04 +02:00
|
|
|
raptor.set_scaling(0.01,0.01,0.01);
|
|
|
|
raptor.set_rotation(-90,1,0,0);
|
|
|
|
|
2019-09-24 09:34:53 +02:00
|
|
|
|
|
|
|
glutTimerFunc(50,update_angle,0);
|
2019-11-02 16:25:02 +01:00
|
|
|
|
2019-11-03 18:03:30 +01:00
|
|
|
OGLE::camera.set_position({10,0,10});
|
|
|
|
OGLE::camera.rotate({0,1.5*M_PI_4,0});
|
2019-09-24 09:34:53 +02:00
|
|
|
|
|
|
|
// Enters main loop, managed by GLUT
|
|
|
|
glutMainLoop();
|
|
|
|
return 0;
|
|
|
|
}
|