Last active
August 29, 2015 14:13
-
-
Save panmari/eedf62ddf8f5fbbd5f9c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (mat *T) MulVec4(v *vec4.T) vec4.T { | |
return vec4.T{ | |
mat[0][0]*v[0] + mat[1][0]*v[1] + mat[2][0]*v[2] + mat[3][0]*v[3], | |
mat[0][1]*v[0] + mat[1][1]*v[1] + mat[2][1]*v[2] + mat[3][1]*v[3], | |
mat[0][2]*v[0] + mat[1][2]*v[1] + mat[2][2]*v[2] + mat[3][2]*v[3], | |
mat[0][3]*v[0] + mat[1][3]*v[1] + mat[2][3]*v[2] + mat[3][3]*v[3], | |
} | |
} | |
// Strangely, this is the slowest of the three. | |
func (mat *T) AltMulVec4(v *vec4.T) vec4.T { | |
result := *v | |
mat.TransformVec4(&result) | |
return result | |
} | |
// MulVec3 multiplies v with mat with w as fourth component of the vector. | |
func (mat *T) TransformVec4(v *vec4.T) { | |
// use intermediate variables to not alter further computations | |
x := mat[0][0]*v[0] + mat[1][0]*v[1] + mat[2][0]*v[2] + mat[3][0]*v[3] | |
y := mat[0][1]*v[0] + mat[1][1]*v[1] + mat[2][1]*v[2] + mat[3][1]*v[3] | |
z := mat[0][2]*v[0] + mat[1][2]*v[1] + mat[2][2]*v[2] + mat[3][2]*v[3] | |
v[3] = mat[0][3]*v[0] + mat[1][3]*v[1] + mat[2][3]*v[2] + mat[3][3]*v[3] | |
v[0] = x | |
v[1] = y | |
v[2] = z | |
} | |
Author
panmari
commented
Jan 9, 2015
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment