我正在尝试学习OpenGL中的转换,并且正在使用glm进行数学计算。我有一个向量,我想对该向量进行一些旋转。但是我得到的输出为vec3(0,0,0)
#define GLM_ENABLE_EXPERIMENTAL
#include <glm/ext/matrix_float4x4.hpp> // mat4x4
#include <glm/ext/matrix_transform.hpp> // translate, rotate, scale, identity
#include <glm/gtx/string_cast.hpp>
#include<iostream>
int main(){
//define a 4x4 model matrix
glm::mat4 model;
//define a vector
glm::vec4 Position = glm::vec4(glm::vec3(0.4,0.2,0.2), 1.0);
//create a model matrix with rotation of 45 degrees around z aixs
model = glm::rotate(model, 45.0f, glm::vec3(0.0f, 0.0f, 1.0f));
//print the final vector position after rotation is applied
std::cout<< glm::to_string(model*Position) <<std::endl;
return 0;
}
答案 0 :(得分:2)
您没有初始化模型矩阵。 应该是:
glm::mat4 model = glm::mat4(1.0f);
将其初始化为单位矩阵。