Applying Standard Transformations

Note: This is a continuation of the "Manipulating The Box - First Steps in MAXScript" tutorial's previous lessons "Drawing a Box with MAXScript" and "Modifying the Box". It requires the variable mybox to be already defined and containing an instance of a Box primitive. If you are not continuing directly from these previous lessons, you must at least evaluate the line
mybox = box()

in order to apply the following examples to the 3ds Max scene.

Now that you know how to create and modify the basic properties of a box, you need to learn how to apply the standard transformations (move, scale, and rotate) to it. It is possible to designate position, size, and orientation when the box is created; however, you can also carry out these operations after you have created your object, just as you would in 3ds Max.

Moving the Box

Moving an object in MAXScript is very simple:

move name_obj [<x,y,z>]

where name_objis the name of the object you want to move and <x,y,z> is the amount you want it to move.

It is important to note that you are not moving the object to <x,y,z>, but by the amounts <x,y,z>.

Therefore, if you apply the move function more than once, the object continues to move. This is also true for the scale and rotate transforms.

This is in contrast to setting a property of an object. If you set the object position, scale, and rotation properties several times, the object won’t change, assuming that you assign the same value each time.

FOR EXAMPLE:

   mybox.pos = [10,0,0]
   mybox.pos = [10,0,0]
   mybox.pos = [10,0,0]

will only change the position of your box after the first line is executed.

The second and third lines do not affect the position of your box, as they do not change the absolute position of the box:

If you entered the above three commands, click Undo three times to move the box back to its original position.

ON THE OTHER HAND, ENTERING

   move mybox [10,0,0]
   move mybox [10,0,0]
   move mybox [10,0,0]

will move your box 30 units along the X-axis:

If you entered the above commands, click Undo three times to move the box back to its original position.

Scaling the Box

Scaling is performed in a similar manner:

scale name_obj [<x,y,z>]

where name_obj is the name of the object and <x,y,z> is a 3D coordinate that corresponds to the amount you would like to scale the object along the X, Y, and Z-axis, respectively.

Again, the scale transformation is different from the scale object property. Setting the object’s scale property (name_obj.scale= …) repeatedly with the same values will only scale the object the first time, but applying the scale transformation repeatedly will continue to scale the object relatively to the previous scale.

Rotating the Box

The rotate transformation is not as simple as the move and rotate transforms. In fact, there are three ways to express rotation values in MAXScript:

[Euler Angles], [Quaternions ] and [Angleaxis ].

This lesson will only consider Euler Angles. If you would like further information on any of these transformations, see the MAXScript Reference.

To apply a rotation transform in MAXScript, you must first define the rotation as a sort of rotation object, and then apply the rotation object to the object you want to rotate. The rotation object is defined in the following way:

rot_obj = eulerangles x y z

whererot_objcan be any name and x,y, and z represent the amount you want to rotate your object (in degrees) around the X, Y, and Z-axes, respectively.

FOR EXAMPLE,

   rot_box = eulerangles 0 30 0

creates an object called rot_box, which will rotate an object around the Y-axis by 30 degrees. This rotation can be applied to your box in the following way:

   rotate mybox rot_box

In fact, this rotation could be applied to any object by writing the same line as above and replacing mybox with the name of the object you want to rotate.

If you entered the above commands, click Undo to change the box back to its original orientation.

IF YOU DESIGNATE ANGLES FOR MORE THAN ONE AXIS:

   rot_box2 = eulerangles 30 45 60

The rotation is applied to an object, with the X-axis rotation occurring first, followed by the Y-axis rotation, and then the Z-axis rotation.

Note:

Moving, scaling, or rotating objects, or setting transform-related properties operates in the World Coordinate System, by default. If you want to perform these transformations in another coordinate system, see Coordsys.

Next Topic

More Box Transformations