klampt.vis.glviewport module

class klampt.vis.glviewport.GLViewport[source]

Bases: object

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 yet.)

Type

bool

camera

an orbit camera controlling the target, zoom, and orientation of the “trackball” (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

contains(x, y)[source]
Return type

bool

set_transform(T, convention='standard')[source]

Sets the pose of the camera, with T given in world coordinates.

If convention = ‘openGL’, the Z axis of T is the backward direction of the camera, with Y pointing up and X pointing to the right.

If convention = ‘standard’, the Z axis of T is the forward direction of the camera, with Y pointing down and X pointing to the right

Return type

None

get_transform(convention='standard')[source]

Gets the pose of the camera, with T given in world coordinates.

If convention = ‘openGL’, the Z axis of T is the backward direction of the camera, with Y pointing up and X pointing to the right.

If convention = ‘standard’, the Z axis of T is the forward direction of the camera, with Y pointing down and X pointing to the right

Return type

Tuple[Sequence[float], Sequence[float]]

fit(center, radius)[source]

Fits the viewport to an object filling a sphere of a certain center and radius

Return type

None

to_viewport()[source]

Returns a Klampt C++ Viewport() instance corresponding to this view. This is used to interface with the Widget classes

Return type

Viewport

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)

Return type

Tuple[Sequence[float], Sequence[float]]

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.

Return type

Sequence[float]

set_current_GL()[source]

Sets up the view in the current OpenGL context

Return type

None

save_file(fn)[source]

Saves to a viewport txt file. The file format is compatible with the RobotTest, RobotPose, and SimTest apps.

Return type

None

load_file(fn)[source]

Loads from a viewport txt file. The file format is compatible with the RobotTest, RobotPose, and SimTest apps.

Return type

None

drawGL(draw_frustum=True, draw_coords=True)[source]

Draws an OpenGL widget illustrating the viewport.

Return type

None