Closed notlion closed 10 years ago
I was thinking, even though it's nice to just have this on vec3, isn't the way you should really go about this:
mat4 = new plask.Mat4(); mat4.rotate(angle, x, y, z); mat4.mulVec3(vec)
?
IMO it's mostly a convenience issue, but with a performance bonus. Using a Mat4 incurs the cost of creating the identity and rotation matrices, multiplying them, and then actually transforming your Vec3. It makes sense if you use that Mat4 repeatedly, but for certain things I want to be able to chain a lightweight rotation onto some other vector operations.
I think all the issues you addressed should be fixed with my latest commit.
But there are loads of things you can do with a mat4, where do you draw the line to what goes into vec3?
I guess the best answer I can give is "common operations", which to me means translate (add), rotate, scale. Those are at least the ones that could be performed with a matrix, but are simpler computationally and code-wise to do in-place.
There might be an alternative to this if we changed the way Mat4 works. For example..
vec3.rotate(theta, x, y, z)
vs
vec3.mulMat4(Mat4.createRotation(theta, x, y, z))
..if Mat4.createRotation() didn't incur the call to reset() and mul4x4r, that would probably be a more general solution and would allow matrix multiplication to be chained with other vector operations.
You can write (new plask.Mat4()).rotate(theta, x, y, z).mulVec3(vec)
true, but you'd break the flow of a statement like this..
v2.subbed(v1).rotate(theta, x, y, z).normalize()
..and besides would still incur the matrix creation and 2x multiplication cost.
Yeah, but when you talk about performance that goes for any/all operations, it would always be cheaper if we rolled multiple operations into one, or specialized everything in mat4. I dunno, I guess I'm just not that convinced about this specific case... How often do you really do it? How important is the performance really?
Hm. The specific use case I have in mind i'm doing twice per edge over a mesh.. It's a one time process though, so performance isn't a huge concern. I just find it convenient to have a rotate function on Vec3. I'll try it with matrices for now.
It might be nice to think about static matrix creation functions like Mat4.createRotation() for the future though.
Should be a bit faster than making a Mat4, and more convenient sometimes. I made a test here to show that it works:
https://gist.github.com/1267219