public static LQuaternion AngleAxis(LFloat angle, LVector3 axis) { LFloat radian2 = angle * 0.5d * LMath.DegToRad; LFloat sina = LMath.Sin(radian2); LFloat cosa = LMath.Cos(radian2); axis = axis.normalized; return(new LQuaternion(sina * axis.x, sina * axis.y, sina * axis.z, cosa)); }
public void SetDeg(LFloat rdeg) { deg = rdeg; var rad = LMath.Deg2Rad * deg; var c = LMath.Cos(rad); var s = LMath.Sin(rad); up = new LVector2(-s, c); }
public OBB(LVector2 pos, LVector2 size, LFloat deg) { this.pos = pos; this.size = size; radius = size.magnitude; this.deg = deg; var rad = LMath.Deg2Rad * deg; var c = LMath.Cos(rad); var s = LMath.Sin(rad); up = new LVector2(-s, c); }
/// <summary> /// 轴向旋转 /// </summary> /// <param name="angle"></param> /// <param name="axis"></param> /// <returns></returns> public static LQuaternion AngleAxis(LFloat angle, LVector3 axis) { axis = axis.normalized; angle = angle * LMath.Deg2Rad; LQuaternion q = new LQuaternion(); LFloat halfAngle = angle * LFloat.half; LFloat s = LMath.Sin(halfAngle); q.w = LMath.Cos(halfAngle); q.x = s * axis.x; q.y = s * axis.y; q.z = s * axis.z; return(q); }
/// <summary> /// 欧拉角转四元数 /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <returns></returns> public static LQuaternion Euler(LFloat x, LFloat y, LFloat z) { LFloat cX = LMath.Cos(x * LMath.PI / 360); LFloat sX = LMath.Sin(x * LMath.PI / 360); LFloat cY = LMath.Cos(y * LMath.PI / 360); LFloat sY = LMath.Sin(y * LMath.PI / 360); LFloat cZ = LMath.Cos(z * LMath.PI / 360); LFloat sZ = LMath.Sin(z * LMath.PI / 360); LQuaternion qX = new LQuaternion(sX, LFloat.zero, LFloat.zero, cX); LQuaternion qY = new LQuaternion(LFloat.zero, sY, LFloat.zero, cY); LQuaternion qZ = new LQuaternion(LFloat.zero, LFloat.zero, sZ, cZ); LQuaternion q = (qY * qX) * qZ; return(q); }
public static LQuaternion Euler(LVector3 euler) { LFloat ex = euler.x * LMath.DegToRad / 2; LFloat ey = euler.y * LMath.DegToRad / 2; LFloat ez = euler.z * LMath.DegToRad / 2; LFloat sinex = LMath.Sin(ex); LFloat siney = LMath.Sin(ey); LFloat sinez = LMath.Sin(ez); LFloat cosex = LMath.Cos(ex); LFloat cosey = LMath.Cos(ey); LFloat cosez = LMath.Cos(ez); LQuaternion rotation; rotation.x = sinez * cosex * cosey - cosez * sinex * siney; rotation.y = cosez * sinex * cosey + sinez * cosex * siney; rotation.z = cosez * cosex * siney - sinez * sinex * cosey; rotation.w = cosez * cosex * cosey + sinez * sinex * siney; rotation.Normalize(); return(rotation); }
public LVector3 GetPosition(LFloat timer) { var rad = (InitDeg + ((timer / Interval) - (timer / Interval).Floor()) * 360) * LMath.Deg2Rad; return(InitPos + new LVector3(LMath.Cos(rad), 0, LMath.Sin(rad)) * Radius); }