Gorgon Game Engine
Point3D.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <iostream>
4 #include <cmath>
5 
6 #include "../Types.h"
7 #include "Point.h"
8 
9 namespace Gorgon { namespace Geometry {
10 
11  template<class T_>
12  class basic_Point3D {
13  public:
15  typedef T_ BaseType;
16 
19 
21  basic_Point3D(const T_ &X, const T_ &Y, const T_ &Z) : X(X), Y(Y), Z(Z) { }
22 
24  basic_Point3D(const basic_Point<T_> &point, const T_ &Z = T_()) : X(point.X), Y(point.Y), Z(Z) { }
25 
26  Float operator *(const basic_Point3D &other) const {
27  return X*other.X + Y*other.Y + Z*other.Z;
28  }
29 
31  return {X*val, Y*val, Z*val};
32  }
33 
35  return {X/val, Y/val, Z/val};
36  }
37 
38  basic_Point3D operator +(const basic_Point3D &other) const {
39  return {X+other.X, Y+other.Y, Z+other.Z};
40  }
41 
42  basic_Point3D operator -(const basic_Point3D &other) const {
43  return {X-other.X, Y-other.Y, Z-other.Z};
44  }
45 
47  auto dist = Distance();
48 
49  return {X/dist, Y/dist, Z/dist};
50  }
51 
52  Float Distance() const {
53  return (Float)std::sqrt(X*X+Y*Y+Z*Z);
54  }
55 
57  return (Float)(std::abs(X)+std::abs(Y)+std::abs(Z));
58  }
59 
61  return {Y*other.Z - Z*other.Y, Z*other.X - X*other.Z, X*other.Y - Y*other.X};
62  }
63 
64  union {
65  struct {
66  T_ X;
67  T_ Y;
68  T_ Z;
69  };
70 
71  T_ Vector[3];
72  };
73  };
74 
77  template <class T_>
78  std::ostream &operator << (std::ostream &out, const basic_Point3D<T_> &point) {
79  out<<"("<<point.X<<", "<<point.Y<<", "<<point.Z<<")";
80 
81  return out;
82  }
83 
85 
86 } }
Gorgon::Geometry::basic_Point3D::Vector
T_ Vector[3]
Definition: Point3D.h:71
Gorgon::Geometry::basic_Point3D::CrossProduct
basic_Point3D CrossProduct(const basic_Point3D &other) const
Definition: Point3D.h:60
Gorgon::Geometry::basic_Point3D::operator+
basic_Point3D operator+(const basic_Point3D &other) const
Definition: Point3D.h:38
Gorgon::Geometry::basic_Point3D::Y
T_ Y
Definition: Point3D.h:67
Gorgon::Geometry::basic_Point3D::Normalize
basic_Point3D Normalize() const
Definition: Point3D.h:46
Point.h
contains point class.
Gorgon::Geometry::basic_Point3D::Z
T_ Z
Definition: Point3D.h:68
Gorgon::Geometry::basic_Point3D::operator*
Float operator*(const basic_Point3D &other) const
Definition: Point3D.h:26
Gorgon::Geometry::basic_Point3D::operator/
basic_Point3D operator/(Float val) const
Definition: Point3D.h:34
Gorgon::Geometry::basic_Point3D
Definition: Point3D.h:12
Gorgon::Float
float Float
Represents floating point data type.
Definition: Types.h:16
Gorgon::Geometry::basic_Point3D::basic_Point3D
basic_Point3D(const basic_Point< T_ > &point, const T_ &Z=T_())
Filling constructor.
Definition: Point3D.h:24
Gorgon::Geometry::basic_Point3D::basic_Point3D
basic_Point3D(const T_ &X, const T_ &Y, const T_ &Z)
Filling constructor.
Definition: Point3D.h:21
Gorgon
Root namespace for Gorgon Game Engine.
Definition: Any.h:19
Gorgon::Geometry::basic_Point3D::BaseType
T_ BaseType
Base type of the point elements.
Definition: Point3D.h:15
Gorgon::Geometry::basic_Point3D::X
T_ X
Definition: Point3D.h:66
Gorgon::Geometry::basic_Point
This class represents a 2D point.
Definition: Point.h:32
Gorgon::Geometry::basic_Point3D::operator-
basic_Point3D operator-(const basic_Point3D &other) const
Definition: Point3D.h:42
Gorgon::Geometry::operator<<
std::ostream & operator<<(std::ostream &out, const basic_Bounds< T_ > &bounds)
Allows streaming of bounds.
Definition: Bounds.h:415
Gorgon::Geometry::basic_Point3D::Distance
Float Distance() const
Definition: Point3D.h:52
Gorgon::Geometry::basic_Point3D::ManhattanDistance
Float ManhattanDistance() const
Definition: Point3D.h:56
Gorgon::Geometry::basic_Point3D::basic_Point3D
basic_Point3D()
Default constructor, does not zero initialize point.
Definition: Point3D.h:18