Exemplo n.º 1
0
    public void OnRenderObject()
    {
        if (c.start == true && toggleCfd.HasSelection == true)
        {
            //CheckData();
            // c.waiting.enabled = false;

            CFD = (c.toggleSection.HasSelection == true) ? c.Section() : c.cfd;

            CreateLineMaterial();
            lineMaterial.SetPass(0);

            GL.PushMatrix();
            GL.MultMatrix(transform.localToWorldMatrix);
            GL.Begin(GL.LINES);

            // Cycle time: the interval is equal to the remainder of the time in seconds divided by 1.
            float frac = (Time.time) % 1.0f;

            foreach (p0 p in CFD)
            {
                float a      = CFD_JSON.remap((float)Math.Pow(p.vmeg, .5), (float)Math.Pow(c.vMin, .5), (float)Math.Pow(c.vMax, .5), 0, 1);
                Color vcolor = new Color(a, 1 - a, 0, 0.5f);
                GL.Color(vcolor);

                // Create the start and end positions of the vector
                Vector3 start = new Vector3(p.x, p.z, p.y);
                Vector3 v     = new Vector3(p.vx, p.vz, p.vy);

                // We adjust the length of the vector by a factor R
                Vector3 end = start + r * v;

                // Interpolate the animation
                Vector3 start2 = Vector3.Lerp(start, end, frac);
                Vector3 end2   = start2 + v.normalized * 0.15f;
                GL.Vertex3(start2.x, start2.y, start2.z);
                GL.Vertex3(end2.x, end2.y, end2.z);
            }

            GL.End();
            GL.PopMatrix();
        }

        /*
         * else
         * {
         *  c.waiting.text = "waiting to download data";
         *  c.waiting.enabled = true;
         *  //Debug.Log("waiting for connection");
         * }
         */
    }
Exemplo n.º 2
0
    /*
     * public ColorGradient(float width, float height, float radius)
     * {
     *  width = w;
     *  height = h;
     *  radius = (float)r;
     *  samples = new float[(int) (w*h)];
     *  CreateCircleMap();
     * }
     *
     * void CreateCircleMap()
     * {
     *  circle = new float[(r * r * 4)];
     *  for(int x=-r; x<r; x++)
     *  {
     *      for (int y =-r; y<r; y++)
     *      {
     *          float l = (x * x * +y * y) / (float)(r * r);
     *          float v = 0;
     *          if (l < 1)
     *          {
     *              v = 1 - l;
     *              circle[x + r + r * x * y] = v;
     *          }
     *      }
     *  }
     * }
     *
     * public void AddPoint(Vector2 pos)
     * {
     *  int px = Mathf.RoundToInt(pos.x);
     *  int py = Mathf.RoundToInt(pos.y);
     *  for (int x = -r; x<r; x++)
     *  {
     *      for(int y=-r;y<r; y++)
     *      {
     *          int ix = px + x;
     *          int iy = py + y;
     *          if (ix < 0 || iy < 0 || ix >= w || iy >= h) continue;
     *          samples[ix + iy * (int)w] += circle[x + r + r * 2 * y];
     *      }
     *  }
     * }
     *
     * public Texture2D GetHeatMap(Gradient g)
     * {
     *  Texture2D tex = new Texture2D((int)w, (int)h, TextureFormat.ARGB32, false);
     *  float scale = 1 / c.vMax;
     *  Color[] col = new Color[samples.Length];
     *
     *  for (int i = 0; i < col.Length; i++) col[i] = g.Evaluate(samples[i] * scale);
     *  tex.SetPixels(col);
     *  tex.Apply();
     *  return tex;
     * }
     *
     * public void OnHeatMap()
     * {
     *
     *
     * }
     */

    public void OnRenderObject()
    {
        if (c.start == true && toggleCfd.HasSelection == true)
        {
            // c.waiting.enabled = false;
            CFD = (c.toggleSection.HasSelection == true) ? c.Section() : c.cfd;

            CreateQuadMaterial();
            QuadMaterial.SetPass(0);

            GL.PushMatrix();
            GL.MultMatrix(transform.localToWorldMatrix);
            GL.Begin(GL.QUADS);

            foreach (p0 p in CFD)
            {
                float a      = CFD_JSON.remap(p.vmeg, c.vMin, c.vMax, 0, 1);
                Color vcolor = new Color(a, 1 - a, 1 - a, 0.5f);
                GL.Color(vcolor);

                Vector3 start = new Vector3(p.x, p.z, p.y);

                GL.Vertex3(start.x - s, start.y - s, start.z);
                GL.Vertex3(start.x + s, start.y - s, start.z);
                GL.Vertex3(start.x + s, start.y + s, start.z);
                GL.Vertex3(start.x - s, start.y + s, start.z);
            }

            GL.End();
            GL.PopMatrix();

            /*
             * float st = t * (float)(col.Count - 1);
             * Color prevC = col[(int)st];
             * Color nextC = col[(int)st];
             * float newt =  st - (float)((int)st);
             *
             * if (t != 1)
             * {
             *  quadRender.material.color = Color.Lerp(prevC, nextC, newt);
             * }
             * else
             * {
             *  quadRender.material.color = col[col.Count-1];
             * }
             */
        }
    }
Exemplo n.º 3
0
    public void OnRenderObject()
    {
        if (c.start == true && toggleCfd.HasSelection == true)
        {
            //CheckData();
            // c.waiting.enabled = false;
            CFD = (c.toggleSection.HasSelection == true) ? c.Section() : c.cfd;

            CreateLineMaterial();
            lineMaterial.SetPass(0);

            GL.PushMatrix();
            GL.MultMatrix(transform.localToWorldMatrix);
            GL.Begin(GL.LINES);

            foreach (p0 p in CFD)
            {
                float a      = CFD_JSON.remap((float)Math.Pow(p.vmeg, .5), (float)Math.Pow(c.vMin, .5), (float)Math.Pow(c.vMax, .5), 0, 1);
                Color vcolor = new Color(a, 1 - a, 0, 0.5f);
                GL.Color(vcolor);

                Vector3 start = new Vector3(p.x, p.z, p.y);
                Vector3 move  = new Vector3(p.vx, p.vz, p.vy);
                Vector3 end   = start + move.normalized * len;

                Vector3 proj = Vector3.ProjectOnPlane(end, Vector3.Cross(start, end));
                //Vector3 projN = len*Vector3.Normalize(proj);

                GL.Vertex3(start.x, start.y, start.z);
                GL.Vertex3(proj.x, proj.y, proj.z);
            }

            GL.End();
            GL.PopMatrix();
        }

        /*
         * else
         * {
         *  c.waiting.text = "waiting to download data";
         *  c.waiting.enabled = true;
         *  //Debug.Log("waiting for connection");
         * }
         */
    }
Exemplo n.º 4
0
    void Start()
    {
        c         = GetComponent <CFD_JSON>();
        toggleCfd = GameObject.Find("ToggleColorGradient").GetComponent <InteractiveToggle>();
        //s = 0.1f;

        /*
         * quad = GameObject.Find("Quad");
         * quadRender = quad.GetComponent<Renderer>();
         * w = quadRender.bounds.size.x;
         * h = quadRender.bounds.size.y;
         */
        //quadShader = Shader.Find("ColorMap");

        if (c.start == true && toggleCfd.HasSelection == true && c.toggleSection.HasSelection == true)
        {
            //c.waiting.enabled = false;
            CFD = (c.toggleSection.HasSelection == true) ? c.Section() : c.cfd;
        }
    }