Пример #1
0
 public void AdditionOperator()
 {
     Vector4D a = new Vector4D(1.0, 2.0, 3.0, 4.0);
       Vector4D b = new Vector4D(2.0, 3.0, 4.0, 5.0);
       Vector4D c = a + b;
       Assert.AreEqual(new Vector4D(3.0, 5.0, 7.0, 9.0), c);
 }
Пример #2
0
        public static bool Decompose(Matrix4x4 m, out Vector3D scale, out Vector4D rotationQuaternion, out Vector3D translation)
        {
            SlimDX.Vector3 s;
            SlimDX.Quaternion r;
            SlimDX.Vector3 t;

            if (Matrix4x4ToSlimDXMatrix(m).Decompose(out s, out r, out t))
            {
                scale.x = s.X;
                scale.y = s.Y;
                scale.z = s.Z;
                rotationQuaternion.x = r.X;
                rotationQuaternion.y = r.Y;
                rotationQuaternion.z = r.Z;
                rotationQuaternion.w = r.W;
                translation.x = t.X;
                translation.y = t.Y;
                translation.z = t.Z;

                return true;
            }
            else
            {
                scale = new Vector3D(0);
                rotationQuaternion = new Vector4D(0);
                translation = new Vector3D(0);
                return false;
            }
        }
Пример #3
0
 public void Addition()
 {
     Vector4D a = new Vector4D(1.0, 2.0, 3.0, 4.0);
       Vector4D b = new Vector4D(2.0, 3.0, 4.0, 5.0);
       Vector4D c = Vector4D.Add(a, b);
       Assert.AreEqual(new Vector4D(3.0, 5.0, 7.0, 9.0), c);
 }
Пример #4
0
        public override void MouseMove(Vector2D mouseMovePos, EnumMouseButton button)
        {


            base.MouseMove(mouseMovePos, button);

            if (handleIndex == null) return;
            Vector2D p = mouseCurrPos - new Vector2D(projectedCenter.x, projectedCenter.y);
            p.x += 100;
            p.y += 100;
            switch (button)
            {
                case EnumMouseButton.Middle: movingBall.Drag(p); break;
                case EnumMouseButton.Left: movingBall.Drag(p / this.ScaleRatio); break;
                case EnumMouseButton.Right: movingBall.Drag(p); break;
            }
            Matrix4D tran = TransformController.Instance.TransformInverse * movingBall.CreateMatrix().Transpose() * TransformController.Instance.ModelMatrix;

            for (int i = 0; i < handleIndex.Count; i++)
            {
                int j = handleIndex[i];
                Vector4D q = new Vector4D((Vector3D)oldHandlePos[i], 1);
                q = tran * (q - handleCenter) + handleCenter;
                mesh.Vertices[j].Traits.Position.x = q.x;
                mesh.Vertices[j].Traits.Position.y = q.y;
                mesh.Vertices[j].Traits.Position.z = q.z;
            }

            //TriMeshUtil.SetUpNormalVertex(mesh);
            OnChanged(EventArgs.Empty);
        }
Пример #5
0
 public void Write(Vector4D value)
 {
     Write(value.X);
     Write(value.Y);
     Write(value.Z);
     Write(value.W);
 }
Пример #6
0
        public void Normalize()
        {
            Vector4D v, n1, n2;
            double magnitude;

            v = new Vector4D(3.0, 4.0, 0.0, 0.0);
            n1 = v.Normalize();
            n2 = v.Normalize(out magnitude);
            Assert.AreEqual(1.0, n1.Magnitude, 1e-14);
            Assert.AreEqual(1.0, n2.Magnitude, 1e-14);
            Assert.AreEqual(5.0, magnitude, 1e-14);

            v = new Vector4D(3.0, 0.0, 4.0, 0.0);
            n1 = v.Normalize();
            n2 = v.Normalize(out magnitude);
            Assert.AreEqual(1.0, n1.Magnitude, 1e-14);
            Assert.AreEqual(1.0, n2.Magnitude, 1e-14);
            Assert.AreEqual(5.0, magnitude, 1e-14);

            v = new Vector4D(0.0, 3.0, 4.0, 0.0);
            n1 = v.Normalize();
            n2 = v.Normalize(out magnitude);
            Assert.AreEqual(1.0, n1.Magnitude, 1e-14);
            Assert.AreEqual(1.0, n2.Magnitude, 1e-14);
            Assert.AreEqual(5.0, magnitude, 1e-14);

            v = new Vector4D(0.0, 0.0, 3.0, 4.0);
            n1 = v.Normalize();
            n2 = v.Normalize(out magnitude);
            Assert.AreEqual(1.0, n1.Magnitude, 1e-14);
            Assert.AreEqual(1.0, n2.Magnitude, 1e-14);
            Assert.AreEqual(5.0, magnitude, 1e-14);
        }
Пример #7
0
 public void Construct2()
 {
     Vector4D v = new Vector4D(new Vector2D(1.0, 2.0), 3.0, 4.0);
     Assert.AreEqual(1.0, v.X);
     Assert.AreEqual(2.0, v.Y);
     Assert.AreEqual(3.0, v.Z);
     Assert.AreEqual(4.0, v.W);
 }
Пример #8
0
		public void Drag(Vector2D pt)
		{
			endPt = pt;
			endVec = MapToSphere(pt);

			double epsilon = 1.0e-5;
			Vector3D prep = startVec.Cross(endVec);

			if (prep.Length() > epsilon)
				quat = new Vector4D(prep, startVec.Dot(endVec));
			else
				quat = new Vector4D();
		}
        //from openFrameworks
        private Vector4D MakeRotate(Vector3D from, Vector3D to)
        {
            Vector4D quat = new Vector4D();
            Vector3D sourceVector = from / from.Length;
            Vector3D targetVector = to / to.Length;

            // Now let's get into the real stuff
            // Use "dot product plus one" as test as it can be re-used later on

            double dotProdPlus1 = 1.0 +  sourceVector.dot(targetVector);

            // Check for degenerate case of full u-turn. Use epsilon for detection
            if (dotProdPlus1 < 1e-7) {

                // Get an orthogonal vector of the given vector
                // in a plane with maximum vector coordinates.
                // Then use it as quaternion axis with pi angle
                // Trick is to realize one value at least is >0.6 for a normalized vector.
                if (fabs(sourceVector.x) < 0.6) {
                    const double norm = sqrt(1.0 - sourceVector.x * sourceVector.x);
                    _v.x = 0.0;
                    _v.y = sourceVector.z / norm;
                    _v.z = -sourceVector.y / norm;
                    _v.w = 0.0;
                } else if (fabs(sourceVector.y) < 0.6) {
                    const double norm = sqrt(1.0 - sourceVector.y * sourceVector.y);
                    _v.x = -sourceVector.z / norm;
                    _v.y = 0.0;
                    _v.z = sourceVector.x / norm;
                    _v.w = 0.0;
                } else {
                    const double norm = sqrt(1.0 - sourceVector.z * sourceVector.z);
                    _v.x = sourceVector.y / norm;
                    _v.y = -sourceVector.x / norm;
                    _v.z = 0.0;
                    _v.w = 0.0;
                }
            }

            else {
                // Find the shortest angle quaternion that transforms normalized vectors
                // into one other. Formula is still valid when vectors are colinear
                const double s = sqrt(0.5 * dotProdPlus1);
                const ofVec3f tmp = sourceVector.getCrossed(targetVector) / (2.0 * s);
                _v.x = tmp.x;
                _v.y = tmp.y;
                _v.z = tmp.z;
                _v.w = s;
            }
            return quat;
        }
Пример #10
0
        public void AreEqual()
        {
            double originalEpsilon = Numeric.EpsilonD;
              Numeric.EpsilonD = 1e-8;

              Vector4D u = new Vector4D(1.0, 2.0, 3.0, 4.0);
              Vector4D v = new Vector4D(1.000001, 2.000001, 3.000001, 4.000001);
              Vector4D w = new Vector4D(1.00000001, 2.00000001, 3.00000001, 4.00000001);

              Assert.IsTrue(Vector4D.AreNumericallyEqual(u, u));
              Assert.IsFalse(Vector4D.AreNumericallyEqual(u, v));
              Assert.IsTrue(Vector4D.AreNumericallyEqual(u, w));

              Numeric.EpsilonD = originalEpsilon;
        }
Пример #11
0
 public void ResolveShadows(Image shadowCastersTexture, RenderImage result, Vector2D lightPosition,
                            bool attenuateShadows, Image mask, Vector4D maskProps, Vector4D diffuseColor)
 {
     resolveShadowsEffect.Parameters["AttenuateShadows"].SetValue(attenuateShadows ? 0 : 1);
     resolveShadowsEffect.Parameters["MaskProps"].SetValue(maskProps);
     resolveShadowsEffect.Parameters["DiffuseColor"].SetValue(diffuseColor);
     //Gorgon.CurrentRenderTarget.BlendingMode = BlendingModes.None;
     ExecuteTechnique(shadowCastersTexture, distancesRT, "ComputeDistances");
     ExecuteTechnique(distancesRT.Image, distortRT, "Distort");
     ApplyHorizontalReduction(distortRT, shadowMap);
     ExecuteTechnique(mask, result, "DrawShadows", shadowMap);
     //ExecuteTechnique(shadowsRT.Image, processedShadowsRT, "BlurHorizontally");
     //ExecuteTechnique(processedShadowsRT.Image, result, "BlurVerticallyAndAttenuate");
     Gorgon.CurrentShader = null;
 }
Пример #12
0
        public static Vector4D BBox2DtoVVVV(this PXCMRectI32 pt, Vector2D ImageSize)
        {
            var bbox2d = new Vector4D();

            bbox2d.z = pt.w / (float)ImageSize.x;
            bbox2d.w = pt.h / (float)ImageSize.y;

            bbox2d.x = (pt.x / (float)ImageSize.x * 2.0f - 1.0f) + bbox2d.z;
            bbox2d.y = (1.0f - pt.y / (float)ImageSize.y * 2.0f) - bbox2d.w;

            bbox2d.z *= 2;
            bbox2d.w *= 2;

            return bbox2d;
        }
Пример #13
0
        public void AbsoluteStatic()
        {
            Vector4D v = new Vector4D(-1, -2, -3, -4);
              Vector4D absoluteV = Vector4D.Absolute(v);

              Assert.AreEqual(1, absoluteV.X);
              Assert.AreEqual(2, absoluteV.Y);
              Assert.AreEqual(3, absoluteV.Z);
              Assert.AreEqual(4, absoluteV.W);

              v = new Vector4D(1, 2, 3, 4);
              absoluteV = Vector4D.Absolute(v);
              Assert.AreEqual(1, absoluteV.X);
              Assert.AreEqual(2, absoluteV.Y);
              Assert.AreEqual(3, absoluteV.Z);
              Assert.AreEqual(4, absoluteV.W);
        }
Пример #14
0
        public void Absolute()
        {
            Vector4D v = new Vector4D(-1, -2, -3, -4);
              v.Absolute();

              Assert.AreEqual(1, v.X);
              Assert.AreEqual(2, v.Y);
              Assert.AreEqual(3, v.Z);
              Assert.AreEqual(4, v.W);

              v = new Vector4D(1, 2, 3, 4);
              v.Absolute();
              Assert.AreEqual(1, v.X);
              Assert.AreEqual(2, v.Y);
              Assert.AreEqual(3, v.Z);
              Assert.AreEqual(4, v.W);
        }
Пример #15
0
        public void Magnitude()
        {
            Vector4D v = new Vector4D(3.0, 4.0, 0.0, 0.0);
            Assert.AreEqual(25.0, v.MagnitudeSquared, 1e-14);
            Assert.AreEqual(5.0, v.Magnitude, 1e-14);

            v = new Vector4D(3.0, 0.0, 4.0, 0.0);
            Assert.AreEqual(25.0, v.MagnitudeSquared, 1e-14);
            Assert.AreEqual(5.0, v.Magnitude, 1e-14);

            v = new Vector4D(0.0, 3.0, 4.0, 0.0);
            Assert.AreEqual(25.0, v.MagnitudeSquared, 1e-14);
            Assert.AreEqual(5.0, v.Magnitude, 1e-14);

            v = new Vector4D(0.0, 0.0, 3.0, 4.0);
            Assert.AreEqual(25.0, v.MagnitudeSquared, 1e-14);
            Assert.AreEqual(5.0, v.Magnitude, 1e-14);
        }
Пример #16
0
        public static TriMesh BulidSphere(string data)//通过文件建立Trimesh
        {
            data = "D:\\atet.obj";
            TriMesh sphere= FromObjFile(data);
            Matrix4D m = new Matrix4D();
            m[0, 0] = 0.01; m[1, 1] = 0.01; m[2, 2] = 0.01;
            Vector4D v = new Vector4D();
            for (int i = 0; i < sphere.Vertices.Count; i++)//对整个球进行缩放
            {
                v.x = sphere.Vertices[i].Traits.Position.x;
                v.y = sphere.Vertices[i].Traits.Position.y;
                v.z = sphere.Vertices[i].Traits.Position.z;
                v.w = 1;
                v *= m;
                sphere.Vertices[i].Traits.Position.x = v.x;
                sphere.Vertices[i].Traits.Position.y = v.y;
                sphere.Vertices[i].Traits.Position.z = v.z;
             }

            return sphere;
        }
Пример #17
0
        public SplineCurve3D(int degree, double[] knots, Vector4D[] controlPoints)
        {
            this.bsplineD_0 = new BSplineD(degree, knots);
            this.point3D_0  = new Point3D[controlPoints.Length];
            this.double_0   = new double[controlPoints.Length];
            bool flag = false;

            for (int index = controlPoints.Length - 1; index >= 0; --index)
            {
                Vector4D controlPoint = controlPoints[index];
                this.point3D_0[index] = new Point3D(controlPoint.X, controlPoint.Y, controlPoint.Z);
                double w = controlPoint.W;
                this.double_0[index] = w;
                flag = flag || w != 1.0;
            }
            if (flag)
            {
                return;
            }
            this.double_0 = (double[])null;
        }
Пример #18
0
        public override void DrawInternal(
            DrawContext.Wireframe context,
            IWireframeGraphicsFactory graphicsFactory)
        {
            if (this.list_0.Count <= 0)
            {
                return;
            }
            Polygon2D clipBoundary = this.GetClipBoundary((DrawContext)context);

            if (clipBoundary == null)
            {
                return;
            }
            Matrix4D             preTransform        = this.method_15();
            IClippingTransformer clippingTransformer = (IClippingTransformer)context.GetTransformer().Clone();

            clippingTransformer.SetPreTransform(preTransform);
            Matrix4D matrix = clippingTransformer.Matrix;

            WW.Math.Point3D point             = new WW.Math.Point3D(-0.5, -0.5, 0.0);
            Vector4D        transformedOrigin = matrix.TransformTo4D(point);
            Vector4D        transformedXAxis  = matrix.TransformTo4D(point + WW.Math.Vector3D.XAxis);
            Vector4D        transformedYAxis  = matrix.TransformTo4D(point + WW.Math.Vector3D.YAxis);

            WW.Math.Geometry.Polyline3D polyline = new WW.Math.Geometry.Polyline3D(true);
            foreach (WW.Math.Point2D point2D in (List <WW.Math.Point2D>)clipBoundary)
            {
                polyline.Add((WW.Math.Point3D)point2D);
            }
            IList <Polyline4D> polyline4DList = clippingTransformer.Transform(polyline, true);

            if (polyline4DList.Count <= 0)
            {
                return;
            }
            Polyline4D imageBoundary = polyline4DList[0];

            graphicsFactory.CreateImage(this, context, this.bool_2 ? imageBoundary : (Polyline4D)null, imageBoundary, transformedOrigin, transformedXAxis, transformedYAxis);
        }
        public void Evaluate(int SpreadMax)
        {
            if (FRectangle.IsChanged || FMaxBins.IsChanged || FDiscardBelow.IsChanged || FBox.IsChanged)
            {
                var binlist    = new List <RectBin>();
                var rectlistin = new RectXywhFlipped[FRectangle.SliceCount];
                for (int i = 0; i < FRectangle.SliceCount; i++)
                {
                    rectlistin[i] = new RectXywhFlipped
                    {
                        FWidth  = FRectangle[i].x,
                        FHeight = FRectangle[i].y,
                        ID      = i,
                        Left    = 0, Top = 0, Flipped = false
                    };
                }
                FSuccess[0] = RectPackHelper.Pack(rectlistin, FBox[0], FDiscardBelow[0], binlist, FMaxBins[0]);

                FPacked.SliceCount  = binlist.Count;
                FID.SliceCount      = binlist.Count;
                FDim.SliceCount     = binlist.Count;
                FFlipped.SliceCount = binlist.Count;

                for (int i = 0; i < binlist.Count; i++)
                {
                    FPacked[i].SliceCount  = binlist[i].Rects.Count;
                    FID[i].SliceCount      = binlist[i].Rects.Count;
                    FFlipped[i].SliceCount = binlist[i].Rects.Count;
                    FDim[i] = binlist[i].Size;

                    for (int j = 0; j < FPacked[i].SliceCount; j++)
                    {
                        var rect = binlist[i].Rects[j];
                        FPacked[i][j]  = new Vector4D(rect.Left, rect.Top, rect.Width(), rect.Height());
                        FFlipped[i][j] = rect.Flipped;
                        FID[i][j]      = rect.ID;
                    }
                }
            }
        }
Пример #20
0
        private void OnXyzwChanged()
        {
            if (_isUpdating)
            {
                return;
            }

            _isUpdating = true;
            try
            {
                if (_vectorType == typeof(Vector4))
                {
                    Value = new Vector4((float)X, (float)Y, (float)Z, (float)W);
                }
                else if (_vectorType == typeof(Quaternion))
                {
                    Value = new Quaternion((float)X, (float)Y, (float)Z, (float)W);
                }
                else if (_vectorType == typeof(Vector4))
                {
                    Value = new Vector4((float)X, (float)Y, (float)Z, (float)W);
                }
                else if (_vectorType == typeof(Vector4D))
                {
                    Value = new Vector4D(X, Y, Z, W);
                }
                else if (_vectorType == typeof(Quaternion))
                {
                    Value = new Quaternion((float)W, (float)X, (float)Y, (float)Z);
                }
                else if (_vectorType == typeof(QuaternionD))
                {
                    Value = new QuaternionD(W, X, Y, Z);
                }
            }
            finally
            {
                _isUpdating = false;
            }
        }
Пример #21
0
        public void ProjectTo()
        {
            // Project (1, 1, 1) to axes
            Vector4D v          = new Vector4D(1, 1, 1, 0);
            Vector4D projection = Vector4D.ProjectTo(v, Vector4D.UnitX);

            Assert.AreEqual(Vector4D.UnitX, projection);
            projection = Vector4D.ProjectTo(v, Vector4D.UnitY);
            Assert.AreEqual(Vector4D.UnitY, projection);
            projection = Vector4D.ProjectTo(v, Vector4D.UnitZ);
            Assert.AreEqual(Vector4D.UnitZ, projection);

            // Project axes to (1, 1, 1)
            Vector4D expected = new Vector4D(1, 1, 1, 0) / 3.0;

            projection = Vector4D.ProjectTo(Vector4D.UnitX, v);
            Assert.AreEqual(expected, projection);
            projection = Vector4D.ProjectTo(Vector4D.UnitY, v);
            Assert.AreEqual(expected, projection);
            projection = Vector4D.ProjectTo(Vector4D.UnitZ, v);
            Assert.AreEqual(expected, projection);
        }
Пример #22
0
        public void SerializationJson()
        {
            Vector4D v1 = new Vector4D(0.1, -0.2, 2, 40);
            Vector4D v2;

            string fileName = "SerializationVector4D.json";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            var serializer = new DataContractJsonSerializer(typeof(Vector4D));

            using (var stream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write))
                serializer.WriteObject(stream, v1);

            using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                v2 = (Vector4D)serializer.ReadObject(stream);

            Assert.AreEqual(v1, v2);
        }
Пример #23
0
        private Matrix3D QuatToMatrix3d(Vector4D q)
        {
            double n = q.Dot(q);
            double s = (n > 0.0) ? (2.0 / n) : 0.0f;

            double xs, ys, zs;
            double wx, wy, wz;
            double xx, xy, xz;
            double yy, yz, zz;

            xs = q.x * s;  ys = q.y * s;  zs = q.z * s;
            wx = q.w * xs; wy = q.w * ys; wz = q.w * zs;
            xx = q.x * xs; xy = q.x * ys; xz = q.x * zs;
            yy = q.y * ys; yz = q.y * zs; zz = q.z * zs;

            Matrix3D m = new Matrix3D();

            m[0, 0] = 1.0 - (yy + zz); m[1, 0] = xy - wz;  m[2, 0] = xz + wy;
            m[0, 1] = xy + wz;  m[1, 1] = 1.0 - (xx + zz); m[2, 1] = yz - wx;
            m[0, 2] = xz - wy;  m[1, 2] = yz + wx;  m[2, 2] = 1.0 - (xx + yy);
            return(m);
        }
Пример #24
0
        private void method_4(
            Graphics graphics,
            BlinnClipper4D drawingBoundsClipper,
            Class385 context,
            Vector4D t1,
            Vector4D t2)
        {
            IList <Segment4D> segment4DList = drawingBoundsClipper.Clip(new Segment4D(t1, t2));

            if (segment4DList.Count <= 0)
            {
                return;
            }
            Pen pen = this.method_2(context);

            foreach (Segment4D segment4D in (IEnumerable <Segment4D>)segment4DList)
            {
                Point3D start = (Point3D)segment4D.Start;
                Point3D end   = (Point3D)segment4D.End;
                graphics.DrawLine(pen, (float)start.X, (float)start.Y, (float)end.X, (float)end.Y);
            }
        }
Пример #25
0
        public void Constructors()
        {
            Vector4D v = new Vector4D();

            Assert.AreEqual(0.0, v.X);
            Assert.AreEqual(0.0, v.Y);
            Assert.AreEqual(0.0, v.Z);
            Assert.AreEqual(0.0, v.W);

            v = new Vector4D(2.3);
            Assert.AreEqual(2.3, v.X);
            Assert.AreEqual(2.3, v.Y);
            Assert.AreEqual(2.3, v.Z);
            Assert.AreEqual(2.3, v.W);

            v = new Vector4D(1.0, 2.0, 3.0, 4.0);
            Assert.AreEqual(1.0, v.X);
            Assert.AreEqual(2.0, v.Y);
            Assert.AreEqual(3.0, v.Z);
            Assert.AreEqual(4.0, v.W);

            v = new Vector4D(new[] { 1.0, 2.0, 3.0, 4.0 });
            Assert.AreEqual(1.0, v.X);
            Assert.AreEqual(2.0, v.Y);
            Assert.AreEqual(3.0, v.Z);
            Assert.AreEqual(4.0, v.W);

            v = new Vector4D(new List <double>(new[] { 1.0, 2.0, 3.0, 4.0 }));
            Assert.AreEqual(1.0, v.X);
            Assert.AreEqual(2.0, v.Y);
            Assert.AreEqual(3.0, v.Z);
            Assert.AreEqual(4.0, v.W);

            v = new Vector4D(new Vector3D(1.0, 2.0, 3.0), 4.0);
            Assert.AreEqual(1.0, v.X);
            Assert.AreEqual(2.0, v.Y);
            Assert.AreEqual(3.0, v.Z);
            Assert.AreEqual(4.0, v.W);
        }
Пример #26
0
        protected virtual Vector4D getColorForFeature(Feature input, FilterEnv env)
        {
            Vector4D result = overall_color;

            if (is_batch)
            {
                result = batch_feature_color;
            }
            else if (getColorScript() != null)
            {
                ScriptResult r = env.getScriptEngine().run(getColorScript(), input, env);
                if (r.isValid())
                {
                    result = r.asVec4();
                }
                else
                {
                    env.getReport().error(r.asString());
                }
            }

            return(result);
        }
Пример #27
0
        public static TriMesh BulidSphere(string data)//通过文件建立Trimesh
        {
            data = "D:\\atet.obj";
            TriMesh  sphere = FromObjFile(data);
            Matrix4D m      = new Matrix4D();

            m[0, 0] = 0.01; m[1, 1] = 0.01; m[2, 2] = 0.01;
            Vector4D v = new Vector4D();

            for (int i = 0; i < sphere.Vertices.Count; i++)//对整个球进行缩放
            {
                v.x = sphere.Vertices[i].Traits.Position.x;
                v.y = sphere.Vertices[i].Traits.Position.y;
                v.z = sphere.Vertices[i].Traits.Position.z;
                v.w = 1;
                v  *= m;
                sphere.Vertices[i].Traits.Position.x = v.x;
                sphere.Vertices[i].Traits.Position.y = v.y;
                sphere.Vertices[i].Traits.Position.z = v.z;
            }

            return(sphere);
        }
Пример #28
0
        public void SerializationXml()
        {
            Vector4D v1 = new Vector4D(1.0, 2.0, 3.0, 4.0);
            Vector4D v2;
            string   fileName = "SerializationVector4D.xml";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            XmlSerializer serializer = new XmlSerializer(typeof(Vector4D));
            StreamWriter  writer     = new StreamWriter(fileName);

            serializer.Serialize(writer, v1);
            writer.Close();

            serializer = new XmlSerializer(typeof(Vector4D));
            FileStream fileStream = new FileStream(fileName, FileMode.Open);

            v2 = (Vector4D)serializer.Deserialize(fileStream);
            Assert.AreEqual(v1, v2);
        }
        //gets the shortest quaternion between two vectors
        public Vector4D qGetQuaternionToPoint(Vector3D vecA, Vector3D vecB)
        {
            Vector4D result;

            if ((vecA.x == 0 && vecA.y == 0 && vecA.z == 0) || (vecB.x == 0 && vecB.y == 0 && vecB.z == 0))
            {
                result = new Vector4D(0, 0, 0, 1);
            }
            else
            {
                vecA = normalizeVector(vecA);
                vecB = normalizeVector(vecB);
                double   d    = dotVectors(vecA, vecB);
                double   s    = Math.Sqrt((1 + d) * 2);
                double   invs = 1 / s;
                Vector3D c    = crossVectors(vecA, vecB);
                result.x = c.x * invs;
                result.y = c.y * invs;
                result.z = c.z * invs;
                result.w = s * 0.5;
            }
            return(qUnify(result));
        }
Пример #30
0
        public void MultiplicationOperator()
        {
            double x = 23.4;
            double y = -11.0;
            double z = 6.0;
            double w = 0.4;
            double s = 13.3;

            Vector4D v = new Vector4D(x, y, z, w);

            Vector4D u = v * s;

            Assert.AreEqual(x * s, u.X);
            Assert.AreEqual(y * s, u.Y);
            Assert.AreEqual(z * s, u.Z);
            Assert.AreEqual(w * s, u.W);

            u = s * v;
            Assert.AreEqual(x * s, u.X);
            Assert.AreEqual(y * s, u.Y);
            Assert.AreEqual(z * s, u.Z);
            Assert.AreEqual(w * s, u.W);
        }
Пример #31
0
        public Point?VectorToScreenPosition(Vector3D vector)
        {
            if (!isReady)
            {
                return(null);
            }

            Vector4D v = new Vector4D(vector, 1.0);

            v = Vector4D.TransformCoordinate(ref v, ref transform);
            if (v.W > 0)
            {
                v.MultiplyBy(1.0 / v.W);

                Point position = new Point(
                    (int)(view.Width * (v.X + 1.0) * 0.5),
                    (int)(view.Height * (1.0 - v.Y) * 0.5));

                // check if the projected position is outside the bounds of the view

                if (position.X < 0 ||
                    position.X > view.Width ||
                    position.Y < 0 ||
                    position.Y > view.Height)
                {
                    return(null);
                }

                return(position);
            }
            else
            {
                // position is behind camera
                return(null);
            }
        }
Пример #32
0
        public void SerializationXml2()
        {
            Vector4D v1 = new Vector4D(0.1, -0.2, 2, 40);
            Vector4D v2;

            string fileName = "SerializationVector4D_DataContractSerializer.xml";

            if (File.Exists(fileName))
            {
                File.Delete(fileName);
            }

            var serializer = new DataContractSerializer(typeof(Vector4D));

            using (var stream = new FileStream(fileName, FileMode.CreateNew, FileAccess.Write))
                using (var writer = XmlDictionaryWriter.CreateTextWriter(stream, Encoding.UTF8))
                    serializer.WriteObject(writer, v1);

            using (var stream = new FileStream(fileName, FileMode.Open, FileAccess.Read))
                using (var reader = XmlDictionaryReader.CreateTextReader(stream, new XmlDictionaryReaderQuotas()))
                    v2 = (Vector4D)serializer.ReadObject(reader);

            Assert.AreEqual(v1, v2);
        }
        public override void ProcessImage(RenderImage image)
        {
            if (_noiseBase == null)
                GenerateNoise(32);

            var shadowColor = new Vector4D(1, 0, 0, 1);
            var midtoneColor = new Vector4D(0, 0, 1, 1);
            var highlightColor = new Vector4D(0, 1, 0, 1);
            Gorgon.CurrentRenderTarget = copyImage;
            Gorgon.CurrentShader = _shader;
            _shader.Parameters["xTime"].SetValue(_duration/20);
            _shader.Parameters["xOvercast"].SetValue(1.0f);
            _shader.Parameters["NoiseTexture"].SetValue(_noiseBase);
            _shader.Parameters["SceneTexture"].SetValue(image);
            //_shader.Parameters["shadowColor"].SetValue(shadowColor);
            //_shader.Parameters["midtoneColor"].SetValue(midtoneColor);
            //_shader.Parameters["highlightColor"].SetValue(highlightColor);

            _noiseBase.Blit(0, 0, image.Width, image.Height);
            Gorgon.CurrentShader = null;
            Gorgon.CurrentRenderTarget = null;

            image.CopyFromImage(copyImage.Image);
        }
Пример #34
0
        public override void DrawInternal(
            DrawContext.Wireframe context,
            IWireframeGraphicsFactory graphicsFactory)
        {
            IList <Polyline4D> polyline4DList = context.GetTransformer().Transform(this.method_14(), true);

            if (polyline4DList == null || polyline4DList.Count <= 0)
            {
                return;
            }
            IList <Polyline4D> polylines4D;
            IList <IShape4D>   shapes;

            this.GetPolylines4D((DrawContext)context, context.GetTransformer(), out polylines4D, out shapes);
            IClippingTransformer clippingTransformer = (IClippingTransformer)context.GetTransformer().Clone();
            Matrix4D             preTransform        = Transformation4D.Translation((WW.Math.Vector3D) this.point3D_3);

            clippingTransformer.SetPreTransform(preTransform);
            Matrix4D matrix = clippingTransformer.Matrix;

            WW.Math.Point3D zero = WW.Math.Point3D.Zero;
            Vector4D        transformedOrigin = matrix.TransformTo4D(zero);
            Vector4D        transformedXAxis  = matrix.TransformTo4D(zero + WW.Math.Vector3D.XAxis);
            Vector4D        transformedYAxis  = matrix.TransformTo4D(zero + WW.Math.Vector3D.YAxis);

            graphicsFactory.CreateScalableImage((DxfEntity)this, context, (IBitmapProvider)this, polyline4DList[0], new Size2D((this.point3D_2 - this.point3D_3).GetLength(), (this.point3D_0 - this.point3D_3).GetLength()), transformedOrigin, transformedXAxis, transformedYAxis);
            if (polylines4D.Count > 0)
            {
                graphicsFactory.CreatePath((DxfEntity)this, context, context.GetPlotColor((DxfEntity)this), false, polylines4D, false, true);
            }
            if (shapes == null)
            {
                return;
            }
            Class940.smethod_23((IPathDrawer) new ns0.Class0((DxfEntity)this, context, graphicsFactory), (IEnumerable <IShape4D>)shapes, this.Color.ToColor(), context.GetLineWeight((DxfEntity)this));
        }
Пример #35
0
 private Vector4D Limit(Vector4D color)
 {
     if (Math.Max(color.X, Math.Max(color.Y, Math.Max(color.Z, color.W))) <= 255)
         return color;
     float x, y, z, w;
     x = color.X;
     y = color.Y;
     z = color.Z;
     w = color.W;
     //RGB Max
     var max = Math.Max(y, Math.Max(z, w));
     if(max > 255)
     {
         var f = 255/max;
         y = f*y;
         z = f*z;
         w = f*w;
     }
     if (x > 255)
         x = 255;
     return new Vector4D(x, y, z, w);
 }
Пример #36
0
 private Vector4D VariedPositiveVector4D(Vector4D value, float variance)
 {
     return new Vector4D(
         VariedPositiveFloat(value.X, variance),
         VariedPositiveFloat(value.Y, variance),
         VariedPositiveFloat(value.Z, variance),
         VariedPositiveFloat(value.W, variance)
         );
 }
Пример #37
0
            public void Update(float frameTime)
            {
                Age += frameTime;
                if (Age >= Lifetime)
                    Alive = false;
                Velocity += Acceleration*frameTime;
                RadialVelocity += RadialAcceleration*frameTime;
                TangentialVelocity += TangentialAcceleration*frameTime;

                //Calculate delta p due to radial velocity
                var positionRelativeToEmitter = Position - EmitterPosition;
                var deltaRadial = RadialVelocity * frameTime;
                var deltaPosition = positionRelativeToEmitter*(deltaRadial/positionRelativeToEmitter.Length);

                //Calculate delta p due to tangential velocity
                var radius = positionRelativeToEmitter.Length;
                if (radius > 0)
                {
                    var theta = MathUtility.ATan(positionRelativeToEmitter.Y, positionRelativeToEmitter.X);
                    theta += TangentialVelocity*frameTime;
                    deltaPosition += new Vector2D(radius*MathUtility.Cos(theta), radius*MathUtility.Sin(theta))
                                     - positionRelativeToEmitter;
                }
                //Calculate delta p due to Velocity
                deltaPosition += Velocity*frameTime;
                Position += deltaPosition;
                Spin += SpinVelocity*frameTime;
                Size += SizeDelta*frameTime;
                Color += ColorDelta*frameTime;
            }
 public static void Write(this BitStream stream, Vector4D vec)
 {
     stream.WriteDouble(vec.X);
     stream.WriteDouble(vec.Y);
     stream.WriteDouble(vec.Z);
     stream.WriteDouble(vec.W);
 }
Пример #39
0
 public void CreateLine(DxfEntity entity, Vector4D start, Vector4D end)
 {
     this.DrawLine(start, end);
 }
Пример #40
0
 public override void Write(Vector4D value, int stride)
 {
     Write((double *)&value, stride);
 }
Пример #41
0
 public static Vector3D XYZ(this Vector4D vec)
 {
     return(new Vector3D(vec.X, vec.Y, vec.Z));
 }
Пример #42
0
		protected static Vector4D unpackVector4D(byte[] bytes, ref int start)
		{
			var v = new Vector4D();
			v.x = unpackDouble(bytes, ref start);
			v.y = unpackDouble(bytes, ref start);
			v.z = unpackDouble(bytes, ref start);
			v.w = unpackDouble(bytes, ref start);
			return v;
		}
Пример #43
0
 public void setColor(Vector4D value);
Пример #44
0
        public void Draw_Camera(Camera camera, string camera_type,
                                Matrix4x4 model_to_world,
                                Matrix4x4 world_to_view,
                                Matrix4x4 view_to_screen)
        {
            double semi_width = camera.Width / 2, semi_height = camera.Height / 2;
            double ratio = camera.Z_Far / camera.Z_Near;

            Vector4D origin = camera.World_Origin;
            Vector4D near_top_left_point     = origin + new Vector4D(-semi_width, semi_height, camera.Z_Near);
            Vector4D near_top_right_point    = origin + new Vector4D(semi_width, semi_height, camera.Z_Near);
            Vector4D near_bottom_left_point  = origin + new Vector4D(-semi_width, -semi_height, camera.Z_Near);
            Vector4D near_bottom_right_point = origin + new Vector4D(semi_width, -semi_height, camera.Z_Near);

            if (camera.Draw_Near_View || camera.Draw_Entire_View)
            {
                Edge near_top_left_edge     = new Edge(origin, near_top_left_point);
                Edge near_top_right_edge    = new Edge(origin, near_top_right_point);
                Edge near_bottom_left_edge  = new Edge(origin, near_bottom_left_point);
                Edge near_bottom_right_edge = new Edge(origin, near_bottom_right_point);
                Edge near_top_edge          = new Edge(near_top_left_point, near_top_right_point);
                Edge near_bottom_edge       = new Edge(near_bottom_left_point, near_bottom_right_point);
                Edge near_left_edge         = new Edge(near_top_left_point, near_bottom_left_point);
                Edge near_right_edge        = new Edge(near_top_right_point, near_bottom_right_point);

                /*
                 * Draw_Edge(near_top_left_edge, camera_type);
                 * Draw_Edge(near_top_right_edge, camera_type);
                 * Draw_Edge(near_bottom_left_edge, camera_type);
                 * Draw_Edge(near_bottom_right_edge, camera_type);
                 * Draw_Edge(near_top_edge, camera_type);
                 * Draw_Edge(near_bottom_edge, camera_type);
                 * Draw_Edge(near_left_edge, camera_type);
                 * Draw_Edge(near_right_edge, camera_type);
                 */
            }
            if (camera.Draw_Entire_View)
            {
                double semi_width_ratio = semi_width * ratio, semi_height_ratio = semi_height * ratio;

                Vector4D far_top_left_point     = origin + new Vector4D(-semi_width_ratio, semi_height_ratio, camera.Z_Far);
                Vector4D far_top_right_point    = origin + new Vector4D(semi_width_ratio, semi_height_ratio, camera.Z_Far);
                Vector4D far_bottom_left_point  = origin + new Vector4D(-semi_width_ratio, -semi_height_ratio, camera.Z_Far);
                Vector4D far_bottom_right_point = origin + new Vector4D(semi_width_ratio, -semi_height_ratio, camera.Z_Far);

                Edge far_top_left_edge     = new Edge(near_top_left_point, far_top_left_point);
                Edge far_top_right_edge    = new Edge(near_top_right_point, far_top_right_point);
                Edge far_bottom_left_edge  = new Edge(near_bottom_left_point, far_bottom_left_point);
                Edge far_bottom_right_edge = new Edge(near_bottom_right_point, far_bottom_right_point);
                Edge far_top_edge          = new Edge(far_top_left_point, far_top_right_point);
                Edge far_bottom_edge       = new Edge(far_bottom_left_point, far_bottom_right_point);
                Edge far_left_edge         = new Edge(far_top_left_point, far_bottom_left_point);
                Edge far_right_edge        = new Edge(far_top_right_point, far_bottom_right_point);

                /*
                 * Draw_Edge(far_top_left_edge, camera_type);
                 * Draw_Edge(far_top_right_edge, camera_type);
                 * Draw_Edge(far_bottom_left_edge, camera_type);
                 * Draw_Edge(far_bottom_right_edge, camera_type);
                 * Draw_Edge(far_top_edge, camera_type);
                 * Draw_Edge(far_bottom_edge, camera_type);
                 * Draw_Edge(far_left_edge, camera_type);
                 * Draw_Edge(far_right_edge, camera_type);*/
            }
        }
Пример #45
0
 private WW.Math.Point2D method_6(Vector4D point)
 {
     return(this.xamlExporter_0.matrix4D_0.TransformToPoint2D(point));
 }
Пример #46
0
 public static Vector4 AsSystemVector(this Vector4D v) => new Vector4((float)v.x, (float)v.y, (float)v.z, (float)v.w);
Пример #47
0
 private Color ToColor(Vector4D color)
 {
     color = Limit(color);
     return Color.FromArgb((int) color.X, (int)color.Y, (int)color.Z, (int)color.W);
 }
Пример #48
0
 public void FromVector4( Vector4D a )
 {
     x = a.x; y = a.y; z = a.z; w = a.w;
 }
Пример #49
0
 public void End()
 {
     quat = new Vector4D();
     type = MotionType.None;
 }
Пример #50
0
        public bool StartMoving()
        {
            // find closest selected vertex
            OpenGLProjector projector = new OpenGLProjector();
            TriMesh         m         = this.mesh;

            CRectangle viewport = new CRectangle(0, 0, Width, Height);
            double     eps      = ToolSetting.ToolsSetting.DepthTolerance;
            double     minDis   = double.MaxValue;
            int        minIndex = -1;

            for (int i = 0; i < m.Vertices.Count; i++)
            {
                if (m.Vertices[i].Traits.SelectedFlag == 0)
                {
                    continue;
                }

                Vector3D v3d = projector.Project(m.Vertices[i].Traits.Position);
                Vector2D v   = new Vector2D(v3d.x, v3d.y);

                if (!viewport.Contains((int)v.x, (int)v.y))
                {
                    continue;
                }
                if (projector.GetDepthValue((int)v.x, (int)v.y) - v3d.z < eps)
                {
                    continue;
                }

                double dis = (v - mouseDownPos).Length();
                if (dis < minDis)
                {
                    minDis   = dis;
                    minIndex = i;
                }
            }

            if (minIndex == -1)
            {
                handleIndex = null;
                oldHandlePos.Clear();
                return(false);
            }

            // find boundary box
            int flag = m.Vertices[minIndex].Traits.SelectedFlag;

            handleIndex.Clear();
            oldHandlePos.Clear();

            Vector3D c = new Vector3D(0, 0, 0);

            for (int i = 0; i < m.Vertices.Count; i++)
            {
                if (m.Vertices[i].Traits.SelectedFlag == flag)
                {
                    Vector3D p = new Vector3D(m.Vertices[i].Traits.Position.x, m.Vertices[i].Traits.Position.y, m.Vertices[i].Traits.Position.z);
                    handleIndex.Add(i);
                    oldHandlePos.Add(p);
                    c += p;
                }
            }

            c              /= (double)handleIndex.Count;
            handleCenter    = new Vector4D(c, 0);
            projectedCenter = projector.Project(handleCenter.x, handleCenter.y, handleCenter.z);
            return(true);
        }
Пример #51
0
        /// <summary>
        /// Draws location marker on screen.
        /// </summary>
        public void DrawLocationMarker(int styleHandle, Vector3D position, MyHudEntityParams hudParams, float targetDamageRatio, float targetArmorRatio, float alphaMultiplifier = 1f)
        {
            if (MySession.ControlledEntity == null)
            {
                return;
            }

            //  Transform point to camera space, so Z = -1 is always forward and then do projective transformation
            Vector3D transformedPoint = Vector3D.Transform(position, MySector.MainCamera.ViewMatrix);
            Vector4D projectedPoint   = Vector4D.Transform(transformedPoint, MySector.MainCamera.ProjectionMatrix);

            //  If point is behind camera we swap X and Y (this is mirror-like transformation)
            if (transformedPoint.Z > 0)
            {
                projectedPoint.X *= -1;
                projectedPoint.Y *= -1;
            }

            if (projectedPoint.W == 0)
            {
                return;
            }

            MyMarkerStyle markerStyle = m_markerStyles[styleHandle];

            double distance         = Vector3D.Distance(position, MySession.ControlledEntity.Entity.WorldMatrix.Translation);
            float  maxDistance      = hudParams.MaxDistance;
            byte   colorAlphaInByte = 255;
            var    hudColor         = MyFakes.SHOW_FACTIONS_GUI ? markerStyle.Color : Color.White;

            hudColor.A = (byte)(colorAlphaInByte * alphaMultiplifier);

            //  Calculate centered coordinates in range <0..1>
            Vector2 projectedPoint2D = new Vector2((float)(projectedPoint.X / projectedPoint.W / 2.0f) + 0.5f, (float)(-projectedPoint.Y / projectedPoint.W) / 2.0f + 0.5f);

            if (MyVideoSettingsManager.IsTripleHead())
            {
                projectedPoint2D.X = (projectedPoint2D.X - (1.0f / 3.0f)) / (1.0f / 3.0f);
            }

            float objectNameYOffset = 0.0f; //offset to direction indicator

            //  This will bound the rectangle in circle, although it isn't real circle because we work in [1,1] dimensions,
            //  but number of horizontal pixels is bigger, so at the end it's more elypse
            //  It must be done when point is out of circle or behind the camera
            Vector2 direction = projectedPoint2D - MyHudConstants.DIRECTION_INDICATOR_SCREEN_CENTER;

            if ((direction.Length() > MyHudConstants.DIRECTION_INDICATOR_MAX_SCREEN_DISTANCE) || (transformedPoint.Z > 0))
            {
                if ((hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS) == 0)
                {
                    return;
                }

                if (direction.LengthSquared() > MyMathConstants.EPSILON_SQUARED)
                {
                    direction.Normalize();
                }
                else
                {
                    direction = new Vector2(1f, 0f);
                }
                projectedPoint2D = MyHudConstants.DIRECTION_INDICATOR_SCREEN_CENTER + direction * MyHudConstants.DIRECTION_INDICATOR_MAX_SCREEN_DISTANCE;

                //  Fix vertical scale
                projectedPoint2D.Y *= MyGuiManager.GetHudSize().Y;

                AddTexturedQuad(markerStyle.TextureDirectionIndicator, projectedPoint2D + direction * MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 2.5f, direction,
                                hudColor, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 1.2f, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * 0.8f);
            }
            else
            {
                //  Fix vertical scale
                projectedPoint2D.Y *= MyGuiManager.GetHudSize().Y;

                Color rectangleColor = Color.White;
                rectangleColor.A = colorAlphaInByte;

                if ((hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_FOCUS_MARK) > 0)
                {
                    Vector2 upVector = new Vector2(0, -1);
                    if (markerStyle.TextureTargetRotationSpeed != 0)
                    {
                        upVector = new Vector2((float)Math.Cos(MySandboxGame.TotalGamePlayTimeInMilliseconds / 1000f * markerStyle.TextureTargetRotationSpeed * MathHelper.Pi),
                                               (float)Math.Sin(MySandboxGame.TotalGamePlayTimeInMilliseconds / 1000f * markerStyle.TextureTargetRotationSpeed * MathHelper.Pi));
                    }

                    AddTexturedQuad(markerStyle.TextureTarget, projectedPoint2D, upVector, hudColor, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * markerStyle.TextureTargetScale, MyHudConstants.HUD_DIRECTION_INDICATOR_SIZE * markerStyle.TextureTargetScale);
                }

                objectNameYOffset = -MyHudConstants.HUD_TEXTS_OFFSET;
            }

            if (hudParams.Text != null && hudParams.Text.Length > 0 && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_TEXT) != 0)
            {
                //  Add object's name
                MyHudText objectName = m_hudScreen.AllocateText();
                if (objectName != null)
                {
                    objectName.Start(markerStyle.Font, projectedPoint2D + new Vector2(0, hudParams.OffsetText ? objectNameYOffset : 0),
                                     hudColor, 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);
                    objectName.Append(hudParams.Text);
                }
            }

            // display hud icon
            if (hudParams.Icon != null && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_ICON) != 0)
            {
                Color iconColor = hudParams.IconColor.HasValue && MyFakes.SHOW_FACTIONS_GUI ? hudParams.IconColor.Value : Color.White;
                iconColor.A = (byte)(colorAlphaInByte * alphaMultiplifier);

                AddTexturedQuad(hudParams.Icon.Value, projectedPoint2D + hudParams.IconOffset, new Vector2(0, -1), iconColor, hudParams.IconSize.X / 2f, hudParams.IconSize.Y / 2f);
            }

            if (MyFakes.SHOW_HUD_DISTANCES && (hudParams.FlagsEnum & MyHudIndicatorFlagsEnum.SHOW_DISTANCE) != 0)
            {
                //  Add distance to object
                MyHudText objectDistance = m_hudScreen.AllocateText();
                if (objectDistance != null)
                {
                    objectDistance.Start(markerStyle.Font, projectedPoint2D + new Vector2(0, MyHudConstants.HUD_TEXTS_OFFSET),
                                         hudColor, 0.8f, MyGuiDrawAlignEnum.HORISONTAL_CENTER_AND_VERTICAL_CENTER);

                    //  Create string builder with distance in metres, e.g. "123m"
                    objectDistance.AppendInt32((int)Math.Round(distance));
                    objectDistance.Append("m");
                }
            }
        }
        /// <summary>
        /// Update and get current weights of the weapon variants.
        /// </summary>
        /// <returns>Weights. Normalized.</returns>
        Vector4D UpdateAndGetWeaponVariantWeights(MyHandItemDefinition handItemDefinition)
        {
            float characterSpeed;
            Character.AnimationController.Variables.GetValue(MyAnimationVariableStorageHints.StrIdSpeed, out characterSpeed);
            bool isWalkingState = MyCharacter.IsRunningState(Character.GetCurrentMovementState()) && characterSpeed > Character.Definition.MaxWalkSpeed;
            bool isShooting = Character.IsShooting(MyShootActionEnum.PrimaryAction) && (!Character.IsSprinting);
            bool isInIronSight = Character.ZoomMode == MyZoomModeEnum.IronSight && (!Character.IsSprinting);

            float deltaW = MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS / handItemDefinition.BlendTime;
            float deltaShootW = MyEngineConstants.UPDATE_STEP_SIZE_IN_SECONDS / handItemDefinition.ShootBlend;
            // blend into the current variant
            // if currently shooting/ironsight -> use "shooting" blend speed
            m_weaponPositionVariantWeightCounters.X += !isWalkingState && !isShooting && !isInIronSight ? deltaW : (isShooting || isInIronSight ? -deltaShootW : -deltaW);
            m_weaponPositionVariantWeightCounters.Y += isWalkingState && !isShooting && !isInIronSight ? deltaW : (isShooting || isInIronSight ? -deltaShootW : -deltaW);
            m_weaponPositionVariantWeightCounters.Z += isShooting && !isInIronSight ? deltaShootW : (isInIronSight ? -deltaShootW : -deltaW);
            m_weaponPositionVariantWeightCounters.W += isInIronSight ? deltaShootW : (isShooting ? -deltaShootW : -deltaW);
            m_weaponPositionVariantWeightCounters = Vector4.Clamp(m_weaponPositionVariantWeightCounters, Vector4.Zero, Vector4.One);

            Vector4D rtnWeights = new Vector4D(MathHelper.SmoothStep(0, 1, m_weaponPositionVariantWeightCounters.X),
                MathHelper.SmoothStep(0, 1, m_weaponPositionVariantWeightCounters.Y),
                MathHelper.SmoothStep(0, 1, m_weaponPositionVariantWeightCounters.Z),
                MathHelper.SmoothStep(0, 1, m_weaponPositionVariantWeightCounters.W));

            double weightSum = rtnWeights.X + rtnWeights.Y + rtnWeights.Z + rtnWeights.W;
            return rtnWeights / weightSum;
        }
Пример #53
0
 public void CreateDot(DxfEntity entity, Vector4D position)
 {
     this.method_1(position);
 }
Пример #54
0
 public Particle()
 {
     Position = ParticleDefaults.Position;
     EmitterPosition = ParticleDefaults.EmitterPosition;
     Velocity = ParticleDefaults.Velocity;
     Acceleration = ParticleDefaults.Acceleration;
     RadialVelocity = ParticleDefaults.RadialVelocity;
     RadialAcceleration = ParticleDefaults.RadialAcceleration;
     TangentialVelocity = ParticleDefaults.TangentialVelocity;
     TangentialAcceleration = ParticleDefaults.TangentialAcceleration;
     Age = ParticleDefaults.Age;
     Lifetime = ParticleDefaults.Lifetime;
     Spin = ParticleDefaults.Spin;
     SpinVelocity = ParticleDefaults.SpinVelocity;
     Size = ParticleDefaults.Size;
     SizeDelta = ParticleDefaults.SizeDelta;
     Color = ParticleDefaults.Color;
     ColorDelta = ParticleDefaults.ColorDelta;
     Alive = ParticleDefaults.Alive;
 }
Пример #55
0
 private void method_3(Vector4D start, Vector4D end)
 {
 }
 public static void Serialize(this BitStream stream, ref Vector4D vec)
 {
     stream.Serialize(ref vec.X);
     stream.Serialize(ref vec.Y);
     stream.Serialize(ref vec.Z);
     stream.Serialize(ref vec.W);
 }
Пример #57
0
        private void RefineFoundPath(ref Vector3D begin, ref Vector3D end, MyPath<MyNavigationPrimitive> path)
        {
            Debug.Assert(MyPerGameSettings.EnablePathfinding, "Pathfinding is not enabled!");
            if (!MyPerGameSettings.EnablePathfinding)
            {
                return;
            }

            if (path == null)
            {
                Debug.Assert(false, "Path to refine was null!");
                return;
            }

            m_currentPrimitive = path[path.Count - 1].Vertex as MyNavigationPrimitive;
            if (m_hlBegin != null && !m_pathNodes.Contains(m_hlBegin))
            {
                m_hlBegin.Parent.StopObservingPrimitive(m_hlBegin, this);
            }
            m_hlBegin = m_currentPrimitive.GetHighLevelPrimitive();
            if (m_hlBegin != null && !m_pathNodes.Contains(m_hlBegin))
            {
                m_hlBegin.Parent.ObservePrimitive(m_hlBegin, this);
            }

            ProfilerShort.Begin("Path refining and post-processing");
            IMyNavigationGroup prevGroup = null;
            int groupStart = 0;
            int groupEnd = 0;
            Vector3 prevBegin = default(Vector3);
            Vector3 prevEnd = default(Vector3);
            for (int i = 0; i < path.Count; ++i)
            {
                var primitive = path[i].Vertex as MyNavigationPrimitive;
                var group = primitive.Group;

                if (prevGroup == null)
                {
                    prevGroup = group;
                    prevBegin = prevGroup.GlobalToLocal(begin);
                }

                bool lastPrimitive = i == path.Count - 1;

                if (group != prevGroup)
                {
                    groupEnd = i - 1;
                    prevEnd = prevGroup.GlobalToLocal(primitive.WorldPosition);
                }
                else if (lastPrimitive)
                {
                    groupEnd = i;
                    prevEnd = prevGroup.GlobalToLocal(end);
                }
                else
                {
                    continue;
                }

                int refinedBegin = m_expandedPath.Count;
                prevGroup.RefinePath(path, m_expandedPath, ref prevBegin, ref prevEnd, groupStart, groupEnd);
                int refinedEnd = m_expandedPath.Count;
                for (int j = refinedBegin; j < refinedEnd; ++j)
                {
                    Vector3D position = new Vector3D(m_expandedPath[j]);
                    position = prevGroup.LocalToGlobal(position);

                    m_expandedPath[j] = new Vector4D(position, m_expandedPath[j].W);
                }

                if (lastPrimitive && group != prevGroup)
                {
                    m_expandedPath.Add(new Vector4D(primitive.WorldPosition, m_expandedPath[refinedEnd - 1].W));
                }

                prevGroup = group;
                groupStart = i;
                if (m_expandedPath.Count != 0)
                    prevBegin = group.GlobalToLocal(new Vector3D(m_expandedPath[m_expandedPath.Count - 1]));
            }

            m_pathNodePosition++;

            //m_expandedPath.RemoveAt(0);
            m_expandedPathPosition = 0;

            ProfilerShort.End();
        }
Пример #58
0
		public void End()
		{
			quat = new Vector4D();
			type = MotionType.None;
		}
Пример #59
0
 public static Quaternion AsSystemQuaternion(this Vector4D v) => new Quaternion((float)v.x, (float)v.y, (float)v.z, (float)v.w);
Пример #60
0
        public void Evaluate(int SpreadMax)
        {
            bool reset = false;

            if (this.FInIndex.IsChanged || this.FInReset[0] || this.runtime.Runtime == null)
            {
                this.haskinect = this.runtime.Assign(this.FInIndex[0]);
                reset = true;
            }

            if (this.haskinect)
            {

                if (this.FInEnabled.IsChanged || reset)
                {
                    if (this.FInEnabled[0])
                    {
                        this.runtime.Start(this.FInEnableColor[0], this.FInEnableSkeleton[0], this.FInDepthMode[0]);
                    }
                    else
                    {
                        this.runtime.Stop();
                    }

                    reset = true;
                }

                if (this.FInDepthMode.IsChanged || reset || this.FInDeptRes.IsChanged)
                {
                    this.runtime.SetDepthMode(this.FInDepthMode[0], this.FInDeptRes[0]);
                }

                if (this.FInEnableColor.IsChanged || this.FInInfrared.IsChanged || reset)
                {
                    this.runtime.SetColor(this.FInEnableColor[0],this.FInInfrared[0]);
                }

                if (this.FInInfraredEmit.IsChanged || reset)
                {
                    try
                    {
                        this.runtime.Runtime.ForceInfraredEmitterOff = !this.FInInfraredEmit[0];
                    }
                    catch { }
                }

                if (this.FInDepthRange.IsChanged || reset)
                {
                    try
                    {
                        this.runtime.SetDepthRange(this.FInDepthRange[0]);
                    }
                    catch { }
                }

                if (this.FInEnableSkeleton.IsChanged || reset)
                {
                    TransformSmoothParameters sp;
                    /*if (this.FSmoothParams.PluginIO.IsConnected)
                    {
                        sp = this.FSmoothParams[0];
                    }
                    else
                    {*/
                        sp = this.runtime.DefaultSmooth();
                    //}

                    this.runtime.EnableSkeleton(this.FInEnableSkeleton[0], this.FInEnableSmooth[0], sp);
                }

                if (this.FInSkMode.IsChanged || reset)
                {
                    this.runtime.SetSkeletonMode(this.FInSkMode[0]);
                }

                if (this.FInAngle.IsChanged || reset)
                {
                    if (this.runtime.IsStarted)
                    {
                        try { this.runtime.Runtime.ElevationAngle = (int)VMath.Map(this.FInAngle[0], 0, 1, this.runtime.Runtime.MinElevationAngle, this.runtime.Runtime.MaxElevationAngle, TMapMode.Clamp); }
                        catch { }
                    }
                }

                this.FOutStatus[0] = runtime.Runtime.Status;
                this.FOutRuntime[0] = runtime;
                this.FOutStarted[0] = runtime.IsStarted;

                Vector4 va = this.runtime.Runtime.AccelerometerGetCurrentReading();
                Vector4D acc = new Vector4D(va.X, va.Y, va.Z, va.W);

                this.FOutColorFOV.SliceCount = 1;
                this.FOutDepthFOV.SliceCount = 1;
                this.FOutAccelerometer.SliceCount = 1;

                this.FOutAccelerometer[0] = acc;

                this.FOutColorFOV[0] = new Vector2D(this.runtime.Runtime.ColorStream.NominalHorizontalFieldOfView,
                                                    this.runtime.Runtime.ColorStream.NominalVerticalFieldOfView) * (float)VMath.DegToCyc;

                this.FOutDepthFOV[0] = new Vector2D(this.runtime.Runtime.DepthStream.NominalHorizontalFieldOfView,
                                                    this.runtime.Runtime.DepthStream.NominalVerticalFieldOfView) * (float)VMath.DegToCyc;
            }

            this.FOutKCnt[0] = KinectSensor.KinectSensors.Count;
        }