//设置透视投影
Matrix.frustumM(mProjectMatrix, 0, -ratio, ratio, -1, 1, 3, 7);
//设置相机位置
Matrix.setLookAtM(mViewMatrix, 0, 0, 0, 5f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
说明:相机位置 参照世界坐标系 eyeZ 平截面 以相机位置为原点
//物体默认为 x,y,z 世界坐标系右手规则
(0.0,5)
如下正方体
final float cubePositions[] = {
-1.0f,1.0f,1.0f, //正面左上0
-1.0f,-1.0f,1.0f, //正面左下1
1.0f,-1.0f,1.0f, //正面右下2
1.0f,1.0f,1.0f, //正面右上3
-1.0f,1.0f,-1.0f, //反面左上4
-1.0f,-1.0f,-1.0f, //反面左下5
1.0f,-1.0f,-1.0f, //反面右下6
1.0f,1.0f,-1.0f, //反面右上7
};
final short index[]={
6,7,4,6,4,5, //后面
6,3,7,6,2,3, //右面
6,5,1,6,1,2, //下面
0,3,2,0,2,1, //正面
0,1,5,0,5,4, //左面
0,7,3,0,4,7, //上面
};
float color[] = {
0f,1f,0f,1f,
0f,1f,0f,1f,
0f,1f,0f,1f,
0f,1f,0f,1f,
1f,0f,0f,1f,
1f,0f,0f,1f,
1f,0f,0f,1f,
1f,0f,0f,1f,
};
Matrix.frustumM(mProjectMatrix, 0, -ratio, ratio, -1, 1, 3, 20);
//设置相机位置 正面 x 右偏 0.1 y上方 2.0
Matrix.setLookAtM(mViewMatrix, 0, 0.1f, 2.0f, 10.0f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
//设置相机位置 正面 x 右偏 0.1 y上方 6.0
Matrix.setLookAtM(mViewMatrix, 0, 0.1f, 6.0f, 10.0f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
从背面看
Matrix.setLookAtM(mViewMatrix, 0, 0.5f, 6.0f, -10.0f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);
Matrix.setLookAtM(mViewMatrix, 0, -0.5f, 6.0f, -10.0f, 0f, 0f, 0f, 0f, 1.0f, 0.0f);