1 | // tCamera.h  |
2 | //  |
3 | // The camera tScene object. The primary members are a 4x4 homogeneous projection matrix and a type member that  |
4 | // indicates the type of projection matrix being stored. We could add depth-of-field members at a later time.  |
5 | //  |
6 | // Copyright (c) 2006, 2017 Tristan Grimmer.  |
7 | // Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby  |
8 | // granted, provided that the above copyright notice and this permission notice appear in all copies.  |
9 | //  |
10 | // THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL  |
11 | // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,  |
12 | // INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN  |
13 | // AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR  |
14 | // PERFORMANCE OF THIS SOFTWARE.  |
15 |   |
16 | #pragma once  |
17 | #include <Foundation/tAssert.h>  |
18 | #include "Scene/tObject.h"  |
19 | namespace tScene  |
20 | {  |
21 |   |
22 |   |
23 | class tCamera : public tObject  |
24 | {  |
25 | public:  |
26 | tCamera() { }  |
27 | tCamera(const tChunk& chunk) { Load(chunk); }  |
28 | virtual ~tCamera() { }  |
29 |   |
30 | void Save(tChunkWriter&) const override;  |
31 | void Load(const tChunk&) override;  |
32 | void Clear() { ProjectionMode = tProjectionMode::Invalid; Projection = tMath::tMatrix4::identity; }  |
33 |   |
34 | // If the entire world is scales, this function properly scales any tCameras. Essentially this amounts to adjusting  |
35 | // the near and far planes if the projection is perspective.  |
36 | void Scale(float scale);  |
37 |   |
38 | enum class tProjectionMode  |
39 | {  |
40 | Invalid = -1,  |
41 | Perspective, // A symmetric perspective projection. The most common.  |
42 | PerspectiveOblique, // An asymmetric perspective projection.  |
43 | Parallel // A parallel projection.  |
44 | };  |
45 |   |
46 | // Valid accessors for all types of projection.  |
47 | void (tMath::tVector4 planes[6], bool outwardNormals = false, bool normalizePlanes = true) { Projection.ExtractProjectionPlanes(planes, outwardNormals, normalizePlanes); }  |
48 |   |
49 | // Valid accessors for Perspective and PerspectiveOblique projections. You must ensure the correct projection mode.  |
50 | float GetNearPlane() const { tAssert(ProjectionMode != tProjectionMode::Parallel); return Projection.ExtractProjectionNear(); }  |
51 | float GetFarPlane() const { tAssert(ProjectionMode != tProjectionMode::Parallel); return Projection.ExtractProjectionFar(); }  |
52 | float GetAspect() const { tAssert(ProjectionMode != tProjectionMode::Parallel); return Projection.ExtractProjectionAspect(); }  |
53 | float GetFovV() const { tAssert(ProjectionMode != tProjectionMode::Parallel); return Projection.ExtractPerspectiveFovV(); }  |
54 | float GetFovH() const { tAssert(ProjectionMode != tProjectionMode::Parallel); return Projection.ExtractPerspectiveFovH(); }  |
55 | float () const /* Returns 0.0 for symmetric. */ { tAssert(ProjectionMode != tProjectionMode::Parallel); return Projection.ExtractProjectionOffsetX(); }  |
56 | float () const /* Returns 0.0 for symmetric. */ { tAssert(ProjectionMode != tProjectionMode::Parallel); return Projection.ExtractProjectionOffsetY(); }  |
57 |   |
58 | tProjectionMode ProjectionMode = tProjectionMode::Invalid;  |
59 | tMath::tMatrix4 Projection = tMath::tMatrix4::identity;  |
60 | };  |
61 |   |
62 |   |
63 | }  |
64 | |