本文整理匯總了Java中javax.media.opengl.GL2.glTranslatef方法的典型用法代碼示例。如果您正苦於以下問題:Java GL2.glTranslatef方法的具體用法?Java GL2.glTranslatef怎麽用?Java GL2.glTranslatef使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類javax.media.opengl.GL2
的用法示例。
在下文中一共展示了GL2.glTranslatef方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: drawVertex
import javax.media.opengl.GL2; //導入方法依賴的package包/類
private Vector3f drawVertex(Vector3f vert, double size, float[] color, GL2 gl, GLUT glut) {
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, color, 0);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, color, 0);
gl.glMaterialf(GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 10);
gl.glPushAttrib(GL2.GL_LIGHTING_BIT);
gl.glDisable(GL2.GL_TEXTURE_2D);
gl.glEnable(GL2.GL_LIGHTING);
gl.glPushMatrix();
gl.glTranslatef(vert.getX(), vert.getY(), vert.getZ());
glut.glutSolidSphere(size, 20, 20);
gl.glPopMatrix();
gl.glEnable(GL2.GL_TEXTURE_2D);
gl.glDisable(GL2.GL_LIGHTING);
gl.glPopAttrib();
return vert;
}
示例2: drawCylinder
import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawCylinder(Vector3f from, Vector3f to, GL2 gl, GLUT glut) {
Vector3f zAxis = new Vector3f(0, 0, 1);
Vector3f vector = new Vector3f(to.x - from.x, to.y - from.y, to.z - from.z);
float length = vector.length();
vector.normalize();
float angle = zAxis.angle(vector);
Vector3f axis = new Vector3f();
axis.cross(zAxis, vector);
float convert = (float) (180f / Math.PI);
gl.glPushMatrix();
gl.glTranslatef(from.x, from.y, from.z);
gl.glRotatef(angle * convert, axis.x, axis.y, axis.z);
glut.glutSolidCylinder(info.getPointSize() / 4.5, length - info.getPointSize(), 20, 20);
gl.glPopMatrix();
}
示例3: drawCylinder
import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawCylinder(GLUT glut, GL2 gl, Vector3f from, Vector3f to) {
Vector3f zAxis = new Vector3f(0, 0, 1);
Vector3f vector1 = new Vector3f(to.x - from.x, to.y - from.y, to.z - from.z);
float length = vector1.length();
vector1.normalize();
float angle = zAxis.angle(vector1);
Vector3f axis = new Vector3f();
axis.cross(zAxis, vector1);
float convert = (float) (180f / Math.PI);
gl.glPushMatrix();
gl.glTranslatef(from.x, from.y, from.z);
gl.glRotatef(angle * convert, axis.x, axis.y, axis.z);
glut.glutSolidCylinder(0.5f, length - 0.5f, 20, 5);
//glut.glutSolidCylinder(0.5f, 10, 20, 5);
gl.glPopMatrix();
}
示例4: transformViewport
import javax.media.opengl.GL2; //導入方法依賴的package包/類
public void transformViewport(GL2 gl, Vec2 center) {
Vec2 e = viewportTransform.getExtents();
Vec2 vc = viewportTransform.getCenter();
Mat22 vt = viewportTransform.getMat22Representation();
int f = viewportTransform.isYFlip() ? -1 : 1;
mat[0] = vt.ex.x;
mat[4] = vt.ey.x;
// mat[8] = 0;
mat[12] = e.x;
mat[1] = f * vt.ex.y;
mat[5] = f * vt.ey.y;
// mat[9] = 0;
mat[13] = e.y;
// mat[2] = 0;
// mat[6] = 0;
// mat[10] = 1;
// mat[14] = 0;
// mat[3] = 0;
// mat[7] = 0;
// mat[11] = 0;
// mat[15] = 1;
gl.glMultMatrixf(mat, 0);
gl.glTranslatef(center.x - vc.x, center.y - vc.y, 0);
}
示例5: transformViewport
import javax.media.opengl.GL2; //導入方法依賴的package包/類
public void transformViewport(GL2 gl, Vec2 center) {
Vec2 e = viewportTransform.getExtents();
Vec2 vc = viewportTransform.getCenter();
Mat22 vt = viewportTransform.getMat22Representation();
int f = viewportTransform.isYFlip() ? -1 : 1;
mat[0] = vt.ex.x;
mat[4] = vt.ey.x;
// mat[8] = 0;
mat[12] = e.x;
mat[1] = f * vt.ex.y;
mat[5] = f * vt.ey.y;
// mat[9] = 0;
mat[13] = e.y;
// mat[2] = 0;
// mat[6] = 0;
// mat[10] = 1;
// mat[14] = 0;
// mat[3] = 0;
// mat[7] = 0;
// mat[11] = 0;
// mat[15] = 1;
gl.glMultMatrixf(mat, 0);
gl.glTranslatef(center.x - vc.x, center.y - vc.y, 0);
}
示例6: displace
import javax.media.opengl.GL2; //導入方法依賴的package包/類
/**
*
* @param openGl
*/
public void displace(final GL2 openGl) {
openGl.glPushMatrix();
openGl.glTranslatef(position[0], position[1], position[2]);
xAxis.rotateAround(openGl);
yAxis.rotateAround(openGl);
zAxis.rotateAround(openGl);
}
示例7: drawArrow
import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawArrow(Vector3f from, Vector3f to, float[] color, GL2 gl, GLUT glut) {
Vector3f zAxis = new Vector3f(0, 0, 1);
Vector3f vector = new Vector3f(to.x - from.x, to.y - from.y, to.z - from.z);
float length = vector.length();
vector.normalize();
float angle = zAxis.angle(vector);
Vector3f axis = new Vector3f();
axis.cross(zAxis, vector);
float convert = (float) (180f / Math.PI);
gl.glPushAttrib(GL2.GL_LIGHTING_BIT);
gl.glDisable(GL2.GL_TEXTURE_2D);
gl.glEnable(GL2.GL_LIGHTING);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_AMBIENT, color, 0);
gl.glMaterialfv(GL.GL_FRONT_AND_BACK, GL2.GL_DIFFUSE, color, 0);
gl.glMaterialf(GL.GL_FRONT_AND_BACK, GL2.GL_SHININESS, 10);
gl.glPushMatrix();
gl.glTranslatef(from.x, from.y, from.z);
gl.glRotatef(angle * convert, axis.x, axis.y, axis.z);
glut.glutSolidCylinder(info.getPointSize() / 3, length - info.getPointSize(), 20, 20);
gl.glTranslatef(0, 0, length - info.getPointSize());
glut.glutSolidCone(info.getPointSize(), info.getPointSize(), 20, 20);
gl.glPopMatrix();
gl.glEnable(GL2.GL_TEXTURE_2D);
gl.glDisable(GL2.GL_LIGHTING);
gl.glPopAttrib();
}
示例8: setupCamera
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override
public void setupCamera(GL2 gl, GLU glu, float x, float y, float z,
int width, int height) {
if(state != null) {
// Change to projection matrix.
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glViewport(0, 0, width, height);
FloatBoundingBox bbox = state.getOrthogonalBBox();
float glWidth = Math.abs(bbox.getUpperRight().getX()
- bbox.getUpperLeft().getX());
float glHeight = Math.abs(bbox.getUpperRight().getY()
- bbox.getLowerRight().getY());
FloatVector3D glCenter = state.getPosition();
gl.glOrthof(glCenter.getX() - glWidth / 2.0f, glCenter.getX() + glWidth
/ 2.0f, glCenter.getY() - glHeight / 2.0f, glCenter.getY()
+ glHeight / 2.0f, -10000, 10000);
gl.glTranslatef(glCenter.getX(), glCenter.getY(), 0);
gl.glRotatef(state.getRotation().getX(), 1, 0, 0);
gl.glRotatef(state.getRotation().getZ(), 0, 0, 1);
gl.glTranslatef(-glCenter.getX(), -glCenter.getY(), 0);
// Change back to model view matrix.
gl.glMatrixMode(GL2.GL_MODELVIEW);
gl.glLoadIdentity();
}
}
示例9: render
import javax.media.opengl.GL2; //導入方法依賴的package包/類
public void render(GL2 gl) {
// Create the credits texture if not done yet:
if(creditsTexture == null) {
createTexture();
}
if(creditsTexture != null) {
// Activate alpha:
gl.glEnable(GL2.GL_BLEND);
gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
// Bind the texture for use:
creditsTexture.bind(gl);
// The textures 2D-coordinates:
TextureCoords texCoords = creditsTexture.getImageTexCoords();
// Backup current matrix:
gl.glPushMatrix();
gl.glLoadIdentity();
// Apply transformation:
gl.glRotatef(rotation, 1, 0, 0);
gl.glTranslatef(0, -2, position);
gl.glRotatef(-90, 1, 0, 0);
// Draw vertices and pass uv-coords.
gl.glBegin(GL2.GL_QUADS);
gl.glTexCoord2f(texCoords.right(), texCoords.top());
gl.glVertex3f(CREDITS_PANE_WIDTH/2, CREDITS_PANE_HEIGHT/2, 0);
gl.glTexCoord2f(texCoords.left(), texCoords.top());
gl.glVertex3f(-CREDITS_PANE_WIDTH/2, CREDITS_PANE_HEIGHT/2, 0);
gl.glTexCoord2f(texCoords.left(), texCoords.bottom());
gl.glVertex3f(-CREDITS_PANE_WIDTH/2, -CREDITS_PANE_HEIGHT/2, 0);
gl.glTexCoord2f(texCoords.right(), texCoords.bottom());
gl.glVertex3f(CREDITS_PANE_WIDTH/2, -CREDITS_PANE_HEIGHT/2, 0);
gl.glEnd();
// Restore matrix:
gl.glPopMatrix();
}
}
示例10: draw
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override
public void draw(GL2 gl, float height) {
// Update and fetch texture.
if (adapter.toDraw()) {
adapter.bindTexture(gl);
Texture tex = adapter.getTexture();
if (tex != null) {
gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
tex.bind(gl);
TextureCoords texCoords = tex.getImageTexCoords();
FloatBoundingBox box = adapter.getDrawBox();
FloatVector3D upperLeft = box.getUpperLeft();
FloatVector3D upperRight = box.getUpperRight();
FloatVector3D lowerLeft = box.getLowerLeft();
FloatVector3D lowerRight = box.getLowerRight();
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(-1, 1,
-1, 1,
-10000, 10000);
gl.glDisable(GL2.GL_DEPTH_TEST);
gl.glMatrixMode(GL2.GL_MODELVIEW);
// Lift the x-y-pane up:
gl.glTranslatef(0, 0, height);
// Draw texture.
gl.glBegin(GL2.GL_QUADS);
gl.glTexCoord2f(texCoords.left(), texCoords.top());
gl.glVertex3f(upperLeft.getX(), upperLeft.getY(), 0.0f);
gl.glTexCoord2f(texCoords.left(), texCoords.bottom());
gl.glVertex3f(lowerLeft.getX(), lowerLeft.getY(), 0.0f);
gl.glTexCoord2f(texCoords.right(), texCoords.bottom());
gl.glVertex3f(lowerRight.getX(), lowerRight.getY(), 0.0f);
gl.glTexCoord2f(texCoords.right(), texCoords.top());
gl.glVertex3f(upperRight.getX(), upperRight.getY(), 0.0f);
gl.glEnd();
}
}
// Draw next layer if available.
if (this.hasNextLayer()) {
this.getNextLayer().draw(gl, height + HEIGHT_GAP);
}
}
示例11: draw
import javax.media.opengl.GL2; //導入方法依賴的package包/類
/**
* Draws all tiles available for the current view. Also all OpenGL-specific
* work in the adapter must be performed here. To accomplish this
* <code>performGLCalls()</code> is called.
*/
@Override
public void draw(GL2 gl, float height) {
if (adapter != null) {
// Create outstanding textures.
adapter.performGLCalls(gl);
Collection<GLResource> toDraw = adapter.getGLResources();
for (GLResource current : toDraw) {
// Get texture.
Texture tex = adapter.getTexture(current.getKey());
// Bind texture.
if (tex != null) {
tex.bind(gl);
// Vertices to draw.
FloatBoundingBox box = current.getBox();
FloatVector3D[] vertices = box.getCornersCounterClockwise();
// Tex coords.
TextureCoords texCoords = tex.getImageTexCoords();
// Backup the current Model-View-Matrix:
gl.glPushMatrix();
// Lift the x-y-pane up:
gl.glTranslatef(0, 0, height);
// Draw vertices and pass tex coords.
gl.glBegin(GL2.GL_QUADS);
gl.glTexCoord2f(texCoords.right(), texCoords.top());
gl.glVertex3f(vertices[0].getX(), vertices[0].getY(), 0);
gl.glTexCoord2f(texCoords.left(), texCoords.top());
gl.glVertex3f(vertices[1].getX(), vertices[1].getY(), 0);
gl.glTexCoord2f(texCoords.left(), texCoords.bottom());
gl.glVertex3f(vertices[2].getX(), vertices[2].getY(), 0);
gl.glTexCoord2f(texCoords.right(), texCoords.bottom());
gl.glVertex3f(vertices[3].getX(), vertices[3].getY(), 0);
gl.glEnd();
// Restore the old matrix:
gl.glPopMatrix();
}
}
}
// Draw next layer.
if (this.hasNextLayer()) {
this.getNextLayer().draw(gl, height + HEIGHT_GAP);
}
}
示例12: draw
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override
public void draw(GL2 gl, float height) {
// If not done yet, invoke the adapters initialization:
if(!adapterInitialized) {
adapter.performGLInit(gl);
adapterInitialized = true;
}
// Perform all the necessary OpenGL-stuff:
adapter.performGLCalls(gl);
// Update and fetch texture.
Texture tex = adapter.getTexture(CopyrightAdapter.COPYRIGHT_TEXTURE_KEY);
if (tex != null) {
gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
tex.bind(gl);
TextureCoords texCoords = tex.getImageTexCoords();
FloatBoundingBox box = adapter.getDrawBox();
if(box != null) {
FloatVector3D upperLeft = box.getUpperLeft();
FloatVector3D upperRight = box.getUpperRight();
FloatVector3D lowerLeft = box.getLowerLeft();
FloatVector3D lowerRight = box.getLowerRight();
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(-1, 1,
-1, 1,
-10000, 10000);
gl.glDisable(GL2.GL_DEPTH_TEST);
gl.glMatrixMode(GL2.GL_MODELVIEW);
// Lift the x-y-pane up:
gl.glTranslatef(0, 0, height);
// Draw texture.
gl.glBegin(GL2.GL_QUADS);
gl.glTexCoord2f(texCoords.left(), texCoords.top());
gl.glVertex3f(upperLeft.getX(), upperLeft.getY(), 0.0f);
gl.glTexCoord2f(texCoords.left(), texCoords.bottom());
gl.glVertex3f(lowerLeft.getX(), lowerLeft.getY(), 0.0f);
gl.glTexCoord2f(texCoords.right(), texCoords.bottom());
gl.glVertex3f(lowerRight.getX(), lowerRight.getY(), 0.0f);
gl.glTexCoord2f(texCoords.right(), texCoords.top());
gl.glVertex3f(upperRight.getX(), upperRight.getY(), 0.0f);
gl.glEnd();
}
}
// Draw next layer.
if (this.hasNextLayer()) {
this.getNextLayer().draw(gl, height + HEIGHT_GAP);
}
}
示例13: draw
import javax.media.opengl.GL2; //導入方法依賴的package包/類
/**
* Draws all Wikipedia-POIs available for the current view. Also all
* OpenGL-specific work in the adapter must be performed here.
*/
@Override
public void draw(GL2 gl, float height) {
WikipediaManager wikiManager = (WikipediaManager) ResourceMaster.getInstance().getResourceManager("Wikipedia");
if (wikiManager.isEnabled() && adapter != null && gl != null) {
// Check if the adapter was already initialized.
// This must be done from the OpenGl-thread:
if (!adapterInitialized) {
adapter.performGLInit(gl);
}
// Do further processing in the OpenGL-context:
adapter.performGLCalls(gl);
// Get the texture querying with the default key:
Texture texture = adapter
.getTexture(WikipediaAdapter.WIKIPEDIA_TEXTURE_KEY);
if (texture != null) {
// The textures 2D-coordinates:
TextureCoords texCoords = texture.getImageTexCoords();
gl.glEnable(GL2.GL_BLEND);
gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
// Bind the texture for use with every marker to draw:
texture.bind(gl);
// Iterate all markers already converted into GL-coordinates:
Collection<GLResource> glResources = adapter.getGLResources();
for (GLResource current : glResources) {
// Vertices to draw:
FloatBoundingBox box = current.getBox();
FloatVector3D[] vertices = box.getCornersCounterClockwise();
// Backup the current Model-View-Matrix:
gl.glPushMatrix();
// Lift the x-y-pane up:
gl.glTranslatef(0, 0, height);
// Draw vertices and pass uv-coords.
gl.glBegin(GL2.GL_QUADS);
gl.glTexCoord2f(texCoords.right(), texCoords.top());
gl.glVertex3f(vertices[0].getX(), vertices[0].getY(), 0);
gl.glTexCoord2f(texCoords.left(), texCoords.top());
gl.glVertex3f(vertices[1].getX(), vertices[1].getY(), 0);
gl.glTexCoord2f(texCoords.left(), texCoords.bottom());
gl.glVertex3f(vertices[2].getX(), vertices[2].getY(), 0);
gl.glTexCoord2f(texCoords.right(), texCoords.bottom());
gl.glVertex3f(vertices[3].getX(), vertices[3].getY(), 0);
gl.glEnd();
// Restore the old matrix:
gl.glPopMatrix();
}
}
}
// Draw next layer.
if (this.hasNextLayer()) {
this.getNextLayer().draw(gl, height + HEIGHT_GAP);
}
}
示例14: draw
import javax.media.opengl.GL2; //導入方法依賴的package包/類
/**
* Draws all POIs available for the current view. Also all OpenGL-specific
* work in the adapter must be performed here.
*/
@Override
public void draw(GL2 gl, float height) {
if (adapter != null && gl != null) {
// Check if the adapter was already initialized.
// This must be done from the OpenGl-thread:
if (!adapterInitialized) {
adapter.performGLInit(gl);
}
// Do further processing in the OpenGL-context:
adapter.performGLCalls(gl);
// Get the texture querying with the default key:
Texture texture = adapter
.getTexture(MarkerAdapter.MARKER_TEXTURE_KEY);
if (texture != null) {
// The textures 2D-coordinates:
TextureCoords texCoords = texture.getImageTexCoords();
gl.glEnable(GL2.GL_BLEND);
gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
// Bind the texture for use with every marker to draw:
texture.bind(gl);
// Iterate all markers already converted into GL-coordinates:
Collection<GLResource> glResources = adapter.getGLResources();
for (GLResource current : glResources) {
// Vertices to draw:
FloatBoundingBox box = current.getBox();
FloatVector3D[] vertices = box.getCornersCounterClockwise();
// Backup the current Model-View-Matrix:
gl.glPushMatrix();
// Lift the x-y-pane up:
gl.glTranslatef(0, 0, height);
// Draw vertices and pass uv-coords.
gl.glBegin(GL2.GL_QUADS);
gl.glTexCoord2f(texCoords.right(), texCoords.top());
gl.glVertex3f(vertices[0].getX(), vertices[0].getY(), 0);
gl.glTexCoord2f(texCoords.left(), texCoords.top());
gl.glVertex3f(vertices[1].getX(), vertices[1].getY(), 0);
gl.glTexCoord2f(texCoords.left(), texCoords.bottom());
gl.glVertex3f(vertices[2].getX(), vertices[2].getY(), 0);
gl.glTexCoord2f(texCoords.right(), texCoords.bottom());
gl.glVertex3f(vertices[3].getX(), vertices[3].getY(), 0);
gl.glEnd();
// Restore the old matrix:
gl.glPopMatrix();
}
}
}
// Draw next layer.
if (this.hasNextLayer()) {
this.getNextLayer().draw(gl, height + HEIGHT_GAP);
}
}
示例15: draw
import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override
public void draw(GL2 gl, float height) {
// If not done yet, invoke the adapters initialization:
if(!adapterInitialized) {
adapter.performGLInit(gl);
}
// Perform all the necessary OpenGL-stuff:
adapter.performGLCalls(gl);
// Update and fetch texture.
Texture tex = adapter.getTexture(CompassAdapter.COMPASS_TEXTURE_KEY);
if (tex != null) {
gl.glBlendFunc(GL2.GL_SRC_ALPHA, GL2.GL_ONE_MINUS_SRC_ALPHA);
tex.bind(gl);
TextureCoords texCoords = tex.getImageTexCoords();
FloatBoundingBox box = adapter.getDrawBox();
FloatVector3D upperLeft = box.getUpperLeft();
FloatVector3D upperRight = box.getUpperRight();
FloatVector3D lowerLeft = box.getLowerLeft();
FloatVector3D lowerRight = box.getLowerRight();
gl.glMatrixMode(GL2.GL_PROJECTION);
gl.glLoadIdentity();
gl.glOrthof(-1, 1,
-1, 1,
-10000, 10000);
gl.glDisable(GL2.GL_DEPTH_TEST);
gl.glMatrixMode(GL2.GL_MODELVIEW);
// Lift the x-y-pane up:
gl.glTranslatef(0, 0, height);
// Draw texture.
gl.glBegin(GL2.GL_QUADS);
gl.glTexCoord2f(texCoords.left(), texCoords.top());
gl.glVertex3f(upperLeft.getX(), upperLeft.getY(), 0.0f);
gl.glTexCoord2f(texCoords.left(), texCoords.bottom());
gl.glVertex3f(lowerLeft.getX(), lowerLeft.getY(), 0.0f);
gl.glTexCoord2f(texCoords.right(), texCoords.bottom());
gl.glVertex3f(lowerRight.getX(), lowerRight.getY(), 0.0f);
gl.glTexCoord2f(texCoords.right(), texCoords.top());
gl.glVertex3f(upperRight.getX(), upperRight.getY(), 0.0f);
gl.glEnd();
}
// Draw next layer.
if (this.hasNextLayer()) {
this.getNextLayer().draw(gl, height + HEIGHT_GAP);
}
}