2015-08-31 106 views
1

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

    } 

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

回答

1

轉換在現代的OpenGL通過在着色器使用統一矩陣來完成。基本上,您將不得不查詢轉換變量的統一位置(glGetUniformLocation),然後使用glUniformMatrix4fvobj->transform成員傳遞到此位置。

對於材料參數,工作流程基本相同,但是具有與該類型不同的glUniform *調用。