for graphics project i'm trying implement minimap. unlike usual objects thought specify vertex coordinates in opengl's default camera coordinate system. have vertices @ (-1,1,0)
, (1,1,0)
, (-1,-1,0)
, (1,-1,0)
. don't use projection matrix calculation of gl_position
. if don't use model view matrix, quad 4 vertices fills whole screen (as expected). want scale quad 100x100
pixels , put in upper right corner of viewport, distance of 40
border of viewport.
i tried setup model view matrix this:
// move upper right corner - targetdistance translate(vec3((viewportwidth - targetdistance) / viewportwidth, (viewportheight - targetdistance) / viewportheight), 0.0) // move upper right corner origin * translate(vec3(-0.5*targetwidth / viewportwidth,-0.5*targetheight / viewportwidth, 0.0) // scale desired size * scale(vec3(targetwidth / viewportwidth, targetheight / viewportheight, 0.0)
the corresponding cpp code looks (uses glm).
glm::uvec2 viewportsize = this->camera->getviewportsize(); const float targetwidth = 100; const float targetheight = 100; const float targetdistance = 40; glm::mat4 modelviewmatrix = glm::translate( glm::vec3((viewportsize.x - targetdistance) / viewportsize.x, (viewportsize.y - targetdistance) / viewportsize.y, 0.0)) * glm::translate(glm::vec3(-0.5f * targetwidth / viewportsize.x, -0.5f * targetheight / viewportsize.y, 0.0f)) * glm::scale(glm::vec3(targetwidth / viewportsize.x, targetheight / viewportsize.y, 0.0f));
unfortunately, doesn't work. minimap gets scaled correctly , put in upper right corner there no distance border (or negative one).
instead of fiddling vertex coordinate transformation suggest far more simpler? move viewport desired corner , size of window:
glviewport( lower_left_corner_in_the_window_in_pixels, lower_right_corner_in_the_window_in_pixels, width_in_pixels, height_in_pixels )
if initial though on "how should this? set viewport in resize (reshape) function" you're doing wrong. calls glviewport
belong drawing process, i.e. should placed in drawing code, right before opengl calls depend on viewport being set done.
Comments
Post a Comment