Zoom a drawing

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

Use gluLookAt with an incrementation of position to zoomin and decrementation to zoomout.

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.

Dear Olivie and Vaticanfox
Regards!
kindly complete code for Zoomin and Zoomout.
as i am a begginner.

Thanks

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

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.

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. :wink: 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.

Dear All
Regards!
I am positng this reply as begginner and i came here through
“OpenGL coding: beginners”
if still i m n wrong place then kindly guide me that where begginner posting his problems

Dear Derbie

Regards
I want to zoom through GluLookat() function and yes one can zoom through FOV in GLPerspective but it will zoom all drawings and i want to zoom only one drawing.
and i think i can do through GluLookat(), but i can’t passing valid parameters, so i need help to zoom a drawing through GluLookAt(), function,

hope now u peopel understand what i want.
Thanks and Regards
David

gluLookAt should not be used to zoom as it will not perform a zoom it will move the viewpoint.

If you want to zoom the only thing you need to do is to change the last parameter in the gluPerspective command, this is the field of view and is true zooming.

If you increase the field of view you will see more and that means you will zoom out, lower field of view zooms in.

Mikael is of course correct.

If by zoom you mean simply “move closer” then you can do it with gluLookAt.

Now reading your followup it sounds like you want to zoom in on a particular object on the screen.

You can do this two ways.

  1. use gluLookat to center on the object’s position AND use the gluPerspective call to zoom in.

or

  1. use glFrustum instead of gluPerspective and locate the objects position in eye space (simple but may be tricky for a beginner) then use the asymmetric frustum definition available in glFrustum to define a zoom window around that object.

Method 1) is easier but 2) is more elegant and will zoom in on the object anywhere on screen without distorting the projection.

Method 2)of course is limited to stuff forward of the viewer (as defined by the eyespace axis orientation).