示例#1
0
        public static SVector3 GetRotVectorFromOrigin(SVector3 origin, SQuaternion q)
        {
            SQuaternion temq   = new SQuaternion(origin.x, origin.y, origin.z, (Fix64)0);
            SQuaternion finalq = q * temq * q.conjugated;

            return(new SVector3(finalq.x, finalq.y, finalq.z));
        }
示例#2
0
        public static SQuaternion AxisAngle(SVector3 axis, Fix64 angle)
        {
            axis.Normalize();
            Fix64 x = (Fix64)(axis.x * Fix64.Sin(angle / (Fix64)2));
            Fix64 y = (Fix64)(axis.y * Fix64.Sin(angle / (Fix64)2));
            Fix64 z = (Fix64)(axis.z * Fix64.Sin(angle / (Fix64)2));
            Fix64 w = (Fix64)Fix64.Cos(angle / (Fix64)2);

            return(new SQuaternion(x, y, z, w));
        }
示例#3
0
 public void LookAt(SVector3 lookAtPoint)
 {
     SVector3 dir = lookAtPoint - position;
     //SVector3 norm = SVector3.Cross(forward, dir);
     if(dir.sqrtMagnitude < Fix64.One / (Fix64)10)
         return;
     
     SVector3 norm = SVector3.Cross(forward, dir);
     if(norm.sqrtMagnitude < Fix64.One / (Fix64)100 && SVector3.Dot(dir.normalized,forward) > (Fix64)0)
     {
         return;
     }
     else if(norm.sqrtMagnitude < Fix64.One / (Fix64)100 && SVector3.Dot(dir.normalized,forward) < (Fix64)0)
     {
         RotateAroundAxis(up, (Fix64)Fix64.Pi / (Fix64)2);
     }
     else
     {
         
         
         RotateAroundAxis(norm.normalized, SVector3.AngleFromTo(forward, dir));
     }
 }
示例#4
0
 public STransform()
 {
     _localRotation = SQuaternion.AxisAngle(SVector3.up, (Fix64)0);
     _localPosition = SVector3.zero;
 }
示例#5
0
 public void RotateAroundAxis(SVector3 axis, Fix64 angle)
 {
     rotation = SQuaternion.AxisAngle(axis, angle) * rotation;
 }
示例#6
0
        public static SQuaternion AxisAngleInDeg(SVector3 axis, Fix64 angle)
        {
            Fix64 temAngle = angle / (Fix64)180 * (Fix64)Fix64.Pi;

            return(AxisAngle(axis, temAngle));
        }
示例#7
0
 public static SVector3 ProjectOnPlane(SVector3 a, SVector3 normal)
 {
     return(a - Project(a, normal));
 }
示例#8
0
        public static SVector3 Project(SVector3 a, SVector3 normal)
        {
            Fix64 pl = Dot(a, normal);

            return(pl * normal.normalized);
        }
示例#9
0
 public static Fix64 AngleFromTo(SVector3 a, SVector3 b)
 {
     return((Fix64)Fix64.Acos(Dot(a.normalized, b.normalized)));
 }
示例#10
0
 public static SVector3 Cross(SVector3 a, SVector3 b)
 {
     return(a.Cross(b));
 }
示例#11
0
 public SVector3 Cross(SVector3 b)
 {
     return(new SVector3(y * b.z - z * b.y, z * b.x - x * b.z, x * b.y - y * b.x));
 }
示例#12
0
 public static Fix64 Dot(SVector3 a, SVector3 b)
 {
     return(a.Dot(b));
 }
示例#13
0
 public Fix64 Dot(SVector3 other)
 {
     return(other.x * x + other.y * y + other.z * z);
 }
示例#14
0
 public void Add(SVector3 b)
 {
     this.x += b.x;
     this.y += b.y;
     this.z += b.z;
 }
示例#15
0
        public static SVector3 GetRotVectorFromX(SVector3 origin, SQuaternion q)
        {
            Fix64 length = origin.magnitude;

            return(GetRotVectorFromOrigin(SVector3.right, q) * length);
        }