Hello Guest

Moving Around

  • 1 Replies
  • 6913 Views
Moving Around
« on: May 03, 2005, 13:16:46 »
Ok, so ive got my room looking alrite. Here is the code:

Code: [Select]


public void render() {

        gl.glClear(GL11.GL_COLOR_BUFFER_BIT | GL11.GL_DEPTH_BUFFER_BIT);          // Clear The Screen And The Depth Buffer

gl.glLoadIdentity();

gl.glTranslatef(0.0f, 0.0f, 0.0f);

gl.glRotatef(rtri,0.0f,1.0f,0.0f);

//Build Room

gl.glBegin(gl.GL_QUADS);

gl.glNormal3f(0.0f, 0.0f, 1.0f);


gl.glColor3f(0.0f,1.0f,0.0f);

gl.glVertex3f(-2.0f, 2.0f, -8.0f); //Draw Back Wall - Top Left
gl.glVertex3f( 2.0f, 2.0f, -8.0f); //Draw Back Wall - Top Right
gl.glVertex3f( 2.0f, -2.0f, -8.0f); //Draw Back Wall - Bottom Right
gl.glVertex3f(-2.0f, -2.0f, -8.0f); //Draw Back Wall - Bottom Left



gl.glEnd();


gl.glBegin(gl.GL_QUADS);
gl.glNormal3f(1.0f, 0.0f, 0.0f);


gl.glColor3f(1.0f,0.0f,0.0f);

gl.glVertex3f( -2.0f, 2.0f, 2.0f); //Draw Left Wall - Top Left
gl.glVertex3f( -2.0f, 2.0f,-8.0f); //Draw Left Wall - Top Right

gl.glVertex3f( -2.0f, -2.0f,-8.0f); //Draw Left Wall - Bottom Right
gl.glVertex3f( -2.0f, -2.0f, 2.0f); //Draw Left Wall - Bottom Left



gl.glEnd();


gl.glBegin(gl.GL_QUADS);


gl.glNormal3f(-1.0f, 0.0f, 0.0f);

gl.glColor3f(0.0f,0.0f,1.0f);

gl.glVertex3f( 2.0f, 2.0f,-8.0f); //Draw Right Wall - Top Left
gl.glVertex3f( 2.0f, 2.0f, 2.0f); //Draw Right Wall - Top Right

gl.glVertex3f( 2.0f, -2.0f, 2.0f); //Draw Right Wall - Bottom Right
gl.glVertex3f( 2.0f, -2.0f,-8.0f); //Draw Right Wall - Bottom Left



gl.glEnd();

gl.glBegin(gl.GL_QUADS);


gl.glNormal3f(0.0f, 1.0f, 0.0f);

gl.glColor3f(1.0f,1.0f,1.0f);

gl.glVertex3f( -2.0f,-2.0f,-8.0f); //Draw Floor - Top Left
gl.glVertex3f(  2.0f,-2.0f,-8.0f); //Draw Floor - Top Right
gl.glVertex3f(  2.0f,-2.0f, 2.0f); //Draw Floor - Bottom Right
gl.glVertex3f( -2.0f,-2.0f, 2.0f); //Draw Floor - Bottom Left




gl.glEnd();


gl.glBegin(gl.GL_QUADS);


gl.glNormal3f(0.0f, 0.0f, 1.0f);


gl.glColor3f(0.0f,1.0f,1.0f);

gl.glVertex3f(-2.0f, 2.0f, 2.0f); //Draw Front Wall - Top Left
gl.glVertex3f( 2.0f, 2.0f, 2.0f); //Draw Front Wall - Top Right
gl.glVertex3f( 2.0f, -2.0f, 2.0f); //Draw Front Wall - Bottom Right
gl.glVertex3f(-2.0f, -2.0f, 2.0f); //Draw Front Wall - Bottom Left


gl.glEnd();


rtri += .06;





    }




So i start at the origin (gl.glTranslatef(0.0f, 0.0f, 0.0f);) drawing the back wall -8 on the z-axis, left and right walls from 2 to -8 on the z-axis and the front wall (behind where u face at the start) on the z-axis at 2.

My question is, how can i make it appear as if my player is moving towards the back wall? Ive played around with translate but no real luck, what exactly does translate do?

Any help would be great :)

Thanks,

Cheers, Nick

Moving Around
« Reply #1 on: May 10, 2005, 01:56:04 »
What you need to do is have the following:

1. A loop that renders this over and over again (think a while !done loop)
2. A way to increase the GL11.glTranslatef() values over time. Think another loop.