1 /* 2 Copyright (c) 2009 Seneca College 3 Licenced under the MIT License (http://www.c3dl.org/index.php/mit-license/) 4 */ 5 6 /** 7 @class c3dl.Line represents a line segment in 3D space. The beginning and ending 8 coordinates have their own color. If the beginning and ending colors are different, 9 the line will be drawn with a gradient color change.<br /> 10 <br /> 11 The default color of the line is black and the default coordinates 12 are both [0,0,0], which results in the line not being rendered.The default width 13 is 1 pixel. 14 */ 15 c3dl.Line = function() 16 { 17 // begin and end coordinates in the order [x,y,z]. 18 this.coords = [ 0,0,0, 19 0,0,0]; 20 21 // begin and end colors in the order [r,g,b]. 22 this.colors = [ 0,0,0, 23 0,0,0]; 24 25 // Will the line be drawn on render? 26 this.visible = true; 27 28 // The default width of the line is 1 pixel. 29 this.width = 1.0; 30 31 /** 32 Set the begin and end coordinates. 33 34 @param {Array} beginCoord Array of 3 values in the order [x,y,z], where 35 the line segment begins. 36 37 @param {Array} endCoord Array of 3 values in the order [x,y,z], where 38 the line segment ends. 39 */ 40 this.setCoordinates = function(beginCoord, endCoord) 41 { 42 if( beginCoord.length == 3 && endCoord.length == 3) 43 { 44 this.coords[0] = beginCoord[0]; 45 this.coords[1] = beginCoord[1]; 46 this.coords[2] = beginCoord[2]; 47 48 this.coords[3] = endCoord[0]; 49 this.coords[4] = endCoord[1]; 50 this.coords[5] = endCoord[2]; 51 } 52 else 53 { 54 c3dl.debug.logWarning("invalid values passed to Line::setCoordinates()"); 55 } 56 } 57 58 59 /** 60 Set the color of each end of the line. A line can rendered using a solid color (by assigning 61 both ends of the line the same color), or a color gradient from beginColor and endColor. 62 The beginColor sets the color of the first coordinate of the line. The endColor sets the 63 end coordinate of the line. The rendered pixels in between transition from one color to 64 the other. 65 66 @param {Array} beginColor An array of 3 values in the order [r,g,b]. Each component must 67 range from 0.0 to 1.0. 68 69 @param {Array} endColor An array of 3 values in the order [r,g,b]. Each component must 70 range from 0.0 to 1.0. 71 */ 72 this.setColors = function(beginColor, endColor) 73 { 74 if( beginColor.length == 3 && endColor.length == 3) 75 { 76 this.colors[0] = beginColor[0]; 77 this.colors[1] = beginColor[1]; 78 this.colors[2] = beginColor[2]; 79 80 this.colors[3] = endColor[0]; 81 this.colors[4] = endColor[1]; 82 this.colors[5] = endColor[2]; 83 } 84 else 85 { 86 c3dl.debug.logWarning("invalid values passed to Line::setColors"); 87 } 88 } 89 90 /** 91 Set the line's visibility. 92 93 @param {bool} visible true if the line should be rendered. 94 */ 95 this.setVisible = function(visible) 96 { 97 this.visible = visible; 98 } 99 100 /** 101 Get the visibility of the line. 102 103 @returns {bool} true if the line is rendered, otherwise false. 104 */ 105 this.isVisible = function() 106 { 107 return this.visible; 108 } 109 110 /** 111 Set the width the line in pixels. A line width of 1 is guaranteed to be supported. 112 However, the maximum supported width for lines is implementation dependent. To get the 113 maximum supported line width, call Renderer's getMaxLineWidth() once the scene and renderer 114 have been initialized. 115 116 @param {float} width Specified in pixels. Must be at least 1. Will be rounded to 117 the nearest integer. 118 */ 119 this.setWidth = function(width) 120 { 121 // if a line width of 0 is passed to opengl, it will use a line with of 1, so 122 // don't bother allowing the user to specify anything below 1. 123 if(width >= 1) 124 { 125 this.width = width; 126 } 127 } 128 129 /** 130 Get the width the line in pixels. 131 132 @returns {float} The width of the line in pixels. 133 */ 134 this.getWidth = function() 135 { 136 return this.width; 137 } 138 139 /** 140 Get the beginning and ending coordinates. 141 142 @returns {Array} Array of 6 values. first 3 values represent the coordinates 143 of the beginning of the line. The last 3 values represent the coordinates 144 of the end of the line in the order [x,y,z]. 145 */ 146 this.getCoordinates = function() 147 { 148 return [this.coords[0],this.coords[1],this.coords[2], 149 this.coords[3],this.coords[4],this.coords[5]]; 150 } 151 152 /** 153 Get beginning and ending colors of the line. 154 155 @returns {Array} Array of 6 values. First 3 represent beginning color, last 3 represent 156 ending color in the order [r,g,b]. 157 */ 158 this.getColors = function() 159 { 160 return [this.colors[0],this.colors[1],this.colors[2], 161 this.colors[3],this.colors[4],this.colors[5]]; 162 } 163 164 /** 165 */ 166 this.getObjectType = function() 167 { 168 return c3dl.LINE; 169 } 170 } 171