FIFE 2008.0
FIFE::Camera Class Reference

#include <camera.h>

Inheritance diagram for FIFE::Camera:
Collaboration diagram for FIFE::Camera:

List of all members.

Public Member Functions

 Camera (const std::string &id, Layer *layer, const Rect &viewport, RenderBackend *renderbackend, ImagePool *ipool, AnimationPool *apool)
virtual ~Camera ()
const std::string & getId () const
void setId (const std::string &id)
void setTilt (double tilt)
double getTilt () const
void setRotation (double rotation)
double getRotation () const
void setZoom (double zoom)
double getZoom () const
void setCellImageDimensions (unsigned int width, unsigned int height)
Point getCellImageDimensions ()
Point getCellImageDimensions (Layer *layer)
void setLocation (const Location &location)
Location getLocation () const
Location & getLocationRef ()
void attach (Instance *instance)
void detach ()
InstancegetAttached () const
void setViewPort (const Rect &viewport)
const RectgetViewPort () const
ExactModelCoordinate toMapCoordinates (ScreenPoint screen_coords, bool z_calculated=true)
ScreenPoint toScreenCoordinates (ExactModelCoordinate map_coords)
DoublePoint3D toVirtualScreenCoordinates (ExactModelCoordinate map_coords)
void setEnabled (bool enabled)
bool isEnabled ()
void getMatchingInstances (ScreenPoint screen_coords, Layer &layer, std::list< Instance * > &instances)
void getMatchingInstances (Rect screen_rect, Layer &layer, std::list< Instance * > &instances)
void getMatchingInstances (Location &loc, std::list< Instance * > &instances, bool use_exactcoordinates=false)
void update ()
void refresh ()
void resetUpdates ()
void addRenderer (RendererBase *renderer)
RendererBasegetRenderer (const std::string &name)
void resetRenderers ()
void calculateZValue (ScreenPoint &screen_coords)
void onRendererPipelinePositionChanged (RendererBase *renderer)
void onRendererEnabledChanged (RendererBase *renderer)
bool testRenderedViewPort ()
void render ()

Detailed Description

Camera describes properties of a view port shown in the main screen Main screen can have multiple cameras active simultanously Different cameras can have different properties, like location to shoot, zoom or tilt

Definition at line 58 of file camera.h.


Constructor & Destructor Documentation

FIFE::Camera::Camera ( const std::string &  id,
Layer layer,
const Rect viewport,
RenderBackend renderbackend,
ImagePool ipool,
AnimationPool apool 
)

Constructor Camera needs to be added to the view. If not done so, it is not rendered.

Parameters:
ididentifier for the camera
layerlayer where camera is bound. Camera is bound to a layer for two reasons: * camera's scaling is done based on cell image dimensions. Cell image is layer based (
See also:
setCellImageDimensions) * camera could be bound to a pather, which operates on layer
Parameters:
viewportused viewport for the camera. Viewport is measured in pixels in relation to game main screen
emccoordinate, where camera is focused on given layer
renderbackendto use with rendering
ipoolto use with rendering
apoolto use with rendering

Definition at line 79 of file camera.cpp.

References FIFE::RenderBackend::getName(), and setLocation().

FIFE::Camera::~Camera ( ) [virtual]

Destructor

Definition at line 125 of file camera.cpp.


Member Function Documentation

void FIFE::Camera::addRenderer ( RendererBase renderer)

Adds new renderer on the view. Ownership is transferred to the camera.

Definition at line 584 of file camera.cpp.

References FIFE::RendererBase::getName(), FIFE::RendererBase::isEnabled(), and FIFE::RendererBase::setRendererListener().

Referenced by FIFE::Map::addCamera().

Here is the caller graph for this function:

void FIFE::Camera::attach ( Instance instance)

Attaches the camera to an instance.

Parameters:
instanceInstance to which the camera shall be attached
Note:
The camera can only be attached to an instance at the same layer!

Definition at line 547 of file camera.cpp.

References FIFE::Instance::getLocation().

void FIFE::Camera::calculateZValue ( ScreenPoint screen_coords)

calculates z-value for given screenpoint

Definition at line 329 of file camera.cpp.

References toScreenCoordinates().

Referenced by toMapCoordinates().

Here is the caller graph for this function:

void FIFE::Camera::detach ( )

Detaches the camera from an instance.

Definition at line 556 of file camera.cpp.

Instance* FIFE::Camera::getAttached ( ) const [inline]

Returns instance where camera is attached. NULL if not attached

Definition at line 178 of file camera.h.

Point FIFE::Camera::getCellImageDimensions ( Layer layer)

Gets screen cell image dimensions for given layer.

Returns:
Point Point containing x=width and y=height

Definition at line 241 of file camera.cpp.

References FIFE::Layer::getCellGrid().

Point FIFE::Camera::getCellImageDimensions ( )

Gets screen cell image dimensions.

See also:
setCellImageDimensions
Returns:
Point containing x=width and y=height

Definition at line 237 of file camera.cpp.

const std::string& FIFE::Camera::getId ( ) const [inline]

Gets the identifier for this camera.

Definition at line 90 of file camera.h.

Location FIFE::Camera::getLocation ( ) const

Gets the location camera is rendering

Returns:
camera location

Definition at line 259 of file camera.cpp.

Location & FIFE::Camera::getLocationRef ( )

Gets a reference to the camera location

Note:
if you change returned location without calling Camera::setLocation(...), remember to call Camera::refresh() (otherwise camera transforms are not updated)
Returns:
reference to the camera location

Definition at line 263 of file camera.cpp.

void FIFE::Camera::getMatchingInstances ( ScreenPoint  screen_coords,
Layer layer,
std::list< Instance * > &  instances 
)

Returns instances that match given screen coordinate

Parameters:
screen_coordsscreen coordinates to be used for hit search
layerlayer to use for search
instanceslist of instances that is filled based on hit test results

Definition at line 456 of file camera.cpp.

void FIFE::Camera::getMatchingInstances ( Rect  screen_rect,
Layer layer,
std::list< Instance * > &  instances 
)

Returns instances that match given screen coordinate

Parameters:
screen_point1top left screen coordinates to be used for hit search
screen_point2right bottom screen coordinates to be used for hit search
layerlayer to use for search
instanceslist of instances that is filled based on hit test results

Definition at line 488 of file camera.cpp.

References FIFE::RectType< T >::h, FIFE::RectType< T >::w, FIFE::RectType< T >::x, and FIFE::RectType< T >::y.

void FIFE::Camera::getMatchingInstances ( Location &  loc,
std::list< Instance * > &  instances,
bool  use_exactcoordinates = false 
)

Returns instances that match given location. Instances are sorted based on camera view, so that "topmost" instance is first in returned list

Parameters:
loclocation where to fetch instances from
instanceslist of instances that is filled based on hit test results
use_exactcoordinatesif true, comparison is done using exact coordinates. if not, cell coordinates are used

Definition at line 528 of file camera.cpp.

References FIFE::Instance::getLocationRef().

RendererBase * FIFE::Camera::getRenderer ( const std::string &  name) [virtual]

Gets renderer with given name

Implements FIFE::IRendererContainer.

Definition at line 608 of file camera.cpp.

double FIFE::Camera::getRotation ( ) const

Gets camera rotation

Returns:
rotation of the camera

Definition at line 159 of file camera.cpp.

double FIFE::Camera::getTilt ( ) const

Gets camera tilt

Returns:
tilt of camera

Definition at line 146 of file camera.cpp.

const Rect & FIFE::Camera::getViewPort ( ) const

Gets the viewport for camera

Returns:
camera viewport

Definition at line 271 of file camera.cpp.

Referenced by render().

Here is the caller graph for this function:

double FIFE::Camera::getZoom ( ) const

Gets camera zoom

Returns:
zoom of the camera

Definition at line 173 of file camera.cpp.

bool FIFE::Camera::isEnabled ( )

Gets if camera is enabled / disabled

Definition at line 279 of file camera.cpp.

void FIFE::Camera::onRendererEnabledChanged ( RendererBase renderer) [virtual]

Renderer is enabled / disabled

Implements FIFE::IRendererListener.

Definition at line 597 of file camera.cpp.

References FIFE::RendererBase::getName(), and FIFE::RendererBase::isEnabled().

void FIFE::Camera::onRendererPipelinePositionChanged ( RendererBase renderer) [virtual]

Renderer's pipeline position has been changed

Implements FIFE::IRendererListener.

Definition at line 593 of file camera.cpp.

void FIFE::Camera::refresh ( )

Refreshes camera view in case e.g. location is updated directly (not via setLocation)

Note:
calling this function marks camera as "warped", therefore it causes all instance positions to be recalculated. If you constantly call this, you end up with pixel wobbling effect when camera is moved.

Definition at line 570 of file camera.cpp.

void FIFE::Camera::resetRenderers ( )

resets active layer information on all renderers.

Definition at line 612 of file camera.cpp.

void FIFE::Camera::resetUpdates ( )

Resets temporary values from last update round, like warped flag

Definition at line 575 of file camera.cpp.

Referenced by render().

Here is the caller graph for this function:

void FIFE::Camera::setCellImageDimensions ( unsigned int  width,
unsigned int  height 
)

Sets screen cell image dimensions. Cell image dimension is basically width and height of a bitmap, that covers one cell in the layer where camera is bind

Returns:
Point Point containing x=width and y=height

Definition at line 177 of file camera.cpp.

void FIFE::Camera::setEnabled ( bool  enabled)

Sets camera enabled / disabled

Definition at line 275 of file camera.cpp.

void FIFE::Camera::setId ( const std::string &  id) [inline]

Sets the identifier for this camera.

Definition at line 94 of file camera.h.

void FIFE::Camera::setLocation ( const Location &  location)

Sets the location for camera

Parameters:
locationlocation (center point) to render

Definition at line 185 of file camera.cpp.

References toScreenCoordinates().

Referenced by Camera(), and update().

Here is the caller graph for this function:

void FIFE::Camera::setRotation ( double  rotation)

Sets rotation for the camera. Rotation can be visualized by thinking camera that rotates around an object that it is rendering

Parameters:
rotationrotation for the camera

Definition at line 150 of file camera.cpp.

void FIFE::Camera::setTilt ( double  tilt)

Sets tilt for the camera. e.g. overhead camera has tilt 0, while traditional isometric camera has tilt 45

Parameters:
tilttilt for the camera

Definition at line 137 of file camera.cpp.

void FIFE::Camera::setViewPort ( const Rect viewport)

Sets the viewport for camera viewport is rectangle inside the view where camera renders

Parameters:
viewportarea for camera render

Definition at line 267 of file camera.cpp.

void FIFE::Camera::setZoom ( double  zoom)

Sets zoom for the camera.

Parameters:
zoomzoom for the camera

Definition at line 163 of file camera.cpp.

bool FIFE::Camera::testRenderedViewPort ( )

Use with OpenGL only! Checks to see if the entire viewport was rendered last frame. If so it wont clear the backbuffer.

Definition at line 406 of file camera.cpp.

References FIFE::Map::getLayers(), FIFE::RectType< T >::h, FIFE::RectType< T >::w, FIFE::RectType< T >::x, and FIFE::RectType< T >::y.

Referenced by render().

Here is the caller graph for this function:

ExactModelCoordinate FIFE::Camera::toMapCoordinates ( ScreenPoint  screen_coords,
bool  z_calculated = true 
)

Transforms given point from screen coordinates to map coordinates

Parameters:
screen_coordsscreen coordinates to transform
z_calculatedif true, z-value (depth cut point) is pre-calculated. If false, camera calculates it
Returns:
point in map coordinates

Definition at line 334 of file camera.cpp.

References calculateZValue(), and FIFE::intPt2doublePt().

ScreenPoint FIFE::Camera::toScreenCoordinates ( ExactModelCoordinate  map_coords)

Transforms given point from map coordinates to screen coordinates

Returns:
point in screen coordinates

Definition at line 341 of file camera.cpp.

References FIFE::doublePt2intPt().

Referenced by calculateZValue(), FIFE::CellSelectionRenderer::render(), and setLocation().

Here is the caller graph for this function:

DoublePoint3D FIFE::Camera::toVirtualScreenCoordinates ( ExactModelCoordinate  map_coords)

Transforms given point from map coordinates to virtual screen coordinates

Returns:
point in screen coordinates

Definition at line 347 of file camera.cpp.

void FIFE::Camera::update ( )

General update routine. In this function, the camera's position gets updated when its attached to another instance.

Note:
call this only once in engine update cycle, so that tracking between current position and previous position keeps in sync. This information is used e.g. by view to fix the pixel wobbling problem

Definition at line 560 of file camera.cpp.

References FIFE::Instance::getLocationRef(), and setLocation().


The documentation for this class was generated from the following files:
 All Classes Namespaces Functions Variables Enumerations Enumerator