At this step, we will spin the background cube . This application is implemented by modifying the result of previous step. This page introduces the periodic timer geometry in secnes to add motions in 3D applications.
Following is the result of this step. Try “RUN”. You can see spinning cube at the background of the green “HELLO WOLRD” text. Break button stops this application.
STEP 3-1. Loading previous application.
Load the result of Page 0030 thru LOAD/SAVE tab. How to load is decribed in STEP 2-1 in Page 0020
STEP 3-2. Add Timer Geometry in the scene AppMain
Selecting “GEO EDITOR” tab on the top of VPGL UI displays 3D Geometry Editor, then switch SCENE to “AppMain” created in Page 0030, And “Add New Item” menu from “Select Ops”
Choosing “Add New Item” displays a modal dialog to specify the name of the new item. We will name it to “Tact”, then touch OK button.
Now the new item “Tact” is created as a blue cube. But we can change this item to a Timer geometry item by changing it Box to Timer in TYPE Menu. At first, comfirm the SCENE is AppMain and ITEM is Tact, then chenge the value of TYPE Menu to “timer”, then finally set its INTERVAL as 100 (milliseconds). The Check Box “Off” should be unchecked.
STEP 3-3 Set up to capture the timer event.
Now the timer Tact raise “tick” event in 100ms interval in Running this application, but no one responds to it so no motion appears, because no set up is done. This step sets capturing this event up.
To do this, we will make it the new method “INIT” for App class. INIT will be invoded from Mainline method of App Class which is kicked by RUN button. In other words, touching RUN button will make a instance of a App Class, then send “Mainline” message to created one.
Anyway, to create INIT method, (1) Choose display the class “App”, then (2) Touch (single click/tap) the “NEW METHOD” button.
Touching it pops the follwing dialog. Then specfies the new method name, grid size of this method, input/output directions. In this case, We will set them to: (1) The method name is “INIT”, (2) 3×3 tiles grid, (3) Take only 1 input from “T” (Top), (4) Emit 1 output to “B” Bottom.
Finally, touch “Add Method” button to make the method and close this dialog.
After that you can see the 3×3 blank Grid as the defintion of INIT method of App Class. Draw the diagram of INIT definition as follows with reffer to “Editting grid tile” page if you needed.
In this diagram the option of GEO at position A2 is
{ ‘Scene’: ‘AppMain’ ‘Geo’: ‘Tact’}
And the option of ATTATH at B2 is :
{ ‘evt’: ‘OnTick’ ‘msg’: ‘OnTick’ }
This diagram set application so that the ‘OnTick’ method to this application (the instance of App class) is invoked when ‘OnTick’ event (timer ticks) from Tact in the AppMain scene.
STEP 3-4 Define OnTick Method
The next step is make definition of OnTick method in App Class which is invoked by OnTick event set by INIT. This will increase +0.1 radian to the value “roty” of BlueBox in AppMain sceen. It will spinthe box around the y-axis of the box, not around the y-axis of global cordinate system as you can see above. Spinning axis is tilted 45 degrees to our view.
After making OnTick method on the App Class with 7×7 grid size, draw the diagram as follows:
Where the option of GEO at C2 is:
{ ‘Scene’: ‘AppMain’ ‘Geo’: ‘BlueBox’}
OnTick will (1) read the value of “roty” of BlueBox in AppMain Scene, (2) adds 0.1 to it, (3) write the result back to “roty” property of BlueBox, (4) then updates (redisplays) the world.
STEP 3-5 Rewrite Mainline to invode INIT
The final step of construction is rewriting Mainline method like this:
Where the opion of SETSCN at D3 is
“AppMain”
The new Mainline method is invoke INIT at first to set up the event handling so that OnTick method will be invoked by OnTick event is fired, then set viewing world as the AppMain scene, the display the world (specified as AppMain).
STEP 3-6 Try Application
After save your work, try “RUN” button. You’ve got a success if you can see the same result as the example at the top of this page.
STEP 3-7 Go to Part 2
Currently the spinning axis is tilted against global vartical y-axis (up-down direction). Spinning around the vartical axis would be nice. But it’s not so easy.
Next Step is solving it by introducing “importing” scene technique.