Skip to content

Instantly share code, notes, and snippets.

@skrat
Created June 24, 2013 14:37
Show Gist options
  • Save skrat/5850513 to your computer and use it in GitHub Desktop.
Save skrat/5850513 to your computer and use it in GitHub Desktop.
return class AABB
@property 'size',
get: -> @max.sub(@min, new Vec3)
@property 'vertices',
get: -> [
new Vec3(new Float32Array([@min.x, @min.y, @min.z]))
new Vec3(new Float32Array([@max.x, @min.y, @min.z]))
new Vec3(new Float32Array([@max.x, @min.y, @max.z]))
new Vec3(new Float32Array([@min.x, @min.y, @max.z]))
new Vec3(new Float32Array([@min.x, @max.y, @min.z]))
new Vec3(new Float32Array([@max.x, @max.y, @min.z]))
new Vec3(new Float32Array([@max.x, @max.y, @max.z]))
new Vec3(new Float32Array([@min.x, @max.y, @max.z]))
]
constructor: () ->
vmax = Number.MAX_VALUE
vmin = -vmax
@min = new Vec3(new Float32Array([vmax, vmax, vmax]))
@max = new Vec3(new Float32Array([vmin, vmin, vmin]))
add: (v) ->
[x, y, z] = v
@min.x = Math.min(@min.x, x)
@min.y = Math.min(@min.y, y)
@min.z = Math.min(@min.z, z)
@max.x = Math.max(@max.x, x)
@max.y = Math.max(@max.y, y)
@max.z = Math.max(@max.z, z)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment