/extensions/org/mt4jx/input/inputProcessors/componentProcessors/Group3DProcessorNew/Cluster.java

http://mt4j.googlecode.com/ · Java · 339 lines · 215 code · 36 blank · 88 comment · 40 complexity · 990b4911fd0bf20fd053f286e00e7ac8 MD5 · raw file

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