# Intermediate – Part 1

So! Since now we have discussed how to control the flow of our script and how to execute simple actions multiple times, now it’s time to jump into more complex areas, like transformations.

Transforming max objects is pretty easy. To do that you have to use your objects position, rotation and scale (PRS) values. Doing that is fairly simple, you just have to update your selections &.position, &.rotation and &.scale properties. Every property have their own x, y and z (Point3) or even w (Point4) values.

So if you want to update these values you can do that two different ways.

### Position (Translation)

#### The first method

```
$.pos.x = 0
$.pos.y = 0
$.pos.z = 0
```

So to set these values you can simply use the ‘=’ sign to assign a value.

#### The second method

`$.pos = [0,0,0]`

This one is useful when you want to set all the values at once. This way you can simply reduce the number of lines of your code.

### Rotation

Rotating an object might be a bit trickier, especially if you have never done anything like this before. To rotate an object you have to understand the two different ways how you can do that. The first way is the world rotation, while the second one is the local rotation. Fortunately maxscript has a very good solution to do such things, especially when you would like to do the rotation in the local reference coordinate system, which we’ll discuss later.

So to rotate an object you have to understand how max handles the different type of rotations.

#### Quternion

```
-- quat w [x, y, z]
$.rot = quat 0 [0, 0, 1]
<quat>.angle: Float
<quat>.axis: Point3
```

The quaternion rotation is probably the simplest. It is nothing more than a simple vector that tells you where your object points to with its ‘z’ axis, or with other words, it’s the ‘up vector’ of your object. The w value simply tells you the rotation about the up vector in degrees.

#### Euler Angles

```
-- eulerAngles x y z
$.rot = eulerAngles 0 0 0
<eulerAngles>.x: Float
<eulerAngles>.y: Float
<eulerAngles>.z: Float
```

Euler Angles are a bit different. The most important thing about eulerAngles is that these values are the actual rotations about the axises. So first it rotates about the X, then the Y and then the Z axis. Working with these values are more important in animations. These are sequential rotations, which means that the rotation can happen about different axis order, like XYZ, or YZX, ZXZ etc…

#### Angle Axis

```
-- quat w [x, y, z]
$.rot = angleAxis 0 [0, 0, 1]
<angleaxis>.angle: Float
<angleaxis>.axis: Point3
<angleaxis>.numrevs: Integer
```

Same as Quaternion with the only difference that it has a 3rd property, called number of revolves. This is useful when you have to deal with animations, like rotating wheels and other objects that can revolve multiple time about their up vector.

#### Scale

```
$.scale.x = 0
$.scale.y = 0
$.scale.z = 0
```

It’s also a pretty simpe to modify the scale on each axis.

### Local and World

As I mentioned in the begining of this tutorial there are two reference coordinate systems how you can modify your object rotation. The above examples were world space transformations. To change to a different ref coord system we have to use the following.

```
in coordsys $.transform
(
$.pos.x = 10
)
```

In this case if you have rotated your object in a certain direction, the transformation will happen in that coordinate system. The $.transform property is the actual Transformation Matrix of this object. The Transformation Matrix contains all the above values in a compact form.

### The Transformation Matrix (Matrix3)

```
-- Matrix 3
[1 | 0 | 0] -- X Axis Direction
[0 | 1 | 0] -- Y Axis Direction
[0 | 0 | 1] -- Z Axis Direction
[0 | 0 | 0] -- Position (X Y Z)
```

So! To simplify this. The first 3 rows are the axis of your transform gizmo. (Yes the transform gizmo which represents your local space) Each row tells you what is the direction where the gizmo axises are pointing to. These are unit vectors, so the length of each of them is 1. The last row is the actual position of your object.

If the length of these vectors are not 1 but greater or smaller, then it means it has a scale on it.

```
[2 | 0 | 0] -- X Axis Direction
[0 | 2 | 0] -- Y Axis Direction
[0 | 0 | 1] -- Z Axis Direction
[0 | 0 | 0] -- Position (X Y Z)
```

This means that this object is scaled along its X and Y axis. That’s how it looks in the viewport below.

```
-- $.transform
(matrix3 [1.41421,1.41421,-1.74846e-07] [-1.41421,1.41421,0] [0,0,1] [0,0,0])
```

`Red position: 1.41421, 1.41421, 0`

Green position: -1.41421, 1.41421, 0

Blue position: 0, 0, 1

Note that the Red and Green points are 2 units away from the center. If you calculate the length of these vectors:

`Sqrt(1,41421`^{2} + 1,41421^{2}) = 2

So the length of the vector is 2 and this means that it has a 2 scale on both the X and Y axises. If we rotate this back, then we will get this transform.

```
-- $.transform
(matrix3 [2,0,0] [0,2,0] [0,0,1] [0,0,0])
```

So that’s it. Now you know the most important things about the transformations in 3ds max. :) In the next part, we will reconstruct the Clone Between Spinner using the things we have learnt in this lesson.