Falco Engine 3.9.0.1 (beta)
Bounds.cs
Go to the documentation of this file.
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5
6namespace FalcoEngine
7{
8 public struct Bounds
9 {
10 private Vector3 m_Center;
11
12 private Vector3 m_Extents;
13
18 {
19 get
20 {
21 return m_Center;
22 }
23 set
24 {
25 m_Center = value;
26 }
27 }
28
33 {
34 get
35 {
36 return m_Extents * 2f;
37 }
38 set
39 {
40 m_Extents = value * 0.5f;
41 }
42 }
43
48 {
49 get
50 {
51 return m_Extents;
52 }
53 set
54 {
55 m_Extents = value;
56 }
57 }
58
62 public Vector3 min
63 {
64 get
65 {
66 return center - extents;
67 }
68 set
69 {
70 SetMinMax(value, max);
71 }
72 }
73
77 public Vector3 max
78 {
79 get
80 {
81 return center + extents;
82 }
83 set
84 {
85 SetMinMax(min, value);
86 }
87 }
88
95 {
96 m_Center = center;
97 m_Extents = size * 0.5f;
98 }
99
100 public override int GetHashCode()
101 {
102 return center.GetHashCode() ^ (extents.GetHashCode() << 2);
103 }
104
105 public override bool Equals(object other)
106 {
107 if (!(other is Bounds))
108 {
109 return false;
110 }
111 return Equals((Bounds)other);
112 }
113
114 public bool Equals(Bounds other)
115 {
116 return center.Equals(other.center) && extents.Equals(other.extents);
117 }
118
119 public static bool operator ==(Bounds lhs, Bounds rhs)
120 {
121 return lhs.center == rhs.center && lhs.extents == rhs.extents;
122 }
123
124 public static bool operator !=(Bounds lhs, Bounds rhs)
125 {
126 return !(lhs == rhs);
127 }
128
135 {
136 extents = (max - min) * 0.5f;
137 center = min + extents;
138 }
139
144 public void Encapsulate(Vector3 point)
145 {
146 SetMinMax(Vector3.Min(min, point), Vector3.Max(max, point));
147 }
148
153 public void Encapsulate(Bounds bounds)
154 {
155 Encapsulate(bounds.center - bounds.extents);
156 Encapsulate(bounds.center + bounds.extents);
157 }
158
163 public void Expand(float amount)
164 {
165 amount *= 0.5f;
166 extents += new Vector3(amount, amount, amount);
167 }
168
173 public void Expand(Vector3 amount)
174 {
175 extents += amount * 0.5f;
176 }
177
182 public bool Intersects(Bounds bounds)
183 {
184 return min.x <= bounds.max.x && max.x >= bounds.min.x && min.y <= bounds.max.y && max.y >= bounds.min.y && min.z <= bounds.max.z && max.z >= bounds.min.z;
185 }
186
191 public override string ToString()
192 {
193 return String.Format("Center: {0}, Extents: {1}", m_Center, m_Extents);
194 }
195
200 public string ToString(string format)
201 {
202 return String.Format("Center: {0}, Extents: {1}", m_Center.ToString(format), m_Extents.ToString(format));
203 }
204 }
205}
void Expand(float amount)
Definition: Bounds.cs:163
Vector3 extents
Definition: Bounds.cs:48
Vector3 min
Definition: Bounds.cs:63
Vector3 max
Definition: Bounds.cs:78
bool Equals(Bounds other)
Definition: Bounds.cs:114
void Expand(Vector3 amount)
Definition: Bounds.cs:173
Vector3 center
Definition: Bounds.cs:18
bool Intersects(Bounds bounds)
Definition: Bounds.cs:182
static bool operator==(Bounds lhs, Bounds rhs)
Definition: Bounds.cs:119
override string ToString()
Definition: Bounds.cs:191
void SetMinMax(Vector3 min, Vector3 max)
Definition: Bounds.cs:134
static bool operator!=(Bounds lhs, Bounds rhs)
Definition: Bounds.cs:124
string ToString(string format)
Definition: Bounds.cs:200
override int GetHashCode()
Definition: Bounds.cs:100
Vector3 size
Definition: Bounds.cs:33
void Encapsulate(Vector3 point)
Definition: Bounds.cs:144
override bool Equals(object other)
Definition: Bounds.cs:105
void Encapsulate(Bounds bounds)
Definition: Bounds.cs:153
Bounds(Vector3 center, Vector3 size)
Definition: Bounds.cs:94
override bool Equals(object other)
Definition: Vector3.cs:169
static Vector3 Min(Vector3 lhs, Vector3 rhs)
Definition: Vector3.cs:337
static Vector3 Max(Vector3 lhs, Vector3 rhs)
Definition: Vector3.cs:347
override int GetHashCode()
Definition: Vector3.cs:160
override string ToString()
Definition: Vector3.cs:356