H3DU.Camera
### H3DU.Camera(batch, fov, nearZ, farZ, [canvas])
A class for controlling the projection and view of a 3D scene, in the nature of an abstract “camera”. This class uses the concept of a “camera’s position”, or where the camera is located in world space, as well as a “reference point”, or the point in world space that the camera is looking at.
This class is considered a supplementary class to the Public Domain HTML 3D Library and is not considered part of that library.
To use this class, you must include the script “extras/camera.js”; the class is not included in the “h3du_min.js” file which makes up the HTML 3D Library. Example:
<script type="text/javascript" src="extras/camera.js"></script>
Parameters
batch
(Type: H3DU.Batch3D)
A 3D batch to associate with this camera object. Using a H3DU.Scene3D here is deprecated.fov
(Type: number)
Vertical field of view, in degrees. Should be less than 180 degrees. (The smaller this number, the bigger close objects appear to be.) See H3DU.MathUtil.mat4perspective.nearZ
(Type: number)
The distance from the camera to the near clipping plane. Objects closer than this distance won’t be seen. See H3DU.MathUtil.mat4perspective. This should be slightly greater than 0.farZ
(Type: number)
The distance from the camera to the far clipping plane. Objects beyond this distance will be too far to be seen. See H3DU.MathUtil.mat4perspective.canvas
(Type: HTMLCanvasElement) (optional)
A canvas to associate with this camera object. This argument is deprecated.
Methods
- getDistance
Finds the distance from the camera’s position to the reference point. - getPosition
Gets the position of the camera. - getVectorFromCenter
Gets the 3-element vector that points from the reference point to the camera’s position. - moveAngleHorizontal
Moves the camera to the left or right so that it faces the same reference point at the same distance. - moveAngleVertical
Moves the camera upward or downward so that it faces the same reference point at the same distance. - moveClose
Moves the camera the given distance, but not too close to the reference point. - moveForward
Moves the camera forward the given distance. - moveHorizontal
Moves the camera horizontally relative to the camera’s up vector. - moveVertical
Moves the camera toward or away from the camera’s up vector. - setDistance
Moves the camera a given distance from the reference point without changing its orientation. - setPosition
Sets the position of the camera. - turnAngleHorizontal
Turns the camera to the left or right so that it faces the same distance from a reference point. - turnAngleVertical
Turns the camera upward or downward so that it faces the same distance from a reference point. - turnHorizontal
Deprecated: Renamed to “moveAngleHorizontal”. - turnVertical
Deprecated: Renamed to “moveAngleVertical”. - update
Updates information about this camera based on the state of an input tracker.
Finds the distance from the camera’s position to the reference point.
Return Value
Return value. (Type: number)
Gets the position of the camera.
Return Value
An array of three numbers giving the X, Y, and Z coordinates of the camera’s position, respectively. (Type: Array.<number>)
### H3DU.Camera#getVectorFromCenter()
Gets the 3-element vector that points from the reference point to the camera’s position.
Return Value
The return value as a unit vector (a “normalized” vector with a length of 1). Returns (0,0,0) if the reference point is the same as the camera’s position. (Type: Array.<number>)
### H3DU.Camera#moveAngleHorizontal(angleDegrees)
Moves the camera to the left or right so that it faces the same reference point at the same distance.
Parameters
angleDegrees
(Type: number)
The angle to rotate the camera, in degrees. If the coordinate-system is right-handed, positive values rotate the camera leftward, and negative values rightward. If the coordinate-system is left-handed, vice versa.
Return Value
This object. (Type: H3DU.Camera)
### H3DU.Camera#moveAngleVertical(angleDegrees)
Moves the camera upward or downward so that it faces the same reference point at the same distance.
Parameters
angleDegrees
(Type: number)
The angle to rotate the camera, in degrees. If the coordinate-system is right-handed, positive values rotate the camera upward, and negative values downward. If the coordinate-system is left-handed, vice versa.
Return Value
This object. (Type: H3DU.Camera)
### H3DU.Camera#moveClose(dist)
Moves the camera the given distance, but not too close to the reference point.
Parameters
dist
(Type: number)
The distance to move. Positive values mean forward, and negative distances mean back.
Return Value
This object. (Type: H3DU.Camera)
### H3DU.Camera#moveForward(dist)
Moves the camera forward the given distance.
Parameters
dist
(Type: number)
The distance to move. Positive values mean forward, and negative distances mean back.
Return Value
This object. (Type: H3DU.Camera)
### H3DU.Camera#moveHorizontal(dist)
Moves the camera horizontally relative to the camera’s up vector.
Parameters
dist
(Type: number)
Distance to move the camera.
Return Value
This object. (Type: H3DU.Camera)
### H3DU.Camera#moveVertical(dist)
Moves the camera toward or away from the camera’s up vector.
Parameters
dist
(Type: number)
Distance to move the camera.
Return Value
This object. (Type: H3DU.Camera)
### H3DU.Camera#setDistance(dist)
Moves the camera a given distance from the reference point without changing its orientation.
Parameters
dist
(Type: number)
Positive number giving the distance. If this is less than the near plane distance, the distance will be equal to the near plane distance. Does nothing if the distance is 0 or less.
Return Value
This object. (Type: H3DU.Camera)
### H3DU.Camera#setPosition(cx, [cy], [cz])
Sets the position of the camera.
Parameters
cx
(Type: number)
The camera’s new X coordinate, or a 3-element vector containing the X, Y, and Z coordinates. In the latter case, “cy” and “cz” can be omitted.cy
(Type: number) (optional)
The camera’s new Y coordinate.cz
(Type: number) (optional)
The camera’s new Z coordinate.
Return Value
This object. (Type: H3DU.Camera)
### H3DU.Camera#turnAngleHorizontal(angleDegrees)
Turns the camera to the left or right so that it faces the same distance from a reference point.
Parameters
angleDegrees
(Type: number)
The angle to rotate the camera, in degrees. If the coordinate-system is right-handed, positive values rotate the camera rightward, and negative values leftward. If the coordinate-system is left-handed, vice versa.
Return Value
This object. (Type: H3DU.Camera)
### H3DU.Camera#turnAngleVertical(angleDegrees)
Turns the camera upward or downward so that it faces the same distance from a reference point.
Parameters
angleDegrees
(Type: number)
The angle to rotate the camera, in degrees. If the coordinate-system is right-handed, positive values rotate the camera upward, and negative values downward. If the coordinate-system is left-handed, vice versa.
Return Value
This object. (Type: H3DU.Camera)
### H3DU.Camera#turnHorizontal(angleDegrees)
Deprecated: Renamed to “moveAngleHorizontal”.
Moves the camera to the left or right so that it faces the same reference point at the same distance.
Parameters
angleDegrees
(Type: number)
The angle to rotate the camera, in degrees. If the coordinate-system is right-handed, positive values rotate the camera leftward, and negative values rightward. If the coordinate-system is left-handed, vice versa.
Return Value
This object. (Type: H3DU.Camera)
### H3DU.Camera#turnVertical(angleDegrees)
Deprecated: Renamed to “moveAngleVertical”.
Moves the camera upward or downward so that it faces the same reference point at the same distance.
Parameters
angleDegrees
(Type: number)
The angle to rotate the camera, in degrees. If the coordinate-system is right-handed, positive values rotate the camera upward, and negative values downward. If the coordinate-system is left-handed, vice versa.
Return Value
This object. (Type: H3DU.Camera)
### H3DU.Camera#update([input])
Updates information about this camera based on the state of an input tracker.
Parameters
input
(Type: H3DU.InputTracker) (optional)
An input tracker. This method should be called right after the tracker’s ‘update’ method was called. Note that future versions may require this parameter.
Return Value
Return value. (Type: Object)