gpt4 book ai didi

c++ - 如何重新定义 glm 矩阵变量或删除其变换?

转载 作者:行者123 更新时间:2023-11-30 04:53:08 26 4
gpt4 key购买 nike

我需要在不使用 for 循环的情况下一个接一个地制作多个模型。我用 glm::mat4 model(1) 定义了第一个,对其进行了一些平移和旋转,然后我想删除它的所有变换。但是让它等于 NULL 是行不通的。我可以调用 glm 中的某些函数吗?

另外还有一个问题,有人可以解释为什么我在声明 glm 矩阵变量时需要添加“(1)”。没有它是行不通的。在声明 glm 矩阵数组 glm::mat4 models[] 时,我是否还需要添加一些内容?因为数组似乎不存储变量。

最佳答案

glm::mat4 的默认构造函数不初始化矩阵,它使矩阵的字段未初始化。

glm API documentationThe OpenGL Shading Language specification 4.20 .

5.4.2 Vector and Matrix Constructors

If there is a single scalar parameter to a vector constructor, it is used to initialize all components of the constructed vector to that scalar’s value. If there is a single scalar parameter to a matrix constructor, it is used to initialize all the components on the matrix’s diagonal, with the remaining components initialized to 0.0.

这意味着,通过 Identity matrix 来初始化一个矩阵,必须使用具有单个标量的构造函数:

glm::mat4 model(1.0f);

当然还有 Identity matrix可以分配给现有矩阵:

model = glm::mat4(1.0f); 

动态数组,例如std::vector 可以生成 100 个单位矩阵轻松:

std::vector<glm::mat4> models(100, glm::mat4(1.0f));

关于c++ - 如何重新定义 glm 矩阵变量或删除其变换?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53979492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com