當前位置: 首頁>>代碼示例>>Java>>正文


Java GL2.glTranslated方法代碼示例

本文整理匯總了Java中javax.media.opengl.GL2.glTranslated方法的典型用法代碼示例。如果您正苦於以下問題:Java GL2.glTranslated方法的具體用法?Java GL2.glTranslated怎麽用?Java GL2.glTranslated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.media.opengl.GL2的用法示例。


在下文中一共展示了GL2.glTranslated方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: draw

import javax.media.opengl.GL2; //導入方法依賴的package包/類
/**
 * Draws this robot on the screen.
 *
 * @param gl          The instance of GL2 responsible for drawing the robot
 *                    on the screen.
 * @param glut        An instance of GLUT to optionally aid in drawing the
 *                    robot body.
 * @param stickFigure If true, the robot must draw itself as a stick figure
 *                    rather than a solid body.
 * @param tAnim       Time since the start of the animation in seconds.
 * @param lighting    The Lighting instance responsible for calculating the
 *                    lighting in this scene. Can be used to set the color
 *                    of bodies before drawing them.
 */
public void draw(GL2 gl, GLUT glut, boolean stickFigure, float tAnim, Lighting lighting) {
    lighting.setMaterial(gl, getMaterial());
    gl.glPushMatrix();
    {
        gl.glTranslated(position.x(), position.y(), position.z());
        final double rotationDotY = direction.dot(Vector.Y) / (direction.length() * Vector.Y.length());
        final double rotationDotX = direction.dot(Vector.X) / (direction.length() * Vector.X.length());
        final double rotationAngle = Math.toDegrees(Math.acos(rotationDotY));
        gl.glRotated((rotationDotX > 0d) ? (-rotationAngle) : (rotationAngle), Vector.Z.x(), Vector.Z.y(), Vector.Z.z());
        final double elevationDot = direction.dot(Vector.Z) / (direction.length() * Vector.Z.length());
        final double elevationAngle = Math.toDegrees(Math.asin(elevationDot));
        gl.glRotated(elevationAngle, Vector.X.x(), Vector.X.y(), Vector.X.z());
        robotBody.draw(gl, glut, stickFigure, tAnim);
    }
    gl.glPopMatrix();
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:31,代碼來源:Robot.java

示例2: draw

import javax.media.opengl.GL2; //導入方法依賴的package包/類
/**
 * Draws the terrain.
 *
 * @param gl       The instance of GL2 responsible for drawing the body.
 * @param glut     An instance of GLUT that can be optionally used to assist
 *                 in drawing.
 * @param camPos   The position of the camera in world coordinates.
 * @param lighting The Lighting instance responsible for calculating the
 *                 lighting in this scene. Can be used to set the colours of
 *                 bodies before drawing them.
 */
public void draw(GL2 gl, GLUT glut, Vector camPos, Lighting lighting) {
    gl.glPushMatrix();
    {
        gl.glTranslated(TERRAIN_LEVEL.x(), TERRAIN_LEVEL.y(), TERRAIN_LEVEL.z());
        gl.glEnable(GL_CULL_FACE);
        lighting.setMaterial(gl, Material.DIRT, true);
        terrainBody.draw(gl);
        lighting.setMaterial(gl, Material.WATER);
        waterBody.draw(gl);
        gl.glDisable(GL_CULL_FACE);
        final Vector camPosRelativeToTerrain = camPos.subtract(TERRAIN_LEVEL);
        trees.stream().forEach((tree) -> tree.draw(gl, camPosRelativeToTerrain, lighting));
    }
    gl.glPopMatrix();
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:27,代碼來源:Terrain.java

示例3: display

import javax.media.opengl.GL2; //導入方法依賴的package包/類
public void display(GLAutoDrawable drawable) {
	GL2 gl = drawable.getGL().getGL2();
	this.drawable = drawable;

	// Apply transformations
	double transx = -origin.getX(), transy = -origin.getY();

	gl.glMatrixMode(GL2.GL_PROJECTION);
	gl.glLoadIdentity();
	gl.glOrtho(0, width, height, 0, -1, 1);
	gl.glViewport(0, 0, width, height);

	gl.glTranslated(transx + zoomPos.getX(), transy + zoomPos.getY(), 0);
	gl.glScaled(scaleFactor, scaleFactor, 1);
	gl.glTranslated(-zoomPos.getX(), -zoomPos.getY(), 0);

	gl.glGetDoublev(GL2.GL_MODELVIEW_MATRIX, modelview);
	gl.glGetDoublev(GL2.GL_PROJECTION_MATRIX, projection);
	gl.glGetIntegerv(GL2.GL_VIEWPORT, viewport);
	gl.glClear(GL2.GL_COLOR_BUFFER_BIT | GL2.GL_DEPTH_BUFFER_BIT);

	// Draw edges, arrows and vertices
	edgeRenderer.transform(transx, transy, scaleFactor);
	edgeRenderer.render();

	if (animateLabels) {
		labelRenderer.scale(scaleFactor);
		labelRenderer.drawLabels();
	}

	vertexRenderer.transform(transx, transy, scaleFactor);
	vertexRenderer.render();
}
 
開發者ID:dev-cuttlefish,項目名稱:cuttlefish,代碼行數:34,代碼來源:NetworkRenderer.java

示例4: drawHips

import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawHips(GL2 gl, GLUT glut, boolean stickFigure, Animation animation) {
    for (int i = 0; i < NR_HIP_JOINTS; i++) {
        gl.glRotated(getPartialHipAngle(animation), -1d, 0d, 0d);
        limb.drawSegment(gl, glut, stickFigure);
        gl.glTranslated(0d, 0d, Limb.HEIGHT_OUTER_SEGMENT);
    }
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:8,代碼來源:Leg.java

示例5: drawKnees

import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawKnees(GL2 gl, GLUT glut, boolean stickFigure, Animation animation) {
    for (int i = 0; i < NR_KNEE_JOINTS; i++) {
        gl.glRotated(getPartialKneeAngle(animation), -1d, 0d, 0d);
        limb.drawSegment(gl, glut, stickFigure);
        gl.glTranslated(0d, 0d, Limb.HEIGHT_OUTER_SEGMENT);
    }
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:8,代碼來源:Leg.java

示例6: drawAnkles

import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawAnkles(GL2 gl, GLUT glut, boolean stickFigure, Animation animation) {
    for (int i = 0; i < NR_ANKLE_JOINTS + 1; i++) {
        gl.glRotated(getPartialAnkleAngle(animation), -1d, 0d, 0d);
        if (i == NR_ANKLE_JOINTS) {
            limb.drawFoot(gl, stickFigure);
        } else {
            limb.drawSegment(gl, glut, stickFigure);
            gl.glTranslated(0d, 0d, Limb.HEIGHT_OUTER_SEGMENT);
        }
    }
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:12,代碼來源:Leg.java

示例7: draw

import javax.media.opengl.GL2; //導入方法依賴的package包/類
@Override
public void draw(GL2 gl, GLUT glut, boolean stickFigure, float tAnim) {
    animation.update(tAnim);
    gl.glPushMatrix();
    {
        final double legHeight = Limb.HEIGHT_OUTER_SEGMENT * Limb.RING_COUNT + Limb.HEIGHT_FOOT;
        gl.glTranslated(0d, 0d, legHeight);

        torso.draw(gl, glut, stickFigure, animation, backNumber);

        gl.glPushMatrix();
        {
            torso.setRightLegMountPoint(gl);
            rightLeg.draw(gl, glut, stickFigure, animation);
        }
        gl.glPopMatrix();
        gl.glPushMatrix();
        {
            torso.setLeftLegMountPoint(gl);
            leftLeg.draw(gl, glut, stickFigure, animation);
        }
        gl.glPopMatrix();
        gl.glPushMatrix();
        {
            torso.setRightArmMountPoint(gl);
            rightArm.draw(gl, glut, stickFigure, animation);
        }
        gl.glPopMatrix();
        gl.glPushMatrix();
        {
            torso.setLeftArmMountPoint(gl);
            leftArm.draw(gl, glut, stickFigure, animation);
        }
        gl.glPopMatrix();
    }
    gl.glPopMatrix();
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:38,代碼來源:Bender.java

示例8: drawSegment

import javax.media.opengl.GL2; //導入方法依賴的package包/類
public void drawSegment(GL2 gl, GLUT glut, boolean stickFigure) {
    gl.glPushMatrix();
    if (stickFigure) {
        gl.glTranslated(0d, 0d, HEIGHT_OUTER_SEGMENT / 2f);
        gl.glScaled(RobotBody.STICK_THICKNESS, RobotBody.STICK_THICKNESS, HEIGHT_OUTER_SEGMENT);
        glut.glutSolidCube(1f);
    } else {
        outerSegmentBody.draw(gl);
        final double heightDifference = HEIGHT_OUTER_SEGMENT - HEIGHT_INNER_SEGMENT;
        gl.glTranslated(0d, 0d, heightDifference / 2f);
        innerSegmentBody.draw(gl);
    }
    gl.glPopMatrix();
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:15,代碼來源:Limb.java

示例9: drawStickFigureBody

import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawStickFigureBody(GL2 gl, GLUT glut, double bodyHeight) {
    gl.glPushMatrix();
    gl.glScaled(RobotBody.STICK_THICKNESS, RobotBody.STICK_THICKNESS, bodyHeight);
    gl.glTranslated(0d, 0d, bodyHeight / 2f);
    glut.glutSolidCube(1f);
    gl.glPopMatrix();
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:8,代碼來源:Torso.java

示例10: drawStickFigureShoulders

import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawStickFigureShoulders(GL2 gl, GLUT glut) {
    final double shoulderWidth = SHOULDER_OFFCENTER * 2f;
    gl.glPushMatrix();
    gl.glTranslated(0d, 0d, SHOULDER_HEIGHT);
    gl.glScaled(shoulderWidth, RobotBody.STICK_THICKNESS, RobotBody.STICK_THICKNESS);
    glut.glutSolidCube(1f);
    gl.glPopMatrix();
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:9,代碼來源:Torso.java

示例11: drawEyes

import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawEyes(GL2 gl, GLUT glut) {
    gl.glPushMatrix();
    gl.glTranslated(0.05d, 0.125d, 0.8d);
    glut.glutSolidSphere(0.025d, 50, 50);
    gl.glTranslated(-0.1d, 0d, 0d);
    glut.glutSolidSphere(0.025d, 50, 50);
    gl.glPopMatrix();
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:9,代碼來源:Torso.java

示例12: draw

import javax.media.opengl.GL2; //導入方法依賴的package包/類
public void draw(GL2 gl, Lighting lighting, Foliage foliage, int requiredDetailLevel, int depth) {
    gl.glPushMatrix();
    gl.glTranslated(0d, 0d, zTranslation);
    gl.glRotated(zRotation, 0d, 0d, 1d);
    gl.glRotated(yRotation, 0d, 1d, 0d);
    gl.glPushMatrix();
    if (isLeaf) {
        final float scaleMultiplier = (requiredDetailLevel == 0) ? (4f) : ((requiredDetailLevel == 1) ? (2f) : (1f));
        gl.glScaled(scale.x() * scaleMultiplier, scale.y() * scaleMultiplier, scale.z() * scaleMultiplier);
        gl.glTranslated(sidewaysTranslation, 0d, 0d);
        gl.glRotated(zRotation, 0d, 0d, 1d);
        foliage.drawLeaf(gl);
    } else {
        gl.glScaled(scale.x(), scale.y(), scale.z());
        foliage.drawBranch(gl, calcRequiredDetailForBranch(requiredDetailLevel, (float) scale.x()));
    }
    gl.glPopMatrix();
    final int maxNodes = (requiredDetailLevel == 0) ? (1)
            : ((requiredDetailLevel == 1) ? (4)
                    : ((requiredDetailLevel == 2) ? (10)
                            : (Integer.MAX_VALUE)));
    if (!childLeafs.isEmpty()) {
        lighting.setMaterial(gl, Material.LEAF);
        childLeafs.stream().limit(maxNodes).forEach((node) -> node.draw(gl, lighting, foliage, requiredDetailLevel, depth + 1));
        lighting.setMaterial(gl, Material.BARK);
    }
    if (!keepGoing(requiredDetailLevel, depth)) {
        gl.glPopMatrix();
        return;
    }
    childBranches.stream().limit(maxNodes).forEach((child) -> child.draw(gl, lighting, foliage, requiredDetailLevel, depth + 1));
    gl.glPopMatrix();
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:34,代碼來源:Tree.java

示例13: drawElbows

import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawElbows(GL2 gl, GLUT glut, boolean stickFigure, Animation animation) {
    for (int i = 0; i < NR_ELBOW_JOINTS; i++) {
        gl.glRotated(getPartialElbowAngle(animation), 1f, 0f, 0.7f * horizontalTurningAxis.z());
        limb.drawSegment(gl, glut, stickFigure);
        gl.glTranslated(0d, 0d, Limb.HEIGHT_OUTER_SEGMENT);
    }
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:8,代碼來源:Arm.java

示例14: drawWrists

import javax.media.opengl.GL2; //導入方法依賴的package包/類
private void drawWrists(GL2 gl, GLUT glut, boolean stickFigure, Animation animation) {
    for (int i = 0; i < NR_WRIST_JOINTS + 1; i++) {
        gl.glRotated(getPartialWristAngle(animation), 0.1f, 0.5f * horizontalTurningAxis.z(), 0d);
        if (i == NR_WRIST_JOINTS) {
            limb.drawHand(gl, stickFigure);
        } else {
            limb.drawSegment(gl, glut, stickFigure);
            gl.glTranslated(0d, 0d, Limb.HEIGHT_OUTER_SEGMENT);
        }
    }
}
 
開發者ID:ABoschman,項目名稱:2IV60_RobotRace,代碼行數:12,代碼來源:Arm.java

示例15: plotObject

import javax.media.opengl.GL2; //導入方法依賴的package包/類
/**
 *	{@inheritDoc}
 * 	@see org.openimaj.vis.general.ItemPlotter3D#plotObject(javax.media.opengl.GLAutoDrawable, org.openimaj.vis.general.XYZVisualisation3D.LocatedObject3D, org.openimaj.vis.general.AxesRenderer3D)
 */
@Override
public void plotObject( final GLAutoDrawable drawable, final LocatedObject3D<Rectangle3D> object,
		final AxesRenderer3D renderer )
{
	// object.object.x,y,z is where we plot the rectangle.
	// object.x,y,z is the data point position.
	final double[] p = renderer.calculatePosition( new double[]
			{ object.object.x, object.object.y, object.object.z } );
	final double[] p2 = renderer.calculatePosition( new double[]
			{ object.x, object.y, object.z } );

	final GL2 gl = drawable.getGL().getGL2();

	gl.glPushMatrix();

	// Translate to the position of the rectangle
	gl.glMatrixMode( GLMatrixFunc.GL_MODELVIEW );
	gl.glTranslated( p2[0], p2[1], p2[2] );
	gl.glRotated( object.object.xRotation, 1, 0, 0 );
	gl.glRotated( object.object.yRotation, 0, 1, 0 );
	gl.glRotated( object.object.zRotation, 0, 0, 1 );

	final double[] dims = renderer.scaleDimension( new double[]{object.object.width,object.object.height,0} );
	final double w = dims[0];
	final double h = dims[1];

	gl.glBegin( GL.GL_LINE_LOOP );
	gl.glVertex3d( p2[0]-p[0], p2[1]-p[1], 0 );
	gl.glVertex3d( p2[0]-p[0]-w, p2[1]-p[1], 0 );
	gl.glVertex3d( p2[0]-p[0]-w, p2[1]-p[1]-h, 0 );
	gl.glVertex3d( p2[0]-p[0], p2[1]-p[1]-h, 0 );
	gl.glEnd();

	gl.glPopMatrix();

	if( this.pos == RectanglePlotPosition.CENTRAL && this.drawDotAtPoint )
	{
		gl.glPushMatrix();
		gl.glMatrixMode( GLMatrixFunc.GL_MODELVIEW );
		gl.glBegin( GL.GL_POINTS );
		gl.glVertex3d( p2[0], p2[1], p2[2] );
		gl.glEnd();
		gl.glPopMatrix();
	}
}
 
開發者ID:openimaj,項目名稱:openimaj,代碼行數:50,代碼來源:Rectangle3DPlotter.java


注:本文中的javax.media.opengl.GL2.glTranslated方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。