Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
LineSegClass.h
1/* Renegade Scripts.dll
2 Copyright 2013 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
12#ifndef TT_INCLUDE__LINESEGCLASS_H
13#define TT_INCLUDE__LINESEGCLASS_H
14
15#include "Vector3.h"
16#include "Matrix3D.h"
17
18class SCRIPTS_API LineSegClass
19{
20public:
21 LineSegClass(void)
22 {
23 }
24 LineSegClass(const Vector3 & p0,const Vector3 & p1) : P0(p0), P1(p1)
25 {
26 recalculate();
27 }
28 LineSegClass(const Vector3& p0, const Vector3& dir, float l) : P0(p0), Dir(dir), Length(l)
29 {
30 DP = Dir * Length;
31 P1 = P0 + DP;
32 }
33 LineSegClass(const LineSegClass & that,const Matrix3D & tm)
34 {
35 Set(that,tm);
36 }
37 void Set(const Vector3 & p0,const Vector3 & p1)
38 {
39 P0 = p0;
40 P1 = p1;
41 recalculate();
42 }
43 void Set(const Vector3& p0, const Vector3& dir, float l)
44 {
45 DP = dir * l;
46 P0 = p0;
47 P1 = p0 + DP;
48 Dir = dir;
49 Length = l;
50 }
51 void Set(const LineSegClass & that,const Matrix3D & tm);
52 void Set_Random(const Vector3 & min,const Vector3 & max);
53 const Vector3 & Get_P0() const
54 {
55 return P0;
56 }
57 const Vector3 & Get_P1() const
58 {
59 return P1;
60 }
61 const Vector3 & Get_DP() const
62 {
63 return DP;
64 }
65 const Vector3 & Get_Dir() const
66 {
67 return Dir;
68 }
69 float Get_Length() const
70 {
71 return Length;
72 }
73 void Compute_Point(float t,Vector3 * set) const
74 {
75 Vector3::Add(P0,t*DP,set);
76 }
77 Vector3 Find_Point_Closest_To(const Vector3 &pos) const;
78 bool Find_Intersection (const LineSegClass &other_line, Vector3 *p1, float *fraction1, Vector3 *p2, float *fraction2) const;
79protected:
80 void recalculate(void)
81 {
82 DP = P1 - P0;
83 Dir = DP;
84 Dir.Normalize();
85 Length = DP.Length();
86 }
87 Vector3 P0;
88 Vector3 P1;
89 Vector3 DP;
90 Vector3 Dir;
91 float Length;
92}; // 0034
93
94
95#endif