PDA

View Full Version : camera work (serious)

vivek vyas
06-14-2009, 12:24 PM
i am working on a code to understand working of a camera in way that a first person shooter without weapon walks
i have programmed and at few point i got some headache points in my code
i am giving few parts of code if you need more then post me

1st:

void CameraMan()
{
///gluLookAt(x,y,z,Cx,Cy,Cz,0.0f,1.0f,0.0f);Cx <->x , Cy <-> y Cz <->z
//for circle there must radius let it 0.5f
Cx = sin(alpha*M_PI/180);
Cz = cos(beta*M_PI/180);
Cy = sin(alpha*M_PI/180)*sin(beta*M_PI/180);
gluLookAt(x,y,z,Cx+x,y + 0.1f,Cz+z,0,1,0);

}

2nd:yes depth double buffer turnned on

glMatrixMode(GL_PROJECTION);

CameraMan();
glPushMatrix();
glRotatef(90.0f,1.0f,0.0f,0.0f);
glColor3f(0.0f,1.0f,0.0f);

glRectf(2.0f,2.0f,-2.0f,-2.0f);

glPopMatrix();

glMatrixMode(GL_MODELVIEW);

3rd: i found perspective function related to frustum but fovy zNear and zFar are related to each other or not but what there value should be (i am weak in represntin 3d(specially position and angle))

void WinSize(int w,int h)
{
GLfloat As = (GLfloat)w/(GLfloat)h;
glMatrixMode(GL_PROJECTION);
gluPerspective(180.0f,As,-100.0f,100.0f);
glMatrixMode(GL_MODELVIEW);
glViewport(0,0,w,h);
}
4th: angle function controll

void Special(int k,int x,int y)
{
switch(k)
{
case GLUT_KEY_UP:
alpha+=0.1;
break;

case GLUT_KEY_DOWN:
alpha-=0.1;
break;

case GLUT_KEY_LEFT:
beta+=0.1;
break;

case GLUT_KEY_RIGHT:
beta-=0.1;
break;

}
}

and there keyboard function also
w-> incremental of z
a-> incremental of x
s-> -ve of w
d-> -ve of s
light and fog also for what is front and how much far

thanks to jan
Vivek

zeoverlord
06-14-2009, 05:31 PM
try gluPerspective(45.0f,As,0.1f,1000.0f);

vivek vyas
06-15-2009, 05:13 AM
i tried but it not work much
at some point i got polygon cutted when go farther or more above nearer
if do wrong in these sin cos function

Makinis
06-15-2009, 10:27 AM
try gluPerspective(45.0f,As,0.1f,1000.0f);

As I said before, I think I read somewhere that zNear value should be >=1... So:

gluPerspective(45.0f,As,1.0f,1000.0f);

And you should also try to keep the zFar value to minimum possible...

zeoverlord
06-23-2009, 06:17 PM
actually znear could be anything as long as it's positive, it's the ratio between znear and zfar you have to watch out for, 1:10000 is ok depending a little on what your doing, 1:1000 is recommended, though it won't really matter if you can't get something on the screen.