PageRenderTime 38ms CodeModel.GetById 2ms app.highlight 30ms RepoModel.GetById 1ms app.codeStats 0ms

/src/org/mt4j/components/visibleComponents/shapes/MTPolygon.java

http://mt4j.googlecode.com/
Java | 693 lines | 360 code | 101 blank | 232 comment | 73 complexity | ad48ac71dd64784a8383a1f476672cab MD5 | raw file
  1/***********************************************************************
  2 * mt4j Copyright (c) 2008 - 2009, C.Ruff, Fraunhofer-Gesellschaft All rights reserved.
  3 *  
  4 *   This program is free software: you can redistribute it and/or modify
  5 *   it under the terms of the GNU General Public License as published by
  6 *   the Free Software Foundation, either version 3 of the License, or
  7 *   (at your option) any later version.
  8 *
  9 *   This program is distributed in the hope that it will be useful,
 10 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 11 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 12 *   GNU General Public License for more details.
 13 *
 14 *   You should have received a copy of the GNU General Public License
 15 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 16 *
 17 ***********************************************************************/
 18package org.mt4j.components.visibleComponents.shapes;
 19
 20import java.nio.FloatBuffer;
 21import java.nio.IntBuffer;
 22
 23import javax.media.opengl.GL;
 24
 25import org.mt4j.components.bounds.BoundingSphere;
 26import org.mt4j.components.bounds.IBoundingShape;
 27import org.mt4j.components.bounds.OrientedBoundingBox;
 28import org.mt4j.components.css.style.CSSStyle;
 29import org.mt4j.util.MT4jSettings;
 30import org.mt4j.util.MTColor;
 31import org.mt4j.util.math.BezierVertex;
 32import org.mt4j.util.math.Ray;
 33import org.mt4j.util.math.Tools3D;
 34import org.mt4j.util.math.ToolsGeometry;
 35import org.mt4j.util.math.Vector3D;
 36import org.mt4j.util.math.Vertex;
 37import org.mt4j.util.opengl.GLTexture;
 38
 39import processing.core.PApplet;
 40import processing.core.PGraphics;
 41
 42/**
 43 * This class represents a planar, convex polygon. The user of this class
 44 * is responsible for the polygon being planar and convex.
 45 * Methods like picking and others depend on these facts.
 46 * If <code>setNoFill(true)</code> is used and the polygon isnt closed, the
 47 * class can also be used to display a poly-line.
 48 * 
 49 * @author Christopher Ruff
 50 */
 51public class MTPolygon extends MTCSSStylableShape{
 52	
 53	/** The normal. */
 54	private Vector3D normal;
 55	
 56	/** The normal dirty. */
 57	private boolean normalDirty;
 58	
 59	/**
 60	 * Instantiates a new mT polygon.
 61	 * 
 62	 * @param vertices the vertices
 63	 * @param pApplet the applet
 64	 * @deprecated constructor will be deleted! Please , use the constructor with the PApplet instance as the first parameter.
 65	 */
 66	public MTPolygon(Vertex[] vertices, PApplet pApplet) {
 67		this(pApplet,vertices);
 68	}
 69	
 70	/**
 71	 * Instantiates a new mT polygon.
 72	 * 
 73	 * @param pApplet the applet
 74	 * @param vertices the vertices
 75	 */
 76	public MTPolygon(PApplet pApplet, Vertex[] vertices) { //Added for consitency
 77		super(pApplet, vertices);
 78		
 79		this.normalDirty = true;
 80//		this.hasVertexColor = false;//Dont set here, gets set to false after being true in super constructor
 81		
 82		this.setTextureEnabled(false);
 83		this.setTextureMode(PApplet.NORMALIZED);
 84		
 85		this.setEnabled(true);
 86		this.setVisible(true);
 87		
 88		this.setDrawSmooth(true);
 89		this.setNoStroke(false);
 90		this.setNoFill(false);
 91		this.setName("Polygon");
 92		
 93		this.setBoundsBehaviour(AbstractShape.BOUNDS_DONT_USE);
 94//		this.setBoundsBehaviour(AbstractShape.BOUNDS_ONLY_CHECK);
 95	}
 96	
 97	
 98	/* (non-Javadoc)
 99	 * @see org.mt4j.components.visibleComponents.shapes.AbstractShape#computeDefaultBounds()
100	 */
101	@Override
102	protected IBoundingShape computeDefaultBounds(){
103		return new BoundingSphere(this);
104	}
105	
106	
107	/* (non-Javadoc)
108	 * @see org.mt4j.components.visibleComponents.shapes.AbstractShape#setGeometryInfo(org.mt4j.components.visibleComponents.GeometryInfo)
109	 */
110	@Override
111	public void setGeometryInfo(GeometryInfo geometryInfo) {
112		super.setGeometryInfo(geometryInfo);
113		this.normalDirty = true;
114		
115		//FIXME TEST 
116		//If we use processings drawing we have to check if the geometry has individually colored vertices
117		if (!MT4jSettings.getInstance().isOpenGlMode() || (MT4jSettings.getInstance().isOpenGlMode() && this.isUseDirectGL())){
118			this.hasVertexColor = this.hasVertexColors(geometryInfo);
119		}
120	}
121	
122	//FIXME TEST
123	/** The has vertex color. */
124	private boolean hasVertexColor;
125	
126	/**
127	 * Checks for vertex colors.
128	 * 
129	 * @param geometryInfo the geometry info
130	 * @return true, if successful
131	 */
132	private boolean hasVertexColors(GeometryInfo geometryInfo){
133		Vertex[] verts = geometryInfo.getVertices();
134        for (Vertex vertex : verts) {
135            if (vertex.getR() != Vertex.DEFAULT_RED_COLOR_COMPONENT ||
136                    vertex.getG() != Vertex.DEFAULT_GREEN_COLOR_COMPONENT ||
137                    vertex.getB() != Vertex.DEFAULT_BLUE_COLOR_COMPONENT ||
138                    vertex.getA() != Vertex.DEFAULT_ALPHA_COLOR_COMPONENT
139                    ) {
140                return true;
141            }
142        }
143		return false;
144	}
145	
146	
147	/* (non-Javadoc)
148	 * @see org.mt4j.components.visibleComponents.shapes.AbstractShape#setUseDirectGL(boolean)
149	 */
150	@Override
151	public void setUseDirectGL(boolean drawPureGL) {
152		super.setUseDirectGL(drawPureGL);
153		//If we use processings drawing we have to check if the geometry has individually colored vertices
154		if (!drawPureGL && !this.hasVertexColor){ 
155			this.hasVertexColor = this.hasVertexColors(this.getGeometryInfo());
156		}
157	}
158
159	/* (non-Javadoc)
160	 * @see org.mt4j.components.visibleComponents.shapes.AbstractShape#setVertices(org.mt4j.util.math.Vertex[])
161	 */
162	@Override
163	public void setVertices(Vertex[] vertices) {
164		super.setVertices(vertices);
165		this.normalDirty = true;
166	}
167
168	
169	/* (non-Javadoc)
170	 * @see org.mt4j.components.visibleComponents.AbstractVisibleComponent#drawComponent(processing.core.PGraphics)
171	 */
172	@Override
173	public void drawComponent(PGraphics g) {
174//		super.drawComponent(g);
175		
176		PApplet renderer = this.getRenderer();
177				
178		//Draw the shape
179		if (MT4jSettings.getInstance().isOpenGlMode()   
180		   && this.isUseDirectGL()){
181			GL gl = Tools3D.beginGL(renderer);
182			
183			//Draw with PURE opengl
184			if (this.isUseDisplayList() /*&& this.getDisplayListIDs() != null && this.getDisplayListIDs()[0] != -1 && this.getDisplayListIDs()[1] != -1*/){
185				int[] displayLists = this.getGeometryInfo().getDisplayListIDs();
186				//Use Display Lists
187				if (!this.isNoFill()  && displayLists[0] != -1) 
188					gl.glCallList(displayLists[0]); //Draw fill
189				if (!this.isNoStroke()  && displayLists[1] != -1)
190					gl.glCallList(displayLists[1]); //Draw outline
191			}else{
192				//Use Vertex Arrays or VBOs
193				this.drawPureGl(gl);
194			}
195			Tools3D.endGL(renderer);
196			
197		}else{ //Draw with pure proccessing commands...
198			MTColor fillColor = this.getFillColor();
199			MTColor strokeColor = this.getStrokeColor();
200			g.fill(fillColor.getR(), fillColor.getG(), fillColor.getB(), fillColor.getAlpha());
201			g.stroke(strokeColor.getR(), strokeColor.getG(), strokeColor.getB(), strokeColor.getAlpha());
202			g.strokeWeight(this.getStrokeWeight());
203
204			if (MT4jSettings.getInstance().isOpenGlMode())
205				if (this.isDrawSmooth()) 
206					g.smooth();
207				else 			
208					g.noSmooth();
209
210			//NOTE: if noFill() and noStroke()->absolutely nothing will be drawn-even when texture is set
211			if (this.isNoFill())	
212				g.noFill();
213			if (this.isNoStroke()) 	
214				g.noStroke();
215
216			//Set the tint values 
217			g.tint(fillColor.getR(), fillColor.getG(), fillColor.getB(), fillColor.getAlpha());
218
219			//handles the drawing of the vertices with the texture coordinates
220			//try doing a smoothed poly outline with opengl
221			if (
222				MT4jSettings.getInstance().isOpenGlMode()  &&
223				 this.isDrawSmooth() &&
224				 !this.isNoStroke() &&
225				 !this.isUseDirectGL()
226			){
227				//draw FILL of polygon, without smooth or stroke
228				g.noStroke();
229				g.noSmooth();
230				drawWithProcessing(g); 
231				
232				// DRAW SMOOTHED THE STROKE outline OF THE POLYGON WIHTOUT FILL OR TEXTURE
233				g.smooth();
234				g.noFill(); 
235				g.stroke(strokeColor.getR(), strokeColor.getG(), strokeColor.getB(), strokeColor.getAlpha());
236				drawWithProcessing(g); 
237
238				g.noSmooth();
239//				//restore fill color
240//				g.fill(fillColor.getR(), fillColor.getG(), fillColor.getB(), fillColor.getAlpha());
241			}else{
242				drawWithProcessing(g);
243			}//end if gl and smooth
244
245			//reSet the tint values to defaults 
246			g.tint(255, 255, 255, 255);
247
248			if (/*MT4jSettings.getInstance().isOpenGlMode() &&*/ this.isDrawSmooth())
249				g.noSmooth(); //because of tesselation bug/lines visibile in shapes
250		}
251		
252	}
253	
254	
255	
256	/**
257	 * loops through all the vertices of the polygon
258	 * and uses processings "vertex()" command to set their position
259	 * and texture.
260	 * @param g PGraphics
261	 */
262	protected void drawWithProcessing(PGraphics g){
263		g.beginShape(PApplet.POLYGON); //TODO make setbeginshape() behavior settable
264		if (this.getTexture() != null && this.isTextureEnabled()){
265			g.texture(this.getTexture());
266			g.textureMode(this.getTextureMode());
267		}
268		Vertex[] vertices = this.getVerticesLocal();
269
270        for (Vertex v : vertices) {
271            //FIXME TEST
272            if (this.hasVertexColor) {
273                g.fill(v.getR(), v.getG(), v.getB(), v.getA()); //takes vertex colors into account
274            }
275
276            if (this.isTextureEnabled())
277                g.vertex(v.x, v.y, v.z, v.getTexCoordU(), v.getTexCoordV());
278            else {
279                if (v.getType() == Vector3D.BEZIERVERTEX) {
280                    BezierVertex b = (BezierVertex) v;
281                    g.bezierVertex(
282                            b.getFirstCtrlPoint().x, b.getFirstCtrlPoint().y, b.getFirstCtrlPoint().z,
283                            b.getSecondCtrlPoint().x, b.getSecondCtrlPoint().y, b.getSecondCtrlPoint().z,
284                            b.x, b.y, b.z);
285                } else
286                    g.vertex(v.x, v.y, v.z);
287            }
288        }
289		g.endShape();
290	}
291	
292	
293	/*
294	 *TODO
295	 * To do multi-texture:
296	 * 
297	 * glClientActiveTexture(GL_TEXTURE1);
298	 * glEnableClientState(GL_TEXTURE_COORD_ARRAY);
299	 * glTexCoordPointer(2, GL_FLOAT, sizeof(myVertex), &myQuad[0].s1);
300	 *
301	 */
302
303	/**
304	 * Draws with pure opengl commands (without using processing) using vertex arrays, or vbos for speed.
305	 * It is assumed that PGraphicsOpenGL's beginGL() method has already been called
306	 * before calling this method!
307	 * 
308	 * @param gl the gl
309	 */
310	protected void drawPureGl(GL gl){
311//		/*
312		//Get display array/buffer pointers
313		FloatBuffer tbuff 			= this.getGeometryInfo().getTexBuff();
314		FloatBuffer vertBuff 		= this.getGeometryInfo().getVertBuff();
315		FloatBuffer colorBuff 		= this.getGeometryInfo().getColorBuff();
316		FloatBuffer strokeColBuff 	= this.getGeometryInfo().getStrokeColBuff();
317		IntBuffer indexBuff 		= this.getGeometryInfo().getIndexBuff();
318		
319		//Enable Pointers, set vertex array pointer
320		gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
321		gl.glEnableClientState(GL.GL_COLOR_ARRAY);
322		if (this.isUseVBOs()){//Vertices
323			gl.glBindBuffer(GL.GL_ARRAY_BUFFER, this.getGeometryInfo().getVBOVerticesName());
324			gl.glVertexPointer(3, GL.GL_FLOAT, 0, 0);
325		}else{
326			gl.glVertexPointer(3, GL.GL_FLOAT, 0, vertBuff);
327		}
328		
329		//Default texture target
330		int textureTarget = GL.GL_TEXTURE_2D;
331		
332		/////// DRAW SHAPE ///////
333		if (!this.isNoFill()){ 
334			boolean textureDrawn = false;
335			if (this.isTextureEnabled()
336				&& this.getTexture() != null 
337				&& this.getTexture() instanceof GLTexture) //Bad for performance?
338			{
339				GLTexture tex = (GLTexture)this.getTexture();
340				textureTarget = tex.getTextureTarget();
341				
342				//tells opengl which texture to reference in following calls from now on!
343				//the first parameter is eigher GL.GL_TEXTURE_2D or ..1D
344				gl.glEnable(textureTarget);
345				gl.glBindTexture(textureTarget, tex.getTextureID());
346				
347				gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
348				
349				if (this.isUseVBOs()){//Texture
350					gl.glBindBuffer(GL.GL_ARRAY_BUFFER, this.getGeometryInfo().getVBOTextureName());
351					gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, 0);
352				}else
353					gl.glTexCoordPointer(2, GL.GL_FLOAT, 0, tbuff);
354				
355				textureDrawn = true;
356			}
357			
358			if (this.isUseVBOs()){//Color
359				gl.glBindBuffer(GL.GL_ARRAY_BUFFER, this.getGeometryInfo().getVBOColorName());
360				gl.glColorPointer(4, GL.GL_FLOAT, 0, 0);
361			}else{
362				gl.glColorPointer(4, GL.GL_FLOAT, 0, colorBuff);
363			}
364			
365			//Normals
366			if (this.getGeometryInfo().isContainsNormals()){
367				gl.glEnableClientState(GL.GL_NORMAL_ARRAY);
368				if (this.isUseVBOs()){
369					gl.glBindBuffer(GL.GL_ARRAY_BUFFER, this.getGeometryInfo().getVBONormalsName());
370					gl.glNormalPointer(GL.GL_FLOAT, 0, 0); 
371				}else{
372					gl.glNormalPointer(GL.GL_FLOAT, 0, this.getGeometryInfo().getNormalsBuff());
373				}
374			}
375			
376			//DRAW //Draw with drawElements if geometry is indexed, else draw with drawArrays!
377			if (this.getGeometryInfo().isIndexed()){
378				gl.glDrawElements(this.getFillDrawMode(), indexBuff.limit(), GL.GL_UNSIGNED_INT, indexBuff);
379//				gl.glDrawElements(this.getFillDrawMode(), indexBuff.capacity(), GL.GL_UNSIGNED_INT, indexBuff);
380			}else{
381				gl.glDrawArrays(this.getFillDrawMode(), 0, vertBuff.capacity()/3);
382			}
383			
384			if (this.getGeometryInfo().isContainsNormals()){
385				gl.glDisableClientState(GL.GL_NORMAL_ARRAY);
386			}
387			
388			if (textureDrawn){
389				gl.glBindTexture(textureTarget, 0);//Unbind texture
390				gl.glDisableClientState(GL.GL_TEXTURE_COORD_ARRAY);
391				gl.glDisable(textureTarget); //weiter nach unten?
392			}
393		}
394		
395		////////// DRAW OUTLINE ////////
396		if (!this.isNoStroke()){ 
397			if (this.isUseVBOs()){
398				gl.glBindBuffer(GL.GL_ARRAY_BUFFER, this.getGeometryInfo().getVBOStrokeColorName());
399				gl.glColorPointer(4, GL.GL_FLOAT, 0, 0);
400			}else{
401				gl.glColorPointer(4, GL.GL_FLOAT, 0, strokeColBuff);
402			}
403			
404			
405//			//Turn on smooth outlines
406//			if (this.isDrawSmooth()){
407//				gl.glEnable(GL.GL_LINE_SMOOTH);
408//			}
409			//FIXME TEST
410			Tools3D.setLineSmoothEnabled(gl, true);
411			
412//			/*
413			//SET LINE STIPPLE
414				short lineStipple = this.getLineStipple();
415				if (lineStipple != 0){
416					gl.glLineStipple(1, lineStipple);
417					gl.glEnable(GL.GL_LINE_STIPPLE);
418				}
419//			*/
420			
421			if (this.getStrokeWeight() > 0)
422				gl.glLineWidth(this.getStrokeWeight());
423			
424			//DRAW Polygon outline
425			//Draw with drawElements if geometry is indexed, else draw with drawArrays!
426			if (this.getGeometryInfo().isIndexed()){
427				gl.glDrawElements(GL.GL_LINE_STRIP, indexBuff.limit(), GL.GL_UNSIGNED_INT, indexBuff);
428//				gl.glDrawElements(this.getFillDrawMode(), indexBuff.capacity(), GL.GL_UNSIGNED_INT, indexBuff);
429			}else{
430				gl.glDrawArrays(GL.GL_LINE_STRIP, 0, vertBuff.capacity()/3); 
431			}
432			
433			//RESET LINE STIPPLE
434			if (lineStipple != 0){
435				gl.glDisable(GL.GL_LINE_STIPPLE);
436			}
437			
438			//FIXME TEST 
439			Tools3D.setLineSmoothEnabled(gl, false);
440			/*
441			if (this.isDrawSmooth())
442				gl.glDisable(GL.GL_LINE_SMOOTH);
443			 */
444		}
445		
446		gl.glDisableClientState(GL.GL_VERTEX_ARRAY);
447		gl.glDisableClientState(GL.GL_COLOR_ARRAY);
448		
449		//TEST
450		if (this.isUseVBOs()){
451			gl.glBindBuffer(GL.GL_ARRAY_BUFFER, 0);
452			gl.glBindBuffer(GL.GL_ELEMENT_ARRAY_BUFFER, 0);
453		}
454//		*/
455	}
456	
457	/* (non-Javadoc)
458	 * @see org.mt4j.components.visibleComponents.shapes.AbstractShape#isGeometryContainsPointLocal(org.mt4j.util.math.Vector3D)
459	 */
460	@Override
461	public boolean isGeometryContainsPointLocal(Vector3D testPoint) { 
462		return ToolsGeometry.isPolygonContainsPoint(this.getVerticesLocal(), testPoint);
463	}
464
465
466	/* (non-Javadoc)
467	 * @see org.mt4j.components.visibleComponents.shapes.AbstractShape#getGeometryIntersectionLocal(org.mt4j.util.math.Ray)
468	 */
469	@Override
470	public Vector3D getGeometryIntersectionLocal(Ray ray){
471		Vector3D[] vertices;
472		vertices = this.getVerticesLocal();
473		Vector3D polyNormal 	= this.getNormal();
474		
475		//Possible intersection point in plane of polygon
476		Vector3D interSectPoint = ToolsGeometry.getRayPlaneIntersection(ray, polyNormal, vertices[0]);
477		
478		if (interSectPoint == null)
479			return null;
480		
481		return (ToolsGeometry.isPoint3DInPlanarPolygon(vertices, interSectPoint, polyNormal) ? interSectPoint : null);
482	}
483
484
485	
486	/**
487	 * Returns a normalized vector, perpendicular to the polygon (the normal)<br>
488	 * <br>The normal vector is calculated in local object space! To transform it into
489	 * world space use <code>normal.transformNormal(Matrix worldMatrix);</code>
490	 * <br><b>NOTE:</b> The polygon has to have at least 3 vertices, the Polygon has to be coplanar!
491	 * <br><b>NOTE:</b> Uses the three first vertices for computation, so make sure there arent duplicates!
492	 * 
493	 * @return the normal vector
494	 */
495	public Vector3D getNormal(){
496		try {
497			if (normalDirty){
498				Vertex[] vertices;
499				vertices = this.getVerticesLocal();
500				if (vertices[0].equalsVector(vertices[1])
501					|| vertices[0].equalsVector(vertices[2])
502				){
503					System.err.println("Warning: in component " + this.getName() + ", 2 vectors for normal computation are equal -> bad results! -" + this);
504				}
505				this.normal = ToolsGeometry.getNormal(vertices[0], vertices[1], vertices[2], true);
506				this.normalDirty = false;
507				return this.normal.getCopy(); 
508			}else{
509				return this.normal.getCopy();
510			}
511		} catch (Exception e) {
512			e.printStackTrace();
513			return new Vector3D(0,0,1);
514		}
515	}
516	
517
518	
519	/**
520	 * Calculates the area of a 2D polygon using its transformed world coordinates
521	 * <br>NOTE: works only if the last vertex is equal to the first (polygon is closed correctly).
522	 * 
523	 * @return the area as double
524	 */
525	public double get2DPolygonArea(){
526		return ToolsGeometry.getPolygonArea2D(this.getVerticesGlobal());
527	}
528	
529	
530	/**
531	 * Calculates the center of mass of the polygon.
532	 * NOTE: works only if the last vertex is equal to the first (polygon is closed correctly)
533	 * NOTE: polygon needs to be coplanar and in the X,Y plane!
534	 * 
535	 * @return the center or mass as a Vector3D
536	 */
537	public Vector3D getCenterOfMass2DLocal(){
538		return ToolsGeometry.getPolygonCenterOfMass2D(this.getVerticesLocal());
539	}
540	
541	
542	/* (non-Javadoc)
543	 * @see org.mt4j.components.visibleComponents.shapes.AbstractShape#getCenterPointLocal()
544	 */
545	@Override
546	public Vector3D getCenterPointLocal(){
547		if (this.hasBounds()){
548			return this.getBounds().getCenterPointLocal();
549		}else{
550			return new OrientedBoundingBox(this).getCenterPointLocal();
551		}
552	}
553	
554	
555	
556	/**
557	 * Scales this shape to the given width and height. Relative to its parent frame of reference.
558	 * <br>Uses the shapes bounding shape for calculation.
559	 * 
560	 * @param width the width
561	 * @param height the height
562	 * 
563	 * @return true, if sets the size xy relative to parent
564	 * 
565	 * returns false if negative values are put in
566	 */
567	public boolean setSizeXYRelativeToParent(float width, float height){
568		if (width > 0 && height > 0){
569			Vector3D centerPoint = this.getCenterPointRelativeToParent();
570			this.scale( (1f/this.getWidthXYRelativeToParent()) * width, (1f/this.getHeightXYRelativeToParent()) * height, 1, centerPoint);
571			return true;
572		}else
573			return false;
574	}
575	
576	/**
577	 * Scales this shape to the given width and height in the XY-Plane. Relative to world space.
578	 * <br>Uses the shapes bounding shape for calculation.
579	 * 
580	 * @param width the width
581	 * @param height the height
582	 * 
583	 * @return true, if sets the size xy global
584	 */
585	public boolean setSizeXYGlobal(float width, float height){
586		if (width > 0 && height > 0){
587			Vector3D centerPoint = this.getCenterPointGlobal();
588			this.scaleGlobal( (1f/this.getWidthXYGlobal())* width , (1f/this.getHeightXYGlobal()) * height, 1, centerPoint);
589			return true;
590		}else
591			return false;
592	}
593	
594	
595	/**
596	 * Scales the shape to the given height relative to parent space.
597	 * Aspect ratio is preserved! The scaling is done Axis aligned, so
598	 * shearing might occour if rotated!
599	 * <br>Uses the shapes bounding shape for calculation.
600	 * 
601	 * @param height the height
602	 * 
603	 * @return true, if the height isnt negative
604	 */
605	public boolean setHeightXYRelativeToParent(float height){
606		if (height > 0){
607			Vector3D centerPoint = this.getCenterPointRelativeToParent();
608			float factor = (1f/this.getHeightXYRelativeToParent()) * height;
609			this.scale(factor, factor, 1, centerPoint);
610			return true;
611		}else
612			return false;
613	}
614	
615	
616	/**
617	 * Scales the shape to the given height relative to world space.
618	 * Aspect ratio is preserved! The scaling is done Axis aligned, so
619	 * shearing might occour if rotated!
620	 * <br>Uses the shapes bounding shape for calculation.
621	 * 
622	 * @param height the height
623	 * 
624	 * @return true, if sets the height xy global
625	 */
626	public boolean setHeightXYGlobal(float height){
627		if (height > 0){
628			Vector3D centerPoint = this.getCenterPointGlobal();
629			float factor = (1f/this.getHeightXYGlobal())* height;
630			this.scaleGlobal(factor, factor, 1, centerPoint);
631			return true;
632		}else
633			return false;
634	}
635	
636	/**
637	 * Scales the shape to the given width relative to parent space.
638	 * Aspect ratio is preserved! 
639	 * <br>NOTE: The scaling is done Axis aligned, so
640	 * shearing might occour if rotated before!
641	 * <br>Uses the shapes bounding shape for calculation.
642	 * 
643	 * @param width the width
644	 * 
645	 * @return true, if the width isnt negative
646	 */
647	public boolean setWidthXYRelativeToParent(float width){
648		if (width > 0){
649			Vector3D centerPoint = this.getCenterPointRelativeToParent(); 
650			float factor = (1f/this.getWidthXYRelativeToParent()) * width;
651			this.scale(factor, factor, 1, centerPoint);
652			return true;
653		}else
654			return false;
655	}
656	
657	
658	/**
659	 * Scales the shape to the given width relative to world space.
660	 * Aspect ratio is preserved! The scaling is done Axis aligned, so
661	 * shearing might occour if rotated!
662	 * <br>Uses the shapes bounding shape for calculation.
663	 * 
664	 * @param width the width
665	 * 
666	 * @return true, if sets the width xy global
667	 */
668	public boolean setWidthXYGlobal(float width){
669		if (width > 0){
670			Vector3D centerPoint = this.getCenterPointGlobal();
671			float factor = (1f/this.getWidthXYGlobal())* width;
672			this.scaleGlobal(factor, factor, 1, centerPoint);
673			return true;
674		}else
675			return false;
676	}
677
678	
679	/* (non-Javadoc)
680	 * @see org.mt4j.components.visibleComponents.shapes.AbstractShape#destroyComponent()
681	 */
682	@Override
683	protected void destroyComponent() { 	}
684
685	@Override
686	protected void applyStyleSheetCustom(CSSStyle virtualStyleSheet) {
687		if (virtualStyleSheet.isModifiedBackgroundImage()) {
688			getCssHelper().setBackground(this);
689		}
690	}
691
692
693}