java - OpenGL JOGL camera perspective -


i have drawn 3 boxes each same size having different distance camera. these boxes ought perceived decreasing in size moving away camera. how acheive illusion of distance.

//these 3 planes boxes

  // first plane   gl.glvertex3i(0, 30, 30);   gl.glvertex3i(10, 30, 30);   gl.glvertex3i(10, 20, 30);   gl.glvertex3i(0, 20, 30);    //2nd plane   gl.glvertex3i(20, 20, 37);   gl.glvertex3i(30, 20, 37);   gl.glvertex3i(30, 10, 37);   gl.glvertex3i(20, 10, 37);    //3rd plane   gl.glvertex3i(40, 10, 45);   gl.glvertex3i(50, 10, 45);   gl.glvertex3i(50, 0, 45);   gl.glvertex3i(40, 0, 45); 

//and eye @ code.

gl.glmatrixmode(gl2.gl_modelview); gl.glloadidentity(); glu.glulookat(               35, 15,  10,                25, 15, 30,        0,  1,  0                  );  gl.glmatrixmode(gl2.gl_projection); gl.glloadidentity(); gl.glortho(-50.0, 50.0, -30.0, 30.0, 0.0, 60.0); 

you need use perspective projection, instead of orthographic projection.

instead of calling

gl.glortho(-50.0, 50.0, -30.0, 30.0, 0.0, 60.0); 

you should able replace line with

glu glu = new glu(); glu.gluperspective(60.0, 4.0/3.0, 1.0, 100.0); 

the arguments provided might not correct program, might need adjust them.

the arguments, in order, are: fovy, aspect, znear , zfar.

from manpage:

fovy: specifies field of view angle, in degrees, in y direction.

aspect: specifies aspect ratio determines field of view in x direction. aspect ratio ratio of x (width) y (height).

znear: specifies distance viewer near clipping plane (always positive).

zfar: specifies distance viewer far clipping plane (always positive).

the glu class located here

import javax.media.opengl.glu.glu 

Comments

Popular posts from this blog

My HTML document is not linking to my CSS stylesheet properly -

php array slice every 2th rule -

node.js - Sending sockets to client side, Error: Converting circular structure to JSON -