Three. js source code annotation (30) Cameras/PerspectiveCamera. js
I also just started learning. Sorry for the errors in many places.
The following code is a comment on the Cameras/PerspectiveCamera. JS file in the THREE. js source code file.
/*** @ Author mrdoob/http://mrdoob.com/* @ author greggman/http://games.greggman.com/* @ author zz85/http://www.lab4games.net/zz85/blog * // PerspectiveCamera method according to fov, aspect, near, far generates a Perspective Projection camera. the function functions of the PerspectiveCamera object are implemented using a function prototype object constructed. *////PerspectiveCamera///Specifies the visual angle of the camera. An optional parameter. If not specified, the value is initialized to 50 ///Specifies the aspect ratio of the camera's visible range. An optional parameter. If not specified, the initialization is 1 ///Specifies the distance relative to the deep cut surface. It must be a positive number. An optional parameter. If not specified, the value is initialized to 0.1 ///Specifies the distance relative to the deep cut surface. It must be a positive number. An optional parameter. If not specified, the value is initialized to 2000 ///
Returns PerspectiveCamera, a perspective projection camera.
THREE. perspectiveCamera = function (fov, aspect, near, far) {THREE. camera. call (this); // call the call method of the Camera object and hand over the method originally belonging to the Camera to the current object PerspectiveCamera for use. this. fov = fov! = Undefined? Fov: 50; // specifies the visual angle of the camera. An optional parameter. If not specified, the initialization is 50this. aspect = aspect! = Undefined? Aspect: 1; // specifies the aspect ratio of the camera's visible range. An optional parameter. If this parameter is not specified, it is initialized to 1this. near = near! = Undefined? Near: 0.1; // specify the distance relative to the deep cut surface. It must be a positive number. An optional parameter. If not specified, it is initialized to 0.1this.far = far! = Undefined? Far: 2000; // specify the distance relative to the depth cut surface. It must be a positive number. An optional parameter. If not specified, the value is 2000this. updateProjectionMatrix (); // call the updateProjectionMatrix method to update the projection matrix of the camera .}; /*************************************** **************************************** * ********** The following is the function definition provided by the PerspectiveCamera object, some of them inherit from the Camera method through prototype ********************************* **************************************** * *************/THREE. perspectiveCamera. prototype = Object. create (THREE. camera. prototype); // * // The setLens method updates the perspective of the Perspective Projection Camera Based on the focal length focalLength and frame size frameHeight. *////SetLens///Focal Length ///Image Size ///
Returns the Perspective Projection camera that updates the field of view.
/*** Uses Focal Length (in mm) to estimate and set FOV * 35mm (fullframe) camera is used if frame size is not specified; * use Focal Length (in mm) when setting the camera, if the frame size is not specified, the FOV (field of view) 35mm (full frame) camera is used by default, * Formula based on http://www.bobatkins.com/photography/technical/field_of_view.html */THREE. perspectiveCamera. prototype. setLens = function (focalLength, frameHeight) {if (frameHeight = undefined) frameHeight = 24; // if the frame size is not specified, the value is initialized to 24 and the full frame camera this. fov = 2 * THREE. math. radToDeg (Math. atan (frameHeight/(focalLength * 2); // update the perspective of the Perspective Projection camera. this. updateProjectionMatrix (); // update the projection matrix}/* // The setViewOffset method is used to set the preview offset for a large flattened part. This method is used on multiple monitors and multiple machines, the application on the display matrix is very effective *////SetViewOffset///Total width of an oversized camera scene ///The total height of an oversized camera scene ///The starting point of the x coordinate at the upper left corner of the current camera in the grid ///Start Point of the y coordinate at the upper left corner of the current camera in the grid ///Current Camera width ///Current Camera height ///
Returns the Perspective Projection camera that updates the Perspective Projection Matrix.
/*** Sets an offset in a larger frustum. this is useful for multi-window or * multi-monitor/multi-machine setups. * It is very effective to apply the method to multiple monitors, multiple machines, and display matrices for a large flattened head. ** For example, if you have 3x2 monitors and each monitor is 1920x1080 and * the monitors are in grid like this *, For example, you have 3x2 monitors, the resolution of each monitor is 1920x1080, bottom grid of the display matrix ** + --- + * | A | B | C | * + --- + * | D | E | F | * + --- + ** then for each monitor you wowould call it like this * then, you can call the setOffset () method for each monitor to display a part of the canvas. ** var w = 1920; * var h = 1080; * var fullWidth = w * 3; * var fullHeight = h * 2; ** -- A -- * camera. setOffset (fullWidth, fullHeight, w * 0, h * 0, w, h); * -- B -- * camera. setOffset (fullWidth, fullHeight, w * 1, h * 0, w, h); * -- C -- * camera. setOffset (fullWidth, fullHeight, w * 2, h * 0, w, h); * -- D -- * camera. setOffset (fullWidth, fullHeight, w * 0, h * 1, w, h); * -- E -- * camera. setOffset (fullWidth, fullHeight, w * 1, h * 1, w, h); * -- F -- * camera. setOffset (fullWidth, fullHeight, w * 2, h * 1, w, h); ** Note there is no reason monitors have to be the same size or in a grid. * Note: It is possible that these displays are not of the same size. you can set the methods you want as needed. */THREE. perspectiveCamera. prototype. setViewOffset = function (fullWidth, fullHeight, x, y, width, height) {this. fullWidth = fullWidth; // The total width of an oversized camera scene. this. fullHeight = fullHeight; // the total height of an oversized camera scene this. x = x; // the starting point of the x coordinate at the top left corner of the current camera in the grid. this. y = y; // the start point of the y coordinate at the upper left corner of the current camera in the grid. this. width = width; // The Current Camera width this. height = height; // The height of the current camera. this. updateProjectionMatrix (); // returns the Perspective Projection camera that updates the Perspective Projection Matrix};/* // The updateProjectionMatrix method returns the matrix of the visual boundaries of the Perspective Projection camera. this parameter must be called when the camera parameter is changed. *////UpdateProjectionMatrix///
Returns a new OrthographicCamera object.
THREE. perspectiveCamera. prototype. updateProjectionMatrix = function () {if (this. fullWidth) {var aspect = this. fullWidth/this. fullHeight; var top = Math. tan (THREE. math. degToRad (this. fov * 0.5) * this. near; var bottom =-top; var left = aspect * bottom; var right = aspect * top; var width = Math. abs (right-left); var height = Math. abs (top-bottom); this. projectionMatrix. makeFrustum (left + this. x * width/this. fullWidth, left + (this. x + this. width) * width/this. fullWidth, top-(this. y + this. height) * height/this. fullHeight, top-this. y * height/this. fullHeight, this. near, this. far);} else {this. projectionMatrix. makePerspective (this. fov, this. aspect, this. near, this. far) ;}};/* clone method // clone the PerspectiveCamera object *////Clone///
Returns the cloned PerspectiveCamera object.
THREE. perspectiveCamera. prototype. clone = function () {var camera = new THREE. perspectiveCamera (); THREE. camera. prototype. clone. call (this, camera); // call THREE. camera. clone (camera) method to Clone the camera object camera. fov = this. fov; // copy the fov attribute value of the Perspective Projection camera to camera. aspect = this. aspect; // copy the aspect attribute value of the Perspective Projection camera to camera. near = this. near; // copy the near attribute value of the Perspective Projection camera to camera. far = this. far; // copy the far attribute value of the Perspective Projection camera to return camera; // return the cloned PerspectiveCamera object };
Wuji (http://blog.csdn.net/omni360)
This article follows the "signature-non-commercial use-consistency" creation public agreement
Reprinted please keep this sentence: Wuji-this blog focuses on Agile development and mobile and IOT device research: data visualization, GOLANG, Html5, WEBGL, THREE. JS. Otherwise, the post from this blog will not be reprinted or reprinted. Thank you for your cooperation.
The following code is a comment on the Cameras/PerspectiveCamera. JS file in the THREE. js source code file.
More updates in: https://github.com/omni360/three.js.sourcecode