- 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ù)庫基礎(chǔ)教程(SQL Server平臺)
- Word 2010中文版完全自學(xué)手冊
- 數(shù)據(jù)化網(wǎng)站運營深度剖析
- 大話Oracle Grid:云時代的RAC
- 跟老男孩學(xué)Linux運維:MySQL入門與提高實踐
- 數(shù)據(jù)挖掘原理與SPSS Clementine應(yīng)用寶典
- 白話大數(shù)據(jù)與機器學(xué)習(xí)
- 大數(shù)據(jù)架構(gòu)商業(yè)之路:從業(yè)務(wù)需求到技術(shù)方案
- Apache Kylin權(quán)威指南
- MySQL技術(shù)內(nèi)幕:SQL編程
- 企業(yè)主數(shù)據(jù)管理實務(wù)
- 改變未來的九大算法
- Visual FoxPro數(shù)據(jù)庫技術(shù)基礎(chǔ)
- SIEMENS數(shù)控技術(shù)應(yīng)用工程師:SINUMERIK 840D-810D數(shù)控系統(tǒng)功能應(yīng)用與維修調(diào)整教程
- 利用Python進行數(shù)據(jù)分析(原書第2版)