Math 绕任意轴旋转glsl

Math 绕任意轴旋转glsl,math,glsl,Math,Glsl,我正在使用GLSL设置围绕中心对象的简单圆形轨道的动画。 2d轨道足够简单,但当我尝试让对象在另一个轴上轨道时,它会变得更复杂 float xVal = (radius) * sin(timeValue); float yVal = (radius) * cos(timeValue); float zVal = 0.; 谢谢你。不过,我仍在努力将其转换为GLSL用于我的动画 // n=(nx,ny,nz) is the rotation axis, if not normalized, use

我正在使用GLSL设置围绕中心对象的简单圆形轨道的动画。 2d轨道足够简单,但当我尝试让对象在另一个轴上轨道时,它会变得更复杂

float xVal = (radius) * sin(timeValue);
float yVal = (radius) * cos(timeValue);
float zVal = 0.;

谢谢你。不过,我仍在努力将其转换为GLSL用于我的动画
// n=(nx,ny,nz) is the rotation axis, if not normalized, use

norm = sqrt(nx*nx+ny*ny+nz*nz)
nx /= norm; ny /= norm; nz /= norm

// phi is the current rotation angle

c=cos(phi); s=sin(phi);

// rotation is most simple with quaternions

q = quaternion(c, s*nx, s*ny, s*nz)

rotated_vec = q.rotate(vec)