1 /*
  2   Copyright (c) 2008 Seneca College
  3   Licenced under the MIT License (http://www.c3dl.org/index.php/mit-license/)
  4 */
  5 
  6 /**
  7 	@private
  8 	class Particle.
  9 */
 10 c3dl.Particle = function()
 11 {
 12 	// life properties
 13 	this.age = 0;
 14 	this.lifetime = 0;
 15 	this.alive = false;
 16 	
 17 	// what the particle looks like
 18 	this.color = [0,0,0,0];
 19 	this.size = 0;
 20 	
 21 	// how the particle moves and its location
 22 	this.position = c3dl.makeVector(0,0,0);
 23 	this.velocity = c3dl.makeVector(0,0,0);
 24   this.rotation = 0;
 25 	this.vertices = [1,-1, 0,
 26                   -1,-1, 0,
 27                   -1, 1, 0,
 28                    1, 1, 0];
 29 
 30 	this.transform = [	1,0,0,0,
 31 						0,1,0,0,
 32 						0,0,1,0,
 33 						0,0,0,1];
 34 	
 35 	/**
 36 		@private
 37 		Get the age of this particle in seconds.
 38 
 39 		@returns {float}
 40 	*/				
 41 	this.getAge  = function()
 42 	{
 43 		return this.age;
 44 	}
 45 	
 46 	/**
 47 		@private	
 48 	*/
 49 	this.getPosition = function()
 50 	{
 51 		return this.position;
 52 	}
 53 
 54 	/**
 55 		@private	
 56 	*/
 57 	this.getVelocity = function()
 58 	{
 59 		return this.velocity;
 60 	}
 61 	
 62 	/**
 63 		@private
 64 		Get how long this particle is set to live for.
 65 
 66 		@returns {float}
 67 	*/	
 68 	this.getLifetime = function()
 69 	{
 70 		return this.lifetime;
 71 	}
 72 	
 73 	/**
 74 		@private	
 75 		Get the color of this particle.
 76 
 77 		@returns {Array}
 78 	*/
 79 	this.getColor = function()
 80 	{    
 81     return [this.color[0], this.color[1], this.color[2], this.color[3]];
 82 	}
 83 		
 84 	/**
 85 		@private
 86 	*/
 87 	this.getSize = function()
 88 	{
 89 		return this.size;
 90 	}
 91   
 92   /**
 93   */
 94   this.setSize = function(s)
 95   {
 96     this.size = s;
 97   }
 98 	
 99 	/**
100 		@private	
101 	*/
102 	this.isAlive = function()
103 	{
104 		return this.alive;
105 	}
106 
107 	/**
108 		@private
109 	*/
110 	this.getTransform = function()
111 	{
112 		return this.transform;
113 	}
114 	
115 	/**
116 		@private
117 	*/	
118 	this.getVertices = function()
119 	{
120 		var verts = new Array();
121 		
122 		for (var i = 0; i < 12; i++) //18
123 		{
124 			verts.push(this.vertices[i] + this.position[i%3]);
125 		}
126 
127 		return verts;
128 	}
129 	
130 	/**
131 		@private	
132 	*/
133 	this.setAge = function(age)
134 	{
135 		if(age >= 0)
136 		{
137 			this.age = age;
138 		}
139 	}
140 	
141 	/**
142 		@private
143 	*/
144 	this.setColor = function(c)
145 	{
146 		this.color[0] = c[0];
147 		this.color[1] = c[1];
148 		this.color[2] = c[2];
149     this.color[3] = c[3];
150 	}
151 	
152 	/**
153 		@private
154 	*/
155 	this.setVelocity = function(velocity)
156 	{
157 		this.velocity = velocity;
158 	}
159 
160 	/**
161 		@private
162 	*/
163 	this.setPosition = function(position)
164 	{
165 		this.transform[12] = position[0];
166 		this.transform[13] = position[1];
167 		this.transform[14] = position[2];
168  	}
169 
170 	/**
171 		@private
172 	*/
173 	this.setLifetime = function(lifetime)
174 	{
175 		if(this.lifetime >= 0 )
176 		{
177 			this.lifetime = lifetime;
178 		}
179 	}
180 
181 	/**
182 		@private	
183 	*/
184 	this.setAlive = function(alive)
185 	{
186 		this.alive = alive;
187 	}
188 	
189 	/**
190 		@private
191 	*/
192 	this.translate = function(trans)
193 	{
194 		this.transform[12] += trans[0];
195 		this.transform[13] += trans[1];
196 		this.transform[14] += trans[2];
197 	}
198 	
199 	/**
200 		@private	
201 		Update the position of the particle.
202 		
203 		@param timeStep
204 	*/
205 	this.update = function(timeStep)
206 	{
207 	}
208 	
209 	/**
210 		@private
211 	*/
212 	this.render = function(glCanvas3D)
213 	{		
214 	}
215 }
216