1 /*
2 Copyright (C) 2007, 2010 - Bit-Blot
3 
4 This file is part of Aquaria.
5 
6 Aquaria is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License
8 as published by the Free Software Foundation; either version 2
9 of the License, or (at your option) any later version.
10 
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 
15 See the GNU General Public License for more details.
16 
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
20 */
21 #include "Quad.h"
22 #include "Core.h"
23 
24 #include <assert.h>
25 
26 Vector Quad::renderBorderColor = Vector(1,1,1);
27 
Quad(const std::string & tex,const Vector & pos)28 Quad::Quad(const std::string &tex, const Vector &pos)
29 : RenderObject()
30 {
31 	initQuad();
32 	position = pos;
33 	setTexture(tex);
34 }
35 
36 /*
37 void Quad::initDefaultVBO()
38 {
39 }
40 
41 void Quad::shutdownDefaultVBO()
42 {
43 }
44 */
45 
setSegs(int x,int y,float dgox,float dgoy,float dgmx,float dgmy,float dgtm,bool dgo)46 void Quad::setSegs(int x, int y, float dgox, float dgoy, float dgmx, float dgmy, float dgtm, bool dgo)
47 {
48 	deleteGrid();
49 	if (x == 0 || y == 0)
50 	{
51 		gridTimer = 0;
52 		xDivs = 0;
53 		yDivs = 0;
54 		doUpdateGrid = false;
55 	}
56 	else
57 	{
58 		this->drawGridOffsetX = dgox;
59 		this->drawGridOffsetY = dgoy;
60 		this->drawGridModX = dgmx;
61 		this->drawGridModY = dgmy;
62 		this->drawGridTimeMultiplier = dgtm;
63 		drawGridOut = dgo;
64 		xDivs = x;
65 		yDivs = y;
66 
67 		createGrid(x, y);
68 
69 		gridTimer = 0;
70 
71 		doUpdateGrid = true;
72 	}
73 }
74 
createStrip(bool vert,int num)75 void Quad::createStrip(bool vert, int num)
76 {
77 	strip.resize(num);
78 	stripVert = vert;
79 	resetStrip();
80 }
81 
setStrip(const std::vector<Vector> & st)82 void Quad::setStrip(const std::vector<Vector> &st)
83 {
84 	resetStrip();
85 	for (int i = 0; i < st.size(); i++)
86 	{
87 		if (i < strip.size())
88 		{
89 			strip[i].x += st[i].x;
90 			strip[i].y += st[i].y;
91 		}
92 	}
93 }
94 
createGrid(int xd,int yd)95 void Quad::createGrid(int xd, int yd)
96 {
97 	deleteGrid();
98 
99 	xDivs = xd;
100 	yDivs = yd;
101 
102 	drawGrid = new Vector * [xDivs];
103 	for (int i = 0; i < xDivs; i++)
104 	{
105 		drawGrid[i] = new Vector [yDivs];
106 		for (int j = 0; j < yDivs; j++)
107 		{
108 			drawGrid[i][j].z = 1;
109 		}
110 	}
111 
112 	resetGrid();
113 }
114 
setDrawGridAlpha(int x,int y,float alpha)115 void Quad::setDrawGridAlpha(int x, int y, float alpha)
116 {
117 	if (x < xDivs && x >= 0 && y < yDivs && y >= 0)
118 	{
119 		drawGrid[x][y].z = alpha;
120 	}
121 }
122 
setGridPoints(bool vert,const std::vector<Vector> & points)123 void Quad::setGridPoints(bool vert, const std::vector<Vector> &points)
124 {
125 	if (!drawGrid) return;
126 	resetGrid();
127 	for (int i = 0; i < points.size(); i++)
128 	{
129 		if (!vert) // horz
130 		{
131 			for (int y = 0; y < yDivs; y++)
132 			{
133 				for (int x = 0; x < xDivs; x++)
134 				{
135 					if (x < points.size())
136 					{
137 						drawGrid[x][y] += points[x];
138 					}
139 				}
140 			}
141 		}
142 		else
143 		{
144 			for (int x = 0; x < xDivs; x++)
145 			{
146 				for (int y = 0; y < yDivs; y++)
147 				{
148 					if (y < points.size())
149 					{
150 						drawGrid[x][y] += points[y];
151 					}
152 				}
153 			}
154 		}
155 	}
156 }
157 
getStripSegmentSize()158 float Quad::getStripSegmentSize()
159 {
160 	return (1.0f/(float(strip.size())));
161 }
162 
resetStrip()163 void Quad::resetStrip()
164 {
165 	if (!stripVert)
166 	{
167 		for (int i = 0; i < strip.size(); i++)
168 		{
169 			//float v = (i/(float)(strip.size()-1))-0.5f;
170 			float v = (i/(float(strip.size())));
171 			strip[i].x = v;
172 			strip[i].y = 0;
173 		}
174 	}
175 	else
176 	{
177 		errorLog("VERTICAL STRIP NOT SUPPORTED ^_-");
178 	}
179 }
180 
resetGrid()181 void Quad::resetGrid()
182 {
183 	for (int i = 0; i < xDivs; i++)
184 	{
185 		for (int j = 0; j < yDivs; j++)
186 		{
187 			drawGrid[i][j].x = i/(float)(xDivs-1)-0.5f;
188 			drawGrid[i][j].y = j/(float)(yDivs-1)-0.5f;
189 		}
190 	}
191 }
192 
spawnChildClone(float t)193 void Quad::spawnChildClone(float t)
194 {
195 	if (!this->texture) return;
196 	Quad *q = new Quad;
197 	q->setTexture(this->texture->name);
198 	q->setLife(t+0.1f);
199 	q->setDecayRate(1);
200 	q->width = this->width;
201 	q->height = this->height;
202 	q->alpha = 1;
203 	q->alpha.interpolateTo(0, t);
204 	if (isfh())
205 		q->flipHorizontal();
206 	q->position = this->position;
207 	q->followCamera = this->followCamera;
208 	q->scale = this->scale;
209 	q->offset = this->offset;
210 	q->blendType = this->blendType;
211 
212 	//q->parentManagedPointer = true;
213 	//q->renderBeforeParent = false;
214 	core->getTopStateData()->addRenderObject(q, this->layer);
215 	//addChild(q);
216 }
217 /*
218 smoothly transition to texture
219 by creating a copy of the current quad on top and fading it out
220 */
setTextureSmooth(const std::string & texture,float t)221 void Quad::setTextureSmooth(const std::string &texture, float t)
222 {
223 	if (this->texture && !this->texture->name.empty())
224 	{
225 		spawnChildClone(t);
226 		//core->getTopStateData()->addRenderObject(q, this->layer);
227 	}
228 	this->setTexture(texture);
229 }
230 
initQuad()231 void Quad::initQuad()
232 {
233 	repeatToFillScale = Vector(1,1);
234 	gridType = GRID_WAVY;
235 	gridTimer = 0;
236 	xDivs = 0;
237 	yDivs = 0;
238 
239 	doUpdateGrid = false;
240 
241 	autoWidth = autoHeight = 0;
242 
243 	//debugLog("Quad::initQuad()");
244 
245 	repeatingTextureToFill = false;
246 
247 	drawGrid = 0;
248 
249 	renderBorder = false;
250 	renderCenter = true;
251 	width = 2; height = 2;
252 	//llalpha = Vector(1);
253 	//lralpha = Vector(1);
254 	//ulalpha = Vector(1);
255 	//uralpha = Vector(1);
256 	//oriented = false;
257 	upperLeftTextureCoordinates = Vector(0,0);
258 	lowerRightTextureCoordinates = Vector(1,1);
259 	renderQuad = true;
260 	//debugLog("End Quad::initQuad()");
261 }
262 
Quad()263 Quad::Quad() : RenderObject()
264 {
265 	addType(SCO_QUAD);
266 	borderAlpha = 0.5;
267 	//debugLog("Quad::Quad()");
268 	initQuad();
269 	//debugLog("End Quad::Quad()");
270 	//textureSize = Vector(1,1);
271 }
272 
deleteGrid()273 void Quad::deleteGrid()
274 {
275 	if (drawGrid)
276 	{
277 		for (int i = 0; i < xDivs; i++)
278 		{
279 			delete[] drawGrid[i];
280 		}
281 		delete[] drawGrid;
282 		drawGrid = 0;
283 	}
284 }
285 
destroy()286 void Quad::destroy()
287 {
288 	deleteGrid();
289 	RenderObject::destroy();
290 }
291 
isCoordinateInside(Vector coord,int minSize)292 bool Quad::isCoordinateInside(Vector coord, int minSize)
293 {
294 	Vector realscale = getRealScale();
295 	int hw = fabsf((width)*realscale.x)*0.5f;
296 	int hh = fabsf((height)*realscale.y)*0.5f;
297 	if (hw < minSize)
298 		hw = minSize;
299 	if (hh < minSize)
300 		hh = minSize;
301 
302 	Vector pos = getRealPosition();
303 
304 	if (coord.x >= pos.x - hw && coord.x <= pos.x + hw)
305 	{
306 		if (coord.y >= pos.y - hh && coord.y <= pos.y + hh)
307 		{
308 			return true;
309 		}
310 	}
311 	return false;
312 }
313 
isCoordinateInsideWorld(const Vector & coord,int minSize)314 bool Quad::isCoordinateInsideWorld(const Vector &coord, int minSize)
315 {
316 	int hw = fabsf((width)*getRealScale().x)*0.5f;
317 	int hh = fabsf((height)*getRealScale().y)*0.5f;
318 	if (hw < minSize)
319 		hw = minSize;
320 	if (hh < minSize)
321 		hh = minSize;
322 
323 	Vector pos = getWorldPosition();
324 	if (coord.x >= pos.x + offset.x - hw && coord.x <= pos.x + offset.x + hw)
325 	{
326 		if (coord.y >= pos.y + offset.y - hh && coord.y <= pos.y + offset.y + hh)
327 		{
328 			return true;
329 		}
330 	}
331 	return false;
332 }
333 
isCoordinateInsideWorldRect(const Vector & coord,int w,int h)334 bool Quad::isCoordinateInsideWorldRect(const Vector &coord, int w, int h)
335 {
336 	int hw = w*0.5f;
337 	int hh = h*0.5f;
338 
339 	Vector pos = getWorldPosition();
340 	if (coord.x >= pos.x + offset.x - hw && coord.x <= pos.x + offset.x + hw)
341 	{
342 		if (coord.y >= pos.y + offset.y - hh && coord.y <= pos.y + offset.y + hh)
343 		{
344 			return true;
345 		}
346 	}
347 	return false;
348 }
349 
updateGrid(float dt)350 void Quad::updateGrid(float dt)
351 {
352 	//if (xDivs == 0 && yDivs == 0) return;
353 	if (!doUpdateGrid) return;
354 
355 	if (gridType == GRID_WAVY)
356 	{
357 		gridTimer += dt * drawGridTimeMultiplier;
358 		resetGrid();
359 		int hx = xDivs/2;
360 		for (int x = 0; x < xDivs; x++)
361 		{
362 			float yoffset = x * drawGridOffsetY;
363 			float addY = 0;
364 			if (drawGridModY != 0)
365 				addY = cosf(gridTimer+yoffset)*drawGridModY;
366 			for (int y = 0; y < yDivs; y++)
367 			{
368 				float xoffset = y * drawGridOffsetX;
369 				if (drawGridModX != 0)
370 				{
371 					float addX = (sinf(gridTimer+xoffset)*drawGridModX);
372 					if (drawGridOut && x < hx)
373 						drawGrid[x][y].x += addX;
374 					else
375 						drawGrid[x][y].x -= addX;
376 				}
377 				drawGrid[x][y].y += addY;
378 			}
379 		}
380 	}
381 }
382 
renderGrid()383 void Quad::renderGrid()
384 {
385 	if (xDivs < 2 || yDivs < 2)
386 		return;
387 
388 #ifdef BBGE_BUILD_OPENGL
389 	const float percentX = fabsf(this->lowerRightTextureCoordinates.x - this->upperLeftTextureCoordinates.x);
390 	const float percentY = fabsf(this->upperLeftTextureCoordinates.y - this->lowerRightTextureCoordinates.y);
391 
392 	const float baseX =
393 		(lowerRightTextureCoordinates.x < upperLeftTextureCoordinates.x)
394 		? lowerRightTextureCoordinates.x : upperLeftTextureCoordinates.x;
395 	const float baseY =
396 		(lowerRightTextureCoordinates.y < upperLeftTextureCoordinates.y)
397 		? lowerRightTextureCoordinates.y : upperLeftTextureCoordinates.y;
398 
399 	// NOTE: These are used to avoid repeated expensive divide operations,
400 	// but they may cause rounding error of around 1 part per million,
401 	// which could in theory cause minor graphical glitches with broken
402 	// OpenGL implementations.  --achurch
403 	const float incX = percentX / (float)(xDivs-1);
404 	const float incY = percentY / (float)(yDivs-1);
405 
406 	const float w = this->getWidth();
407 	const float h = this->getHeight();
408 
409 	const float red   = this->color.x;
410 	const float green = this->color.y;
411 	const float blue  = this->color.z;
412 	const float alpha = this->alpha.x * this->alphaMod;
413 
414 	/*
415 	glDisable(GL_BLEND);
416 	glDisable(GL_CULL_FACE);
417 	*/
418 	glBegin(GL_QUADS);
419 	float u0 = baseX;
420 	float u1 = u0 + incX;
421 	for (int i = 0; i < (xDivs-1); i++, u0 = u1, u1 += incX)
422 	{
423 		float v0 = 1 - percentY + baseY;
424 		float v1 = v0 + incY;
425 		for (int j = 0; j < (yDivs-1); j++, v0 = v1, v1 += incY)
426 		{
427 			if (drawGrid[i][j].z != 0 || drawGrid[i][j+1].z != 0 || drawGrid[i+1][j].z != 0 || drawGrid[i+1][j+1].z != 0)
428 			{
429 
430 				glColor4f(red, green, blue, alpha*drawGrid[i][j].z);
431 				glTexCoord2f(u0, v0);
432 					//glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u0-baseX, v0-baseY);
433 					//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,0);
434 				glVertex2f(w*drawGrid[i][j].x,		h*drawGrid[i][j].y);
435 				//
436 				glColor4f(red, green, blue, alpha*drawGrid[i][j+1].z);
437 				glTexCoord2f(u0, v1);
438 					//glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u0-baseX, v1-baseY);
439 					//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,0,(float)(screenHeight/(yDivs-1))/16);
440 				glVertex2f(w*drawGrid[i][j+1].x,		h*drawGrid[i][j+1].y);
441 				//
442 				glColor4f(red, green, blue, alpha*drawGrid[i+1][j+1].z);
443 				glTexCoord2f(u1, v1);
444 					//glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u1-baseX, v1-baseY);
445 					//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,(float)(screenHeight/(yDivs-1))/16);
446 				glVertex2f(w*drawGrid[i+1][j+1].x,	h*drawGrid[i+1][j+1].y);
447 				//
448 				glColor4f(red, green, blue, alpha*drawGrid[i+1][j].z);
449 				glTexCoord2f(u1, v0);
450 					//glMultiTexCoord2fARB(GL_TEXTURE0_ARB, u1-baseX, v0-baseY);
451 					//glMultiTexCoord2fARB(GL_TEXTURE1_ARB,(float)(screenWidth/(xDivs-1))/16,0);
452 				glVertex2f(w*drawGrid[i+1][j].x,		h*drawGrid[i+1][j].y);
453 			}
454 		}
455 	}
456 	glEnd();
457 
458 	// debug points
459 	if (RenderObject::renderCollisionShape)
460 	{
461 		glBindTexture(GL_TEXTURE_2D, 0);
462 		glPointSize(2);
463 		glColor3f(1,0,0);
464 		glBegin(GL_POINTS);
465 			for (int i = 0; i < (xDivs-1); i++)
466 			{
467 				for (int j = 0; j < (yDivs-1); j++)
468 				{
469 					glVertex2f(w*drawGrid[i][j].x,		h*drawGrid[i][j].y);
470 					glVertex2f(w*drawGrid[i][j+1].x,		h*drawGrid[i][j+1].y);
471 					glVertex2f(w*drawGrid[i+1][j+1].x,	h*drawGrid[i+1][j+1].y);
472 					glVertex2f(w*drawGrid[i+1][j].x,		h*drawGrid[i+1][j].y);
473 				}
474 			}
475 		glEnd();
476 		if (texture)
477 			glBindTexture(GL_TEXTURE_2D, texture->textures[0]);
478 	}
479 #endif
480 }
481 
repeatTextureToFill(bool on)482 void Quad::repeatTextureToFill(bool on)
483 {
484 	repeatingTextureToFill = on;
485 	repeatTexture = on;
486 	refreshRepeatTextureToFill();
487 
488 }
489 
onRender()490 void Quad::onRender()
491 {
492 	if (!renderQuad) return;
493 
494 #ifdef BBGE_BUILD_OPENGL
495 
496 	float _w2 = width/2.0f;
497 	float _h2 = height/2.0f;
498 
499 	if (!strip.empty())
500 	{
501 		//glDisable(GL_BLEND);gggg
502 		//glDisable(GL_CULL_FACE);
503 
504 		const float texBits = 1.0f / (strip.size()-1);
505 
506 		glBegin(GL_QUAD_STRIP);
507 
508 		if (!stripVert)
509 		{
510 			for (int i = 0; i < strip.size(); i++)
511 			{
512 				glTexCoord2f(texBits*i, 0);
513 				glVertex2f(strip[i].x*width-_w2,  strip[i].y*_h2*10 - _h2);
514 				glTexCoord2f(texBits*i, 1);
515 				glVertex2f(strip[i].x*width-_w2,  strip[i].y*_h2*10 + _h2);
516 			}
517 		}
518 		glEnd();
519 
520 		//glEnable(GL_CULL_FACE);
521 		glBindTexture( GL_TEXTURE_2D, 0 );
522 		glColor4f(1,0,0,1);
523 		glPointSize(64);
524 
525 		glBegin(GL_POINTS);
526 		for (int i = 0; i < strip.size(); i++)
527 		{
528 			glVertex2f((strip[i].x*width)-_w2, strip[i].y*height);
529 		}
530 		glEnd();
531 	}
532 	else
533 	{
534 		if (!drawGrid)
535 		{
536 			glBegin(GL_QUADS);
537 			{
538 				glTexCoord2f(upperLeftTextureCoordinates.x, 1.0f-upperLeftTextureCoordinates.y);
539 				glVertex2f(-_w2, +_h2);
540 
541 				glTexCoord2f(lowerRightTextureCoordinates.x, 1.0f-upperLeftTextureCoordinates.y);
542 				glVertex2f(+_w2, +_h2);
543 
544 				glTexCoord2f(lowerRightTextureCoordinates.x, 1.0f-lowerRightTextureCoordinates.y);
545 				glVertex2f(+_w2, -_h2);
546 
547 				glTexCoord2f(upperLeftTextureCoordinates.x, 1.0f-lowerRightTextureCoordinates.y);
548 				glVertex2f(-_w2, -_h2);
549 			}
550 			glEnd();
551 		}
552 		else
553 		{
554 			renderGrid();
555 		}
556 	}
557 
558 	if (renderBorder)
559 	{
560 		glLineWidth(2);
561 
562 		glBindTexture(GL_TEXTURE_2D, 0);
563 
564 		glColor4f(renderBorderColor.x, renderBorderColor.y, renderBorderColor.z, borderAlpha*alpha.x*alphaMod);
565 
566 		if (renderCenter)
567 		{
568 			glPointSize(16);
569 			glBegin(GL_POINTS);
570 				glVertex2f(0,0);
571 			glEnd();
572 		}
573 
574 		glColor4f(renderBorderColor.x, renderBorderColor.y, renderBorderColor.z, 1*alpha.x*alphaMod);
575 		glBegin(GL_LINES);
576 			glVertex2f(-_w2, _h2);
577 			glVertex2f(_w2, _h2);
578 			glVertex2f(_w2, -_h2);
579 			glVertex2f(_w2, _h2);
580 			glVertex2f(-_w2, -_h2);
581 			glVertex2f(-_w2, _h2);
582 			glVertex2f(-_w2, -_h2);
583 			glVertex2f(_w2, -_h2);
584 		glEnd();
585 		RenderObject::lastTextureApplied = 0;
586 	}
587 
588 #endif
589 #ifdef BBGE_BUILD_DIRECTX
590 	//core->setColor(color.x, color.y, color.z, alpha.x);
591 	//if (!children.empty() || useDXTransform)
592 	if (true)
593 	{
594 		if (this->texture)
595 		{
596 			if (upperLeftTextureCoordinates.x != 0 || upperLeftTextureCoordinates.y != 0
597 				|| lowerRightTextureCoordinates.x != 1 || lowerRightTextureCoordinates.y != 1)
598 			{
599 				//core->blitD3DEx(this->texture->d3dTexture, fontDrawSize/2, fontDrawSize/2, u, v-ybit, u+xbit, v+ybit-ybit);
600 				core->blitD3DEx(this->texture->d3dTexture, width, height, upperLeftTextureCoordinates.x, upperLeftTextureCoordinates.y, lowerRightTextureCoordinates.x, lowerRightTextureCoordinates.y);
601 			}
602 			else
603 				core->blitD3D(this->texture->d3dTexture, width, height);
604 		}
605 		else
606 		{
607 			core->blitD3D(0, width, height);
608 		}
609 	}
610 	else
611 	{
612 		if (this->texture)
613 			core->blitD3DPreTrans(this->texture->d3dTexture, position.x+offset.x, position.y+offset.y, width*scale.x, width.y*scale.y);
614 		else
615 			core->blitD3DPreTrans(0, position.x+offset.x, position.y+offset.y, width*scale.x, width.y*scale.y);
616 	}
617 
618 	/*
619 	if (this->texture)
620 	{
621 		core->getD3DSprite()->Begin(D3DXSPRITE_ALPHABLEND);
622 		D3DXVECTOR2 scaling((1.0f/float(this->texture->width))*width*scale.x,
623 			(1.0f/float(this->texture->height))*height*scale.y);
624 		if (isfh())
625 			scaling.x = -scaling.x;
626 		D3DXVECTOR2 spriteCentre=D3DXVECTOR2((this->texture->width/2), (this->texture->height/2));
627 		///scale.x
628 		//D3DXVECTOR2 trans=D3DXVECTOR2(position.x, position.y);
629 
630 
631 		if (blendType == BLEND_DEFAULT)
632 		{
633 			core->getD3DDevice()->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
634 			core->getD3DDevice()->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_INVSRCALPHA );
635 		}
636 		else
637 		{
638 			core->getD3DDevice()->SetRenderState( D3DRS_SRCBLEND, D3DBLEND_SRCALPHA );
639 			core->getD3DDevice()->SetRenderState( D3DRS_DESTBLEND, D3DBLEND_ONE );
640 		}
641 
642 		D3DXVECTOR2 rotationCentre = spriteCentre;
643 		D3DXVECTOR2 trans=D3DXVECTOR2(position.x,position.y) - spriteCentre;
644 		if (followCamera != 1)
645 		{
646 			trans.x -= core->cameraPos.x;
647 			trans.y -= core->cameraPos.y;
648 		}
649 		D3DXMATRIX mat, scale, final;
650 		//D3DXVECTOR2 centre = trans + spriteCentre;
651 		float rotation = (this->rotation.z*PI)/180.0f;
652 		//D3DXVECTOR2 scaling((1.0f/float(this->texture->width))*width*scale.x,(1.0f/float(this->texture->height))*height*scale.y);
653 
654 		//D3DXVECTOR2 scaling(1,1);
655 		const D3DCOLOR d3dColor=D3DCOLOR_ARGB(int(alpha.x*255), int(color.x*255), int(color.y*255), int(color.z*255));
656 		//const D3DCOLOR d3dColor=D3DCOLOR_ARGB(int(alpha.x*255), int(color.x*255), int(color.y*255), int(color.z*255));
657 		FLOAT scalingRotation = 0;
658 		//D3DXMatrixTransformation2D(&mat,NULL,0.0,&scaling,&spriteCentre,rotation,&trans);
659 		D3DXMatrixTransformation2D(&mat,
660 			&spriteCentre,
661 			scalingRotation,
662 			&scaling,
663 			&spriteCentre,
664 			rotation,
665 			&trans
666 		);
667 
668 		if (followCamera != 1)
669 		{
670 			D3DXMatrixScaling(&scale,core->globalScale.x*core->globalResolutionScale.x,core->globalScale.y*core->globalResolutionScale.y,1);
671 			D3DXMatrixMultiply(&final, &mat, &scale);
672 
673 			core->getD3DSprite()->SetTransform(&final);
674 		}
675 		else
676 		{
677 			D3DXMatrixScaling(&scale,core->globalResolutionScale.x,core->globalResolutionScale.y,1);
678 			D3DXMatrixMultiply(&final, &mat, &scale);
679 			core->getD3DSprite()->SetTransform(&final);
680 		}
681 
682 
683 		//mat = scale * mat;
684 
685 		if (this->texture)
686 		{
687 			core->getD3DSprite()->Draw(this->texture->d3dTexture,NULL,NULL,NULL,d3dColor);//0xFFFFFFFF);//d3dColor);
688 			core->getD3DSprite()->End();
689 		}
690 		else
691 		{
692 			core->getD3DSprite()->End();
693 			D3DRECT rect;
694 			rect.x1 = trans.x - this->width/2;
695 			rect.x2 = trans.x + this->width/2;
696 			rect.y1 = trans.y - this->height/2;
697 			rect.y2 = trans.y + this->height/2;
698 			core->getD3DDevice()->Clear(1,&rect,D3DCLEAR_TARGET,d3dColor,0,0);
699 		}
700 		//core->getD3DSprite()->End();
701 	}
702 	*/
703 
704 #endif
705 }
706 
707 
flipHorizontal()708 void Quad::flipHorizontal()
709 {
710 	RenderObject::flipHorizontal();
711 }
712 
flipVertical()713 void Quad::flipVertical()
714 {
715 	if (!_fv)
716 	{
717 		lowerRightTextureCoordinates.y = 0;
718 		upperLeftTextureCoordinates.y = 1;
719 	}
720 	else
721 	{
722 		lowerRightTextureCoordinates.y = 1;
723 		upperLeftTextureCoordinates.y = 0;
724 	}
725 	RenderObject::flipVertical();
726 }
727 
refreshRepeatTextureToFill()728 void Quad::refreshRepeatTextureToFill()
729 {
730 	if (repeatingTextureToFill && texture)
731 	{
732 		upperLeftTextureCoordinates.x = texOff.x;
733 		upperLeftTextureCoordinates.y = texOff.y;
734 		lowerRightTextureCoordinates.x = (width*scale.x*repeatToFillScale.x)/texture->width + texOff.x;
735 		lowerRightTextureCoordinates.y = (height*scale.y*repeatToFillScale.y)/texture->height + texOff.y;
736 	}
737 	else
738 	{
739 		if (fabsf(lowerRightTextureCoordinates.x) > 1 || fabsf(lowerRightTextureCoordinates.y)>1)
740 			lowerRightTextureCoordinates = Vector(1,1);
741 	}
742 }
743 
reloadDevice()744 void Quad::reloadDevice()
745 {
746 	RenderObject::reloadDevice();
747 }
748 
onUpdate(float dt)749 void Quad::onUpdate(float dt)
750 {
751 	RenderObject::onUpdate(dt);
752 
753 	if (autoWidth == AUTO_VIRTUALWIDTH)
754 		width = core->getVirtualWidth();
755 	else if (autoWidth == AUTO_VIRTUALHEIGHT)
756 		width = core->getVirtualHeight();
757 
758 	if (autoHeight == AUTO_VIRTUALWIDTH)
759 		height = core->getVirtualWidth();
760 	else if (autoHeight == AUTO_VIRTUALHEIGHT)
761 		height = core->getVirtualHeight();
762 
763 
764 	refreshRepeatTextureToFill();
765 
766 	lowerRightTextureCoordinates.update(dt);
767 	upperLeftTextureCoordinates.update(dt);
768 
769 	if (drawGrid && alpha.x > 0 && alphaMod > 0)
770 	{
771 		updateGrid(dt);
772 	}
773 }
774 
setWidthHeight(float w,float h)775 void Quad::setWidthHeight(float w, float h)
776 {
777 	if (h == -1)
778 		height = w;
779 	else
780 		height = h;
781 	width = w;
782 }
783 
setWidth(float w)784 void Quad::setWidth(float w)
785 {
786 	width = w;
787 }
788 
setHeight(float h)789 void Quad::setHeight(float h)
790 {
791 	height = h;
792 }
793 
onSetTexture()794 void Quad::onSetTexture()
795 {
796 	if (texture)
797 	{
798 		width = this->texture->width;
799 		height = this->texture->height;
800 	}
801 	else
802 	{
803 		width = 64;
804 		height = 64;
805 	}
806 }
807 
PauseQuad()808 PauseQuad::PauseQuad() : Quad(), pauseLevel(0)
809 {
810 	addType(SCO_PAUSEQUAD);
811 }
812 
onUpdate(float dt)813 void PauseQuad::onUpdate(float dt)
814 {
815 	if (core->particlesPaused <= pauseLevel)
816 	{
817 		Quad::onUpdate(dt);
818 	}
819 }
820 
821