Example: Transforming a Surface

The following example steps through the process of creating a surface object and all of the supporting objects necessary to display it.

Example Code
The procedure file test_surface.pro, located in the examples/doc/objects subdirectory of the IDL distribution, contains this example's code. Run this example procedure by entering test_surface at the IDL command prompt or view the file in an IDL Editor window by entering .EDIT test_surface.pro.

When creating this procedure, we allow the user to specify keywords that will return object references to the view, model, surface, and window objects. This allows us to manipulate the objects directly from the IDL command line after the procedure has been run.

Play with the example to learn how object transformations work and interact. Try the following commands at the IDL prompt to observe what they do:

First, compile test_surface.pro:

.RUN test_surface.pro 

Now, execute the procedure. The variables you supply via the SURFACE, MODEL, VIEW, and WINDOW keyword will contain object references you can manipulate from the command line:

test_surface, VIEW=myview, MODEL=mymodel, $ 
   SURFACE=mysurf, WINDOW=mywin 

This will create a window object and display the surface. Now try the following to translate the object to the right:

mymodel->Translate, 0.2, 0, 0 

The model transformation changes as soon as you issue this command. The window object, however, will not be updated to reflect the new position until you issue a Draw command:

mywin->Draw, myview 

Try a rotation in the y direction:

mymodel->Rotate, [0,1,0], 45 
mywin->Draw, myview 

Repeat the commands several times and observe what happens.

Try some of the following. Remember to issue a Draw command after each change in order to see what you have done.

mymodel->Scale, 0.5, 0.5, 0.5 
mymodel->Scale, 1, 0.5, 1 
mymodel->Scale, 1, 2, 1 
mymodel->Rotate, [0,0,1], 45 
mysurf->SetProperty, COLOR = [0, 255, 0] 
myview->SetProperty, PROJECTION = 2, EYE = 2 
myview->SetProperty, EYE = 1.1 
myview->SetProperty, EYE = 6