Ejemplo n.º 1
0
		//returns the screen coordinates for the maximum of the graph
		public Vector2 render(Vector2 graphOrigin, float graphWidth, float graphHeight, float minValue, float maxValue)
		{
			//Render the floor display
		    lineMaterial.SetPass(0);
			GL.PushMatrix();
			GL.LoadOrtho();
			float graphXStep=0;
			float graphYStep=graphHeight;
			if (writeIdx>0)
				graphXStep=graphWidth/writeIdx;
			GraphUtils.drawArrow2d(graphOrigin,new Vector2(graphOrigin.x,graphOrigin.y+graphHeight),0.02f);
			GraphUtils.drawArrow2d(graphOrigin,new Vector2(graphOrigin.x+graphWidth,graphOrigin.y),0.02f);
		    GL.Begin(GL.LINES);
			Vector2 previous=new Vector2();
			Vector2 result=new Vector2(-float.MaxValue,-float.MaxValue);
			for (int i=0; i<writeIdx; i++)
			{
				float val=buffer[i];
				val=val-minValue;
				val=val/(maxValue-minValue);
				Vector2 current=new Vector2(graphOrigin.x+graphXStep*(float)i,graphOrigin.y+graphYStep*val);
				if (current.y > result.y)
					result=current;
				if (i!=0){
					GL.Vertex(previous);
					GL.Vertex(current);
				}
				previous=current;
			}
			GL.End();
			GL.PopMatrix();
			return result;
		}
Ejemplo n.º 2
0
		//call this from OnRenderObject of some other object
		public void renderRunning(Vector2 graphOrigin, float graphWidth, float graphHeight, float minValue, float maxValue)
		{
			//Render the floor display
		    lineMaterial.SetPass(0);
			GL.PushMatrix();
			GL.LoadOrtho();
			float graphXStep=0;
			float graphYStep=graphHeight;
			if (buffer.Capacity>0)
				graphXStep=graphWidth/buffer.Capacity;
			GraphUtils.drawArrow2d(graphOrigin,new Vector2(graphOrigin.x,graphOrigin.y+graphHeight),0.02f);
			GraphUtils.drawArrow2d(graphOrigin,new Vector2(graphOrigin.x+graphWidth,graphOrigin.y),0.02f);
		    GL.Begin(GL.LINES);
			Vector2 previous=new Vector2();
			for (int i=0; i<buffer.Capacity; i++)
			{
				int delay=buffer.Capacity-i;
				int idx=writeIdx-delay;
				if (idx<0)
					idx+=buffer.Capacity;
				float val=buffer[idx];
				val=val-minValue;
				val=val/(maxValue-minValue);
				Vector2 current=new Vector2(graphOrigin.x+graphXStep*(float)i,graphOrigin.y+graphYStep*val);
				if (i!=0){
					GL.Vertex(previous);
					GL.Vertex(current);
				}
				previous=current;
			}
			GL.End();
			GL.PopMatrix();
		}