Island Creator/Class: TVehicle
From Croquet Consortium
This manual is part of the Consortium's Community Supported Documentation service. The views expressed in this portion of the wiki are those of some of our community members and may not represent the views of the Croquet Consortium or its other members. These wiki pages are dynamic/living documents with the support of many authors. Thanks to all the members of our community for keeping our documentation up to date!
You have learned the functions of the Class: StreamingMP3Sound . It uses .MP3 files. Now we will present some of the functions of the Class: TVehicle. It uses three types of files: _scene.OBJ, _scene.MTL and .JPG.
Functions of this Class will administrate the inclusion and movements of 3D objects inside a Cobalt island. But Cobalt implements the idea of 3D objects being scenes. When a 3D object is a scene it is glued to its Cartesian axes.
Like we did at the lesson about the Class StreamingMP3Sound, here we have also a bonus: a 3D object that can be used inside Cobalt islands. It's only a red cube having 2 ft. at each side and having its geometric center at the Cartesian position 0,0,0 not like that of the previous figure. This cube is represented by files of the type: _scene.OBJ, _scene.MTL and .JPG, inside a folder whose name is: cube2x2. Please, download and unzip, inside the Content folder of your Cobalt, the free
The functions of the Class are:
translationX:n y:n z:n Adds the values represented by "n" to the actual
position of the 3D object_Scene
translation Returns the actual position of the 3D object_Scene like a
vector of 3 elements. We call these vectors, at Cobalt: a Vector3.
translation:a Vector3 Adds the values represented by a Vector3.
The syntax for a Vector3 is something like: 99@99@99
localTransform column1*n
localTransform column2*n
localTransform column3*n "localTransform" is a kind of matrix where "column1" defines one unit
of distance (ft) in the X axis, "column2" is for one unit of distance in the
Y axis. And "column3" is for the Z axis. It's used with the previous
functions. If you like to move "cube1" 2 ft. up, you can write:
cube1 translation:cube1 translation+(cube1 localTransform column2*2).
addRotationAroundY: n-degrees
addRotationAroundX: n-degrees
addRotationAroundZ: n-degrees These functions are to rotate n-degrees (not radians) around the declared
axis, the object_Scene. Look the Fig.7-1 and try to imagine a rotation,
around the Y axis, of the two objects_Scenes. The cube WILL NOT rotate
around its geometric center.
visible:true/false The object_Scene will be present. If there are, by example,
default vertical collision, it will work...
visible Returns the boolean situation of the visibility
transparency:n The values for n are from: 0.0 to 1.0
destroy The object_Scene will be not present anymore at the island.
For the creation of a prefix for the use of any function of the Class, you need to know the path of the _scene.OBJ file and write the line of code, being, by example, "cube1", the name of the prefix:
cube1:= (OBJImporter parseFile:
(FileDirectory pathFrom:
{FileDirectory default pathName. 'Content'. 'cube2x2' .'cube2x2_Scene.obj'})scale:1) asTMesh.
Pay attention that: we can modify the scale of the 3D object at the definition of the prefix.
And now, that we know how to install 3D objects inside an island, lets go to do a practical exercice to fix the concepts.
The exercise of this lesson is:
Create an island, similar of the island of Firstalia , having our red cube at the right extreme limits of the floor of the island.
We will create a new island - the name will be: Cubenia. Obeying the SILVER RULE OF COBALT we will "copy and modify" a previous created island.
We will repeat here the steps presented at previous lesson :
The first steps when creating a new island are:
1 - Choose an island that you have at your hard disk to "copy and modify" (here will be, like we said, the Firstalia).
2 - Choose a name for YOUR new island. We will use: Cubenia.
3 - Create two new folders; one of the type Content and other of the type Squeaklets: CubeniaCT and CubeniaSQ.
4 - To the folder of contents, you need to copy the subfolders of contents of the "father" island. Here it will be: panel and spell and sounds, having, inside: .OBJ and .JPG and .MP3 files.
5 - You need to copy also, to this folder the subfolder cube2x2.
6 - The folder of squeaklets of Firstalia is empty. So, you don't need to copy anything.
7 - Opening the System Browser of the "father island" image, try to find the functions of the Classes of the category CobaltMorph-Worlds, who are calling files, and replace their paths. Remember that you need to do an "accept" when modifying an script. Here we have path modifications at:
createRegisteredMeshGroup of the Class CobaltWorld - the file: spell_Scene.obj initialize of the Class Panel - the file: panel_Scene.obj initialize of the Class CobaltWorld - the file: applause1.mp3
8 - Doing modifications, you need also to do a "big save" for the creation of a new image, whose name will be: Cubenia.image
At our exercise, you need to add the lines of code to include the 3D object. I imagine that you know how to do this. To know better how all of these things work we will, at a first time, only to load the 3D object, not defining its translation. Look the new initialize of the CobaltWorld Class:
initialize
| space floor mF sound1 cube1 |
space := TSpace new.
space registerGlobal: #mainEntry.
self makeLight: space.
floor := self makeFloor: space fileName: 'lawn.bmp'.
floor extentX: 32 y: 0 z: 32.
mF:= MainFrame new.
space addChild: mF.
self makeRegistered1: space.
sound1:= StreamingMP3Sound onFileNamed:
(FileDirectory pathFrom:
{FileDirectory default pathName. 'CubeniaCT'. 'sounds' .'applause1.mp3'}).
sound1 play.
cube1:= (OBJImporter parseFile:
(FileDirectory pathFrom:
{FileDirectory default pathName. 'CubeniaCT'. 'cube2x2' .'cube2x2_Scene.obj'})scale:1) asTMesh.
space addChild: cube1.
^space.
Here we have something new. We are adding the cube to the "space" of the island. So, we have the line:
space addChild: cube1.
using the prefix for the Class TSpace and its function addChild (we will see all the functions of this important Class soon).
Remember to do an accept. You can open the island from time to time to see if all is OK. Remember also to close the System Browser before the final "big save".
Look the Fig.7.2 to see what we have, after these modifications:
TIP: To have the camera at this "bird-eye" position, the avatar (beeing a Normal Visitor) needs to be outsite the limits of the floor, and you press the arrow keys to go up or down.
A scene-object is "installed" always at the position 0,0,0 of the island. Pay attention to de detail: the default floor of a Cobalt island is at Y=-6 and not at Y=0.
Like our cube has its Cartesian axis at its geometric center (not like that of the Fig. 7-1) we have the situation of the last figure.
We have define the floor of the island of Firstalia having the dimensions 32x32 ft. The extreme right point will be: 16,-6,-16.
Like the cube has 2 ft at each side, the line of code for its translation needs to be:
cube1 translationX: 15 y:-5 z:-15.
And, "WOW !", the cube is at the correct place:
OBSERVATIONS: We have not defined horizontal collision to the cube. So: the avatar, even beeing a "Registered Visitor", will cross it.
The "island of Cubenia" is a Cobalt "multiplayer" island. If you have an WiFi environment, you can test it, following the orientations of the previous lesson.
