Axe Cross Annotation

This commit is contained in:
Martin Pernollet 2014-12-21 15:17:54 +01:00
parent b12a603e06
commit 0af957b7ae
4 changed files with 174 additions and 47 deletions

View File

@ -0,0 +1,31 @@
package org.jzy3d.plot3d.primitives.axes;
import javax.media.opengl.GL;
import org.jzy3d.maths.Coord2d;
import org.jzy3d.maths.Range;
public class AxeCrossAnnotation extends AxeLineAnnotation implements AxeAnnotation {
protected Coord2d value;
@Override
public void draw(GL gl, AxeBox axe) {
Range xrange = axe.getBoxBounds().getXRange();
Range yrange = axe.getBoxBounds().getYRange();
if (gl.isGL2()) {
drawHorizontalLineGL2(gl, xrange, value.y);
drawVerticalLineGL2(gl, yrange, value.x);
} else {
drawHorizontalLineGLES2(xrange, value.y);
drawVerticalLineGLES2(yrange, value.x);
}
}
public synchronized Coord2d getValue() {
return value;
}
public synchronized void setValue(Coord2d value) {
this.value = value;
}
}

View File

@ -0,0 +1,68 @@
package org.jzy3d.plot3d.primitives.axes;
import javax.media.opengl.GL;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Range;
import org.jzy3d.plot3d.rendering.compat.GLES2CompatUtils;
public class AxeLineAnnotation {
protected Color color = Color.RED;
protected float width = 3;
public AxeLineAnnotation() {
super();
}
public void drawVerticalLineGLES2(Range yrange, float value) {
GLES2CompatUtils.glBegin(GL.GL_LINE_STRIP);
GLES2CompatUtils.glLineWidth(width);
GLES2CompatUtils.glColor4f(color.r, color.g, color.b, color.a);
GLES2CompatUtils.glVertex3f(value, yrange.getMin(), 0);
GLES2CompatUtils.glVertex3f(value, yrange.getMax(), 0);
GLES2CompatUtils.glEnd();
}
public synchronized void drawVerticalLineGL2(GL gl, Range yrange, float value) {
gl.getGL2().glLineWidth(width);
gl.getGL2().glBegin(GL.GL_LINE_STRIP);
gl.getGL2().glColor4f(color.r, color.g, color.b, color.a);
gl.getGL2().glVertex3f(value, yrange.getMin()-yrange.getRange()/30, 0);
gl.getGL2().glVertex3f(value, yrange.getMax()+yrange.getRange()/30, 0);
gl.getGL2().glEnd();
}
public void drawHorizontalLineGLES2(Range xrange, float value) {
GLES2CompatUtils.glBegin(GL.GL_LINE_STRIP);
GLES2CompatUtils.glLineWidth(width);
GLES2CompatUtils.glColor4f(color.r, color.g, color.b, color.a);
GLES2CompatUtils.glVertex3f(xrange.getMin(), value, 0);
GLES2CompatUtils.glVertex3f(xrange.getMax(), value, 0);
GLES2CompatUtils.glEnd();
}
public synchronized void drawHorizontalLineGL2(GL gl, Range xrange, float value) {
gl.getGL2().glLineWidth(width);
gl.getGL2().glBegin(GL.GL_LINE_STRIP);
gl.getGL2().glColor4f(color.r, color.g, color.b, color.a);
gl.getGL2().glVertex3f(xrange.getMin()-xrange.getRange()/30, value, 0);
gl.getGL2().glVertex3f(xrange.getMax()+xrange.getRange()/30, value, 0);
gl.getGL2().glEnd();
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public float getWidth() {
return width;
}
public void setWidth(float width) {
this.width = width;
}
}

View File

@ -2,46 +2,20 @@ package org.jzy3d.plot3d.primitives.axes;
import javax.media.opengl.GL;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Range;
import org.jzy3d.plot3d.rendering.compat.GLES2CompatUtils;
public class AxeXLineAnnotation implements AxeAnnotation {
public class AxeXLineAnnotation extends AxeLineAnnotation implements AxeAnnotation {
protected float value;
protected Color color = Color.RED;
protected float width = 3;
@Override
public void draw(GL gl, AxeBox axe) {
Range yrange = axe.getBoxBounds().getYRange();
Range zrange = axe.getBoxBounds().getYRange();
if (gl.isGL2()) {
drawLineGL2(gl, yrange, zrange);
drawVerticalLineGL2(gl, yrange, value);
} else {
drawLineGLES2(yrange, zrange);
drawVerticalLineGLES2(yrange, value);
}
}
public void drawLineGLES2(Range yrange, Range zrange) {
GLES2CompatUtils.glBegin(GL.GL_LINE_STRIP);
GLES2CompatUtils.glLineWidth(width);
GLES2CompatUtils.glColor4f(color.r, color.g, color.b, color.a);
GLES2CompatUtils.glVertex3f(value, yrange.getMin(), 0);
GLES2CompatUtils.glVertex3f(value, yrange.getMax(), 0);
GLES2CompatUtils.glEnd();
}
public synchronized void drawLineGL2(GL gl, Range yrange, Range zrange) {
gl.getGL2().glLineWidth(width);
gl.getGL2().glBegin(GL.GL_LINE_STRIP);
gl.getGL2().glColor4f(color.r, color.g, color.b, color.a);
gl.getGL2().glVertex3f(value, yrange.getMin()-yrange.getRange()/30, zrange.getMin()-2);
gl.getGL2().glVertex3f(value, yrange.getMax()+yrange.getRange()/30, zrange.getMin()-2);
//System.out.println("x=" + value + " y:" + yrange);
gl.getGL2().glEnd();
}
public synchronized float getValue() {
@ -51,21 +25,4 @@ public class AxeXLineAnnotation implements AxeAnnotation {
public synchronized void setValue(float value) {
this.value = value;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public float getWidth() {
return width;
}
public void setWidth(float width) {
this.width = width;
}
}

View File

@ -0,0 +1,71 @@
package org.jzy3d.plot3d.primitives.axes;
import javax.media.opengl.GL;
import org.jzy3d.colors.Color;
import org.jzy3d.maths.Range;
import org.jzy3d.plot3d.rendering.compat.GLES2CompatUtils;
public class AxeYLineAnnotation implements AxeAnnotation {
protected float value;
protected Color color = Color.RED;
protected float width = 3;
@Override
public void draw(GL gl, AxeBox axe) {
Range xrange = axe.getBoxBounds().getXRange();
Range zrange = axe.getBoxBounds().getYRange();
if (gl.isGL2()) {
drawLineGL2(gl, xrange, zrange);
} else {
drawLineGLES2(xrange, zrange);
}
}
public void drawLineGLES2(Range yrange, Range zrange) {
GLES2CompatUtils.glBegin(GL.GL_LINE_STRIP);
GLES2CompatUtils.glLineWidth(width);
GLES2CompatUtils.glColor4f(color.r, color.g, color.b, color.a);
GLES2CompatUtils.glVertex3f(value, yrange.getMin(), 0);
GLES2CompatUtils.glVertex3f(value, yrange.getMax(), 0);
GLES2CompatUtils.glEnd();
}
public synchronized void drawLineGL2(GL gl, Range yrange, Range zrange) {
gl.getGL2().glLineWidth(width);
gl.getGL2().glBegin(GL.GL_LINE_STRIP);
gl.getGL2().glColor4f(color.r, color.g, color.b, color.a);
gl.getGL2().glVertex3f(value, yrange.getMin()-yrange.getRange()/30, zrange.getMin()-2);
gl.getGL2().glVertex3f(value, yrange.getMax()+yrange.getRange()/30, zrange.getMin()-2);
//System.out.println("x=" + value + " y:" + yrange);
gl.getGL2().glEnd();
}
public synchronized float getValue() {
return value;
}
public synchronized void setValue(float value) {
this.value = value;
}
public Color getColor() {
return color;
}
public void setColor(Color color) {
this.color = color;
}
public float getWidth() {
return width;
}
public void setWidth(float width) {
this.width = width;
}
}