klampt.vis.glprogram module¶
This module defines convenient classes for building 3D GUI programs.
- GLProgram takes care of basic user input.
- GLNavigationProgram allows 3D navigation with the mouse.
- GLRealtimeProgram calls a subclass-defined idle() function roughly on a constant time step.
Bases:
klampt.vis.glprogram.GLProgram
A more advanced form of GLProgram that allows you to navigate a camera around a 3D world. Click-drag rotates, Control-drag translates, Shift-drag zooms.
Returns a GLViewport describing the viewport, which could be saved to file.
Sets the viewport to a tuple previously returned by get_view(), e.g. a prior view that was saved to file.
-
class
klampt.vis.glprogram.
GLPluginProgram
(name='GLWidget')[source]¶ Bases:
klampt.vis.glprogram.GLRealtimeProgram
This base class should be used with a GLPluginBase object to handle the GUI functionality (see glcommon.py). Call setPlugin() on this object to set the currently used plugin. pushPlugin()/popPlugin() can also be used to set a hierarchy of plugins.
-
class
klampt.vis.glprogram.
GLProgram
(name='OpenGL Program')[source]¶ A basic OpenGL visualization, run as part of some _GLBackend. For the most part there is a one-to-one correspondence and the backend just relays the input / drawing messages
Assumes that glinit.py has been imported to define _GLBackend.
-
name
¶ title of the window (only has an effect before calling run())
Type: str
-
window
¶ the QtBackend or GLUTBackend instance
-
view
¶ describes the OpenGL viewport. If this is provided to an empty _GLBackend window, the w,h gives a hint to the size of the window. It is then updated by the user and setting the viewport size has no effect on the window.
Type: GLViewport
-
clearColor
¶ the RGBA floating point values of the background color.
Type: list of 4 floats
-
actions
¶ the list of actions. Must be populated using add_action before init().
Type: list of GLProgramAction
-
add_action
(hook, short_text, key, description=None)[source]¶ Defines a new generic GUI action. The action will be available in a menu in Qt or as keyboard commands in GLUT.
-
displayfunc
()[source]¶ All OpenGL calls go here. May be overridden, although you may wish to override display() and display_screen() instead.
-
idlefunc
()[source]¶ Called on idle. Default value stops all additional idle calls. Must be overridden if you want to do something in the idle loop.
-
idlesleep
(duration=inf)[source]¶ Sleeps the idle callback for t seconds. If t is not provided, the idle callback is slept forever
-
initialize
()[source]¶ Called after the GL context is initialized, but before main loop. May be overridden. Users should not call this directly!
-
keyboardfunc
(c, x, y)[source]¶ Called on keypress down. May be overridden. c is either the ASCII/unicode character of the key pressed or a string describing the character (up,down,left,right, home,end,delete,enter,f1,…,f12)
-
keyboardupfunc
(c, x, y)[source]¶ Called on keyboard up (if your system allows it). May be overridden.
-
modifiers
()[source]¶ Retrieves a list of currently pressed keyboard modifiers. Values can be any combination of ‘ctrl’, ‘shift’, ‘alt’.
-
-
class
klampt.vis.glprogram.
GLRealtimeProgram
(name)[source]¶ Bases:
klampt.vis.glprogram.GLNavigationProgram
A GLNavigationProgram that refreshes the screen at a given frame rate.
-
ttotal
¶ total elapsed time assuming a constant frame rate
Type: float
-
fps
¶ the frame rate in Hz
Type: float
-
dt
¶ 1.0/fps
Type: float
-
counter
¶ a frame counter
Type: int
-
lasttime
¶ time.time() value on the last frame.
Type: float
-
-
class
klampt.vis.glprogram.
GLViewport
[source]¶ A class describing an OpenGL camera view.
-
x,y
upper left hand corner of the view in the OpenGL canvas, in screen pixels
Type: int
-
w,h
width and height of the view, in screen pixels
Type: int
-
screenDeviceScale
¶ if not 1, multiply screen pixel coordinates by this to get openGL pixel coordinates (usually Mac Retina displays)
Type: float
-
orthogonal
¶ if true, does an orthogonal projection. (Not supported)
Type: bool
-
camera
¶ an orbit camera (see
orbit
)
-
fov
¶ the camera field of view in x direction, in degrees
Type: float
-
clippingplanes
¶ a pair containing the near and far clipping planes
Type: pair of floats
-
click_ray
(x, y)[source]¶ Returns a pair of 3-tuples indicating the ray source and direction in world coordinates for a screen-coordinate point (x,y)
-
fit
(center, radius)[source]¶ Fits the viewport to an object filling a sphere of a certain center and radius
-
project
(pt, clip=True)[source]¶ Given a point in world space, returns the (x,y,z) coordinates of the projected pixel. z is given in absolute coordinates, while x,y are given in pixel values.
If clip=True and the point is out of the viewing volume, then None is returned. Otherwise, if the point is exactly at the focal plane then the middle of the viewport is returned.
-