PDA

View Full Version : Zoom a drawing



david123
06-21-2007, 09:11 PM
Dear all

I have drawn a line, triangle using opengl, now i want to Zoomin and zoomout what i drawn,
help needed while writing program for Zoomin and Zoomout.
Regards
david

Olivier B.
06-22-2007, 03:01 AM
Use gluLookAt with an incrementation of position to zoomin and decrementation to zoomout.

Vaticanfox
06-22-2007, 05:22 AM
If you're using a perspective projection matrix, you could always increase the FOV when you want to zoom out and decrease it when you want to zoom in.

david123
06-24-2007, 10:48 PM
Dear Olivie and Vaticanfox
Regards!
kindly complete code for Zoomin and Zoomout.
as i am a begginner.

Thanks

david123
06-25-2007, 11:21 PM
Dear all
Regards

following is my code for zooming a triangle, but it is not working , i think some problem in GLlookAt();

----------------CODE----------------------
protected override void OnSizeChanged(EventArgs e)
{


base.OnSizeChanged(e);
System.Drawing.Size s = Size;
width = (double)s.Width;
height = (double)s.Height;
GL.glViewport(0,0,s.Width,s.Height);
GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
GL.gluPerspective(60.0, (float)s.Width / (float)s.Height, 1.0, 50.0);
GL.glMatrixMode(GL.GL_MODELVIEW);
GL.glLoadIdentity();



}
public override void glDraw()
{

GL.glClear(GL.GL_COLOR_BUFFER_BIT | GL.GL_DEPTH_BUFFER_BIT); // Clear Screen And Depth Buffer
GL.glLoadIdentity(); // Reset The Current Modelview Matrix
GL.gluLookAt(0.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.0, 1.0, 0.0);
GL.glLoadIdentity();
GL.glTranslatef(-1.5f, 0.0f, -6.0f); // Move Left 1.5 Units And Into The Screen 6.0
GL.glBegin(GL.GL_TRIANGLES); // Drawing Using Triangles
GL.glVertex3f(0.0f, 1.0f, 0.0f); // Top
GL.glVertex3f(-1.0f, -1.0f, 0.0f); // Bottom Left
GL.glVertex3f(1.0f, -1.0f, 0.0f); // Bottom Right
GL.glEnd();


this.Refresh();
// GL.glFlush();
}
----------------------End----------------------------------------------------

kindly help me while zooming the above triangle.

waiting for your help

regards
david

dorbie
06-26-2007, 12:03 AM
You need to take this code:


GL.glMatrixMode(GL.GL_PROJECTION);
GL.glLoadIdentity();
GL.gluPerspective(60.0, (float)s.Width / (float)s.Height, 1.0, 50.0);
GL.glMatrixMode(GL.GL_MODELVIEW);Out of your window resize event handler leaving only the viewport change there, and move the projection update into the glDraw method, at the start before anything is drawn, (you can put it after the glClear call).

You will then be free to parameterize the 60.0 value, (the field of view) and decrease it to zoom in, or increase it to zoom out.

This will meet the technical definition of a 'zoom' I hope it is what you're looking for.

Please do not message the moderators for attention. Use that channel of communication to report abuse and other forum related issues.

dorbie
06-26-2007, 12:13 AM
P.S. please post to the beginners forum for similar questions, you will get a more enthusiastic response. By all means post more advanced stuff here. I know it is difficult to know where to post as a beginner, but your self professed beginner's status should be a big clue. ;-) Welcome to OpenGL.

I'm moving this thread to beginners incase you want to continue the discussion, there will be a link generated on this page to take you there, or you can go look in that forum yourself.