wfmath  1.0.3
A math library for the Worldforge system.
rotbox.cpp
1 // rotbox.cpp (RotBox<> implementation)
2 //
3 // The WorldForge Project
4 // Copyright (C) 2011 The WorldForge Project
5 //
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the Free Software
18 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 //
20 // For information about WorldForge and its authors, please contact
21 // the Worldforge Web Site at http://www.worldforge.org.
22 
23 // Author: Alistair Riddoch
24 // Created: 2011-1-27
25 
26 // Extensive amounts of this material come from the Vector2D
27 // and Vector3D classes from stage/math, written by Bryce W.
28 // Harrington, Kosh, and Jari Sundell (Rakshasa).
29 
30 #include "rotbox_funcs.h"
31 
32 #include "quaternion.h"
33 
34 #include <cmath>
35 
36 namespace WFMath {
37 
38 template<> RotBox<3>& RotBox<3>::rotatePoint(const Quaternion& q, const Point<3>& p)
39 {
40  m_orient = m_orient.rotate(q); m_corner0.rotate(q, p); return *this;
41 }
42 
43 template<> RotBox<3>& RotBox<3>::rotateCorner(const Quaternion& q, size_t corner)
44 {
45  rotatePoint(q, getCorner(corner)); return *this;
46 }
47 
48 template<> RotBox<3>& RotBox<3>::rotateCenter(const Quaternion& q)
49 {
50  rotatePoint(q, getCenter()); return *this;
51 }
52 
53 template<> RotBox<3> RotBox<3>::toParentCoords(const Point<3>& origin,
54  const Quaternion& rotation) const
55 {
56  RotMatrix<3> orient = m_orient;
57  return RotBox<3>(m_corner0.toParentCoords(origin, rotation), m_size, orient.rotate(rotation));
58 }
59 
60 template<> RotBox<3> RotBox<3>::toLocalCoords(const Point<3>& origin,
61  const Quaternion& rotation) const
62 {
63  RotMatrix<3> orient = m_orient;
64  return RotBox<3>(m_corner0.toLocalCoords(origin, rotation), m_size, orient.rotate(rotation.inverse()));
65 }
66 
67 template class RotBox<2>;
68 template class RotBox<3>;
69 
70 static_assert(std::is_standard_layout<RotBox<2>>::value, "RotBox should be standard layout.");
71 static_assert(std::is_trivially_copyable<RotBox<2>>::value, "RotBox should be trivially copyable.");
72 
73 static_assert(std::is_standard_layout<RotBox<3>>::value, "RotBox should be standard layout.");
74 static_assert(std::is_trivially_copyable<RotBox<3>>::value, "RotBox should be trivially copyable.");
75 
76 
77 
78 template Point<2> Point<2>::toLocalCoords(RotBox<2> const&) const;
79 template Point<3> Point<3>::toLocalCoords(RotBox<3> const&) const;
80 template Point<2> Point<2>::toParentCoords(RotBox<2> const&) const;
81 template Point<3> Point<3>::toParentCoords(RotBox<3> const&) const;
82 
83 }
Generic library namespace.
Definition: shape.h:41