math - Orbit around arbitrary axis glsl -
i animating simple circular orbit around central object using glsl. 2d orbit simple enough, when try object orbiting in other axis becomes more complicated.
float xval = (radius) * sin(timevalue); float yval = (radius) * cos(timevalue); float zval = 0.;
// n=(nx,ny,nz) rotation axis, if not normalized, use norm = sqrt(nx*nx+ny*ny+nz*nz) nx /= norm; ny /= norm; nz /= norm // phi current rotation angle c=cos(phi); s=sin(phi); // rotation simple quaternions q = quaternion(c, s*nx, s*ny, s*nz) rotated_vec = q.rotate(vec)
Comments
Post a Comment