Richard Boegli's CnC_Generals_Zero_Hour Fork WIP
This is documentation of Richard Boegil's Zero Hour Fork
 
Loading...
Searching...
No Matches
lineseg.h
Go to the documentation of this file.
1/*
2** Command & Conquer Generals Zero Hour(tm)
3** Copyright 2025 Electronic Arts Inc.
4**
5** This program is free software: you can redistribute it and/or modify
6** it under the terms of the GNU General Public License as published by
7** the Free Software Foundation, either version 3 of the License, or
8** (at your option) any later version.
9**
10** This program is distributed in the hope that it will be useful,
11** but WITHOUT ANY WARRANTY; without even the implied warranty of
12** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13** GNU General Public License for more details.
14**
15** You should have received a copy of the GNU General Public License
16** along with this program. If not, see <http://www.gnu.org/licenses/>.
17*/
18
19/***********************************************************************************************
20 *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
21 ***********************************************************************************************
22 * *
23 * Project Name : WWMath *
24 * *
25 * $Archive:: /Commando/Code/wwmath/lineseg.h $*
26 * *
27 * Author:: Greg_h *
28 * *
29 * $Modtime:: 3/16/00 3:16p $*
30 * *
31 * $Revision:: 21 $*
32 * *
33 *---------------------------------------------------------------------------------------------*
34 * Functions: *
35 * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
36
37
38#if defined(_MSC_VER)
39#pragma once
40#endif
41
42#ifndef LINESEG_H
43#define LINESEG_H
44
45#include "always.h"
46#include "vector3.h"
47#include "castres.h"
48
49class TriClass;
50class AABoxClass;
51class OBBoxClass;
52class PlaneClass;
53class SphereClass;
54class Matrix3D;
55
56
58{
59
60public:
61
62 LineSegClass(void) { }
63 LineSegClass(const Vector3 & p0,const Vector3 & p1) : P0(p0), P1(p1) { recalculate(); }
64 LineSegClass(const LineSegClass & that,const Matrix3D & tm) { Set(that,tm); }
65
66 void Set(const Vector3 & p0,const Vector3 & p1) { P0 = p0; P1 = p1; recalculate(); }
67 void Set(const LineSegClass & that,const Matrix3D & tm);
68 void Set_Random(const Vector3 & min,const Vector3 & max);
69
70 const Vector3 & Get_P0() const { return P0; } // start point
71 const Vector3 & Get_P1() const { return P1; } // end point
72 const Vector3 & Get_DP() const { return DP; } // difference of the two points
73 const Vector3 & Get_Dir() const { return Dir; } // normalized direction.
74 float Get_Length() const { return Length; } // length of the segment
75
76 void Compute_Point(float t,Vector3 * set) const { Vector3::Add(P0,t*DP,set); }
77
78 Vector3 Find_Point_Closest_To(const Vector3 &pos) const;
79 bool Find_Intersection (const LineSegClass &other_line, Vector3 *p1, float *fraction1, Vector3 *p2, float *fraction2) const;
80
81protected:
82
83 void recalculate(void) { DP = P1 - P0; Dir = DP; Dir.Normalize(); Length = DP.Length(); }
84
85 Vector3 P0; // start point
86 Vector3 P1; // end point
87 Vector3 DP; // difference of the two points
88 Vector3 Dir; // normalized direction.
89 float Length; // length of the segment
90};
91
92
93#endif
#define min(x, y)
Definition BaseType.h:101
#define max(x, y)
Definition BaseType.h:105
LineSegClass(const Vector3 &p0, const Vector3 &p1)
Definition lineseg.h:63
Vector3 P0
Definition lineseg.h:85
float Get_Length() const
Definition lineseg.h:74
const Vector3 & Get_Dir() const
Definition lineseg.h:73
LineSegClass(const LineSegClass &that, const Matrix3D &tm)
Definition lineseg.h:64
Vector3 DP
Definition lineseg.h:87
LineSegClass(void)
Definition lineseg.h:62
const Vector3 & Get_P1() const
Definition lineseg.h:71
Vector3 Find_Point_Closest_To(const Vector3 &pos) const
Definition lineseg.cpp:133
float Length
Definition lineseg.h:89
void Set(const Vector3 &p0, const Vector3 &p1)
Definition lineseg.h:66
Vector3 Dir
Definition lineseg.h:88
const Vector3 & Get_DP() const
Definition lineseg.h:72
void recalculate(void)
Definition lineseg.h:83
bool Find_Intersection(const LineSegClass &other_line, Vector3 *p1, float *fraction1, Vector3 *p2, float *fraction2) const
Definition lineseg.cpp:167
void Set_Random(const Vector3 &min, const Vector3 &max)
Definition lineseg.cpp:94
Vector3 P1
Definition lineseg.h:86
const Vector3 & Get_P0() const
Definition lineseg.h:70
void Compute_Point(float t, Vector3 *set) const
Definition lineseg.h:76
Definition tri.h:61
static WWINLINE void Add(const Vector3 &a, const Vector3 &b, Vector3 *c)
Definition vector3.h:555