Changed cursor pos to double.

This commit is contained in:
Camilla Berglund 2013-04-04 16:16:21 +02:00
parent 4c0e946da3
commit 129e94da2e
12 changed files with 39 additions and 40 deletions

View File

@ -308,6 +308,7 @@ GLFW.
* Changed `glfwGetProcAddress` to return a (generic) function pointer
* Changed `glfwGetVideoModes` to return a dynamic, unlimited number of video
modes for the specified monitor
* Changed cursor position to double-precision floating-point
* Renamed `glfw.h` to `glfw3.h` to avoid conflicts with 2.x series
* Renamed `glfwOpenWindowHint` to `glfwWindowHint`
* Renamed `GLFW_ACTIVE` to `GLFW_FOCUSED`

View File

@ -27,7 +27,7 @@
//========================================================================
// Mouse position
static int xpos = 0, ypos = 0;
static double xpos = 0, ypos = 0;
// Window size
static int width, height;
@ -379,24 +379,24 @@ static void windowRefreshFun(GLFWwindow* window)
// Mouse position callback function
//========================================================================
static void cursorPosFun(GLFWwindow* window, int x, int y)
static void cursorPosFun(GLFWwindow* window, double x, double y)
{
// Depending on which view was selected, rotate around different axes
switch (active_view)
{
case 1:
rot_x += y - ypos;
rot_z += x - xpos;
rot_x += (int) y - ypos;
rot_z += (int) x - xpos;
do_redraw = 1;
break;
case 3:
rot_x += y - ypos;
rot_y += x - xpos;
rot_x += (int) y - ypos;
rot_y += (int) x - xpos;
do_redraw = 1;
break;
case 4:
rot_y += x - xpos;
rot_z += y - ypos;
rot_y += (int) x - xpos;
rot_z += (int) y - ypos;
do_redraw = 1;
break;
default:

View File

@ -335,7 +335,7 @@ void mouse_button_callback(GLFWwindow* window, int button, int action)
// Callback function for cursor motion events
//========================================================================
void cursor_position_callback(GLFWwindow* window, int x, int y)
void cursor_position_callback(GLFWwindow* window, double x, double y)
{
if (locked)
{

View File

@ -641,7 +641,7 @@ typedef void (* GLFWmousebuttonfun)(GLFWwindow*,int,int);
*
* @sa glfwSetCursorPosCallback
*/
typedef void (* GLFWcursorposfun)(GLFWwindow*,int,int);
typedef void (* GLFWcursorposfun)(GLFWwindow*,double,double);
/*! @brief The function signature for cursor enter/exit callbacks.
* @param[in] window The window that received the event.
@ -1730,7 +1730,7 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow* window, int button);
*
* @ingroup input
*/
GLFWAPI void glfwGetCursorPos(GLFWwindow* window, int* xpos, int* ypos);
GLFWAPI void glfwGetCursorPos(GLFWwindow* window, double* xpos, double* ypos);
/*! @brief Sets the position of the cursor, relative to the client area of the window.
*
@ -1748,7 +1748,7 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* window, int* xpos, int* ypos);
*
* @ingroup input
*/
GLFWAPI void glfwSetCursorPos(GLFWwindow* window, int xpos, int ypos);
GLFWAPI void glfwSetCursorPos(GLFWwindow* window, double xpos, double ypos);
/*! @brief Sets the key callback.
*

View File

@ -365,11 +365,7 @@ static int convertMacKeyCode(unsigned int macKeyCode)
[window->ns.object contentRectForFrameRect:[window->ns.object frame]];
const NSPoint p = [event locationInWindow];
// Cocoa coordinate system has origin at lower left
const int x = lround(floor(p.x));
const int y = contentRect.size.height - lround(ceil(p.y));
_glfwInputCursorMotion(window, x, y);
_glfwInputCursorMotion(window, p.x, contentRect.size.height - p.y);
}
}

View File

@ -38,7 +38,8 @@
//
static void setCursorMode(_GLFWwindow* window, int newMode)
{
int width, height, oldMode, centerPosX, centerPosY;
int width, height, oldMode;
double centerPosX, centerPosY;
if (newMode != GLFW_CURSOR_NORMAL &&
newMode != GLFW_CURSOR_HIDDEN &&
@ -54,8 +55,8 @@ static void setCursorMode(_GLFWwindow* window, int newMode)
_glfwPlatformGetWindowSize(window, &width, &height);
centerPosX = width / 2;
centerPosY = height / 2;
centerPosX = width / 2.0;
centerPosY = height / 2.0;
if (oldMode == GLFW_CURSOR_CAPTURED || newMode == GLFW_CURSOR_CAPTURED)
_glfwPlatformSetCursorPos(window, centerPosX, centerPosY);
@ -171,11 +172,11 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action)
window->callbacks.mouseButton((GLFWwindow*) window, button, action);
}
void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y)
void _glfwInputCursorMotion(_GLFWwindow* window, double x, double y)
{
if (window->cursorMode == GLFW_CURSOR_CAPTURED)
{
if (!x && !y)
if (x == 0.0 && y == 0.0)
return;
window->cursorPosX += x;
@ -297,7 +298,7 @@ GLFWAPI int glfwGetMouseButton(GLFWwindow* handle, int button)
return (int) window->mouseButton[button];
}
GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, int* xpos, int* ypos)
GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, double* xpos, double* ypos)
{
_GLFWwindow* window = (_GLFWwindow*) handle;
@ -310,7 +311,7 @@ GLFWAPI void glfwGetCursorPos(GLFWwindow* handle, int* xpos, int* ypos)
*ypos = window->cursorPosY;
}
GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, int xpos, int ypos)
GLFWAPI void glfwSetCursorPos(GLFWwindow* handle, double xpos, double ypos)
{
_GLFWwindow* window = (_GLFWwindow*) handle;

View File

@ -225,7 +225,7 @@ struct _GLFWwindow
// Window input state
GLboolean stickyKeys;
GLboolean stickyMouseButtons;
int cursorPosX, cursorPosY;
double cursorPosX, cursorPosY;
int cursorMode;
char mouseButton[GLFW_MOUSE_BUTTON_LAST + 1];
char key[GLFW_KEY_LAST + 1];
@ -344,7 +344,7 @@ const char* _glfwPlatformGetVersionString(void);
/*! @copydoc glfwSetCursorPos
* @ingroup platform
*/
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int xpos, int ypos);
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos);
/*! @brief Sets up the specified cursor mode for the specified window.
* @param[in] window The window whose cursor mode to change.
@ -614,7 +614,7 @@ void _glfwInputMouseClick(_GLFWwindow* window, int button, int action);
* of the client area of the window.
* @ingroup event
*/
void _glfwInputCursorMotion(_GLFWwindow* window, int x, int y);
void _glfwInputCursorMotion(_GLFWwindow* window, double x, double y);
/*! @brief Notifies shared code of a cursor enter/leave event.
* @param[in] window The window that received the event.

View File

@ -1049,9 +1049,9 @@ void _glfwPlatformWaitEvents(void)
_glfwPlatformPollEvents();
}
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int xpos, int ypos)
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double xpos, double ypos)
{
POINT pos = { xpos, ypos };
POINT pos = { (int) xpos, (int) ypos };
ClientToScreen(window->win32.handle, &pos);
SetCursorPos(pos.x, pos.y);
}

View File

@ -1004,13 +1004,14 @@ void _glfwPlatformWaitEvents(void)
_glfwPlatformPollEvents();
}
void _glfwPlatformSetCursorPos(_GLFWwindow* window, int x, int y)
void _glfwPlatformSetCursorPos(_GLFWwindow* window, double x, double y)
{
// Store the new position so it can be recognized later
window->x11.cursorPosX = x;
window->x11.cursorPosY = y;
XWarpPointer(_glfw.x11.display, None, window->x11.handle, 0,0,0,0, x, y);
XWarpPointer(_glfw.x11.display, None, window->x11.handle,
0,0,0,0, (int) x, (int) y);
}
void _glfwPlatformSetCursorMode(_GLFWwindow* window, int mode)

View File

@ -35,7 +35,7 @@
#include <stdio.h>
#include <stdlib.h>
static int cursor_x = 0, cursor_y = 0;
static double cursor_x = 0.0, cursor_y = 0.0;
static int window_width = 640, window_height = 480;
static int swap_interval = 1;
@ -68,7 +68,7 @@ static void window_size_callback(GLFWwindow* window, int width, int height)
gluOrtho2D(0.f, window_width, 0.f, window_height);
}
static void cursor_position_callback(GLFWwindow* window, int x, int y)
static void cursor_position_callback(GLFWwindow* window, double x, double y)
{
cursor_x = x;
cursor_y = y;

View File

@ -290,9 +290,9 @@ static void mouse_button_callback(GLFWwindow* window, int button, int action)
printf(" was %s\n", get_action_name(action));
}
static void cursor_position_callback(GLFWwindow* window, int x, int y)
static void cursor_position_callback(GLFWwindow* window, double x, double y)
{
printf("%08x at %0.3f: Cursor position: %i %i\n", counter++, glfwGetTime(), x, y);
printf("%08x at %0.3f: Cursor position: %f %f\n", counter++, glfwGetTime(), x, y);
}
static void cursor_enter_callback(GLFWwindow* window, int entered)

View File

@ -36,8 +36,8 @@
#include <stdlib.h>
static GLboolean reopen = GL_FALSE;
static int cursor_x;
static int cursor_y;
static double cursor_x;
static double cursor_y;
static void toggle_cursor(GLFWwindow* window)
{
@ -58,9 +58,9 @@ static void error_callback(int error, const char* description)
fprintf(stderr, "Error: %s\n", description);
}
static void cursor_position_callback(GLFWwindow* window, int x, int y)
static void cursor_position_callback(GLFWwindow* window, double x, double y)
{
printf("Cursor moved to: %i %i (%i %i)\n", x, y, x - cursor_x, y - cursor_y);
printf("Cursor moved to: %f %f (%f %f)\n", x, y, x - cursor_x, y - cursor_y);
cursor_x = x;
cursor_y = y;
}
@ -102,7 +102,7 @@ static GLFWwindow* open_window(void)
glfwSwapInterval(1);
glfwGetCursorPos(window, &cursor_x, &cursor_y);
printf("Cursor position: %i %i\n", cursor_x, cursor_y);
printf("Cursor position: %f %f\n", cursor_x, cursor_y);
glfwSetWindowSizeCallback(window, window_size_callback);
glfwSetCursorPosCallback(window, cursor_position_callback);