Subversion Repository Public Repository

Divide-Framework

This repository has no backups
This repository's network speed is throttled to 100KB/sec

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/*
   Copyright (c) 2017 DIVIDE-Studio
   Copyright (c) 2009 Ionut Cava

   This file is part of DIVIDE Framework.

   Permission is hereby granted, free of charge, to any person obtaining a copy
   of this software
   and associated documentation files (the "Software"), to deal in the Software
   without restriction,
   including without limitation the rights to use, copy, modify, merge, publish,
   distribute, sublicense,
   and/or sell copies of the Software, and to permit persons to whom the
   Software is furnished to do so,
   subject to the following conditions:

   The above copyright notice and this permission notice shall be included in
   all copies or substantial portions of the Software.

   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
   IMPLIED,
   INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
   PARTICULAR PURPOSE AND NONINFRINGEMENT.
   IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
   DAMAGES OR OTHER LIABILITY,
   WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR
   IN CONNECTION WITH THE SOFTWARE
   OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 */

#ifndef _FRUSTUM_H_
#define _FRUSTUM_H_

#include "Core/Math/Headers/MathMatrices.h"
#include "Core/Math/Headers/Plane.h"

namespace Divide {

class Camera;
class BoundingBox;
class Frustum {
   protected:
    friend class Camera;
    Frustum(Camera& parentCamera);
    void Extract(const mat4<F32>& viewMatrix, const mat4<F32>& projectionMatrix);

   public:
    enum class FrustCollision : U32 {
        FRUSTUM_OUT = 0,
        FRUSTUM_IN = 1,
        FRUSTUM_INTERSECT = 2
    };

    enum class FrustPlane : U32 {
        PLANE_LEFT = 0,
        PLANE_RIGHT,
        PLANE_NEAR,
        PLANE_FAR,
        PLANE_TOP,
        PLANE_BOTTOM,
        COUNT
    };

    enum class FrustPoints : U32 {
        NEAR_LEFT_TOP = 0,
        NEAR_RIGHT_TOP,
        NEAR_RIGHT_BOTTOM,
        NEAR_LEFT_BOTTOM,
        FAR_LEFT_TOP,
        FAR_RIGHT_TOP,
        FAR_RIGHT_BOTTOM,
        FAR_LEFT_BOTTOM,
        COUNT
    };

   public:
    FrustCollision ContainsPoint(const vec3<F32>& point, I8& lastPlaneCache) const;
    FrustCollision ContainsBoundingBox(const BoundingBox& bbox, I8& lastPlaneCache) const;
    FrustCollision ContainsSphere(const vec3<F32>& center, F32 radius, I8& lastPlaneCache) const;

    inline FrustCollision ContainsPoint(const vec3<F32>& point) const {
        I8 lastPlaneCache = -1;
        return ContainsPoint(point, lastPlaneCache);
    }
    inline FrustCollision ContainsBoundingBox(const BoundingBox& bbox) const {
        I8 lastPlaneCache = -1;
        return ContainsBoundingBox(bbox, lastPlaneCache);
    }
    inline FrustCollision ContainsSphere(const vec3<F32>& center, F32 radius) const {
        I8 lastPlaneCache = -1;
        return ContainsSphere(center, radius, lastPlaneCache);
    }

    // Get the frustum corners in WorldSpace. cornerWS must be a vector with at
    // least 8 allocated slots
    void getCornersWorldSpace(vectorImpl<vec3<F32> >& cornersWS);
    // Get the frustum corners in ViewSpace. cornerVS must be a vector with at
    // least 8 allocated slots
    void getCornersViewSpace(vectorImpl<vec3<F32> >& cornersVS);

    void computePlanes(const mat4<F32>& viewProjMatrix);

    static void computePlanes(const mat4<F32>& viewProjMatrix, vec4<F32>* planesOut);
    static void computePlanes(const mat4<F32>& viewProjMatrix, Plane<F32>* planesOut);

   private:
     FrustCollision PlaneBoundingBoxIntersect(const Plane<F32>& frustumPlane,
                                              const BoundingBox& bbox) const;
     FrustCollision PlanePointIntersect(const Plane<F32>& frustumPlane, 
                                        const vec3<F32>& point) const;
     FrustCollision PlaneSphereIntersect(const Plane<F32>& frustumPlane,
                                         const vec3<F32>& center,
                                         F32 radius) const;

    /// Get the point where the 3 specified planes intersect
    void intersectionPoint(const Plane<F32>& a, const Plane<F32>& b,
                           const Plane<F32>& c, vec3<F32>& outResult);
    void updatePoints();

   private:
    Camera& _parentCamera;
    bool _pointsDirty;

    std::array<Plane<F32>, to_base(FrustPlane::COUNT)>  _frustumPlanes;
    std::array<vec3<F32>,  to_base(FrustPoints::COUNT)> _frustumPoints;
};

};  // namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Rendering/Camera/Headers/Frustum.h

Diff revisions: vs.
Revision Author Commited Message
1021 Diff Diff IonutCava picture IonutCava Sun 21 Jan, 2018 22:19:16 +0000

[Ionut]
- Performance optimizations

990 Diff Diff IonutCava picture IonutCava Tue 05 Dec, 2017 17:20:10 +0000

[Ionut]
- Some SceneGraph and SceneGraphNode cleanup

874 Diff Diff IonutCava picture IonutCava Mon 13 Mar, 2017 17:29:45 +0000

[IonutCava]
- Fix boundingbox skewing bug.
- Optimise frustum collision checks by adding a plane-cache system.
— ToDo: solve mutable status of _frustPlaneCache
— ToDo: TRIPLE check results to avoid false-positives
- Speedup terrain by not stack-allocating QuadtreeNodes in a QuadtreeChildren container instead of new-ing each one of them.

872 Diff Diff IonutCava picture IonutCava Mon 06 Mar, 2017 23:23:20 +0000

[IonutCava]
- Optimise static casts

867 Diff Diff IonutCava picture IonutCava Mon 20 Feb, 2017 17:01:12 +0000

[IonutCava]
- Rename to_XNN and to_const_XNN functions to reflect the target data type they are converting to.
- Cleanup Angle namespace and remove all “inDegrees” parameters from rotation functions. Use aliases to differentiate between Degree and Radian parameters.
- Profile guided optimizations.

836 Diff Diff IonutCava picture IonutCava Fri 27 Jan, 2017 14:59:56 +0000

[IonutCava]
- Update copyright notice

788 Diff Diff IonutCava picture IonutCava Fri 21 Oct, 2016 16:11:37 +0000

[IonutCava]
- Added support for the Arena Allocator by Mamasha Knows (http://www.codeproject.com/Articles/44850/Arena-Allocator-DTOR-and-Embedded-Preallocated-Buf)
— Used for GFX Related objects: Textures, shaders, etc

783 Diff Diff IonutCava picture IonutCava Fri 14 Oct, 2016 15:50:34 +0000

[IonutCava]
- More cleanup of the Frustum class
- Change random number generation system to use the C++11 <random> features. (default engine set to Mersenne Twister and using a uniform distribution as default)

779 Diff Diff IonutCava picture IonutCava Mon 10 Oct, 2016 15:31:45 +0000

[IonutCava]
- Frustum calculation bug fix

648 IonutCava picture IonutCava Sun 21 Feb, 2016 16:32:52 +0000

[IonutCava]
- Update copyright notice
- Move BoundingBox and BoundingSphere to a new BoundsComponent
— Add a temp hack in SceneGraphNode to update these