Java Code Examples for com.jogamp.opengl.GL2#glTranslated()

The following examples show how to use com.jogamp.opengl.GL2#glTranslated() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PrimitiveSolids.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
static public void drawStar(GL2 gl2,Vector3d p,double size) {
	// save the current color
	double [] params = new double[4];
	gl2.glGetDoublev(GL2.GL_CURRENT_COLOR, params, 0);
	
	boolean lightWasOn = OpenGLHelper.disableLightingStart(gl2);
	int depth = OpenGLHelper.drawAtopEverythingStart(gl2);

	size/=2.0f;
	
	gl2.glPushMatrix();
	gl2.glTranslated(p.x, p.y, p.z);
	gl2.glBegin(GL2.GL_LINES);
	gl2.glColor3d(1, 0, 0);		gl2.glVertex3d(0, 0, 0);		gl2.glVertex3d(size, 0, 0);
	gl2.glColor3d(0, 1, 0);		gl2.glVertex3d(0, 0, 0);		gl2.glVertex3d(0, size, 0);
	gl2.glColor3d(0, 0, 1);		gl2.glVertex3d(0, 0, 0);		gl2.glVertex3d(0, 0, size);
	gl2.glEnd();
	gl2.glPopMatrix();

	OpenGLHelper.drawAtopEverythingEnd(gl2,depth);
	OpenGLHelper.disableLightingEnd(gl2,lightWasOn);
	
	// restore color
	gl2.glColor4dv(params,0);
}
 
Example 2
Source File: MatrixHelper.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
/**
 * See drawMatrix(gl2,p,u,v,w,1)
 * @param gl2
 * @param m
 * @param scale
 */
public static void drawMatrix(GL2 gl2,Matrix4d m,double scale) {
	boolean depthWasOn = gl2.glIsEnabled(GL2.GL_DEPTH_TEST);
	gl2.glDisable(GL2.GL_DEPTH_TEST);
	boolean lightWasOn = gl2.glIsEnabled(GL2.GL_LIGHTING);
	gl2.glDisable(GL2.GL_LIGHTING);
	
	gl2.glPushMatrix();
		gl2.glTranslated(m.m03,m.m13,m.m23);
		gl2.glScaled(scale, scale, scale);
		
		gl2.glBegin(GL2.GL_LINES);
		gl2.glColor3f(1,0,0);		gl2.glVertex3f(0,0,0);		gl2.glVertex3d(m.m00,m.m10,m.m20);  // 1,0,0 = red
		gl2.glColor3f(0,1,0);		gl2.glVertex3f(0,0,0);		gl2.glVertex3d(m.m01,m.m11,m.m21);  // 0,1,0 = green 
		gl2.glColor3f(0,0,1);		gl2.glVertex3f(0,0,0);		gl2.glVertex3d(m.m02,m.m12,m.m22);  // 0,0,1 = blue
		gl2.glEnd();

	gl2.glPopMatrix();
	if(lightWasOn) gl2.glEnable(GL2.GL_LIGHTING);
	if(depthWasOn) gl2.glEnable(GL2.GL_DEPTH_TEST);
}
 
Example 3
Source File: MatrixHelper.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
/**
 * See drawMatrix(gl2,p,u,v,w,1)
 * @param gl2
 * @param m
 * @param scale
 */
public static void drawMatrix2(GL2 gl2,Matrix4d m,double scale) {
	boolean depthWasOn = gl2.glIsEnabled(GL2.GL_DEPTH_TEST);
	gl2.glDisable(GL2.GL_DEPTH_TEST);
	boolean lightWasOn = gl2.glIsEnabled(GL2.GL_LIGHTING);
	gl2.glDisable(GL2.GL_LIGHTING);
	
	gl2.glPushMatrix();
		gl2.glTranslated(m.m03,m.m13,m.m23);
		gl2.glScaled(scale, scale, scale);
		
		gl2.glBegin(GL2.GL_LINES);
		gl2.glColor3f(1,1,0);		gl2.glVertex3f(0,0,0);		gl2.glVertex3d(m.m00,m.m10,m.m20);  // 1,1,0 = yellow
		gl2.glColor3f(0,1,1);		gl2.glVertex3f(0,0,0);		gl2.glVertex3d(m.m01,m.m11,m.m21);  // 0,1,1 = teal 
		gl2.glColor3f(1,0,1);		gl2.glVertex3f(0,0,0);		gl2.glVertex3d(m.m02,m.m12,m.m22);  // 1,0,1 = magenta
		gl2.glEnd();

	gl2.glPopMatrix();
	if(lightWasOn) gl2.glEnable(GL2.GL_LIGHTING);
	if(depthWasOn) gl2.glEnable(GL2.GL_DEPTH_TEST);
}
 
Example 4
Source File: Spidee.java    From Robot-Overlord-App with GNU General Public License v2.0 6 votes vote down vote up
void Draw_Body(GL2 gl2) {
	gl2.glPushMatrix();

	DoubleBuffer m=DoubleBuffer.allocate(16);

	m.put( 0,-body.left.x);
	m.put( 1,-body.left.y);
	m.put( 2,-body.left.z);
	m.put( 4,body.forward.x);
	m.put( 5,body.forward.y);
	m.put( 6,body.forward.z);
	m.put( 8,body.up.x);
	m.put( 9,body.up.y);
	m.put(10,body.up.z);
	m.put(15,1);

	matBody.render(gl2);
    gl2.glTranslated(body.pos.x + 7.5f * body.up.x,
                 body.pos.y + 7.5f * body.up.y,
                 body.pos.z + 7.5f * body.up.z );
    gl2.glMultMatrixd(m);
    gl2.glRotatef(180,0,1,0);
    modelBody.render(gl2);

    gl2.glPopMatrix();
}
 
Example 5
Source File: Spidee.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public void render(GL2 gl2) {
	super.render(gl2);
	gl2.glPushName(getPickName());
	gl2.glPushMatrix();

	Vector3d p = getPosition();
	gl2.glTranslated(p.x, p.y, p.z);
	Draw_Head(gl2);
	Draw_Legs(gl2);
	Draw_Body(gl2);
	gl2.glPopMatrix();
	gl2.glPopName();
}
 
Example 6
Source File: Sixi2Live.java    From Robot-Overlord-App with GNU General Public License v2.0 5 votes vote down vote up
public void renderCartesianForce(GL2 gl2) {
	double len = Math.sqrt(
		cartesianForceDetected[0]*cartesianForceDetected[0]+
		cartesianForceDetected[1]*cartesianForceDetected[1]+
		cartesianForceDetected[2]*cartesianForceDetected[2]);
	if(len<1) return;
	//System.out.println(len);

	int previousState = OpenGLHelper.drawAtopEverythingStart(gl2);
	boolean lightWasOn = OpenGLHelper.disableLightingStart(gl2);
	gl2.glLineWidth(4);
	
	double scale=1;

	gl2.glPushMatrix();
		Matrix4d m4 = endEffector.getPoseWorld();
		gl2.glTranslated(m4.m03, m4.m13, m4.m23);

		gl2.glBegin(GL2.GL_LINES);
		gl2.glColor3d(0, 0.6, 1);
		gl2.glVertex3d(0,0,0);
		gl2.glVertex3d(
				cartesianForceDetected[0]*scale,
				cartesianForceDetected[1]*scale,
				cartesianForceDetected[2]*scale);
		
		gl2.glColor3d(1.0, 0.5, 0.5);	PrimitiveSolids.drawCircleYZ(gl2, cartesianForceDetected[3]*scale, 20);
		gl2.glColor3d(0.5, 1.0, 0.5);	PrimitiveSolids.drawCircleXZ(gl2, cartesianForceDetected[4]*scale, 20);
		gl2.glColor3d(0.5, 0.5, 1.0);	PrimitiveSolids.drawCircleXY(gl2, cartesianForceDetected[5]*scale, 20);
	
	gl2.glPopMatrix();

	gl2.glLineWidth(1);
	OpenGLHelper.disableLightingEnd(gl2, lightWasOn);
	OpenGLHelper.drawAtopEverythingEnd(gl2, previousState);
}
 
Example 7
Source File: SkyBoxEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 4 votes vote down vote up
public void render(GL2 gl2,CameraEntity camera) {		
	//gl2.glDisable(GL2.GL_DEPTH_TEST);
	gl2.glDisable(GL2.GL_LIGHTING);
	gl2.glDisable(GL2.GL_COLOR_MATERIAL);
	gl2.glEnable(GL2.GL_TEXTURE_2D);
	gl2.glPushMatrix();
		gl2.glColor3f(1, 1, 1);
		Vector3d p = camera.getPosition();
		gl2.glTranslated(-p.x,-p.y,-p.z);

		skyboxtextureXPos.render(gl2);
		gl2.glBegin(GL2.GL_TRIANGLE_FAN);
			gl2.glTexCoord2d(0,1);  gl2.glVertex3d(10, 10, 10);
			gl2.glTexCoord2d(1,1);  gl2.glVertex3d(10, -10, 10);
			gl2.glTexCoord2d(1,0);  gl2.glVertex3d(10, -10, -10);
			gl2.glTexCoord2d(0,0);  gl2.glVertex3d(10, 10, -10);
		gl2.glEnd();

		skyboxtextureXNeg.render(gl2);
		gl2.glBegin(GL2.GL_TRIANGLE_FAN);
			gl2.glTexCoord2d(0,1);  gl2.glVertex3d(-10, -10, 10);
			gl2.glTexCoord2d(1,1);  gl2.glVertex3d(-10, 10, 10);
			gl2.glTexCoord2d(1,0);  gl2.glVertex3d(-10, 10, -10);
			gl2.glTexCoord2d(0,0);  gl2.glVertex3d(-10, -10, -10);
		gl2.glEnd();

		skyboxtextureYPos.render(gl2);
		gl2.glBegin(GL2.GL_TRIANGLE_FAN);
			gl2.glTexCoord2d(0,1);  gl2.glVertex3d(-10, 10, 10);
			gl2.glTexCoord2d(1,1);  gl2.glVertex3d(10, 10, 10);
			gl2.glTexCoord2d(1,0);  gl2.glVertex3d(10, 10, -10);
			gl2.glTexCoord2d(0,0);  gl2.glVertex3d(-10, 10, -10);
		gl2.glEnd();

		skyboxtextureYNeg.render(gl2);
		gl2.glBegin(GL2.GL_TRIANGLE_FAN);
			gl2.glTexCoord2d(0,1);  gl2.glVertex3d(10, -10, 10);
			gl2.glTexCoord2d(1,1);  gl2.glVertex3d(-10, -10, 10);
			gl2.glTexCoord2d(1,0);  gl2.glVertex3d(-10, -10, -10);
			gl2.glTexCoord2d(0,0);  gl2.glVertex3d(10, -10, -10);
		gl2.glEnd();

		skyboxtextureZPos.render(gl2);
		gl2.glBegin(GL2.GL_TRIANGLE_FAN);
			gl2.glTexCoord2d(0,0);  gl2.glVertex3d(-10, 10, 10);
			gl2.glTexCoord2d(1,0);  gl2.glVertex3d( 10, 10, 10);
			gl2.glTexCoord2d(1,1);  gl2.glVertex3d( 10,-10, 10);
			gl2.glTexCoord2d(0,1);  gl2.glVertex3d(-10,-10, 10);
		gl2.glEnd();

		skyboxtextureZNeg.render(gl2);
		gl2.glBegin(GL2.GL_TRIANGLE_FAN);
			gl2.glTexCoord2d(0,0);  gl2.glVertex3d(-10,-10, -10);
			gl2.glTexCoord2d(1,0);  gl2.glVertex3d( 10,-10, -10);
			gl2.glTexCoord2d(1,1);  gl2.glVertex3d( 10, 10, -10);
			gl2.glTexCoord2d(0,1);  gl2.glVertex3d(-10, 10, -10);
		gl2.glEnd();
		
	gl2.glPopMatrix();
	gl2.glEnable(GL2.GL_DEPTH_TEST);
}
 
Example 8
Source File: ViewCubeEntity.java    From Robot-Overlord-App with GNU General Public License v2.0 4 votes vote down vote up
public void render(GL2 gl2) {
	RobotOverlord ro = (RobotOverlord)getRoot();
	ViewportEntity cameraView = ro.viewport;
	
	gl2.glClear(GL2.GL_DEPTH_BUFFER_BIT);

	gl2.glEnable(GL2.GL_DEPTH_TEST);
	gl2.glEnable(GL2.GL_CULL_FACE);
	
	gl2.glBlendFunc(GL2.GL_SRC_ALPHA,GL2.GL_ONE_MINUS_SRC_ALPHA);

   	gl2.glMatrixMode(GL2.GL_PROJECTION);
	gl2.glPushMatrix();
	cameraView.renderOrtho(gl2,1);
	gl2.glMatrixMode(GL2.GL_MODELVIEW);
	
	gl2.glPushMatrix();			
		double c = cubeSize.get();			
		PoseEntity camera = cameraView.getAttachedTo();
		Matrix4d m = camera.getPoseWorld();
		Vector3d p = camera.getPosition();
		Vector3d vx = MatrixHelper.getXAxis(m);
		Vector3d vy = MatrixHelper.getYAxis(m);
		Vector3d vz = MatrixHelper.getZAxis(m);
	
		vz.scale(-100);
		vx.scale(cameraView.getCanvasWidth() /10 -c*2);
		vy.scale(cameraView.getCanvasHeight()/10 -c*2);
		p.add(vx);
		p.add(vy);
		p.add(vz);
		
		gl2.glTranslated(p.x, p.y, p.z);
		gl2.glScaled(c,c,c);

		model.render(gl2);

		gl2.glDisable(GL2.GL_LIGHTING);
		gl2.glDisable(GL2.GL_COLOR_MATERIAL);
		gl2.glDisable(GL2.GL_TEXTURE_2D);
		
		// the big lines
		gl2.glLineWidth(4);
		gl2.glPushMatrix();
			gl2.glTranslated(-1.05,-1.05,-0.95);
			gl2.glBegin(GL2.GL_LINES);
			gl2.glColor3d(1, 0, 0);		gl2.glVertex3d(0, 0, 0);		gl2.glVertex3d(2.5, 0, 0);
			gl2.glColor3d(0, 1, 0);		gl2.glVertex3d(0, 0, 0);		gl2.glVertex3d(0, 2.5, 0);
			gl2.glColor3d(0, 0, 1);		gl2.glVertex3d(0, 0, 0);		gl2.glVertex3d(0, 0, 2.5);
			gl2.glEnd();
		gl2.glPopMatrix();
		gl2.glLineWidth(1);
					
	gl2.glPopMatrix();

   	gl2.glMatrixMode(GL2.GL_PROJECTION);
	gl2.glPopMatrix();
	gl2.glMatrixMode(GL2.GL_MODELVIEW);
}
 
Example 9
Source File: ScreenSelector.java    From hortonmachine with GNU General Public License v3.0 4 votes vote down vote up
protected void drawOrderedRenderable( DrawContext dc ) {
    int attrs = GL2.GL_COLOR_BUFFER_BIT // For blend enable, alpha
                                        // enable, blend func, alpha
                                        // func.
            | GL2.GL_CURRENT_BIT // For current color.
            | GL2.GL_DEPTH_BUFFER_BIT; // For depth test disable.

    Rectangle viewport = dc.getView().getViewport();
    Rectangle selection = this.getSelection();

    GL2 gl = dc.getGL().getGL2(); // GL initialization checks for GL2
                                  // compatibility.
    this.BEogsh.pushAttrib(gl, attrs);
    this.BEogsh.pushClientAttrib(gl, GL2.GL_VERTEX_ARRAY);
    try {
        // Configure the modelview-projection matrix to transform vertex
        // points from screen rectangle
        // coordinates to clip coordinates without any perspective
        // transformation. We offset the rectangle by
        // 0.5 pixels to ensure that the line loop draws a line without
        // a 1-pixel gap between the line's
        // beginning and its end. We scale by (width - 1, height - 1) to
        // ensure that only the actual selected
        // area is filled. If we scaled by (width, height), GL line
        // rasterization would fill one pixel beyond
        // the actual selected area.
        this.BEogsh.pushProjectionIdentity(gl);
        gl.glOrtho(0, viewport.getWidth(), 0, viewport.getHeight(), -1, 1); // l,
                                                                            // r,
                                                                            // b,
                                                                            // t,
                                                                            // n,
                                                                            // f
        this.BEogsh.pushModelviewIdentity(gl);
        gl.glTranslated(0.5, 0.5, 0.0);
        gl.glTranslated(selection.getX(), viewport.getHeight() - selection.getY(), 0);
        gl.glScaled(selection.getWidth() - 1, selection.getHeight() - 1, 1);

        // Disable the depth test and enable blending so this screen
        // rectangle appears on top of the existing
        // framebuffer contents.
        gl.glDisable(GL.GL_DEPTH_TEST);
        gl.glEnable(GL.GL_BLEND);
        OGLUtil.applyBlending(gl, false); // SelectionRectangle does not
                                          // use pre-multiplied colors.

        // Draw this screen rectangle's interior as a filled
        // quadrilateral.
        Color c = this.getInteriorColor() != null ? this.getInteriorColor() : DEFAULT_INTERIOR_COLOR;
        gl.glColor4ub((byte) c.getRed(), (byte) c.getGreen(), (byte) c.getBlue(), (byte) c.getAlpha());
        dc.drawUnitQuad();

        // Draw this screen rectangle's border as a line loop. This
        // assumes the default line width of 1.0.
        c = this.getBorderColor() != null ? this.getBorderColor() : DEFAULT_BORDER_COLOR;
        gl.glColor4ub((byte) c.getRed(), (byte) c.getGreen(), (byte) c.getBlue(), (byte) c.getAlpha());
        dc.drawUnitQuadOutline();
    } finally {
        this.BEogsh.pop(gl);
    }
}