Example #1
0
        public override void OnHandleInput()
        {
            if (Input.KeysPressed.Contains(Keys.B))
            {
                PreviousDemo();
            }
            else if (Input.KeysPressed.Contains(Keys.N))
            {
                NextDemo();
            }

            if (Input.KeysDown.Count != 0)
            {
                if (demos[demo] == Init_ClusterCombine || demos[demo] == Init_ClusterCar)
                {
                    if (Input.KeysDown.Contains(Keys.Up))
                    {
                        motorControl.MaxTorque = 1;
                        motorControl.Goal += FrameDelta * 2;
                    }
                    else if (Input.KeysDown.Contains(Keys.Down))
                    {
                        motorControl.MaxTorque = 1;
                        motorControl.Goal -= FrameDelta * 2;
                    }
                    else if (Input.KeysDown.Contains(Keys.Left))
                    {
                        steerControlF.Angle += FrameDelta;
                        steerControlR.Angle += FrameDelta;
                    }
                    else if (Input.KeysDown.Contains(Keys.Right))
                    {
                        steerControlF.Angle -= FrameDelta;
                        steerControlR.Angle -= FrameDelta;
                    }
                }
            }

            if (Input.MousePressed == MouseButtons.Right)
            {
                results.Fraction = 1;
                if (pickConstraint == null)
                {
                    Vector3 rayFrom = Freelook.Eye;
                    Vector3 rayTo = GetRayTo(Input.MousePoint, Freelook.Eye, Freelook.Target, Graphics.FieldOfView);
                    Vector3 rayDir = rayTo - rayFrom;
                    rayDir.Normalize();

                    SRayCast res = new SRayCast();
                    var softBodies = (World as SoftRigidDynamicsWorld).SoftBodyArray;
                    if (softBodies.Any(b => b.RayTest(rayFrom, rayTo, res)))
                    {
                        results = res;
                        impact = rayFrom + (rayTo - rayFrom) * results.Fraction;
                        drag = !cutting;
                        lastMousePos = Input.MousePoint;

                        NodePtrArray nodes;
                        switch (results.Feature)
                        {
                            case EFeature.Face:
                                nodes = results.Body.Faces[results.Index].N;
                                break;
                            case EFeature.Tetra:
                                nodes = results.Body.Tetras[results.Index].Nodes;
                                break;
                            default:
                                nodes = null;
                                break;
                        }
                        if (nodes != null)
                        {
                            node = nodes.Aggregate((min, n) =>
                                (n.X - impact).LengthSquared <
                                (min.X - impact).LengthSquared ? n : min
                            );
                            goal = node.X;
                        }
                        else
                        {
                            node = null;
                        }
                    }
                }
            }
            else if (Input.MouseReleased == MouseButtons.Right)
            {
                if (!drag && cutting && results.Fraction < 1)
                {
                    using (var isphere = new ImplicitSphere(impact, 1))
                    {
                        results.Body.Refine(isphere, 0.0001f, true);
                    }
                }
                results.Fraction = 1;
                drag = false;
            }

            // Mouse movement
            if (Input.MouseDown == MouseButtons.Right)
            {
                if (node != null && results.Fraction < 1)
                {
                    if (!drag)
                    {
                        int x = Input.MousePoint.X - lastMousePos.X;
                        int y = Input.MousePoint.Y - lastMousePos.Y;
                        if ((x * x) + (y * y) > 6)
                        {
                            drag = true;
                        }
                    }
                    if (drag)
                    {
                        lastMousePos = Input.MousePoint;
                    }
                }
            }

            base.OnHandleInput();
        }
Example #2
0
        public override void OnHandleInput()
        {
            if (Input.KeysPressed.Contains(Keys.B))
            {
                PreviousDemo();
            }
            else if (Input.KeysPressed.Contains(Keys.N))
            {
                NextDemo();
            }

            if (Input.KeysDown.Count != 0)
            {
                if (demos[demo] == InitClusterCombine || demos[demo] == InitClusterCar)
                {
                    if (Input.KeysDown.Contains(Keys.Up))
                    {
                        motorControl.MaxTorque = 1;
                        motorControl.Goal     += FrameDelta * 2;
                    }
                    else if (Input.KeysDown.Contains(Keys.Down))
                    {
                        motorControl.MaxTorque = 1;
                        motorControl.Goal     -= FrameDelta * 2;
                    }
                    else if (Input.KeysDown.Contains(Keys.Left))
                    {
                        steerControlF.Angle += FrameDelta;
                        steerControlR.Angle += FrameDelta;
                    }
                    else if (Input.KeysDown.Contains(Keys.Right))
                    {
                        steerControlF.Angle -= FrameDelta;
                        steerControlR.Angle -= FrameDelta;
                    }
                }
            }

            if (Input.MousePressed == MouseButtons.Right)
            {
                results.Fraction = 1;
                //if (pickConstraint == null)
                {
                    Vector3 rayFrom = Freelook.Eye;
                    Vector3 rayTo   = GetRayTo(Input.MousePoint, Freelook.Eye, Freelook.Target, Graphics.FieldOfView);
                    Vector3 rayDir  = rayTo - rayFrom;
                    rayDir.Normalize();

                    SRayCast res        = new SRayCast();
                    var      softBodies = (World as SoftRigidDynamicsWorld).SoftBodyArray;
                    if (softBodies.Any(b => b.RayTest(rayFrom, rayTo, res)))
                    {
                        results      = res;
                        impact       = rayFrom + (rayTo - rayFrom) * results.Fraction;
                        drag         = !cutting;
                        lastMousePos = Input.MousePoint;

                        NodePtrArray nodes;
                        switch (results.Feature)
                        {
                        case EFeature.Face:
                            nodes = results.Body.Faces[results.Index].N;
                            break;

                        case EFeature.Tetra:
                            nodes = results.Body.Tetras[results.Index].Nodes;
                            break;

                        default:
                            nodes = null;
                            break;
                        }
                        if (nodes != null)
                        {
                            node = nodes.Aggregate((min, n) =>
                                                   (n.X - impact).LengthSquared <
                                                   (min.X - impact).LengthSquared ? n : min
                                                   );
                            goal = node.X;
                        }
                        else
                        {
                            node = null;
                        }
                    }
                }
            }
            else if (Input.MouseReleased == MouseButtons.Right)
            {
                if (!drag && cutting && results.Fraction < 1)
                {
                    using (var isphere = new ImplicitSphere(impact, 1))
                    {
                        results.Body.Refine(isphere, 0.0001f, true);
                    }
                }
                results.Fraction = 1;
                drag             = false;
            }

            // Mouse movement
            if (Input.MouseDown == MouseButtons.Right)
            {
                if (node != null && results.Fraction < 1)
                {
                    if (!drag)
                    {
                        int x = Input.MousePoint.X - lastMousePos.X;
                        int y = Input.MousePoint.Y - lastMousePos.Y;
                        if ((x * x) + (y * y) > 6)
                        {
                            drag = true;
                        }
                    }
                    if (drag)
                    {
                        lastMousePos = Input.MousePoint;
                    }
                }
            }

            base.OnHandleInput();
        }
Example #3
0
        protected override void OnHandleInput()
        {
            base.OnHandleInput();

            if (Input.MousePressed == MouseButtons.Right)
            {
                results.Fraction = 1;
                if (pickConstraint == null)
                {
                    Vector3 rayFrom = Freelook.Eye;
                    Vector3 rayTo   = GetRayTo(Input.MousePoint, Freelook.Eye, Freelook.Target, FieldOfView);
                    Vector3 rayDir  = rayTo - rayFrom;
                    rayDir.Normalize();

                    SRayCast res        = new SRayCast();
                    var      softBodies = (PhysicsContext.World as SoftRigidDynamicsWorld).SoftBodyArray;
                    if (softBodies.Any(b => b.RayTest(rayFrom, rayTo, res)))
                    {
                        results      = res;
                        impact       = rayFrom + (rayTo - rayFrom) * results.Fraction;
                        drag         = !(PhysicsContext as Physics).cutting;
                        lastMousePos = Input.MousePoint;

                        NodePtrArray nodes;
                        switch (results.Feature)
                        {
                        case EFeature.Face:
                            nodes = results.Body.Faces[results.Index].N;
                            break;

                        case EFeature.Tetra:
                            nodes = results.Body.Tetras[results.Index].Nodes;
                            break;

                        default:
                            nodes = null;
                            break;
                        }
                        if (nodes != null)
                        {
                            node = nodes.Aggregate((min, n) =>
                                                   (n.X - impact).LengthSquared() <
                                                   (min.X - impact).LengthSquared() ? n : min
                                                   );
                            goal = node.X;
                        }
                        else
                        {
                            node = null;
                        }
                    }
                }
            }
            else if (Input.MouseReleased == MouseButtons.Right)
            {
                if (!drag && (PhysicsContext as Physics).cutting && results.Fraction < 1)
                {
                    using (var isphere = new ImplicitSphere(impact, 1))
                    {
                        results.Body.Refine(isphere, 0.0001f, true);
                    }
                }
                results.Fraction = 1;
                drag             = false;
            }

            // Mouse movement
            if (Input.MouseDown == MouseButtons.Right)
            {
                if (node != null && results.Fraction < 1)
                {
                    if (!drag)
                    {
                        int x = Input.MousePoint.X - lastMousePos.X;
                        int y = Input.MousePoint.Y - lastMousePos.Y;
                        if ((x * x) + (y * y) > 6)
                        {
                            drag = true;
                        }
                    }
                    if (drag)
                    {
                        lastMousePos = Input.MousePoint;
                    }
                }
            }

            (PhysicsContext as Physics).HandleInput(Input, FrameDelta);
        }
Example #4
0
        protected override void OnHandleInput()
        {
            base.OnHandleInput();

            if (Input.MousePressed == MouseButtons.Right)
            {
                results.Fraction = 1;
                if (pickConstraint == null)
                {
                    Vector3 rayFrom = Freelook.Eye;
                    Vector3 rayTo   = GetRayTo(Input.MousePoint, Freelook.Eye, Freelook.Target, FieldOfView);
                    Vector3 rayDir  = (rayTo - rayFrom);
                    rayDir.Normalize();
                    AlignedSoftBodyArray sbs = ((SoftRigidDynamicsWorld)PhysicsContext.World).SoftBodyArray;
                    for (int ib = 0; ib < sbs.Count; ++ib)
                    {
                        SoftBody psb = sbs[ib];
                        SRayCast res = new SRayCast();
                        if (psb.RayTest(rayFrom, rayTo, res))
                        {
                            results = res;
                        }
                    }
                    if (results.Fraction < 1)
                    {
                        impact       = rayFrom + (rayTo - rayFrom) * results.Fraction;
                        drag         = !(PhysicsContext as Physics).cutting;
                        lastMousePos = Input.MousePoint;
                        node         = null;
                        switch (results.Feature)
                        {
                        case EFeature.Tetra:
                        {
                            Tetra tet = results.Body.Tetras[results.Index];
                            node = tet.Nodes[0];
                            for (int i = 1; i < 4; ++i)
                            {
                                if ((node.X - impact).LengthSquared() >
                                    (tet.Nodes[i].X - impact).LengthSquared())
                                {
                                    node = tet.Nodes[i];
                                }
                            }
                            break;
                        }

                        case EFeature.Face:
                        {
                            Face f = results.Body.Faces[results.Index];
                            node = f.N[0];
                            for (int i = 1; i < 3; ++i)
                            {
                                if ((node.X - impact).LengthSquared() >
                                    (f.N[i].X - impact).LengthSquared())
                                {
                                    node = f.N[i];
                                }
                            }
                        }
                        break;
                        }
                        if (node != null)
                        {
                            goal = node.X;
                        }
                        //return;
                    }
                }
            }
            else if (Input.MouseReleased == MouseButtons.Right)
            {
                if ((!drag) && (PhysicsContext as Physics).cutting && (results.Fraction < 1))
                {
                    ImplicitSphere isphere = new ImplicitSphere(impact, 1);
                    results.Body.Refine(isphere, 0.0001f, true);
                }
                results.Fraction = 1;
                drag             = false;
            }

            // Mouse movement
            if (Input.MouseDown == MouseButtons.Right)
            {
                if (node != null && (results.Fraction < 1))
                {
                    if (!drag)
                    {
                        int x = Input.MousePoint.X - lastMousePos.X;
                        int y = Input.MousePoint.Y - lastMousePos.Y;
                        if ((x * x) + (y * y) > 6)
                        {
                            drag = true;
                        }
                    }
                    if (drag)
                    {
                        lastMousePos = Input.MousePoint;
                    }
                }
            }

            (PhysicsContext as Physics).HandleInput(Input, FrameDelta);
        }
Example #5
0
        protected override void OnHandleInput()
        {
            base.OnHandleInput();

            if (Input.MousePressed == MouseButtons.Right)
            {
                results.Fraction = 1;
                if (pickConstraint == null)
                {
                    Vector3 rayFrom = Freelook.Eye;
                    Vector3 rayTo = GetRayTo(Input.MousePoint, Freelook.Eye, Freelook.Target, FieldOfView);
                    Vector3 rayDir = rayTo - rayFrom;
                    rayDir.Normalize();

                    SRayCast res = new SRayCast();
                    var softBodies = (PhysicsContext.World as SoftRigidDynamicsWorld).SoftBodyArray;
                    if (softBodies.Any(b => b.RayTest(rayFrom, rayTo, res)))
                    {
                        results = res;
                        impact = rayFrom + (rayTo - rayFrom) * results.Fraction;
                        drag = !(PhysicsContext as Physics).cutting;
                        lastMousePos = Input.MousePoint;

                        NodePtrArray nodes;
                        switch (results.Feature)
                        {
                            case EFeature.Face:
                                nodes = results.Body.Faces[results.Index].N;
                                break;
                            case EFeature.Tetra:
                                nodes = results.Body.Tetras[results.Index].Nodes;
                                break;
                            default:
                                nodes = null;
                                break;
                        }
                        if (nodes != null)
                        {
                            node = nodes.Aggregate((min, n) =>
                                (n.X - impact).LengthSquared() <
                                (min.X - impact).LengthSquared() ? n : min
                            );
                            goal = node.X;
                        }
                        else
                        {
                            node = null;
                        }
                    }
                }
            }
            else if (Input.MouseReleased == MouseButtons.Right)
            {
                if (!drag && (PhysicsContext as Physics).cutting && results.Fraction < 1)
                {
                    using (var isphere = new ImplicitSphere(impact, 1))
                    {
                        results.Body.Refine(isphere, 0.0001f, true);
                    }
                }
                results.Fraction = 1;
                drag = false;
            }

            // Mouse movement
            if (Input.MouseDown == MouseButtons.Right)
            {
                if (node != null && results.Fraction < 1)
                {
                    if (!drag)
                    {
                        int x = Input.MousePoint.X - lastMousePos.X;
                        int y = Input.MousePoint.Y - lastMousePos.Y;
                        if ((x * x) + (y * y) > 6)
                        {
                            drag = true;
                        }
                    }
                    if (drag)
                    {
                        lastMousePos = Input.MousePoint;
                    }
                }
            }

            (PhysicsContext as Physics).HandleInput(Input, FrameDelta);
        }
        public override void OnHandleInput()
        {
            if (Input.KeysPressed.Contains(Keys.B))
            {
                PreviousDemo();
            }
            else if (Input.KeysPressed.Contains(Keys.N))
            {
                NextDemo();
            }

            if (Input.KeysDown.Count != 0)
            {
                if (demos[demo] == Init_ClusterCombine || demos[demo] == Init_ClusterCar)
                {
                    if (Input.KeysDown.Contains(Keys.Up))
                    {
                        motorControl.MaxTorque = 1;
                        motorControl.Goal += FrameDelta * 2;
                    }
                    else if (Input.KeysDown.Contains(Keys.Down))
                    {
                        motorControl.MaxTorque = 1;
                        motorControl.Goal -= FrameDelta * 2;
                    }
                    else if (Input.KeysDown.Contains(Keys.Left))
                    {
                        steerControlF.Angle += FrameDelta;
                        steerControlR.Angle += FrameDelta;
                    }
                    else if (Input.KeysDown.Contains(Keys.Right))
                    {
                        steerControlF.Angle -= FrameDelta;
                        steerControlR.Angle -= FrameDelta;
                    }
                }
            }

            if (Input.MousePressed == MouseButtons.Right)
            {
                results.Fraction = 1;
                if (pickConstraint == null)
                {
                    Vector3 rayFrom = Freelook.Eye;
                    Vector3 rayTo = GetRayTo(Input.MousePoint, Freelook.Eye, Freelook.Target, Graphics.FieldOfView);
                    Vector3 rayDir = (rayTo - rayFrom);
                    rayDir.Normalize();
                    AlignedSoftBodyArray sbs = SoftWorld.SoftBodyArray;
                    for (int ib = 0; ib < sbs.Count; ++ib)
                    {
                        SoftBody psb = sbs[ib];
                        SRayCast res = new SRayCast();
                        if (psb.RayTest(ref rayFrom, ref rayTo, res))
                        {
                            results = res;
                        }
                        else
                        {
                            res.Dispose();
                        }
                    }
                    if (results.Fraction < 1)
                    {
                        impact = rayFrom + (rayTo - rayFrom) * results.Fraction;
                        drag = !cutting;
                        lastMousePos = Input.MousePoint;
                        node = null;
                        switch (results.Feature)
                        {
                            case EFeature.Tetra:
                                {
                                    Tetra tet = results.Body.Tetras[results.Index];
                                    node = tet.Nodes[0];
                                    for (int i = 1; i < 4; ++i)
                                    {
                                        if ((node.Position - impact).LengthSquared >
                                            (tet.Nodes[i].Position - impact).LengthSquared)
                                        {
                                            node = tet.Nodes[i];
                                        }
                                    }
                                    break;
                                }
                            case EFeature.Face:
                                {
                                    Face f = results.Body.Faces[results.Index];
                                    node = f.N[0];
                                    for (int i = 1; i < 3; ++i)
                                    {
                                        if ((node.Position - impact).LengthSquared >
                                            (f.N[i].Position - impact).LengthSquared)
                                        {
                                            node = f.N[i];
                                        }
                                    }
                                }
                                break;
                        }
                        if (node != null)
                            goal = node.Position;
                        //return;
                    }
                }
            }
            else if (Input.MouseReleased == MouseButtons.Right)
            {
                if ((!drag) && cutting && (results.Fraction < 1))
                {
                    using (ImplicitSphere isphere = new ImplicitSphere(ref impact, 1))
                    {
                        results.Body.Refine(isphere, 0.0001f, true);
                    }
                }
                results.Fraction = 1;
                drag = false;
            }

            // Mouse movement
            if (Input.MouseDown == MouseButtons.Right)
            {
                if (node != null && (results.Fraction < 1))
                {
                    if (!drag)
                    {
                        int x = Input.MousePoint.X - lastMousePos.X;
                        int y = Input.MousePoint.Y - lastMousePos.Y;
                        if ((x * x) + (y * y) > 6)
                        {
                            drag = true;
                        }
                    }
                    if (drag)
                    {
                        lastMousePos = Input.MousePoint;
                    }
                }
            }

            base.OnHandleInput();
        }
Example #7
0
        protected override void OnHandleInput()
        {
            base.OnHandleInput();

            if (Input.MousePressed == MouseButtons.Right)
            {
                results.Fraction = 1;
                if (pickConstraint == null)
                {
                    Vector3 rayFrom = Freelook.Eye;
                    Vector3 rayTo = GetRayTo(Input.MousePoint, Freelook.Eye, Freelook.Target, FieldOfView);
                    Vector3 rayDir = (rayTo - rayFrom);
                    rayDir.Normalize();
                    AlignedSoftBodyArray sbs = ((SoftRigidDynamicsWorld)PhysicsContext.World).SoftBodyArray;
                    for (int ib = 0; ib < sbs.Count; ++ib)
                    {
                        SoftBody psb = sbs[ib];
                        SRayCast res = new SRayCast();
                        if (psb.RayTest(rayFrom, rayTo, res))
                        {
                            results = res;
                        }
                    }
                    if (results.Fraction < 1)
                    {
                        impact = rayFrom + (rayTo - rayFrom) * results.Fraction;
                        drag = !(PhysicsContext as Physics).cutting;
                        lastMousePos = Input.MousePoint;
                        node = null;
                        switch (results.Feature)
                        {
                            case EFeature.Tetra:
                                {
                                    Tetra tet = results.Body.Tetras[results.Index];
                                    node = tet.Nodes[0];
                                    for (int i = 1; i < 4; ++i)
                                    {
                                        if ((node.X - impact).LengthSquared() >
                                            (tet.Nodes[i].X - impact).LengthSquared())
                                        {
                                            node = tet.Nodes[i];
                                        }
                                    }
                                    break;
                                }
                            case EFeature.Face:
                                {
                                    Face f = results.Body.Faces[results.Index];
                                    node = f.N[0];
                                    for (int i = 1; i < 3; ++i)
                                    {
                                        if ((node.X - impact).LengthSquared() >
                                            (f.N[i].X - impact).LengthSquared())
                                        {
                                            node = f.N[i];
                                        }
                                    }
                                }
                                break;
                        }
                        if (node != null)
                            goal = node.X;
                        //return;
                    }
                }
            }
            else if (Input.MouseReleased == MouseButtons.Right)
            {
                if ((!drag) && (PhysicsContext as Physics).cutting && (results.Fraction < 1))
                {
                    ImplicitSphere isphere = new ImplicitSphere(impact, 1);
                    results.Body.Refine(isphere, 0.0001f, true);
                }
                results.Fraction = 1;
                drag = false;
            }

            // Mouse movement
            if (Input.MouseDown == MouseButtons.Right)
            {
                if (node != null && (results.Fraction < 1))
                {
                    if (!drag)
                    {
                        int x = Input.MousePoint.X - lastMousePos.X;
                        int y = Input.MousePoint.Y - lastMousePos.Y;
                        if ((x * x) + (y * y) > 6)
                        {
                            drag = true;
                        }
                    }
                    if (drag)
                    {
                        lastMousePos = Input.MousePoint;
                    }
                }
            }

            (PhysicsContext as Physics).HandleInput(Input, FrameDelta);
        }