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
/*
   Copyright (c) 2013 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 "MathVectors.h"
#include "Utility/Headers/Vector.h"
///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 Crespectively
///and a constant (D) which is the distance along the normal you have to go to move the plane back to the origin.
template<class 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 Side {
        NO_SIDE,
        POSITIVE_SIDE,
        NEGATIVE_SIDE,
        BOTH_SIDE
    };

	Plane() : _distance(0), _active(true) {}
	Plane(const Plane& rhs) : _normal(rhs._normal), _distance(rhs._distance), _active(true) {}
	///distance is stored as the negative of the specified value
	Plane(const vec3<T>& normal, T distance) : _normal(normal), _distance(-distance), _active(true) {}
	///distance is stored as the negative of the specified value
	Plane(T a, T b, T c, T distance) : _normal(a, b, c), _distance(distance), _active(true){}
	Plane(const vec3<T>& normal, const vec3<T>& point) : _active(true)
	{
		redefine(normal, point);
	}
	Plane (const vec3<T>& point0, const vec3<T>& point1, const vec3<T>& point2) : _active(true)
	{
		redefine(point0, point1, point2);
	}
	
	inline T getDistance(const vec3<T>& point) const{	return _normal.dot(point) + _distance; }

	inline void set(const vec3<T>& normal, T distance) {_normal = normal; _distance = -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);}

	/// 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;}
	/// Comparison operator
    bool operator==(const Plane& rhs) const { return (rhs._distance == _distance && rhs._normal == _normal); }
    bool operator!=(const Plane& rhs) const { return (rhs._distance != _distance || rhs._normal != _normal); }
	
	T normalize() {
        T length = _normal.length();
        if ( length > F32(0.0f) ) {
            T invLength = 1.0f / length;
            _normal *= invLength;
            _distance *= invLength;
        }
        return length;
    }

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

typedef vectorImpl<Plane<F32> > PlaneList;

#endif

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

Diff revisions: vs.
Revision Author Commited Message
168 k1ngp1n picture k1ngp1n Sat 26 Oct, 2013 19:03:21 +0000

- Reworked the Camera class[[BR]]
— Now fully quaternion based [[BR]]
— Basic camera types added but not used yet (third person, first person, orbit) [[BR]]
- Cleaned up Material and Texture handling [[BR]]
- Added clipping plane support [[BR]]
— Similar to OpenGL fixed-function clip planes but fully shader driven [[BR]]
— Added a new class, “Plane”, that helps define clip planes [[BR]]
- Optimized the Singleton class to allow faster “getInstance” calls without performance penalties [[BR]]
-- “createInstance” must be called for each singleton class before usage. Or “gerOrCreateInstance” can be used, which is basically the former “getInstance” implementation [[BR]]
- Improved console logging by changing some heap allocations to stack and removing dependencies on the std::string class [[BR]]
- Added a lot of performance optimizations related to coding standards and redundant calculations [[BR]]
— e.g. Frustum AABB check didn’t need to recompute the AABB points as they were calculated already [[BR]]
— e.g. A vector did not need to be set to 0 on initialization as that is already it’s default state on creation [[BR]]
— e.g. Faster Framerate and Timing calculations by using less member variables that are not needed outsied of calling functions [[BR]]
- The SceneState now contains the SceneRenderState and is passed on to the SceneGraph’s update calls [[BR]]
- Better material export/import to/from XML format [[BR]]
- More bug fixes and cleanups [[BR]]