// Use this for initialization void Start() { // float input = 237.5654665f; // // float part1 = GetColorPart1(input, 0, 1024); // float part2 = GetColorPart2(input, 0, 1024); // // Debug.Log ("MAP1: " + part1); // Debug.Log ("MAP2: " + part2); // Debug.Log ("Convert: " + PartsToFloat(part1, part2, 0, 1024)); cam = Camera.main; cfs = cam.GetComponent <CameraFrustrumScript>(); front = cfs.GetFrontPlane(); back = new Vector3[4]; for (int i = 0; i < front.Length; i++) { back[i] = UtilScript.CloneVec3(front[i]); back[i].z = front[0].z + cam.farClipPlane - cam.nearClipPlane; } totalWidth = front[1].x - front[0].x; totalHeight = front[2].y - front[0].y; totalDepth = back[0].z - front[0].z; Debug.Log("totalWidth: " + totalWidth); Debug.Log("totalHeight: " + totalHeight); Debug.Log("totalDepth: " + totalDepth); camPos = cam.transform.position; gridDivide = (int)Mathf.Ceil(Mathf.Sqrt(lineConfiguration)); if (lumarcaMode == LUMARCA_MODE.Dots) { GenerateDots(); } else { GenerateLines(); MultiPerDepthAndCutOutsideOfCube(); } Debug.Log("Lines: " + lines.Count); SetColorToPart(); }
// Use this for initialization void Start() { // float input = 237.5654665f; // // float part1 = GetColorPart1(input, 0, 1024); // float part2 = GetColorPart2(input, 0, 1024); // // Debug.Log ("MAP1: " + part1); // Debug.Log ("MAP2: " + part2); // Debug.Log ("Convert: " + PartsToFloat(part1, part2, 0, 1024)); cam = Camera.main; cfs = cam.GetComponent <CameraFrustrumScript>(); front = cfs.GetFrontPlane(); back = new Vector3[4]; back[0] = GetFarClippingPlane(front[0]); back[1] = GetFarClippingPlane(front[1]); back[2] = GetFarClippingPlane(front[2]); back[3] = GetFarClippingPlane(front[3]); totalWidth = front[1].x - front[0].x; frontHeight = front[2].y - front[0].y; backHeight = back[2].y - back[0].y; totalDepth = back[0].z - front[0].z; Debug.Log("totalWidth: " + totalWidth); Debug.Log("totalHeight: " + frontHeight); Debug.Log("totalDepth: " + totalDepth); camPos = cam.transform.position; gridDivide = (int)Mathf.Ceil(Mathf.Sqrt(numDepths)); // gridDivide = lineConfiguration/numDepths; GenerateLines(); // MultiPerDepthAndCutOutsideOfCube(); Debug.Log("Lines: " + lines.Count); SetColorToPart(); }
// Use this for initialization void Start() { Cursor.visible = false; ray = new Ray(); BinaryReader reader = new BinaryReader(File.Open("DotPositions.json", FileMode.Open)); // JSONNode ja = SimpleJSON.JSONNode.Deserialize(reader); string jsonStr = reader.ReadString(); JObject ja = JsonConvert.DeserializeObject(jsonStr) as JObject; for (int i = 0; i < ja.Count; i++) { Vector3 vec = UtilScript.JsonToVector3(ja[i]); posList.Add(vec); } Dictionary <int, List <Vector3> > sameDepth = new Dictionary <int, List <Vector3> >(); dotsByZY = new Dictionary <int, Dictionary <int, List <Vector3> > >(); quadsByZY = new Dictionary <int, Dictionary <int, List <GameObject> > >(); //Sort all the dots at the same depth into a temporary Dictionary foreach (Vector3 dPos in posList) { if (!sameDepth.ContainsKey((int)dPos.z)) { sameDepth.Add((int)dPos.z, new List <Vector3>()); } sameDepth[(int)dPos.z].Add(dPos); } //Sort all the dots into a Dictionary of Dictionarys, sorted by Z and Y //This makes rows of dots, or lines, which we can then use to check intersections foreach (int z in sameDepth.Keys) { dotsByZY.Add(z, new Dictionary <int, List <Vector3> >()); List <Vector3> list = sameDepth[z]; foreach (Vector3 zPos in list) { if (!dotsByZY[z].ContainsKey((int)zPos.y)) { dotsByZY[z].Add((int)zPos.y, new List <Vector3>()); } dotsByZY[z][(int)zPos.y].Add(zPos); } } int totalLines = 0; //Count up all the lines, create a Quad for each position foreach (int zVal in dotsByZY.Keys) { Dictionary <int, List <Vector3> > dict = dotsByZY[zVal]; if (debugMessages) { Debug.Log("->" + zVal + ": " + dict.Count); } quadsByZY.Add(zVal, new Dictionary <int, List <GameObject> >()); foreach (int yVal in dict.Keys) { List <Vector3> line = dict[yVal]; if (debugMessages) { Debug.Log("---->" + yVal + ": " + line.Count); } quadsByZY[zVal].Add(yVal, new List <GameObject>()); foreach (Vector3 vec in line) { GameObject q = Instantiate(Resources.Load("Quad")) as GameObject; q.transform.localScale = new Vector3(dotSize / 2, dotSize / 2, dotSize / 2); q.transform.position = vec; q.SetActive(false); quadsByZY[zVal][yVal].Add(q); } totalLines++; } } if (debugMessages) { Debug.Log("totalLines: " + totalLines); } int posCount = 0; CameraFrustrumScript cfs = Camera.main.GetComponent <CameraFrustrumScript>(); front = cfs.GetFrontPlane(); back = new Vector3[4]; for (int i = 0; i < front.Length; i++) { back[i] = UtilScript.CloneVec3(front[i]); back[i].z = Camera.main.farClipPlane - Camera.main.nearClipPlane; } }
// Use this for initialization void Setup() { if (!init) { PlayerPrefs.SetString(PP_KILL_STRING, ""); foreach (int i in killStrings) { killStringsList.Add(i); } print("killStringsList:" + killStringsList.Count); string text = PlayerPrefs.GetString(PP_KILL_STRING, ""); string[] splitKill = text.Split(','); print("text: " + text); for (int i = 0; i < splitKill.Length; i++) { int num = 0; System.Int32.TryParse(splitKill[i], out num); //KILL STRING MIGHT ALWAYS INCLUDE 0, BECAUSE OF TryParse if (!killStringsList.Contains(num)) { killStringsList.Add(num); } else { print("Killer"); } } for (int i = 0; i < killStringsList.Count; i++) { int num = killStringsList[i]; while (killStringsList.Contains(num)) { killStringsList.Remove(num); } killStringsList.Add(num); } print("killStringsList count: " + killStringsList.Count); init = true; Cursor.visible = !Application.isEditor; SetMaterial(); pool = new List <Vector3>(); for (int i = 0; i < 10000; i++) { pool.Add(new Vector3()); } result = new List <float>(); TextAsset asset = Resources.Load <TextAsset>(jsonLineFile); JObject j1 = JObject.Parse(asset.text); cfs = Camera.main.GetComponent <CameraFrustrumScript>(); Vector3 projPos = new Vector3( (float)j1[LumarcaGenerator.PROP_PROJ_POS]["x"], (float)j1[LumarcaGenerator.PROP_PROJ_POS]["y"], (float)j1[LumarcaGenerator.PROP_PROJ_POS]["z"]); cfs.SetupCamera( (float)j1[LumarcaGenerator.PROP_PHYSICAL_WIDTH], projPos, (float)j1[LumarcaGenerator.PROP_THROW_RATIO], (bool)j1[LumarcaGenerator.PROP_CEILING_MOUNT]); front = cfs.GetFrontPlane(); back = new Vector3[4]; back[0] = LumarcaGenerator.GetFarClippingPlane(front[0]); back[1] = LumarcaGenerator.GetFarClippingPlane(front[1]); back[2] = LumarcaGenerator.GetFarClippingPlane(front[2]); back[3] = LumarcaGenerator.GetFarClippingPlane(front[3]); frontHeight = front[2].y - front[0].y; backHeight = back[2].y - back[0].y; JArray ja = j1["positions"] as JArray; for (int i = 0; i < ja.Count; i++) { Vector3 vec = UtilScript.JsonToVector3(ja[i]); if (flipX) { vec.x = -vec.x; } float lerpPer = (vec.z - front[0].z) / (back[0].z - front[0].z); float lineHeight = Mathf.Lerp(frontHeight, backHeight, lerpPer); if (cfs.ceilingMounted) { vec.y = (front[2].y + (front[2].y - lineHeight)) / 2f; } else { vec.y = (front[0].y + (front[0].y + lineHeight)) / 2f; } posList.Add(vec); } pos = posList.ToArray(); Debug.Log("Num Lines: " + pos.Length); foreach (LumarcaAnimation la in lumarcaAnimations) { la.LoadFromJSON(); } GetComponent <LumarcaAnimation>(); if (recordName) { recordAnimation = GetComponent <LumarcaAnimation>(); if (recordAnimation == null) { recordAnimation = gameObject.AddComponent <LumarcaAnimation>(); } } VectorManager.useDraw3D = true; // 0.6424695 // VectorLine.SetRay3D (Color.green, transform.position, transform.forward * 5.0f); // VectorLine line = VectorLine.SetLine(Color.green, new Vector3[]{Vector3.left, Vector3.down}); // line.SetColor(Color.yellow); // line.Draw3D(); // VectorLine.SetLine(Color.red, new Vector3[]{Vector3.left, Vector3.down}); // // vectorLinePool = new ObjectPool<VectorLine>(new ObjectGenerator<VectorLine>()); // // VectorLine myLine = vectorLinePool.GetObject(); // // myLine.SetColor(Color.blue); // myLine.points3[0] = new Vector3(0,0,0); // myLine.points3[1] = new Vector3(0,1,0); // // List<int> myWidths = new List<int>(){1}; // C# // myLine.SetWidths (myWidths); } }
void drawScene() { if (recordName) { currentFrame = new LumarcaFrame(); } // GL.PushMatrix(); if (mat != null) { mat.SetPass(0); } if (cfs == null) { cfs = Camera.main.GetComponent <CameraFrustrumScript>(); } if (drawCube) { DrawBox(); } foreach (GameObject go in gameObjects) { drawMesh(go); } foreach (LumarcaAnimation la in lumarcaAnimations) { drawAnimation(la); } float topY = front[2].y; foreach (GameObject go in lineRenderers) { LumarcaLineRenderer[] llr = go.GetComponentsInChildren <LumarcaLineRenderer>(); foreach (LumarcaLineRenderer lineRender in llr) { if (lineRender.enabled) { for (int lineNum = 0; lineNum < pos.Length; lineNum++) { if (!killStringsList.Contains(lineNum)) { Vector3 vec = pos[lineNum]; float lerpPer = (vec.z - front[0].z) / (back[0].z - front[0].z); float lineHeight = Mathf.Lerp(frontHeight, backHeight, lerpPer); float bottomY = front[2].y - lineHeight; if (!cfs.ceilingMounted) { bottomY = front[0].y; topY = bottomY + lineHeight; } Vector3[] points = lineRender.GenerateLine( lineNum, vec, front[1].x, front[0].x, topY, bottomY, back[0].z, front[0].z); for (int i = 0; i + 1 < points.Length; i += 2) { points[i].y = Mathf.Clamp(points[i].y, bottomY, topY); if (lineRender.drawDots) { DrawLine(points[i], points[i + 1], lineRender.mat); } else { DrawLineWithoutDots(points[i], points[i + 1], lineRender.mat); } } } } } } } // GL.PopMatrix(); if (recordName) { print(recordName); recordAnimation.AddFrame(currentFrame); } }
void GenerateLines() { float depthIncrement = totalDepth / (numDepths - 1); dotHolder = new GameObject("LineHolder"); GameObject[] depthHolders = new GameObject[numDepths]; for (int i = 1; i <= numDepths; i++) { GameObject go = new GameObject("Depth " + i); go.transform.parent = dotHolder.transform; depthHolders[i - 1] = go; } bag = MakeBag(); lines = new List <Vector3>(); lineObjects = new List <GameObject>(); int index = 0; int maxAttempts = 10; // int temp = bag.Count - 1; // int[,] depths = new int[gridDivide, lineConfiguration/(gridDivide - 1)]; List <List <int> > depths = new List <List <int> >(); for (int gridPos = 0; gridPos < gridDivide; gridPos++) { depths.Add(new List <int>()); } for (int x = 0; x < lineConfiguration; x++) { // Debug.Log("x: " + x + " depths.Count: " + depths.Count + " (x/gridDivide)%gridDivide: " + [(x/gridDivide)%gridDivide); depths[(x / gridDivide) % gridDivide].Add(x); } List <int> gridPickingOrder = new List <int>(); for (int i = 0; i < gridDivide; i += 2) { gridPickingOrder.Add(i); } for (int i = 1; i < gridDivide; i += 2) { gridPickingOrder.Add(i); } // string orderStr = ""; // for(int i = 0; i < gridDivide; i++){ // orderStr += gridPickingOrder[i] + " "; // } // // print("gridPickingOrder: " + orderStr); int lineSplit = (lineConfiguration / gridDivide); int interval = lineSplit / gridDivide; // Debug.Log("lineSplit: " + lineSplit); CameraFrustrumScript cfs = Camera.main.GetComponent <CameraFrustrumScript>(); float lineSpacing = cfs.physicalWidth / lineConfiguration; int lineNum = 0; for (float x = front[0].x + lineSpacing / 2; x < front[1].x; x += lineSpacing) { int attempts = 0; int gridIndex = lineNum % gridPickingOrder.Count; int gridPos = gridPickingOrder[gridIndex]; int segPos = (depths[gridPos].Count) / 2; if ((lineNum / gridDivide) % 2 != 0) { segPos = 0; } // Debug.Log("depths: " + depths.Count); while (depths[gridPos].Count == 0) { lineNum++; gridIndex = lineNum % gridPickingOrder.Count; gridPos = gridPickingOrder[gridIndex]; segPos = (depths[gridPos].Count - 1) / 2; } int depthPos = depths[gridPos][segPos]; Vector3 pos = GetNewLinePos(depthPos, x, camPos, depthIncrement); int trys = 0; depths[gridPos].RemoveAt(segPos); lines.Add(pos); index++; GameObject q = Instantiate(Resources.Load("Quad")) as GameObject; q.transform.parent = dotHolder.transform; float lerpPer = (pos.z - front[0].z) / (back[0].z - front[0].z); float lineHeight = Mathf.Lerp(frontHeight, backHeight, lerpPer); if (cfs.ceilingMounted) //if ceiling ceiling mounted { lineHeight = -lineHeight; //flip the lineHeight down } pos.y = Camera.main.transform.position.y + lineHeight / 2; // print("pos.y: " + pos.y); q.transform.localScale = new Vector3(yarnWidth, lineHeight, yarnWidth); q.transform.position = pos; lineObjects.Add(q); lineNum++; } // Debug.Log ("tolerance: " + tolerance); // Debug.Log ("Num Lines: " + index); // Debug.Log ("lineObjects[0]: " + lineObjects[0].transform.position); // Debug.Log ("lines[0]: " + lines[0]); }
// Use this for initialization void Start() { Cursor.visible = false; SetMaterial(); pool = new List <Vector3>(); for (int i = 0; i < 10000; i++) { pool.Add(new Vector3()); } result = new List <float>(); TextAsset asset = Resources.Load(jsonLineFile) as TextAsset; JObject j1 = JObject.Parse(asset.text); JArray ja = j1["positions"] as JArray; for (int i = 0; i < ja.Count; i++) { Vector3 vec = UtilScript.JsonToVector3(ja[i]); posList.Add(vec); } pos = posList.ToArray(); Debug.Log("Num Lines: " + pos.Length); cfs = Camera.main.GetComponent <CameraFrustrumScript>(); // jObject["lumarcaSize"] = cfs.physicalWidth; // jObject["ProjPos"] = UtilScript.Vector3ToJson(cfs.transform.position); // jObject["ThrowRatio"] = cfs.throwRatio; // jObject["PhysicalWidth"] = cfs.physicalWidth; // jObject["CeilingMount"] = cfs.ceilingMounted; // JArray jPositions = new JArray(); // jObject["positions"] = jPositions; Vector3 projPos = new Vector3( (float)j1[LumarcaGenerator.PROP_PROJ_POS]["x"], (float)j1[LumarcaGenerator.PROP_PROJ_POS]["y"], (float)j1[LumarcaGenerator.PROP_PROJ_POS]["z"]); cfs.SetupCamera( (float)j1[LumarcaGenerator.PROP_PHYSICAL_WIDTH], projPos, (float)j1[LumarcaGenerator.PROP_THROW_RATIO], (bool)j1[LumarcaGenerator.PROP_CEILING_MOUNT]); front = cfs.GetFrontPlane(); back = new Vector3[4]; for (int i = 0; i < front.Length; i++) { back[i] = UtilScript.CloneVec3(front[i]); back[i].z = front[0].z + Camera.main.farClipPlane - Camera.main.nearClipPlane; } foreach (LumarcaAnimation la in lumarcaAnimations) { la.LoadFromJSON(); } GetComponent <LumarcaAnimation>(); if (recordName) { recordAnimation = gameObject.AddComponent <LumarcaAnimation>(); } }
void GenerateLines() { float depthIncrement = totalDepth / (numDepths - 1); dotHolder = new GameObject("LineHolder"); GameObject[] depthHolders = new GameObject[numDepths]; for (int i = 1; i <= numDepths; i++) { GameObject go = new GameObject("Depth " + i); go.transform.parent = dotHolder.transform; depthHolders[i - 1] = go; } bag = MakeBag(); lines = new List <Vector3>(); lineObjects = new List <GameObject>(); int index = 0; int maxAttempts = 10; // int temp = bag.Count - 1; // int[,] depths = new int[gridDivide, lineConfiguration/(gridDivide - 1)]; List <List <int> > depths = new List <List <int> >(); for (int gridPos = 0; gridPos < gridDivide; gridPos++) { depths.Add(new List <int>()); } for (int x = 0; x < lineConfiguration; x++) { // Debug.Log("x: " + x + " x%gridDivide: " + x%gridDivide + " x/gridDivide: " + x/gridDivide); depths[x / gridDivide].Add(x); } List <int> gridPickingOrder = new List <int>(); for (int i = 0; i < gridDivide; i += 2) { gridPickingOrder.Add(i); } for (int i = 1; i < gridDivide; i += 2) { gridPickingOrder.Add(i); } // string orderStr = ""; // for(int i = 0; i < gridDivide; i++){ // orderStr += gridPickingOrder[i] + " "; // } // // print("gridPickingOrder: " + orderStr); int lineSplit = (lineConfiguration / gridDivide); int interval = lineSplit / gridDivide; // Debug.Log("lineSplit: " + lineSplit); CameraFrustrumScript cfs = Camera.main.GetComponent <CameraFrustrumScript>(); float lineSpacing = cfs.physicalWidth / lineConfiguration; int lineNum = 0; for (float x = front[0].x + lineSpacing / 2; x < front[1].x; x += lineSpacing) { int attempts = 0; // int depthPos = (int)(Random.Range(0, bag.Count)); // int xPos = index/lineSplit; // if(xPos == depths.GetLength(0)){ // xPos = 0; // } // int yPos = (index - (xPos*lineSplit)); // Debug.Log("[" + xPos + ", " + yPos + "]"); // int start = index%gridDivide; // int end = start + 1; int gridIndex = lineNum % gridPickingOrder.Count; int gridPos = gridPickingOrder[gridIndex]; int segPos = (depths[gridPos].Count) / 2; if ((lineNum / gridDivide) % 2 != 0) { segPos = 0; } Debug.Log("depths: " + depths.Count); while (depths[gridPos].Count == 0) { Debug.Log("IN While2"); lineNum++; gridIndex = lineNum % gridPickingOrder.Count; gridPos = gridPickingOrder[gridIndex]; segPos = (depths[gridPos].Count - 1) / 2; } int depthPos = depths[gridPos][segPos]; Vector3 pos = GetNewLinePos(depthPos, x, camPos, depthIncrement); int trys = 0; depths[gridPos].RemoveAt(segPos); // bool badString = false; // // while(depthPos == -1000){ // badString = true; // Debug.Log("CHECK"); // depthPos = depths[gridPos, segPos]; // segPos++; // pos = GetNewLinePos(depthPos, x, camPos, depthIncrement); // } // // if(badString){ // maxAttempts--; // } // depths[xPos, selectPos] = -1000; // if(mod == 0){ // depthPos = index/3; // } else if (mod == 1){ // depthPos = index/3; // } else { // depthPos = index/3; // } // int depthPos = (int)(Random.Range(0, bag.Count)); // while(!ValidLine(pos) && attempts < maxAttempts){ // depthPos = (int)(Random.Range(0, bag.Count)); // pos = GetNewLinePos(depthPos, x, camPos, depthIncrement); // // attempts++; // } // // if(attempts == maxAttempts){ // tolerance -= 1; // // Application.LoadLevel(Application.loadedLevel); // } // // bag.RemoveAt(depthPos); // if(InsideCube(pos)){ lines.Add(pos); index++; GameObject q = Instantiate(Resources.Load("Quad")) as GameObject; // q.transform.parent = depthHolders[depthPos].transform; // q.transform.localScale = new Vector3(dotSize/2, totalHeight, dotSize/2); q.transform.localScale = new Vector3(yarnWidth, totalHeight, yarnWidth); q.transform.position = pos; lineObjects.Add(q); lineNum++; } // Debug.Log ("tolerance: " + tolerance); // Debug.Log ("Num Lines: " + index); // Debug.Log ("lineObjects[0]: " + lineObjects[0].transform.position); // Debug.Log ("lines[0]: " + lines[0]); }