- XNA 4 3D Game Development by Example:Beginner's Guide
- Kurt Jaegers
- 257字
- 2021-08-05 18:55:29
Time for action – the View matrix
- Add the following variable to the
Fields
region of theCamera
class:private Matrix cachedViewMatrix;
- Add the following property to the
Properties
region of theCamera
class:public Matrix View { get { if (needViewResync) cachedViewMatrix = Matrix.CreateLookAt( Position, lookAt, Vector3.Up); return cachedViewMatrix; } }
What just happened?
We could simply recalculate the View
matrix every time the Camera
class was asked for it, but doing so would incur a small performance penalty. Because we do not have a lot of action happening in Cube Chaser, this penalty would not impact our game, but we can avoid it altogether. We are building a caching mechanism into the camera code in the event our game develops to the point that this optimization is helpful. Any time the View
matrix is calculated, we will store it in cachedViewMatrix
and simply return that matrix if the View
matrix is requested without the underlying camera information having been modified.
In order to create the View
matrix, we use the convenient Matrix.CreateLookAt()
method, which accepts the camera position, the look at point we calculated previously, and a vector indicating what direction is considered to be up for the camera. In our case, we are using the pre-defined Vector3.Up
, which translates to (0, 1, 0), or up along the positive Y axis.
That is enough of the camera to get us started. We will return to the Camera
class later when we implement movement. For now, let's get on with actually drawing something to the screen!
- 大數(shù)據(jù):規(guī)劃、實施、運維
- 算法與數(shù)據(jù)中臺:基于Google、Facebook與微博實踐
- 數(shù)據(jù)驅(qū)動設(shè)計:A/B測試提升用戶體驗
- 數(shù)據(jù)庫原理與應用(Oracle版)
- Scratch 3.0 藝術(shù)進階
- Python金融數(shù)據(jù)分析(原書第2版)
- 深入淺出 Hyperscan:高性能正則表達式算法原理與設(shè)計
- Proxmox VE超融合集群實踐真?zhèn)?/a>
- SQL應用及誤區(qū)分析
- Solaris操作系統(tǒng)原理實驗教程
- Mastering ROS for Robotics Programming(Second Edition)
- 中國云存儲發(fā)展報告
- 一本書讀懂大數(shù)據(jù)
- Artificial Intelligence for Big Data
- Tableau商業(yè)分析從新手到高手(視頻版)