mirror of
https://github.com/TorqueGameEngines/Torque3D.git
synced 2026-07-11 06:34:36 +00:00
Engine directory for ticket #1
This commit is contained in:
parent
352279af7a
commit
7dbfe6994d
3795 changed files with 1363358 additions and 0 deletions
56
Engine/lib/opcode/Ice/IceSegment.cpp
Normal file
56
Engine/lib/opcode/Ice/IceSegment.cpp
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Contains code for segments.
|
||||
* \file IceSegment.cpp
|
||||
* \author Pierre Terdiman
|
||||
* \date April, 4, 2000
|
||||
*/
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
/**
|
||||
* Segment class.
|
||||
* A segment is defined by S(t) = mP0 * (1 - t) + mP1 * t, with 0 <= t <= 1
|
||||
* Alternatively, a segment is S(t) = Origin + t * Direction for 0 <= t <= 1.
|
||||
* Direction is not necessarily unit length. The end points are Origin = mP0 and Origin + Direction = mP1.
|
||||
*
|
||||
* \class Segment
|
||||
* \author Pierre Terdiman
|
||||
* \version 1.0
|
||||
*/
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
|
||||
#include "../Opcode.h"
|
||||
|
||||
using namespace IceMaths;
|
||||
|
||||
float Segment::SquareDistance(const Point& point, float* t) const
|
||||
{
|
||||
Point Diff = point - mP0;
|
||||
Point Dir = mP1 - mP0;
|
||||
float fT = Diff | Dir;
|
||||
|
||||
if(fT<=0.0f)
|
||||
{
|
||||
fT = 0.0f;
|
||||
}
|
||||
else
|
||||
{
|
||||
float SqrLen= Dir.SquareMagnitude();
|
||||
if(fT>=SqrLen)
|
||||
{
|
||||
fT = 1.0f;
|
||||
Diff -= Dir;
|
||||
}
|
||||
else
|
||||
{
|
||||
fT /= SqrLen;
|
||||
Diff -= fT*Dir;
|
||||
}
|
||||
}
|
||||
|
||||
if(t) *t = fT;
|
||||
|
||||
return Diff.SquareMagnitude();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue