Mouse Over OpenGL Primitiv

21 views
Skip to first unread message

Silentpolygon

unread,
Dec 2, 2008, 12:10:52 PM12/2/08
to pyglet-users
Hi everybody

This is the code, that i have right now. Sorry for the german
comments, but I think it should be understandable code. It draws 2 Hex
Polys. Now i want know how does pyglet know if the Mouse cursoer is
over one of them. Searched in the OpenGL and PyGlet docs but I could
not find anything. A Hint would be much appreciated.

Thanks in advance
Thorsten

from pyglet.gl import *
window = pyglet.window.Window()

class my_hexagon():
def __init__(self, posX, posY):
glBegin(GL_TRIANGLE_FAN)
glVertex2f(posX, posY) # Mittelpunkt
glVertex2f(posX-50, posY-86.6) # Unten Links
glVertex2f(posX+50, posY-86.6) # Unten Rechts
glVertex2f(posX+100, posY) # Rechts
glVertex2f(posX+50, posY+86.6) # Oben Rechts
glVertex2f(posX-50, posY+86.6) # Oben Links
glVertex2f(posX-100, posY) # Links
glVertex2f(posX-50, posY-86.6) # Unten Links
glEnd()

@window.event
def on_draw():
glClear(GL_COLOR_BUFFER_BIT)
glLoadIdentity()
HexA = my_hexagon(400, 400)
HexB = my_hexagon(200, 200)

pyglet.app.run()

Drew Smathers

unread,
Dec 2, 2008, 12:43:24 PM12/2/08
to pyglet...@googlegroups.com
On Tue, Dec 2, 2008 at 12:10 PM, Silentpolygon <Thorste...@gmx.net> wrote:
>
> Hi everybody
>
> This is the code, that i have right now. Sorry for the german
> comments, but I think it should be understandable code. It draws 2 Hex
> Polys. Now i want know how does pyglet know if the Mouse cursoer is
> over one of them. Searched in the OpenGL and PyGlet docs but I could
> not find anything. A Hint would be much appreciated.

Neither OpenGL or Pyglet "knows" when the mouse is over a geometric
primitive. This is functionality you need to implement based on mouse
location (see pyglet docs) and testing whether the point is inside the
target shape. In 2d application this is simple for circles and
axis-aligned rectangles, but for arbitrary polygons, some more math is
needed.


>
> Thanks in advance
> Thorsten
>
> from pyglet.gl import *
> window = pyglet.window.Window()
>
> class my_hexagon():
> def __init__(self, posX, posY):
> glBegin(GL_TRIANGLE_FAN)
> glVertex2f(posX, posY) # Mittelpunkt
> glVertex2f(posX-50, posY-86.6) # Unten Links
> glVertex2f(posX+50, posY-86.6) # Unten Rechts
> glVertex2f(posX+100, posY) # Rechts
> glVertex2f(posX+50, posY+86.6) # Oben Rechts
> glVertex2f(posX-50, posY+86.6) # Oben Links
> glVertex2f(posX-100, posY) # Links
> glVertex2f(posX-50, posY-86.6) # Unten Links
> glEnd()
>
> @window.event
> def on_draw():
> glClear(GL_COLOR_BUFFER_BIT)
> glLoadIdentity()
> HexA = my_hexagon(400, 400)
> HexB = my_hexagon(200, 200)
>
> pyglet.app.run()
>
> >
>



--
\\\\\/\"/\\\\\\\\\\\
\\\\/ // //\/\\\\\\\
\\\/ \\// /\ \/\\\\
\\/ /\/ / /\/ /\ \\\
\/ / /\/ /\ /\\\ \\
/ /\\\ /\\\ \\\\\/\
\/\\\\\/\\\\\/\\\\\\
d.p.s

Jimmy...@gmail.com

unread,
Dec 4, 2008, 1:26:20 PM12/4/08
to pyglet-users
I started reading chapter 13 of the Red book http://glprogramming.com/red/chapter13.html

Being a noob, I'm not sure if this help or if pyglet has anything
predefined.

On Dec 2, 9:43 am, "Drew Smathers" <drew.smath...@gmail.com> wrote:

Silentpolygon

unread,
Dec 4, 2008, 5:31:03 PM12/4/08
to pyglet-users
Thank you. Yes I just started working through the Red Book. So it is
very helpful once I get into the architecture of OpenGL.
Thank you

Ben Smith

unread,
Dec 5, 2008, 12:18:50 AM12/5/08
to pyglet-users
You can use mouse picking to do this, google for opengl mouse picking
tutorial and you'll come up with a few different ways to do this,
based on 3d math or a way to do it by color.

-b
Reply all
Reply to author
Forward
0 new messages