Android +camara

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/lyp13243189027/article/details/70258542
http://blog.csdn.net/gf771115/article/details/19438409
阅读更多
换一批

关于这个camara类的疑惑

05-13

下面是一个摄像机类:rnrn[code=C/C++]rnclass Camerarnrnpublic:rn enum CameraType LANDOBJECT, AIRCRAFT ;rnrn Camera();rn Camera(CameraType cameraType);rn ~Camera();rnrn void strafe(float units); // left/rightrn void fly(float units); // up/downrn void walk(float units); // forward/backwardrn rn void pitch(float angle); // rotate on right vectorrn void yaw(float angle); // rotate on up vectorrn void roll(float angle); // rotate on look vectorrnrn void getViewMatrix(D3DXMATRIX* V); rn void setCameraType(CameraType cameraType); rn void getPosition(D3DXVECTOR3* pos); rn void setPosition(D3DXVECTOR3* pos); rnrn void getRight(D3DXVECTOR3* right);rn void getUp(D3DXVECTOR3* up);rn void getLook(D3DXVECTOR3* look);rnprivate:rn CameraType _cameraType;rn D3DXVECTOR3 _right;rn D3DXVECTOR3 _up;rn D3DXVECTOR3 _look;rn D3DXVECTOR3 _pos;rn;rnrnrn#include "camera.h"rnrnCamera::Camera()rnrn _cameraType = AIRCRAFT;rnrn _pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);rn _right = D3DXVECTOR3(1.0f, 0.0f, 0.0f);rn _up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);rn _look = D3DXVECTOR3(0.0f, 0.0f, 1.0f);rnrnrnCamera::Camera(CameraType cameraType)rnrn _cameraType = cameraType;rnrn _pos = D3DXVECTOR3(0.0f, 0.0f, 0.0f);rn _right = D3DXVECTOR3(1.0f, 0.0f, 0.0f);rn _up = D3DXVECTOR3(0.0f, 1.0f, 0.0f);rn _look = D3DXVECTOR3(0.0f, 0.0f, 1.0f);rnrnrnCamera::~Camera()rnrnrnrnrnvoid Camera::getPosition(D3DXVECTOR3* pos)rnrn *pos = _pos;rnrnrnvoid Camera::setPosition(D3DXVECTOR3* pos)rnrn _pos = *pos;rnrnrnvoid Camera::getRight(D3DXVECTOR3* right)rnrn *right = _right;rnrnrnvoid Camera::getUp(D3DXVECTOR3* up)rnrn *up = _up;rnrnrnvoid Camera::getLook(D3DXVECTOR3* look)rnrn *look = _look;rnrnrnvoid Camera::walk(float units)rnrn // move only on xz plane for land objectrn if( _cameraType == LANDOBJECT )rn _pos += D3DXVECTOR3(_look.x, 0.0f, _look.z) * units;rnrn if( _cameraType == AIRCRAFT )rn _pos += _look * units;rnrnrnvoid Camera::strafe(float units)rnrn // move only on xz plane for land objectrn if( _cameraType == LANDOBJECT )rn _pos += D3DXVECTOR3(_right.x, 0.0f, _right.z) * units;rnrn if( _cameraType == AIRCRAFT )rn _pos += _right * units;rnrnrnvoid Camera::fly(float units)rnrn if( _cameraType == AIRCRAFT )rn _pos += _up * units;rnrnrnvoid Camera::pitch(float angle)rnrn D3DXMATRIX T;rn D3DXMatrixRotationAxis(&T, &_right, angle);rnrn // rotate _up and _look around _right vectorrn D3DXVec3TransformCoord(&_up,&_up, &T);rn D3DXVec3TransformCoord(&_look,&_look, &T);rnrnrnvoid Camera::yaw(float angle)rnrn D3DXMATRIX T;rnrn // rotate around world y (0, 1, 0) always for land objectrn if( _cameraType == LANDOBJECT )rn D3DXMatrixRotationY(&T, angle);rnrn // rotate around own up vector for aircraftrn if( _cameraType == AIRCRAFT )rn D3DXMatrixRotationAxis(&T, &_up, angle);rnrn // rotate _right and _look around _up or y-axisrn D3DXVec3TransformCoord(&_right,&_right, &T);rn D3DXVec3TransformCoord(&_look,&_look, &T);rnrnrnvoid Camera::roll(float angle)rnrn // only roll for aircraft typern if( _cameraType == AIRCRAFT )rn rn D3DXMATRIX T;rn D3DXMatrixRotationAxis(&T, &_look, angle);rnrn // rotate _up and _right around _look vectorrn D3DXVec3TransformCoord(&_right,&_right, &T);rn D3DXVec3TransformCoord(&_up,&_up, &T);rn rnrnrnvoid Camera::getViewMatrix(D3DXMATRIX* V)rnrn // Keep camera's axes orthogonal to eachotherrn D3DXVec3Normalize(&_look, &_look);rnrn D3DXVec3Cross(&_up, &_look, &_right);rn D3DXVec3Normalize(&_up, &_up);rnrn D3DXVec3Cross(&_right, &_up, &_look);rn D3DXVec3Normalize(&_right, &_right);rnrn // Build the view matrix:rn float x = -D3DXVec3Dot(&_right, &_pos);rn float y = -D3DXVec3Dot(&_up, &_pos);rn float z = -D3DXVec3Dot(&_look, &_pos);rnrn (*V)(0,0) = _right.x; (*V)(0, 1) = _up.x; (*V)(0, 2) = _look.x; (*V)(0, 3) = 0.0f;rn (*V)(1,0) = _right.y; (*V)(1, 1) = _up.y; (*V)(1, 2) = _look.y; (*V)(1, 3) = 0.0f;rn (*V)(2,0) = _right.z; (*V)(2, 1) = _up.z; (*V)(2, 2) = _look.z; (*V)(2, 3) = 0.0f;rn (*V)(3,0) = x; (*V)(3, 1) = y; (*V)(3, 2) = z; (*V)(3, 3) = 1.0f;rnrnrnvoid Camera::setCameraType(CameraType cameraType)rnrn _cameraType = cameraType;rnrnrnrnrn[/code]rnrnrn对于这样一个函数....rn对于这样一个函数....rn对于这样一个函数....rnvoid Camera::getViewMatrix(D3DXMATRIX* V)rnrn // Keep camera's axes orthogonal to eachotherrn D3DXVec3Normalize(&_look, &_look);rnrn D3DXVec3Cross(&_up, &_look, &_right);rn D3DXVec3Normalize(&_up, &_up);rnrn D3DXVec3Cross(&_right, &_up, &_look);rn D3DXVec3Normalize(&_right, &_right);rnrn // Build the view matrix:rn float x = -D3DXVec3Dot(&_right, &_pos);rn float y = -D3DXVec3Dot(&_up, &_pos);rn float z = -D3DXVec3Dot(&_look, &_pos);rnrn (*V)(0,0) = _right.x; (*V)(0, 1) = _up.x; (*V)(0, 2) = _look.x; (*V)(0, 3) = 0.0f;rn (*V)(1,0) = _right.y; (*V)(1, 1) = _up.y; (*V)(1, 2) = _look.y; (*V)(1, 3) = 0.0f;rn (*V)(2,0) = _right.z; (*V)(2, 1) = _up.z; (*V)(2, 2) = _look.z; (*V)(2, 3) = 0.0f;rn (*V)(3,0) = x; (*V)(3, 1) = y; (*V)(3, 2) = z; (*V)(3, 3) = 1.0f;rnrn他跟 D3DXMatrixLookAtLH(&matrixView, &position, &lookat, &up)rnrn有什么区别???rn为什么getViewMatrix得到的Matrix 可以直接这么用rnrnD3DXMATRIX V;rnTheCamera.getViewMatrix(&V);rnDevice->SetTransform(D3DTS_VIEW, &V);rnrnSetTransform中参数V到底是需要什么样一个矩阵啊..rn

没有更多推荐了,返回首页