DANCING SPHERES. TIME-STEP LOOP

Look! You and Alice are looking to a 2D image of the Earth.

If you have the Flash plugin you can see a 2D animation of the Earth.It's a better level of "reality" and interaction.(Our spaceship is a little unstable...)

If you have Croquet you can see the Earth rotating in a 3D space! You can change your point-of-view. You can go near to the Earth. Etc. Etc. A better, much better level of "reality" and interaction.

If you are working for the NASA like an astronaut you can... OK... Forget... Back to the Earth and to our lesson.

We will learn here how to create programs for continuous 3D animations in Croquet.

First of all, download this new piece:

scalableSphere.ase - in the folder scalableSphere

scalableSphere.jpg - in the subfolder Textures

Like you saw in the previous lesson, you can create many other pieces using this "standard piece", changing the texture. Here we have a new resource. Defining the tframe inside the "initialize" method you can change the "scale" for different values to have different sizes of the sphere:

...
 
tframe := (TLoad3DSMax new initializeWithFileName: 
	   (FileDirectory pathFrom:
            {FileDirectory default pathName.  'Content'.   'name-of-the-piece'. 'scalableSphere.ase'}) 
	   scale: 0.1  shadeAngle: 90.1 textureMode: GLReplace) frame. 
...

The main subject of this lesson is to talk about the : time-step-loop. The TGroup Class has a method stepAt: currentTime that creates a continuous loop. You can override this method writing inside it statements that will be executed at each "time-step" - a time interval that depends of the framerate.

Lets present an example. We would like to rotate our "scalableSpehere", the Earth.

We, like ever needs to create a new Class. It will have the usual 3 "basic methods".

And the new method will be:

stepAt: currentTime

tframe addRotationAroundY: 1.

CODE COMMENTS

But this new method and statement is not enought to do our sphere to dance. There are two main staments to control the "time-step-loop" (we have here two methods of the Class TGroup/TFrame):

self startStepping.

self stopStepping.

In some cases you can put these statements to be triggered by keyboard keys, but, here, we would like that our sphere have a continuous movement. So, we will use only the startStepping inside the initialize method of the Class:

initialize

super initialize.
tframe := (TLoad3DSMax new initializeWithFileName: 
	   (FileDirectory pathFrom:
            {FileDirectory default pathName.  'Content'.   'scalableSphere'. 'scalableSphere.ase'}) 
	   scale: 0.1  shadeAngle: 90.1 textureMode: GLReplace) frame.
tframe collapse.
tframe boundsDepth: 3.
tframe initBounds.
self addChild: tframe.
tframe objectOwner: self.
inControl := false.
self startStepping.

Very easy. If you like, you can put also the method keyDown: pointer in the Class to move the sphere in "execution time". But remember that for objects having "actions" the clone creation doesn't works.

The exercice for you is the creation of 3 planets:

You need to download the textures:

planet1.jpg

planet2.jpg

TIP: You will not use these names for the textures...

Look the "photo-album" of the exercice:




PREVIOUS LESSON NEXT LESSON
T. CONTENTS HOMEPAGE

DISCLAIMER: This material can be translated for any language, and reproduced total or partially by anybody using any type of media. But, please, don't put your name like author. And let me know if it was useful (americo@dmu.com).The use of any code, 3D model or technique published is free and doesn't need to have any reference about this source.The author is not responsible for any damage that the material can cause to your professional or sexual life.