Android OpenGL_ES2.0 LookAt 我的眼睛在哪里?

public static void setLookAtM(float[] rm, int rmOffset,
float eyeX, float eyeY, float eyeZ,
float centerX, float centerY, float centerZ, float upX, float upY,
float upZ) {}
// Position the eye behind the origin.
final float eyeX = 0.0f;
final float eyeY = 0.0f;
final float eyeZ = 1.5f;

// We are looking toward the distance
final float lookX = 0.0f;
final float lookY = 0.0f;
final float lookZ = -5.0f;

// Set our up vector. This is where our head would be pointing were we holding the camera.
final float upX = 0.0f;
final float upY = 1.0f;
final float upZ = 0.0f;

// Set the view matrix. This matrix can be said to represent the camera position.
// NOTE: In OpenGL 1, a ModelView matrix is used, which is a combination of a model and
// view matrix. In OpenGL 2, we can keep track of these matrices separately if we choose.
Matrix.setLookAtM(mViewMatrix, 0, eyeX, eyeY, eyeZ, lookX, lookY, lookZ, upX, upY, upZ);


float[] mViewMatrix = new float[16];
Matrix.setLookAtM将计算结果保存到以上数组,将和Frustum视野一起使用

eyeX eyeY eyeZ表示眼睛或摄像机所在的空间位置

lookX lookY lookZ 表示焦点位置,表示眼睛要看哪里

upX upY upZ表示眼睛的方向

可以想象一个人站立在哪里,右手方向为x,头顶方向为y,后背方向为z.....upX,upY,upZ表示脑袋的方向(只表示方向,无关具体值)
1.如果一个人站立:那么upX=0,upY=1,upZ=0;(此时视野方向其实是正前方)
2.如果直接向后躺下:那么upX=0,upY=0,upZ=1;(此时脑袋在z方向上,此时视野方向在正上方)
3.如果朝着右手边平躺:那么upX=1,upY=0,upZ=0;(此时闹到在x方向上,视野方向仍然是正上方,只是和第2中情况看到的物体的角度不同而已)


眼睛位置+视野方向+视野范围=渲染出的效果


配上《Android 3D游戏开发技术宝典》一书中的示例图:








  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值