On Sun, Jul 22, 2012 at 1:12 PM, Derek S. <[email protected]> wrote:
> I have made a basic straightedge-and-compass geometry program.
> Point objects are represented by GL_POINTS
> Lines by GL_LINES
> Circles by GL_LINE_LOOP
>
> I've searched about how zooming and panning can be accomplished,
> and have found talk about glMatrixMode, glScale, glTranslate, glOrtho,
> etc...
>
> All of the examples / tutorials I've found deal with C++ and 3D,
> and none of them seem to actually setup a matrix,
> yet they all talk about how zooming/panning is accomplished by
> transforming a matrix..
>
> I have never studied matrices so I'm hoping to speed up the learning curve
> by seeing an example of:
>
> initial matrix
> [0][0][0][0]
> [0][0][0][0]
> [0][0][0][0]
> [0][0][0][0]
>
> zoom
>
> changed matrix
> [0][0][0][0]
> [0][0][0][0]
> [0][0][0][0]
> [0][0][0][0]
>
> I'm also wondering if numpy will be of benefit in this situation.
> I'm already using it for vectors.
>
> If you can provide an example that will help me figure this out
> I would be most grateful! At the very least I would appreciate
> a list of the functions you would recommend using for this.
>
> Thanks!
> (I'm using pyglet 1.1.4)


Here's the code I have in a 2d sidescroller prototype I have.  I know
why you are asking -- it took me awhile to work out how to do this.

Assuming that you have a window of width VIEWPORT_WIDTH and height
VIEWPORT_HEIGHT you can scroll the screen so the corner is at
(self.viewportx, self.viewporty) with the following code (this is a
function on a subclass of window)

def scroll(self):
    glViewport(0, 0, VIEWPORT_WIDTH, VIEWPORT_HEIGHT)
    glMatrixMode(gl.GL_PROJECTION)
    glLoadIdentity()
    glOrtho(self.viewportx, self.viewportx+VIEWPORT_WIDTH,
self.viewporty, self.viewporty+VIEWPORT_HEIGHT, -1, 1)
    glMatrixMode(gl.GL_MODELVIEW)

If anyone knows of an even better way to do that, I'm all ears.

~ Nathan

-- 
You received this message because you are subscribed to the Google Groups 
"pyglet-users" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/pyglet-users?hl=en.

Reply via email to