+++ /dev/null
-/*\r
-* Copyright (c) 2007-2009 SlimDX Group\r
-* \r
-* Permission is hereby granted, free of charge, to any person obtaining a copy\r
-* of this software and associated documentation files (the "Software"), to deal\r
-* in the Software without restriction, including without limitation the rights\r
-* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell\r
-* copies of the Software, and to permit persons to whom the Software is\r
-* furnished to do so, subject to the following conditions:\r
-* \r
-* The above copyright notice and this permission notice shall be included in\r
-* all copies or substantial portions of the Software.\r
-* \r
-* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
-* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\r
-* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\r
-* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\r
-* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\r
-* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN\r
-* THE SOFTWARE.\r
-*/\r
-using SharpDX;\r
-\r
-namespace SampleFramework\r
-{\r
- /// <summary>\r
- /// Represents a view onto a 3D scene.\r
- /// </summary>\r
- public class Camera\r
- {\r
- Vector3 location;\r
- Vector3 target;\r
- float fieldOfView;\r
- float aspectRatio;\r
- float nearPlane;\r
- float farPlane;\r
- Matrix viewMatrix;\r
- Matrix projectionMatrix;\r
- bool viewDirty = true;\r
- bool projectionDirty = true;\r
-\r
- /// <summary>\r
- /// Gets or sets the location of the camera eye point.\r
- /// </summary>\r
- /// <value>The location of the camera eye point.</value>\r
- public Vector3 Location\r
- {\r
- get { return location; }\r
- set\r
- {\r
- if (location == value)\r
- return;\r
-\r
- location = value;\r
- viewDirty = true;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets or sets the view target point.\r
- /// </summary>\r
- /// <value>The view target point.</value>\r
- public Vector3 Target\r
- {\r
- get { return target; }\r
- set\r
- {\r
- if (target == value)\r
- return;\r
-\r
- target = value;\r
- viewDirty = true;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets or sets the field of view.\r
- /// </summary>\r
- /// <value>The field of view.</value>\r
- public float FieldOfView\r
- {\r
- get { return fieldOfView; }\r
- set\r
- {\r
- if (fieldOfView == value)\r
- return;\r
-\r
- fieldOfView = value;\r
- projectionDirty = true;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets or sets the aspect ratio.\r
- /// </summary>\r
- /// <value>The aspect ratio.</value>\r
- public float AspectRatio\r
- {\r
- get { return aspectRatio; }\r
- set\r
- {\r
- if (aspectRatio == value)\r
- return;\r
-\r
- aspectRatio = value;\r
- projectionDirty = true;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets or sets the near plane.\r
- /// </summary>\r
- /// <value>The near plane.</value>\r
- public float NearPlane\r
- {\r
- get { return nearPlane; }\r
- set\r
- {\r
- if (nearPlane == value)\r
- return;\r
-\r
- nearPlane = value;\r
- projectionDirty = true;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets or sets the far plane.\r
- /// </summary>\r
- /// <value>The far plane.</value>\r
- public float FarPlane\r
- {\r
- get { return farPlane; }\r
- set\r
- {\r
- if (farPlane == value)\r
- return;\r
-\r
- farPlane = value;\r
- projectionDirty = true;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the view matrix.\r
- /// </summary>\r
- /// <value>The view matrix.</value>\r
- public Matrix ViewMatrix\r
- {\r
- get\r
- {\r
- if (viewDirty)\r
- RebuildViewMatrix();\r
- return viewMatrix;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Gets the projection matrix.\r
- /// </summary>\r
- /// <value>The projection matrix.</value>\r
- public Matrix ProjectionMatrix\r
- {\r
- get\r
- {\r
- if (projectionDirty)\r
- RebuildProjectionMatrix();\r
- return projectionMatrix;\r
- }\r
- }\r
-\r
- /// <summary>\r
- /// Initializes a new instance of the <see cref="Camera"/> class.\r
- /// </summary>\r
- public Camera()\r
- {\r
- }\r
-\r
- /// <summary>\r
- /// Rebuilds the view matrix.\r
- /// </summary>\r
- protected virtual void RebuildViewMatrix()\r
- {\r
- viewMatrix = Matrix.LookAtLH(Location, Target, Vector3.UnitY);\r
- viewDirty = false;\r
- }\r
-\r
- /// <summary>\r
- /// Rebuilds the projection matrix.\r
- /// </summary>\r
- protected virtual void RebuildProjectionMatrix()\r
- {\r
- projectionMatrix = Matrix.PerspectiveFovLH(FieldOfView, AspectRatio, NearPlane, FarPlane);\r
- projectionDirty = false;\r
- }\r
- }\r
-}\r