CREATING 3D SPACES

Java programers will be happy now because we will use, for this lesson, another technique of Squeak-Croquet programming: the creation of subclasses, adding some new functions to them or "overriding" - writing another having the same name - some functions that we would like to change.

Purists and fundamentalists of OOP (Object Oriented Programming) will be ungry with me because I will not use its more important concept that is the creation of many little modular classes that can be reused in the future. We will use OOP a little like any old structured language and, for us, a Class will be, many times, a complete application that will be executed when "instantialized" in the Workspace. Or something that can used by more code created inside the Workspace (like we have used some Classes at the previous lesson).

Squeak-Croquet has a tool for the creation of subclasses. You can open it - you need to create first a new morph-project, please - using the "green window":

The "Package Browser" has 5 lists on top but the important are: the 3th (Classes) and the last (functions of a selected Class). The other are only used for organize better our work. By example, the subclasses we will use at this course will be organized in a new: category (the first level of the Package Browser organization) whose name will be: "DMU course". Remember that this is irrelevant for the code.

In the first list, find and click: Croquet. In the 2nd list, find and click: Morphic. In the 3th list (realy the important) we find the name of some Croquet Classes. Click: SampleTeapotMorph.

In the bottom window, redefine the name of the subclass and the category. We are creating a new Class: BasicSpace (subclass of TeapotMorph) were we will have, by definition, available, using the prefix/object: self, all the functions of this Class TeapotMorph (we will see who they are) and we can "override" (write another function having the same name) if we like to modify any function existent (we will do it soon). And, of course, we can create new functions for OUR Class.

Rightclicking the window, we do the usual accept.

At this moment is created our new cathegory and our new Class.

All OOP language has the concept of "constructor methods". They are (sometimes only one) methods/functions executed automaticaly when the Class is instancialized.

In Squeak-Croquet if you create a function having the name: initialize it will be a constructor method.

The Class TeapotMorph has also the constructor: initializeDefaultSpace. Go back clicking: Croquet-Morph-TeapotMorh and try to find this function in the last list. Clicking it, you will see, in the bottom window, the code of the function:

WOW! It's too much for our BASIC space! We will override this function.

Back to "DMU course-BasicSpace", click in: -all- (4th list).

In the bottom window, replace the skeleton by our code:

initializeDefaultSpace

| space win lf  |
"Create a new space"
space := TSpace new.
"Make a light"
self makeLight: space.
"Make a floor"
self makeFloor: space fileName:'lawn.BMP'.
^space. 

CODE COMMENTS:

Oops! Don't forget to do an accept. Will appear a little window where you put some initials that will define that this code is YOURS.

Now, open a Workspace (you have learned how to do it in previous lesson) and type in it the code:

| win lf | 
bs:= BasicSpace new. 
win:=   SystemWindow new.
lf:= LayoutFrame new.
lf leftFraction:0.
lf rightFraction:1.
lf topFraction:0.
lf bottomFraction:1.
win setLabel: 'Hello Space!'.
win addMorph: bs fullFrame:lf.
win openInWorldExtent: 300@150.
bs requestInitialSpace.  

CODE COMMENTS:

Run the code of the Workspace with the usual: accept and do it.

Mama mia! We have a Croquet space here! Congratulations, you did your first Croquet space!

We will talk more about how to use this space in the next lesson.

Like you have created a new class or function you need to do a "big save":

The Squeak-Crocket will be closed. In the next time you open it, you will see this project first. Like this is how we create a new "main page"(?) for our Squeak-Croquet system: opening, saving-and-quiting a project that will make links (now can be 3D links/portals) to all the others (we will talk more about this later). To return to the old "main page", click in any place to open our old friend, the "World" window, where you click: previous project. If you like to have again this "project" created by the Croquet developers like your "main page", do other "save-and-quit".


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.