PDA

View Full Version : Rotate triangles and set the gluLookAt

alihuseyin
12-14-2015, 04:38 AM
I am new in this field and I've searched this subject on the internet. What I found is only about one triangle, but I created many triangles which are related with each others and I can't rotate it. Here is my code:

glPushMatrix();
glRotatef(angle, 0, 1, 0); ///

glColor3f(-1.0, -1.0, -1.0);
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
for (int i = 0; i < 17; i++)
{
for (int j = 0; j < 21; j++)
{
glBegin(GL_TRIANGLES);

glVertex3f(xT, mat[i][j], zT);
glVertex3f(xT + 20, mat[i+1][j], zT);
glVertex3f(xT, mat[i][j+1], zT + 20);

glVertex3f(xT, mat[i][j+1], zT + 20);
glVertex3f(xT + 20, mat[i+1][j], zT);
glVertex3f(xT + 20, mat[i+1][j+1], zT + 20);

glEnd();

zT += 20.0;

}

xT += 20.0;
zT = 0.0;
}
xT = 0.0;

glPopMatrix();
min xT = 0.0 and max xT = 320 and min zT = 0.0 and max zT = 420

It crates a mountainous field and I want to see all area. My questions are:

What should my gluLookAt function be like?
How can I rotate this area by its origin?

GClements
12-14-2015, 01:37 PM
What should my gluLookAt function be like?

If you want a view that's not horizontal, rotate about the X axis before rotating about the Y axis.

How can I rotate this area by its origin?

You are rotating it about its origin, which is one of its corners. If you want to rotate about the centre, call glTranslatef(-10,0,-10) after the rotations.

You may also need something like glTranslatef(0,0,-30) before the rotations so that the viewpoint isn't in the middle of the object.

mhagain
12-14-2015, 02:08 PM

alihuseyin
12-14-2015, 02:47 PM

too late dude and i am new here i dont know the delete the previous post, can you delete it for me ? Thanks.

Dark Photon
12-14-2015, 04:22 PM

alihuseyin
12-15-2015, 03:39 AM
If you want a view that's not horizontal, rotate about the X axis before rotating about the Y axis.

You are rotating it about its origin, which is one of its corners. If you want to rotate about the centre, call glTranslatef(-10,0,-10) after the rotations.

You may also need something like glTranslatef(0,0,-30) before the rotations so that the viewpoint isn't in the middle of the object.

Unluckily it did not work, I lose the view of this field when I adjust those parameters.

Carmine
12-18-2015, 03:07 PM
You don't need to use gluLookAt. Just position and scale your data so that they are in the default camera FOV. The default camera is located at the origin and is pointed in the -Z direction (i.e. into the screen). This is why GClements says to translate by -30 in Z. Here is a version of your code and the image it generates. I used random numbers for the y values of the vertices.

2203

2204