Pygame components on 3D planes
After resolving the size issue with pygame components (now a seperate surface with power-of-2 dimensions is stored for each component), I managed to get pygame components to display on 3D planes. This is done by PygameWrapperPlane components. One of them has to be created for each pygame component. It sends a WRAPPERREQUEST to Display3D which returns the needed data to draw the corresponding surface and then it is just displayed like in TexPlanes.
The tricky part was to get input events to the pygame component. While I could easily determine the point of intersection in 3D of the plane the surface was drawn on, it was not so easy to get the corresponding 2D coordinates of the surface. After a while I realised that these coords could be determined by calculating the dot product between the point of intersection and the edge vectors of the plane. This is true because the dot product is equal to the cosine of the angle between two vectors. The results then get scaled to the surface size and sent to the pygame component.
To distinguish between movement and pygame component interaction, a movementMode flag now gets inserted in events sent to 3D objects. It is true when the CTRL-key is pressed.
The appended picture shows the current example which is included in PygameWrapperPlane. To test the mapping I have created a simple pygame drawing board component which is called MagnaDoodle (bottom left). The example also shows two Ticker components, a Button and a SimpleCube.
The tricky part was to get input events to the pygame component. While I could easily determine the point of intersection in 3D of the plane the surface was drawn on, it was not so easy to get the corresponding 2D coordinates of the surface. After a while I realised that these coords could be determined by calculating the dot product between the point of intersection and the edge vectors of the plane. This is true because the dot product is equal to the cosine of the angle between two vectors. The results then get scaled to the surface size and sent to the pygame component.
To distinguish between movement and pygame component interaction, a movementMode flag now gets inserted in events sent to 3D objects. It is true when the CTRL-key is pressed.
The appended picture shows the current example which is included in PygameWrapperPlane. To test the mapping I have created a simple pygame drawing board component which is called MagnaDoodle (bottom left). The example also shows two Ticker components, a Button and a SimpleCube.

0 Comments:
Post a Comment
<< Home