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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
/*
   Copyright (c) 2016 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.

 */

// This file is based on material originally from:
// Geometric Tools, LLC
// Copyright (c) 1998-2010
// Distributed under the Boost Software License, Version 1.0.
// http://www.boost.org/LICENSE_1_0.txt
// http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
// This code is HEAVILY inspired by Ogre3D and Torque3D
#ifndef _CORE_MATH_PLANE_H_
#define _CORE_MATH_PLANE_H_

#include "MathUtil.h"

namespace Divide {

/// This class defines a 3D plane defined as Ax + By + Cz + D = 0
/// This class is equivalent to a vector, the plane's normal,
/// whose x, y and z components equate to the coefficients A, B and C
/// respectively
/// and a constant (D) which is the distance along the normal you have to go to
/// move the plane back to the origin.
template <typename T>
class Plane {
   public:
    /** From Ogre3D: The "positive side" of the plane is the half space to which
       the
        plane normal points. The "negative side" is the other half
        space. The flag "no side" indicates the plane itself.
        */
    enum class Side : I32 {
        NO_SIDE,
        POSITIVE_SIDE,
        NEGATIVE_SIDE
    };

    Plane() : _distance(0), _active(false), _index(0) {}

    Plane(const Plane& rhs)
        : _normal(rhs._normal),
          _distance(rhs._distance),
          _active(rhs._active),
          _index(rhs._index) {}

    /// distance is stored as the negative of the specified value
    Plane(const vec3<T>& normal, T distance)
        : _normal(normal), _distance(distance), _active(false), _index(0) {}

    /// distance is stored as the negative of the specified value
    Plane(T a, T b, T c, T distance) : Plane(vec3<T>(a, b, c), distance) {}

    Plane(const vec4<T>& plane) : Plane(plane.xyz(), plane.w) {}

    Plane(const vec3<T>& normal, const vec3<T>& point)
        : _active(false), _index(0) {
        redefine(normal, point);
    }
    Plane(const vec3<T>& point0, const vec3<T>& point1, const vec3<T>& point2)
        : _active(false), _index(0) {
        redefine(point0, point1, point2);
    }

    Plane& operator=(const Plane& other) {
        _normal.set(other._normal);
        _distance = other._distance;
        _active = other._active;
        _index = other._index;

        return *this;
    }

    inline Side classifyPoint(const vec3<F32>& point) const {
        F32 result = signedDistanceToPoint(point);
        return (result > 0 ? Side::POSITIVE_SIDE
                           : (result < 0 ? Side::NEGATIVE_SIDE : Side::NO_SIDE));
    }

    inline T signedDistanceToPoint(const vec3<T>& point) const {
        return _normal.dot(point) + _distance;
    }
    inline T getDistance() const { return _distance; }

    inline void set(const vec3<T>& normal, T distance) {
        _normal = normal;
        _distance = distance;
    }
    inline void set(T a, T b, T c, T distance) {
        set(vec3<T>(a, b, c), distance);
    }

    inline void redefine(const vec3<T>& point0, const vec3<T>& point1,
                         const vec3<T>& point2) {
        vec3<T> edge1 = point1 - point0;
        vec3<T> edge2 = point2 - point0;
        _normal = edge1.cross(edge2);
        _normal.normalize();
        _distance = _normal.dot(point0);
    }

    inline void redefine(const vec3<T>& normal, const vec3<T>& point) {
        _normal = normal;
        _distance = _normal.dot(point);
    }
    inline vec4<T> getEquation() const { return vec4<T>(_normal, _distance); }
    inline const vec3<T>& getNormal() const { return _normal; }
    /// active plane state. used by rendering API's when the plane is considered
    /// a clipplane
    inline bool active() const { return _active; }
    inline void active(bool state) { _active = state; }
    /// store an internal id used as userData
    inline I32 getIndex() const { return _index; }
    inline void setIndex(I32 index) { _index = index; }
    /// Comparison operator
    bool operator==(const Plane& rhs) const {
        return COMPARE(rhs._distance, _distance) && rhs._normal == _normal;
    }

    bool operator!=(const Plane& rhs) const {
        return !COMPARE(rhs._distance, _distance) || rhs._normal != _normal;
    }

    T normalize() {
        T length = _normal.length();
        assert(length > 0.0f);
        T invLength = 1.0f / length;
        _normal *= invLength;
        _distance *= invLength;
        
        return length;
    }

   protected:
    vec3<T> _normal;
    T _distance;
    bool _active;
    I32 _index;
};

typedef vectorImpl<Plane<F32> > PlaneList;

};  // namespace Divide

#endif

Commits for Divide-Framework/trunk/Source Code/Core/Math/Headers/Plane.h

Diff revisions: vs.
Revision Author Commited Message
781 Diff Diff IonutCava picture IonutCava Wed 12 Oct, 2016 16:03:46 +0000

[IonutCava]
- ShaderComputeQueue <-> Material shader request bug fix (element stuck in QUEUED state)
- More Camera class cleanups
- Add a method of removing EnvironmentProbes from their Pool

750 Diff Diff IonutCava picture IonutCava Thu 07 Jul, 2016 16:02:03 +0000

[IonutCava]
- Static analysis based fixes and improvements

648 Diff Diff 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

366 Diff Diff IonutCava picture IonutCava Tue 10 Mar, 2015 16:56:30 +0000

[Ionut]
- More type safe enum replacement

352 Diff Diff IonutCava picture IonutCava Thu 12 Feb, 2015 17:10:21 +0000

[Ionut]
- Moved per-frame-per-animation bounding boxes back to SkinnedSubMesh class with better multithreading support
- Fixed a Util::Mat4::multiply related crash
- Added a basic framework (non-functional yet) for registering events with floating point data and a basic plotting system
- Removed custom M_PI define and changed code to use the one in math.h
- Added Scoped classes for rendering (they revert state back to what it was upon destruction)
— Scoped classes for 2D rendering, toggling the rasterizer on/off, changing viewport and changing line width

350 Diff Diff IonutCava picture IonutCava Tue 10 Feb, 2015 16:25:39 +0000

[Ionut]
- Simplified some Util-namespace level functions by using STL algorithms where possible
- Formatted the entire codebase using clang-format with the following style: "{BasedOnStyle: Google, IndentWidth: 4}"
- Attempted to make ProfileTimer thread-safe (temp fix until std::chrono works properly in Visual Studio)

343 Diff Diff IonutCava picture IonutCava Thu 15 Jan, 2015 17:30:12 +0000

[Ionut]
- Refactored 2 singletons into static classes (Console and TerrainLoader)
- Changed some C-casts to static_casts
- Updated copyright notices

338 Diff Diff IonutCava picture IonutCava Thu 08 Jan, 2015 14:17:33 +0000

[Ionut]
- Added Metric, Time and Angle namespaces and moved all related functions to the appropriate one.
- Reworked most dynamic_cast calls to static_cast (with static_assert where possible)
- Moved ProfileTimer and ApplicationTimer to Time namespace
- More .h/.cpp/.inl splitting in core files (mostly Math files)

331 Diff Diff IonutCava picture IonutCava Sat 06 Dec, 2014 20:53:45 +0000

[Ionut]
- Limited line length to 132 characters to improve readability and diff-comparisons
- Refactored memory allocation/deallocation functions
- Fixed a few compatibility issues with HashMap.h
- Fixed a bug in GPU Skinning shaders (cast a float to int)

318 IonutCava picture IonutCava Sat 30 Aug, 2014 17:35:53 +0000

[Ionut]
- Wrapped the entire code in a “Divide” namespace
- VertexBuffers now call “shrink_to_fit” on all internal data storage
- Improved some vector performance by preferring “emplace_back” instead of “push_back” + proepr usage of reserve / resize
- Wrapped OIS specific types and classes in Divide::Input namespace
- Added the messageBox.layout file (forgot it in the previous few commits)