Compare commits

..

No commits in common. "205ef0e7aaf0bc79572a6d90100b507b63264fd7" and "442020f271c856cf1e10a36f742dcb1c0a4656d5" have entirely different histories.

5 changed files with 25 additions and 58 deletions

View file

@ -1,13 +1,4 @@
cmake_minimum_required(VERSION 3.14) cmake_minimum_required(VERSION 3.14)
if(DEFINED ENV{VCPKG_ROOT})
set(VCPKG_TARGET_TRIPLET "x64-windows")
if(NOT DEFINED CMAKE_TOOLCHAIN_FILE)
set(CMAKE_TOOLCHAIN_FILE "$ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake"
CACHE STRING "")
endif()
endif()
project(tests_opengl) project(tests_opengl)
set(CMAKE_CXX_STANDARD 14) set(CMAKE_CXX_STANDARD 14)

View file

@ -20,12 +20,7 @@ As this project evolves I am thinking more and more about making it a "complete"
- [ ] Detect key press' edges ? - [ ] Detect key press' edges ?
- [ ] Switch from GLUT to GLFW - [ ] Switch from GLUT to GLFW
## Building ## Dependencies
The windows build supports only supports the `vcpkg` package manager. You can either import the project directly in Visual Studio or use another IDE.
In order to use another IDE with vcpkg, make sure of the following:
- `VCPKG_ROOT` is an environment variable and correctly points at the root of your vcpkg install.
### Dependencies
The following libraries must be installed and findable by CMake: The following libraries must be installed and findable by CMake:
- OpenGL - OpenGL

View file

@ -6,7 +6,7 @@
// Initialize static members // Initialize static members
Vec2i InputStatus::window_size; Vec2i InputStatus::window_center;
Vec2f InputStatus::mouse_sensitivity{100, 100}; Vec2f InputStatus::mouse_sensitivity{100, 100};
std::map<unsigned char,bool> InputStatus::ascii_keys_status = {}; std::map<unsigned char,bool> InputStatus::ascii_keys_status = {};
@ -103,41 +103,25 @@ void InputStatus::update_special_key(int event_key, bool new_status)
// Mouse // Mouse
// ================== // ==================
void InputStatus::keep_cursor_bounded(int mouse_x, int mouse_y)
{
if (mouse_x < cursor_bounds_width)
{
glutWarpPointer(window_size.x - cursor_bounds_width, mouse_y);
}
else if (mouse_x > window_size.x - cursor_bounds_width)
{
glutWarpPointer(cursor_bounds_width, mouse_y);
}
if (mouse_y < cursor_bounds_width)
{
glutWarpPointer(mouse_x, window_size.y - cursor_bounds_width);
}
else if (mouse_y > window_size.y - cursor_bounds_width)
{
glutWarpPointer(mouse_x, cursor_bounds_width);
}
}
void InputStatus::mouse_movement(int mouse_x, int mouse_y) void InputStatus::mouse_movement(int mouse_x, int mouse_y)
{ {
Vec2i current_frame; Vec2i current_frame;
current_frame.x = mouse_x; current_frame.x = mouse_x;
current_frame.y = mouse_y; current_frame.y = mouse_y;
keep_cursor_bounded(mouse_x, mouse_y); // Prevent counting the glutWarpPointer movement into account
if (current_frame != window_center)
Vec2i frame_delta = current_frame - last_mouse_position;
// Prevent jumping around when entering the window
if (frame_delta.magnitude() < window_size.magnitude() / 10)
{ {
current_mouse_delta.x += frame_delta.x; Vec2i frame_delta = current_frame - last_mouse_position;
current_mouse_delta.y += frame_delta.y; // Prevent jumping around when entering the window
if (frame_delta.magnitude() < window_center.magnitude()/10)
{
current_mouse_delta.x += frame_delta.x;
current_mouse_delta.y += frame_delta.y;
// Re-center mouse
glutWarpPointer(window_center.x, window_center.y);
}
} }
last_mouse_position = current_frame; last_mouse_position = current_frame;

View file

@ -41,7 +41,7 @@ public:
/// Accumulates the movements of the mouse /// Accumulates the movements of the mouse
static void mouse_movement(int mouse_x, int mouse_y); static void mouse_movement(int mouse_x, int mouse_y);
static Vec2i window_size; static Vec2i window_center;
static Vec2f mouse_sensitivity; static Vec2f mouse_sensitivity;
private: private:
@ -56,13 +56,9 @@ private:
static Vec2i last_mouse_delta; static Vec2i last_mouse_delta;
static Vec2i last_mouse_position; static Vec2i last_mouse_position;
static constexpr int cursor_bounds_width = 5;
// These functions are called by *_press and *_up to update their values // These functions are called by *_press and *_up to update their values
static void update_key(unsigned char event_key, bool new_status); static void update_key(unsigned char event_key, bool new_status);
static void update_special_key(int event_key, bool new_status); static void update_special_key(int event_key, bool new_status);
static void keep_cursor_bounded(int mouse_x, int mouse_y);
}; };

View file

@ -37,30 +37,30 @@ void manage_inputs()
if (InputStatus::is_special_key_pressed(GLUT_KEY_RIGHT)) if (InputStatus::is_special_key_pressed(GLUT_KEY_RIGHT))
{ {
timer_ticks += 5; timer_ticks += 5;
camera.translate({0,0,0.1}); camera.translate({0,0,1});
} }
if (InputStatus::is_special_key_pressed(GLUT_KEY_LEFT)) if (InputStatus::is_special_key_pressed(GLUT_KEY_LEFT))
{ {
timer_ticks -= 5; timer_ticks -= 5;
camera.translate({0,0,-0.1}); camera.translate({0,0,-1});
} }
if (InputStatus::is_key_pressed(' ')) if (InputStatus::is_key_pressed(' '))
{ {
camera.translate({0,0.1,0}); camera.translate({0,1,0});
} }
if (InputStatus::is_special_key_pressed(GLUT_KEY_PAGE_DOWN)) if (InputStatus::is_special_key_pressed(GLUT_KEY_PAGE_DOWN))
{ {
camera.translate({0,-0.1,0}); camera.translate({0,-1,0});
} }
if (InputStatus::is_special_key_pressed(GLUT_KEY_UP)) if (InputStatus::is_special_key_pressed(GLUT_KEY_UP))
{ {
camera.translate({0.1,0,0}); camera.translate({1,0,0});
} }
if (InputStatus::is_special_key_pressed(GLUT_KEY_DOWN)) if (InputStatus::is_special_key_pressed(GLUT_KEY_DOWN))
{ {
camera.translate({-0.1,0,0}); camera.translate({-1,0,0});
} }
// Get mouse delta since last frame // Get mouse delta since last frame
@ -109,8 +109,8 @@ void reshape(int new_x, int new_y)
glViewport(0,0,new_x,new_y); glViewport(0,0,new_x,new_y);
aspect_ratio = (double)new_x/new_y; aspect_ratio = (double)new_x/new_y;
InputStatus::window_size.x = new_x; InputStatus::window_center.x = new_x / 2;
InputStatus::window_size.y = new_y; InputStatus::window_center.y = new_y / 2;
} }
void update_angle(int value) void update_angle(int value)
@ -126,11 +126,12 @@ int main(int argc, char** argv)
glutInitDisplayMode(GLUT_RGB| GLUT_DEPTH | GLUT_DOUBLE); glutInitDisplayMode(GLUT_RGB| GLUT_DEPTH | GLUT_DOUBLE);
glutCreateWindow("OpenGL custom engine tests"); glutCreateWindow("OpenGL custom engine tests");
glutIgnoreKeyRepeat(true); glutIgnoreKeyRepeat(true);
glutSetCursor(GLUT_CURSOR_NONE);
// Init OpenGL // Init OpenGL
glClearColor(0,0,0,1); glClearColor(0,0,0,1);
glClearDepth(1.0); glClearDepth(1.0);
// glEnable(GL_LIGHTING);
// glEnable(GL_LIGHT0);
glEnable(GL_DEPTH_TEST); glEnable(GL_DEPTH_TEST);
// Setup OPenGL to use textures // Setup OPenGL to use textures