1、繼續(xù)上一個工程硬耍,修改頂點參數(shù)裁僧,將三角形改成正方形
//blockSize 1/2邊長
GLfloatblockSize =0.2f;
//指定正方形的頂點數(shù)據(jù) x,y,z
GLfloatvVerts[] = {
??? -blockSize,-blockSize,0.0f,
???blockSize,-blockSize,0.0f,
???blockSize,blockSize,0.0f,
??? -blockSize,blockSize,0.0f
};
voidsetupRC()
{
???//1.設(shè)置清屏顏色
???glClearColor(0.33f,0.45f,0.12f,1.0f);
???//初始化固定管線
???shaderManager.InitializeStockShaders();
???triangleBatch.Begin(GL_TRIANGLE_FAN,4);
???triangleBatch.CopyVertexData3f(vVerts);
???triangleBatch.End();
}
2、使用旋轉(zhuǎn)矩加平移矩陣想結(jié)合起宽,用平面著色器完成繪制
//利用矩陣幫助移動
???//mFinalTransform 結(jié)果矩陣
???//mTransformMatrix 平移矩陣
???//mRotationMatrix? 旋轉(zhuǎn)矩陣
???M3DMatrix44fmFinalTransform,mTransformMatrix,mRotationMatrix;
???//平移 x,y,z,w(縮放因子= 1)
???//3D中平移的原理與矩陣之間關(guān)系
???/*
???? 參數(shù)1:矩陣
???? 參數(shù)2职车、3瘫俊、4:X,Y,Z上平移距離
???? */
???m3dTranslationMatrix44(mTransformMatrix,xPos,yPos,0.0f);
???//增加難度! 一邊移動,一邊旋轉(zhuǎn)
???staticfloatyRot =0.0f;
???/*
???? 參數(shù)1:矩陣
???? 參數(shù)2:弧度
???? 參數(shù)3:X:1悴灵,0 1:圍繞X軸旋轉(zhuǎn)扛芽,0不圍繞X軸旋轉(zhuǎn)
???? 參數(shù)4:Y:1,0
???? 參數(shù)5:Z:1积瞒,0
???? */
???m3dRotationMatrix44(mRotationMatrix,m3dDegToRad(yRot),0.0f,0.0f,1.0f);
???//修改旋轉(zhuǎn)度數(shù)
??? yRot +=5.0f;
???//思考:結(jié)合2個矩陣的結(jié)果 平移矩陣 * 旋轉(zhuǎn)矩陣 = 最終結(jié)果矩陣
???m3dMatrixMultiply44(mFinalTransform, mTransformMatrix, mRotationMatrix);
3胸哥、運行,實現(xiàn)效果
總結(jié):主要使用了兩個矩陣相結(jié)合赡鲜,合成一個矩陣完成移動+旋轉(zhuǎn)