Esempio n. 1
0
        public void Generate()
        {
            float apothem = 0.5f * unit / Mathf.Tan(Mathf.PI / nSides);

            apex     = GeoObjConstruction.iPoint(spawnPoint.position + unit * Vector3.up);
            basePoly = GeoObjConstruction.rPoly(nSides, apothem, spawnPoint.position);
            dPyramid = GeoObjConstruction.dPyramid(basePoly, apex);

            if (prism)
            {
                dPyramid.sides.ForEach(p => p.LeapInteraction = false);
                dPyramid.sides.ForEach(p => p.transform.GetChild(0).gameObject.SetActive(false));

                iPrism = GeoObjConstruction.iPrism(basePoly, spawnPoint.position + unit * Vector3.up);
                iPrism.LeapInteraction = false;

                iPrism.sides.ForEach(p => GeoObjConstruction.dPyramid(p, apex).sides.ForEach(q => q.LeapInteraction = false));
                iPrism.sides.ForEach(p => p.LeapInteraction = false);

                iPrism.bases.ForEach(p => p.pointList.ForEach(q => q.LeapInteraction = false));
                iPrism.bases.ForEach(p => p.pointList.ForEach(q => q.GetComponent <MeshRenderer>().enabled = false));

                HW_GeoSolver.ins.AddDependence(basePoly2, apex);

                apex.GetComponent <InteractionBehaviour>().OnGraspedMovement += updateFigure;
            }
            else
            {
                HW_GeoSolver.ins.removeComponent(basePoly2);
                //iPrism.geoManager.removeComponent(iPrism.transform);
            }
            thisAS.clip = successClip;
            thisAS.Play();
        }
Esempio n. 2
0
        private void equalArea(AbstractPolygon abstractPolygon1, AbstractPolygon abstractPolygon2)
        {
            if (verbose)
            {
                Debug.Log(abstractPolygon1.figName + " and " + abstractPolygon2 + " have equal areas.");
            }
            abstractPolygon1.GetComponent <MeshRenderer>().material.color = Color.green;
            abstractPolygon2.GetComponent <MeshRenderer>().material.color = Color.green;

            //also need to change textures.
        }
Esempio n. 3
0
        public static DependentPyramid dPyramid(AbstractPolygon basePoly, AbstractPoint apex)
        {
            DependentPyramid pyramid = DependentPyramid.Constructor();

            pyramid.basePolygon = basePoly;
            pyramid.apex        = apex;

            List <AbstractPolygon> sideList = new List <AbstractPolygon>();

            foreach (AbstractLineSegment baseLine in basePoly.lineList)
            {
                if (baseLine.GetComponent <InteractableLineSegment>() != null)
                {
                    List <AbstractPoint>       vertexList = new List <AbstractPoint>();
                    List <AbstractLineSegment> lineList   = new List <AbstractLineSegment>();

                    vertexList.Add(apex);
                    vertexList.Add(baseLine.GetComponent <InteractableLineSegment>().point1);
                    vertexList.Add(baseLine.GetComponent <InteractableLineSegment>().point2);

                    lineList.Add(baseLine);
                    lineList.Add(iLineSegment(apex, baseLine.GetComponent <InteractableLineSegment>().point1));
                    lineList.Add(iLineSegment(apex, baseLine.GetComponent <InteractableLineSegment>().point2));

                    sideList.Add(dPolygon(lineList, vertexList));
                }
                else
                {
                    List <AbstractPoint>       vertexList = new List <AbstractPoint>();
                    List <AbstractLineSegment> lineList   = new List <AbstractLineSegment>();

                    vertexList.Add(apex);
                    vertexList.Add(baseLine.GetComponent <DependentLineSegment>().point1);
                    vertexList.Add(baseLine.GetComponent <DependentLineSegment>().point2);

                    lineList.Add(baseLine);
                    lineList.Add(iLineSegment(apex, baseLine.GetComponent <DependentLineSegment>().point1));
                    lineList.Add(iLineSegment(apex, baseLine.GetComponent <DependentLineSegment>().point2));

                    sideList.Add(dPolygon(lineList, vertexList));
                }
            }

            pyramid.sides = sideList;

            HW_GeoSolver.ins.AddDependence(pyramid, basePoly);//This dependency must be first on the list for XMLManager Loading to operate correctly

            foreach (AbstractPolygon poly in sideList)
            {
                HW_GeoSolver.ins.AddDependence(pyramid, poly);
            }

            return(pyramid);
        }
Esempio n. 4
0
 public void Initialize()
 {
     myPoly = GetComponent <AbstractPolygon>();
     mesh0  = GetComponent <MeshFilter>().mesh;
     child  = new GameObject();
     child.transform.parent = this.transform.parent;
     mesh1 = child.AddComponent <MeshFilter>().mesh;
     child.AddComponent <MeshRenderer>().material = myPoly.GetComponent <MeshRenderer>().material;
     mesh1.vertices  = mesh0.vertices;
     mesh1.triangles = mesh0.triangles;
     mesh1.normals   = mesh0.normals;
 }
Esempio n. 5
0
        private void checkTwoPoints()
        {
            if (prevSet && currSet && _prevPoint != _currPoint)
            {
                currPoint.tag = "Untagged";
                prevPoint.tag = "Untagged";
                switch (thisPinType)
                {
                case pinType.polymaker:
                    lineList.Add(GeoObjConstruction.dLineSegment(currPoint, prevPoint));
                    if (_currPoint == pointList[0] && lineList.Count > 1)
                    {
                        GeoObjConstruction.iPolygon(lineList, pointList);
                        Destroy(gameObject, Time.fixedDeltaTime);
                    }
                    break;

                case pinType.wireframe:
                    lineList.Add(GeoObjConstruction.dLineSegment(currPoint, prevPoint));
                    successfullyMade = true;
                    break;

                case pinType.solidmaker:
                    Debug.Log("This isn't setup yet do not use! Object: " + gameObject.name);
                    Destroy(gameObject, Time.fixedDeltaTime);
                    break;

                case pinType.polycut:
                    List <AbstractPolygon> prevPointPolygons = new List <AbstractPolygon>();
                    List <AbstractPolygon> currPointPolygons = new List <AbstractPolygon>();
                    HW_GeoSolver.ins.geomanager.bidirectionalNeighborsOfNode(_prevPoint.figName)                                                           //all bidirectional neighbors
                    .Where(d => HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractPolygon>() != null).ToList()          // list of all abstractpolygons in prev list
                    .ForEach(d => prevPointPolygons.Add(HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractPolygon>())); //foreach adds the polygon to final list
                    HW_GeoSolver.ins.geomanager.bidirectionalNeighborsOfNode(_currPoint.figName)                                                           //same as above but with other point
                    .Where(d => HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractPolygon>() != null).ToList()
                    .ForEach(d => currPointPolygons.Add(HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <AbstractPolygon>()));
                    //prevPointPolygons.ForEach(p => Debug.Log(_prevPoint.figName + " is in the following: " + p.figName));
                    //Debug.Log("_____+_____");
                    //currPointPolygons.ForEach(p => Debug.Log(_currPoint.figName + " is in the following: " + p.figName));
                    //Debug.Log("_____=_____");
                    List <AbstractPolygon> sharedPolygons;
                    if (prevPointPolygons.Count > currPointPolygons.Count)
                    {
                        sharedPolygons = prevPointPolygons.Intersect(currPointPolygons).Where(poly => poly.lineList.Count > 3).ToList();
                    }
                    else
                    {
                        sharedPolygons = currPointPolygons.Intersect(prevPointPolygons).Where(poly => poly.lineList.Count > 3).ToList();
                    }
                    //sharedPolygons.ForEach(p => Debug.Log("Both are in the following: " + p.figName));
                    //list created from any duplicates from two prev lists that have more than 3 sides
                    //Debug.Log(_prevPoint.figName + " and " + _currPoint.figName + " are both on " + sharedPolygons.Count + " together.");
                    if (sharedPolygons.Count > 0)
                    {
                        DependentLineSegment cutLine = GeoObjConstruction.dLineSegment(_prevPoint, _currPoint);
                        foreach (AbstractPolygon p in sharedPolygons)
                        {
                            List <AbstractPoint>       currPointList = p.pointList;
                            List <AbstractLineSegment> currLineList  = p.lineList;
                            if (Mathf.Abs(currPointList.IndexOf(_prevPoint) - currPointList.IndexOf(_currPoint)) > 1)
                            {
                                List <AbstractPoint> newPointList1 = newPointListGen(currPointList, currPointList.IndexOf(_prevPoint), currPointList.IndexOf(_currPoint));
                                List <AbstractPoint> newPointList2 = newPointListGen(currPointList, currPointList.IndexOf(_currPoint), currPointList.IndexOf(_prevPoint));

                                List <AbstractLineSegment> newLineList1 = new List <AbstractLineSegment>()
                                {
                                    cutLine
                                };                                                                                                                           //creates list and adds the line created by the cut
                                List <AbstractLineSegment> newLineList2 = new List <AbstractLineSegment>()
                                {
                                    cutLine
                                };                                                                                                                   //creates list and adds the line created by the cut
                                foreach (AbstractLineSegment currLine in currLineList                                                                //newLineList1 Generator
                                         .Where(cL => ((cL.GetComponent <InteractableLineSegment>() != null &&                                       //is interactable line segment and point1 or point2 is found in newPointList1
                                                        newPointList1.Any(point => point == cL.GetComponent <InteractableLineSegment>().point1 || point == cL.GetComponent <InteractableLineSegment>().point2)) ||
                                                       ((cL.GetComponent <DependentLineSegment>() != null &&                                         //is dependent line segment and point1 or point2 is found in newPointList1
                                                         newPointList1.Any(point => point == cL.GetComponent <DependentLineSegment>().point1 || point == cL.GetComponent <DependentLineSegment>().point2))))))
                                {
                                    newLineList1.Add(currLine);
                                }
                                foreach (AbstractLineSegment currLine in currLineList                                                                   //newLineList2 Generator
                                         .Where(cL => ((cL.GetComponent <InteractableLineSegment>() != null &&                                          //is interactable line segment and point1 or point2 is found in newPointList1
                                                        newPointList2.Any(point => point == cL.GetComponent <InteractableLineSegment>().point1 || point == cL.GetComponent <InteractableLineSegment>().point2)) ||
                                                       ((cL.GetComponent <DependentLineSegment>() != null &&                                            //is dependent line segment and point1 or point2 is found in newPointList1
                                                         newPointList2.Any(point => point == cL.GetComponent <DependentLineSegment>().point1 || point == cL.GetComponent <DependentLineSegment>().point2))))))
                                {
                                    newLineList2.Add(currLine);
                                }
                                AbstractPolygon          newPoly1      = GeoObjConstruction.iPolygon(newLineList1, newPointList1);
                                AbstractPolygon          newPoly2      = GeoObjConstruction.iPolygon(newLineList2, newPointList2);
                                List <InteractablePrism> currPrismList = new List <InteractablePrism>();
                                HW_GeoSolver.ins.geomanager.bidirectionalNeighborsOfNode(p.figName)                                        //all bidirectional neighbors
                                .Where(d => HW_GeoSolver.ins.geomanager.findGraphNode(d.Value).mytransform.GetComponent <InteractablePrism>() != null).ToList().ForEach(prism => currPrismList.Add(prism.mytransform.GetComponent <InteractablePrism>()));
                                foreach (InteractablePrism cPrism in currPrismList)
                                {
                                    HW_GeoSolver.ins.AddDependence(newPoly1, cPrism);
                                    HW_GeoSolver.ins.AddDependence(newPoly2, cPrism);
                                }
                                HW_GeoSolver.ins.removeComponent(p);
                            }
                        }
                        //GameObject currScissors = Instantiate(scissors);
                        //currScissors.transform.position = _prevPoint.transform.position;														Cuts things
                        //currScissors.GetComponent<scissorAnimator>().travel(_prevPoint.transform.position, _currPoint.transform.position);
                        Destroy(gameObject, Time.fixedDeltaTime);
                    }
                    break;

                default:
                    break;
                }
            }
        }
Esempio n. 6
0
        internal static InteractablePrism iPrism(AbstractPolygon polygon)
        {
            List <AbstractLineSegment> lineList0  = polygon.transform.GetComponent <AbstractPolygon>().lineList;
            List <AbstractPoint>       pointList0 = polygon.transform.GetComponent <AbstractPolygon>().pointList;

            //make new lists for the points and lines in the new plane
            List <AbstractLineSegment> lineList1  = new List <AbstractLineSegment>();
            List <AbstractPoint>       pointList1 = new List <AbstractPoint>();

            //create new points for the new plane.
            foreach (AbstractPoint point in pointList0)
            {
                AbstractPoint newPoint = iPoint(point.Position3);
                pointList1.Add(newPoint);
            }

            //create new lines for the new plane.
            foreach (AbstractLineSegment line in lineList0)
            {
                if (line.GetComponent <InteractableLineSegment>() != null)
                {
                    int point1Index = pointList0.IndexOf(line.transform.GetComponent <InteractableLineSegment>().point1);
                    int point2Index = pointList0.IndexOf(line.transform.GetComponent <InteractableLineSegment>().point2);

                    AbstractLineSegment newLine = iLineSegment(pointList1[point1Index], pointList1[point2Index]);
                    lineList1.Add(newLine);
                    HW_GeoSolver.ins.AddDependence(newLine, pointList1[point1Index]);
                    HW_GeoSolver.ins.AddDependence(newLine, pointList1[point2Index]);
                }
                else if (line.GetComponent <DependentLineSegment>() != null)
                {
                    int point1Index = pointList0.IndexOf(line.transform.GetComponent <DependentLineSegment>().point1);
                    int point2Index = pointList0.IndexOf(line.transform.GetComponent <DependentLineSegment>().point2);

                    AbstractLineSegment newLine = iLineSegment(pointList1[point1Index], pointList1[point2Index]);
                    lineList1.Add(newLine);

                    HW_GeoSolver.ins.AddDependence(newLine, pointList1[point1Index]);
                    HW_GeoSolver.ins.AddDependence(newLine, pointList1[point2Index]);
                }
            }

            AbstractPolygon plane1 = iPolygon(lineList1, pointList1);


            plane1.InitializeFigure();
            List <AbstractPolygon> sideList = new List <AbstractPolygon>();

            foreach (AbstractLineSegment l in lineList0)
            {
                int lineIndex = lineList0.IndexOf(l);

                sideList.Add(makePlaneWall(lineIndex, lineList0, lineList1));
            }

            InteractablePrism      prism    = InteractablePrism.Constructor();
            List <AbstractPolygon> baseList = new List <AbstractPolygon>();

            baseList.Add(polygon);
            baseList.Add(plane1);

            prism.bases = baseList;
            prism.sides = sideList;

            prism.vertexPoints.ForEach(p => HW_GeoSolver.ins.AddDependence(prism, p));
            prism.lineSegments.ForEach(l => HW_GeoSolver.ins.AddDependence(prism, l));
            prism.bases.ForEach(b => HW_GeoSolver.ins.AddDependence(prism, b));
            prism.sides.ForEach(b => HW_GeoSolver.ins.AddDependence(prism, b));
            prism.InitializeFigure();

            return(prism);
        }
Esempio n. 7
0
        internal static InteractablePrism dPrism(AbstractPolygon polygon, Vector3 base2Pos)
        {
            List <AbstractLineSegment> lineList0  = new List <AbstractLineSegment>();
            List <AbstractPoint>       pointList0 = new List <AbstractPoint>();

            lineList0  = polygon.transform.GetComponent <AbstractPolygon>().lineList;
            pointList0 = polygon.transform.GetComponent <AbstractPolygon>().pointList;

            //make new lists for the points and lines in the new plane
            List <AbstractLineSegment> lineList1  = new List <AbstractLineSegment>();
            List <AbstractPoint>       pointList1 = new List <AbstractPoint>();

            //create new points for the new plane.
            foreach (AbstractPoint point in pointList0)
            {
                AbstractPoint newPoint = dPoint(point.Position3 - polygon.Position3 + base2Pos);
                pointList1.Add(newPoint);
            }

            //create new lines for the new plane.
            foreach (AbstractLineSegment line in lineList0)
            {
                if (line.GetComponent <InteractableLineSegment>() != null)
                {
                    int point1Index = pointList0.IndexOf(line.transform.GetComponent <InteractableLineSegment>().point1);
                    int point2Index = pointList0.IndexOf(line.transform.GetComponent <InteractableLineSegment>().point2);

                    AbstractLineSegment newLine = iLineSegment(pointList1[point1Index].GetComponent <AbstractPoint>(), pointList1[point2Index].GetComponent <AbstractPoint>());
                    lineList1.Add(newLine);

                    HW_GeoSolver.ins.AddDependence(newLine, pointList1[point1Index]);
                    HW_GeoSolver.ins.AddDependence(newLine, pointList1[point2Index]);
                }
                else if (line.GetComponent <DependentLineSegment>() != null)
                {
                    int point1Index = pointList0.IndexOf(line.transform.GetComponent <DependentLineSegment>().point1);
                    int point2Index = pointList0.IndexOf(line.transform.GetComponent <DependentLineSegment>().point2);

                    AbstractLineSegment newLine = iLineSegment(pointList1[point1Index].GetComponent <AbstractPoint>(), pointList1[point2Index].GetComponent <AbstractPoint>());
                    lineList1.Add(newLine);

                    HW_GeoSolver.ins.AddDependence(newLine, pointList1[point1Index]);
                    HW_GeoSolver.ins.AddDependence(newLine, pointList1[point2Index]);
                }
            }

            AbstractPolygon plane1 = dPolygon(lineList1, pointList1);

            plane1.AddToRManager();

            foreach (AbstractLineSegment line in lineList1)
            {
                HW_GeoSolver.ins.AddDependence(plane1, line);
            }

            plane1.transform.GetComponent <AbstractPolygon>().InitializeFigure();
            List <AbstractPolygon> sideList = new List <AbstractPolygon>();

            foreach (AbstractLineSegment line0 in lineList0)
            {
                int lineIndex = lineList0.IndexOf(line0);


                AbstractLineSegment lineTest = lineList0[lineIndex];

                sideList.Add(makePlaneWall(lineIndex, lineList0, lineList1));
            }

            InteractablePrism      prism    = InteractablePrism.Constructor();
            List <AbstractPolygon> baseList = new List <AbstractPolygon>
            {
                polygon,
                plane1
            };

            prism.bases = baseList;
            prism.sides = sideList;

            foreach (AbstractPolygon poly in baseList)
            {
                HW_GeoSolver.ins.AddDependence(prism, poly);
            }
            foreach (AbstractPolygon poly in sideList)
            {
                HW_GeoSolver.ins.AddDependence(prism, poly);
            }

            prism.vertexPoints.ForEach(p => HW_GeoSolver.ins.AddDependence(prism, p));

            prism.InitializeFigure();

            return(prism);
        }