hermes
Class HCamera

java.lang.Object
  extended by hermes.HObject
      extended by hermes.Being
          extended by hermes.HCamera
All Implemented Interfaces:
KeySubscriber, MouseSubscriber, MouseWheelSubscriber, OscSubscriber

public class HCamera
extends Being

HCamera determines which Beings get drawn. You can think of it as a window into the World, and any Beings that are inside of its bounding box will have their draw() methods called automatically.

The World class needs to be passed an HCamera when constructed. Any Being(s) registered with that World will automatically get drawn if they are spatially within that HCamera's bounding box.

An HCamera's bounding box is determined at construction - by default, it uses the pixel width and height of the PApplet that was passed to Hermes. Alternatively, HCamera has an alternate constructor that allows you to set your own custom screen to world coordinate ratio. If you wish to use a coordinate system other than pixels coordinates, simply set the width and height of the camera to the area of the world you want the camera to see at a time.

HCamera extends Being, which allows it to move around and interact with other entities in the game. This opens interesting possibilities, such as having a camera follow a character, having the camera move based on game events or other logic, etc.


Field Summary
 
Fields inherited from class hermes.Being
_position, _shape, _time, _velocity
 
Constructor Summary
HCamera()
          Default HCamera constructor.
HCamera(float x, float y, float cameraWidth, float cameraHeight)
          Constructs an HCamera with a custom coordinate unit size.
 
Method Summary
 void addBeing(Being being)
          adds a Being to _beings.
 void collisionsComplete()
          This method is a callback, letting the Camera know that the _beingsPending list has been completed for this timestep, and that it can switch to make it the actively drawn list of Beings on the next call to draw()
 void collisionsReset()
          Resets internal state parameters, effectively clearing the cache of collided Beings from the last time step
 void draw()
          This method gets called by Processing's draw thread.
 float getScreenToWorldRatioX()
           
 float getScreenToWorldRatioY()
           
 float getWorldCoordinateHeight()
           
 float getWorldCoordinateWidth()
           
 void setWorldCoordinateHeight(float worldCoordinateHeight)
           
 void setWorldCoordinateWidth(float worldCoordinateWidth)
           
 void zoomWithScreenCoordinates(float zoomFactor, float screenZoomCenterX, float screenZoomCenterY)
           
 void zoomWithWorldCoordinates(float zoomFactor, float worldZoomCenterX, float worldZoomCenterY)
           
 
Methods inherited from class hermes.Being
EulerIntegratePosition, getBoundingBox, getPosition, getShape, getVelocity, getVelocityX, getVelocityY, getX, getY, needsMoreSamples, processUpdate, setDone, setPosition, setPosition, setPosition, setVelocity, setVelocityX, setVelocityY, setX, setY, step, toString, update, updateTime
 
Methods inherited from class hermes.HObject
addToGroup, delete, getGroups, receive, receive, receive, receive, removeFromGroup
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

HCamera

public HCamera()
Default HCamera constructor. Passing no arguments gives HCamera a 1-to-1 world pixel ratio (the world coordinate units are the same size as the screen's pixel coordinates)


HCamera

public HCamera(float x,
               float y,
               float cameraWidth,
               float cameraHeight)
Constructs an HCamera with a custom coordinate unit size.

Parameters:
x - the starting x coordinate of the camera
y - the starting y coordinate of the camera
cameraWidth - the width of the camera view, in world coordinate units. This determines how far the camera can see in the x direction.
cameraHeight - the height of the camera view. This determines how far the camera can see in the y direction.
Method Detail

getWorldCoordinateWidth

public float getWorldCoordinateWidth()

setWorldCoordinateWidth

public void setWorldCoordinateWidth(float worldCoordinateWidth)

getWorldCoordinateHeight

public float getWorldCoordinateHeight()

setWorldCoordinateHeight

public void setWorldCoordinateHeight(float worldCoordinateHeight)

getScreenToWorldRatioX

public float getScreenToWorldRatioX()

getScreenToWorldRatioY

public float getScreenToWorldRatioY()

collisionsReset

public void collisionsReset()
Resets internal state parameters, effectively clearing the cache of collided Beings from the last time step


collisionsComplete

public void collisionsComplete()
This method is a callback, letting the Camera know that the _beingsPending list has been completed for this timestep, and that it can switch to make it the actively drawn list of Beings on the next call to draw()


addBeing

public void addBeing(Being being)
adds a Being to _beings. Every item in the list gets drawn.

Parameters:
being -

zoomWithWorldCoordinates

public void zoomWithWorldCoordinates(float zoomFactor,
                                     float worldZoomCenterX,
                                     float worldZoomCenterY)
Parameters:
zoomFactor -
worldZoomCenterX -
worldZoomCenterY -

zoomWithScreenCoordinates

public void zoomWithScreenCoordinates(float zoomFactor,
                                      float screenZoomCenterX,
                                      float screenZoomCenterY)

draw

public void draw()
This method gets called by Processing's draw thread. It handles drawing all of the Beings that are colliding with the camera. It translates to each Being's position on screen and draws the Being there.

Overrides:
draw in class Being