I'm trying to make a 3D rotating shape with a hexagon top (and bottom) and square sides, out of several pictures that I have.
I've managed to get the basic object built but it doesn't pivot around the centre, rather it swings out to one side. Try as I might, I just can't seem to find what code to alter to get it central!
The code is as follows...
global gCorners, gCentre, gRectList, gRotate, gPlane
on startMovie
--initialise lists for shape
initBox
end
on frameScript
gRotate = gRotate - (float(40)/30)*pi()/100
gPlane = - (float(20)/30)*pi/20
drawSides
end
on initBox
--list of corners with x,y and z coordinates
--original corners
corner1 = [-200,-100,-200]
corner2 = [100,-100,-200]
corner3 = [100,100,-200]
corner4 = [-200,100,-200]
--extra corners for making hex top
corner5 = [-100,-300,-200]
corner6 = [-100,300,-200]
--first square drop-down side
corner7 = [-100,300,100] --based on corner5
corner8 = [-100,-300,100] --based on corner6
--second square drop-down side
corner9 = [-200,-100,100] --based on corner1
--third square drop-down side
corner10 = [100,-100,100] --based on corner2
--fourth square drop-down side
corner11 = [100,100,100] --based on corner3
--fifth square drop-down side
corner12 = [-200,100,100] --based on corner4
--new corners for testing
gCorners = [corner1,corner2,corner3,corner4,corner5,corner6,corner7,corner8,corner9,corner10,corner11,corner12]
--the screen centre
gCentre = point(400,350)
--list of sides
gRectList = [[1,2,3,4],[1,5,6,4],[5,6,7,8],[1,5,8,9],[9,10,2,1],[2,3,11,10],[3,4,12,11],[4,6,7,12]]
end
on drawSides
--generate a list of screen points and depths based on the gCorners
--list and the transformation to 2d screen coordinates
list = []
repeat with i = 1 to gCorners.count
temp = plotPoint(gCorners)
add list, temp
end repeat
--create a quad list that takes four points to display a side of the shape
repeat with i = 1 to gRectList.count
--get the four corners
thisRect = gRectList
--get the four screen points to draw
q = [list[thisRect[1]][2],list[thisRect[2]][2], list[thisRect[3]][2],list[thisRect[4]][2]]
--get the closest (depth) screen point
z = min(list[thisRect[1]][1],list[thisRect[2]][1], list[thisRect[3]][1],list[thisRect[4]][1])
--draw the side
sprite(i).quad = q
sprite(i).locZ = z
end repeat
end
on plotPoint objectInfo
--get x,y and z from objectInfo list
x = getAt(objectInfo,1)
y = getAt(objectInfo,2)
z = getAt(objectInfo,3)
--TRANSFORM BY ROTATION AROUND Z
--compute the radius
radius = sqrt(x*x+y*y)
--compute the angle
if x =0.0 then angle = atan(the maxInteger)
else angle = atan(float/x)
if y < 0 then angle = angle + pi()
--rotate
set angle = angle+gRotate
--compute new x,y and z
realX = radius*cos(angle)
realZ = radius*sin(angle)
realY = Z
--TRANSFORM BY ROTATION AROUND X
--compute the radius
radius = sqrt(realY*realY + realZ*realZ)
--compute the angle
if realZ = 0 then angle = atan(the maxInteger)
else angle = (atan(realY/realZ))
if realZ < 0 then angle = angle + pi()
--rotate
angle = angle - gPlane
--compute the new x,y and z
screenX = realX
screenY = radius*sin(angle)
screenZ = radius*cos(angle)
--return both z, and the x and y point
return [screenZ, point(screenX, screenY)+gCentre]
end
8 pictures are then placed in the score and it uses these to build the 3D shape. 2 pictures are used to make the hexagon shape at the top.
Can anyone even give me an idea of what bit of code I'd need to alter?
Thanks
Suzy
I've managed to get the basic object built but it doesn't pivot around the centre, rather it swings out to one side. Try as I might, I just can't seem to find what code to alter to get it central!
The code is as follows...
global gCorners, gCentre, gRectList, gRotate, gPlane
on startMovie
--initialise lists for shape
initBox
end
on frameScript
gRotate = gRotate - (float(40)/30)*pi()/100
gPlane = - (float(20)/30)*pi/20
drawSides
end
on initBox
--list of corners with x,y and z coordinates
--original corners
corner1 = [-200,-100,-200]
corner2 = [100,-100,-200]
corner3 = [100,100,-200]
corner4 = [-200,100,-200]
--extra corners for making hex top
corner5 = [-100,-300,-200]
corner6 = [-100,300,-200]
--first square drop-down side
corner7 = [-100,300,100] --based on corner5
corner8 = [-100,-300,100] --based on corner6
--second square drop-down side
corner9 = [-200,-100,100] --based on corner1
--third square drop-down side
corner10 = [100,-100,100] --based on corner2
--fourth square drop-down side
corner11 = [100,100,100] --based on corner3
--fifth square drop-down side
corner12 = [-200,100,100] --based on corner4
--new corners for testing
gCorners = [corner1,corner2,corner3,corner4,corner5,corner6,corner7,corner8,corner9,corner10,corner11,corner12]
--the screen centre
gCentre = point(400,350)
--list of sides
gRectList = [[1,2,3,4],[1,5,6,4],[5,6,7,8],[1,5,8,9],[9,10,2,1],[2,3,11,10],[3,4,12,11],[4,6,7,12]]
end
on drawSides
--generate a list of screen points and depths based on the gCorners
--list and the transformation to 2d screen coordinates
list = []
repeat with i = 1 to gCorners.count
temp = plotPoint(gCorners)
add list, temp
end repeat
--create a quad list that takes four points to display a side of the shape
repeat with i = 1 to gRectList.count
--get the four corners
thisRect = gRectList
--get the four screen points to draw
q = [list[thisRect[1]][2],list[thisRect[2]][2], list[thisRect[3]][2],list[thisRect[4]][2]]
--get the closest (depth) screen point
z = min(list[thisRect[1]][1],list[thisRect[2]][1], list[thisRect[3]][1],list[thisRect[4]][1])
--draw the side
sprite(i).quad = q
sprite(i).locZ = z
end repeat
end
on plotPoint objectInfo
--get x,y and z from objectInfo list
x = getAt(objectInfo,1)
y = getAt(objectInfo,2)
z = getAt(objectInfo,3)
--TRANSFORM BY ROTATION AROUND Z
--compute the radius
radius = sqrt(x*x+y*y)
--compute the angle
if x =0.0 then angle = atan(the maxInteger)
else angle = atan(float/x)
if y < 0 then angle = angle + pi()
--rotate
set angle = angle+gRotate
--compute new x,y and z
realX = radius*cos(angle)
realZ = radius*sin(angle)
realY = Z
--TRANSFORM BY ROTATION AROUND X
--compute the radius
radius = sqrt(realY*realY + realZ*realZ)
--compute the angle
if realZ = 0 then angle = atan(the maxInteger)
else angle = (atan(realY/realZ))
if realZ < 0 then angle = angle + pi()
--rotate
angle = angle - gPlane
--compute the new x,y and z
screenX = realX
screenY = radius*sin(angle)
screenZ = radius*cos(angle)
--return both z, and the x and y point
return [screenZ, point(screenX, screenY)+gCentre]
end
8 pictures are then placed in the score and it uses these to build the 3D shape. 2 pictures are used to make the hexagon shape at the top.
Can anyone even give me an idea of what bit of code I'd need to alter?
Thanks
Suzy