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
/*
   Copyright (c) 2018 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 _CORE_MATH_BOUNDINGVOLUMES_BOUNDINGSPHERE_INL_
#define _CORE_MATH_BOUNDINGVOLUMES_BOUNDINGSPHERE_INL_

namespace Divide {

inline void BoundingSphere::fromBoundingBox(const BoundingBox& bBox) {
    _center.set(bBox.getCenter());
    _radius = (bBox.getMax() - _center).length();
}

inline void BoundingSphere::fromBoundingSphere(const BoundingSphere& bSphere) {
    _center.set(bSphere.getCenter());
    _radius = bSphere.getRadius();
}

// https://code.google.com/p/qe3e/source/browse/trunk/src/BoundingSphere.h?r=28
inline void BoundingSphere::add(const BoundingSphere& bSphere) {
    const F32 dist = (bSphere._center - _center).length();

    if (_radius >= dist + bSphere._radius) {
        return;
    }

    if (bSphere._radius >= dist + _radius) {
        _center = bSphere._center;
        _radius = bSphere._radius;
    }

    if (dist > EPSILON_F32) {
        const F32 nRadius = (_radius + dist + bSphere._radius) * 0.5f;
        const F32 ratio = (nRadius - _radius) / dist;
        _center += (bSphere._center - _center) * ratio;

        _radius = nRadius;
    }
}

inline void BoundingSphere::addRadius(const BoundingSphere& bSphere) {
    const F32 dist = (bSphere._center - _center).length() + bSphere._radius;
    if (_radius < dist) {
        _radius = dist;
    }
}

inline void BoundingSphere::add(const vec3<F32>& point) {
    const vec3<F32> diff(point - _center);
    const F32 dist = diff.length();
    if (_radius < dist) {
        const F32 nRadius = (dist - _radius) * 0.5f;
        _center += diff * (nRadius / dist);
        _radius += nRadius;
    }
}

inline void BoundingSphere::addRadius(const vec3<F32>& point) {
    const F32 dist = (point - _center).length();
    if (_radius < dist) {
        _radius = dist;
    }
}

inline void BoundingSphere::createFromPoints(const vectorImpl<vec3<F32>>& points) {
    _radius = 0;
    const F32 numPoints = to_F32(points.size());

    for (const vec3<F32>& p : points) {
        _center += p / numPoints;
    }

    for (const vec3<F32>& p : points) {
        const F32 distance = (p - _center).length();

        if (distance > _radius) {
            _radius = distance;
        }
    }
}

inline void BoundingSphere::reset() {
    _center.reset();
    _radius = 0.0f;
}

inline void BoundingSphere::setRadius(F32 radius) noexcept { _radius = radius; }

inline void BoundingSphere::setCenter(const vec3<F32>& center) noexcept {
    _center = center;
}

inline const vec3<F32>& BoundingSphere::getCenter() const noexcept { return _center; }

inline F32 BoundingSphere::getRadius() const noexcept { return _radius; }

inline F32 BoundingSphere::getDiameter() const noexcept { return _radius * 2; }

inline F32 BoundingSphere::getDistanceFromPoint(const vec3<F32>& point) const {
    return getCenter().distance(point) - getRadius();
}

inline vec4<F32> BoundingSphere::asVec4() const {
    return vec4<F32>(getCenter(), getRadius());
}
};  // namespace Divide

#endif  //_CORE_MATH_BOUNDINGVOLUMES_BOUNDINGSPHERE_INL_

Commits for Divide-Framework/trunk/Source Code/Core/Math/BoundingVolumes/Headers/BoundingSphere.inl

Diff revisions: vs.
Revision Author Commited Message
1029 Diff Diff IonutCava picture IonutCava Tue 30 Jan, 2018 17:28:39 +0000

[Ionut]
- Update copyright notices

993 Diff Diff IonutCava picture IonutCava Sun 10 Dec, 2017 20:07:57 +0000

[Ionut]
- Finished initial port of the old scene graph system to the new ECS based system.
- Finished converting 2 components to the new ECS system: Transform and RigidBody
- Fixed the “Deploy” build error with the CEGUI OpenGL renderer.
- Compilation now needs C++14 support (it’s sufficiently wide-spread now)

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

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

548 Diff Diff IonutCava picture IonutCava Wed 04 Nov, 2015 17:23:15 +0000

[IonutCava]
- More work on improving cascaded shadow maps

543 Diff Diff IonutCava picture IonutCava Fri 30 Oct, 2015 17:18:18 +0000

[IonutCava]
- More profile guided optimizations
- Attempt to render all CSM splits in a single pass using geometry shader based instancing (unfinished)

444 Diff Diff IonutCava picture IonutCava Thu 21 May, 2015 16:06:53 +0000

[Ionut]
- More platform independent code cleanup:
— Moved platform specific defines to their respective header files (e.g. THREAD_LOCAL)
— Moved most preprocessor defines from the VisualC++ projects into source code
— Removed compiler specific code (e.g. warning disables) and fixed most warning resulting from this

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