Package org.mt4j.util.math

Examples of org.mt4j.util.math.Vector3D


       * the resulting vertex normal
       */
      public Vector3D calcVertexNormalAllNeighbors(){
        if (allNeighborsNormal == null ){
          //Add up face normals of smooth neighbors
          Vector3D allNeighborNormal = new Vector3D(0,0,0);
          for (int i = 0; i < faces.size(); i++) {
            MyFace neighbor = faces.get(i);
            allNeighborNormal.addLocal(neighbor.normal);
           
            logger.debug("Vertex index:" + this.getArrayIndex() + " calcing in neighbor normal of face: " + neighbor.index);
          }
          //Normalize in the end
          allNeighborNormal.normalizeLocal();
          allNeighborsNormal = allNeighborNormal;
          return allNeighborsNormal;
        }else{
          return allNeighborsNormal;
        }
View Full Code Here


    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 = new MTProgressBar(app, app.createFont("arial", 18));
   
    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.setExpandDirection(ExpandDirection.UP);
          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( "advanced" + MTApplication.separator +  "flickrMT" + MTApplication.separator + "data" + MTApplication.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 {
                        InputStream in = null;
                        try {
                          in = new FileInputStream( "examples" + MTApplication.separator + "advanced" + MTApplication.separator + "flickrMT" + MTApplication.separator + "data" + MTApplication.separator + "FlickrApiKey.txt");
                    } catch (Exception e) {
                      System.err.println(e.getLocalizedMessage());
                    }
                   
                        if (in == null){
                          try {
                            in = Thread.currentThread().getContextClassLoader().getResourceAsStream("advanced" + MTApplication.separator + "flickrMT" + MTApplication.separator + "data" + MTApplication.separator + "FlickrApiKey.txt");
                      } catch (Exception e) {
                        System.err.println(e.getLocalizedMessage());
                      }
                        }
                        properties.load(in);

                        flickrApiKey = properties.getProperty("FlickrApiKey", " ");
                        flickrSecret = properties.getProperty("FlickrSecret", " ");
                    } catch (Exception e) {
                      System.err.println("Error while loading FlickrApiKey.txt file.");
                      e.printStackTrace();
                     
                    }
                     
                      //Create flickr loader thread
                      final FlickrMTFotoLoader flickrLoader = new FlickrMTFotoLoader(app, flickrApiKey, flickrSecret, sp, 300);
                      flickrLoader.setFotoLoadCount(5);
                      //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(ToolsMath.getRandom(10, MT4jSettings.getInstance().getWindowWidth()-100), ToolsMath.getRandom(10, MT4jSettings.getInstance().getWindowHeight()-50),0 )  );
                            card.scale(0.6f, 0.6f, 0.6f, card.getCenterPointLocal(), TransformSpace.LOCAL);
                            card.addGestureListener(DragProcessor.class, new InertiaDragAction());
                            lassoProcessor.addClusterable(card); //make fotos lasso-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;
        }
      }
View Full Code Here

  /**
   * Gets the position.
   * @return the position
   */
  public Vector3D getPosition(){
    return new Vector3D(getCurrentEvtPosX(), getCurrentEvtPosY());
  }
View Full Code Here

  /**
   * Gets the start position.
   * @return the start position
   */
  public Vector3D getStartPosition(){
    return new Vector3D(getStartPosX(), getStartPosY());
  }
View Full Code Here

    AbstractCursorInputEvt posEvt   = events.get(events.size()-1);
    AbstractCursorInputEvt prev   = events.get(events.size()-2);
    if (prev == null)
      prev = posEvt;
    //TODO normalize direction or not?
    return new Vector3D(posEvt.getPosX() - prev.getPosX(), posEvt.getPosY() - prev.getPosY(), 0);
  }
View Full Code Here

   
    //works ok with damping float dampingValue = 0.85f; later
   
    //System.out.println("X total: " + totalX);
    //System.out.println("Y total: " + totalY);
    return new Vector3D(totalX, totalY);
  }
View Full Code Here

   * @param y the y
   * @param width the width
   * @param height the height
   */
  public BoundsZPlaneRectangle(MTComponent peerComponent, float x, float y, float width, float height) {
    this(peerComponent, new Vector3D[]{new Vector3D(x,y), new Vector3D(x+width,y), new Vector3D(x+width,y+height), new Vector3D(x,y+height)});
  }
View Full Code Here

    float z = vertices[0].z;
    if (peerComponent != null && peerComponent instanceof AbstractShape){
      z = ((AbstractShape)peerComponent).getCenterPointLocal().z;
    }
    return (new Vector3D[]{
        new Vector3D(minX, minY,z),
        new Vector3D(maxX, minY,z),
        new Vector3D(maxX, maxY,z),
        new Vector3D(minX, maxY,z),
//        new Vector3D(minX, minY,z)
        });
  }
View Full Code Here

 
  public boolean intersects(BoundsZPlaneRectangle boundingRect){
    //TODO actually we would have to check all rectangle
    //line segments against each other instead of the points
    Vector3D[] globalBoundingVectorsR2 = boundingRect.getVectorsGlobal();
    Vector3D globalCenterR2 = boundingRect.getCenterPointGlobal();
    boolean colliding = false;
    //Check if rectangle points lie inside of this rectangle
    for (int i = 0; i < globalBoundingVectorsR2.length; i++) {
      Vector3D localVectorR2 = peerComponent.globalToLocal(globalBoundingVectorsR2[i]);
      if (this.containsPointLocal(localVectorR2)){
        colliding = true;
      }
    }
    //Check rectangle center
View Full Code Here

 
  public Vector3D getIntersectionLocal(Ray ray) {
    Vector3D[] verts = this.boundingPointsLocal;
//    rectNormal= this.getNormalObjSpace();
    //Normal should actually always be (0,0,1)!
    Vector3D testPoint = ToolsGeometry.getRayPlaneIntersection(ray, rectNormal, verts[0]);
   
    if (testPoint == null){
      return null;
    }
    return (this.containsPointLocal(testPoint) ? testPoint : null);
View Full Code Here

TOP

Related Classes of org.mt4j.util.math.Vector3D

Copyright © 2018 www.massapicom. 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.