diff options
Diffstat (limited to 'js/lib/geom/circle.js')
-rwxr-xr-x | js/lib/geom/circle.js | 53 |
1 files changed, 50 insertions, 3 deletions
diff --git a/js/lib/geom/circle.js b/js/lib/geom/circle.js index 896803bf..b7027eec 100755 --- a/js/lib/geom/circle.js +++ b/js/lib/geom/circle.js | |||
@@ -4,9 +4,12 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot | |||
4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. | 4 | (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. |
5 | </copyright> */ | 5 | </copyright> */ |
6 | 6 | ||
7 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; | 7 | var GeomObj = require("js/lib/geom/geom-obj").GeomObj; |
8 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; | 8 | var ShapePrimitive = require("js/lib/geom/shape-primitive").ShapePrimitive; |
9 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; | 9 | var MaterialsModel = require("js/models/materials-model").MaterialsModel; |
10 | var drawUtils = require("js/helper-classes/3D/draw-utils").DrawUtils; | ||
11 | var vecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; | ||
12 | |||
10 | /////////////////////////////////////////////////////////////////////// | 13 | /////////////////////////////////////////////////////////////////////// |
11 | // Class GLCircle | 14 | // Class GLCircle |
12 | // GL representation of a circle. | 15 | // GL representation of a circle. |
@@ -710,6 +713,49 @@ var Circle = function GLCircle() { | |||
710 | return (MathUtils.fpCmp(distToPt,distToBoundary) <= 0); | 713 | return (MathUtils.fpCmp(distToPt,distToBoundary) <= 0); |
711 | }; | 714 | }; |
712 | 715 | ||
716 | this.getNearPoint = function( pt, dir ) | ||
717 | { | ||
718 | var world = this.getWorld(); | ||
719 | if (!world) throw( "null world in getNearPoint" ); | ||
720 | |||
721 | // the input point and direction are in GL space | ||
722 | // project to the z == 0 plane | ||
723 | var mat = this.getMatrix(); | ||
724 | var plane = [0,0,1,0]; | ||
725 | plane = MathUtils.transformPlane( plane, mat ); | ||
726 | var projPt = MathUtils.vecIntersectPlane ( pt, dir, plane ); | ||
727 | |||
728 | // get the center of the circle in GL space | ||
729 | var ctr = this.getGLCenter(); | ||
730 | |||
731 | // transform the projected point to the plane of the circle | ||
732 | var planePt = MathUtils.transformPoint( projPt, mat ); | ||
733 | |||
734 | // get a matrix mapping the circle to a 2D coordinate system | ||
735 | var normal = [ mat[8], mat[9], mat[10] ]; | ||
736 | var planeMat = drawUtils.getPlaneToWorldMatrix(normal, ctr); | ||
737 | var planeMatInv = glmat4.inverse( planeMat, [] ); | ||
738 | var planePt2D = MathUtils.transformPoint( planePt, planeMatInv ); | ||
739 | |||
740 | // get 2 points on the axes of the oval | ||
741 | var wPt = this.preViewToGL( [this._xOffset + 0.5*this.getWidth(), this._yOffset, 0] ), | ||
742 | hPt = this.preViewToGL( [this._xOffset, this._yOffset + 0.5*this.getHeight(), 0] ); | ||
743 | var w = vecUtils.vecDist( 2, wPt, ctr ), | ||
744 | h = vecUtils.vecDist( 2, hPt, ctr ); | ||
745 | var aspect = w/h; | ||
746 | |||
747 | // get the angle of the projected point relative to the circle | ||
748 | var angle = Math.atan2( planePt2D[1], planePt2D[0]/aspect ); | ||
749 | var degrees = angle*180.0/Math.PI; | ||
750 | |||
751 | // get the corresponding point on the object | ||
752 | var pt = [ Math.cos(angle)*w, Math.sin(angle)*h, 0 ]; | ||
753 | var glPt = MathUtils.transformPoint( pt, planeMat ); | ||
754 | |||
755 | return glPt; | ||
756 | } | ||
757 | |||
758 | /* | ||
713 | this.getNearPoint = function( pt, dir ) { | 759 | this.getNearPoint = function( pt, dir ) { |
714 | var world = this.getWorld(); | 760 | var world = this.getWorld(); |
715 | if (!world) throw( "null world in getNearPoint" ); | 761 | if (!world) throw( "null world in getNearPoint" ); |
@@ -759,6 +805,7 @@ var Circle = function GLCircle() { | |||
759 | 805 | ||
760 | return objPt; | 806 | return objPt; |
761 | }; | 807 | }; |
808 | */ | ||
762 | 809 | ||
763 | this.recalcTexMapCoords = function( vrts, uvs ) { | 810 | this.recalcTexMapCoords = function( vrts, uvs ) { |
764 | var n = vrts.length/3; | 811 | var n = vrts.length/3; |