Three. js source code annotation (16) Math/Frustum. js, three. jsfrustum. js
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.
I also just started learning. Sorry for the errors in many places.
The following code is a comment on the Math/Frustum. JS file in the THREE. js source code file.
More updates in: https://github.com/omni360/three.js.sourcecode/blob/master/Three.js
// File: src/math/Frustum. js/*** @ author mrdoob/http://mrdoob.com/* @ author alteredq/http://alteredqualia.com/* @ author bhouston/http://exocortex.com * // Frustum object constructor. used to create an intercept object in a 3D space. the functional functions of the Frustum object are implemented using a function prototype object constructed by // definition. The flat header is composed of six flat objects. * //// <summary> Frustum </summary> /// <param name = "p0" type = "THREE. plane "> p0 </param> // <param name =" p1 "type =" THREE. plane "> surface p1 of the heartbeat header </param> /// <par Am name = "p2" type = "THREE. plane "> p2 </param> // <param name =" p3 "type =" THREE. plane "> compose the surface p3 of the heartbeat header </param> /// <param name =" p4 "type =" THREE. plane "> p4 </param> // <param name =" p5 "type =" THREE. plane "> layer p5 </param> THREE. frustum = function (p0, p1, p2, p3, p4, p5) {this. planes = [(p0! = Undefined )? P0: new THREE. Plane (), (p1! = Undefined )? P1: new THREE. Plane (), (p2! = Undefined )? P2: new THREE. Plane (), (p3! = Undefined )? P3: new THREE. Plane (), (p4! = Undefined )? P4: new THREE. Plane (), (p5! = Undefined )? P5: new THREE. plane ()] ;}; /*************************************** * ***** the following are the functions provided by the Frustum object. **************************************** /THREE. frustum. prototype = {constructor: THREE. frustum, // constructor, returns a reference to the Frustum function that creates this object/* // set method to reset the starting point, ending point, p0, p1, p2, p3, p4, p5. and return the equal part of the new coordinate value. * //// <summary> set </summary> /// <param name = "p0" type = "THREE. plane "> p0 </param> // <param name =" p1 "type =" THREE. pla Ne "> the surface p1 of the heartbeat header </param> /// <param name =" p2 "type =" THREE. plane "> p2 </param> // <param name =" p3 "type =" THREE. plane "> compose the surface p3 of the heartbeat header </param> /// <param name =" p4 "type =" THREE. plane "> p4 </param> // <param name =" p5 "type =" THREE. plane "> Plane p5 that makes up the intercept body </param> // <returns type =" Frustum "> returns a new intercept body </returns> set: function (p0, p1, p2, p3, p4, p5) {var planes = this. planes; planes [0]. copy (p0); planes [1]. Copy (p1); planes [2]. copy (p2); planes [3]. copy (p3); planes [4]. copy (p4); planes [5]. copy (p5); return this; // return the new heartbeat object}, and the/* // copy method is used to copy the six planes that constitute the heartbeat object, p0, p1, p2, p3, p4, p5. and return the new intercept. * //// <summary> copy </summary> /// <param name = "frustum" type = "Frustum"> intercept </param> /// <returns type = "Frustum"> return the new heartbeat header </returns> copy: function (frustum) {var planes = this. planes; for (var I = 0; I <6; I ++) {pl Anes [I]. copy (frustum. planes [I]);} return this; // return a new flat header},/* // setFromMatrix, returns the new intercept. * //// <summary> setFromMatrix </summary> // <param name = "m" type = "Matrix4"> 4x4 matrix </param> /// <returns type = "Frustum"> return the new HTTP header </returns> setFromMatrix: function (m) {var planes = this. planes; var me = m. elements; var me0 = me [0], me1 = me [1], me2 = me [2], me3 = me [3]; var me4 = me [4], me5 = Me [5], me6 = me [6], me7 = me [7]; var me8 = me [8], me9 = me [9], me10 = me [10], me11 = me [11]; var me12 = me [12], me13 = me [13], me14 = me [14], me15 = me [15]; planes [0]. setComponents (me3-me0, me7-me4, me11-me8, me15-me12 ). normalize (); planes [1]. setComponents (me3 + me0, me7 + me4, me11 + me8, me15 + me12 ). normalize (); planes [2]. setComponents (me3 + me1, me7 + me5, m E11 + me9, me15 + me13 ). normalize (); planes [3]. setComponents (me3-me1, me7-me5, me11-me9, me15-me13 ). normalize (); planes [4]. setComponents (me3-me2, me7-me6, me11-me10, me15-me14 ). normalize (); planes [5]. setComponents (me3 + me2, me7 + me6, me11 + me10, me15 + me14 ). normalize (); return this; // return the new HTTP header},/* // use the intersectsObject method to determine whether the current HTTP header is intersection with the parameter object, returns true or false * // <summary> IntersectsObject </summary> /// <param name = "object" type = "Object3d"> 3d stereo object </param> /// <returns type = "Boolean"> return true or false </returns> intersectsObject: function () {var sphere = new THREE. sphere (); return function (object) {var geometry = object. geometry; if (geometry. boundingSphere === null) geometry. computeBoundingSphere (); sphere. copy (geometry. boundingSphere); sphere. applyMatrix4 (object. matri XWorld); return this. intersectsSphere (sphere); // return true or false};} (),/* // use the intersectsSphere method to determine whether the current section body is intersecting with the sphere object parameter, returns true or false * /// <summary> intersectsSphere </summary> /// <param name = "sphere" type = "Sphere"> Sphere sphere Sphere </param >/// <returns type = "Boolean"> return true or false </returns> intersectsSphere: function (sphere) {var planes = this. planes; var center = sphere. center; var negRadius =-sphere. Radius; for (var I = 0; I <6; I ++) {var distance = planes [I]. distanceToPoint (center); if (distance <negRadius) {return false; // returns false if there is no intersection} return true; // returns true if there is no intersection }, /* // The intersectsBox method is used to obtain whether the current flat header is intersecting with the parameter box cube object, returns true or false * /// <summary> intersectsBox </summary> /// <param name = "box" type = "Box3"> cube object </param>/ // <returns type = "Boolean"> return true or false </returns> intersectsBox: function () {var P1 = new THREE. vector3 (), p2 = new THREE. vector3 (); return function (box) {var planes = this. planes; for (var I = 0; I <6; I ++) {var plane = planes [I]; p1.x = plane. normal. x> 0? Box. min. x: box. max. x; p2.x = plane. normal. x> 0? Box. max. x: box. min. x; p1.y = plane. normal. y> 0? Box. min. y: box. max. y; p2.y = plane. normal. y> 0? Box. max. y: box. min. y; p1.z = plane. normal. z> 0? Box. min. z: box. max. z; p2.z = plane. normal. z> 0? Box. max. z: box. min. z; var d1 = plane. distanceToPoint (p1); var d2 = plane. distanceToPoint (p2); // if both outside plane, no intersection // if the p1 and p2 of the cube do not want to be handed over to the plane, the cube and the intercept body do not intersection. if (d1 <0 & d2 <0) {return false; // returns false if there is no intersection} return true; // returns true if the intersection is true .};} (), // * // The containsPoint method is used to obtain whether the point parameter (the three-dimensional coordinate of A Vector3) is in the current flat header. * //// <summary> containsPoint </summary> /// <param name = "point" type = "THREE. vector3 "> three-dimensional coordinate of A Vector3 </param> // <returns type =" Boolean "> returns true or false </returns> containsPoint: function (point) {var planes = this. planes; for (var I = 0; I <6; I ++) {if (planes [I]. distanceToPoint (point) <0) {return false; // if the value is not within the boundary, false is returned.} return true; // if the value is within the boundary, true is returned }, /* clone method // clone method to clone a flat object. * //// <summary> clone </summary> /// <returns type = "Frustum"> returns the heartbeat object. </returns> clone: function () {return new THREE. frustum (). copy (this); // returns the object of the heartbeat header }};
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 Math/Frustum. JS file in the THREE. js source code file.
More updates in: https://github.com/omni360/three.js.sourcecode/blob/master/Three.js