STriangle2.h
Go to the documentation of this file.
1 
2 #pragma once
3 
4 #include "SVector3.h"
5 
6 
9 template <typename T>
11 {
12 
13 public:
14 
16 
18  {}
19 
20  STriangle2(vec2<T> const & v1, vec2<T> const & v2, vec2<T> const & v3)
21  {
22  Vertices[0] = v1;
23  Vertices[1] = v2;
24  Vertices[2] = v3;
25  }
26 
27  static T Sign(vec2<T> const & p1, vec2<T> const & p2, vec2<T> const & p3)
28  {
29  return (p1.X - p3.X) * (p2.Y - p3.Y) - (p2.X - p3.X) * (p1.Y - p3.Y);
30  }
31 
32  bool PointInside(vec2<T> const & pt) const
33  {
34  bool b1, b2, b3;
35 
36  b1 = Sign(pt, Vertices[0], Vertices[1]) < 0.0f;
37  b2 = Sign(pt, Vertices[1], Vertices[2]) < 0.0f;
38  b3 = Sign(pt, Vertices[2], Vertices[0]) < 0.0f;
39 
40  return ((b1 == b2) && (b2 == b3));
41  }
42 
43 };
44 
49 
2D vector
Definition: SVector2.h:11
T X
Definition: SVector2.h:14
STriangle2()
Definition: STriangle2.h:17
T Y
Definition: SVector2.h:15
STriangle2u tri2u
Definition: STriangle2.h:53
STriangle2d tri2d
Definition: STriangle2.h:51
STriangle2< f64 > STriangle2d
Definition: STriangle2.h:46
vec2< T > Vertices[3]
Definition: STriangle2.h:15
2D triangle
Definition: STriangle2.h:10
STriangle2< s32 > STriangle2i
Definition: STriangle2.h:47
STriangle2< f32 > STriangle2f
Definition: STriangle2.h:45
STriangle2< u32 > STriangle2u
Definition: STriangle2.h:48
STriangle2i tri2i
Definition: STriangle2.h:52
static T Sign(vec2< T > const &p1, vec2< T > const &p2, vec2< T > const &p3)
Definition: STriangle2.h:27
STriangle2(vec2< T > const &v1, vec2< T > const &v2, vec2< T > const &v3)
Definition: STriangle2.h:20
STriangle2f tri2f
Definition: STriangle2.h:50
bool PointInside(vec2< T > const &pt) const
Definition: STriangle2.h:32