Module Rasterizer

Module Rasterizer

Documentation for the Rasterizer module.

Example Uses an SCA_MouseSensor, and two KX_ObjectActuators to implement MouseLook:

       # To use a mouse movement sensor "Mouse" and a 
       # motion actuator to mouse look:
       import Rasterizer
       import GameLogic

       # SCALE sets the speed of motion
       SCALE=[1, 0.5]
       
       co = GameLogic.getCurrentController()
       obj = co.getOwner()
       mouse = co.getSensor("Mouse")
       lmotion = co.getActuator("LMove")
       wmotion = co.getActuator("WMove")
       
       # Transform the mouse coordinates to see how far the mouse has moved.
       def mousePos():
               x = (Rasterizer.getWindowWidth()/2 - mouse.getXPosition())*SCALE[0]
               y = (Rasterizer.getWindowHeight()/2 - mouse.getYPosition())*SCALE[1]
               return (x, y)
       
       pos = mousePos()
       
       # Set the amount of motion: X is applied in world coordinates...
       lmotion.setTorque(0.0, 0.0, pos[0], False)
       # ...Y is applied in local coordinates
       wmotion.setTorque(-pos[1], 0.0, 0.0, True)
       
       # Activate both actuators
       GameLogic.addActiveActuator(lmotion, True)
       GameLogic.addActiveActuator(wmotion, True)
       
       # Centre the mouse
       Rasterizer.setMousePosition(Rasterizer.getWindowWidth()/2, Rasterizer.getWindowHeight()/2)
Functions
list [x, y]
getScreenPosition(arg)
Gets the position of an object projected on screen space.
3d vector
getScreenVect(x, y)
Gets the vector from the camera position in the screen coordinate direction.
KX_GameObject
getScreenRay(x, y, dist, property)
Look towards a screen coordinate (x,y) and find first object hit within dist that matches prop.
integer
getWindowWidth()
Gets the width of the window (in pixels)
integer
getWindowHeight()
Gets the height of the window (in pixels)
 
makeScreenshot(filename)
Writes a screenshot to the given filename.
 
enableVisibility(visible)
Doesn't really do anything...
 
showMouse(visible)
Enables or disables the operating system mouse cursor.
 
setMousePosition(x, y)
Sets the mouse cursor position.
 
setBackgroundColor(rgba)
Sets the window background colour.
 
setMistColor(rgb)
Sets the mist colour.
 
setMistStart(start)
Sets the mist start value.
 
setMistEnd(end)
Sets the mist end value.
 
setEyeSeparation(eyesep)
Sets the eye separation for stereo mode.
float
getEyeSeparation()
Gets the current eye separation for stereo mode.
 
setFocalLength(focallength)
Sets the focal length for stereo mode.
float
getFocalLength()
Gets the current focal length for stereo mode.
 
setMaterialMode(mode)
Set the material mode to use for OpenGL rendering.
KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL
getMaterialMode(mode)
Get the material mode to use for OpenGL rendering.
 
setGLSLMaterialSetting(setting, enable)
Enables or disables a GLSL material setting.
boolean
getGLSLMaterialSetting(setting, enable)
Get the state of a GLSL material setting.
 
drawLine(fromVec, toVec, color)
Draw a line in the 3D scene.
Variables
  __package__ = None
    Material Types
  KX_BLENDER_GLSL_MATERIAL
Materials approximating blender materials with GLSL.
  KX_BLENDER_MULTITEX_MATERIAL
Materials approximating blender materials with multitexturing.
  KX_TEXFACE_MATERIAL
Materials as defined by the texture face settings.
Function Details

getScreenPosition(arg)

 

Gets the position of an object projected on screen space.

Example: # For an object in the middle of the screen, coord = [0.5,0.5] coord = Rasterizer.getScreenPosition(object)

Parameters:
Returns: list [x, y]
the object's position in screen coordinates.

getScreenVect(x, y)

 

Gets the vector from the camera position in the screen coordinate direction.

Example: # Gets the vector of the camera front direction: m_vect = Rasterizer.getScreenVect(0.5,0.5)

Parameters:
  • y (float)
  • x (float)
Returns: 3d vector
the vector from a screen coordinate.

getScreenRay(x, y, dist, property)

 

Look towards a screen coordinate (x,y) and find first object hit within dist that matches prop. The ray is similar to KX_GameObject->rayCastTo.

Example: # Gets an object with a property "wall" in front of the camera within a distance of 100: target = Rasterizer.getScreenRay(0.5,0.5,100,"wall")

Parameters:
  • dist (float) - max distance to look (can be negative => look behind); 0 or omitted => detect up to other
  • property (string) - property name that object must have; can be omitted => detect any object
  • y (float)
  • x (float)
Returns: KX_GameObject
the first object hit or None if no object or object does not match prop

makeScreenshot(filename)

 

Writes a screenshot to the given filename.

If filename starts with // the image will be saved relative to the current directory. If the filename contains # it will be replaced with the frame number.

The standalone player saves .png files. It does not support colour space conversion or gamma correction.

When run from Blender, makeScreenshot supports Iris, IrisZ, TGA, Raw TGA, PNG, HamX, and Jpeg. Gamma, Colourspace conversion and Jpeg compression are taken from the Render settings panels.

Parameters:
  • filename (string)

showMouse(visible)

 

Enables or disables the operating system mouse cursor.

Parameters:
  • visible (boolean)

setMousePosition(x, y)

 

Sets the mouse cursor position.

Parameters:
  • y (integer)
  • x (integer)

setBackgroundColor(rgba)

 

Sets the window background colour.

Parameters:
  • rgba (list [r, g, b, a])

setMistColor(rgb)

 

Sets the mist colour.

Parameters:
  • rgb (list [r, g, b])

setMistStart(start)

 

Sets the mist start value. Objects further away than start will have mist applied to them.

Parameters:
  • start (float)

setMistEnd(end)

 

Sets the mist end value. Objects further away from this will be coloured solid with the colour set by setMistColor().

Parameters:
  • end (float)

setEyeSeparation(eyesep)

 

Sets the eye separation for stereo mode.

Parameters:
  • eyesep (float) - The distance between the left and right eye.

setFocalLength(focallength)

 

Sets the focal length for stereo mode.

Parameters:
  • focallength (float) - The focal length.

setMaterialMode(mode)

 

Set the material mode to use for OpenGL rendering.

Parameters:
  • mode (KX_TEXFACE_MATERIAL, KX_BLENDER_MULTITEX_MATERIAL, KX_BLENDER_GLSL_MATERIAL)

Note: Changes will only affect newly created scenes.

setGLSLMaterialSetting(setting, enable)

 

Enables or disables a GLSL material setting.

Parameters:
  • enable (boolean)
  • setting (string (lights, shaders, shadows, ramps, nodes, extra_textures))

getGLSLMaterialSetting(setting, enable)

 

Get the state of a GLSL material setting.

Parameters:
  • setting (string (lights, shaders, shadows, ramps, nodes, extra_textures))
Returns: boolean

drawLine(fromVec, toVec, color)

 

Draw a line in the 3D scene.

Parameters:
  • fromVec (list [x, y, z]) - the origin of the line
  • toVec (list [x, y, z]) - the end of the line
  • color (list [r, g, b]) - the color of the line