// Introduction
GEM, Graphics Environment for Multimedia is a Pd Library and comes ready to use as a part of Pd-extended. GEM makes it is possible to generate and manipulate 2D and 3D graphics and animations, process and modify media like images and videos and generate particles. GEM-patches are Pd patches. They use a special set of objects that are not native to Pd, but are provided by the GEM library.GEM objects are not standalone objects and you will have to use severl GEM-objects together to get your diesired result. You can use GEM to create and play back videos and still images, mix videos, draw shapes in 2D and 3D, move objects and shapes around. Because it is part of Pd, you can make your visuals react to sounds, generate them from sounds themselves.
You can look at GEM examples via the Pd Help Browser (in the Help menu, under Browser...), under examples/Gem or have a look at the GEM manual in manuals/GEM.
gemwin
The gemwin object is the one object that must be included in your patch to make GEM work. The gemwin object provides the window on which the computer draws your graphics. This object controls the timing of your graphics, by scheduling wheb frames should be drawn based on framerate. By default, it also clears the window every frame and ssets it to a background color.Messages to gemwin change the size of the window, start and stop the rendering process, alter the position from which you look at your 3D , and control various other aspects of the window, such as antialising.

To create the GEM-window, you have to send the create message to gemwin. To destroy the window you have to send the destroy message.To display something on the window you have to turn on rendering. This can be done by sending a 1 to gemwin.You can only turn rendering on when there is already a GEM window.
gemhead
While gemwin creates a window for rendering, gemhead connects a set of GEM objects to this rendering context. gemhead is the start of a chain of graphics operations connected by patch cords that should be executed every frame. Drawing operations, including video effects, cascade from the top down, adding to each other flow downwards across objects. This chain of operations is triggered invisibly by gemwin according to the framerate you have set. gemhead triggers an output, the Gem-list at your framerate. You can turn this automatic rendering off by sending gemhead the message 0. Additionally, gemhead can be triggered manually by a bang, which is useful when you want to control the order in which your graphics chains are drawn. With several gemheads, you can force this execution order by either giving them an argument or set their order number. Lower numbers are triggered first. The default ordering number is 50.
Drawing something
The most basic Gem-objects are called Geos, which are primitive shapes. They are drawables that tell the renderer to draw a certain shape. One example of a drawable is the square object:
The sqare has two inlets. the first is for the Gem-list. The second can be used to set parameters. Keep in mind though that the only parameter that can be set for the square is the length of its edge.
Exercise
- Open Pd
- Create a new patch and save it to a folder and square_with_options
- Create a create message with a second message of 1.This will create the window and start rendering:
- Next create a gemwin object and connect the inlet to the outlet of the create message

In order to open up a window for drawing, you have to create an object called gemwin which is the render context and you send it the messages create to create the window and 1 to start the rendering. - Add a destroy object and connect it to the gemwin object
- Create a gemhead object

- Connect a color object to the outlet of your gemhead object
- Connect a rotate object to the outlet of your color object
- Connect a square object to the outlet of your rotate object
- Connect two messages to the right inlet of your color object. One message should be one color and the other message should be white (1 1 1)
- Connect a number to the center inlet of your rotate object
- Connect two messages to the left inlet of your square object. One message should be the draw function with line as a parameter. The other message should be the draw function with fill as the parameter.
- Connect two more messages to the left inlet of your square object. One message should be the width a small number as a parameter (try 1.5). The other message should be width with a larger number as the parameter.
You can both rotate and translate shapes:


Exercise
Draw each of the other primitives shapes. Add rotateXYZ and translateXYZ- [rectangle a b]
- [triangle edge]
- [cube edge]
- [circle diameter slices]
- [disk outer-radius slices inner-radius]
- [cylinder diameter,height]
- [cone diameter,height]
- [sphere diameter]
Controlling color
There are Control-objects that allow Geos to be moved and colored. Generally these objects are called before Geos. Control objects tell the renderer to change the state of the object.You have to pass the color you want for painting as sets of RGB values each ranging between 0 and 1. If you don't specify any arguments, the default is white.To chnage the color during runtime, you have to send a list of values to the second inlet:
Moving around
The default position for Geos is the center of the screen. Each Geo has a pivot point. When the renderer is told to draw a Geo, it will place the pivot-point of the Geo on the origin of the 3D-world. The camera is aligned to focus on the world-origin of the 3D-space. You can move Geos with [translateXYZ X Y Z] and [translate factor vectorX vectorY vectorZ]You can also rotate a Geo around its pivot point.
| [rotateXYZ rotX rotY rotZ] | Rotates the Geo around the X-axis, then around the Y=axis and then around the Z-axis |
| [rotate amount vecX vecY vecZ] | Rotates the Geo by amount around the vector specified by the direction-vector vecX vecY vecZ |
The order of translating and rotating makes a difference. If you rotate first and translate after, you will end up with a GEO that rotates around the origin of the scene rather than around the pivot point

-
Translate before rotate=rotate around own axis (purple)
- Rotate before translate=rotate around origin (green)
You can put multiple GEOs in a gemlist. When doing transforations, each object that is below the transformation will be affected by it. Objects above the transformation will not.

Lower objects are considered to be parts of the higher objects. Think of it this way: your fingers are parts of your hand. If you move your hand, the fingers move too.
Sometimes you might want partly independent control over a Gem-object. If you modeled a human body and wanted to be able to turn the head and lift an arm independently, you could split the gemlist into independent sub-gemlists by using the separator object. Everything below the separator object is decoupled from other sub-gemlists under other seperator objects.
Adding Light
To see the sides of the objects, you need to add some light-sources.world_light is used as a far away light source. You can rotate the light source.For positioning a light source you can send a debug 1 message to the light source, which will display a small cone that represents the light source. Unfortunately, positioning the light source is not enough. You must explicitly turn on the source. This can be done by sending a lighting 1 or lighting 0 message to the gemwin.


Here's a sphere with a world_light and a light. Recreate this patch and play around with the settings:
Here's are patches that are animated:



Exercise
Build a solar system where your planets orbit at different speeds.Source:http://en.flossmanuals.net/PureData/












