/
G3DBox.h
executable file
·265 lines (222 loc) · 7.52 KB
/
G3DBox.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
//-----------------------------------------------------------------------------
// Project SHGeometryKit
// Class G3DBox
// Creator Philippe C.D. Robert
// Maintainer Philippe C.D. Robert
// Creation Date Thu Sep 9 11:05:08 CEST 1999
//
// Copyright (c) Philippe C.D. Robert
//
// The SHGeometryKit is free software; you can redistribute it and/or modify it
// under the terms of the GNU LGPL Version 2 as published by the Free
// Software Foundation
//
// $Id: G3DBox.h,v 1.8 2002/10/27 20:17:02 probert Exp $
//-----------------------------------------------------------------------------
#ifndef __G3DBox_h_INCLUDE
#define __G3DBox_h_INCLUDE
#import <Foundation/Foundation.h>
#import "G3DIntersecting.h"
@class G3DMatrix4f;
@class G3DTuple3f;
@class G3DSphere;
@class G3DLine;
@class G3DPlane;
/*!
@class G3DBox
@abstract A generic box representation.
@discussion A generic, axis aligned box represented by 2 single-precision 3-element floating
point tuples.
*/
@interface G3DBox : NSObject <G3DIntersecting> // NSCoding, NSCopying
{
G3DTuple3f *min;
G3DTuple3f *max;
}
//-----------------------------------------------------------------------------
// init and free
//-----------------------------------------------------------------------------
/*!
@method init
@abstract Creates an axis aligned box with min [0.0, 0.0, 0.0] and max [1.0, 1.0, 1.0].
@result Returns the newly initialised box object or nil on error.
*/
- (id)init;
/*!
@method initWithMin:max:
@abstract Creates an axis aligned box from minimum to maximum.
@param minimum The minimum of the box
@param maximum The maximum of the box
@result Returns the newly initialised box object or nil on error.
*/
- (id)initWithMin:(G3DTuple3f *)minimum max:(G3DTuple3f *)maximum;
/*!
@method initWithBox:
@abstract Creates a box object with an existing box.
@param aBox Another box
@result Returns the newly initialised box object or nil on error.
*/
- (id)initWithBox:(G3DBox *)aBox;
//-----------------------------------------------------------------------------
// math
//-----------------------------------------------------------------------------
/*!
@method wrapPoint:
@abstract Resizes the sphere so that it wraps the point pt.
@param pt The point to be wrapped by the receiver
*/
- (void)wrapPoint:(G3DTuple3f *)pt;
/*!
@method wrapBox:
@abstract Resizes the sphere so that it wraps the box b.
@param b The box to be wrapped by the receiver
*/
- (void)wrapBox:(G3DBox *)b;
/*!
@method wrapSphere:
@abstract Resizes the sphere so that it wraps the sphere s.
@param s The sphere to be wrapped by the receiver
*/
- (void)wrapSphere:(G3DSphere *)s;
/*!
@method intersectsObject:
@abstract Tests if the receiver intersects the passed object. The method raises a
G3DBoxException if it fails to perform the test.
@param anObject Another mathematical primitive
@result Returns YES if the 2 objects intersect, NO otherwise.
*/
- (BOOL)intersectsObject:(id<G3DIntersecting>)anObject;
/*!
@method intersectsLine:
@abstract Tests if the receiver intersects the passed line.
@param l Another line object
@result Returns YES if the 2 boxes intersect, NO otherwise.
*/
- (BOOL)intersectsLine:(G3DLine *)l;
/*!
@method intersectsBox:
@abstract Tests if the receiver intersects the passed box. It actually currently tests
whether aBox is contained within the receiver.
@param b A box object
@result Returns YES if the box intersects the box, NO otherwise.
*/
- (BOOL)intersectsBox:(G3DBox *)aBox;
/*!
@method intersectsPlane:
@abstract Tests if the receiver intersects the passed plane.
@param p A plane object
@result Returns YES if the box intersects the plane, NO otherwise.
*/
- (BOOL)intersectsPlane:(G3DPlane *)aPlane;
/*!
@method intersectsSphere:
@abstract Tests if the receiver intersects the passed sphere.
@param s A sphere object
@result Returns YES if the box intersects the sphere, NO otherwise.
*/
- (BOOL)intersectsSphere:(G3DSphere *)aSphere;
/*!
@method wrapsPoint:
@abstract Tests if the receiver wraps pt.
@param pt A point
@result Returns YES if the box wraps the point, NO otherwise.
*/
- (BOOL)wrapsPoint:(G3DTuple3f *)pt;
/*!
@method transform:
@abstract Transforms the receiver by the passed 4 by 4 matrix. Hence it calculates
m * min and m * max such as it can be used directly with OpenGL.
@param m A 4 by 4 transformation matrix
*/
- (void)transform:(G3DMatrix4f *)m;
//-----------------------------------------------------------------------------
// accessor methods
//-----------------------------------------------------------------------------
/*!
@method setMin:max:
@abstract Sets the minimum and the maximum of the receiver.
@param minVec The lower left of the box
@param maxVec The upper right of the box
*/
- (void)setMin:(G3DTuple3f *)minVec max:(G3DTuple3f *)maxVec;
/*!
@method getMin:max:
@abstract Copies the minimum and the maximum of the receiver to the passed tuples.
@param minVec The lower left of the box
@param maxVec The upper right of the box
*/
- (void)getMin:(G3DTuple3f **)minVec max:(G3DTuple3f **)maxVec;
/*!
@method setMin:
@abstract Sets the minimum of the receiver.
@param m The lower left of the box
*/
- (void)setMin:(G3DTuple3f *)m;
/*!
@method min
@abstract Returns the lower left of the receiver.
*/
- (G3DTuple3f *)min;
/*!
@method setMax:
@abstract Sets the maximum of the receiver.
@param m The lower left of the box
*/
- (void)setMax:(G3DTuple3f *)m;
/*!
@method min
@abstract Returns the upper right of the receiver.
*/
- (G3DTuple3f *)max;
/*!
@method center
@abstract Returns the center point of the receiver.
*/
- (G3DTuple3f *)center;
/*!
@method volume
@abstract Returns the volume of the receiver.
*/
- (float)volume;
/*!
@method isEmpty
@abstract Returns YES if the volume of the receiver is equal to 0.0, NO otherwise.
*/
- (BOOL)isEmpty;
/*!
@method isEqualToBox:
@abstract Checks if the passed box is equal to the receiver.
@param aBox Another box object.
@result Returns YES if aSphere is equivalent to the receiver, NO otherwise.
*/
- (BOOL)isEqualToBox:(G3DBox *)aBox;
//-----------------------------------------------------------------------------
// NSCoding
//-----------------------------------------------------------------------------
/*!
@method encodeWithCoder:
@abstract Encodes the receiver using encoder.
*/
- (void)encodeWithCoder:(NSCoder *)aCoder;
/*!
@method initWithCoder:
@abstract Initializes a newly allocated instance from data in aCoder.
@result Returns self.
*/
- (id)initWithCoder:(NSCoder *)aCoder;
//-----------------------------------------------------------------------------
// NSCopying
//-----------------------------------------------------------------------------
/*!
@method copyWithZone:
@abstract Returns a new instance that's a copy of the receiver. Memory for the new
instance is allocated from zone, which may be nil. If zone is nil, the new
instance is allocated from the default zone, which is returned from the
function NSDefaultMallocZone. The returned object is implicitly retained
by the sender, who is responsible for releasing.
@result Returns a new instance that's a copy of the receiver.
*/
- (id)copyWithZone:(NSZone *)zone;
@end
extern NSString *G3DBoxException;
#endif