Renamed matrices. I quite like names such as 'modelToWorldMatrix' and 'cameraToClipMatrix' because they were very explicit about what the transform was doing. However OpenGL uses common terms such as 'model matrix' and 'projection matrix', so other people wlil be able to follow the code more easily if we stick to these conventions.
This commit is contained in:
@ -106,9 +106,9 @@ void OpenGLWidget::resizeGL(int w, int h)
|
||||
float zNear = 1.0;
|
||||
float zFar = 1000.0;
|
||||
|
||||
cameraToClipMatrix.setToIdentity();
|
||||
//cameraToClipMatrix.frustum(-aspectRatio, aspectRatio, -1, 1, zNear, zFar);
|
||||
cameraToClipMatrix.perspective(mCameraFOV, aspectRatio, zNear, zFar);
|
||||
projectionMatrix.setToIdentity();
|
||||
//projectionMatrix.frustum(-aspectRatio, aspectRatio, -1, 1, zNear, zFar);
|
||||
projectionMatrix.perspective(mCameraFOV, aspectRatio, zNear, zFar);
|
||||
}
|
||||
|
||||
void OpenGLWidget::paintGL()
|
||||
@ -154,8 +154,8 @@ void OpenGLWidget::paintGL()
|
||||
mCameraPosition -= cameraRight * deltaTime * mCameraMoveSpeed;
|
||||
}
|
||||
|
||||
worldToCameraMatrix.setToIdentity();
|
||||
worldToCameraMatrix.lookAt(
|
||||
viewMatrix.setToIdentity();
|
||||
viewMatrix.lookAt(
|
||||
mCameraPosition, // Camera is here
|
||||
mCameraPosition + cameraForward, // and looks here : at the same position, plus "direction"
|
||||
cameraUp // Head is up (set to 0,-1,0 to look upside-down)
|
||||
|
@ -66,8 +66,8 @@ protected:
|
||||
protected:
|
||||
|
||||
// Matrices
|
||||
QMatrix4x4 worldToCameraMatrix;
|
||||
QMatrix4x4 cameraToClipMatrix;
|
||||
QMatrix4x4 viewMatrix;
|
||||
QMatrix4x4 projectionMatrix;
|
||||
|
||||
// Mouse data
|
||||
QPoint m_LastFrameMousePos;
|
||||
|
@ -163,17 +163,17 @@ protected:
|
||||
mShader->bind();
|
||||
|
||||
// These two matrices are constant for all meshes.
|
||||
mShader->setUniformValue("worldToCameraMatrix", worldToCameraMatrix);
|
||||
mShader->setUniformValue("cameraToClipMatrix", cameraToClipMatrix);
|
||||
mShader->setUniformValue("viewMatrix", viewMatrix);
|
||||
mShader->setUniformValue("projectionMatrix", projectionMatrix);
|
||||
|
||||
// Iterate over each mesh which the user added to our list, and render it.
|
||||
for (OpenGLMeshData meshData : mMeshData)
|
||||
{
|
||||
//Set up the model matrrix based on provided translation and scale.
|
||||
QMatrix4x4 modelToWorldMatrix;
|
||||
modelToWorldMatrix.translate(meshData.translation);
|
||||
modelToWorldMatrix.scale(meshData.scale);
|
||||
mShader->setUniformValue("modelToWorldMatrix", modelToWorldMatrix);
|
||||
QMatrix4x4 modelMatrix;
|
||||
modelMatrix.translate(meshData.translation);
|
||||
modelMatrix.scale(meshData.scale);
|
||||
mShader->setUniformValue("modelMatrix", modelMatrix);
|
||||
|
||||
// Bind the vertex array for the current mesh
|
||||
glBindVertexArray(meshData.vertexArrayObject);
|
||||
|
@ -3,9 +3,9 @@
|
||||
in vec4 position; // This will be the position of the vertex in model-space
|
||||
|
||||
// The usual matrices are provided
|
||||
uniform mat4 cameraToClipMatrix;
|
||||
uniform mat4 worldToCameraMatrix;
|
||||
uniform mat4 modelToWorldMatrix;
|
||||
uniform mat4 projectionMatrix;
|
||||
uniform mat4 viewMatrix;
|
||||
uniform mat4 modelMatrix;
|
||||
|
||||
// This will be used by the fragment shader to calculate flat-shaded normals. This is an unconventional approach
|
||||
// but we use it in this example framework because not all surface extractor generate surface normals.
|
||||
@ -14,7 +14,7 @@ out vec4 worldPosition;
|
||||
void main()
|
||||
{
|
||||
// Standard sequence of OpenGL transformations.
|
||||
worldPosition = modelToWorldMatrix * position;
|
||||
vec4 cameraPosition = worldToCameraMatrix * worldPosition;
|
||||
gl_Position = cameraToClipMatrix * cameraPosition;
|
||||
worldPosition = modelMatrix * position;
|
||||
vec4 cameraPosition = viewMatrix * worldPosition;
|
||||
gl_Position = projectionMatrix * cameraPosition;
|
||||
}
|
||||
|
Reference in New Issue
Block a user