We need to translate a model 90 degrees clockwise in the x/y/z grid.
Can you find the necessary formula?
If you can find this, I will offer you 5000 Zylon Coins, or a perm version of any item in the game, or a guaranteed perm version of the halloween event rewards.
Seriously dudes, I am desperate.
What program are you using?
I don't really see the problem here you can open the model in a model editor and use a turn tool to change the direction it is facing?
I think that you mean that the converter changes your xyz direction, if you need a code to fix that and you want others to fix it for you, you should give more information perhaps the script type, the file type? Also a change of where the model is facing before your file is converted will fix the problem.
We need a formula.
Please do not question our program, it is irrelevant.
I wanted to know because it may make it easier to understand.
visual studio
http://wiki.answers.com/Q/How_do_you_rotate_a_figure_90_degrees_clockwise_about_origin
Like so? ::)
Quote from: Rossbach on October 22, 2013, 05:37:22 AM
http://wiki.answers.com/Q/How_do_you_rotate_a_figure_90_degrees_clockwise_about_origin
Like so? ::)
That's 2d.
Quote from: Purple on October 22, 2013, 05:38:28 AM
Quote from: Rossbach on October 22, 2013, 05:37:22 AM
http://wiki.answers.com/Q/How_do_you_rotate_a_figure_90_degrees_clockwise_about_origin
Like so? ::)
That's 2d.
Bleh. ::)
(http://i40.tinypic.com/2vikoe8.jpg)
Rotated 90 degrees clockwise over a specific axis, or the origin?
it is a script for blender written in python.
I think you can add Z and Y if needed.
discussion found here: http://blenderartists.org/forum/showthread.php?255246-Rotate-whole-scene-around-x-90-and-apply-rotation
the code:
##########################################################
# Custom Blender -> Unity Pipeline
# http://www.mimimi-productions.com, 2012
# Version: 1.0
#
# Thanks to kastoria for his support!
# http://www.blenderartists.org
##########################################################
# Fixes the -90 degree (x-axis) problem for Unity.
# Artists and coders simply work as they should.
# -> No more custom rotation-fixes in Unity or Blender.
##########################################################
# Rotation matrix of -90 around the X-axis
rot_x_neg90 = Matrix.Rotation(-math.pi/2.0, 4, 'X')
# Iterate the objects in the file, only root level and rotate them
for obj in bpy.data.objects:
if obj.parent != None:
continue
obj.matrix_world = rot_x_neg90 * obj.matrix_world
# apply all(!) transforms
for obj in bpy.data.objects:
bpy.ops.object.transform_apply(rotation=True)
# custom args
kwargs = dict( # we dont need the rotation in the exporter anymore
#global_matrix=Matrix.Rotation(-math.pi / 2.0, 4, 'X'),
use_selection=False,
# not sure if we really need 'EMPTY' in our workflow, but we usually don't need the animation-helpers
object_types={'ARMATURE', 'MESH'},
use_mesh_modifiers=True,
use_anim=True,
use_anim_optimize=False,
use_anim_action_all=True,
batch_mode='OFF',
# never used, especially for non-animated objects
use_default_take=False,
)
# export!
io_scene_fbx.export_fbx.save(FakeOp(), bpy.context, filepath=outfile, **kwargs)
if you are asking this in the community you are really depserate and possibly nobody knows how to do that XDXD
this works for 2d. take basics and add an axis and ur done (?)
http://support.microsoft.com/kb/80406/en-us
I don't know anything about models and things, but if you are asking for a formula it's possible the rotation can be done using matrices.
http://stackoverflow.com/questions/9933150/how-do-i-rotate-in-object-space-in-3d-using-matrixes (http://stackoverflow.com/questions/9933150/how-do-i-rotate-in-object-space-in-3d-using-matrixes)
http://www.fastgraph.com/makegames/3drotation/ (http://www.fastgraph.com/makegames/3drotation/)
She wants a formula, not websites. I've already linked/read about 15 sites.
Quote from: Purple on October 22, 2013, 09:55:10 AM
She wants a formula, not websites. I've already linked/read about 15 sites.
Those websites contain the matrices, making it easier, as you can't directly copy and paste them. But the most simple matrix for 3rd rotation:
(http://i781.photobucket.com/albums/yy91/socksphotos/NewPicture_zpscc8ff08a.png)
Where , (phi), and (psi) are the rotations around the X, Y and Z axes.
Quote from: CyberSox on October 22, 2013, 10:12:44 AM
Quote from: Purple on October 22, 2013, 09:55:10 AM
She wants a formula, not websites. I've already linked/read about 15 sites.
Those websites contain the matrices, making it easier, as you can't directly copy and paste them. But the most simple matrix for 3rd rotation:
(http://i781.photobucket.com/albums/yy91/socksphotos/NewPicture_zpscc8ff08a.png)
Where , (phi), and (psi) are the rotations around the X, Y and Z axes.
"...and noone in BC is either smart enough, or willing to go further than finding a page and telling me to figure it out from there"
- Allie 2013
Quote from: Purple on October 22, 2013, 10:15:34 AM
Quote from: CyberSox on October 22, 2013, 10:12:44 AM
Quote from: Purple on October 22, 2013, 09:55:10 AM
She wants a formula, not websites. I've already linked/read about 15 sites.
Those websites contain the matrices, making it easier, as you can't directly copy and paste them. But the most simple matrix for 3rd rotation:
(http://i781.photobucket.com/albums/yy91/socksphotos/NewPicture_zpscc8ff08a.png)
Where , (phi), and (psi) are the rotations around the X, Y and Z axes.
"...and noone in BC is either smart enough, or willing to go further than finding a page and telling me to figure it out from there"
- Allie 2013
I don't see any reason why I should listen to you. Stop pretending you're Allie's little sidekick, and going off topic. All I see you doing on this forums is being negative about others while not doing anything useful yourself. Back on topic, it's clear you haven't even clicked on the website, it contains a few of the required matrices to do the rotation. She asked for help, and that's the formula. She has to plug in her own values for Theta, Phi and Psi.
Quote from: CyberSox on October 22, 2013, 10:27:06 AM
Quote from: Purple on October 22, 2013, 10:15:34 AM
Quote from: CyberSox on October 22, 2013, 10:12:44 AM
Quote from: Purple on October 22, 2013, 09:55:10 AM
She wants a formula, not websites. I've already linked/read about 15 sites.
Those websites contain the matrices, making it easier, as you can't directly copy and paste them. But the most simple matrix for 3rd rotation:
(http://i781.photobucket.com/albums/yy91/socksphotos/NewPicture_zpscc8ff08a.png)
Where , (phi), and (psi) are the rotations around the X, Y and Z axes.
"...and noone in BC is either smart enough, or willing to go further than finding a page and telling me to figure it out from there"
- Allie 2013
I don't see any reason why I should listen to you. Stop pretending you're Allie's little sidekick, and going off topic. All I see you doing on this forums is being negative about others while not doing anything useful yourself. Back on topic, it's clear you haven't even clicked on the website, it contains a few of the required matrices to do the rotation. She asked for help, and that's the formula. She has to plug in her own values for Theta, Phi and Psi.
I don't see where i've become Allie's 'sidekick', I was simply saying that linking a website isn't what she asked for. I already linked her that website and pointed that out, apparently it's not what she wants. I guess I should stop going offtopic though.
Quote from: CyberSox on October 22, 2013, 10:27:06 AM
Quote from: Purple on October 22, 2013, 10:15:34 AM
Quote from: CyberSox on October 22, 2013, 10:12:44 AM
Quote from: Purple on October 22, 2013, 09:55:10 AM
She wants a formula, not websites. I've already linked/read about 15 sites.
Those websites contain the matrices, making it easier, as you can't directly copy and paste them. But the most simple matrix for 3rd rotation:
(http://i781.photobucket.com/albums/yy91/socksphotos/NewPicture_zpscc8ff08a.png)
Where , (phi), and (psi) are the rotations around the X, Y and Z axes.
"...and noone in BC is either smart enough, or willing to go further than finding a page and telling me to figure it out from there"
- Allie 2013
I don't see any reason why I should listen to you. Stop pretending you're Allie's little sidekick, and going off topic. All I see you doing on this forums is being negative about others while not doing anything useful yourself. Back on topic, it's clear you haven't even clicked on the website, it contains a few of the required matrices to do the rotation. She asked for help, and that's the formula. She has to plug in her own values for Theta, Phi and Psi.
There are different formulas for different modeling/game languages such as python, assembly, java, c, c++, etc. There not all the same, however I do commend you on showing her the websites you have offered( considering there pretty good/useful) It probably wont help her in this situation. Allie should have posted the current axis of the model to make it much easier.
Quote from: paranoia on October 22, 2013, 10:42:44 AM
Quote from: CyberSox on October 22, 2013, 10:27:06 AM
Quote from: Purple on October 22, 2013, 10:15:34 AM
Quote from: CyberSox on October 22, 2013, 10:12:44 AM
Quote from: Purple on October 22, 2013, 09:55:10 AM
She wants a formula, not websites. I've already linked/read about 15 sites.
Those websites contain the matrices, making it easier, as you can't directly copy and paste them. But the most simple matrix for 3rd rotation:
(http://i781.photobucket.com/albums/yy91/socksphotos/NewPicture_zpscc8ff08a.png)
Where , (phi), and (psi) are the rotations around the X, Y and Z axes.
"...and noone in BC is either smart enough, or willing to go further than finding a page and telling me to figure it out from there"
- Allie 2013
I don't see any reason why I should listen to you. Stop pretending you're Allie's little sidekick, and going off topic. All I see you doing on this forums is being negative about others while not doing anything useful yourself. Back on topic, it's clear you haven't even clicked on the website, it contains a few of the required matrices to do the rotation. She asked for help, and that's the formula. She has to plug in her own values for Theta, Phi and Psi.
There are different formulas for different modeling/game languages such as python, assembly, java, c, c++, etc. There not all the same, however I do commend you on showing her the websites you have offered( considering there pretty good/useful) It probably wont help her in this situation. Allie should have posted the current axis of the model to make it much easier.
a formula is a formula
2+2 is the same thing in every language
I want be able to help until this weekend but i have the forumla's saved on my laptop at my moms. If your still in need of them then i will either post here or pm them to you. (there is 2 formula's u can use. im asuming 1 is for bc.)
http://stackoverflow.com/questions/16663647/3x3-matrix-rotation-in-c (this is 2d but it could possibly help)
http://www.youtube.com/watch?v=PpUJsw7Y-x0 (this is a youtube video that may help rotating 3d)
Hope i helped.
Quote from: Iridion on October 22, 2013, 10:50:44 AM
Quote from: paranoia on October 22, 2013, 10:42:44 AM
Quote from: CyberSox on October 22, 2013, 10:27:06 AM
Quote from: Purple on October 22, 2013, 10:15:34 AM
Quote from: CyberSox on October 22, 2013, 10:12:44 AM
Quote from: Purple on October 22, 2013, 09:55:10 AM
She wants a formula, not websites. I've already linked/read about 15 sites.
Those websites contain the matrices, making it easier, as you can't directly copy and paste them. But the most simple matrix for 3rd rotation:
(http://i781.photobucket.com/albums/yy91/socksphotos/NewPicture_zpscc8ff08a.png)
Where , (phi), and (psi) are the rotations around the X, Y and Z axes.
"...and noone in BC is either smart enough, or willing to go further than finding a page and telling me to figure it out from there"
- Allie 2013
I don't see any reason why I should listen to you. Stop pretending you're Allie's little sidekick, and going off topic. All I see you doing on this forums is being negative about others while not doing anything useful yourself. Back on topic, it's clear you haven't even clicked on the website, it contains a few of the required matrices to do the rotation. She asked for help, and that's the formula. She has to plug in her own values for Theta, Phi and Psi.
There are different formulas for different modeling/game languages such as python, assembly, java, c, c++, etc. There not all the same, however I do commend you on showing her the websites you have offered( considering there pretty good/useful) It probably wont help her in this situation. Allie should have posted the current axis of the model to make it much easier.
a formula is a formula
2+2 is the same thing in every language
Your not understanding that each programming language works different and reads code different.
class Map extends EventEmitter
constructor: (size) ->
throw new Error "Size must be between 1 and 255" unless 1 < size < 255
¶
@constant
@size = size
@setMaxListeners 2
¶
@constant
initialize grid
@grid = new Array Math.pow(@size, 3)
for x in [0...Math.pow(@size, 3)]
@grid
- = null
@rotation = 0
map = @
@blockDidChangeListener = ->
map.emit 'didChange'
@emit 'didChange'
forceUpdate: ->
@emit 'didChange'
¶
Sets the block at the given coordinates to the given block.
setBlock: (block, x, y, z, silent = no) ->
@validateCoordinates x, y, z
block.setCoordinates x, y, z if block
[x, y] = @applyRotation x, y if @rotation
position = x + y * @size + z * @size * @size
@grid[position]?.removeListener 'didChange', @blockDidChangeListener
@grid[position] = block
@grid[position]?.addListener 'didChange', @blockDidChangeListener
@emit 'didChange' unless silent
¶
Returns the block at the given coordinates.
getBlock: (x, y, z) ->
@validateCoordinates x, y, z
[x, y] = @applyRotation x, y if @rotation
return @grid[x + y * @size + z * @size * @size]
¶
Returns the block at the given coordinates and removes it from the map.
removeBlock: (x, y, z, silent = no) ->
block = @getBlock x, y, z
@setBlock null, x, y, z, yes
block?.removeListener 'didChange', @blockDidChangeListener
block?.setCoordinates null, null, null
@emit 'didChange' unless silent
return block
¶
Returns the height of the block stack at the given coordinates.
heightAt: (x, y) ->
@validateCoordinates x, y, 0
height = 0
while height < @size and @getBlock x, y, height
height++
return height
¶
Returns all blocks at the given coordinates.
getStack: (x, y, z = 0) ->
@validateCoordinates x, y, z
return [] if z > height = @heightAt x, y
blocks = new Array
for currentZ in [z...height]
blocks.push @getBlock x, y, currentZ
return blocks
¶
Blaces a stack of blocks at the given coordinates
setStack: (blocks, x, y, z = 0, silent = no) ->
@validateCoordinates x, y, z
unless blocks.length - 1 + z < @size
throw new Error "Cannot place stack, height out of bounds"
for block in blocks
@setBlock block, x, y, z++, yes
@emit 'didChange' unless silent
¶
Returns the stack at the given coordinates and removes it from the map.
removeStack: (x, y, z = 0, silent = no) ->
stack = @getStack x, y, z
for currentZ in [z...z + stack.length]
@setBlock null, x, y, z++, yes
@emit 'didChange' unless silent
return stack
¶
Validates the map. TODO: Currently only checks for floating blocks. Validate block stacks regarding matching low and top properties.
validate: ->
@blocksEach (block) =>
[x, y, z] = block.getCoordinates()
if block and z > 0 and not @getBlock x, y, z - 1
throw new Error "Encountered floating block at #{x}:#{y}:#{z}"
¶
Makes sure that the given coordinates are within the bounds of the map.
validateCoordinates: (x, y, z) ->
throw new Error "Index out of bounds #{x}:#{y}:#{z}" unless 0 <= x < @size and
0 <= y < @size and
0 <= z < @size
¶
Given a pair of coordinates, transforms the coordinates based on the rotation of the map.
applyRotation: (x, y) ->
switch @rotation
when 90 then return [@size - 1 - y, x]
when 180 then return [@size - 1 - x, @size - 1 - y]
when 270 then return [ y, @size - 1 - x]
else
return [x, y]
¶
Iterates over all block on the map, applies the given function.
blocksEach: (functionToApply) ->
x = @size - 1
while x + 1
y = 0
while y < @size
z = 0
while z < @size
functionToApply block if block = @getBlock(x, y, z)
z++
y++
x--
coordinatesEach: (functionToApply) ->
x = @size - 1
while x + 1
y = 0
while y < @size
z = 0
while z < @size
functionToApply(x, y, z)
z++
y++
x--
¶
Rotates the map 90 degrees clockwise
rotateCW: -> @rotate true
¶
Rotates the map 90 degrees counter-clockwise
rotateCCW: -> @rotate false
rotate: (clockwise, silent = no) ->
if clockwise
@rotation = (@rotation + 90) % 360
else
@rotation = (@rotation + 270) % 360
for block in @grid
if block
block.rotate clockwise, yes, yes, yes, yes
[x, y, z] = block.getCoordinates()
if clockwise
[x, y] = [ y, @size - 1 - x]
else
[x, y] = [@size - 1 - y, x]
block.setCoordinates x, y, z
@emit 'didRotate', clockwise unless silent
Quote from: Iridion on October 22, 2013, 10:50:44 AM
Quote from: paranoia on October 22, 2013, 10:42:44 AM
Quote from: CyberSox on October 22, 2013, 10:27:06 AM
Quote from: Purple on October 22, 2013, 10:15:34 AM
Quote from: CyberSox on October 22, 2013, 10:12:44 AM
Quote from: Purple on October 22, 2013, 09:55:10 AM
She wants a formula, not websites. I've already linked/read about 15 sites.
Those websites contain the matrices, making it easier, as you can't directly copy and paste them. But the most simple matrix for 3rd rotation:
(http://i781.photobucket.com/albums/yy91/socksphotos/NewPicture_zpscc8ff08a.png)
Where , (phi), and (psi) are the rotations around the X, Y and Z axes.
"...and noone in BC is either smart enough, or willing to go further than finding a page and telling me to figure it out from there"
- Allie 2013
I don't see any reason why I should listen to you. Stop pretending you're Allie's little sidekick, and going off topic. All I see you doing on this forums is being negative about others while not doing anything useful yourself. Back on topic, it's clear you haven't even clicked on the website, it contains a few of the required matrices to do the rotation. She asked for help, and that's the formula. She has to plug in her own values for Theta, Phi and Psi.
There are different formulas for different modeling/game languages such as python, assembly, java, c, c++, etc. There not all the same, however I do commend you on showing her the websites you have offered( considering there pretty good/useful) It probably wont help her in this situation. Allie should have posted the current axis of the model to make it much easier.
a formula is a formula
2+2 is the same thing in every language
however that is true there is a lot of difference within each programming language.
@rebuck
I think Allie is looking for something she can just copy paste, so you should remove the texts within each line.
Without Text!!!class Map extends EventEmitter
constructor: (size) ->
throw new Error "Size must be between 1 and 255" unless 1 < size < 255
@size = size
@setMaxListeners 2
@grid = new Array Math.pow(@size, 3)
for x in [0...Math.pow(@size, 3)]
@grid
- = null
@rotation = 0
map = @
@blockDidChangeListener = ->
map.emit 'didChange'
@emit 'didChange'
forceUpdate: ->
@emit 'didChange'
setBlock: (block, x, y, z, silent = no) ->
@validateCoordinates x, y, z
block.setCoordinates x, y, z if block
[x, y] = @applyRotation x, y if @rotation
position = x + y * @size + z * @size * @size
@grid[position]?.removeListener 'didChange', @blockDidChangeListener
@grid[position] = block
@grid[position]?.addListener 'didChange', @blockDidChangeListener
@emit 'didChange' unless silent
getBlock: (x, y, z) ->
@validateCoordinates x, y, z
[x, y] = @applyRotation x, y if @rotation
return @grid[x + y * @size + z * @size * @size]
removeBlock: (x, y, z, silent = no) ->
block = @getBlock x, y, z
@setBlock null, x, y, z, yes
block?.removeListener 'didChange', @blockDidChangeListener
block?.setCoordinates null, null, null
@emit 'didChange' unless silent
return block
heightAt: (x, y) ->
@validateCoordinates x, y, 0
height = 0
while height < @size and @getBlock x, y, height
height++
return height
getStack: (x, y, z = 0) ->
@validateCoordinates x, y, z
return [] if z > height = @heightAt x, y
blocks = new Array
for currentZ in [z...height]
blocks.push @getBlock x, y, currentZ
return blocks
setStack: (blocks, x, y, z = 0, silent = no) ->
@validateCoordinates x, y, z
unless blocks.length - 1 + z < @size
throw new Error "Cannot place stack, height out of bounds"
for block in blocks
@setBlock block, x, y, z++, yes
@emit 'didChange' unless silent
removeStack: (x, y, z = 0, silent = no) ->
stack = @getStack x, y, z
for currentZ in [z...z + stack.length]
@setBlock null, x, y, z++, yes
@emit 'didChange' unless silent
return stack
validate: ->
@blocksEach (block) =>
[x, y, z] = block.getCoordinates()
if block and z > 0 and not @getBlock x, y, z - 1
throw new Error "Encountered floating block at #{x}:#{y}:#{z}"
validateCoordinates: (x, y, z) ->
throw new Error "Index out of bounds #{x}:#{y}:#{z}" unless 0 <= x < @size and
0 <= y < @size and
0 <= z < @size
applyRotation: (x, y) ->
switch @rotation
when 90 then return [@size - 1 - y, x]
when 180 then return [@size - 1 - x, @size - 1 - y]
when 270 then return [ y, @size - 1 - x]
else
return [x, y]
blocksEach: (functionToApply) ->
x = @size - 1
while x + 1
y = 0
while y < @size
z = 0
while z < @size
functionToApply block if block = @getBlock(x, y, z)
z++
y++
x--
coordinatesEach: (functionToApply) ->
x = @size - 1
while x + 1
y = 0
while y < @size
z = 0
while z < @size
functionToApply(x, y, z)
z++
y++
x--
rotateCW: -> @rotate true
rotateCCW: -> @rotate false
rotate: (clockwise, silent = no) ->
if clockwise
@rotation = (@rotation + 90) % 360
else
@rotation = (@rotation + 270) % 360
for block in @grid
if block
block.rotate clockwise, yes, yes, yes, yes
[x, y, z] = block.getCoordinates()
if clockwise
[x, y] = [ y, @size - 1 - x]
else
[x, y] = [@size - 1 - y, x]
block.setCoordinates x, y, z
@emit 'didRotate', clockwise unless silen
Now I get a price :o ??
Quote from: Xx Itz Ian on October 22, 2013, 01:20:38 PM
Quote from: Iridion on October 22, 2013, 10:50:44 AM
Quote from: paranoia on October 22, 2013, 10:42:44 AM
Quote from: CyberSox on October 22, 2013, 10:27:06 AM
Quote from: Purple on October 22, 2013, 10:15:34 AM
Quote from: CyberSox on October 22, 2013, 10:12:44 AM
Quote from: Purple on October 22, 2013, 09:55:10 AM
She wants a formula, not websites. I've already linked/read about 15 sites.
Those websites contain the matrices, making it easier, as you can't directly copy and paste them. But the most simple matrix for 3rd rotation:
(http://i781.photobucket.com/albums/yy91/socksphotos/NewPicture_zpscc8ff08a.png)
Where , (phi), and (psi) are the rotations around the X, Y and Z axes.
"...and noone in BC is either smart enough, or willing to go further than finding a page and telling me to figure it out from there"
- Allie 2013
I don't see any reason why I should listen to you. Stop pretending you're Allie's little sidekick, and going off topic. All I see you doing on this forums is being negative about others while not doing anything useful yourself. Back on topic, it's clear you haven't even clicked on the website, it contains a few of the required matrices to do the rotation. She asked for help, and that's the formula. She has to plug in her own values for Theta, Phi and Psi.
There are different formulas for different modeling/game languages such as python, assembly, java, c, c++, etc. There not all the same, however I do commend you on showing her the websites you have offered( considering there pretty good/useful) It probably wont help her in this situation. Allie should have posted the current axis of the model to make it much easier.
a formula is a formula
2+2 is the same thing in every language
however that is true there is a lot of difference within each programming language.
@rebuck
I think Allie is looking for something she can just copy paste, so you should remove the texts within each line.
but each formula in each programming language has its "normal" version and thats what allie probably wants
for example |x| is done differently in c or vb.net but in both ways it is |x|
class Map extends EventEmitter
constructor: (size) ->
throw new Error "Size must be between 1 and 255" unless 1 < size < 255
@size = size
@setMaxListeners 2
@grid = new Array Math.pow(@size, 3)
for x in [0...Math.pow(@size, 3)]
@grid
= null
@rotation = 0
map = @
@blockDidChangeListener = ->
map.emit 'didChange'
@emit 'didChange'
forceUpdate: ->
@emit 'didChange'
setBlock: (block, x, y, z, silent = no) ->
@validateCoordinates x, y, z
block.setCoordinates x, y, z if block
[x, y] = @applyRotation x, y if @rotation
position = x + y * @size + z * @size * @size
@grid[position]?.removeListener 'didChange', @blockDidChangeListener
@grid[position] = block
@grid[position]?.addListener 'didChange', @blockDidChangeListener
@emit 'didChange' unless silent
getBlock: (x, y, z) ->
@validateCoordinates x, y, z
[x, y] = @applyRotation x, y if @rotation
return @grid[x + y * @size + z * @size * @size]
removeBlock: (x, y, z, silent = no) ->
block = @getBlock x, y, z
@setBlock null, x, y, z, yes
block?.removeListener 'didChange', @blockDidChangeListener
block?.setCoordinates null, null, null
@emit 'didChange' unless silent
return block
heightAt: (x, y) ->
@validateCoordinates x, y, 0
height = 0
while height < @size and @getBlock x, y, height
height++
return height
getStack: (x, y, z = 0) ->
@validateCoordinates x, y, z
return [] if z > height = @heightAt x, y
blocks = new Array
for currentZ in [z...height]
blocks.push @getBlock x, y, currentZ
return blocks
setStack: (blocks, x, y, z = 0, silent = no) ->
@validateCoordinates x, y, z
unless blocks.length - 1 + z < @size
throw new Error "Cannot place stack, height out of bounds"
for block in blocks
@setBlock block, x, y, z++, yes
@emit 'didChange' unless silent
removeStack: (x, y, z = 0, silent = no) ->
stack = @getStack x, y, z
for currentZ in [z...z + stack.length]
@setBlock null, x, y, z++, yes
@emit 'didChange' unless silent
return stack
validate: ->
@blocksEach (block) =>
[x, y, z] = block.getCoordinates()
if block and z > 0 and not @getBlock x, y, z - 1
throw new Error "Encountered floating block at #{x}:#{y}:#{z}"
validateCoordinates: (x, y, z) ->
throw new Error "Index out of bounds #{x}:#{y}:#{z}" unless 0 <= x < @size and
0 <= y < @size and
0 <= z < @size
applyRotation: (x, y) ->
switch @rotation
when 90 then return [@size - 1 - y, x]
when 180 then return [@size - 1 - x, @size - 1 - y]
when 270 then return [ y, @size - 1 - x]
else
return [x, y]
blocksEach: (functionToApply) ->
x = @size - 1
while x + 1
y = 0
while y < @size
z = 0
while z < @size
functionToApply block if block = @getBlock(x, y, z)
z++
y++
x--
coordinatesEach: (functionToApply) ->
x = @size - 1
while x + 1
y = 0
while y < @size
z = 0
while z < @size
functionToApply(x, y, z)
z++
y++
x--
rotateCW: -> @rotate true
rotateCCW: -> @rotate false
rotate: (clockwise, silent = no) ->
if clockwise
@rotation = (@rotation + 90) % 360
else
@rotation = (@rotation + 270) % 360
for block in @grid
if block
block.rotate clockwise, yes, yes, yes, yes
[x, y, z] = block.getCoordinates()
if clockwise
[x, y] = [ y, @size - 1 - x]
else
[x, y] = [@size - 1 - y, x]
block.setCoordinates x, y, z
@emit 'didRotate', clockwise unless silen