package utils;
import java.awt.Graphics2D;
import java.awt.Image;
import javax.media.opengl.GL2;
import com.jogamp.opengl.util.texture.Texture;
import factories.Angles;
import graphics.common.Angle;
import graphics.common.Point;
public class Utils {
public Angle twoPointsAngle2D( Point p1, Point p2 ) {
double theta = Math.atan2(p2.getRealY() - p1.getRealY(),
p2.getRealX() - p1.getRealX() );
Angle ret = Angles.get( theta, 0.0, 0.0 );
return ret;
}
public Angle twoPointsAngle3D( Point p1, Point p2 ) {
return null;
}
/**
* Draws an Image to the screen. Assumes all values are non-null, and WILL
* throw a NullPointerException if null values are passed.<br/>
* Only call this method if you are currently using the GL_MODELVIEW matrix.
*
* @param g The Graphics2D object that will be drawn to.
* @param i The Image object that will be drawn into the Graphics2D object.
* @param x The x location that the Image will be drawn to.
* @param y The y location that the Image will be drawn to.
*/
public void drawFullImage(Graphics2D g, Image i, int x, int y) {
g.drawImage(i, x, y, null);
}
/**
* **UNTESTED** - DO TESTING ON THIS SOON<br/>
* Draws a textured quad, assuming that glBegin( GL_QUADS ) has been called.
* <br/>
* Keeps the previous state of the matrix by pushing the matrix, resetting
* it, and then restores it. All translations/scales/etc. are done inside
* of this method.
*
* @param gl
* @param t
* @param x
* @param y
* @param z
*/
public void drawTextureQuadNoBeginEnd(GL2 gl, Texture t, float x, float y, float z) {
gl.glPushMatrix();
gl.glLoadIdentity();
// from what I understand, this will scale then translate
// this order might not work, swap if graphical output is strange
gl.glTranslatef(x, y, z);
gl.glScalef(t.getWidth(), t.getHeight(), 1.0f);
gl.glTexCoord2d(1.0f, 1.0f);
gl.glVertex2f(1.0f, 0.0f);
gl.glTexCoord2d(0.0f, 1.0f);
gl.glVertex2f(0.0f, 0.0f);
gl.glTexCoord2d(0.0f, 0.0f);
gl.glVertex2f(0.0f, 1.0f);
gl.glTexCoord2d(1.0f, 0.0);
gl.glVertex2f(1.0f, 1.0f);
gl.glPopMatrix();
}
public void drawTextureTriNoBeginEnd(GL2 gl, Texture t, float x, float y, float z) {
}
}