diff options
author | Anthony LaTorre <telatorre@gmail.com> | 2011-05-06 12:06:58 -0400 |
---|---|---|
committer | Anthony LaTorre <telatorre@gmail.com> | 2011-05-06 12:06:58 -0400 |
commit | 4e2720ff56afff978acaf589218cee0122d2ae29 (patch) | |
tree | 98be56318474b5d87c3514bd97bb4ae5b33f0d1b /rotate.h | |
parent | 98dc8b3d4eb46fdb73b01e78c5e53ff3a779ab85 (diff) | |
download | chroma-4e2720ff56afff978acaf589218cee0122d2ae29.tar.gz chroma-4e2720ff56afff978acaf589218cee0122d2ae29.tar.bz2 chroma-4e2720ff56afff978acaf589218cee0122d2ae29.zip |
added rotations
Diffstat (limited to 'rotate.h')
-rw-r--r-- | rotate.h | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/rotate.h b/rotate.h new file mode 100644 index 0000000..52d6d6a --- /dev/null +++ b/rotate.h @@ -0,0 +1,24 @@ +#ifndef __ROTATE_H__ +#define __ROTATE_H__ + +__device__ const Matrix IDENTITY_MATRIX = {1,0,0,0,1,0,0,0,1}; +__device__ const Matrix ZERO_MATRIX = {0,0,0,0,0,0,0,0,0}; + +__device__ __host__ Matrix make_rotation_matrix(float phi, const float3 &n) +{ + /* rotate points counterclockwise, when looking towards +infinity, + through an angle `phi` about the axis `n`. */ + + float cos_phi = cosf(phi); + float sin_phi = sinf(phi); + + return IDENTITY_MATRIX*cos_phi + (1-cos_phi)*outer(n,n) + + sin_phi*make_matrix(0,n.z,-n.y,-n.z,0,n.x,n.y,-n.x,0); +} + +__device__ __host__ float3 rotate(const float3 &a, float phi, const float3 &n) +{ + return make_rotation_matrix(phi,n)*a; +} + +#endif |