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 "export.hpp"
33#include "nomlib/config.hpp"
34
35namespace nom {
36
38const std::string POINT3_DELIMITER = ", ";
39
41template <typename T>
42struct NOM_EXPORT Point3
43{
46 x(-1),
47 y(-1),
48 z(-1)
49 {
50 //NOM_LOG_TRACE(NOM);
51 }
52
55 {
56 //NOM_LOG_TRACE(NOM);
57 }
58
60 Point3(T x, T y, T z) :
61 x(x),
62 y(y),
63 z(z)
64 {
65 //NOM_LOG_TRACE(NOM);
66 }
67
73 template <typename U>
74 explicit Point3<T>(const Point3<U>& copy) :
75 x( NOM_SCAST(T, copy.x) ),
76 y( NOM_SCAST(T, copy.y) ),
77 z( NOM_SCAST(T, copy.z) )
78 {
79 //NOM_LOG_TRACE(NOM);
80 }
81
83 NOM_EXPORT inline const Point3<T>& get() const
84 {
85 return *this;
86 }
87
91 NOM_EXPORT static const Point3 null;
92
94 NOM_EXPORT static const Point3 zero;
95
96 NOM_EXPORT T x;
97 NOM_EXPORT T y;
98 NOM_EXPORT T z;
99};
100
108template <typename T>
109NOM_EXPORT
110inline std::ostream& operator << ( std::ostream& os, const Point3<T>& pos )
111{
112 os
113 << pos.x
114 << POINT3_DELIMITER
115 << pos.y
116 << POINT3_DELIMITER
117 << pos.z;
118
119 return os;
120}
121
122template <typename T>
123NOM_EXPORT
124inline bool operator == ( const Point3<T>& lhs, const Point3<T>& rhs )
125{
126 return ( lhs.x == rhs.x ) && ( lhs.y == rhs.y ) && ( lhs.z == rhs.z );
127}
128
129template <typename T>
130NOM_EXPORT
131inline bool operator != ( const Point3<T>& lhs, const Point3<T>& rhs )
132{
133 return ! ( lhs == rhs );
134}
135
137typedef Point3<int> Point3i;
138
140typedef Point3<real32> Point3f;
141
143typedef Point3<real64> Point3d;
144
146template <> NOM_EXPORT const Point3i Point3i::null;
147
149template <> NOM_EXPORT const Point3f Point3f::null;
150
152template <> NOM_EXPORT const Point3d Point3d::null;
153
155template <> NOM_EXPORT const Point3i Point3i::zero;
156
158template <> NOM_EXPORT const Point3f Point3f::zero;
159
162template <> NOM_EXPORT const Point3d Point3d::zero;
163
164} // namespace nom
165
166#endif // include guard defined
3D Point class
Definition Point3.hpp:43
NOM_EXPORT const Point3< T > & get() const
Obtain a reference of the object.
Definition Point3.hpp:83
~Point3()
Destructor.
Definition Point3.hpp:54
Point3()
Default constructor; initialize values to Point3<T>::null.
Definition Point3.hpp:45
static NOM_EXPORT const Point3 null
Definition Point3.hpp:91
Point3(T x, T y, T z)
Constructor variant for initializing x, y, z at construction.
Definition Point3.hpp:60
static NOM_EXPORT const Point3 zero
Definition Point3.hpp:94