Ejemplo n.º 1
0
    void Update()
    {
        Ray ray = useCamCurser ? new Ray(Cam.transform.position, Cam.transform.forward) : Cam.ScreenPointToRay(Input.mousePosition);

        this.Hit           = new RaycastHit();
        transform.up       = Cam.transform.forward;
        transform.position = ray.GetPoint(GlobalBehaviour.GadgetPhysicalDistance);

        int rayCastMask;

        if (Input.GetButton(this.deactivateSnapKey))
        {
            rayCastMask = this.layerMask & ~this.snapLayerMask.value;
        }
        else
        {
            rayCastMask = this.layerMask;
        }

        if (Physics.Raycast(ray, out Hit, MaxRange, rayCastMask) ||
            (MaxRange <= GlobalBehaviour.GadgetPhysicalDistance &&
             Physics.Raycast(transform.position, Vector3.down, out Hit, GlobalBehaviour.GadgetPhysicalDistance, rayCastMask)))
        {
            if ((Hit.collider.transform.CompareTag("SnapZone") || Hit.collider.transform.CompareTag("Selectable")) &&
                !Input.GetButton(this.deactivateSnapKey))
            {
                if (Hit.collider.gameObject.layer == LayerMask.NameToLayer("Ray") ||
                    Hit.collider.gameObject.layer == LayerMask.NameToLayer("Line"))
                {
                    var id = Hit.collider.gameObject.GetComponent <FactObject>().URI;
                    AbstractLineFact lineFact = StageStatic.stage.factState[id] as AbstractLineFact;
                    PointFact        p1       = StageStatic.stage.factState[lineFact.Pid1] as PointFact;

                    Hit.point = Math3d.ProjectPointOnLine(p1.Point, lineFact.Dir, Hit.point);
                }
                else
                {
                    Hit.point  = Hit.collider.transform.position;
                    Hit.normal = Vector3.up;
                }

                transform.position = Hit.point;
                transform.up       = Hit.normal;
            }
            else
            {
                transform.position  = Hit.point;
                transform.up        = Hit.normal;
                transform.position += .01f * Hit.normal;
            }

            CheckMouseButtons();
        }
    }
Ejemplo n.º 2
0
    private void ResetGadget()
    {
        this.LotModeIsLineSelected = false;
        this.LotModeLineSelected   = null;

        this.LotModeLinePointA = null;

        this.LotModeIsPointSelected   = false;
        this.LotModeIntersectionPoint = null;
        //TODO? reset?
        //this.LotModeLineHit;
        DeactivateLineDrawing();
    }
Ejemplo n.º 3
0
    public override void OnHit(RaycastHit hit)
    {
        void CreateRayAndAngles(string pidIntersectionPoint, string pidLotPoint, bool samestep)
        {
            FactManager.AddRayFact(pidIntersectionPoint, pidLotPoint, samestep);

            //TODO: create at all? / for all points on basline?
            FactManager.AddAngleFact(
                this.LotModeLineSelected.Pid1 == pidIntersectionPoint ? this.LotModeLineSelected.Pid2 : this.LotModeLineSelected.Pid1,
                pidIntersectionPoint, pidLotPoint, true);
        }

        if (!this.isActiveAndEnabled)
        {
            return;
        }

        //If LotPoint is on baseLine
        if (this.LotModeIsPointSelected && (hit.transform.gameObject.layer == LayerMask.NameToLayer("Default") || hit.transform.gameObject.layer == LayerMask.NameToLayer("Tree")))
        {
            Vector3 LotPoint = Math3d.ProjectPointOnLine(hit.point, this.LotModeLineSelected.Dir, this.LotModeIntersectionPoint.Point);

            //TODO: which normal?
            CreateRayAndAngles(this.LotModeIntersectionPoint.Id, FactManager.AddPointFact(LotPoint, hit.normal).Id, true);
            this.ResetGadget();
        }

        //If baseline already selected and point selected
        else if (this.LotModeIsLineSelected && !this.LotModeIsPointSelected && hit.transform.gameObject.layer == LayerMask.NameToLayer("Point"))
        {
            PointFact tempFact = StageStatic.stage.factState[hit.transform.GetComponent <FactObject>().URI] as PointFact;

            Vector3 intersectionPoint = Math3d.ProjectPointOnLine(this.LotModeLinePointA.Point, this.LotModeLineSelected.Dir, tempFact.Point);

            if (intersectionPoint == tempFact.Point) // Vector3.operator== tests for almost Equal()
            {                                        //TempFact is on baseLine
                this.LotModeIsPointSelected   = true;
                this.LotModeIntersectionPoint = tempFact;
                return;
            }

            //TODO: test Facts existance
            //add Facts
            var intersectionId = FactManager.AddPointFact(intersectionPoint, this.LotModeLineHit.normal).Id;

            if (this.LotModeLineSelected is RayFact) //Add OnLineFact only on Ray not Line
            {
                FactManager.AddOnLineFact(intersectionId, this.LotModeLineSelected.Id, true);
            }

            CreateRayAndAngles(intersectionId, tempFact.Id, true);
            this.ResetGadget();
        }

        //If nothing yet selected
        else if (!this.LotModeIsLineSelected &&
                 (hit.transform.gameObject.layer == LayerMask.NameToLayer("Ray") ||
                  hit.transform.gameObject.layer == LayerMask.NameToLayer("Line")))
        {
            Fact tempFact = StageStatic.stage.factState[hit.transform.GetComponent <FactObject>().URI];

            //Activate LineDrawing for preview
            this.LotModeIsLineSelected = true;
            this.LotModeLineSelected   = tempFact as AbstractLineFact;
            this.LotModeLinePointA     = (PointFact)StageStatic.stage.factState[this.LotModeLineSelected.Pid1];
            this.LotModeLineHit        = hit;
            this.ActivateLineDrawing();
        }

        //unexpected usage
        else
        {
            if (this.LotModeIsLineSelected)
            {
                //Deactivate LineDrawing and first point selection
                this.ResetGadget();
            }
        }
    }
Ejemplo n.º 4
0
 protected override bool EquivalentWrapped(AbstractLineFact f1, AbstractLineFact f2)
 {
     return(EquivalentWrapped((T)f1, (T)f2));
 }