public Vector3 GetOneScale() { // TODO: Clean up this function to work more nicely with other zoom functions float sizeRatio = GameMgr.CurrentSizeRatio(); float scaleX = maxScale; float scaleY = maxScale; if (sizeRatio >= 1f) { scaleY /= sizeRatio; } else { scaleX *= sizeRatio; } return(new Vector3(scaleX, scaleY, 1f)); // ok }
public void AssignImage() { if (GameMgr.Instance.CurrentLevel.Tool == ToolTypes.Segment) { Hide(); return; } transform.parent.localScale = GetOneScale(); // Scale parent instead to autoscale everything else Texture2D basePhoto = GameMgr.CurrentTex2D(); int cp = basePhoto.width * basePhoto.height; Color32[] cc = new Color32[cp]; for (int i = 0; i < cp; i++) { cc[i] = UIMgr.Instance.canvasClearColor; } if (GameMgr.Instance.CurrentLevel.Tool == ToolTypes.Paint) { Texture2D groundTruthPhoto = GameMgr.CurrentGroundTruthTex2D(); if (groundTruthPhoto == null) { Hide(); return; } if (GameMgr.Instance.CurrentLevel.TutorialMode == TutorialMode.Full) { Color[] pixels = groundTruthPhoto.GetPixels(); for (int i = 0; i < pixels.Length; i++) { if (pixels[i] != Color.black) { cc[i] = PaintHighlightColor; } } } else if (GameMgr.Instance.CurrentLevel.TutorialMode == TutorialMode.Simple) { PaintTool paintTool = ToolMgr.Instance.activeTool as PaintTool; // Check to make sure the ground truths have been assigned yet. if (paintTool == null || paintTool.groundTruthBlobs == null) { return; } foreach (var blob in paintTool.groundTruthBlobs) { int cx = (int)blob.Value.center.x; int cy = (int)blob.Value.center.y; //Debug.LogFormat("Checking blob at ({0}, {1}) with center at {2}", blob.Value.center.x, blob.Value.center.y, (cx + groundTruthPhoto.width * cy)); DrawCenter(cc, cx, cy, basePhoto.width, basePhoto.height, PaintRadius, PaintCenterColor); } } else { Hide(); return; } } else if (GameMgr.Instance.CurrentLevel.Tool == ToolTypes.Neuron) { NeuronTool neuronTool = ToolMgr.Instance.activeTool as NeuronTool; // Check to make sure the ground truths have been assigned yet. if (neuronTool == null || neuronTool.groundTruthGraph == null) { return; } if (GameMgr.Instance.CurrentLevel.TutorialMode == TutorialMode.Full) { foreach (Node n in neuronTool.groundTruthGraph.nodes) { //Debug.LogFormat("Checking node at ({0}, {1})", n.center.x, n.center.y); int nx = Mathf.RoundToInt(basePhoto.width * n.center.x); int ny = Mathf.RoundToInt(basePhoto.height * n.center.y); if (n.neighbors.Count >= MinNeigbors) { DrawCenter(cc, nx, ny, basePhoto.width, basePhoto.height, NeuronRadius, NeuronHighlightColor); } else { DrawCenter(cc, nx, ny, basePhoto.width, basePhoto.height, NeuronSecondaryRadius, NeuronSecondaryColor); } } } else if (GameMgr.Instance.CurrentLevel.TutorialMode == TutorialMode.Simple) { foreach (Node n in neuronTool.groundTruthGraph.nodes) { if (n.neighbors.Count < MinNeigbors) { continue; } //Debug.LogFormat("Checking node at ({0}, {1})", n.center.x, n.center.y); int nx = Mathf.RoundToInt(basePhoto.width * n.center.x); int ny = Mathf.RoundToInt(basePhoto.height * n.center.y); DrawCenter(cc, nx, ny, basePhoto.width, basePhoto.height, NeuronRadius, NeuronHighlightColor); } } else { Hide(); return; } } else { Hide(); return; } Texture2D tex = new Texture2D(basePhoto.width, basePhoto.height); tex.SetPixels32(0, 0, tex.width, tex.height, cc); tex.Apply(); MeshRenderer renderer = GetComponent <MeshRenderer>(); renderer.material = material; renderer.material.SetTexture("_MainTex", tex); _assigned = true; }
static public float CurrentSizeRatio() { return((float)(GameMgr.CurrentSize().x) / (float)(GameMgr.CurrentSize().y)); }
public void AssignImage() { transform.parent.localScale = GetOneScale(); // Scale parent instead to autoscale everything else // Set the image material here. MeshRenderer renderer = GetComponent <MeshRenderer>(); renderer.material = GameMgr.CurrentIsInverted() ? materialInverted : material; renderer.material.SetTexture("_MainTex", GameMgr.CurrentTex2D()); // Now we need to calculate the image and make a best fit to the current screen dimensions. float screenRatio = ((float)Screen.width) / ((float)Screen.height); float imageRatio = GameMgr.CurrentSizeRatio(); // Calculate zoom sizes here. Debug.LogFormat("Screen ratio versus image ratio {0} {1}", screenRatio, imageRatio); float actualScreenRatio = (ScreenArea.rect.width / ScreenArea.rect.height); Debug.LogFormat("Screen area {0} {1} {2}", ScreenArea.rect.width, ScreenArea.rect.height, actualScreenRatio); if (_zoomController == null) { _zoomController = Camera.main.GetComponent <ZoomController>(); } if (_zoomController != null) { // The max orthographic size to fill the Y-axis is 0.621f. // Currently assumes test image is 1:1 square. float defaultZoom = MAX_SCALE_Y; // If actual screen ratio is landscape, we need to fill in the // X-axis. if (actualScreenRatio > 1f) { defaultZoom = MAX_SCALE_Y / actualScreenRatio; } //float defaultZoom = actualScreenRatio * MAX_SCALE_Y; //if (defaultZoom > MAX_SCALE_Y) // defaultZoom = MAX_SCALE_Y; GameMgr.Instance.CurrentLevel.ZoomSizes = new Vector2(defaultZoom, defaultZoom * smallestZoomAmount); _zoomController.UpdateZoomSizes(); } if (_panController == null) { _panController = Camera.main.GetComponent <PanController>(); } if (_panController != null) { _panController.ResetSliders(); // Set to initial pan amounts. float defaultPanX = 0.1f; float defaultPanY = 0.1f; // If screen area is landscape, then there should be no horizontal // panning and only vertical panning. if (actualScreenRatio > 1f) { defaultPanX = 0.1f; defaultPanY = (actualScreenRatio - MAX_SCALE_Y) * 0.25f; } else { defaultPanX = (actualScreenRatio - MAX_SCALE_Y) * 0.5f; defaultPanY = 0.1f; } GameMgr.Instance.CurrentLevel.PanAmount = new Vector2(defaultPanX, defaultPanY); float zoomedPanX = 0.5f; float zoomedPanY = 0.5f; GameMgr.Instance.CurrentLevel.ZoomedInPanAmount = new Vector2(zoomedPanX, zoomedPanY); _panController.HorizontalPanRange = GameMgr.PanAmount().x; _panController.VerticalPanRange = GameMgr.PanAmount().y; //_panController.HideHorizontalSlider(); //_panController.HideVerticalSlider(); if (Mathf.Abs(defaultPanX) > 0.01f) { _panController.ShowHorizontalSlider(); } if (Mathf.Abs(defaultPanY) > 0.01f) { _panController.ShowVerticalSlider(); } // Force showing pan slider. if (GameMgr.CNV_TOOL) { _panController.ShowHorizontalSlider(); _panController.HideVerticalSlider(); } } _assigned = true; }