# A Technical overview of Second Life

## Intro

Many activities in SL, especially ones related to content creation, require some technical knowledge. This includes Building using prims, Scripting using LSL, and other activities such as creating clothing and textures, though perhaps to a lesser degree.

## Positions and Vectors

Every place in SL has a unique position. Look at the top of your viewer screen to see the current position of your Avatar in the current region, for example Ross/19.5/245.6/51.3. This means you are in the Ross region, 19.5 meters east of the leftmost edge, 245.6 meters north of the bottom edge, and 51.3 meters up from the bottom (which might be both underground and underwater). In LSL, positions are usually stored in a data structure called a vector, and might look like

vector pos = < 19.5, 245.6, 51.3 >;

The Southwest corner of every region is 0/0/0. The positions in a region relative to that corner are sometimes called *world*, *region*, *global*, or *sim* *coordinates*. We will talk about *local* coordinates in a minute.
In World coordinates, the first number is always East, the second is always North, and the third is always Up, though negative numbers can also be used to mean West, South, and Down.

Given the position *pos* above, you can find other points. Exactly 10 meters East would be

vector p1 = pos + <10, 0, 0 >;

Five meters below would be

vector p2 = pos + < 0, 0, -5 >;

Given two points, *p1* and *p2*, a point exactly halfway between them is

vector halfway = (p1 + p2)/2;

and the distance between them is

float d = llVecDist( p1, p2 );

### Finding the position

LSL has a function that returns the current position

vector p = llGetPos();

This function returns the world coordinates for the object it is in. Note that if the object is an attachment to an avatar, it gives the avatar's position, not the object itself.

### Local coordinates

An object or an avatar in SL always has some position in World coordinates, but it also has *local* coordinates as well. The local position of an object is always < 0, 0, 0 >. This might seem boring, because it is, but there are also the directions to consider. The x-direction is considered the *front* of the object, the y-direction is *right*, and the z-direction is *up*.
You can see the x, y, and z directions in the Edit window, just select some object and the Local coordinates (not World). The red arrow is, by definition, *front*. In local coordinates, < 1.5, 0, 0 > is 1.5 meters in front of the object, and <0, 0, -1> is 1 meter below, all in local coordinates.

Of course, you need to be able to convert from local to world, and from world to local. We will see how to do this as soon as we talk about rotations.

## Basic Rotations

Imagine an object that looks like an airplane. The airplane is pointing in some direction (duh!) and has some roll around the direction it is pointing. SL uses a rotation to describe the pointing and the roll. You can get the rotation of an object (such as our arirplane) like this

rotation r = llGetRot();

One rotation is called the ZERO_ROTATION, which is nose (local front) pointing exactly East, the left wing (local left) pointing exactly North, and the top (local up) of the airplane pointing exactly Up. You can make your object point this way using

llSetRot( ZERO_ROTATION );

### Quaternions

An LSL rotation is a set of four numbers. The first three are a vector representing the direction, and the last represents the amount of roll. However, it is not necessary to understand how the four numbers are used, it is often easier to just accept that they are a rotation. In mathematics, the four numbers are called a *quaternion*. To put it bluntly, quaternions have mathematical properties that make them very useful in computer graphics.

In fact, an LSL rotation and a mathmematical quaternion are one and the same.

### Two Other Ways to Represent a Rotation

Another way to represent a rotation is using three numbers, <X, Y, Z>, which represent the amount the object is turned around each axis. This is used in the Edit window, for example, and is generally easy for people to visualize. For example, the edit window shows rotations of x: 30, y: 90, and z: 10. The object is rotated a little around each axis, 30 degrees around x, 90 degrees around y, and 10 degrees around z.This is called the Euler representation of a rotation. (Note that these three numbers are a vector and not a rotation type, though it can represent the same information.) Given such a three number rotation, you can convert it into and from a rotation type:

vector v1 = <30, 90, 10 >; rotation r = llEuler2Rot( v1 ); vector v2 = llRot2Euler( r );

A third way is to use three vectors, showing what the front is pointing at, what the top is pointing at, and what the left side is pointing at. Actually, only two of the three are needed, because any two determines the third. For example, consider

vector f = <20, 30, 100>; vecotr l = <50, -30, -1>;

For good reasons, the four number version, the rotation, is better, though harder for a beginner to grasp. There are functions for converting easily back and forth.