## Monthly Archives: October 2012 this was a multithreading bug that appeared when the cubemap object got destroyed (early) by another thread.

by the time this thread entered the if statement, the cubeMap variable was gone (set to 0 by another thread in the same object)

If you have 3 vectors, right, up, and forward, you can write a ROW MAJOR change of basis matrix as follows:

```  [       right.x     right.y     right.z   ]
[          up.x        up.y        up.z   ]
[    -forward.x  -forward.y  -forward.z   ]
```

The new basis in terms of the original basis are the ROWS of this change-of-basis matrix.

This matrix takes any vector with (1,0,0), (0,1,0), (0,0,1) as its OLD basis vectors, and rotates it so that its new basis vectors ARE right,up,forward as given.

A viewing matrix is the transpose of the change of basis matrix, because a viewing matrix “pushes the world away” from a stationary camera. (The viewing matrix isn’t going to _move the camera_, instead it moves the whole world so that the portion you want to see sits in the canonical viewing volume).

# To make this column major

Just transpose it.

# Arbitrary axis angle rotation C++ code, ROW MAJOR

```/// Arbitrary axis angle rotation
Matrix Matrix::Rotation( const Vector & u, real radians )
{
real c = cos( radians ) ;
real l_c = 1 - c ;

real s = sin( radians ) ;

//ROW MAJOR
return Matrix(
u.x*u.x + (1 - u.x*u.x)*c,      u.x*u.y*l_c + u.z*s,        u.x*u.z*l_c - u.y*s,  0,
u.x*u.y*l_c - u.z*s,  u.y*u.y+(1 - u.y*u.y)*c,        u.y*u.z*l_c + u.x*s,  0,
u.x*u.z*l_c + u.y*s,      u.y*u.z*l_c - u.x*s,  u.z*u.z + (1 - u.z*u.z)*c,  0,
0,                        0,                          0,  1
) ;
}
```

# Arbitrary axis angle rotation C++ code, __COLUMN__ MAJOR

```/// Arbitrary axis angle rotation
Matrix Matrix::Rotation( const Vector & u, real radians )
{
real c = cos( radians ) ;
real l_c = 1 - c ;

real s = sin( radians ) ;

//COLUMN MAJOR
return Matrix(
u.x*u.x + (1 - u.x*u.x)*c,      u.x*u.y*l_c - u.z*s,        u.x*u.z*l_c + u.y*s,  0,
u.x*u.y*l_c + u.z*s,  u.y*u.y+(1 - u.y*u.y)*c,        u.y*u.z*l_c - u.x*s,  0,
u.x*u.z*l_c - u.y*s,      u.y*u.z*l_c + u.x*s,  u.z*u.z + (1 - u.z*u.z)*c,  0,
0,                        0,                          0,  1
) ;
}
```