Sunday, March 16, 2008

B003-Making your first WetObject and give it a behavior

This tutorial lets you get started with wetObject and behaviors.

After this tutorial you should know:

1. How to create WetObject

2. How to alter the behavior of a wetObject by assigning behavior scripts to it



Before you continue any further, I assume you have read Mikey’s email
instruction about obtaining the code, and have downloaded the code from the
CVS repository. Also I assume you have used eclipse and java.


If you run the active_picaso project, you should see a popup window allows
you to choose different master. We will use “levitation” master
for this tutorial.


When you run with “levitation” selected as option, you should see
two boxes, one circulates around and the other looks at the moving box as it
circulates.


We are now going to look at the code of these.

1. Go to a package named “masters” and find levitation

2. Go to the method called “initialize()”


Within this method you are going to create a new box, and let this new box
also look at the circulating box.

1. create a new wetObject

(WetObject by default draws itself as a box, in this tutorial I am not going
to show how to change the appearance of wetObjects. Lets do that in another
tutorial.)

Within this method, At the end of all existing lines, add the following:


// This line creates a new WetObject instance called
o3.

WetObject o3=new WetObject();


//now add this to the scene

//the create() method adds any

//WetObjects or childrens of Wetobject into our world

o3.create();


//set the position of this wetObject

//by default it creates at (0,0,0)

o3.setPos(20,20,20);


if you run the application now, you should see three boxes instead of two.
If so, you have successfully created a wetObject


2. Make the new box look at the circulating box

We have make some simple behaviors in the package called “behaviors”.
If you are writing behaviors later on, you will be adding them to the behaviors
package.

Now we are going to assign one of the behaviors to the new box


Add this line:


o3.subscribe(new LookAtWetObject(o3,o));

if you run the application again, the new box will have a behavior which looks
at the circulating box. Don’t worry about what the arguments are at this
point.


The idea is, you are going to write different behaviors, we can subscribe multiple
behaviors to an object using the subscribe() method. And those behaviors are
what provides us different visual effects and particle dynamics


When you run you application, If you see three boxes, one circulates around
and the other two looks at it, you have completed this tutorial.


The next one is “Understand the Core of WetObject and Write a Behavior






No comments: