2011-12-24 71 views
1

當我在GMax中加載.obj文件時,它位於空間的中心(0,0,0)。 我該如何改變這個位置?有沒有特別的功能?OpenGL pModel翻譯

我不想使用glTranslatef。相反,我希望整個pModel移動(pModel結構改變)。我找到了函數glmScale。翻譯或旋轉有沒有類似的東西?

當我加載OBJ我不服這樣的:

pModelScaun=glmReadOBJ(filename); 
glmUnitize(pModelScaun); 
glmFacetNormals(pModelScaun); 
glmVertexNormals(pModelScaun,90.0); 

,然後我用三角形來判斷光源的位置和陰影frascum

for (unsigned int i = 0; i < pModelScaun->numtriangles; i++) 
{ 
    //compute the light vector (between the center of the current 
    //triangle and the position of the light (converted to object space) 
    for (unsigned int j = 0; j < 3; j++) 
    { 
     fvIncidentLightDir[j] = (pModelScaun->vertices[3*pModelScaun->triangles[i].vindices[0]+j] + 
           pModelScaun->vertices[3*pModelScaun->triangles[i].vindices[1]+j] + 
           pModelScaun->vertices[3*pModelScaun->triangles[i].vindices[2]+j])/3.0 - lp[j];    
    } 

你能指出我的方式在這種情況下我可以使用變換矩陣?

+0

那麼,如果你想翻譯,然後使用glTranlatef! 看起來你並不是很習慣openGL狀態,但是如果我得到了你錯誤的地方,你必須讓所有的模型在0,0,0,並且只需要在你繪製它們的時候轉換狀態,在此之後,回到帶負載標識或popmatrix的0,0,0 – 2011-12-24 15:06:51

+0

確實,我是openGl的新手。我有一個處理shadowVolumes的複雜算法,它使用pModel的inernal Structure。這就是爲什麼我想改變它。 – 2011-12-24 15:08:13

+0

好吧,發佈一些關於如何加載模型的代碼,以及如何繪製它們。這將有助於回答;) – 2011-12-24 15:19:28

回答

0

由於您使用的是對象空間中的頂點,並將光線轉換爲其對象空間,因此可以將fvIncidentLightDir乘以對象的變換矩陣以將其轉換回世界空間。