gpt4 book ai didi

c++ - 如何设置对象转换、属性?

转载 作者:行者123 更新时间:2023-11-30 05:39:33 25 4
gpt4 key购买 nike

我是 OpenGL 的新手,正在做在线类(class)的作业。我的第一个任务是用代码填充煎锅:旋转、缩放、平移、透视、左/右移动、上/下移动。我做到了,但在下一个任务中遇到了问题:设置转换。你能告诉我一个例子或一些链接如何做吗?任何帮助将不胜感激。

  for (int i = 0 ; i < numobjects ; i++) {
object* obj = &(objects[i]);

// Set up the object transformations
// And pass in the appropriate material properties
// Again glUniform() related functions will be useful

// Actually draw the object
// We provide the actual glut drawing functions for you.
// Remember that obj->type is notation for accessing struct fields


if (obj->type == cube) {
glutSolidCube(obj->size);
}
else if (obj->type == sphere) {
const int tessel = 20;
glutSolidSphere(obj->size, tessel, tessel);
}
else if (obj->type == teapot) {
glutSolidTeapot(obj->size);
}

}

const int maxobjects = 10 ; 
EXTERN int numobjects ;
EXTERN struct object {
shape type ;
GLfloat size ;
GLfloat ambient[4] ;
GLfloat diffuse[4] ;
GLfloat specular[4] ;
GLfloat emission[4] ;
GLfloat shininess ;
mat4 transform ;

} objects[maxobjects];

最佳答案

现代 OpenGL 中的变换是通过在着色器中使用统一矩阵来完成的。基本上,您必须查询转换变量 (glGetUniformLocation) 的统一位置,然后使用 glUniformMatrix4fvobj->transform 成员传递到该位置。 .

对于 Material 参数,工作流程基本相同,但使用适合类型的不同 glUniform* 调用。

关于c++ - 如何设置对象转换、属性?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32308833/

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