August'24: Kamaelia is in maintenance mode and will recieve periodic updates, about twice a year, primarily targeted around Python 3 and ecosystem compatibility. PRs are always welcome. Latest Release: 1.14.32 (2024/3/24)

Kamaelia.UI.OpenGL.PygameWrapper

Wrapper for pygame components

A wrapper for two dimensional pygame components that allows to display them on a Plane in 3D using OpenGL.

This component is a subclass of OpenGLComponent and therefore uses the OpenGL display service.

Example Usage

The following example shows a wrapped Ticker and MagnaDoodle component:

# override pygame display service
ogl_display = OpenGLDisplay.getDisplayService()
PygameDisplay.setDisplayService(ogl_display[0])

TICKER = Ticker(size = (150, 150)).activate()
TICKER_WRAPPER = PygameWrapper(wrap=TICKER, position=(4, 1,-10), rotation=(-20,15,3)).activate()
MAGNADOODLE = MagnaDoodle(size=(200,200)).activate()
MAGNADOODLEWRAPPER = PygameWrapper(wrap=MAGNADOODLE, position=(-2, -2,-10), rotation=(20,10,0)).activate()
READER = ConsoleReader().activate()

READER.link( (READER,"outbox"), (TICKER, "inbox") )

Axon.Scheduler.scheduler.run.runThreads()

How does it work?

This component is a subclass of OpenGLComponent. It overrides __init__(), setup(), draw(), handleEvents() and frame().

In setup() first the needed additional mailboxes are created. These are the "eventrequest" and "wrapcallback" inboxes and the "wrapped_events" outbox:

  • "eventrequest" is used for the reception of ADDLISTENEVENT and REMOVELISTENEVENT requests of the wrapped component.
  • "wrapcallback" is used to receive the response from the display service.
  • "wrapped_events" is where the input events get sent to.

Additionally, a WRAPPERREQUEST is sent to the OpenGL display service. It contains the objectid of the wrapped component as well as the comms for callback and eventrequests.

In frame(), it is waited for the response on the WRAPPERREQUEST. The response should contain the OpenGL texture name, the texture size and the size of the wrapped component. The wanted events are stored and the "wrapped_events" outbox is linked to the wrapped components "events" inbox. If the size of the wrapper is not set, it is calculated using the wrapped component pixel size multiplied by the pixelscaling factor.

To handle event requests by the wrapped component, the method handleEventRequests() gets called.

In handleEvents() received mouse events get translated into the 2d space of the wrapped component and sent to it if requested. This is done by using ray/polygon intersection to determine the point of intersection in 3d. The 2d coordinates are then calculated by using the dot product between the point of intersection relative to the top left corner and the edge vectors.

In draw() a cuboid gets drawn with the texture of the pygame component on its front plane. If the z component of the size is set to zero, only the front plane is drawn.


Kamaelia.UI.OpenGL.PygameWrapper.PygameWrapper

class PygameWrapper(OpenGLComponent)

PygameWrapper(...) -> A new PygameWrapper component.

A wrapper for two dimensional pygame components that allows to display them on a Plane in 3D using OpenGL.

Keyword arguments:

  • wrap -- Pygame component to wrap
  • pixelscaling -- Factor to convert pixels to units in 3d, ignored if size is specified (default=100)
  • sidecolour -- Colour of side and back planes (default=(200,200,244))
  • thickness -- Thickness of wrapper, ignored if size is specified (default=0.3)

Inboxes

Outboxes

Methods defined here

Warning!

You should be using the inbox/outbox interface, not these methods (except construction). This documentation is designed as a roadmap as to their functionalilty for maintainers and new component developers.

__init__(self, **argd)

x.__init__(...) initializes x; see x.__class__.__doc__ for signature

draw(self)

Draw cuboid.

frame(self)

handleEventRequests(self)

handleEvents(self)

setup(self)

Feedback

Got a problem with the documentation? Something unclear that could be clearer? Want to help improve it? Constructive criticism is very welcome - especially if you can suggest a better rewording!

Please leave you feedback here in reply to the documentation thread in the Kamaelia blog.

-- Automatic documentation generator, 05 Jun 2009 at 03:01:38 UTC/GMT