diff options
| -rw-r--r-- | Spear/Math/Matrix3.hs | 28 | ||||
| -rw-r--r-- | Spear/Math/Matrix4.hs | 30 |
2 files changed, 57 insertions, 1 deletions
diff --git a/Spear/Math/Matrix3.hs b/Spear/Math/Matrix3.hs index 06c06a2..b295cbd 100644 --- a/Spear/Math/Matrix3.hs +++ b/Spear/Math/Matrix3.hs | |||
| @@ -11,7 +11,9 @@ module Spear.Math.Matrix3 | |||
| 11 | -- * Construction | 11 | -- * Construction |
| 12 | , mat3 | 12 | , mat3 |
| 13 | , mat3fromVec | 13 | , mat3fromVec |
| 14 | , transform | 14 | , transform |
| 15 | , translation | ||
| 16 | , rotation | ||
| 15 | , Spear.Math.Matrix3.id | 17 | , Spear.Math.Matrix3.id |
| 16 | -- * Transformations | 18 | -- * Transformations |
| 17 | -- ** Translation | 19 | -- ** Translation |
| @@ -153,6 +155,30 @@ transform r f p = mat3 | |||
| 153 | (V2.x r) (V2.x f) (V2.x p) | 155 | (V2.x r) (V2.x f) (V2.x p) |
| 154 | (V2.y r) (V2.y f) (V2.y p) | 156 | (V2.y r) (V2.y f) (V2.y p) |
| 155 | 0 0 1 | 157 | 0 0 1 |
| 158 | |||
| 159 | |||
| 160 | -- | Get the translation part of the given transformation matrix. | ||
| 161 | translation :: Matrix3 -> Matrix3 | ||
| 162 | translation (Matrix3 | ||
| 163 | a00 a10 a20 | ||
| 164 | a01 a11 a21 | ||
| 165 | a02 a12 a22) | ||
| 166 | = mat3 | ||
| 167 | 1 0 a20 | ||
| 168 | 0 1 a21 | ||
| 169 | 0 0 a22 | ||
| 170 | |||
| 171 | |||
| 172 | -- | Get the rotation part of the given transformationmatrix. | ||
| 173 | rotation :: Matrix3 -> Matrix3 | ||
| 174 | rotation (Matrix3 | ||
| 175 | a00 a10 a20 | ||
| 176 | a01 a11 a21 | ||
| 177 | a02 a12 a22) | ||
| 178 | = mat3 | ||
| 179 | a00 a10 0 | ||
| 180 | a01 a11 0 | ||
| 181 | a02 a12 1 | ||
| 156 | 182 | ||
| 157 | 183 | ||
| 158 | -- | Return the identity matrix. | 184 | -- | Return the identity matrix. |
diff --git a/Spear/Math/Matrix4.hs b/Spear/Math/Matrix4.hs index 85ab39f..5c54aea 100644 --- a/Spear/Math/Matrix4.hs +++ b/Spear/Math/Matrix4.hs | |||
| @@ -13,6 +13,8 @@ module Spear.Math.Matrix4 | |||
| 13 | , mat4 | 13 | , mat4 |
| 14 | , mat4fromVec | 14 | , mat4fromVec |
| 15 | , transform | 15 | , transform |
| 16 | , translation | ||
| 17 | , rotation | ||
| 16 | , lookAt | 18 | , lookAt |
| 17 | , Spear.Math.Matrix4.id | 19 | , Spear.Math.Matrix4.id |
| 18 | -- * Transformations | 20 | -- * Transformations |
| @@ -186,6 +188,34 @@ transform right up fwd pos = mat4 | |||
| 186 | 0 0 0 1 | 188 | 0 0 0 1 |
| 187 | 189 | ||
| 188 | 190 | ||
| 191 | -- | Get the translation part of the given transformation matrix. | ||
| 192 | translation :: Matrix4 -> Matrix4 | ||
| 193 | translation (Matrix4 | ||
| 194 | a00 a10 a20 a30 | ||
| 195 | a01 a11 a21 a31 | ||
| 196 | a02 a12 a22 a32 | ||
| 197 | a03 a13 a23 a33) | ||
| 198 | = mat4 | ||
| 199 | 1 0 0 a30 | ||
| 200 | 0 1 0 a31 | ||
| 201 | 0 0 1 a32 | ||
| 202 | 0 0 0 a33 | ||
| 203 | |||
| 204 | |||
| 205 | -- | Get the rotation part of the given transformation matrix. | ||
| 206 | rotation :: Matrix4 -> Matrix4 | ||
| 207 | rotation (Matrix4 | ||
| 208 | a00 a10 a20 a30 | ||
| 209 | a01 a11 a21 a31 | ||
| 210 | a02 a12 a22 a32 | ||
| 211 | a03 a13 a23 a33) | ||
| 212 | = mat4 | ||
| 213 | a00 a10 a20 0 | ||
| 214 | a01 a11 a21 0 | ||
| 215 | a02 a12 a22 0 | ||
| 216 | a03 a13 a23 1 | ||
| 217 | |||
| 218 | |||
| 189 | -- | Build a transformation 'Matrix4' defined by the given position and target. | 219 | -- | Build a transformation 'Matrix4' defined by the given position and target. |
| 190 | lookAt :: Vector3 -- ^ Eye position. | 220 | lookAt :: Vector3 -- ^ Eye position. |
| 191 | -> Vector3 -- ^ Target point. | 221 | -> Vector3 -- ^ Target point. |
