Class: CGLM::AABB
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #[](corner_index) ⇒ Object
- #[]=(index, val) ⇒ Object
-
#center([dest]) ⇒ dest | new Vec3
Computes the center point of the AABB and places it into the Vec3
dest
, creating a new one ifdest
is omitted. -
#contains_aabb?(aabb) ⇒ Boolean
Returns true if this AABB contains the specified AABB, false otherwise.
-
#contains_point?(vec3) ⇒ Boolean
Returns true if this AABB contains the specified point (inclusive), false otherwise.
-
#crop(crop[, dest]) ⇒ Object
Crops this AABB by
crop
, placing the result indest
or creating a new one. -
#crop_until(crop, clamp[, dest]) ⇒ Object
Crops this AABB by
crop
, placing the result indest
or creating a new one. -
#=~(b) ⇒ Object
(also: #=~)
Returns true if each member of
a
is very close to, but not necessarily exactly equal to, each corresponding member ofb
. -
#intersects_aabb?(aabb) ⇒ Boolean
Returns true if the two AABB's overlap, false otherwise.
-
#intersects_frustum?(frustum) ⇒ Boolean
Returns true if this AABB intersects the given Frustum, false otherwise.
-
#intersects_sphere?(vec4) ⇒ Boolean
Returns true if the sphere described by the given Vec4 intersects this AABB, false otherwise.
-
#invalidate ⇒ self
Invalidates the AABB min and max values.
-
#merge(other[, dest]) ⇒ Object
Merges two axis-aligned bounding boxes, storing the result in
dest
. -
#radius ⇒ Numeric
Returns the radius of a sphere which surrounds this AABB.
-
#size ⇒ Numeric
Returns the length of the diagonal line between the corners of this AABB.
-
#transform(mat4[, dest]) ⇒ Object
Applies transform to an axis-aligned bounding box, placing the result in
dest
and allocating it if necessary. -
#valid? ⇒ Boolean
Returns true if this AABB is valid, false otherwise.
Methods inherited from Base
#copy_to, #dup, #initialize, #initialize_dup
Constructor Details
This class inherits a constructor from CGLM::Base
Class Method Details
.alignment ⇒ Object
216 |
# File 'ext/cglm/rb_cglm_aabb.c', line 216 VALUE rb_cglm_aabb_alignment_bytes(VALUE klass) { return SIZET2NUM(AABB_ALIGNMENT); } |
.size ⇒ Object
214 |
# File 'ext/cglm/rb_cglm_aabb.c', line 214 VALUE rb_cglm_aabb_size_bytes(VALUE klass) { return SIZET2NUM(aabb_size()); } |
Instance Method Details
#==(other) ⇒ Object
218 219 220 221 |
# File 'ext/cglm/rb_cglm_aabb.c', line 218
VALUE rb_cglm_aabb_equals_aabb(VALUE self, VALUE other) {
if (memcmp(&VAL2AABB(self), &VAL2AABB(other), sizeof(aabb))) return Qfalse;
return Qtrue;
}
|
#[](corner_index) ⇒ Object
203 204 205 206 |
# File 'ext/cglm/rb_cglm_aabb.c', line 203
VALUE rb_cglm_aabb_aref(VALUE self, VALUE corner_index) {
CHECK_RANGE(corner_index, 0, 1);
return VEC3_NEW(VAL2AABB(self).corners[NUM2INT(corner_index)]);
}
|
#[]=(index, val) ⇒ Object
208 209 210 211 212 |
# File 'ext/cglm/rb_cglm_aabb.c', line 208
VALUE rb_cglm_aabb_aset(VALUE self, VALUE index, VALUE val) {
CHECK_RANGE(index, 0, 1);
memcpy(VAL2AABB(self).corners[NUM2INT(index)], VAL2VEC3(val), sizeof(vec3));
return self;
}
|
#center([dest]) ⇒ dest | new Vec3
Computes the center point of the AABB and places it into the Vec3 dest
,
creating a new one if dest
is omitted.
143 144 145 146 147 148 149 150 151 152 153 |
# File 'ext/cglm/rb_cglm_aabb.c', line 143
VALUE rb_cglm_aabb_center(int argc, VALUE *argv, VALUE self) {
VALUE dest;
rb_scan_args(argc, argv, "01", &dest);
if (NIL_P(dest)) dest = VEC3_NEW(ALLOC_VEC3);
aabb *a;
vec3 *b;
a = &VAL2AABB(self);
b = &VAL2VEC3(dest);
glm_aabb_center(a->corners, *b);
return dest;
}
|
#contains_aabb?(aabb) ⇒ Boolean
Returns true if this AABB contains the specified AABB, false otherwise.
196 197 198 199 200 201 |
# File 'ext/cglm/rb_cglm_aabb.c', line 196
VALUE rb_cglm_aabb_contains_aabb(VALUE self, VALUE other) {
aabb *a, *b;
a = &VAL2AABB(self);
b = &VAL2AABB(other);
return glm_aabb_contains(a->corners, b->corners) ? Qtrue : Qfalse;
}
|
#contains_point?(vec3) ⇒ Boolean
Returns true if this AABB contains the specified point (inclusive), false otherwise.
184 185 186 187 188 189 190 |
# File 'ext/cglm/rb_cglm_aabb.c', line 184
VALUE rb_cglm_aabb_contains_point(VALUE self, VALUE point) {
aabb *a;
vec3 *b;
a = &VAL2AABB(self);
b = &VAL2VEC3(point);
return glm_aabb_point(a->corners, *b) ? Qtrue : Qfalse;
}
|
#crop(crop[, dest]) ⇒ Object
Crops this AABB by crop
, placing the result in dest
or creating a new
one. Returns dest
.
This could be useful for gettng an AABB which fits with view frustum and object bounding boxes. In this case you crop view frustum box with object's box.
49 50 51 52 53 54 55 56 57 58 59 |
# File 'ext/cglm/rb_cglm_aabb.c', line 49
VALUE rb_cglm_aabb_crop(int argc, VALUE *argv, VALUE self) {
VALUE other, dest;
rb_scan_args(argc, argv, "11", &other, &dest);
if (NIL_P(dest)) dest = AABB_NEW(ALLOC_AABB);
aabb *a, *b, *out;
a = &VAL2AABB(self);
b = &VAL2AABB(other);
out = &VAL2AABB(dest);
glm_aabb_crop(a->corners, b->corners, out->corners);
return dest;
}
|
#crop_until(crop, clamp[, dest]) ⇒ Object
Crops this AABB by crop
, placing the result in dest
or creating a new
one. Returns dest
. If the result would be smaller than clamp
, it is
restricted to the extents of clamp
instead.
This could be useful for gettng a bbox which fits with view frustum and object bounding boxes. In this case you crop view frustum box with objects box.
71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'ext/cglm/rb_cglm_aabb.c', line 71
VALUE rb_cglm_aabb_crop_until(int argc, VALUE *argv, VALUE self) {
VALUE other, clamp, dest;
rb_scan_args(argc, argv, "21", &other, &clamp, &dest);
if (NIL_P(dest)) dest = AABB_NEW(ALLOC_AABB);
aabb *a, *b, *c, *out;
a = &VAL2AABB(self);
b = &VAL2AABB(other);
c = &VAL2AABB(clamp);
out = &VAL2AABB(dest);
glm_aabb_crop_until(a->corners, b->corners, c->corners, out->corners);
return dest;
}
|
#=~(b) ⇒ Object Also known as: =~
Returns true if each member of a
is very close to, but not necessarily
exactly equal to, each corresponding member of b
. This is useful in many
circumstances because imprecision introduced by floating point calculations
can lead to two expressions which are otherwise mathematically equivalent
returning false.
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'ext/cglm/rb_cglm_aabb.c', line 231
VALUE rb_cglm_aabb_equalish_aabb(int argc, VALUE *argv, VALUE self) {
VALUE other, epsilon;
float feps = FLT_EPSILON;
rb_scan_args(argc, argv, "11", &other, &epsilon);
if (!NIL_P(epsilon)) feps = NUM2FLT(epsilon);
aabb *a = &VAL2AABB(self);
aabb *b = &VAL2AABB(other);
for (int i = 0; i < 2; i++) {
for (int j = 0; j < 3; j++) {
if (fabsf((*a).corners[i][j] - (*b).corners[i][j]) > feps)
return Qfalse;
}
}
return Qtrue;
}
|
#intersects_aabb?(aabb) ⇒ Boolean
Returns true if the two AABB's overlap, false otherwise.
159 160 161 162 163 164 |
# File 'ext/cglm/rb_cglm_aabb.c', line 159
VALUE rb_cglm_aabb_intersect_aabb(VALUE self, VALUE other) {
aabb *a, *b;
a = &VAL2AABB(self);
b = &VAL2AABB(other);
return glm_aabb_aabb(a->corners, b->corners) ? Qtrue : Qfalse;
}
|
#intersects_frustum?(frustum) ⇒ Boolean
Returns true if this AABB intersects the given Frustum, false otherwise.
88 89 90 91 92 93 94 |
# File 'ext/cglm/rb_cglm_aabb.c', line 88
VALUE rb_cglm_aabb_intersect_frustum(VALUE self, VALUE frstm) {
aabb *a;
frustum *f;
a = &VAL2AABB(self);
f = &VAL2FRUSTUM(frstm);
return glm_aabb_frustum(a->corners, f->planes) ? Qtrue : Qfalse;
}
|
#intersects_sphere?(vec4) ⇒ Boolean
Returns true if the sphere described by the given Vec4 intersects this AABB, false otherwise.
171 172 173 174 175 176 177 |
# File 'ext/cglm/rb_cglm_aabb.c', line 171
VALUE rb_cglm_aabb_intersect_sphere(VALUE self, VALUE sphere) {
aabb *a;
vec4 *b;
a = &VAL2AABB(self);
b = &VAL2VEC4(sphere);
return glm_aabb_sphere(a->corners, *b) ? Qtrue : Qfalse;
}
|
#invalidate ⇒ self
Invalidates the AABB min and max values.
100 101 102 103 104 105 |
# File 'ext/cglm/rb_cglm_aabb.c', line 100
VALUE rb_cglm_aabb_invalidate_self(VALUE self) {
aabb *a;
a = &VAL2AABB(self);
glm_aabb_invalidate(a->corners);
return self;
}
|
#merge(other[, dest]) ⇒ Object
Merges two axis-aligned bounding boxes, storing the result in dest
. If
dest
is omitted, a new AABB is created. Returns dest
.
Both boxes must be in the same space.
28 29 30 31 32 33 34 35 36 37 38 |
# File 'ext/cglm/rb_cglm_aabb.c', line 28
VALUE rb_cglm_aabb_merge(int argc, VALUE *argv, VALUE self) {
VALUE other, dest;
rb_scan_args(argc, argv, "11", &other, &dest);
if (NIL_P(dest)) dest = AABB_NEW(ALLOC_AABB);
aabb *a, *b, *out;
a = &VAL2AABB(self);
b = &VAL2AABB(other);
out = &VAL2AABB(dest);
glm_aabb_merge(a->corners, b->corners, out->corners);
return dest;
}
|
#radius ⇒ Numeric
Returns the radius of a sphere which surrounds this AABB.
132 133 134 135 136 |
# File 'ext/cglm/rb_cglm_aabb.c', line 132
VALUE rb_cglm_aabb_radius(VALUE self) {
aabb *a;
a = &VAL2AABB(self);
return DBL2NUM(glm_aabb_radius(a->corners));
}
|
#size ⇒ Numeric
Returns the length of the diagonal line between the corners of this AABB.
122 123 124 125 126 |
# File 'ext/cglm/rb_cglm_aabb.c', line 122
VALUE rb_cglm_aabb_size(VALUE self) {
aabb *a;
a = &VAL2AABB(self);
return DBL2NUM(glm_aabb_size(a->corners));
}
|
#transform(mat4[, dest]) ⇒ Object
Applies transform to an axis-aligned bounding box, placing the result in
dest
and allocating it if necessary.
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'ext/cglm/rb_cglm_aabb.c', line 8
VALUE rb_cglm_aabb_transform(int argc, VALUE *argv, VALUE self) {
VALUE matr, dest;
rb_scan_args(argc, argv, "11", &matr, &dest);
if (NIL_P(dest)) dest = AABB_NEW(ALLOC_AABB);
mat4 *m;
aabb *a, *b;
m = &VAL2MAT4(matr);
a = &VAL2AABB(self);
b = &VAL2AABB(dest);
glm_aabb_transform(a->corners, *m, a->corners);
return dest;
}
|
#valid? ⇒ Boolean
Returns true if this AABB is valid, false otherwise.
111 112 113 114 115 116 |
# File 'ext/cglm/rb_cglm_aabb.c', line 111
VALUE rb_cglm_aabb_is_valid(VALUE self) {
aabb *a;
a = &VAL2AABB(self);
glm_aabb_isvalid(a->corners);
return self;
}
|