---
# System prepended metadata

title: Untitled

---

### Rotation matrix class!

```
//HERE'S THE NEW ONE

struct Vector3 {
    float x, y, z;
    
    Vector3 add(Vector3);
    Vector3 scale(float);
    Vector3 subtract(Vector3);
};

struct Matrix3{
    float ii, ij, ik,
          ji, jj, jk,
          ki, kj, kk;
    
    Matrix3 multiply(Matrix3);
    Vector3 preMultiply(Vector3);
    
    /// Gets a rotation matrix
    static Matrix3 getRotMatrix(float alpha, float beta, float gamma);
    
    /// Gets a perspective scaling matrix, scaled along the z-axis
    static Matrix3 getPerspMatrix(Vector3 surfacePos);
    
    /// Gets a camera transform matrix
    /*static Matrix3 getCameraMaterix(Vector3 cameraPosition,
                                    Vector3 cameraRotation,
                                    float surfaceDistanceIntoZ);*/
};



```

```
#include "vectormath.h"
Matrix3 Matrix3::multiply(Matrix3 m)
{
    Matrix3 output = {m.ii*ii+m.ji*ij+m.ki*ik, m.ij*ii+m.jj*ij+m.kj*ik, m.ik*ii+m.jk*ij+m.kk*ik,
                      m.ii*ji+m.ji*jj+m.ki*jk, m.ij*ji+m.jj*jj+m.kj*jk, m.ik*ji+m.jk*jj+m.kk*jk,
                      m.ii*ki+m.ji*kj+m.ki*kk, m.ij*ki+m.jj*kj+m.kj*kk, m.ik*ki+m.jk*kj+m.kk*kk};
    return output;
}
Vector3 Matrix3::premultiply(Vector3 v)
{
    Vector3 output = {v.x*ii + v.y*ij + v.z*ik,
                      v.x*ji + v.y*jj + v.z*jk,
                      v.x*ki + v.y*kj + v.z*kk};
    return output;
}

Vector3 Vector3::add(Vector3 v)
{
    Vector3 out = {x + v.x,
                   y + v.y,
                   z + v.z};
    return out;
}
Vector3 Vector3::subtract(Vector3 v)
{
    Vector3 out = {x - v.x,
                   y - v.y,
                   z - v.z};
    return out;
}
Vector3 Vector3::scale(float s)
{
    Vector3 out = {x * s,
                   y * s,
                   z * s};
    return out;
}
```

```
// rotation matrix, angles about rotate(x, y, z)
Matrix3 Matrix3::rotate(float alpha, float beta, float gamma) 
{
    Matrix3 Rz = {cosf(gamma), -sinf(gamma), 0,
                  sinf(gamma),  cosf(gamma), 0,
                            0,            0, 1};
    Matrix3 Ry = { cosf(beta), 0, sinf(beta),
                            0, 1           0,
                  -sinf(beta), 0, cosf(beta)};
    Matrix3 Rx = {  1,           0,            0,
                    0, cosf(alpha), -sinf(alpha),
                    0, sinf(alpha),  cosf(alpha)};
    return Rz.multiply(Ry.multiply(Rx));
}

Matrix3 Matrix3::getPerspMatrix(Vector3 sp)
{
    Matrix3 mat = {  1  ,  0  , sp.x/sp.z,
                     0  ,  1  , sp.y/sp.z,
                     0  ,  0  , 1.0f/sp.z};
    return mat;
}

/*Matrix3 Matrix3::getCameraMatrix(Vector3 camPos, Vector3 camRot, float d)
{
    // Rotate the world inversely around the camera position
    Matrix3 invRot = rotate(camRot)
}*/

Vector3 p;// Yah point
p = p.scale(1/(p.z + focalPoint));



```            


