Examples of MTComponent


Examples of org.mt4j.components.MTComponent

  }

  public boolean processGestureEvent(MTGestureEvent ge) {
    IMTComponent3D t = ge.getTargetComponent();
    if (t instanceof MTComponent) {
      MTComponent comp = (MTComponent) t;
      DragEvent de = (DragEvent)ge;
      IMTController oldController;
      switch (de.getId()) {
      case DragEvent.GESTURE_DETECTED:
        break;
      case DragEvent.GESTURE_UPDATED:
        break;
      case DragEvent.GESTURE_ENDED:
        Vector3D vel = de.getDragCursor().getVelocityVector(integrationTime);
        vel.scaleLocal(0.9f); //Test - integrate over longer time but scale down velocity vec
        vel = vel.getLimited(limit);
        oldController = comp.getController();
        comp.setController(new InertiaController(comp, vel, oldController));
        break;
      default:
        break;
      }
    }
View Full Code Here

Examples of org.mt4j.components.MTComponent

    //Scale position
//    pos.scaleLocal(1f/scale); //FIXME REALLY?
//    PhysicsHelper.scaleDown(pos, scale);
    Vector3D scaledPos = PhysicsHelper.scaleDown(pos.getCopy(), scale);
   
    MTComponent parent = this.getParent();
    this.removeFromParent();
   
    //Temporarily move the mesh so that we know where the calculated center of the body
    //would be (the body takes the body.position as the center reference instead of a calculated center)
//    //FIXME welchen centerpoint nehmen? -> kommt auch drauf an ob shape schon auf canvas war!?
    //We have to do this because the anchor point ("position") of the pyhsics shape is the body.position
    //but the anchor point of our shapes is the point returned from getCenterpoint..()
    this.translate(scaledPos);
    Vector3D realBodyCenter = this.getCenterPointGlobal(); //FIXME geht nur if detached from world //rename futurebodycenter?
    //Reset position
    this.translate(scaledPos.getScaled(-1));
   
    //Now get the position where the global center will be after setting the shape at the desired position
    this.setPositionGlobal(scaledPos);
    Vector3D meshCenterAtPosition = this.getCenterPointGlobal();
   
    if (parent != null){
      parent.addChild(this);//TODO add at same index
    }

    //Compute the distance we would have to move the vertices for the body creation
    //so that the body.position(center) is at the same position as our mesh center
    Vector3D realBodyCenterToMeshCenter = meshCenterAtPosition.getSubtracted(realBodyCenter);
View Full Code Here

Examples of org.mt4j.components.MTComponent

    e.setVisible(false);
    e.setDegrees(0);
   
    e.setController(new IMTController() {
      public void update(long timeDelta) {
        MTComponent parent = e.getParent();
        if (parent != null){
          int childCount = parent.getChildCount();
          if (childCount > 0
            && !parent.getChildByIndex(childCount-1).equals(e))
          {
            TapAndHoldVisualizer.this.app.invokeLater(new Runnable() {
              public void run(){
                MTComponent parent = e.getParent();
                if (parent != null){
                  parent.removeChild(e);
                  parent.addChild(e);
                }
              }
            });
          }
        }
View Full Code Here

Examples of org.mt4j.components.MTComponent

//        comp.addGestureListener(DragProcessor.class, new IGestureEventListener() {
        //@Override
        public boolean processGestureEvent(MTGestureEvent ge) {
          DragEvent de = (DragEvent)ge;
          try{
            MTComponent comp = (MTComponent)de.getTargetComponent();
            Body body = (Body)comp.getUserData("box2d");
            MouseJoint mouseJoint;
            Vector3D to = new Vector3D(de.getTo());
            //Un-scale position from mt4j to box2d
            PhysicsHelper.scaleDown(to, worldScale);
            //System.out.println("MouseJoint To: " + to);
            long cursorID =  de.getDragCursor().getId();

            switch (de.getId()) {
            case DragEvent.GESTURE_DETECTED:
              comp.sendToFront();
              body.wakeUp();
              mouseJoint = createDragJoint(theWorld, body, to.x, to.y);
              comp.setUserData("mouseJoint" + cursorID, mouseJoint);
              break;
            case DragEvent.GESTURE_UPDATED:
              mouseJoint = (MouseJoint) comp.getUserData("mouseJoint" + cursorID);
              if (mouseJoint != null){
                mouseJoint.setTarget(new Vec2(to.x, to.y));
              }
              break;
            case DragEvent.GESTURE_ENDED:
              mouseJoint = (MouseJoint) comp.getUserData("mouseJoint" + cursorID);
              if (mouseJoint != null){
                comp.setUserData("mouseJoint" + cursorID, null);
//                theWorld.destroyJoint(mouseJoint); 
                //Only destroy the joint if it isnt already (go through joint list and check)
                for (Joint joint = theWorld.getJointList(); joint != null; joint = joint.getNext()) {
                  JointType type = joint.getType();
                  switch (type) {
                  case MOUSE_JOINT:
                    MouseJoint mj = (MouseJoint)joint;
                    if (body.equals(mj.getBody1()) || body.equals(mj.getBody2())){
//                      theWorld.destroyJoint(mj);
                      if (mj.equals(mouseJoint)) {
                        theWorld.destroyJoint(mj);
                      }
                    }
                    break;
                  default:
                    break;
                  }
                }
              }
              mouseJoint = null;
              break;
            default:
              break;
            }
          }catch (Exception e) {
            System.err.println(e.getMessage());
          }
          return true;
        }
      });
    }else{
      comp.removeAllGestureEventListeners(DragProcessor.class);
     
      boolean hasDragProcessor = false;
      AbstractComponentProcessor[] p = comp.getInputProcessors();
      for (int i = 0; i < p.length; i++) {
        AbstractComponentProcessor abstractComponentProcessor = p[i];
        if (abstractComponentProcessor instanceof DragProcessor) {
          hasDragProcessor = true;
        }
      }
      if (!hasDragProcessor){
        comp.registerInputProcessor(new DragProcessor(comp.getRenderer()));
      }
     
      //For static bodies just alter the transform of the body
      comp.addGestureListener(DragProcessor.class, new IGestureEventListener() {
        //@Override
        public boolean processGestureEvent(MTGestureEvent ge) {
          DragEvent de = (DragEvent)ge;
          Vector3D dir = PhysicsHelper.scaleDown(new Vector3D(de.getTranslationVect()), worldScale);
          try{
            MTComponent comp = (MTComponent)de.getTargetComponent();
            Body body = (Body)comp.getUserData("box2d");
            body.setXForm(
                new Vec2(body.getPosition().x + dir.x, body.getPosition().y + dir.y),
                body.getAngle());
            switch (de.getId()) {
            case DragEvent.GESTURE_DETECTED:
              comp.sendToFront();
              body.wakeUp();
              break;
            case DragEvent.GESTURE_UPDATED:
            case DragEvent.GESTURE_ENDED:
            default:
View Full Code Here

Examples of org.mt4j.components.MTComponent

    this.registerGlobalInputProcessor(new CursorTracer(app, this));
   
    //Update the positions of the components according the the physics simulation each frame
    this.registerPreDrawAction(new UpdatePhysicsAction(world, timeStep, constraintIterations, scale));
   
    physicsContainer = new MTComponent(app);
    //Scale the physics container. Physics calculations work best when the dimensions are small (about 0.1 - 10 units)
    //So we make the display of the container bigger and add in turn make our physics object smaller
    physicsContainer.scale(scale, scale, 1, Vector3D.ZERO_VECTOR);
    this.getCanvas().addChild(physicsContainer);
   
View Full Code Here

Examples of org.mt4j.components.MTComponent

      ){
        IFontFactory fontFactory = FontManager.getInstance().getFactoryForFileSuffix(".ttf");
        if (fontFactory != null && fontFactory instanceof TTFontFactory){
          TTFontFactory ttFontFactory = (TTFontFactory)fontFactory;
          if (this.getCharacters().length > 0 && this.getCharacters()[0] != null && this.getCharacters()[0] instanceof MTComponent){
            MTComponent comp = (MTComponent)this.getCharacters()[0];
            PApplet pa = comp.getRenderer();
            VectorFontCharacter[] characters = ttFontFactory.getTTFCharacters(pa, unicode, fillColor, strokeColor, this.fontFileName, this.originalFontSize, this.antiAliased);
            if (characters.length == 1 && characters[0] != null){
              VectorFontCharacter loadedCharacter = characters[0];
              VectorFontCharacter[] newArray = new VectorFontCharacter[this.getCharacters().length + 1];
              System.arraycopy(this.getCharacters(), 0, newArray, 0, this.getCharacters().length);
View Full Code Here

Examples of org.mt4j.components.MTComponent

    });
  }
 
 
  private void putLastInParentList(){
    MTComponent parent = getParent();
    if (parent != null){
      int childCount = parent.getChildCount();
     
      if childCount > 0
        && !parent.getChildByIndex(childCount-1).equals(MTOverlayContainer.this)
      ){
        MTComponent lastChild = parent.getChildByIndex(childCount-1);
        if !(lastChild instanceof MTOverlayContainer)
          &&   !(lastChild.getName().equalsIgnoreCase("Cursor Trace group"))
        ){
          //last component in canvas child list is not a overlay container:
          MTOverlayContainer.this.app.invokeLater(new Runnable() {
            public void run(){
              MTComponent parent = getParent();
              if (parent != null){
                parent.removeChild(MTOverlayContainer.this);
                parent.addChild(MTOverlayContainer.this);
              }
            }
          });
        }else{
          //last component in canvas already is a different overlay container:
View Full Code Here

Examples of org.mt4j.components.MTComponent

        break;
      case MTGestureEvent.GESTURE_UPDATED:
       
        if (this.hasScaleLimit){
          if (target instanceof MTComponent) {
            MTComponent comp = (MTComponent) target;
           
            //FIXME actually we should use globalmatrix but performance is better for localMatrix..
            Vector3D currentScale = comp.getLocalMatrix().getScale();
           
//            if (currentScale.x != currentScale.y){
//              System.out.println("non uniform scale!");
//            }
           
View Full Code Here

Examples of org.mt4j.components.MTComponent

   * @param selectable the selectable
   */
  public synchronized void addClusterable(IdragClusterable selectable){
    dragSelectables.add(selectable);
    if (selectable instanceof MTComponent) {
      MTComponent baseComp = (MTComponent) selectable;

      baseComp.addStateChangeListener(StateChange.COMPONENT_DESTROYED, new StateChangeListener(){
        public void stateChanged(StateChangeEvent evt) {
          if (evt.getSource() instanceof IdragClusterable) {
            IdragClusterable clusterAble = (IdragClusterable) evt.getSource();
            removeClusterable(clusterAble);
            //logger.debug("Removed comp from clustergesture analyzers tracking");
View Full Code Here

Examples of org.mt4j.components.MTComponent

    this.world = new World(worldAABB, gravity, sleep);
   
    //Update the positions of the components according the the physics simulation each frame
    this.registerPreDrawAction(new UpdatePhysicsAction(world, timeStep, constraintIterations, scale));
   
    physicsContainer = new MTComponent(app);
    //Scale the physics container. Physics calculations work best when the dimensions are small (about 0.1 - 10 units)
    //So we make the display of the container bigger and add in turn make our physics object smaller
    physicsContainer.scale(scale, scale, 1, Vector3D.ZERO_VECTOR);
    this.getCanvas().addChild(physicsContainer);
   
    //Create borders around the screen
    this.createScreenBorders(physicsContainer);
   
    //Create gamefield marks
    MTLine line = new MTLine(mtApplication, mtApplication.width/2f/scale, 0, mtApplication.width/2f/scale, mtApplication.height/scale);
    line.setPickable(false);
//    line.setStrokeColor(new MTColor(0,0,0));
    line.setStrokeColor(new MTColor(150,150,150));
    line.setStrokeWeight(0.5f);
    physicsContainer.addChild(line);
   
    MTEllipse centerCircle = new MTEllipse(mtApplication, new Vector3D(mtApplication.width/2f/scale, mtApplication.height/2f/scale), 80/scale, 80/scale);
    centerCircle.setPickable(false);
    centerCircle.setNoFill(true);
//    centerCircle.setStrokeColor(new MTColor(0,0,0));
    centerCircle.setStrokeColor(new MTColor(150,150,150));
    centerCircle.setStrokeWeight(0.5f);
    physicsContainer.addChild(centerCircle);
   
    MTEllipse centerCircleInner = new MTEllipse(mtApplication, new Vector3D(mtApplication.width/2f/scale, mtApplication.height/2f/scale), 10/scale, 10/scale);
    centerCircleInner.setPickable(false);
    centerCircleInner.setFillColor(new MTColor(160,160,160));
//    centerCircleInner.setStrokeColor(new MTColor(150,150,150));
//    centerCircleInner.setStrokeColor(new MTColor(0,0,0));
    centerCircleInner.setStrokeColor(new MTColor(150,150,150));
    centerCircleInner.setStrokeWeight(0.5f);
    physicsContainer.addChild(centerCircleInner);
   
    //Create the paddles
    PImage paddleTex = mtApplication.loadImage(imagesPath + "paddle.png");
    redCircle = new Paddle(app, new Vector3D(mtApplication.width - 60, mtApplication.height/2f), 50, world, 1.0f, 0.3f, 0.4f, scale);
    redCircle.setTexture(paddleTex);
    redCircle.setFillColor(new MTColor(255,50,50));
    redCircle.setNoStroke(true);
    redCircle.setName("red");
    redCircle.setPickable(false);
    physicsContainer.addChild(redCircle);
   
    blueCircle = new Paddle(app, new Vector3D(80, mtApplication.height/2f), 50, world, 1.0f, 0.3f, 0.4f, scale);
    blueCircle.setTexture(paddleTex);
    blueCircle.setFillColor(new MTColor(50,50,255));
    blueCircle.setNoStroke(true);
    blueCircle.setName("blue");
    blueCircle.setPickable(false);
    physicsContainer.addChild(blueCircle);
   
    //Create the ball
    ball = new HockeyBall(app, new Vector3D(mtApplication.width/2f, mtApplication.height/2f), 38, world, 0.5f, 0.005f, 0.70f, scale);
//    MTColor ballCol = new MTColor(0,255,0);
//    ball.setFillColor(ballCol);
    PImage ballTex = mtApplication.loadImage(imagesPath + "puk.png");
    ball.setTexture(ballTex);
//    ball.setFillColor(new MTColor(160,160,160,255));
    ball.setFillColor(new MTColor(255,255,255,255));
    ball.setNoStroke(true);
    ball.setName("ball");
    physicsContainer.addChild(ball);
    ball.getBody().applyImpulse(new Vec2(ToolsMath.getRandom(-8f, 8),ToolsMath.getRandom(-8, 8)), ball.getBody().getWorldCenter());
   
    //Create the GOALS
    HockeyGoal goal1 = new HockeyGoal(new Vector3D(0, mtApplication.height/2f), 50, mtApplication.height/4f, mtApplication, world, 0.0f, 0.1f, 0.0f, scale);
    goal1.setName("goal1");
    goal1.setFillColor(new MTColor(0,0,255));
    goal1.setStrokeColor(new MTColor(0,0,255));
    physicsContainer.addChild(goal1);
   
    HockeyGoal goal2 = new HockeyGoal(new Vector3D(mtApplication.width, mtApplication.height/2f), 50, mtApplication.height/4f, mtApplication, world, 0.0f, 0.1f, 0.0f, scale);
    goal2.setName("goal2");
    goal2.setFillColor(new MTColor(255,0,0));
    goal2.setStrokeColor(new MTColor(255,0,0));
    physicsContainer.addChild(goal2);
   
    //Make two components for both game field sides to drag the puks upon
    MTRectangle leftSide = new MTRectangle(
        PhysicsHelper.scaleDown(0, scale), PhysicsHelper.scaleDown(0, scale),
        PhysicsHelper.scaleDown(app.width/2f, scale), PhysicsHelper.scaleDown(app.height, scale)
        , app);
    leftSide.setName("left side");
    leftSide.setNoFill(true); //Make it invisible -> only used for dragging
    leftSide.setNoStroke(true);
    leftSide.unregisterAllInputProcessors();
    leftSide.removeAllGestureEventListeners(DragProcessor.class);
    leftSide.registerInputProcessor(new DragProcessor(app));
    leftSide.addGestureListener(DragProcessor.class, new GameFieldHalfDragListener(blueCircle));
    physicsContainer.addChild(0, leftSide);
    MTRectangle rightSide = new MTRectangle(
        PhysicsHelper.scaleDown(app.width/2f, scale), PhysicsHelper.scaleDown(0, scale),
        PhysicsHelper.scaleDown(app.width, scale), PhysicsHelper.scaleDown(app.height, scale)
        , app);
    rightSide.setName("right Side");
    rightSide.setNoFill(true); //Make it invisible -> only used for dragging
    rightSide.setNoStroke(true);
    rightSide.unregisterAllInputProcessors();
    rightSide.removeAllGestureEventListeners(DragProcessor.class);
    rightSide.registerInputProcessor(new DragProcessor(app));
    rightSide.addGestureListener(DragProcessor.class, new GameFieldHalfDragListener(redCircle));
    physicsContainer.addChild(0, rightSide);
   
    //Display Score UI
    MTComponent uiLayer = new MTComponent(mtApplication, new MTCamera(mtApplication));
    uiLayer.setDepthBufferDisabled(true);
    getCanvas().addChild(uiLayer);
    IFont font = FontManager.getInstance().createFont(mtApplication, "arial", 50, new MTColor(255,255,255), new MTColor(0,0,0));
   
    t1 = new MTTextArea(mtApplication, font);
    t1.setPickable(false);
    t1.setNoFill(true);
    t1.setNoStroke(true);
    t1.setPositionGlobal(new Vector3D(5,30,0));
    uiLayer.addChild(t1);
   
    t2 = new MTTextArea(mtApplication, font);
    t2.setPickable(false);
    t2.setNoFill(true);
    t2.setNoStroke(true);
    t2.setPositionGlobal(new Vector3D(mtApplication.width - 65 , 30,0));
    uiLayer.addChild(t2);
    this.updateScores();
   
    //Set up check for collisions between objects
    this.addWorldContactListener(world);
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.