feat(viewport): add setUniform camera method
This commit is contained in:
@@ -6,6 +6,8 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <glm/ext/quaternion_trigonometric.hpp>
|
#include <glm/ext/quaternion_trigonometric.hpp>
|
||||||
#include <glm/ext/quaternion_float.hpp>
|
#include <glm/ext/quaternion_float.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
#include <QOpenGLFunctions>
|
||||||
|
|
||||||
void printMatrix(const glm::mat4& matrix) {
|
void printMatrix(const glm::mat4& matrix) {
|
||||||
for (int i = 0; i < 4; ++i) {
|
for (int i = 0; i < 4; ++i) {
|
||||||
@@ -132,3 +134,8 @@ glm::vec3 GLCamera::getForward()
|
|||||||
return glm::normalize(camCenter_-camPos_);
|
return glm::normalize(camCenter_-camPos_);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void GLCamera::setUniform(uint uniformLocation)
|
||||||
|
{
|
||||||
|
QOpenGLFunctions *f = QOpenGLContext::currentContext()->functions();
|
||||||
|
f->glUniformMatrix4fv(uniformLocation, 1, GL_FALSE, glm::value_ptr(getViewMatrix()));
|
||||||
|
}
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public:
|
|||||||
void changeRadius(float delta);
|
void changeRadius(float delta);
|
||||||
void changeCenter(float x, float y, float z);
|
void changeCenter(float x, float y, float z);
|
||||||
void setCenter(float x, float y, float z);
|
void setCenter(float x, float y, float z);
|
||||||
|
void setUniform(uint uniformLocation);
|
||||||
|
|
||||||
glm::vec3 getForward();
|
glm::vec3 getForward();
|
||||||
glm::vec3 getRight();
|
glm::vec3 getRight();
|
||||||
|
|||||||
@@ -133,14 +133,11 @@ void ViewportGLWidget::paintGL()
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
glm::mat4 viewMatrix = curCamera.getViewMatrix();
|
|
||||||
|
|
||||||
|
|
||||||
GLint projMLoc = glGetUniformLocation(shaderProgram, "uProj");
|
GLint projMLoc = glGetUniformLocation(shaderProgram, "uProj");
|
||||||
glUniformMatrix4fv(projMLoc, 1, GL_FALSE, glm::value_ptr(projMatrix));
|
glUniformMatrix4fv(projMLoc, 1, GL_FALSE, glm::value_ptr(projMatrix));
|
||||||
|
|
||||||
GLint viewMLoc = glGetUniformLocation(shaderProgram, "uView");
|
GLint viewMLoc = glGetUniformLocation(shaderProgram, "uView");
|
||||||
glUniformMatrix4fv(viewMLoc, 1, GL_FALSE, glm::value_ptr(viewMatrix));
|
curCamera.setUniform(viewMLoc);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user