Beispiel #1
0
        public static void FromVector(ref Vector3F dir, out SphericalDirectionF result)
        {
            result.Horizontal = MathEx.Atan2(dir.Y, dir.X);
            float dir2Length = MathEx.Sqrt(dir.X * dir.X + dir.Y * dir.Y);

            result.Vertical = MathEx.Atan2(dir.Z, dir2Length);
        }
        protected override void OnGetLocalPosition(Random random, out Vector3 result)
        {
            var a = random.Next(MathEx.PI * 2);
            var r = MathEx.Sqrt(random.NextFloat()) * Radius;

            result.X = (float)(random.NextFloat() * Height.Value - Height.Value / 2);
            result.Y = r * MathEx.Cos(a);
            result.Z = r * MathEx.Sin(a);
        }
Beispiel #3
0
        public float GetPointDistance(Vector2F point)
        {
            float sqr = GetPointDistanceSquared(point);

            if (sqr == 0)
            {
                return(0);
            }
            return(MathEx.Sqrt(sqr));
        }
Beispiel #4
0
        public void Normalize()
        {
            float len = MathEx.Sqrt(X * X + Y * Y + Z * Z + W * W);

            if (len != 0)
            {
                float ilength = 1.0f / len;
                X *= ilength;
                Y *= ilength;
                Z *= ilength;
                W *= ilength;
            }
        }
Beispiel #5
0
                public void GetInstancingData(out ObjectInstanceData data)
                {
                    GetWorldMatrixTranspose(out data.Transform);
                    data.PositionPreviousFrame = PositionPreviousFrame;
                    //data.Unused = 0;
                    //!!!!slowly?
                    ColorValue c;

                    c.Red      = MathEx.Sqrt(Color.Red / 10);
                    c.Green    = MathEx.Sqrt(Color.Green / 10);
                    c.Blue     = MathEx.Sqrt(Color.Blue / 10);
                    c.Alpha    = MathEx.Sqrt(Color.Alpha / 10);
                    data.Color = c.ToColorPacked();
                    //data.Color = ( Color * 0.25f ).ToColorPacked();
                    //data.Color = BillboardOne.Color;
                }
Beispiel #6
0
                //public float Unused;

                //

                public void Init(ref Matrix4F transform, ref Vector3F positionPreviousFrame, ref ColorValue color)
                {
                    transform.GetTranspose(out Transform);
                    PositionPreviousFrame = positionPreviousFrame;
                    //Unused = 0;
                    //!!!!slowly?
                    ColorValue c;

                    c.Red   = MathEx.Sqrt(color.Red / 10);
                    c.Green = MathEx.Sqrt(color.Green / 10);
                    c.Blue  = MathEx.Sqrt(color.Blue / 10);
                    c.Alpha = MathEx.Sqrt(color.Alpha / 10);
                    Color   = c.ToColorPacked();
                    //Color = ( color * 0.25f ).ToColorPacked();
                    //Color = new ColorByte( color );
                }
Beispiel #7
0
        /// <summary>
        /// Similar to Mat3F.LookAt( direction, Vec3F.ZAxis ) with fix for vertical direction.
        /// </summary>
        /// <param name="direction"></param>
        /// <returns></returns>
        public static void FromDirectionZAxisUp(ref Vector3F direction, out QuaternionF result)
        {
            //SphereDir sphereDir = SphereDir.FromVector( direction );
            //rotation = new Angles( 0, 0, MathFunctions.RadToDeg(
            //   -sphereDir.Horizontal ) ).ToQuat();
            //rotation *= new Angles( 0,
            //   MathFunctions.RadToDeg( sphereDir.Vertical ), 0 ).ToQuat();

            float horizontal;
            float vertical;
            {
                horizontal = MathEx.Atan2(direction.Y, direction.X);
                float dir2Length = MathEx.Sqrt(direction.X * direction.X + direction.Y * direction.Y);
                vertical = MathEx.Atan2(direction.Z, dir2Length);
            }

            //Quat horizRotation;
            float horizRotationZ;
            float horizRotationW;
            {
                float a = -horizontal * .5f;
                horizRotationZ = -MathEx.Sin(a);
                horizRotationW = MathEx.Cos(a);
                //float sz = MathFunctions.Sin( a );
                //float cz = MathFunctions.Cos( a );
                //horizRotation = new Quat( 0, 0, -sz, cz );
            }

            //Quat vertRotation;
            float vertRotationY;
            float vertRotationW;

            {
                float a = vertical * .5f;
                vertRotationY = -MathEx.Sin(a);
                vertRotationW = MathEx.Cos(a);
                //float sy = MathFunctions.Sin( a );
                //float cy = MathFunctions.Cos( a );
                //vertRotation = new Quat( 0, -sy, 0, cy );
            }

            result = new QuaternionF(
                -horizRotationZ * vertRotationY, horizRotationW * vertRotationY,
                horizRotationZ * vertRotationW, horizRotationW * vertRotationW);
            //return horizRotation * vertRotation;
        }
Beispiel #8
0
        public void ToBounds(out BoundsF result)
        {
            Vector3F a    = Point2 - Point1;
            var      dotA = Vector3F.Dot(a, a);

            if (dotA == 0)
            {
                dotA = MathEx.Epsilon;
            }

            Vector3F e = new Vector3F(
                Radius * MathEx.Sqrt(1.0f - a.X * a.X / dotA),
                Radius * MathEx.Sqrt(1.0f - a.Y * a.Y / dotA),
                Radius * MathEx.Sqrt(1.0f - a.Z * a.Z / dotA));

            result = new BoundsF(Vector3F.Min(Point1 - e, Point2 - e), Vector3F.Max(Point1 + e, Point2 + e));
        }
Beispiel #9
0
        public float GetRadius(Vector3F center)
        {
            float total = 0.0f;

            for (int i = 0; i < 3; i++)
            {
                float b0 = Math.Abs(center[i] - Minimum[i]);
                float b1 = Math.Abs(Maximum[i] - center[i]);
                if (b0 > b1)
                {
                    total += b0 * b0;
                }
                else
                {
                    total += b1 * b1;
                }
            }
            return(MathEx.Sqrt(total));
        }
Beispiel #10
0
        public static void GetNormalize(ref QuaternionF q, out QuaternionF result)
        {
            float len = MathEx.Sqrt(q.X * q.X + q.Y * q.Y + q.Z * q.Z + q.W * q.W);

            if (len != 0)
            {
                float ilength = 1.0f / len;
                result.X = q.X * ilength;
                result.Y = q.Y * ilength;
                result.Z = q.Z * ilength;
                result.W = q.W * ilength;
            }
            else
            {
                result.X = q.X;
                result.Y = q.Y;
                result.Z = q.Z;
                result.W = q.W;
            }
        }
Beispiel #11
0
        public QuaternionF GetNormalize()
        {
            QuaternionF result;
            float       len = MathEx.Sqrt(X * X + Y * Y + Z * Z + W * W);

            if (len != 0)
            {
                float ilength = 1.0f / len;
                result.X = X * ilength;
                result.Y = Y * ilength;
                result.Z = Z * ilength;
                result.W = W * ilength;
            }
            else
            {
                result.X = X;
                result.Y = Y;
                result.Z = Z;
                result.W = W;
            }
            return(result);
        }
Beispiel #12
0
 /// <summary>
 /// Calculates the length of the current instance of <see cref="Vector2F"/>.
 /// </summary>
 /// <returns>The length of the current instance of <see cref="Vector2F"/>.</returns>
 public float Length()
 {
     return(MathEx.Sqrt(X * X + Y * Y));
 }
Beispiel #13
0
 /// <summary>
 /// Calculates the square root of each component of the specified vector.
 /// </summary>
 /// <param name="v">The specified vector.</param>
 /// <returns>The vector which contains the square root of the corresponding components in the specified vector.</returns>
 public static Vector2F Sqrt(Vector2F v)
 {
     return(new Vector2F(MathEx.Sqrt(v.X), MathEx.Sqrt(v.Y)));
 }
Beispiel #14
0
 public float Length()
 {
     return(MathEx.Sqrt(X * X + Y * Y + Z * Z + W * W));
 }
Beispiel #15
0
 /// <summary>
 /// Calculates the square root of each component of the specified vector.
 /// </summary>
 /// <param name="v">The specified vector.</param>
 /// <returns>The vector which contains the square root of the corresponding components in the specified vector.</returns>
 public static Vector4F Sqrt(Vector4F v)
 {
     return(new Vector4F(MathEx.Sqrt(v.X), MathEx.Sqrt(v.Y), MathEx.Sqrt(v.Z), MathEx.Sqrt(v.W)));
 }