Package snap.gfx3d

Class Camera

java.lang.Object
snap.gfx3d.Camera

public class Camera extends Object
This class represent a camera focusing on a scene and manages a display list of simple paths based on the scene shapes and the camera transform. Camera transform is currently relative to scene. At some point, that may become an option instead. 3D conventions: Coordinate system: Right handed (not left handed) Polygon front: Right hand rule (counter-clockwise defined polygons face forward) Transforms: Row major notation (as opposed to column major, points are assumed row vectors)
  • Field Details

  • Constructor Details

    • Camera

      public Camera()
      Constructor.
  • Method Details

    • getScene

      public Scene3D getScene()
      Returns the scene this camera is associated with.
    • setScene

      public void setScene(Scene3D aScene)
      Sets the scene this camera is associated with.
    • getViewWidth

      public double getViewWidth()
      Returns the width of the camera viewing plane.
    • setViewWidth

      public void setViewWidth(double aValue)
      Sets the width of the camera viewing plane.
    • getViewHeight

      public double getViewHeight()
      Returns the height of the camera viewing plane.
    • setViewHeight

      public void setViewHeight(double aValue)
      Sets the height of the camera viewing plane.
    • getYaw

      public double getYaw()
      Returns the rotation about the Y axis in degrees.
    • setYaw

      public void setYaw(double aValue)
      Sets the rotation about the Y axis in degrees.
    • getPitch

      public double getPitch()
      Returns the rotation about the X axis in degrees.
    • setPitch

      public void setPitch(double aValue)
      Sets the rotation about the X axis in degrees.
    • getRoll

      public double getRoll()
      Returns the rotation about the Z axis in degrees.
    • setRoll

      public void setRoll(double aValue)
      Sets the rotation about the Z axis in degrees.
    • getFocalLength

      public double getFocalLength()
      Returns the focal length of the camera (derived from the field of view and with view size).
    • setFocalLength

      public void setFocalLength(double aValue)
      Sets the focal length of the camera. Two feet is normal (1728 points).
    • getGimbalRadius

      public double getGimbalRadius()
      Returns the distance from center of scene to camera when in gimbal mode.
    • setGimbalRadius

      protected void setGimbalRadius(double aValue)
      Sets the distance from center of scene to camera when in gimbal mode.
    • isPrefGimbalRadiusSet

      public boolean isPrefGimbalRadiusSet()
      Returns whether PrefGimbalRadius is explicitly set.
    • getPrefGimbalRadius

      public double getPrefGimbalRadius()
      Returns the optimal distance from center of scene to camera when in gimbal mode.
    • setPrefGimbalRadius

      public void setPrefGimbalRadius(double aValue)
      Sets the optimal distance from center of scene to camera when in gimbal mode.
    • calcPrefGimbalRadius

      public double calcPrefGimbalRadius()
      Returns the optimal distance from center of scene to camera when in gimbal mode.
    • getFieldOfViewX

      public double getFieldOfViewX()
      Returns the field of view of the camera (derived from focalLength).
    • getFieldOfViewY

      public double getFieldOfViewY()
      Returns the field of view Y of camera (derived from focalLength).
    • setFieldOfViewY

      public void setFieldOfViewY(double aValue)
      Sets the field of view Y of camera.
    • isOrtho

      public boolean isOrtho()
      Returns whether camera is viewing in orthographic projection (no perspective).
    • setOrtho

      public void setOrtho(boolean aValue)
      Sets whether camera is viewing in orthographic projection (no perspective).
    • getNormal

      public Vector3D getNormal()
      Returns the camera normal as a vector.
    • getSceneToCamera

      public Matrix3D getSceneToCamera()
      Returns the transform from scene coords to camera coords.
    • getCameraToClip

      public Matrix3D getCameraToClip()
      Returns the transform from camera coords to clip space (AKA the 'Projection' matrix).
    • getCameraToView

      public Matrix3D getCameraToView()
      Returns the transform from camera to View space.
    • getSceneToView

      public Matrix3D getSceneToView()
      Returns the transform from scene to View space.
    • getSceneToCameraArray

      public double[] getSceneToCameraArray()
      Returns the SceneToCamera transform as double array.
    • getCameraToClipArray

      public double[] getCameraToClipArray()
      Returns the CameraToClip transform as double array.
    • setYawPitchRollForSideAndPos

      public void setYawPitchRollForSideAndPos(Side3D aSide, Pos aPos)
      Set camera view to given side.
    • isFacing

      public boolean isFacing(Vector3D aV3D)
      Returns whether a vector is facing camera.
    • isFacingAway

      public boolean isFacingAway(Vector3D aV3D)
      Returns whether a vector is facing away from camera.
    • getRenderer

      public Renderer getRenderer()
      Returns the renderer.
    • setRenderer

      public void setRenderer(Renderer aRenderer)
      Sets the renderer.
    • getRayToViewPoint

      public void getRayToViewPoint(double aX, double aY, Point3D rayOrigin, Vector3D rayDir)
      Calculates and sets the ray (origin,dir) from camera origin to 2D point in camera view coords.
    • paintScene

      public void paintScene(Painter aPntr)
      Paints the scene from the view of this camera for given painter.
    • processEvent

      public void processEvent(ViewEvent anEvent)
      Viewer method.
    • getSceneBounds2D

      public Rect getSceneBounds2D()
      Returns the bounding rect for camera paths.
    • sceneDidChange

      protected void sceneDidChange()
      Called when Scene changes.
    • clearCachedValues

      protected void clearCachedValues()
      Clears cached values.
    • copy3D

      public void copy3D(Camera aCam)
      Copy attributes of another camera.
    • addPropChangeListener

      public void addPropChangeListener(PropChangeListener aLsnr)
      Add listener.
    • removePropChangeListener

      public void removePropChangeListener(PropChangeListener aLsnr)
      Remove listener.
    • firePropChange

      protected final void firePropChange(String aProp, Object oldVal, Object newVal)
      Fires a property change for given property name, old value, new value and index.
    • firePropChange

      protected void firePropChange(PropChange aPCE)
      Fires a given property change.