1

I have an OpenGL .NET WPF (SharpGL) app which draws small squares in immediate mode, they are really 3D:

float z = -200f;
float farz = 400f;
...

// init
gl.ShadeModel(OpenGL.GL_SMOOTH);
gl.ClearColor(0.0f, 0.0f, 0.0f, 0.0f);
gl.ClearDepth(1.0f);
gl.Disable(OpenGL.GL_DEPTH_TEST);
gl.Enable(OpenGL.GL_BLEND);
gl.BlendFunc(OpenGL.GL_SRC_ALPHA, OpenGL.GL_ONE);
gl.Hint(OpenGL.GL_PERSPECTIVE_CORRECTION_HINT, OpenGL.GL_NICEST);
gl.Hint(OpenGL.GL_POINT_SMOOTH_HINT, OpenGL.GL_NICEST);

// resize
gl.MatrixMode(OpenGL.GL_PROJECTION);
gl.LoadIdentity();
gl.Perspective(45.0, ratio, 0.1, farz);
gl.MatrixMode(OpenGL.GL_MODELVIEW);
gl.LoadIdentity();

// draw
gl.Begin(OpenGL.GL_TRIANGLE_STRIP);
gl.TexCoord(1, 1); gl.Vertex(x + 0.5f, y + 0.5f, z);
gl.TexCoord(0, 1); gl.Vertex(x - 0.5f, y + 0.5f, z);
gl.TexCoord(1, 0); gl.Vertex(x + 0.5f, y - 0.5f, z);
gl.TexCoord(0, 0); gl.Vertex(x - 0.5f, y - 0.5f, z);
gl.End();

I have buttons to "zoom" and "pan".

Zoom is currently alters z by +/- 10 between 0 and -400 which is good enough.

I tried to implement pan by using LookAt but I cant make it work. I did put it in resize method - is this the right place for it?

Is it possible to have a single line code to move the eye by +/- 5 left/right/up/down without enduring a matrix theory lesson? Id appreciate it.

Rabbid76
  • 202,892
  • 27
  • 131
  • 174
Boppity Bop
  • 9,613
  • 13
  • 72
  • 151
  • 1
    e.g.: `gl.Translate(-5, 0, 0);` – Rabbid76 Apr 08 '21 at 14:05
  • 1
    haha genius! thank you. please put it as an answer (for future dummies like me). cheers - i spent hour yesterday trying to get through all the "explanations" on the google which are largely copy/pastes of same text.. – Boppity Bop Apr 08 '21 at 14:09

1 Answers1

1

Use gl.Translate to translate the model view matrix. e.g:

gl.MatrixMode(OpenGL.GL_MODELVIEW);
gl.LoadIdentity();
gl.Translate(-5, 0, 0)
Rabbid76
  • 202,892
  • 27
  • 131
  • 174