2 * Copyright (c) 2007-2009 SlimDX Group
\r
4 * Permission is hereby granted, free of charge, to any person obtaining a copy
\r
5 * of this software and associated documentation files (the "Software"), to deal
\r
6 * in the Software without restriction, including without limitation the rights
\r
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
\r
8 * copies of the Software, and to permit persons to whom the Software is
\r
9 * furnished to do so, subject to the following conditions:
\r
11 * The above copyright notice and this permission notice shall be included in
\r
12 * all copies or substantial portions of the Software.
\r
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
\r
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
\r
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
\r
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
\r
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
\r
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
\r
24 namespace SampleFramework
\r
27 /// Represents a view onto a 3D scene.
\r
38 Matrix projectionMatrix;
\r
39 bool viewDirty = true;
\r
40 bool projectionDirty = true;
\r
43 /// Gets or sets the location of the camera eye point.
\r
45 /// <value>The location of the camera eye point.</value>
\r
46 public Vector3 Location
\r
48 get { return location; }
\r
51 if (location == value)
\r
60 /// Gets or sets the view target point.
\r
62 /// <value>The view target point.</value>
\r
63 public Vector3 Target
\r
65 get { return target; }
\r
68 if (target == value)
\r
77 /// Gets or sets the field of view.
\r
79 /// <value>The field of view.</value>
\r
80 public float FieldOfView
\r
82 get { return fieldOfView; }
\r
85 if (fieldOfView == value)
\r
88 fieldOfView = value;
\r
89 projectionDirty = true;
\r
94 /// Gets or sets the aspect ratio.
\r
96 /// <value>The aspect ratio.</value>
\r
97 public float AspectRatio
\r
99 get { return aspectRatio; }
\r
102 if (aspectRatio == value)
\r
105 aspectRatio = value;
\r
106 projectionDirty = true;
\r
111 /// Gets or sets the near plane.
\r
113 /// <value>The near plane.</value>
\r
114 public float NearPlane
\r
116 get { return nearPlane; }
\r
119 if (nearPlane == value)
\r
123 projectionDirty = true;
\r
128 /// Gets or sets the far plane.
\r
130 /// <value>The far plane.</value>
\r
131 public float FarPlane
\r
133 get { return farPlane; }
\r
136 if (farPlane == value)
\r
140 projectionDirty = true;
\r
145 /// Gets the view matrix.
\r
147 /// <value>The view matrix.</value>
\r
148 public Matrix ViewMatrix
\r
153 RebuildViewMatrix();
\r
159 /// Gets the projection matrix.
\r
161 /// <value>The projection matrix.</value>
\r
162 public Matrix ProjectionMatrix
\r
166 if (projectionDirty)
\r
167 RebuildProjectionMatrix();
\r
168 return projectionMatrix;
\r
173 /// Initializes a new instance of the <see cref="Camera"/> class.
\r
180 /// Rebuilds the view matrix.
\r
182 protected virtual void RebuildViewMatrix()
\r
184 viewMatrix = Matrix.LookAtLH(Location, Target, Vector3.UnitY);
\r
189 /// Rebuilds the projection matrix.
\r
191 protected virtual void RebuildProjectionMatrix()
\r
193 projectionMatrix = Matrix.PerspectiveFovLH(FieldOfView, AspectRatio, NearPlane, FarPlane);
\r
194 projectionDirty = false;
\r