Hi,
(especially Zhaltkis and Theodox)
I have done this script of Rubik’s cube game in max. I am doing this like selecting the cubes on position basis, and rotating them by picking the directions arrow objects. It works good for the first time and in a weird way from the second time onwards i think. I think the center cube of the selected array is rotated by 90 in y axis. Or some thing else… any suggestions to fix the problem.
the code goes like this
Undo off
Rollout rubixCube "Rubix Cube"
(
local objs_ifCol = #()
local objs_ifRow = #()
local objs_ifCol_Y = #()
----- UI Elements -----
group "Instructions"
(
label msg "Click on any cube and"
label msg1 "click on Arrow Objects to rotate"
)
group "Direction"
(
radiobuttons vnh labels:#("Vertical", "Horizontal")
)
group "Rotation Direction"
(
pickbutton pickbtn "Pick directional arrow"
)
----- Colors for the cubes --------
local colArr = #(red,green,blue,black,white,orange)
----- Creating The Rubix Cube -----
fn rubixCub =
(
for i=0 to 2 do
(
for j = 0 to 2 do
(
for k = 0 to 2 do
(
local cuBox = box width:15 length:15 height:15
cuBox.pos = [i*15,j*15,k*15]
cuBox.material = meditMaterials [1]
convertTopoly cuBox
polyop.chamferEdges cuBox #{1..12} 0.25
centerpivot cuBox
)
)
)
rubCubMat = meditMaterials [1] = multiMaterial numsubs:6 -- Assigning Multi Sub Object Material
for i =1 to rubCubMat.numsubs do
(
rubCubMat.material[i].shaderType = 0
rubCubMat.material[i].diffuse = colArr[i]
rubCubMat.material[i].specularLevel = 50
rubCubMat.material[i].glossiness = 60
)
select $*
$.material = rubCubMat
/*objForRot = for o in selection collect o
(
for i = 1 to objForRot.count do
(
rotate objForRot[i] (angleAxis (i*90)[1,0,0])
)
)*/
group selection name:"cubGrp"
$cubGrp.pos = [0,0,20]
ungroup $cubGrp
deselect $*
)
fn dirArrows =
(
for i in 0 to 3 do
(
arws= helix radius1:5 radius2:0 height:15 prefix:"Arw_" turns:10 sides:3
arws.pivot = [0,0,0]
arws.render_displayRenderMesh = true
arws.Thickness = .5
move arws [0,60,20]
in coordsys world arws.rotation = (eulerAngles 0 0 (i*90))
in coordsys local arws.rotation = (eulerangles 90 0 0)
)
)
fn SelCubes =
(
if ($ != undefined) then
(
selobjX = $.pos.x
selobjY = $.pos.y
selobjz = $.pos.z
objs_ifRow = for o in geometry where o.pos.z == selobjZ collect o
objs_ifCol = for o in geometry where o.pos.x == selobjX collect o
objs_ifCol_Y= for o in geometry where o.pos.y == selobjY collect o
)
else messagebox "Please Select a cube"
)
on rubixCube open do
(
rubixCub ()
dirArrows ()
)
on pickbtn picked obj do
(
SelCubes()
case vnh.state of
(
1:(
if ($Arw_001 == obj) then
(
select objs_ifCol
in coordsys world rotate objs_ifCol (angleAxis 90 [-1,0,0])
deselect $
)
if ($Arw_003 == obj) then
(
select objs_ifCol
in coordsys world rotate objs_ifCol (angleAxis 90 [1,0,0])
deselect $
)
if ($Arw_002 == obj) then
(
select objs_ifCol_Y
in coordsys world rotate objs_ifCol_Y (angleAxis 90 [0,1,0])
deselect $
)
if ($Arw_004 == obj) then
(
select objs_ifCol_Y
in coordsys world rotate objs_ifCol_Y (angleAxis 90 [0,-1,0])
deselect $
)
)
2:(
if ($Arw_001 == obj) then
(
select objs_ifRow
in coordsys world rotate objs_ifRow (angleAxis 90 [0,0,1])
deselect $
)
if ($Arw_003 == obj) then
(
select objs_ifRow
in coordsys world rotate objs_ifRow (angleAxis 90 [0,0,-1])
deselect $
)
if ($Arw_002 == obj) then
(
select objs_ifRow
in coordsys world rotate objs_ifRow (angleAxis 90 [0,0,1])
deselect $
)
if ($Arw_004 == obj) then
(
select objs_ifRow
in coordsys world rotate objs_ifRow (angleAxis 90 [0,0,-1])
deselect $
)
)
)
)
on rubixCube close do
(
delete objects
)
)
createDialog rubixCube width:200