I try to render a simple grid using glBegin(GL_LINES). I have a class Camera, which provides values like this:
float farPlane = 100.0f; float nearPlane= 0.1f; float screenRatio = 1,42857; //width/height = 1000/700 float frustum = 70.0f; glm::vec3 position = glm::vec3(3.0f, 3.0f, 3.0f); glm::vec3 UP = glm::vec3(0.0f, 1.0f, 0.0f); glm::mat4 view = glm::lookAt(position, position - glm::normalize(position), UP); // makes the lookAt vector always point towards (0, 0, 0) glm::mat4 projection = glm::perspective(frustum, screenRatio, nearPlane, farPlane); using the view and projection matrices, i transform every vertex from my Grid model and render it.
glm::mat4 viewProjectionMatrix = Graphic::camera->getViewProjectionMatrix(); // returns Camera::projection * Camera::view glBegin(GL_LINES); for (unsigned int i = 0; i < vertexNum; ++i) { glColor3f(vertexArray[i].normal.x, vertexArray[i].normal.y, vertexArray[i].normal.z); // normal vector is used for color in this case glm::vec4 translatedPosition(viewProjectionMatrix*gridTransformationMatrix*(glm::vec4(vertexArray[i].position, 1.0f))); glVertex3f(translatedPosition.x, translatedPosition.y, translatedPosition.z); } glEnd(); but this is what i see when i move the camera along the line: (0,0,0) + u*(1,1,1) http://i.imgur.com/PrcDcLs.gifv (you can see the camera cooridnates in the console)
viewProjectionMatrixcalculated? \$\endgroup\$glm::mat4 Graphic::Camera::getViewProjectionMatrix() { return glm::mat4(projection * view); }\$\endgroup\$