First problem is i want everything to be made of cubes so i made a class that makes cubes but i dont know how to implement that in my program.
i had makeCube cube[] = new makeCube[10]; for (int i=0;i<10;i++) { cube[i].draw(drawable,earthTex,X,Y,Z); } so basically i would put I into x y or z and draw 10 cubes in a row but im not sure thats the best way also when i tried to translate the cubes it would just move the camera for the camera i am using gl.glMatrixMode(GL2.GL_PROJECTION);//Stuff for camera gl.glLoadIdentity(); glu.gluPerspective(50.0, 1.0, 1.0, 50.0); gl.glMatrixMode(GL2.GL_MODELVIEW); gl.glLoadIdentity(); glu.gluLookAt(Xpos, 0.0, Zpos, Xpos, 0.0, 0.0, 0.0, 1.0, 0.0); and for drawing the cubes im using public void draw(GLAutoDrawable drawable,Texture tex,float X,float Y,float Z) { GL2 gl = drawable.getGL().getGL2(); gl.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); gl.glEnable(GL2.GL_TEXTURE_2D); tex.bind(); gl.glBegin(GL2.GL_QUADS); gl.glPushMatrix(); gl.glTranslatef(X,Y,Z); gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f); gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 1.0f); gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(1.0f, 1.0f, 1.0f); gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, 1.0f); // Back Face gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f); gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, -1.0f); gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(1.0f, 1.0f, -1.0f); gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, -1.0f); // Top Face gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, -1.0f); gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, 1.0f, 1.0f); gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(1.0f, 1.0f, 1.0f); gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(1.0f, 1.0f, -1.0f); // Bottom Face gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f); gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(1.0f, -1.0f, -1.0f); gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 1.0f); gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f); // Right face gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, -1.0f); gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(1.0f, 1.0f, -1.0f); gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(1.0f, 1.0f, 1.0f); gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(1.0f, -1.0f, 1.0f); // Left Face gl.glTexCoord2f(0.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, -1.0f); gl.glTexCoord2f(1.0f, 0.0f); gl.glVertex3f(-1.0f, -1.0f, 1.0f); gl.glTexCoord2f(1.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, 1.0f); gl.glTexCoord2f(0.0f, 1.0f); gl.glVertex3f(-1.0f, 1.0f, -1.0f); gl.glPopMatrix(); gl.glDisable(GL2.GL_TEXTURE_2D); gl.glEnd(); } Second problem is i want to somehow have first person shooter controls like the mouse is locked in the frame and the mouse does all the looking and i dont really know how to do that but i can probably google JOGL first person shooter |
Administrator
|
Hi!
Use glTranslate to "move" the cube and look at my source code for the first person shooter (it uses JOGL 1.1.1a but it is easy to port it to JOGL 2.0).
Julien Gouesse | Personal blog | Website
|
Im using glTranslate and it moves the camera and not the cube
in my code it looks like this gl.glTranslate(X,Y,Z); |
Also for the FPS controls im assuming you just lock the mouse inside the frame then when they move the mouse they just measure the distance from the center then reset the mouse back to the center. Problem is i dont know how to control the mouse like that
|
Administrator
|
Look at my source code, I have already solved such problems in at least 3 3D engines including mine. Look at the code that uses a MouseListener.
Julien Gouesse | Personal blog | Website
|
Yea i just looked at that code so im gonna try it out, thanks. Now onto the problem of how am i gonna draw as little or as many cubes as i want using a cube object
|
In reply to this post by Klinenator
Im having problems with glulookat() and glLoadIdentity()
if i want to draw a bunch of cubes i need to reload the identity in between otherwise if i want to use glTranslate it will just use the previous point as a reference instead of 0,0,0. But if i use glLoadIdentity i cant move the camera for some reason |
Administrator
|
If you use glLoadIdentity, you replace the current matrix by the identity matrix whereas this matrix may have been changed by gluLookAt.
Julien Gouesse | Personal blog | Website
|
Free forum by Nabble | Edit this page |