Example #1
0
    public void RenderGridRect(Vector3 from, Vector3 to, GFColorVector3 colors, int width = 0, Camera cam = null, Transform camTransform = null)
    {
        if (!renderGrid)
        {
            return;
        }

        if (!renderMaterial)
        {
            renderMaterial = defaultRenderMaterial;
        }

        CalculateDrawPointsRect(from, to, gridStyle == HexGridShape.CompactRectangle);

        RenderGridLines(colors, width, cam, camTransform);
    }
Example #2
0
File: GFGrid.cs Project: LynnPi/OF
    /// <summary>Renders the grid at runtime</summary>
    /// <param name="from">Lower limit</param>
    /// <param name="to">Upper limit</param>
    /// <param name="colors">Colors for rendering</param>
    /// <param name="width">Width of the line</param>
    /// <param name="cam">Camera for rendering</param>
    /// <param name="camTransform">Transform of the camera</param>
    public virtual void RenderGrid(Vector3 from, Vector3 to, GFColorVector3 colors, int width = 0, Camera cam = null, Transform camTransform = null)
    {
        if (!renderGrid)
        {
            return;
        }

        if (!renderMaterial)
        {
            renderMaterial = defaultRenderMaterial;
        }

        CalculateDrawPoints(from, to);

        RenderGridLines(colors, width, cam, camTransform);
    }
Example #3
0
 public override void RenderGrid(Vector3 from, Vector3 to, GFColorVector3 colors, int width = 0, Camera cam = null, Transform camTransform = null)
 {
     RenderGridRect(from, to, useSeparateRenderColor ? renderAxisColors : axisColors, width, cam, camTransform);
 }
Example #4
0
    public void RenderGridRect(Vector3 from, Vector3 to, GFColorVector3 colors, int width = 0, Camera cam = null, Transform camTransform = null)
    {
        if (!renderGrid)
        {
            return;
        }

        if (!renderMaterial)
        {
            renderMaterial = defaultRenderMaterial;
        }

        Vector3[][][] lines = CalculateDrawPointsRect(from, to, gridStyle == HexGridShape.CompactRectangle);

        renderMaterial.SetPass(0);

        if (width <= 1 || !cam || !camTransform)        // use simple lines for width 1 or if no camera was passed
        {
            GL.Begin(GL.LINES);
            for (int i = 0; i < 3; i++)
            {
                if (hideAxis[i])
                {
                    continue;
                }
                GL.Color(colors[i]);
                foreach (Vector3[] line in lines[i])
                {
                    if (line == null)
                    {
                        continue;
                    }
                    GL.Vertex(line[0]); GL.Vertex(line[1]);
                }
            }
            GL.End();
        }
        else                                         // quads for "lines" with width
        {
            GL.Begin(GL.QUADS);                      // we will be working in Screen Space here
            float mult = Mathf.Max(0, 0.5f * width); //the multiplier, half the desired width

            for (int i = 0; i < 3; i++)
            {
                GL.Color(colors[i]);
                if (hideAxis[i] || lines[i][0] == null)
                {
                    continue;
                }

                //sample a direction vector, one per direction is enough (using the first line of each line set
                Vector3 dir = Vector3.Cross(lines[i][0][0] - lines[i][0][1], camTransform.forward).normalized;
                //multiply dir with the world length of one pixel in distance
                if (cam.orthographic)
                {
                    dir *= (cam.orthographicSize * 2) / cam.pixelHeight;
                }
                else                   // (the 20 below is just there to smooth out rounding errors)
                {
                    dir *= (cam.ScreenToWorldPoint(20 * new Vector3(0, 0, 1)) - cam.ScreenToWorldPoint(20 * new Vector3(1, 0, 1))).magnitude / 20;
                }

                foreach (Vector3[] line in lines[i])
                {
                    if (line == null)
                    {
                        continue;
                    }

                    Vector3 vec1 = line[0];
                    Vector3 vec2 = line[1];
                    GL.Vertex(vec1 - mult * dir); GL.Vertex(vec1 + mult * dir); GL.Vertex(vec2 + mult * dir); GL.Vertex(vec2 - mult * dir);
                }
            }
            GL.End();
        }
    }
Example #5
0
	protected void RenderGridRect(Vector3 from, Vector3 to, GFColorVector3 colors, int width = 0, Camera cam = null, Transform camTransform = null){
		if(!renderGrid)
			return;
		
		if(!renderMaterial)
			renderMaterial = defaultRenderMaterial;
		
		CalculateDrawPointsRect(from, to, gridStyle == HexGridShape.CompactRectangle);
		
		RenderGridLines(colors, width, cam, camTransform);
	}
Example #6
0
	public override void RenderGrid(Vector3 from, Vector3 to, GFColorVector3 colors, int width = 0, Camera cam = null, Transform camTransform = null){
		RenderGridRect(from, to, useSeparateRenderColor ? renderAxisColors : axisColors, width, cam, camTransform);
	}
Example #7
0
	// we need this because we can't pass the indexer or getter/setter as ref
	private void ColourSwap (ref GFColorVector3 col, int i, int j, bool condition = true) {
		if (!condition)
			return;
		Color temp = col[i];
		col [i] = col [j];
		col [j] = temp;
	}
Example #8
0
 public abstract void RenderGrid(Vector3 from, Vector3 to, GFColorVector3 colors, int width = 0, Camera cam = null, Transform camTransform = null);
Example #9
0
//_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-_-

    #region Render Methods

    public override void RenderGrid(Vector3 from, Vector3 to, GFColorVector3 colors, int width = 0, Camera cam = null, Transform camTransform = null)
    {
        if (!renderGrid)
        {
            return;
        }

        if (!renderMaterial)
        {
            renderMaterial = defaultRenderMaterial;
        }

        CalculateDrawPoints(from, to);

        renderMaterial.SetPass(0);

        if (width <= 1 || !cam || !camTransform)        // use simple lines for width 1 or if no camera was passed
        {
            GL.Begin(GL.LINES);
            for (int i = 0; i < 3; i++)
            {
                if (hideAxis[i])
                {
                    continue;
                }
                GL.Color(colors[i]);
                //foreach(Vector3[] line in _drawPoints[i]){
                for (int j = 0; j < _drawPoints[i].Length; j++)
                {
                    //GL.Vertex(line[0]); GL.Vertex(line[1]);
                    GL.Vertex(_drawPoints[i][j][0]); GL.Vertex(_drawPoints[i][j][1]);
                }
            }
            GL.End();
        }
        else           // quads for "lines" with width
        {
            GL.Begin(GL.QUADS);
            float mult = Mathf.Max(0, 0.5f * width);             //the multiplier, half the desired width

            for (int i = 0; i < 3; i++)
            {
                GL.Color(colors[i]);
                if (hideAxis[i])
                {
                    continue;
                }

                //sample a direction vector, one per direction is enough (using the first line of each line set
                Vector3 dir = new Vector3();
                if (_drawPoints[i].Length > 0)                //can't get a line if the set is empty
                {
                    dir = Vector3.Cross(_drawPoints[i][0][0] - _drawPoints[i][0][1], camTransform.forward).normalized;
                }
                //multiply dir with the world length of one pixel in distance
                if (cam.orthographic)
                {
                    dir *= (cam.orthographicSize * 2) / cam.pixelHeight;
                }
                else                   // (the 50 below is just there to smooth things out)
                {
                    dir *= (cam.ScreenToWorldPoint(new Vector3(0, 0, 50)) - cam.ScreenToWorldPoint(new Vector3(20, 0, 50))).magnitude / 20;
                }

                //foreach(Vector3[] line in _drawPoints[i]){
                for (int j = 0; j < _drawPoints[i].Length; j++)
                {
                    //if(line == null) continue;
                    if (_drawPoints[i][j] == null)
                    {
                        continue;
                    }

                    //Vector3 vec1 = line[0];
                    //Vector3 vec2 = line[1];
                    //GL.Vertex(vec1-mult*dir); GL.Vertex(vec1+mult*dir); GL.Vertex(vec2+mult*dir); GL.Vertex(vec2-mult*dir);
                    GL.Vertex(_drawPoints[i][j][0] - mult * dir); GL.Vertex(_drawPoints[i][j][0] + mult * dir); GL.Vertex(_drawPoints[i][j][1] + mult * dir); GL.Vertex(_drawPoints[i][j][1] - mult * dir);
                }
            }
            GL.End();
        }
    }
Example #10
0
    public override void RenderGrid(Vector3 from, Vector3 to, GFColorVector3 colors, int width = 0, Camera cam = null, Transform camTransform = null)
    {
        if(!renderGrid)
            return;

        if(!renderMaterial)
            renderMaterial = defaultRenderMaterial;

        CalculateDrawPoints(from, to);

        renderMaterial.SetPass(0);

        if(width <= 1 || !cam || !camTransform){// use simple lines for width 1 or if no camera was passed
            GL.Begin(GL.LINES);
            for(int i = 0; i < 3; i++){
                if(hideAxis[i])
                    continue;
                GL.Color(colors[i]);
                //foreach(Vector3[] line in _drawPoints[i]){
                for(int j = 0; j < _drawPoints[i].Length; j++){
                    //GL.Vertex(line[0]); GL.Vertex(line[1]);
                    GL.Vertex(_drawPoints[i][j][0]); GL.Vertex(_drawPoints[i][j][1]);
                }
            }
            GL.End();
        } else{// quads for "lines" with width
            GL.Begin(GL.QUADS);
            float mult = Mathf.Max(0, 0.5f * width); //the multiplier, half the desired width

            for(int i = 0; i < 3; i++){
                GL.Color(colors[i]);
                if(hideAxis[i])
                    continue;

                //sample a direction vector, one per direction is enough (using the first line of each line set
                Vector3 dir = new Vector3();
                if(_drawPoints[i].Length > 0) //can't get a line if the set is empty
                    dir = Vector3.Cross(_drawPoints[i][0][0] - _drawPoints[i][0][1], camTransform.forward).normalized;
                //multiply dir with the world length of one pixel in distance
                if(cam.orthographic){
                    dir *= (cam.orthographicSize * 2) / cam.pixelHeight;
                } else{// (the 50 below is just there to smooth things out)
                    dir *= (cam.ScreenToWorldPoint(new Vector3(0, 0, 50)) - cam.ScreenToWorldPoint(new Vector3(20, 0, 50))).magnitude/20;
                }

                //foreach(Vector3[] line in _drawPoints[i]){
                for(int j = 0; j < _drawPoints[i].Length; j++){
                    //if(line == null) continue;
                    if(_drawPoints[i][j] == null) continue;

                    //Vector3 vec1 = line[0];
                    //Vector3 vec2 = line[1];
                    //GL.Vertex(vec1-mult*dir); GL.Vertex(vec1+mult*dir); GL.Vertex(vec2+mult*dir); GL.Vertex(vec2-mult*dir);
                    GL.Vertex(_drawPoints[i][j][0]-mult*dir); GL.Vertex(_drawPoints[i][j][0]+mult*dir); GL.Vertex(_drawPoints[i][j][1]+mult*dir); GL.Vertex(_drawPoints[i][j][1]-mult*dir);

                }
            }
            GL.End();
        }
    }
Example #11
0
	protected void RenderGridRect(Vector3 from, Vector3 to, GFColorVector3 colors, int width = 0, Camera cam = null, Transform camTransform = null) {
		if (!renderGrid) {
			return;
		}
		
		if (!renderMaterial) {
			renderMaterial = defaultRenderMaterial;
		}
		
		RenderGridLines(colors, width, cam, camTransform);
	}
Example #12
0
File: GFGrid.cs Project: LynnPi/OF
    protected void RenderGridLines(GFColorVector3 colors, int width = 0, Camera cam = null, Transform camTransform = null)
    {
        renderMaterial.SetPass(0);

        if (width <= 1 || !cam || !camTransform)        // use simple lines for width 1 or if no camera was passed
        {
            GL.Begin(GL.LINES);
            for (int i = 0; i < 3; i++)
            {
                if (hideAxis[i])
                {
                    continue;
                }
                GL.Color(colors[i]);
                foreach (Vector3[] line in _drawPoints[i])
                {
                    if (line == null)
                    {
                        continue;
                    }
                    GL.Vertex(line[0]); GL.Vertex(line[1]);
                }
            }
            GL.End();
        }
        else           // quads for "lines" with width
        {
            GL.Begin(GL.QUADS);
            float mult = Mathf.Max(0, 0.5f * width);             //the multiplier, half the desired width

            for (int i = 0; i < 3; i++)
            {
                GL.Color(colors[i]);
                if (hideAxis[i])
                {
                    continue;
                }

                //sample a direction vector, one per direction is enough (using the first line of each line set (<- !!! ONLY TRUE FOR RECT GRIDS !!!)
                Vector3 dir = new Vector3();
                if (_drawPoints[i].Length > 0)                //can't get a line if the set is empty
                {
                    dir = Vector3.Cross(_drawPoints[i][0][0] - _drawPoints[i][0][1], camTransform.forward).normalized;
                }
                //multiply dir with the world length of one pixel in distance
                if (cam.orthographic)
                {
                    dir *= (cam.orthographicSize * 2) / cam.pixelHeight;
                }
                else                   // (the 50 below is just there to smooth things out)
                {
                    dir *= (cam.ScreenToWorldPoint(new Vector3(0, 0, 50)) - cam.ScreenToWorldPoint(new Vector3(20, 0, 50))).magnitude / 20;
                }

                foreach (Vector3[] line in _drawPoints[i])
                {
                    if (line == null)
                    {
                        continue;
                    }
                    // if the grid is not rectangular we need to change dir every time
                    if (this.GetType() != typeof(GFRectGrid))
                    {
                        dir = Vector3.Cross(line[0] - line[1], camTransform.forward).normalized;
                        if (cam.orthographic)
                        {
                            dir *= (cam.orthographicSize * 2) / cam.pixelHeight;
                        }
                        else                           // (the 50 below is just there to smooth things out)
                        {
                            dir *= (cam.ScreenToWorldPoint(new Vector3(0, 0, 50)) - cam.ScreenToWorldPoint(new Vector3(20, 0, 50))).magnitude / 20;
                        }
                    }
                    GL.Vertex(line[0] - mult * dir); GL.Vertex(line[0] + mult * dir); GL.Vertex(line[1] + mult * dir); GL.Vertex(line[1] - mult * dir);
                }
            }
            GL.End();
        }
    }