-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
added ability to transform points to screenspace when window resizes #4
base: master
Are you sure you want to change the base?
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||
---|---|---|---|---|
|
@@ -107,6 +107,11 @@ void GLFWCharCallback(GLFWwindow* glfw_window, unsigned int codepoint) { | |||
|
||||
} // namespace | ||||
|
||||
glm::vec2 smk::Window::ToScreenSpace(const glm::vec2& world) { | ||||
glm::vec2 factor = glm::vec2(initialSize_.x/width_, initialSize_.y/height_); | ||||
return glm::vec2(world.x*factor.x, world.y*factor.y); | ||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The view can also be rotated / skewed. Line 74 in 24049a5
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm yeah the view could be accounted for. That would make sense and become very useful. My original intention was to match the window size even after resizing. I originally had this event handled by |
||||
} | ||||
|
||||
/// @brief A null window. | ||||
Window::Window() { | ||||
id_ = ++id; | ||||
|
@@ -123,6 +128,7 @@ Window::Window(int width, int height, const std::string& title) { | |||
window_by_id[id_] = this; | ||||
width_ = width; | ||||
height_ = height; | ||||
initialSize_ = {width, height}; | ||||
|
||||
glfwSetErrorCallback(GLFWErrorCallback); | ||||
// initialize the GLFW library | ||||
|
@@ -219,6 +225,7 @@ void Window::operator=(Window&& other) { | |||
std::swap(input_, other.input_); | ||||
std::swap(id_, other.id_); | ||||
std::swap(module_canvas_selector_, other.module_canvas_selector_); | ||||
std::swap(initialSize_, other.initialSize_); | ||||
window_by_id[id_] = this; | ||||
window_by_glfw_window[window_] = this; | ||||
} | ||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The name is a bit confusing, I would have thought we went from screen space to world coordinate.
What about MapPixelToWorldCoordinates?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the input is the world position and the output is the screenspace. This is pretty standard convention. Unsure how to make this more clear.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
MapPixelToWorldCoordinates would be appropriate the more I think about it. SFML uses this name too for that purpose I assume