Three.js Source Code Gaze (16) Math/frustum.js

Source: Internet
Author: User
Tags truncated

Commercial Territory (http://blog.csdn.net/omni360/)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Business Domain-this blog focuses on Agile development and mobile and IoT device research: Data visualization, Golang, HTML5, WEBGL, three. JS, Otherwise, from this blog article refused to reprint or reprint, thank you for your cooperation.


I also just started to learn, a lot of children are certainly not correct also forgive me.

The following code is the gaze of the Math/frustum.js file in the Three.js source code file.

Many other 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/* @aut Hor the constructor of the Bhouston/http://exocortex.com *//*///frustum object. Used to create a flat-truncated object in a three-dimensional space. The function function of the Frustum object is implemented by the function prototype object defined by///. The flat head body is composed of 6 planar objects. *////<summary>frustum</summary>///<param name = "P0" type= "three. Plane "> The face P0</param>///<param that make up the flat head body name =" P1 "type=" three. Plane "> The face P1</param>///<param that make up the flat head body name =" P2 "type=" three. Plane "> The face P2</param>///<param that make up the flat head body name =" P3 "type=" three. Plane "> The face P3</param>///<param that make up the flat head body name =" P4 "Type=" three. Plane "> The face P4</param>///<param that make up the flat head body name =" P5 "type=" three. Plane "> The face P5</param>three that make up the flat head body. 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 function functions provided by the Frustum object. ****************************************/three . Frustum.prototype = {Constructor:three. The frustum,//constructor, which returns a reference to the Frustum function that created this object/*///set method is used to set the start point, end Point, P0, p1, p2, P3, P4, and P5 of the flat head body again. and return the new coordinate value of the flat-truncated head body .*////< Summary>set</summary>///<param name = "P0" type= "three. Plane "> The face P0</param>///<param that make up the flat head body name =" P1 "type=" three. Plane "> The face P1</param>///<param that make up the flat head body name =" P2 "type=" three. Plane "> The face P2</param>///<param that make up the flat head body name =" P3 "type=" three. Plane "> The face P3</param>///<param that make up the flat head body name =" P4 "Type=" three. Plane "> The face P4</param>///<param that make up the flat head body name =" P5 "type=" three. Plane "> The face p5</param>///<returns type=" Frustum "> returns the new flat head body </returns>set:function (P0, p1, P2, P3, P4, p5) {var planes = this.planes;planes[0].copy (p0);p lanes[1].copy (p1);p lanes[2].copy (p2);p lanes[3 ].copy (p3);p lanes[4].coPY (p4);p lanes[5].copy (p5); return this;//returns a new flat head body},/*///copy method used to replicate the six faces that make up the flat head body, p0, p1, p2, p3, P4, P5. and returns a new flat-head body. *////&L T;summary>copy</summary>///<param name = "Frustum" type= "frustum" > Flat head Body </param>///<returns Type= "Frustum" > returns the new flat head body </returns>copy:function (Frustum) {var planes = this.planes;for (var i = 0; i < 6; i + +) {planes[i].copy (frustum.planes[i]);} Return this;//Returns a new},/*///setfrommatrix method by applying a transform to the current flat-head body and returning a new flat-truncated head body. *////<summary>setfrommatrix</ Summary>///<param name = "M" type= "Matrix4" >4x4 matrix </param>///<returns type= "Frustum" > Returns a new flat head body  </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 = m e[9], me10 = me[], Me11 = me[one];var me12 = me[], me13 = me[], me14 = me[], me15 = me[);p lanes[0 ].setcomponEnts (ME3-ME0, Me7-me4, Me11-me8, me15-me12). Normalize ();p lanes[1].setcomponents (Me3 + ME0, Me7 + me4, Me11 + Me8, Me15 + me12). Normalize ();p lanes[2].setcomponents (Me3 + me1, Me7 + me5, Me11 + me9, Me15 + me13). Normalize ();p LAN es[3].setcomponents (me3-me1, Me7-me5, Me11-me9, me15-me13). Normalize ();p lanes[4].setcomponents (me3-me2, M  E7-me6, Me11-me10, me15-me14). Normalize ();p lanes[5].setcomponents (Me3 + me2, Me7 + me6, Me11 + me10, Me15 + me14 ). normalize (); return this;//returns a new flat-truncated body},/*///intersectsobject method gets whether the current flat-head body intersects with the parameter object, returns True, or false*////< Summary>intersectsobject</summary>///<param name = "Object" type= "Object3d" >3d Stereoscopic object </param>/// <returns type= "Boolean" > Returns TRUE or False</returns>intersectsobject:function () {var sphere = new three. Sphere (); return function (object) {var geometry = object.geometry;if (Geometry.boundingsphere = = = null) geometry.compu Teboundingsphere (); Sphere.copy (GEOMETRY.BOUNDINGSPHere); sphere.applymatrix4 (Object.matrixworld); return This.intersectssphere (sphere);//returns TRUE or false};} (), the/*///intersectssphere method gets whether the current flat-head body intersects with the sphere sphere object, returns TRUE or false*////<summary>intersectssphere</ Summary>///<param name = "Sphere" type= "sphere" > a sphere Sphere </param>///<returns type= "Boolean" > Returns 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;//does not intersect returns false}} Return true;//intersect returns the True},/*///intersectsbox method to obtain whether the current flat head body intersects with the Reference box cube object, returns True, or false*////<summary> Intersectsbox</summary>///<param name = "box" type= "Box3" > Cube object </param>///<returns type= " Boolean "> Returns 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];p 1.x = plane.normal.x > 0? box.min.x:bo x.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//assumes that the p1,p2 of the cube do not want to intersect with the plane, indicating that the cube is disjoint. if (D1 < 0 && D2 < 0) {return false;//disjoint return False}}retur N true;//intersection returns TRUE.};} (), the/*///containspoint method is used to obtain the reference point (a Vector3 's three-dimensional dot coordinate) in the current flat head. *////<summary>containspoint</summary >///<param name = "point" type= "three. Vector3 "> A Vector3 three-dimensional point coordinate </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;//not within the bounds, return False}}return true;//within the bounds, return to True},/*clone method// Clone method clones a truncated head body object. *////<summary>clone</summary>///<returns type= "Frustum" > Return to the Flat head body object </ Returns>clone:function () {return new three. Frustum (). copy (this);//Return to the flat head object}};


Commercial Territory (http://blog.csdn.net/omni360/)

This article follows "Attribution-non-commercial use-consistent" authoring public agreement

Reprint Please keep this sentence: Business Domain-this blog focuses on Agile development and mobile and IoT device research: Data visualization, Golang, HTML5, WEBGL, three. JS, Otherwise, from this blog article refused to reprint or reprint, thank you for your cooperation.


The following code is the gaze of the Math/frustum.js file in the Three.js source code file.

Many other updates in: Https://github.com/omni360/three.js.sourcecode/blob/master/Three.js

Three.js Source Code Gaze (16) Math/frustum.js

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.