Package org.xjge.core

Class Camera

java.lang.Object
org.xjge.core.Camera

public abstract class Camera
extends java.lang.Object
Abstract class which can be used to create specialized objects that will render the current perspective of a Viewport.

NOTE: Subclasses of this object use a combination of matrices to alter how the game world is perceived. Game implementations that specify custom shader programs are required to supply a 4x4 projection matrix of via uniform variable if they wish to utilize camera objects correctly.

Since:
2.0.0
  • Field Summary

    Fields
    Modifier and Type Field Description
    org.joml.Vector3f direction  
    protected float fov  
    org.joml.Vector3f position  
    protected org.joml.Matrix4f projMatrix  
    org.joml.Vector3f up  
    protected org.joml.Matrix4f viewMatrix  
  • Constructor Summary

    Constructors
    Modifier Constructor Description
    protected Camera​(boolean isOrtho)
    Creates a new camera object that will render the game world using the specified projection type.
  • Method Summary

    Modifier and Type Method Description
    abstract void render​(java.util.Map<java.lang.String,​GLProgram> glPrograms)
    Used to organize calls to the OpenGL API and other code pertaining to rendering.
    static void setOrthoDepthRange​(float near, float far)
    Sets the near/far clipping distance the depth buffer will use while cameras are in orthographic mode.
    void setProjectionType​(boolean isOrtho)
    Changes the current projection type the camera will use.
    abstract void update()
    Optional abstract method which can be used to organize camera logic not directly related to rendering.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • fov

      protected float fov
    • position

      public org.joml.Vector3f position
    • direction

      public org.joml.Vector3f direction
    • up

      public org.joml.Vector3f up
    • viewMatrix

      protected org.joml.Matrix4f viewMatrix
    • projMatrix

      protected org.joml.Matrix4f projMatrix
  • Constructor Details

    • Camera

      protected Camera​(boolean isOrtho)
      Creates a new camera object that will render the game world using the specified projection type. By default, the engine provides two projection types; orthographic for 2D and perspective for 3D.
      Parameters:
      isOrtho - if true, the camera will use an orthographic projection to render the scene
  • Method Details

    • update

      public abstract void update()
      Optional abstract method which can be used to organize camera logic not directly related to rendering. Examples of this include applying effects such as camera shake or dolly motion.
    • render

      public abstract void render​(java.util.Map<java.lang.String,​GLProgram> glPrograms)
      Used to organize calls to the OpenGL API and other code pertaining to rendering.
      Parameters:
      glPrograms - an immutable collection containing the shader programs compiled during startup
    • setProjectionType

      public void setProjectionType​(boolean isOrtho)
      Changes the current projection type the camera will use.

      By default, the engine provides two projection types; orthographic for 2D and perspective for 3D.

      Parameters:
      isOrtho - if true, the camera will use an orthographic projection to render the scene
    • setOrthoDepthRange

      public static void setOrthoDepthRange​(float near, float far)
      Sets the near/far clipping distance the depth buffer will use while cameras are in orthographic mode. Objects which lay outside of this range will be invisible.

      NOTE: Because the engine makes no assumptions about the size of the depth buffer, the near/far clipping distance is between -32768 and 32767 by default. These values correspond to the lowest depth buffer size allowed by OpenGL (a half-precision 16-bit float). Changing these may result in undefined behavior on some machines.

      Parameters:
      near - the distance considered closest to the camera
      far - the distance considered furthest from the camera