Hi everyone,
I’m doing a game for a project with university. After I loaded a blender model with “Assimp” I’m trying to move the object on the “x” axes but after a while the object goes out of the view.
I would like to find a way to know which “x” correspond to the left and right limit of the screen, in order to constrain the object to stay in the boundary of the viewport. Do you know how can I find these values?
To make things more clear there is the code that I use to move the object
void keyboard(unsigned char key, int x, int y)
{
switch (key) {
case 27:
exit(1);
break;
case 'a':
if(x_cord >-1.36)
x_cord -= 0.1;
glutPostRedisplay();
break;
case 'd':
if (x_cord < scene_max.x)
x_cord += 0.1;
glutPostRedisplay();
break;
default:
break;
}
}
and here there is the display function that calls keyboard:
void display(void)
{
float tmp;
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
gluLookAt(0.f, 0.f, 3.f, 0.f, 0.f, -5.f, 0.f, 1.f, 0.f);
// rotate it around the x axis
glRotatef(angle, 1.f, 0.f, 0.f);
glTranslatef(x_cord, y_cord, z_cord);
// scale the whole asset to fit into our view frustum
tmp = scene_max.x - scene_min.x;
tmp = aisgl_max(scene_max.y - scene_min.y, tmp);
tmp = aisgl_max(scene_max.z - scene_min.z, tmp);
tmp = 1.f / tmp;
glScalef(tmp, tmp, tmp);
// center the model
glTranslatef(-scene_center.x, -scene_center.y, -scene_center.z);
// if the display list has not been made yet, create a new one and
// fill it with scene contents
if (scene_list == 0) {
scene_list = glGenLists(1);
glNewList(scene_list, GL_COMPILE);
// now begin at the root node of the imported data and traverse
// the scenegraph by multiplying subsequent local transforms
// together on GL's matrix stack.
recursive_render(scene, scene->mRootNode, 1.0);
glEndList();
}
glCallList(scene_list);
glutSwapBuffers();
//do_motion();
}
and this is the reshape function:
void reshape(int width, int height)
{
W = width;
const double aspectRatio = (float)width / height, fieldOfView = 45.0;
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
gluPerspective(fieldOfView, aspectRatio,
1.0, 1000.0); // Znear and Zfar
glViewport(0, 0, width, height);
}
thanks in advance