38 lines
1.1 KiB
Plaintext
38 lines
1.1 KiB
Plaintext
import "mathUtil"
|
|
scale = 20
|
|
|
|
img = file.loadImage("/sys/pics/shapes/SquareThin.png")
|
|
clear; gfx.clear color.gray
|
|
|
|
// Rotate the given [x,y,z] point by some number of degrees
|
|
// around the Y axis, then project to the screen.
|
|
rotateAndProject = function(point3d, rotDegrees)
|
|
radians = rotDegrees * pi/180
|
|
cosAng = cos(radians); sinAng = sin(radians)
|
|
// First, rotate around the Y axis in 3D space
|
|
x = point3d[0] * cosAng - point3d[2] * sinAng
|
|
y = point3d[1]
|
|
z = point3d[0] * sinAng + point3d[2] * cosAng
|
|
// Then, project this to the screen
|
|
result = [480 + x * scale, 320 + y * scale]
|
|
p = (80 - z) / 80 // (perspective factor)
|
|
return mathUtil.lerp2d(result, [480,800], 1-p)
|
|
end function
|
|
|
|
addFace = function(points3d, tint)
|
|
sp = new Face
|
|
sp.image = img
|
|
corners = []
|
|
for p in points3d
|
|
corners.push rotateAndProject(p, -45)
|
|
end for
|
|
sp.setCorners corners
|
|
sp.tint = tint
|
|
display(4).sprites.push sp
|
|
end function
|
|
|
|
w = 3; h = 2; d = 4
|
|
addFace [[-w,-h,-d],[w,-h,-d],[w,h,-d],[-w,h,-d]], color.lime
|
|
addFace [[w,-h,-d],[w,-h,d],[w,h,d],[w,h,-d]], color.aqua
|
|
addFace [[-w,h,-d],[w,h,-d],[w,h,d],[-w,h,d]], color.pink
|