Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/149.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 如何设置对象变换、属性?_C++_Opengl - Fatal编程技术网

C++ 如何设置对象变换、属性?

C++ 如何设置对象变换、属性?,c++,opengl,C++,Opengl,我是OpenGL新手,在网上做作业。我的第一个任务是用代码填充平底锅:旋转、缩放、平移、透视、左/右移动、上/下移动。我做到了,但在下一个任务中遇到了一个问题:设置转换。你能给我看一个例子或一些如何做的链接吗? 任何帮助都将不胜感激 for (int i = 0 ; i < numobjects ; i++) { object* obj = &(objects[i]); // Set up the object transformations //

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

  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); 
    }

  }

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

对于材质参数,工作流基本相同,但具有不同的glUniform*调用,适合该类型

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];