private MasterGeoObj[] checkSphereSphere(AbstractSphere abstractSphere1, AbstractSphere abstractSphere2) { intersectionFigData data = IntersectionMath.SphereSphereIntersection(abstractSphere1, abstractSphere2); Debug.Log("Data produces " + data.figtype.ToString()); Debug.Log("Point Value " + data.vectordata[0].ToString()); MasterGeoObj[] mgoResult = null; if (data.figtype == GeoObjType.circle) { DependentPoint centerPoint = GeoObjConstruction.dPoint(data.vectordata[0]); Vector3 radiusDirection = Vector3.up; if (Vector3.Cross(radiusDirection, data.vectordata[1]).magnitude == 0) { radiusDirection = Vector3.right; } radiusDirection = Vector3.Cross(data.vectordata[1], radiusDirection).normalized; DependentPoint edgePoint = GeoObjConstruction.dPoint(data.vectordata[2]); DependentCircle newCircle = GeoObjConstruction.dCircle(centerPoint, edgePoint, data.vectordata[1]); mgoResult = new MasterGeoObj[] { centerPoint.setIntersectionFigure(0), edgePoint.setIntersectionFigure(0), newCircle.setIntersectionFigure(0) }; } else if (data.figtype == GeoObjType.point) { mgoResult = new MasterGeoObj[] { GeoObjConstruction.dPoint(data.vectordata[0]) }; } return(mgoResult); }
private MasterGeoObj[] checkSphereFlatface(AbstractSphere abstractSphere, flatfaceBehave flatfaceBehave) { intersectionFigData data = IntersectionMath.SpherePlaneIntersection(abstractSphere, flatfaceBehave); MasterGeoObj[] mgoResult = null; if (data.figtype == GeoObjType.circle) { DependentPoint centerPoint = GeoObjConstruction.dPoint(data.vectordata[0]); Vector3 radiusDirection = Vector3.up; if (Vector3.Cross(radiusDirection, data.vectordata[1]).magnitude == 0) { radiusDirection = Vector3.right; } radiusDirection = Vector3.Cross(data.vectordata[1], radiusDirection).normalized; DependentPoint edgePoint = GeoObjConstruction.dPoint(data.vectordata[0] + data.floatdata[0] * radiusDirection); DependentCircle newCircle = GeoObjConstruction.dCircle(centerPoint, edgePoint, data.vectordata[1]); mgoResult = new MasterGeoObj[] { centerPoint.setIntersectionFigure(0), edgePoint.setIntersectionFigure(1), newCircle.setIntersectionFigure(2) }; } else if (data.figtype == GeoObjType.point) { mgoResult = new MasterGeoObj[] { GeoObjConstruction.dPoint(data.vectordata[0]) }; } return(mgoResult); }
private MasterGeoObj[] checkFlatfaceStraightedge(flatfaceBehave flatfaceBehave, straightEdgeBehave straightEdgeBehave) { intersectionFigData data = IntersectionMath.LinePlaneIntersection(flatfaceBehave, straightEdgeBehave); MasterGeoObj[] mgoResult = null; if (data.figtype == GeoObjType.point) { mgoResult = new MasterGeoObj[] { GeoObjConstruction.dPoint(data.vectordata[0]).setIntersectionFigure(0) }; } return(mgoResult); }
private AbstractGeoObj[] checkStraightedgeStraightedge(straightEdgeBehave straightEdgeBehave1, straightEdgeBehave straightEdgeBehave2) { intersectionFigData data = IntersectionMath.LineLineIntersection(straightEdgeBehave1, straightEdgeBehave2); AbstractGeoObj[] mgoResult = null; if (data.figtype == GeoObjType.point) { mgoResult = new AbstractGeoObj[] { GeoObjConstruction.dPoint(data.vectordata[0]).setIntersectionFigure(0) }; } return(mgoResult); }
private MasterGeoObj[] checkSphereStraightEdge(AbstractSphere abstractSphere, straightEdgeBehave straightEdgeBehave) { intersectionFigData data = IntersectionMath.SphereLineIntersection(abstractSphere, straightEdgeBehave); MasterGeoObj[] mgoResult = null; if (data.figtype == GeoObjType.point) { if (data.vectordata.Length == 1) { mgoResult = new MasterGeoObj[] { GeoObjConstruction.dPoint(data.vectordata[0]).setIntersectionFigure(0) }; } else if (data.vectordata.Length == 2) { mgoResult = new MasterGeoObj[] { GeoObjConstruction.dPoint(data.vectordata[0]).setIntersectionFigure(0), GeoObjConstruction.dPoint(data.vectordata[1]).setIntersectionFigure(1) }; } } return(mgoResult); }
private MasterGeoObj[] CheckCircleCircle(AbstractCircle abstractCircle1, AbstractCircle abstractCircle2) { intersectionFigData data = IntersectionMath.CircleCircleIntersection(abstractCircle1, abstractCircle2); MasterGeoObj[] mgoResult = null; if (data.figtype == GeoObjType.point) { if (data.vectordata.Length == 1) { mgoResult = new MasterGeoObj[] { GeoObjConstruction.dPoint(data.vectordata[0]).setIntersectionFigure(0) }; } else if (data.vectordata.Length == 2) { mgoResult = new MasterGeoObj[] { GeoObjConstruction.dPoint(data.vectordata[0]).setIntersectionFigure(0), GeoObjConstruction.dPoint(data.vectordata[1]).setIntersectionFigure(1) }; } } return(mgoResult); }
private AbstractGeoObj[] checkSpherecircle(AbstractSphere abstractSphere, AbstractCircle abstractCircle) { intersectionFigData data = IntersectionMath.SphereCircleIntersection(abstractSphere, abstractCircle); AbstractGeoObj[] mgoResult = null; if (data.figtype == GeoObjType.point) { if (data.vectordata.Length == 1) { mgoResult = new AbstractGeoObj[] { GeoObjConstruction.dPoint(data.vectordata[0]).setIntersectionFigure(0) }; } else if (data.vectordata.Length == 2) { mgoResult = new AbstractGeoObj[] { GeoObjConstruction.dPoint(data.vectordata[0]).setIntersectionFigure(0), GeoObjConstruction.dPoint(data.vectordata[1]).setIntersectionFigure(1) }; } } return(mgoResult); }
private AbstractGeoObj[] checkCircleFlatface(AbstractCircle abstractCircle, flatfaceBehave flatfaceBehave) { intersectionFigData data = IntersectionMath.CirclePlaneIntersection(abstractCircle, flatfaceBehave); AbstractGeoObj[] mgoResult = null; if (data.figtype == GeoObjType.point) { if (data.vectordata.Length == 1) { mgoResult = new AbstractGeoObj[] { GeoObjConstruction.dPoint(data.vectordata[0]).setIntersectionFigure(0) }; } else if (data.vectordata.Length == 2) { mgoResult = new AbstractGeoObj[] { GeoObjConstruction.dPoint(data.vectordata[0]).setIntersectionFigure(0), GeoObjConstruction.dPoint(data.vectordata[1]).setIntersectionFigure(1) }; } } return(mgoResult); }
//[ContextMenu("Load from Save")] for debugging make public and uncomment private void xmlToMGO() { Dictionary <string, AbstractGeoObj> spawnedObjects = new Dictionary <string, AbstractGeoObj>(); foreach (GeoObj geo in GeoObjDB.list) { switch (geo.type) { case GeoObjType.point: AbstractGeoObj spawnedPoint = null; //initialzed as null so that cases that do not spawn still have it initialized but still fails a null check. switch (geo.definition) { case GeoObjDef.Abstract: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Dependent: spawnedPoint = GeoObjConstruction.dPoint(geo.position); break; case GeoObjDef.Interactable: spawnedPoint = GeoObjConstruction.iPoint(geo.position); break; case GeoObjDef.Static: spawnedPoint = GeoObjConstruction.sPoint(geo.position); break; case GeoObjDef.none: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; default: break; } if (spawnedPoint != null) { if (!String.IsNullOrEmpty(geo.label)) { GeoObjConstruction.label(spawnedPoint, geo.label); } spawnedObjects.Add(geo.figName, spawnedPoint); } break; case GeoObjType.line: AbstractGeoObj spawnedLine = null; //initialzed as null so that cases that do not spawn still have it initialized but still fails a null check. switch (geo.definition) { case GeoObjDef.Abstract: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Dependent: spawnedLine = GeoObjConstruction.dLineSegment(spawnedObjects[geo.dependencies[0]] as AbstractPoint, spawnedObjects[geo.dependencies[1]] as AbstractPoint); break; case GeoObjDef.Interactable: spawnedLine = GeoObjConstruction.iLineSegment(spawnedObjects[geo.dependencies[0]] as AbstractPoint, spawnedObjects[geo.dependencies[1]] as AbstractPoint); break; case GeoObjDef.Static: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.none: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; default: break; } if (spawnedLine != null) { if (!String.IsNullOrEmpty(geo.label)) { GeoObjConstruction.label(spawnedLine, geo.label); } spawnedObjects.Add(geo.figName, spawnedLine); } break; case GeoObjType.polygon: AbstractGeoObj spawnedPoly = null; //initialzed as null so that cases that do not spawn still have it initialized but still fails a null check. List <AbstractLineSegment> lineList; List <AbstractPoint> pointList; switch (geo.definition) { case GeoObjDef.Abstract: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Dependent: lineList = new List <AbstractLineSegment>(); geo.dependencies.Where(d => spawnedObjects[d].figType == GeoObjType.line).ToList().ForEach(l => lineList.Add(spawnedObjects[l] as AbstractLineSegment)); pointList = new List <AbstractPoint>(); geo.dependencies.Where(d => spawnedObjects[d].figType == GeoObjType.point).ToList().ForEach(p => pointList.Add(spawnedObjects[p] as AbstractPoint)); spawnedPoly = GeoObjConstruction.dPolygon(lineList, pointList); break; case GeoObjDef.Interactable: lineList = new List <AbstractLineSegment>(); geo.dependencies.Where(d => spawnedObjects[d].figType == GeoObjType.line).ToList().ForEach(l => lineList.Add(spawnedObjects[l] as AbstractLineSegment)); pointList = new List <AbstractPoint>(); geo.dependencies.Where(d => spawnedObjects[d].figType == GeoObjType.point).ToList().ForEach(p => pointList.Add(spawnedObjects[p] as AbstractPoint)); spawnedPoly = GeoObjConstruction.iPolygon(lineList, pointList); break; case GeoObjDef.Static: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.none: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; default: break; } if (spawnedPoly != null) { if (!String.IsNullOrEmpty(geo.label)) { GeoObjConstruction.label(spawnedPoly, geo.label); } spawnedObjects.Add(geo.figName, spawnedPoly); } break; case GeoObjType.prism: AbstractGeoObj spawnedPrism = null; //initialzed as null so that cases that do not spawn still have it initialized but still fails a null check. switch (geo.definition) { case GeoObjDef.Abstract: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Dependent: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Interactable: if (!(geo.prismData.bases.Count < 2 || geo.prismData.sides.Count < spawnedObjects[geo.prismData.bases[0]].GetComponent <AbstractPolygon>().pointList.Count)) { List <AbstractPolygon> bases = new List <AbstractPolygon>(); List <AbstractPolygon> sides = new List <AbstractPolygon>(); geo.prismData.bases.ForEach(b => bases.Add(spawnedObjects[b] as AbstractPolygon)); geo.prismData.sides.ForEach(s => sides.Add(spawnedObjects[s] as AbstractPolygon)); spawnedPrism = GeoObjConstruction.iPrism(bases, sides); } else { List <AbstractLineSegment> edges = new List <AbstractLineSegment>(); geo.prismData.edges.ForEach(e => edges.Add(spawnedObjects[e] as AbstractLineSegment)); spawnedPrism = GeoObjConstruction.iPrism(edges); } break; case GeoObjDef.Static: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.none: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; default: break; } if (spawnedPrism != null) { if (!String.IsNullOrEmpty(geo.label)) { GeoObjConstruction.label(spawnedPrism, geo.label); } spawnedObjects.Add(geo.figName, spawnedPrism); } break; case GeoObjType.pyramid: AbstractGeoObj spawnedPyramid = null; //initialzed as null so that cases that do not spawn still have it initialized but still fails a null check. switch (geo.definition) { case GeoObjDef.Abstract: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Dependent: spawnedPyramid = GeoObjConstruction.dPyramid(spawnedObjects[geo.dependencies[0]] as AbstractPolygon, spawnedObjects[geo.pyramidData.apexName] as AbstractPoint); break; case GeoObjDef.Interactable: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Static: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.none: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; default: break; } if (spawnedPyramid != null) { if (!String.IsNullOrEmpty(geo.label)) { GeoObjConstruction.label(spawnedPyramid, geo.label); } spawnedObjects.Add(geo.figName, spawnedPyramid); } break; case GeoObjType.circle: AbstractGeoObj spawnedCircle = null; //initialzed as null so that cases that do not spawn still have it initialized but still fails a null check. switch (geo.definition) { case GeoObjDef.Abstract: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Dependent: spawnedCircle = GeoObjConstruction.dCircle(spawnedObjects[geo.dependencies[0]] as AbstractPoint, spawnedObjects[geo.dependencies[1]] as AbstractPoint, geo.circleData.normDir); break; case GeoObjDef.Interactable: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Static: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.none: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; default: break; } if (spawnedCircle != null) { if (!String.IsNullOrEmpty(geo.label)) { GeoObjConstruction.label(spawnedCircle, geo.label); } spawnedObjects.Add(geo.figName, spawnedCircle); } break; case GeoObjType.sphere: AbstractGeoObj spawnedSphere = null; //initialzed as null so that cases that do not spawn still have it initialized but still fails a null check. switch (geo.definition) { case GeoObjDef.Abstract: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Dependent: spawnedSphere = GeoObjConstruction.dSphere(spawnedObjects[geo.dependencies[0]] as AbstractPoint, spawnedObjects[geo.dependencies[1]] as AbstractPoint); break; case GeoObjDef.Interactable: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Static: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.none: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; default: break; } if (spawnedSphere != null) { if (!String.IsNullOrEmpty(geo.label)) { GeoObjConstruction.label(spawnedSphere, geo.label); } spawnedObjects.Add(geo.figName, spawnedSphere); } break; case GeoObjType.revolvedsurface: AbstractGeoObj spawnedrevSurf = null; //initialzed as null so that cases that do not spawn still have it initialized but still fails a null check. switch (geo.definition) { case GeoObjDef.Abstract: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Dependent: spawnedrevSurf = GeoObjConstruction.dRevSurface(spawnedObjects[geo.dependencies[0]] as AbstractPoint, spawnedObjects[geo.dependencies[1]] as AbstractLineSegment, geo.revSurfData.normDir); spawnedrevSurf.transform.position = geo.position; spawnedrevSurf.transform.rotation = geo.rotation; break; case GeoObjDef.Interactable: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.Static: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; case GeoObjDef.none: Debug.Log(geo.figName + " was attempted to spawn but is not supported yet within XMLManager script! Add construction function in place of this log."); break; default: break; } if (spawnedrevSurf != null) { if (!String.IsNullOrEmpty(geo.label)) { GeoObjConstruction.label(spawnedrevSurf, geo.label); } spawnedObjects.Add(geo.figName, spawnedrevSurf); } break; case GeoObjType.torus: break; case GeoObjType.flatface: Transform flatface = flatfaceBehave.Constructor().transform; flatface.transform.position = geo.position; flatface.transform.rotation = geo.rotation; if (!String.IsNullOrEmpty(geo.label)) { GeoObjConstruction.label(flatface.GetComponent <flatfaceBehave>(), geo.label); } spawnedObjects.Add(geo.figName, flatface.GetComponent <AbstractGeoObj>()); break; case GeoObjType.straightedge: Transform straightEdge = straightEdgeBehave.Constructor().transform; straightEdge.transform.position = geo.position; straightEdge.transform.rotation = geo.rotation; if (!String.IsNullOrEmpty(geo.label)) { GeoObjConstruction.label(straightEdge.GetComponent <straightEdgeBehave>(), geo.label); } spawnedObjects.Add(geo.figName, straightEdge.GetComponent <AbstractGeoObj>()); break; default: break; } } }
// Use this for initialization private void Start() { volumeLineRenderer = GetComponentInChildren <LineRenderer>(); TMPro = GetComponentInChildren <TextMeshPro>(); myAudioSource = GetComponent <AudioSource>(); xLen = .1f; controllPoint = GeoObjConstruction.iPoint(this.transform.position); prismBase.Add(controllPoint); prismBase.Add(GeoObjConstruction.dPoint(controllPoint.Position3 + Vector3.right * (sideLength1 - 2 * xLen))); prismBase.Add(GeoObjConstruction.dPoint(controllPoint.Position3 + Vector3.right * (sideLength1 - 2 * xLen) + Vector3.forward * (sideLength2 - 2 * xLen))); prismBase.Add(GeoObjConstruction.dPoint(controllPoint.Position3 + Vector3.forward * (sideLength2 - 2 * xLen))); List <AbstractLineSegment> prismBaseLines = new List <AbstractLineSegment>(); for (int i = 0; i < 3; i++) { prismBaseLines.Add(GeoObjConstruction.dLineSegment(prismBase[i], prismBase[i + 1])); } prismBaseLines.Add(GeoObjConstruction.dLineSegment(prismBase[prismBase.Count - 1], prismBase[0])); prismBasePoly = GeoObjConstruction.dPolygon(prismBaseLines, prismBase); prism = GeoObjConstruction.dPrism(prismBasePoly, prismBasePoly.center + Vector3.up * xLen); prismTopPoly = prism.bases[1]; cutoutRectangle.Add(prismBase[0]); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[0].Position3 + Vector3.back * xLen)); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[1].Position3 + Vector3.back * xLen)); cutoutRectangle.Add(prismBase[1]); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[1].Position3 + Vector3.right * xLen)); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[2].Position3 + Vector3.right * xLen)); cutoutRectangle.Add(prismBase[2]); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[2].Position3 + Vector3.forward * xLen)); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[3].Position3 + Vector3.forward * xLen)); cutoutRectangle.Add(prismBase[3]); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[3].Position3 + Vector3.left * xLen)); cutoutRectangle.Add(GeoObjConstruction.dPoint(prismBase[0].Position3 + Vector3.left * xLen)); List <AbstractLineSegment> cutoutLines = new List <AbstractLineSegment>(); for (int i = 0; i < cutoutRectangle.Count - 1; i++) { cutoutLines.Add(GeoObjConstruction.dLineSegment(cutoutRectangle[i], cutoutRectangle[i + 1])); } cutoutLines.Add(GeoObjConstruction.dLineSegment(cutoutRectangle[0], cutoutRectangle[cutoutRectangle.Count - 1])); cutoutRectanglePoly = GeoObjConstruction.dPolygon(cutoutLines, cutoutRectangle); foreach (MasterGeoObj mgo in prism.transform.parent.GetComponentsInChildren <MasterGeoObj>()) { if (mgo != controllPoint) { mgo.LeapInteraction = false; } } controllPoint.GetComponent <Leap.Unity.Interaction.InteractionBehaviour>().OnGraspedMovement += updateDiagram; controllPoint.GetComponent <Leap.Unity.Interaction.InteractionBehaviour>().OnGraspEnd += updateDiagram; volumeLineRenderer.useWorldSpace = false; Color tmp = Color.blue; tmp.a = .5f; cutoutRectanglePoly.figColor = tmp; foreach (AbstractPolygon poly in prism.allfaces) { tmp = Color.red; tmp.a = .5f; poly.figColor = tmp; } prism.bases[0].figColor = Color.clear; }