Hi. I use color-based picking in a module called nabla.geo, may be it
can give you some ideas.
You can download it here [1].
You should:
1.- Assign a different color to each "object" you want to detect.
2.- Render the masked scene in the back buffer and read the color,
so you get the object
3.- Now you can use all viewport/model matrices to get the x,y
coord in that
The worst problem is that you need to render all the scene masking all
the sprites, and to create a mask for a sprite is too slow. You can use
PIL, and generate a white mask for every sprite at startup, but anyway
you will have to paint it. The best way I found is to use a shader. I
use Tristam's GLSL wrapper [2] to do that. A long time ago, I was doing
this [3]
Some clues if you take a look: nabla.geo uses a Space(pyglet.Batch) to
draw a tree of Planes.
- GLSL program: nabla/geo/shader/GLSL_MASK_ALFA
- Space class: nabla/geo/space.py
- Plane class: nabla/geo/plane.py
- Transparency class: nabla/geo/plane/group.py
All starts in Space.on_mouse_press
1.- Plane.mask sets the color for Transparency.mask where the
shader is applied
2.- Space.selected_plane to get the picked Plane
3.- Space.unproject returns the x,y point in that Plane
[1] http://www.nabla.net/lab/nabla-test.zip
[2]
http://swiftcoder.wordpress.com/2008/12/19/simple-glsl-wrapper-for-pyglet/
[3]
http://groups.google.com/group/pyglet-users/browse_thread/thread/3bc01958a60c1b87/4868a655c173dd84?lnk=raot&pli=1
El 28/06/2011 18:53, greenmoss escribió:
Thanks; I understood that part. Currently I'm unable to figure out how
to do color-based picking though, so if there's a pyglet example
somewhere it would make me very happy :)
On Jun 28, 12:26 pm, Peter Enerccio<[email protected]> wrote:
It was more about transparency. The fourth byte of the point would be
the alpha, and if it is not 255, then you got a hit.
2011/6/28 greenmoss<[email protected]>:
Did you detect the squares using the coloring method?
On Jun 28, 10:04 am, Peter Enerccio<[email protected]> wrote:
How about using square detection, and then using finer detection with alpha?
sprite.get_image_data().get_data("RGBA", 4*width)
and then you check the A value of the target pixel where mouse is
I did the same with cocos and it worked well.
2011/6/28 greenmoss<[email protected]>:
I looked at the pyglet mouse picking example (http://sites.google.com/
site/swinesmallpygletexamples/mouse-picking), but I'm not sure it will
work for my game. Currently I have two kinds of objects to pick, with
maybe more to follow:
- GL_LINES; any coordinate along the line should be pickable
- pyglet sprites; ideally, any pixel that is part of the sprite's
image should be pickable, but easier/less-granular picks would also be
acceptable
The pyglet example seems to work based on rays to vertices only, so
would it work to pick the two types of objects above?
Maybe I need to be looking at color-based picking instead? For
example, this technique:
http://wiki.processing.org/w/Picking_with_a_color_buffer
Is there an example anywhere using color-based picking with pyglet?
Could it also easily be adapted to pyglet sprites?
--
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
athttp://groups.google.com/group/pyglet-users?hl=en.
--
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
athttp://groups.google.com/group/pyglet-users?hl=en.
--
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.