/extensions/org/mt4jx/input/inputProcessors/componentProcessors/Group3DProcessorNew/Cluster.java
Java | 339 lines | 215 code | 36 blank | 88 comment | 40 complexity | 990b4911fd0bf20fd053f286e00e7ac8 MD5 | raw file
1package org.mt4jx.input.inputProcessors.componentProcessors.Group3DProcessorNew; 2 3import java.util.ArrayList; 4 5import javax.media.opengl.GL; 6 7import org.mt4j.components.MTComponent; 8import org.mt4j.components.visibleComponents.shapes.MTLine; 9import org.mt4j.input.inputProcessors.IGestureEventListener; 10import org.mt4j.input.inputProcessors.componentProcessors.lassoProcessor.IdragClusterable; 11import org.mt4j.input.inputProcessors.componentProcessors.tapProcessor.TapProcessor; 12import org.mt4j.util.math.Matrix; 13import org.mt4j.util.math.Tools3D; 14import org.mt4j.util.math.Vector3D; 15 16import processing.core.PApplet; 17import processing.core.PGraphics; 18 19public class Cluster extends MTComponent { 20 21 private MTComponent visualComponentGroup; 22 23 private MTComponent currentlySelectedChildren = null; 24 25 private IVisualizeMethodProvider visualizeProvider; 26 27 private PApplet pApplet; 28 public Cluster(PApplet pApplet) { 29 super(pApplet); 30 this.pApplet = pApplet; 31 } 32 33 public Cluster(PApplet pApplet,ArrayList<MTComponent> components) 34 { 35 super(pApplet); 36 this.pApplet = pApplet; 37 for (int i = 0; i < components.size(); i++) { 38 MTComponent component3D = components.get(i); 39 this.addChild(component3D); 40 this.setComposite(true); 41 } 42 43 } 44 45 /** 46 * Transforms the shapes local coordinate space by the given matrix. 47 * 48 * @param transformMatrix the transform matrix 49 */ 50 public void transform(Matrix transformMatrix) { 51 for (MTComponent c : this.getChildList()){ 52 c.transform(transformMatrix); 53 } 54 if(visualComponentGroup!=null) 55 { 56 for(MTComponent comp : visualComponentGroup.getChildren()) 57 { 58 comp.transform(transformMatrix); 59 } 60 } 61 } 62 63 64 /* (non-Javadoc) 65 * @see com.jMT.components.MTBaseComponent#translateGlobal(util.math.Vector3D) 66 */ 67 public void translateGlobal(Vector3D dirVect) { 68 for (MTComponent c : this.getChildList()){ 69 c.translateGlobal(dirVect); 70 } 71 if(visualComponentGroup!=null) 72 { 73 for(MTComponent comp : visualComponentGroup.getChildren()) 74 { 75 comp.translateGlobal(dirVect); 76 } 77 } 78 } 79 80 /* (non-Javadoc) 81 * @see com.jMT.components.MTBaseComponent#translate(util.math.Vector3D) 82 */ 83 public void translate(Vector3D dirVect) { 84 for (MTComponent c : this.getChildList()){ 85 c.translate(dirVect); 86 } 87 if(visualComponentGroup!=null) 88 { 89 for(MTComponent comp : visualComponentGroup.getChildren()) 90 { 91 comp.translate(dirVect); 92 } 93 } 94 } 95 96 97 /* (non-Javadoc) 98 * @see com.jMT.components.MTBaseComponent#xRotateGlobal(util.math.Vector3D, float) 99 */ 100 public void rotateXGlobal(Vector3D rotationPoint, float degree) { 101 for (MTComponent c : this.getChildList()){ 102 c.rotateXGlobal(rotationPoint, degree); 103 } 104 if(visualComponentGroup!=null) 105 { 106 for(MTComponent comp : visualComponentGroup.getChildren()) 107 { 108 comp.rotateXGlobal(rotationPoint, degree); 109 } 110 } 111 } 112 113 /* (non-Javadoc) 114 * @see com.jMT.components.MTBaseComponent#xRotate(util.math.Vector3D, float) 115 */ 116 public void rotateX(Vector3D rotationPoint, float degree) { 117 for (MTComponent c : this.getChildList()){ 118 c.rotateX(rotationPoint, degree); 119 } 120 if(visualComponentGroup!=null) 121 { 122 for(MTComponent comp : visualComponentGroup.getChildren()) 123 { 124 comp.rotateX(rotationPoint, degree); 125 } 126 } 127 } 128 129 130 /* (non-Javadoc) 131 * @see com.jMT.components.MTBaseComponent#yRotateGlobal(util.math.Vector3D, float) 132 */ 133 public void rotateYGlobal(Vector3D rotationPoint, float degree) { 134 for (MTComponent c : this.getChildList()){ 135 c.rotateYGlobal(rotationPoint, degree); 136 } 137 if(visualComponentGroup!=null) 138 { 139 for(MTComponent comp : visualComponentGroup.getChildren()) 140 { 141 comp.rotateYGlobal(rotationPoint, degree); 142 } 143 } 144 } 145 146 /* (non-Javadoc) 147 * @see com.jMT.components.MTBaseComponent#yRotate(util.math.Vector3D, float) 148 */ 149 public void rotateY(Vector3D rotationPoint, float degree) { 150 for (MTComponent c : this.getChildList()){ 151 c.rotateY(rotationPoint, degree); 152 } 153 if(visualComponentGroup!=null) 154 { 155 for(MTComponent comp : visualComponentGroup.getChildren()) 156 { 157 comp.rotateY(rotationPoint, degree); 158 } 159 } 160 } 161 162 /* (non-Javadoc) 163 * @see com.jMT.components.MTBaseComponent#zRotateGlobal(util.math.Vector3D, float) 164 */ 165 public void rotateZGlobal(Vector3D rotationPoint, float degree) { 166 for (MTComponent c : this.getChildList()){ 167 c.rotateZGlobal(rotationPoint, degree); 168 } 169 if(visualComponentGroup!=null) 170 { 171 for(MTComponent comp : visualComponentGroup.getChildren()) 172 { 173 comp.rotateZGlobal(rotationPoint, degree); 174 } 175 } 176 } 177 178 179 /* (non-Javadoc) 180 * @see com.jMT.components.MTBaseComponent#zRotate(util.math.Vector3D, float) 181 */ 182 public void rotateZ(Vector3D rotationPoint, float degree) { 183 for (MTComponent c : this.getChildList()){ 184 c.rotateZ(rotationPoint, degree); 185 } 186 if(visualComponentGroup!=null) 187 { 188 for(MTComponent comp : visualComponentGroup.getChildren()) 189 { 190 comp.rotateZ(rotationPoint, degree); 191 } 192 } 193 } 194 195 /* (non-Javadoc) 196 * @see com.jMT.components.MTBaseComponent#scaleGlobal(float, util.math.Vector3D) 197 */ 198 public void scaleGlobal(float factor, Vector3D scaleReferencePoint) { 199 this.scaleGlobal(factor, factor, factor, scaleReferencePoint); 200 if(visualComponentGroup!=null) 201 { 202 for(MTComponent comp : visualComponentGroup.getChildren()) 203 { 204 comp.scaleGlobal(factor, factor, factor, scaleReferencePoint); 205 } 206 } 207 } 208 209 /** 210 * scales the polygon around the scalingPoint, currently dosent support scaling around the Z axis. 211 * 212 * @param X the x 213 * @param Y the y 214 * @param Z the z 215 * @param scalingPoint the scaling point 216 */ 217 public void scaleGlobal(float X, float Y, float Z, Vector3D scalingPoint) { 218 for (MTComponent c : this.getChildList()){ 219 c.scaleGlobal(X, Y, Z, scalingPoint); 220 if(visualComponentGroup!=null) 221 { 222 for(MTComponent comp : visualComponentGroup.getChildren()) 223 { 224 comp.scaleGlobal(X, Y, Z, scalingPoint); 225 } 226 } 227 228 } 229 } 230 231 232 /* (non-Javadoc) 233 * @see com.jMT.components.MTBaseComponent#scale(float, util.math.Vector3D) 234 */ 235 public void scale(float factor, Vector3D scaleReferencePoint) { 236 this.scale(factor, factor, factor, scaleReferencePoint); 237 if(visualComponentGroup!=null) 238 { 239 for(MTComponent comp : visualComponentGroup.getChildren()) 240 { 241 comp.scale(factor, factor, factor, scaleReferencePoint); 242 } 243 } 244 } 245 246 /** 247 * scales the polygon around the scalingPoint, currently dosent support scaling around the Z axis. 248 * 249 * @param X the x 250 * @param Y the y 251 * @param Z the z 252 * @param scalingPoint the scaling point 253 */ 254 public void scale(float X, float Y, float Z, Vector3D scalingPoint) { 255 for (MTComponent c : this.getChildList()){ 256 c.scale(X, Y, Z, scalingPoint); 257 } 258 if(visualComponentGroup!=null) 259 { 260 for(MTComponent comp : visualComponentGroup.getChildren()) 261 { 262 comp.scale(X, Y, Z, scalingPoint); 263 } 264 } 265 } 266 267 public void setVisualComponentGroup(MTComponent v_visualComponentGroup) { 268 this.visualComponentGroup = v_visualComponentGroup; 269 if(this.visualComponentGroup.isComposite()!=true) 270 { 271 this.visualComponentGroup.setComposite(true); 272 } 273 } 274 275 public MTComponent getVisualComponentGroup() { 276 return visualComponentGroup; 277 } 278 279 @Override 280 public void drawComponent(PGraphics g) 281 { 282 if(getVisualizeProvider()!=null) 283 { 284 getVisualizeProvider().visualize(this); 285 } 286 } 287 288 public void setVisualizeProvider(IVisualizeMethodProvider visualizeProvider) { 289 this.visualizeProvider = visualizeProvider; 290 } 291 292 public IVisualizeMethodProvider getVisualizeProvider() { 293 return visualizeProvider; 294 } 295 public void setCurrentlySelectedChildren(MTComponent currentComponent) { 296 this.currentlySelectedChildren = currentComponent; 297 } 298 299 public MTComponent getCurrentlySelectedChildren() { 300 return currentlySelectedChildren; 301 } 302 /*@Override 303 public void preDraw(PGraphics g) 304 { 305 if(visualComponentGroup!=null) 306 { 307 for(MTComponent comp : visualComponentGroup.getChildren()) 308 { 309 comp.preDraw(g); 310 } 311 } 312 } 313 314 @Override 315 public void drawComponent(PGraphics g) 316 { 317 if(visualComponentGroup!=null) 318 { 319 //visualComponentGroup.drawComponent(g); 320 for(MTComponent comp : visualComponentGroup.getChildren()) 321 { 322 comp.drawComponent(g); 323 } 324 } 325 } 326 327 @Override 328 public void postDraw(PGraphics g) 329 { 330 if(visualComponentGroup!=null) 331 { 332 for(MTComponent comp : visualComponentGroup.getChildren()) 333 { 334 comp.preDraw(g); 335 } 336 } 337 } 338 */ 339}