Module KX_Camera :: Class KX_Camera
[frames | no frames]

Class KX_Camera

KX_GameObject --+
                |
               KX_Camera


A Camera object.
Method Summary
  boxInsideFrustum(box)
Tests the given box against the view frustum.
matrix (4x4 list) getCameraToWorld()
Returns the camera-to-world transform.
matrix (4x4 list) getProjectionMatrix()
Returns the camera's projection matrix.
matrix (4x4 list) getWorldToCamera()
Returns the world-to-camera transform.
boolean pointInsideFrustum(point)
Tests the given point against the view frustum.
  setProjectionMatrix(matrix)
Sets the camera's projection matrix.
  sphereInsideFrustum(centre, radius)
Tests the given sphere against the view frustum.
    Inherited from KX_GameObject
  applyImpulse(point, impulse)
Applies an impulse to the game object.
  disableRigidBody()
Disables rigid body physics for this object.
  enableRigidBody()
Enables rigid body physics for this object.
float getDistanceTo(other)
Returns the distance to another object or point.
list [vx, vy, vz] getLinearVelocity()
Gets the game object's linear velocity.
float getMass()
Gets the game object's mass.
KX_MeshProxy getMesh(mesh)
Gets the mesh object for this object.
3x3 rotation matrix getOrientation()
Gets the game object's orientation.
KX_GameObject getParent()
Gets this object's parent.
  getPhysicsId()
Returns the user data object associated with this game object's physics controller.
list [x, y, z] getPosition()
Gets the game object's position.
list [fx, fy, fz] getReactionForce()
Gets the game object's reaction force.
list [vx, vy, vz] getVelocity(point)
Gets the game object's velocity at the specified point.
  restoreDynamics()
Resumes physics for this object.
  setOrientation(orn)
Sets the game object's orientation.
  setPosition(pos)
Sets the game object's position.
  setVisible(visible)
Sets the game object's visible flag.
  suspendDynamics()
Suspends physics for this object.

Instance Variable Summary
4x4 Matrix [[float]] camera_to_world: This camera's camera to world transform.
float far: The camera's far clip distance.
boolean frustum_culling: True if this camera is frustum culling.
float lens: The camera's lens value.
4x4 Matrix [[float]] modelview_matrix: This camera's 4x4 model view matrix.
float near: The camera's near clip distance.
boolean perspective: True if this camera has a perspective transform.
4x4 Matrix [[float]] projection_matrix: This camera's 4x4 projection matrix.
4x4 Matrix [[float]] world_to_camera: This camera's world to camera transform.
    Constants
  INSIDE: see sphereInsideFrustum() and boxInsideFrustum()
  INTERSECT: see sphereInsideFrustum() and boxInsideFrustum()
  OUTSIDE: see sphereInsideFrustum() and boxInsideFrustum()
    Inherited from KX_GameObject
float mass: The object's mass (provided the object has a physics controller).
string. name: The object's name.
3x3 Matrix [[float]] orientation: The object's orientation.
KX_GameObject parent: The object's parent object.
list [x, y, z] position: The object's position.
list [sx, sy, sz] scaling: The object's scaling factor.
boolean visible: visibility flag.

Method Details

boxInsideFrustum(box)

Tests the given box against the view frustum.

Example:
       import GameLogic
       co = GameLogic.getCurrentController()
       cam = co.GetOwner()
       
       # Box to test...
       box = []
       box.append([-1.0, -1.0, -1.0])
       box.append([-1.0, -1.0,  1.0])
       box.append([-1.0,  1.0, -1.0])
       box.append([-1.0,  1.0,  1.0])
       box.append([ 1.0, -1.0, -1.0])
       box.append([ 1.0, -1.0,  1.0])
       box.append([ 1.0,  1.0, -1.0])
       box.append([ 1.0,  1.0,  1.0])
       
       if (cam.boxInsideFrustum(box) != cam.OUTSIDE):
               # Box is inside/intersects frustum !
               # Do something useful !
       else:
               # Box is outside the frustum !
Parameters:
box - Eight (8) corner points of the box (in world coordinates.)
           (type=list)
Returns:
INSIDE, OUTSIDE or INTERSECT

getCameraToWorld()

Returns the camera-to-world transform.
Returns:
the camera-to-world transform matrix.
           (type=matrix (4x4 list))

getProjectionMatrix()

Returns the camera's projection matrix.
Returns:
the camera's projection matrix.
           (type=matrix (4x4 list))

getWorldToCamera()

Returns the world-to-camera transform.

This returns the inverse matrix of getCameraToWorld().
Returns:
the world-to-camera transform matrix.
           (type=matrix (4x4 list))

pointInsideFrustum(point)

Tests the given point against the view frustum.

Example:
       import GameLogic
       co = GameLogic.getCurrentController()
       cam = co.GetOwner()

       # Test point [0.0, 0.0, 0.0]
       if (cam.pointInsideFrustum([0.0, 0.0, 0.0])):
               # Point is inside frustum !
               # Do something useful !
       else:
               # Box is outside the frustum !
Parameters:
point - The point to test (in world coordinates.)
           (type=[x, y, z])
Returns:
True if the given point is inside this camera's viewing frustum.
           (type=boolean)

setProjectionMatrix(matrix)

Sets the camera's projection matrix.

You should use normalised device coordinates for the clipping planes: left = -1.0, right = 1.0, top = 1.0, bottom = -1.0, near = cam.near, far = cam.far

Example:
       import GameLogic

       def Scale(matrix, size):
               for y in range(4):
                       for x in range(4):
                               matrix[y][x] = matrix[y][x] * size[y]
               return matrix
       
       # Generate a perspective projection matrix
       def Perspective(cam):
               return [[cam.near, 0.0     ,  0.0                                  ,  0.0                                      ],
                       [0.0     , cam.near,  0.0                                  ,  0.0                                      ],
                       [0.0     , 0.0     , -(cam.far+cam.near)/(cam.far-cam.near), -2.0*cam.far*cam.near/(cam.far - cam.near)],
                       [0.0     , 0.0     , -1.0                                  ,  0.0                                      ]]
       
       # Generate an orthographic projection matrix
       # You will need to scale the camera
       def Orthographic(cam):
               return [[1.0/cam.scaling[0], 0.0               ,  0.0                   ,  0.0                                  ],
                       [0.0               , 1.0/cam.scaling[1],  0.0                   ,  0.0                                  ],
                       [0.0               , 0.0               , -2.0/(cam.far-cam.near), -(cam.far+cam.near)/(cam.far-cam.near)],
                       [0.0               , 0.0               ,  0.0                   ,  1.0                                  ]]
       
       # Generate an isometric projection matrix
       def Isometric(cam):
               return Scale([[0.707, 0.0  , 0.707, 0.0],
                             [0.408, 0.816,-0.408, 0.0],
                             [0.0  , 0.0  , 0.0  , 0.0],
                             [0.0  , 0.0  , 0.0  , 1.0]],
                             [1.0/cam.scaling[0], 1.0/cam.scaling[1], 1.0/cam.scaling[2], 1.0])
       
       co = GameLogic.getCurrentController()
       cam = co.getOwner()
       cam.setProjectionMatrix(Perspective(cam)))
Parameters:
matrix - The new projection matrix for this camera.
           (type=4x4 matrix.)

sphereInsideFrustum(centre, radius)

Tests the given sphere against the view frustum.
Parameters:
centre - The centre of the sphere (in world coordinates.)
           (type=list [x, y, z])
radius - the radius of the sphere
           (type=float)
Returns:

INSIDE, OUTSIDE or INTERSECT

Example:
       import GameLogic
       co = GameLogic.getCurrentController()
       cam = co.GetOwner()
       
       # A sphere of radius 4.0 located at [x, y, z] = [1.0, 1.0, 1.0]
       if (cam.sphereInsideFrustum([1.0, 1.0, 1.0], 4) != cam.OUTSIDE):
               # Sphere is inside frustum !
               # Do something useful !
       else:
               # Sphere is outside frustum

Instance Variable Details

INSIDE

see sphereInsideFrustum() and boxInsideFrustum()

INTERSECT

see sphereInsideFrustum() and boxInsideFrustum()

OUTSIDE

see sphereInsideFrustum() and boxInsideFrustum()

camera_to_world

This camera's camera to world transform. (read only) Regenerated every frame from the camera's position and orientation.
Type:
4x4 Matrix [[float]]

far

The camera's far clip distance.
Type:
float

frustum_culling

True if this camera is frustum culling.
Type:
boolean

lens

The camera's lens value.
Type:
float

modelview_matrix

This camera's 4x4 model view matrix. (read only) Regenerated every frame from the camera's position and orientation.
Type:
4x4 Matrix [[float]]

near

The camera's near clip distance.
Type:
float

perspective

True if this camera has a perspective transform.

If perspective is False, this camera has an orthographic transform.

Note that the orthographic transform is faked by multiplying the lens attribute by 100.0 and translating the camera 100.0 along the z axis.

This is the same as Blender. If you want a true orthographic transform, see setProjectionMatrix.
Type:
boolean

projection_matrix

This camera's 4x4 projection matrix.
Type:
4x4 Matrix [[float]]

world_to_camera

This camera's world to camera transform. (read only) Regenerated every frame from the camera's position and orientation. This is camera_to_world inverted.
Type:
4x4 Matrix [[float]]

Generated by Epydoc 2.1 on Thu Feb 1 00:12:33 2007 http://epydoc.sf.net