Esempio n. 1
0
        public void TestSnapPointToPoint2()
        {
            XNAGame game = new XNAGame();


            SnapPoint p1 = new SnapPoint();

            p1.Position = new Vector3(0, 0, 0);
            var w2 = (float)(1 / Math.Sqrt(2));

            p1.Normal           = Vector3.Normalize(new Vector3(w2 * w2, w2, w2 * w2));
            p1.Up               = Vector3.Normalize(new Vector3(-w2 * w2, w2, -w2 * w2));
            p1.ClockwiseWinding = true;

            SnapPoint p2 = new SnapPoint();

            p2.Position         = new Vector3(0, 0, 0);
            p2.Normal           = Vector3.Normalize(new Vector3(1, 0, 0));
            p2.Up               = Vector3.Normalize(new Vector3(0, 1, 0));
            p2.ClockwiseWinding = false;

            var snapper = new SnapperPointPoint();

            List <Transformation> transformations = new List <Transformation>();


            game.DrawEvent += delegate
            {
                transformations.Clear();
                snapper.SnapAToB(p2, p1, Transformation.Identity, transformations);
                game.LineManager3D.DrawGroundShadows = true;

                game.LineManager3D.AddLine(p1.Position, p1.Position + 3f * p1.Normal, Color.Red);
                game.LineManager3D.AddLine(p1.Position, p1.Position + 3f * p1.Up, Color.Blue);

                game.LineManager3D.WorldMatrix = transformations[0].CreateMatrix();

                game.LineManager3D.AddLine(p2.Position, p2.Position + 3f * p2.Normal + Vector3.One * 0.01f, Color.Yellow);
                game.LineManager3D.AddLine(p2.Position, p2.Position + 3f * p2.Up + Vector3.One * 0.01f, Color.Purple);
            };

            game.Run();
        }
        public void TestSnapperPointPoint()
        {
            SnapPoint PointA = new SnapPoint();
            SnapPoint PointB = new SnapPoint();

            PointA.Position = new Vector3(1, 0, 2);
            PointA.Normal   = Vector3.Normalize(new Vector3(1, 0, 1));
            PointA.Up       = Vector3.Normalize(new Vector3(0, 1, 0));

            PointB.Position = new Vector3(2, 0, 3);
            PointB.Normal   = Vector3.Normalize(new Vector3(3, 0, 4));
            PointB.Up       = Vector3.Normalize(new Vector3(0, 1, 0));

            SnapperPointPoint     pointSnapper    = new SnapperPointPoint();
            List <Transformation> transformations = new List <Transformation>();

            pointSnapper.SnapAToB(PointA, PointB, Transformation.Identity, transformations);

            XNAGame game = new XNAGame();

            Matrix  transformation = transformations[0].CreateMatrix();
            Vector3 APosTrans      = PointA.Position;
            Vector3 ANormTrans     = PointA.Normal;
            Vector3 AUpTrans       = PointA.Up;



            game.DrawEvent += delegate
            {
                game.LineManager3D.AddLine(PointA.Position, PointA.Position + PointA.Normal, Color.Red);
                game.LineManager3D.AddLine(PointA.Position, PointA.Position + PointA.Up, Color.Yellow);

                game.LineManager3D.AddLine(PointB.Position, PointB.Position + PointB.Normal, Color.Red);
                game.LineManager3D.AddLine(PointB.Position, PointB.Position + PointB.Up, Color.Red);

                Vector3 offset = new Vector3(0.01f, 0.01f, 0.01f);
                game.LineManager3D.AddLine(Vector3.Transform(APosTrans, transformation) + offset, Vector3.Transform(APosTrans + ANormTrans, transformation) + offset, Color.Blue);
                game.LineManager3D.AddLine(Vector3.Transform(APosTrans, transformation) + offset, Vector3.Transform(APosTrans + AUpTrans, transformation) + offset, Color.Orange);
            };

            game.Run();
        }
        public void Update(IXNAGame _game)
        {
            if (!Enabled)
            {
                return;
            }

            if (!_game.Mouse.CursorEnabled)
            {
                return;
            }

            WorldObject target = RaycastWorldTile(_game);

            if (target == null)
            {
                return;
            }

            TileFace resultFace = RaycastTileFace(_game, target);

            if (PickOperandAState)
            {
                if (_game.Mouse.LeftMouseJustPressed)
                {
                    tileA     = target;
                    tileFaceA = resultFace;


                    ghost = renderer.AddMesh(tileA.ObjectType.Mesh);


                    PickOperandAState = false;
                    PickOperandBState = true;
                }
            }

            if (PickOperandBState)
            {
                if (tileA.Equals(target))
                {
                    return;
                }

                tileB     = target;
                tileFaceB = resultFace;

                PointA = builder.GetPoint(tileA.ObjectType.TileData, tileFaceA, null
                                          , tileA.ObjectType.TileData.GetTotalWinding(tileFaceA) ^ winding);
                PointB = builder.GetPoint(tileB.ObjectType.TileData, tileFaceB, null
                                          , tileB.ObjectType.TileData.GetTotalWinding(tileFaceB));


                List <Transformation> transformations = new List <Transformation>();

                snapper.SnapAToB(PointA, PointB, tileB.Transformation, transformations);

                if (transformations.Count != 0)
                {
                    ghost.WorldMatrix = transformations[0].CreateMatrix();
                }

                if (_game.Mouse.RightMouseJustPressed)
                {
                    winding = !winding;
                }
                if (_game.Mouse.LeftMouseJustPressed)
                {
                    PickOperandBState = false;
                    SnapLearnState    = true;
                }
            }

            if (SnapLearnState)
            {
                learnSnap();


                SnapLearnState    = false;
                PickOperandAState = true;

                ghost.WorldMatrix     = new Matrix();
                ghostFace.WorldMatrix = new Matrix();

                Enabled = false; // TODO: If you are going to decide how to use this class in this class,
                                 //      then you should put your entire program here too.
                return;
            }

            SetGhostFaceAtFace(target, resultFace);
        }