Exemplo n.º 1
0
 private void createScreenBorders(MTComponent parent) {
   // Left border
   float borderWidth = 50f;
   float borderHeight = app.height;
   Vector3D pos = new Vector3D(-(borderWidth / 2f), app.height / 2f);
   PhysicsRectangle borderLeft =
       new PhysicsRectangle(pos, borderWidth, borderHeight, app, world, 0, 0, 0, scale);
   borderLeft.setName("borderLeft");
   parent.addChild(borderLeft);
   // Right border
   pos = new Vector3D(app.width + (borderWidth / 2), app.height / 2);
   PhysicsRectangle borderRight =
       new PhysicsRectangle(pos, borderWidth, borderHeight, app, world, 0, 0, 0, scale);
   borderRight.setName("borderRight");
   parent.addChild(borderRight);
   // Top border
   borderWidth = app.width;
   borderHeight = 50f;
   pos = new Vector3D(app.width / 2, -(borderHeight / 2));
   PhysicsRectangle borderTop =
       new PhysicsRectangle(pos, borderWidth, borderHeight, app, world, 0, 0, 0, scale);
   borderTop.setName("borderTop");
   parent.addChild(borderTop);
   // Bottom border
   pos = new Vector3D(app.width / 2, app.height + (borderHeight / 2));
   PhysicsRectangle borderBottom =
       new PhysicsRectangle(pos, borderWidth, borderHeight, app, world, 0, 0, 0, scale);
   borderBottom.setName("borderBottom");
   parent.addChild(borderBottom);
 }
Exemplo n.º 2
0
  /** Adds the to scene. */
  public void addToScene() {
    MTComponent cursorTraceContainer = null;
    MTCanvas canvas = scene.getCanvas();

    /*
    //Re-use cursor trace group which is always on top for this menu
    MTComponent[] children = canvas.getChildren();
    for (int i = 0; i < children.length; i++) {
    	MTComponent component = children[i];
    	if (component instanceof MTOverlayContainer
    			&&
    		component.getName().equalsIgnoreCase("Cursor Trace group")){
    		cursorTraceContainer  = component;
    		component.addChild(0, this); //add to cursor trace overlay container
    	}
    }
    */

    //		/*
    // cursor tracer group NOT found in the scene -> add overlay container to canvas
    if (cursorTraceContainer == null) {
      overlayGroup.addChild(this);
      canvas.addChild(overlayGroup);
    }
    //		*/
  }
  public void visualize(Cluster3DExt cluster) {

    //		GL gl = Tools3D.getGL(pApplet);
    //		Tools3D.beginGL(pApplet);
    //		gl.glBegin(gl.GL_LINES);
    //		MTLine[] lines = getVisualizationLines(cluster.getChildren());
    //		MTComponent linesGroup = new MTComponent(pApplet);
    //		for(MTLine line : lines)
    //		{
    //			linesGroup.addChild(line);
    //		}
    //		cluster.setVisualComponentGroup(linesGroup);
    //
    //		for(MTLine line : lines)
    //		{
    //
    //	gl.glVertex3f(line.getVerticesLocal()[0].x,line.getVerticesLocal()[0].y,line.getVerticesLocal()[0].z);
    //
    //	gl.glVertex3f(line.getVerticesLocal()[1].x,line.getVerticesLocal()[1].y,line.getVerticesLocal()[1].z);
    //		}
    //		gl.glEnd();
    //		Tools3D.endGL(pApplet);

    pApplet.beginShape(PApplet.LINES);
    MTLine[] lines = getVisualizationLines(cluster.getChildren());
    MTComponent linesGroup = new MTComponent(pApplet);
    for (MTLine line : lines) {
      linesGroup.addChild(line);
    }
    cluster.setVisualComponentGroup(linesGroup);

    for (MTLine line : lines) {
      pApplet.vertex(
          line.getVerticesLocal()[0].x, line.getVerticesLocal()[0].y, line.getVerticesLocal()[0].z);
      pApplet.vertex(
          line.getVerticesLocal()[1].x, line.getVerticesLocal()[1].y, line.getVerticesLocal()[1].z);
    }
    pApplet.endShape();
  }
Exemplo n.º 4
0
  public static void addUniqueEditBar(final MTApplication mtApplication, MTComponent component) {

    System.out.println("******************** Entré al addUniqueEditBar ********************");

    final MTRectangle textureBrush;
    final MTEllipse pencilBrush;
    final DrawSurfaceScene drawingScene;

    String path = StartYPYIShell.getPathToIconsYPYI();

    //		final MTRoundRectangle frame = new MTRoundRectangle(-50,-50, 0,
    // mtApplication.width+100,mtApplication.height+100, 25,25, mtApplication);
    final MTRectangle frame =
        new MTRectangle(
            -50, -50, 0, mtApplication.width + 100, mtApplication.height + 100, mtApplication);
    frame.setSizeXYGlobal(mtApplication.width, mtApplication.height);
    frame.setNoFill(true);
    frame.sendToFront();
    frame.setPickable(false);
    component.addChild(frame);

    // Create the scene in which we actually draw
    drawingScene = new DrawSurfaceScene(mtApplication, "DrawSurface Scene");
    drawingScene.setClear(false);

    // Create texture brush
    PImage brushImage = mtApplication.loadImage(path + "brush1.png");
    textureBrush = new MTRectangle(brushImage, mtApplication);
    textureBrush.setPickable(false);
    textureBrush.setNoFill(false);
    textureBrush.setNoStroke(true);
    textureBrush.setDrawSmooth(true);
    textureBrush.setFillColor(new MTColor(0, 0, 0));
    // Set texture brush as default
    drawingScene.setBrush(textureBrush);

    // Create pencil brush
    pencilBrush =
        new MTEllipse(
            mtApplication,
            new Vector3D(brushImage.width / 2f, brushImage.height / 2f, 0),
            brushImage.width / 2f,
            brushImage.width / 2f,
            60);
    pencilBrush.setPickable(false);
    pencilBrush.setNoFill(false);
    pencilBrush.setNoStroke(false);
    pencilBrush.setDrawSmooth(true);
    pencilBrush.setStrokeColor(new MTColor(0, 0, 0, 255));
    pencilBrush.setFillColor(new MTColor(0, 0, 0, 255));

    // Create the frame/window that displays the drawing scene through a FBO
    //        final MTSceneTexture sceneWindow = new MTSceneTexture(0,0, pa, drawingScene);
    // We have to create a fullscreen fbo in order to save the image uncompressed
    int w = new Float(frame.getWidthXY(TransformSpace.GLOBAL)).intValue();
    int h = new Float(frame.getHeightXY(TransformSpace.GLOBAL)).intValue();

    final MTSceneTexture sceneTexture = new MTSceneTexture(mtApplication, 0, 0, w, h, drawingScene);
    sceneTexture.getFbo().clear(true, 255, 255, 255, 0, true);
    sceneTexture.setStrokeColor(new MTColor(155, 155, 155));
    frame.addChild(sceneTexture);

    // Eraser button
    PImage eraser = mtApplication.loadImage(path + "Kde_crystalsvg_eraser.png");
    final MTImageButton eraserButton = new MTImageButton(eraser, mtApplication);
    eraserButton.setNoStroke(true);
    float yButton = mtApplication.height - (eraser.height / 3);
    eraserButton.translate(new Vector3D(480, yButton, 0));
    eraserButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
              case TapEvent.BUTTON_UP:
                {
                  //					//As we are messing with opengl here, we make sure it happens in the
                  // rendering thread
                  mtApplication.invokeLater(
                      new Runnable() {
                        public void run() {
                          sceneTexture.getFbo().clear(true, 255, 255, 255, 0, true);
                        }
                      });
                }
                break;
              default:
                break;
            }
          }
        });
    frame.addChild(eraserButton);

    eraserButton.scale(2f, 2f, 1, eraserButton.getCenterPointLocal(), TransformSpace.LOCAL);

    // Pen brush selector button
    PImage penIcon = mtApplication.loadImage(path + "pen.png");
    final MTImageButton penButton = new MTImageButton(penIcon, mtApplication);
    frame.addChild(penButton);
    penButton.translate(new Vector3D(580f, yButton, 0));
    penButton.setNoStroke(true);
    penButton.setStrokeColor(new MTColor(0, 0, 0));
    penButton.scale(2f, 2f, 1, penButton.getCenterPointLocal(), TransformSpace.LOCAL);

    // Texture brush selector button
    PImage brushIcon = mtApplication.loadImage(path + "paintbrush.png");
    final MTImageButton brushButton = new MTImageButton(brushIcon, mtApplication);
    frame.addChild(brushButton);
    brushButton.translate(new Vector3D(660f, yButton, 0));
    brushButton.setStrokeColor(new MTColor(0, 0, 0));
    brushButton.setNoStroke(true);
    brushButton.scale(1.5f, 1.5f, 1, brushButton.getCenterPointLocal(), TransformSpace.LOCAL);
    brushButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
              case TapEvent.BUTTON_UP:
                {
                  drawingScene.setBrush(textureBrush);
                  brushButton.setNoStroke(false);
                  penButton.setNoStroke(true);
                }
                break;
              default:
                break;
            }
          }
        });

    penButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
              case TapEvent.BUTTON_UP:
                {
                  drawingScene.setBrush(pencilBrush);
                  penButton.setNoStroke(false);
                  brushButton.setNoStroke(true);
                }
                break;
              default:
                break;
            }
          }
        });

    /////////////////////////
    // ColorPicker and colorpicker button
    PImage colPick = mtApplication.loadImage(path + "colorcircle.png");
    //        final MTColorPicker colorWidget = new MTColorPicker(0, pa.height-colPick.height,
    // colPick, pa);
    final MTColorPicker colorWidget = new MTColorPicker(0, 0, colPick, mtApplication);
    colorWidget.translate(
        new Vector3D(
            705f,
            mtApplication.height
                - (eraser.height / 1.5f)
                - colorWidget.getHeightXY(TransformSpace.GLOBAL),
            0));
    colorWidget.setStrokeColor(new MTColor(0, 0, 0));
    colorWidget.addGestureListener(
        DragProcessor.class,
        new IGestureEventListener() {
          public boolean processGestureEvent(MTGestureEvent ge) {
            if (ge.getId() == MTGestureEvent.GESTURE_ENDED) {
              if (colorWidget.isVisible()) {
                colorWidget.setVisible(false);
              }
            } else {
              drawingScene.setBrushColor(colorWidget.getSelectedColor());
            }
            return false;
          }
        });
    frame.addChild(colorWidget);
    colorWidget.setVisible(false);

    PImage colPickIcon = mtApplication.loadImage(path + "ColorPickerIcon.png");
    final MTImageButton colPickButton = new MTImageButton(colPickIcon, mtApplication);
    frame.addChild(colPickButton);
    colPickButton.translate(new Vector3D(780f, yButton, 0));
    colPickButton.setNoStroke(true);
    colPickButton.scale(2f, 2f, 1, colPickButton.getCenterPointLocal(), TransformSpace.LOCAL);
    colPickButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
              case TapEvent.BUTTON_UP:
                {
                  if (colorWidget.isVisible()) {
                    colorWidget.setVisible(false);
                  } else {
                    colorWidget.setVisible(true);
                    colorWidget.sendToFront();
                  }
                }
                break;
              default:
                break;
            }
          }
        });

    // Add a slider to set the brush width
    final MTSlider slider = new MTSlider(0, 0, 400, 76, 0.05f, 2.0f, mtApplication);

    slider.setValue(0);
    frame.addChild(slider);
    //        slider.rotateZ(new Vector3D(), 90, TransformSpace.LOCAL);
    slider.translate(new Vector3D(880, mtApplication.height - (eraser.height / 1.5f)));
    slider.setStrokeColor(new MTColor(0, 0, 0));
    slider.setFillColor(new MTColor(220, 220, 220));
    slider.getKnob().setFillColor(new MTColor(70, 70, 70));
    slider.getKnob().setStrokeColor(new MTColor(70, 70, 70));
    slider.addPropertyChangeListener(
        "value",
        new PropertyChangeListener() {
          public void propertyChange(PropertyChangeEvent p) {
            drawingScene.setBrushScale((Float) p.getNewValue());
          }
        });
    // Add triangle in slider to indicate brush width
    MTPolygon p =
        new MTPolygon(
            new Vertex[] {
              new Vertex(
                  2 + slider.getKnob().getWidthXY(TransformSpace.LOCAL),
                  slider.getHeightXY(TransformSpace.LOCAL) / 2f,
                  0),
              new Vertex(
                  slider.getWidthXY(TransformSpace.LOCAL) - 3,
                  slider.getHeightXY(TransformSpace.LOCAL) / 4f + 2,
                  0),
              new Vertex(
                  slider.getWidthXY(TransformSpace.LOCAL) - 1,
                  slider.getHeightXY(TransformSpace.LOCAL) / 2f,
                  0),
              new Vertex(
                  slider.getWidthXY(TransformSpace.LOCAL) - 3,
                  -slider.getHeightXY(TransformSpace.LOCAL) / 4f
                      - 2
                      + slider.getHeightXY(TransformSpace.LOCAL),
                  0),
              new Vertex(2, slider.getHeightXY(TransformSpace.LOCAL) / 2f, 0),
            },
            mtApplication);
    p.setFillColor(new MTColor(150, 150, 150, 150));
    p.setStrokeColor(new MTColor(160, 160, 160, 190));
    p.unregisterAllInputProcessors();
    p.setPickable(false);
    slider.getOuterShape().addChild(p);
    slider.getKnob().sendToFront();

    PImage editIcon = mtApplication.loadImage(path + "edit_icon.png");
    final MTImageButton editButton = new MTImageButton(editIcon, mtApplication);
    frame.addChild(editButton);
    editButton.translate(new Vector3D(360f, yButton, 0));
    editButton.setNoStroke(true);
    editButton.setStrokeColor(new MTColor(0, 0, 0));
    editButton.scale(2f, 2f, 1, editButton.getCenterPointLocal(), TransformSpace.LOCAL);

    PImage handIcon = mtApplication.loadImage(path + "hand2.png");
    final MTImageButton handButton = new MTImageButton(handIcon, mtApplication);
    frame.addChild(handButton);
    handButton.translate(new Vector3D(250f, yButton, 0));
    handButton.setNoStroke(true);
    handButton.setStrokeColor(new MTColor(0, 0, 0));
    handButton.scale(2f, 2f, 1, handButton.getCenterPointLocal(), TransformSpace.LOCAL);

    penButton.setVisible(false);
    brushButton.setVisible(false);
    slider.setVisible(false);
    colPickButton.setVisible(false);
    eraserButton.setVisible(false);
    sceneTexture.setVisible(false);

    handButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
              case TapEvent.BUTTON_UP:
                {
                  handButton.setNoStroke(false);
                  penButton.setVisible(false);
                  brushButton.setVisible(false);
                  slider.setVisible(false);
                  colPickButton.setVisible(false);
                  eraserButton.setVisible(false);

                  sceneTexture.setVisible(false);
                }
                break;
              default:
                break;
            }
          }
        });

    editButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
              case TapEvent.BUTTON_UP:
                {
                  editButton.setNoStroke(false);
                  penButton.setVisible(true);
                  brushButton.setVisible(true);
                  slider.setVisible(true);
                  colPickButton.setVisible(true);
                  eraserButton.setVisible(true);

                  sceneTexture.setVisible(true);
                  //					sceneTexture.sendToFront();
                  frame.sendToFront();
                }
                break;
              default:
                break;
            }
          }
        });
  }
Exemplo n.º 5
0
  public FlickrScene(MTApplication mtAppl, String name) {
    super(mtAppl, name);
    this.app = mtAppl;
    piler = new PileManager(this.app, this.getCanvas());

    // Set a zoom limit
    final MTCamera camManager = new MTCamera(mtAppl);
    this.setSceneCam(camManager);
    this.getSceneCam().setZoomMinDistance(80);

    //		this.setClearColor(new MTColor(135, 206, 250, 255));
    this.setClearColor(new MTColor(70, 70, 72, 255));

    // Show touches
    this.registerGlobalInputProcessor(new CursorTracer(mtAppl, this));

    // Add multitouch gestures to the canvas background
    lassoProcessor = new LassoProcessor(app, this.getCanvas(), this.getSceneCam());
    this.getCanvas().registerInputProcessor(lassoProcessor);
    this.getCanvas()
        .addGestureListener(
            LassoProcessor.class,
            new DefaultLassoAction(app, this.getCanvas().getPileManager(), this.getCanvas()));

    this.getCanvas().registerInputProcessor(new PanProcessorTwoFingers(app));
    this.getCanvas().addGestureListener(PanProcessorTwoFingers.class, new DefaultPanAction());

    this.getCanvas().registerInputProcessor(new ZoomProcessor(app));
    this.getCanvas().addGestureListener(ZoomProcessor.class, new DefaultZoomAction());

    makePileProcessor = new MakePileProcessor(app, this.getCanvas());
    this.getCanvas().registerInputProcessor(makePileProcessor);
    this.getCanvas()
        .addGestureListener(
            MakePileProcessor.class,
            new DefaultMakePileAction(app, this.getCanvas().getPileManager(), this.getCanvas()));

    this.getCanvas().registerInputProcessor(new TapAndHoldProcessor(app, 2000));
    this.getCanvas()
        .addGestureListener(TapAndHoldProcessor.class, new TapAndHoldVisualizer(app, getCanvas()));
    this.getCanvas()
        .addGestureListener(
            TapAndHoldProcessor.class,
            new IGestureEventListener() {
              public boolean processGestureEvent(MTGestureEvent ge) {
                TapAndHoldEvent th = (TapAndHoldEvent) ge;
                switch (th.getId()) {
                  case TapAndHoldEvent.GESTURE_DETECTED:
                    break;
                  case TapAndHoldEvent.GESTURE_UPDATED:
                    break;
                  case TapAndHoldEvent.GESTURE_ENDED:
                    break;
                  default:
                    break;
                }
                return false;
              }
            });

    piler = new PileManager(app, getCanvas());

    pictureLayer = new MTComponent(app);

    MTComponent topLayer = new MTComponent(app, "top layer group", new MTCamera(app));

    PImage keyboardImg =
        app.loadImage(
            System.getProperty("user.dir")
                + File.separator
                + "examples"
                + File.separator
                + "advanced"
                + File.separator
                + File.separator
                + "flickrMT"
                + File.separator
                + File.separator
                + "data"
                + File.separator
                //		+ "keyb2.png");
                + "keyb128.png");

    final MTImageButton keyboardButton = new MTImageButton(keyboardImg, app);
    keyboardButton.setFillColor(new MTColor(255, 255, 255, 200));
    keyboardButton.setName("KeyboardButton");
    keyboardButton.setNoStroke(true);
    //		keyboardButton.translateGlobal(new Vector3D(5,5,0));
    keyboardButton.translateGlobal(
        new Vector3D(-2, app.height - keyboardButton.getWidthXY(TransformSpace.GLOBAL) + 2, 0));
    topLayer.addChild(keyboardButton);

    progressBar =
        new MTProgressBar(
            app, app.loadFont(MT4jSettings.getInstance().getDefaultFontPath() + "Ziggurat.vlw"));
    progressBar.setDepthBufferDisabled(true);
    progressBar.setVisible(false);
    topLayer.addChild(progressBar);

    keyboardButton.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent ae) {
            switch (ae.getID()) {
              case TapEvent.BUTTON_CLICKED:
                // Flickr Keyboard
                MTKeyboard keyb = new MTKeyboard(app);
                keyb.setFillColor(new MTColor(30, 30, 30, 210));
                keyb.setStrokeColor(new MTColor(0, 0, 0, 255));

                final MTTextArea t =
                    new MTTextArea(
                        app,
                        FontManager.getInstance()
                            .createFont(
                                app,
                                "arial.ttf",
                                50,
                                new MTColor(0, 0, 0, 255), // Fill color
                                new MTColor(0, 0, 0, 255))); // Stroke color
                t.setStrokeColor(new MTColor(0, 0, 0, 255));
                t.setFillColor(new MTColor(205, 200, 177, 255));
                t.unregisterAllInputProcessors();
                t.setEnableCaret(true);
                t.snapToKeyboard(keyb);
                keyb.addTextInputListener(t);

                // Flickr Button for the keyboard
                MTSvgButton flickrButton =
                    new MTSvgButton(
                        System.getProperty("user.dir")
                            + File.separator
                            + "examples"
                            + File.separator
                            + "advanced"
                            + File.separator
                            + File.separator
                            + "flickrMT"
                            + File.separator
                            + "data"
                            + File.separator
                            + "Flickr_Logo.svg",
                        app);
                flickrButton.scale(0.4f, 0.4f, 1, new Vector3D(0, 0, 0), TransformSpace.LOCAL);
                flickrButton.translate(new Vector3D(0, 15, 0));
                flickrButton.setBoundsPickingBehaviour(AbstractShape.BOUNDS_ONLY_CHECK);

                // Add actionlistener to flickr button
                flickrButton.addActionListener(
                    new ActionListener() {
                      public void actionPerformed(ActionEvent arg0) {
                        if (arg0.getSource() instanceof MTComponent) {
                          // MTBaseComponent clickedComp = (MTBaseComponent)arg0.getSource();
                          switch (arg0.getID()) {
                            case TapEvent.BUTTON_CLICKED:
                              // Get current search parameters
                              SearchParameters sp = new SearchParameters();
                              // sp.setSafeSearch("213on");
                              /*
                              DateFormat dateFormat = new SimpleDateFormat ("yyyy/MM/dd HH:mm:ss");
                              java.util.Date date = new java.util.Date ();
                              String dateStr = dateFormat.format (date);
                              System.out.println("Date: " + dateStr);
                              try{
                              	Date date2 = dateFormat.parse (dateStr);
                              	sp.setInterestingnessDate(date2);
                              }catch(ParseException pe){
                              	pe.printStackTrace();
                              }
                              */

                              // sp.setMachineTags(new String[]{"geo:locality=\"san francisco\""});
                              sp.setText(t.getText());
                              // sp.setTags(new String[]{t.getText()});
                              sp.setSort(SearchParameters.RELEVANCE);

                              System.out.println("Flickr search for: \"" + t.getText() + "\"");

                              // Load flickr api key from file
                              String flickrApiKey = "";
                              String flickrSecret = "";
                              Properties properties = new Properties();
                              try {
                                properties.load(
                                    new FileInputStream(
                                        System.getProperty("user.dir")
                                            + File.separator
                                            + "examples"
                                            + File.separator
                                            + "advanced"
                                            + File.separator
                                            + File.separator
                                            + "flickrMT"
                                            + File.separator
                                            + "data"
                                            + File.separator
                                            + "FlickrApiKey.txt"));
                                flickrApiKey = properties.getProperty("FlickrApiKey", " ");
                                flickrSecret = properties.getProperty("FlickrSecret", " ");
                              } catch (Exception e) {
                                System.err.println(
                                    "Error while loading Settings.txt file. Using defaults.");
                              }

                              // Create flickr loader thread
                              final FlickrMTFotoLoader flickrLoader =
                                  new FlickrMTFotoLoader(app, flickrApiKey, flickrSecret, sp, 300);
                              flickrLoader.setFotoLoadCount(15);
                              // Define action when loader thread finished
                              flickrLoader.addProgressFinishedListener(
                                  new IMTEventListener() {
                                    public void processMTEvent(MTEvent mtEvent) {
                                      // Add the loaded fotos in the main drawing thread to
                                      // avoid threading problems
                                      registerPreDrawAction(
                                          new IPreDrawAction() {
                                            public void processAction() {
                                              MTImage[] fotos = flickrLoader.getMtFotos();
                                              for (int i = 0; i < fotos.length; i++) {
                                                MTImage card = fotos[i];
                                                card.setUseDirectGL(true);
                                                card.setDisplayCloseButton(true);
                                                card.setPositionGlobal(
                                                    new Vector3D(
                                                        Tools3D.getRandom(
                                                            10,
                                                            MT4jSettings.getInstance()
                                                                    .getScreenWidth()
                                                                - 100),
                                                        Tools3D.getRandom(
                                                            10,
                                                            MT4jSettings.getInstance()
                                                                    .getScreenHeight()
                                                                - 50),
                                                        0));
                                                card.toSize(200, 200);
                                                card.addGestureListener(
                                                    DragProcessor.class, new InertiaDragAction());
                                                lassoProcessor.addClusterable(
                                                    card); // make fotos lasso-able
                                                makePileProcessor.addClusterable(
                                                    card); // make elements pileable by this
                                                           // processor
                                                piler.addPileable(
                                                    card); // makes the photos pile-able
                                                pictureLayer.addChild(card);
                                              }
                                              progressBar.setVisible(false);
                                            }

                                            public boolean isLoop() {
                                              return false;
                                            }
                                          });
                                    }
                                  });
                              progressBar.setProgressInfoProvider(flickrLoader);
                              progressBar.setVisible(true);
                              // Run the thread
                              flickrLoader.start();
                              // Clear textarea
                              t.clear();
                              break;
                            default:
                              break;
                          }
                        }
                      }
                    });
                keyb.addChild(flickrButton);
                //			        getCanvas().addChild(0, keyb);
                getCanvas().addChild(keyb);
                keyb.setPositionGlobal(new Vector3D(app.width / 2f, app.height / 2f, 0));
                break;
              default:
                break;
            }
          }
        });

    this.getCanvas().addChild(pictureLayer);
    this.getCanvas().addChild(topLayer);
  }
Exemplo n.º 6
0
  /**
   * Instantiates a new model display scene.
   *
   * @param mtApplication the mt application
   * @param name the name
   */
  public Space3DScene(MTApplication mtApplication, String name) {
    super(mtApplication, name);
    this.pa = mtApplication;

    if (!MT4jSettings.getInstance().isOpenGlMode()) {
      System.err.println("Scene only usable when using the OpenGL renderer! - See settings.txt");
      return;
    }

    this.setClearColor(new MTColor(200, 200, 200, 255));
    this.registerGlobalInputProcessor(new CursorTracer(pa, this));

    // Add a background image for the scene
    this.getCanvas()
        .addChild(new MTBackgroundImage(pa, pa.loadImage(imagesPath + "3040.jpg"), true));

    // Init light settings
    MTLight.enableLightningAndAmbient(pa, 150, 150, 150, 255);
    // Create a light source //I think GL_LIGHT0 is used by processing!
    //		MTLight light = new MTLight(pa, GL.GL_LIGHT3, new Vector3D(0,0,0));
    MTLight light = new MTLight(pa, GL.GL_LIGHT3, new Vector3D(pa.width / 5f, -pa.height / 10f, 0));

    // Set up a material to react to the light
    GLMaterial material = new GLMaterial(Tools3D.getGL(pa));
    material.setAmbient(new float[] {.1f, .1f, .1f, 1f});
    material.setDiffuse(new float[] {1.0f, 1.0f, 1.0f, 1f});
    material.setEmission(new float[] {.0f, .0f, .0f, 1f});
    material.setSpecular(new float[] {1.0f, 1.0f, 1.0f, 1f}); // almost white: very reflective
    material.setShininess(127); // 0=no shine,  127=max shine

    // Create the earth
    earth = new MTSphere(pa, "earth", 40, 40, 80, TextureMode.Projected); // TextureMode.Polar);
    earth.setLight(light);
    earth.setMaterial(material);
    earth.rotateX(earth.getCenterPointRelativeToParent(), -90);
    earth.setTexture(
        new GLTexture(
            pa,
            imagesPath + "worldMap.jpg",
            new GLTextureSettings(
                TEXTURE_TARGET.TEXTURE_2D,
                SHRINKAGE_FILTER.Trilinear,
                EXPANSION_FILTER.Bilinear,
                WRAP_MODE.CLAMP_TO_EDGE,
                WRAP_MODE.CLAMP_TO_EDGE)));
    earth.generateAndUseDisplayLists();
    earth.setPositionGlobal(
        new Vector3D(
            pa.width / 2f,
            pa.height / 2f,
            250)); // earth.setPositionGlobal(new Vector3D(200, 200, 250));
    // Animate earth rotation
    new Animation(
            "rotation animation", new MultiPurposeInterpolator(0, 360, 17000, 0, 1, -1), earth)
        .addAnimationListener(
            new IAnimationListener() {
              public void processAnimationEvent(AnimationEvent ae) {
                earth.rotateY(earth.getCenterPointLocal(), ae.getDelta(), TransformSpace.LOCAL);
              }
            })
        .start();

    // Put planets in a group that can be manipulated by gestures
    // so the rotation of the planets doesent get changed by the gestures
    MTComponent group = new MTComponent(mtApplication);
    group.setComposite(
        true); // This makes the group "consume" all picking and gestures of the children
    group.registerInputProcessor(new DragProcessor(mtApplication));
    group.addGestureListener(DragProcessor.class, new DefaultDragAction());
    group.addGestureListener(DragProcessor.class, new InertiaDragAction(80, 0.8f, 10));
    group.registerInputProcessor(new RotateProcessor(mtApplication));
    group.addGestureListener(RotateProcessor.class, new DefaultRotateAction());
    // Scale the earth from the center. Else it might get distorted
    group.registerInputProcessor(new ScaleProcessor(mtApplication));
    group.addGestureListener(
        ScaleProcessor.class,
        new IGestureEventListener() {
          public boolean processGestureEvent(MTGestureEvent ge) {
            ScaleEvent se = (ScaleEvent) ge;
            earth.scaleGlobal(
                se.getScaleFactorX(),
                se.getScaleFactorY(),
                se.getScaleFactorX(),
                earth.getCenterPointGlobal());
            return false;
          }
        });
    this.getCanvas().addChild(group);
    group.addChild(earth);

    // Create the moon
    final MTSphere moonSphere = new MTSphere(pa, "moon", 35, 35, 25, TextureMode.Polar);
    moonSphere.setMaterial(material);
    moonSphere.translate(new Vector3D(earth.getRadius() + moonSphere.getRadius() + 50, 0, 0));
    moonSphere.setTexture(
        new GLTexture(
            pa,
            imagesPath + "moonmap1k.jpg",
            new GLTextureSettings(
                TEXTURE_TARGET.RECTANGULAR,
                SHRINKAGE_FILTER.Trilinear,
                EXPANSION_FILTER.Bilinear,
                WRAP_MODE.CLAMP_TO_EDGE,
                WRAP_MODE.CLAMP_TO_EDGE)));
    moonSphere.generateAndUseDisplayLists();
    moonSphere.unregisterAllInputProcessors();
    // Rotate the moon around the earth
    new Animation(
            "moon animation", new MultiPurposeInterpolator(0, 360, 12000, 0, 1, -1), moonSphere)
        .addAnimationListener(
            new IAnimationListener() {
              public void processAnimationEvent(AnimationEvent ae) {
                moonSphere.rotateZ(
                    earth.getCenterPointLocal(), ae.getDelta(), TransformSpace.RELATIVE_TO_PARENT);
              }
            })
        .start();
    // Rotate the moon around ints own center
    new Animation(
            "moon animation around own axis",
            new MultiPurposeInterpolator(0, 360, 9000, 0, 1, -1),
            moonSphere)
        .addAnimationListener(
            new IAnimationListener() {
              public void processAnimationEvent(AnimationEvent ae) {
                moonSphere.rotateZ(
                    moonSphere.getCenterPointLocal(), -3 * ae.getDelta(), TransformSpace.LOCAL);
                moonSphere.rotateY(
                    moonSphere.getCenterPointLocal(), 0.5f * ae.getDelta(), TransformSpace.LOCAL);
              }
            })
        .start();
    earth.addChild(moonSphere);
  }
Exemplo n.º 7
0
  public AirHockeyScene(AbstractMTApplication mtApplication, String name) {
    super(mtApplication, name);
    this.app = mtApplication;
    //		this.setClearColor(new MTColor(120,150,150));
    //		this.setClearColor(new MTColor(190, 190, 170, 255));
    this.setClearColor(new MTColor(0, 0, 0, 255));
    //		this.setClearColor(new MTColor(40, 40, 40, 255));
    this.registerGlobalInputProcessor(new CursorTracer(app, this));

    this.scorePlayer1 = 0;
    this.scorePlayer2 = 0;

    float worldOffset = 10; // Make Physics world slightly bigger than screen borders
    // Physics world dimensions
    AABB worldAABB =
        new AABB(
            new Vec2(-worldOffset, -worldOffset),
            new Vec2((app.width) / scale + worldOffset, (app.height) / scale + worldOffset));
    Vec2 gravity = new Vec2(0, 0);
    boolean sleep = true;
    // Create the pyhsics world
    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(
            app,
            PhysicsHelper.scaleDown(0, scale),
            PhysicsHelper.scaleDown(0, scale),
            PhysicsHelper.scaleDown(app.width / 2f, scale),
            PhysicsHelper.scaleDown(app.height, scale));
    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(
            app,
            PhysicsHelper.scaleDown(app.width / 2f, scale),
            PhysicsHelper.scaleDown(0, scale),
            PhysicsHelper.scaleDown(app.width, scale),
            PhysicsHelper.scaleDown(app.height, scale));
    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, MTColor.WHITE);

    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);

    /*
    		//Sound
    		if (enableSound){
    			minim = new Minim(mtApplication);
    			wallHit = minim.loadSnippet(MT4jSettings.getInstance().getDataFolderPath() + "sound" + File.separator + "paddleBallHit.wav");
    //			paddleBallClash = minim.loadSample(MT4jSettings.getInstance().getDataFolderPath() + "sound" + File.separator + "paddleBallHit.wav", 2048);
    //			goalHit = minim.loadSnippet(MT4jSettings.getInstance().getDataFolderPath() + "sound" + File.separator + "goal.wav");
    //			goalHit.play();
    			paddleHit = minim.loadSnippet(MT4jSettings.getInstance().getDataFolderPath() + "sound" + File.separator + "wallHit.wav");
    		}
    		*/
  }