Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
IceSegment.cpp
Go to the documentation of this file.
1 
8 
11 
21 
24 // Precompiled Header
25 #include "Stdafx.h"
26 
27 
28 using namespace Opcode;
29 
30 float Segment::SquareDistance(const Point& point, float* t) const
31 {
32  Point Diff = point - mP0;
33  Point Dir = mP1 - mP0;
34  float fT = Diff | Dir;
35 
36  if(fT<=0.0f)
37  {
38  fT = 0.0f;
39  }
40  else
41  {
42  float SqrLen= Dir.SquareMagnitude();
43  if(fT>=SqrLen)
44  {
45  fT = 1.0f;
46  Diff -= Dir;
47  }
48  else
49  {
50  fT /= SqrLen;
51  Diff -= fT*Dir;
52  }
53  }
54 
55  if(t) *t = fT;
56 
57  return Diff.SquareMagnitude();
58 }
59