4 ms·
Here is the maths for rotation of vectors around arbitrary axes: https://sites.google.com/site/glennmurray/Home/rotation-matrices-and-formulas/rotation-about-
by subroutine 7y ago
Here is the maths for rotation of vectors around arbitrary axes:
https://sites.google.com/site/glennmurray/Home/rotation-matrices-and-formulas/rotation-about-an-arbitrary-axis-in-3-dimensions https://sites.google.com/site/glennmurray/Home/rotation-matr...
I've used these to simulate polymer growth branching in 3D. Determining if and where two lines in 3D space intersect requires determining the scalar parametric equations of the two lines, then solving 3 simultaneous equations using a method like gaussian elimination. Seems like the last step could be computationally taxing for a cpu if performed each time-tic during sword swings - not sure if modern GPUs are optimized for just this sort of problem.
- nwallin 7y agoI'm aware. I deal with rotations and intersecting geometries at work too. There's a closed form 3x3 matrix inversion procedure which is very fast on CPUs. [1] We don't use it with pen and paper because it's too hard to remember and there's a lot of places to fuck up substitutions, but computers don't have problems with remembering obtuse formulas. (it's like the 2x2 inverse where you shuffle stuff around and divide by the determinant) So you're looking at about 60 instructions (one division operation) with no branching to solve Ax = b in R3. [2] The reciprocal throughput is 16.5 cycles, so 5.5ns on a 3GHz Skylake assuming everything's in cache. In gamedev you'll use an approximate reciprocal instead of the division, so the latency will be lower but AFAIK the throughput will be the same. The slow part of rotations is actually computing the sin/cos of the angles. You'll notice my model avoids anything to do with angles: there are no transcendental functions. This is non-physical for a few reasons, notably it's not possible to swing a sword more than 90 degrees in one frame. It's fine for a video game where you assume a full sword swing will take 15-30 frames and good enough is good enough, but it's not fine for scientific computing. Video games are all about faking it when nobody's looking. Also, my model starts with defining motion in terms of the scalar parametric equations of the lines. I did think about this before posting. :) [1] https://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of_3_%C3%97_3_matrices https://en.wikipedia.org/wiki/Invertible_matrix#Inversion_of... [2] https://godbolt.org/z/ND6tTM https://godbolt.org/z/ND6tTM
- subroutine 7y agoYou sure did think about it, hah, thanks for sharing!