Class Camera



  • public class Camera
    extends java.lang.Object
    Creates a virtual camera wich displays the game world on the viewport. A camera can be locked to an entity with setFocusEntity(AbstractEntity).
    • Constructor Summary

      Constructors 
      Constructor Description
      Camera​(GameView view)
      Creates a fullscale camera pointing at the middle of the map.
      Camera​(GameView view, int x, int y, int width, int height)
      Creates a camera pointing at the middle of the map.
      Camera​(GameView view, int x, int y, int width, int height, AbstractEntity focusentity)
      Creates a camera focusing an entity.
      Camera​(GameView view, int x, int y, int width, int height, Point center)
      Create a camera focusin a specific coordinate.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void endMultiRendering​()
      Stop the multipass rendering.
      Point getCenter​()
      Returns the focuspoint.
      int getCenterChunkX​()  
      int getCenterChunkY​()  
      GameView getGameView​()  
      int getHeightScreenSpc​()
      Returns the height of the camera output.
      int getId​()  
      float getProjScaling​()
      Returns a scaling factor calculated by the width to achieve the same viewport size with every resolution.
      int getScreenPosX​()
      Returns the position of the cameras output (on the screen)
      int getScreenPosY​()
      Returns the position of the camera (on the screen)
      float getViewSpaceX​()
      The Camera Position in the game world.
      float getViewSpaceY​()
      The Camera's center position in the game world. viewMat space. yIndex up
      int getVisibleBackBorder​()
      Returns the top seight border of the camera covered groundBlock
      int getVisibleFrontBorderHigh​()
      Returns the bottom seight border y-coordinate of the frontmost cells which could be visible.
      int getVisibleFrontBorderLow​()
      Returns the bottom seight border y-coordinate of the lowest cell
      int getVisibleLeftBorder​()
      Returns the left border of the actual visible area.
      float getVisibleLeftBorderVS​()
      Returns the left border of the actual visible area.
      int getVisibleRightBorder​()
      Returns the right seight border of the camera covered area currently visible.
      float getVisibleRightBorderVS​()
      Returns the right seight border of the camera covered area currently visible.
      int getWidthScreenSpc​()
      Returns the width of the camera output.
      int getWorldHeightViewport​()
      The amount of game pixel which are visible in Y direction after the zoom has been applied.
      int getWorldWidthViewport​()
      The amount of game pixels which are visible in X direction after the zoom has been applied.
      float getZoom​()
      Returns the zoomfactor.
      void initSorter​()  
      boolean inViewFrustum​(Position pos)
      checks if the projected position is inside the viewMat Frustum
      boolean isEnabled​()  
      boolean isFullWindow​()
      Does the cameras output cover the whole screen?
      void loadShader​()  
      void move​(int x, int y)
      Move x and y coordinate
      void render​(GameView view)
      Renders the viewport
      void resize​(int width, int height)
      Should be called when resized
      void setActive​(boolean active)
      enable or disable the camera
      void setCenter​(Point point)
      Set the cameras center to a point.
      void setFocusEntity​(AbstractEntity focusEntity)
      Sets the center of the camera to this entity and follows it.
      void setFullWindow​(boolean fullWindow)
      Set to true if the camera's output should cover the whole window
      void setId​(int id)  
      void setInternalRenderResolution​(int resolution)
      the width of the internal render resolution
      void setScreenSize​(int width, int height)
      updates the screen size
      void setZoom​(float zoom)
      Set the zoom factor.
      void shake​(float amplitude, float time)
      shakes the screen
      void startMultiRendering​()
      Allows the rendering of mutiple images (multipass) without resorting.
      void update​(float dt)
      Updates the camera.
      void updateCenter​()
      Check if center has to be moved and if chunks must be loaded or unloaded performs according actions.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • Camera

        public Camera​(GameView view)
        Creates a fullscale camera pointing at the middle of the map.
        Parameters:
        view -
      • Camera

        public Camera​(GameView view,
                      int x,
                      int y,
                      int width,
                      int height)
        Creates a camera pointing at the middle of the map.
        Parameters:
        x - the position in the application window (viewport position). Origin top left
        y - the position in the application window (viewport position). Origin top left
        width - The width of the image (screen size) the camera creates on the application window (viewport)
        height - The height of the image (screen size) the camera creates on the application window (viewport)
        view -
      • Camera

        public Camera​(GameView view,
                      int x,
                      int y,
                      int width,
                      int height,
                      Point center)
        Create a camera focusin a specific coordinate. It can later be changed with focusCoordinates(). Screen size does refer to the output of the camera not the real size on the display.
        Parameters:
        center - the point where the camera focuses
        x - the position in the application window (viewport position). Origin top left
        y - the position in the application window (viewport position). Origin top left
        width - The width of the image (screen size) the camera creates on the application window (viewport)
        height - The height of the image (screen size) the camera creates on the application window (viewport)
        view -
      • Camera

        public Camera​(GameView view,
                      int x,
                      int y,
                      int width,
                      int height,
                      AbstractEntity focusentity)
        Creates a camera focusing an entity. The values are sceen-size and do refer to the output of the camera not the real display size.
        Parameters:
        focusentity - the entity wich the camera focuses and follows
        x - the position in the application window (viewport position). Origin top left
        y - the position in the application window (viewport position). Origin top left
        width - The width of the image (screen size) the camera creates on the application window (viewport)
        height - The height of the image (screen size) the camera creates on the application window (viewport)
        view -
    • Method Detail

      • loadShader

        public void loadShader​()
      • update

        public final void update​(float dt)
        Updates the camera.
        Parameters:
        dt -
      • initSorter

        public void initSorter​()
      • updateCenter

        public void updateCenter​()
        Check if center has to be moved and if chunks must be loaded or unloaded performs according actions.
      • render

        public void render​(GameView view)
        Renders the viewport
        Parameters:
        view -
      • startMultiRendering

        public void startMultiRendering​()
        Allows the rendering of mutiple images (multipass) without resorting.
      • endMultiRendering

        public void endMultiRendering​()
        Stop the multipass rendering. After this method each new call to render(GameView) is sorting again.
      • inViewFrustum

        public boolean inViewFrustum​(Position pos)
        checks if the projected position is inside the viewMat Frustum
        Parameters:
        pos -
        Returns:
      • getVisibleLeftBorderVS

        public float getVisibleLeftBorderVS​()
        Returns the left border of the actual visible area.
        Returns:
        left x position in view space
      • getVisibleLeftBorder

        public int getVisibleLeftBorder​()
        Returns the left border of the actual visible area.
        Returns:
        the left (X) border coordinate
      • getVisibleRightBorder

        public int getVisibleRightBorder​()
        Returns the right seight border of the camera covered area currently visible.
        Returns:
        measured in grid-coordinates
      • getVisibleRightBorderVS

        public float getVisibleRightBorderVS​()
        Returns the right seight border of the camera covered area currently visible.
        Returns:
        measured in grid-coordinates
      • getVisibleBackBorder

        public int getVisibleBackBorder​()
        Returns the top seight border of the camera covered groundBlock
        Returns:
        measured in grid-coordinates
      • getVisibleFrontBorderLow

        public int getVisibleFrontBorderLow​()
        Returns the bottom seight border y-coordinate of the lowest cell
        Returns:
        measured in grid-coordinates
        See Also:
        getVisibleFrontBorderHigh()
      • getVisibleFrontBorderHigh

        public int getVisibleFrontBorderHigh​()
        Returns the bottom seight border y-coordinate of the frontmost cells which could be visible.
        Returns:
        measured in grid-coordinates
        See Also:
        getVisibleFrontBorderLow()
      • getViewSpaceX

        public float getViewSpaceX​()
        The Camera Position in the game world.
        Returns:
        game in pixels
      • getViewSpaceY

        public float getViewSpaceY​()
        The Camera's center position in the game world. viewMat space. yIndex up
        Returns:
        in camera position game space
      • setZoom

        public void setZoom​(float zoom)
        Set the zoom factor.
        Parameters:
        zoom - 1 is default
      • setInternalRenderResolution

        public void setInternalRenderResolution​(int resolution)
        the width of the internal render resolution
        Parameters:
        resolution -
      • getZoom

        public float getZoom​()
        Returns the zoomfactor.
        Returns:
        zoomfactor applied on the game world
      • getProjScaling

        public float getProjScaling​()
        Returns a scaling factor calculated by the width to achieve the same viewport size with every resolution. If displayed twice as big as render resolution has factor 2.
        Returns:
        a scaling factor applied on the projection
      • getWorldWidthViewport

        public final int getWorldWidthViewport​()
        The amount of game pixels which are visible in X direction after the zoom has been applied. For screen pixels use getWidthScreenSpc().
        Returns:
        in projection space
      • getWorldHeightViewport

        public final int getWorldHeightViewport​()
        The amount of game pixel which are visible in Y direction after the zoom has been applied. For screen pixels use getHeightScreenSpc().
        Returns:
        in projection space
      • getScreenPosX

        public int getScreenPosX​()
        Returns the position of the cameras output (on the screen)
        Returns:
        in projection pixels
      • getScreenPosY

        public int getScreenPosY​()
        Returns the position of the camera (on the screen)
        Returns:
        yIndex-down
      • getHeightScreenSpc

        public int getHeightScreenSpc​()
        Returns the height of the camera output.
        Returns:
        the value before scaling
      • getWidthScreenSpc

        public int getWidthScreenSpc​()
        Returns the width of the camera output.
        Returns:
        the value before scaling
      • isFullWindow

        public boolean isFullWindow​()
        Does the cameras output cover the whole screen?
        Returns:
      • setFullWindow

        public void setFullWindow​(boolean fullWindow)
        Set to true if the camera's output should cover the whole window
        Parameters:
        fullWindow -
      • resize

        public void resize​(int width,
                           int height)
        Should be called when resized
        Parameters:
        width - width of window
        height - height of window
      • setScreenSize

        public void setScreenSize​(int width,
                                  int height)
        updates the screen size
        Parameters:
        width -
        height -
      • move

        public void move​(int x,
                         int y)
        Move x and y coordinate
        Parameters:
        x - in game space
        y - in game space
      • shake

        public void shake​(float amplitude,
                          float time)
        shakes the screen
        Parameters:
        amplitude -
        time - game time
      • getCenter

        public Point getCenter​()
        Returns the focuspoint. Approximated because is stored in view space and backtransformation is a line.
        Returns:
        in game space
      • setCenter

        public void setCenter​(Point point)
        Set the cameras center to a point. If the camera is locked to a an entity this lock will be removed.
        Parameters:
        point - game space. z gets ignored
      • setFocusEntity

        public void setFocusEntity​(AbstractEntity focusEntity)
        Sets the center of the camera to this entity and follows it.
        Parameters:
        focusEntity - must be spawned.
      • setActive

        public void setActive​(boolean active)
        enable or disable the camera
        Parameters:
        active -
      • getGameView

        public GameView getGameView​()
      • getCenterChunkX

        public int getCenterChunkX​()
        Returns:
      • getCenterChunkY

        public int getCenterChunkY​()
        Returns:
      • isEnabled

        public boolean isEnabled​()
        Returns:
      • setId

        public void setId​(int id)
        Parameters:
        id -
      • getId

        public int getId​()