nomlib
Loading...
Searching...
No Matches
Point3.hpp
1/******************************************************************************
2
3 nomlib - C++11 cross-platform game engine
4
5Copyright (c) 2013, 2014 Jeffrey Carpenter <i8degrees@gmail.com>
6All rights reserved.
7
8Redistribution and use in source and binary forms, with or without
9modification, are permitted provided that the following conditions are met:
10
111. Redistributions of source code must retain the above copyright notice, this
12 list of conditions and the following disclaimer.
132. Redistributions in binary form must reproduce the above copyright notice,
14 this list of conditions and the following disclaimer in the documentation
15 and/or other materials provided with the distribution.
16
17THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
18ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
19WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
21ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
22(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
23LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28******************************************************************************/
29#ifndef NOMLIB_MATH_POINT3_HEADERS
30#define NOMLIB_MATH_POINT3_HEADERS
31
32#include "nomlib/config.hpp"
33
34namespace nom {
35
37const std::string POINT3_DELIMITER = ", ";
38
40template <typename T>
41struct Point3
42{
45 x(-1),
46 y(-1),
47 z(-1)
48 {
49 //NOM_LOG_TRACE(NOM);
50 }
51
54 {
55 //NOM_LOG_TRACE(NOM);
56 }
57
59 Point3(T x, T y, T z) :
60 x(x),
61 y(y),
62 z(z)
63 {
64 //NOM_LOG_TRACE(NOM);
65 }
66
72 template <typename U>
73 explicit Point3<T>(const Point3<U>& copy) :
74 x( NOM_SCAST(T, copy.x) ),
75 y( NOM_SCAST(T, copy.y) ),
76 z( NOM_SCAST(T, copy.z) )
77 {
78 //NOM_LOG_TRACE(NOM);
79 }
80
82 inline const Point3<T>& get() const
83 {
84 return *this;
85 }
86
90 static const Point3 null;
91
93 static const Point3 zero;
94
95 T x;
96 T y;
97 T z;
98};
99
107template <typename T>
108inline std::ostream& operator << ( std::ostream& os, const Point3<T>& pos )
109{
110 os
111 << pos.x
112 << POINT3_DELIMITER
113 << pos.y
114 << POINT3_DELIMITER
115 << pos.z;
116
117 return os;
118}
119
120template <typename T>
121inline bool operator == ( const Point3<T>& lhs, const Point3<T>& rhs )
122{
123 return ( lhs.x == rhs.x ) && ( lhs.y == rhs.y ) && ( lhs.z == rhs.z );
124}
125
126template <typename T>
127inline bool operator != ( const Point3<T>& lhs, const Point3<T>& rhs )
128{
129 return ! ( lhs == rhs );
130}
131
133typedef Point3<int> Point3i;
134
136typedef Point3<real32> Point3f;
137
139typedef Point3<real64> Point3d;
140
141} // namespace nom
142
143#endif // include guard defined
3D Point class
Definition Point3.hpp:42
static const Point3 zero
Definition Point3.hpp:93
~Point3()
Destructor.
Definition Point3.hpp:53
Point3()
Default constructor; initialize values to Point3<T>::null.
Definition Point3.hpp:44
static const Point3 null
Definition Point3.hpp:90
Point3(T x, T y, T z)
Constructor variant for initializing x, y, z at construction.
Definition Point3.hpp:59
const Point3< T > & get() const
Obtain a reference of the object.
Definition Point3.hpp:82