use Math, Strings, Editor, Windows
use D3D11, Camera, Light, Color, Material, Shape
design ShapeWithAction(MeshClass cppMesh) like SharedMesh( cppMesh ) is
var function FrameAction (word Interval) to do
on NewFrame(word Interval) do
FrameAction( Interval )
end
on RandomRotation do
body FrameAction with
float AngularSpeed = randf() * 0.05
xyz Axis = norm( [randf(),randf(),randf()] )
matrix4 RotationMatrix = Rotate.Axis( Axis , AngularSpeed)
end
is
WorldMatrix = RotationMatrix * WorldMatrix
end
end
on Rotate( xyz Axis, float Speed) do
body FrameAction with
matrix4 RotationMatrix = Rotate.Axis( Axis, Speed )
end
is
WorldMatrix = RotationMatrix * WorldMatrix
end
end
on Spin( xyz Axis, float Speed ) do
body FrameAction with
matrix4 Spin = Rotate.Axis( Axis, Speed )
end
is
WorldMatrix = WorldMatrix * Spin
end
end
on RadialMove( float Factor) do
body FrameAction
keep Factor
is
WorldMatrix.c14 = WorldMatrix.c14 * Factor
WorldMatrix.c24 = WorldMatrix.c24 * Factor
WorldMatrix.c34 = WorldMatrix.c34 * Factor
end
end
on RandomRadialMove do
body FrameAction with
float Factor = 1 + randf()*0.01
end
is
WorldMatrix.c14 = WorldMatrix.c14 * Factor
WorldMatrix.c24 = WorldMatrix.c24 * Factor
WorldMatrix.c34 = WorldMatrix.c34 * Factor
end
end
on NewRandomMaterial do
MatSpec = Material.random()
end
end
design CubeOfCubes(int NrOfCubes ) is
float Rib = 3
float Sep = 7
float CubeSpace = Rib + Sep
Mesh.Cube CubeMesh
CubeMesh.Build()
matrix4 WorldMatrix = [
Rib, 0, 0, 0,
0, Rib, 0, 0,
0, 0, Rib, 0,
0, 0, 0, 1
]
for i = 0 to NrOfCubes-1, j = 0 to NrOfCubes-1, k = 0 to NrOfCubes-1 do
create ShapeWithAction(CubeMesh.cppMesh) <- SetWorldMatrix( WorldMatrix ) , Move([i*CubeSpace, j*CubeSpace, k*CubeSpace]),SetMaterial( Material.random() )
end
on ? => all <- (same)
end
design World is
cell Camera
cell Light
cell Window
cell Timer
CanvasWindowClass CameraWindow
Hwnd CameraWindowHandle
RectangleType Rectangle
float zz
cell Log
word FrameCount=0
cell Scene
constructor is
xyz From = [100,150,250]
xyz To = [0,0,0]
Window = create MenuWindow("Rotating Cubes")
system <- stdout.Set( Window )
Camera = create FromTo(From,To)
Rectangle = [900,0,2500,1200]
CameraWindow = CameraWindow.Create("Camera",&Rectangle, 0, 0,null )
CameraWindow.SetCamera(Camera)
Light = create Directional( Color.White*0.7, Color.White*0.7, Color.White*0.7, [1,1,-1] )
Scene = create CubeOfCubes( 10 )
Camera <- SetWindow(CameraWindow), SetLight(Light), SetScene( Scene )
system <- Service.Get("Timer")
Camera <+- Roll
Window <- print("\nScene was created - Camera = [Camera] and Light = [Light] ")
end
on Roll.DN do
Window <- print("\nReceived Delivery Notification from Camera [sender]")
end
on Service.Provider( ansi Name, cell Provider) do
Name is "Timer" ? Timer = Provider : yield
Scene <- Rotate([1,1,1],0.005)
Timer <- Subscribe.Interval(2500w,"ChangeAction")
end
int Count = 0
on ChangeAction( word Time) do
system <- println("[Time/1000] seconds: change to action [Count%7]")
switch Count%7
case 0: Scene <- RandomRadialMove
case 1: Scene <- Rotate( [1,0,0], 0.02 )
case 2: Scene <- RandomRotation
case 3: Scene <- Spin([1,1,1], 0.25)
case 4: Timer <- Subscribe.Relative(250w,"Color.Red")
Timer <- Subscribe.Relative(500w,"Color.Green")
Timer <- Subscribe.Relative(750w,"Color.Blue")
Timer <- Subscribe.Relative(1000w,"Color.Random")
case 5: Scene <- RadialMove(0.995)
case 6: Scene <- Rotate( [0,1,0], 0.1 )
end
Count += 1
end
interface Color is
on Red(word t) => Scene <- SetMaterial( Red )
on Blue(word t) => Scene <- SetMaterial( Blue )
on Green(word t) => Scene <- SetMaterial( Green )
on Random(word t) => Scene <- NewRandomMaterial
interface end
end