Package com.jme3.math

Examples of com.jme3.math.Vector2f


    return this.m_CellPlane.getNormal();
  }

  public Vector3f getRandomPoint() {
    Random rand = new Random();
    Vector2f ret =
    this.m_Side[0].EndPointA().add(this.m_Side[0].GetDirection().mult(rand.nextFloat()).add(
        this.m_Side[1].GetDirection().mult(rand.nextFloat())));
    ForcePointToCellCollumn(ret);
    Vector3f vec = new Vector3f(ret.x, 0, ret.y);
    MapVectorHeightToCell(vec);
View Full Code Here


          }
        }
      }
     
      if (!FoundHomeCell) {
        Vector2f Start = new Vector2f(pCell.CenterPoint().x, pCell
            .CenterPoint().z);
        Vector2f End = new Vector2f(Point.x, Point.z);
        Line2D MotionPath = new Line2D(Start, End);

        ClassifyResult Result = pCell.ClassifyPathToCell(MotionPath);

        if (Result.result == Cell.PATH_RESULT.EXITING_CELL) {
View Full Code Here

  @Deprecated //Use EntityNavigationManager.revolveMotionNewWay
  public Cell ResolveMotionOnMesh(Vector3f StartPos, Cell StartCell,  Vector3f EndPos) {
    // create a 2D motion path from our Start and End positions, tossing out
    // their Y values to project them
    // down to the XZ plane.
    Line2D MotionPath = new Line2D(new Vector2f(StartPos.x, StartPos.z),
        new Vector2f(EndPos.x, EndPos.z));

    // these three will hold the results of our tests against the cell walls
    ClassifyResult Result = null;

    // TestCell is the cell we are currently examining.
    Cell TestCell = StartCell;

//    do {
//      i++;
      // use NavigationCell to determine how our path and cell interact
//       if(TestCell.IsPointInCellCollumn(MotionPath.EndPointA()))
//       System.out.println("Start is in cell:"+TestCell);
//       else
//       System.out.println("Start is NOT in cell:"+TestCell);
//       if(TestCell.IsPointInCellCollumn(MotionPath.EndPointB()))
//       System.out.println("End is in cell:"+TestCell);
//       else
//       System.out.println("End is NOT in cell:"+TestCell);
      Result = TestCell.ClassifyPathToCell(MotionPath);

      // if exiting the cell...
      if (Result.result == Cell.PATH_RESULT.EXITING_CELL) {
        // Set if we are moving to an adjacent cell or we have hit a
        // solid (unlinked) edge
        if (Result.cell != null) {
          // moving on. Set our motion origin to the point of
          // intersection with this cell
          // and continue, using the new cell as our test cell.
          MotionPath.SetEndPointA(Result.intersection);
          TestCell = Result.cell;
        } else {
          //FIXME this could also be the case of switching meshes :-< check this !!
//          Cell c = Singleton.get().getNavManager().FindClosestCell(EndPos, true);
//          if(c!= null && c != TestCell){
////System.out.println("Mesh switching");
//              TestCell =c;
//          }
//          else{
            //FIXME thid should push the entity more away from a wall than it does at the moment and make it move more perpendicular to the wall
//System.out.println("Hitting a wall!");
            // we have hit a solid wall. Resolve the collision and
            // correct our path.
            MotionPath.SetEndPointA(Result.intersection);
            TestCell.ProjectPathOnCellWall(Result.side, MotionPath);
 
            // add some friction to the new MotionPath since we are
            // scraping against a wall.
            // we do this by reducing the magnatude of our motion by 10%
            Vector2f Direction = MotionPath.EndPointB().subtract(
                MotionPath.EndPointA()).mult(0.9f);
            // Direction.mult(0.9f);
            MotionPath.SetEndPointB(MotionPath.EndPointA().add(
                Direction));
//          }
        }
      } else if (Result.result == Cell.PATH_RESULT.NO_RELATIONSHIP) {
//System.out.println("NO RELATION");
        //FIXME this could also be the case of optimized meshes
//        Cell c =Singleton.get().getNavManager().FindClosestCell(EndPos, true);
//        if(c!= null && c != TestCell){
//            TestCell =c;
//        } else {
        // Although theoretically we should never encounter this case,
        // we do sometimes find ourselves standing directly on a vertex
        // of the cell.
        // This can be viewed by some routines as being outside the
        // cell.
        // To accomodate this rare case, we can force our starting point
        // to be within
        // the current cell by nudging it back so we may continue.
        Vector2f NewOrigin = MotionPath.EndPointA();
        TestCell.ForcePointToCellCollumn(NewOrigin);
//        MotionPath.SetEndPointA(NewOrigin);
        //we do not want to iterate we just want them to stop at the wall and not cet out
        MotionPath.SetEndPointB(NewOrigin);
//        }
View Full Code Here

  // Test to see if two points on the mesh can view each other
  //
  // -------------------------------------------------------------------------------------://
  // FIXME EndCell is the last visible cell?
  boolean LineOfSightTest(Cell StartCell, Vector3f StartPos, Vector3f EndPos) {
    Line2D MotionPath = new Line2D(new Vector2f(StartPos.x, StartPos.z),
        new Vector2f(EndPos.x, EndPos.z));

    Cell testCell = StartCell;
    Cell.ClassifyResult result = testCell.ClassifyPathToCell(MotionPath);
    ;
    while (result.result == Cell.PATH_RESULT.EXITING_CELL) {
View Full Code Here

        graphics.setRenderingHints( hints );
    }

    public Vector2f getMousePosition()
    {
      return new Vector2f((float)lastXin, (float)lastYin);
    }
View Full Code Here

            final Vector3f v1 = vertex[i1];
            final Vector3f v2 = vertex[i2];
            final Vector3f v3 = vertex[i3];

            final Vector2f w1 = texcoord[i1];
            final Vector2f w2 = texcoord[i2];
            final Vector2f w3 = texcoord[i3];

            final float x1 = v2.x - v1.x;
            final float x2 = v3.x - v1.x;
            final float y1 = v2.y - v1.y;
            final float y2 = v3.y - v1.y;
View Full Code Here

      //TODO check heading is really of any relevance
      if(FastMath.abs(heading-pos.heading)> FastMath.PI/180f*5f)//difference by more than 5 degrees
        log.severe(objId+" heads differ by more than 5 deg cHeading:"+pos.heading+" tHeading:"+heading);
     
      //also do an adjustment to get closer to server location
      if(new Vector2f(tPos.x, tPos.z).distance(new Vector2f(pos.position.x,pos.position.z)) > 1f) {
        log.severe(objId+" positions differ in x/z by more than 1f current:"+pos.position+" target:"+tPos);

        Singleton.get().getPosSystem().initMoveTo(objId, tPos.x, tPos.y, tPos.z, pos.position.x, pos.position.y, pos.position.z);
      }
      if(Singleton.get().getEntityManager().isPlayerComponent(pos)){
View Full Code Here

    }
    faceMat.setBoolean("Swaying", true);
    faceMat.setVector3("SwayData", new Vector3f(1.0f, 0.5f, 300f));// frequency,
                                    // variation,
                                    // third?
    faceMat.setVector2("Wind", new Vector2f(1f, 1f));

    Geometry terrain = null;

    if (spatial instanceof Geometry) {
      terrain = (Geometry) spatial;
    } else {
      for (Spatial currentSpatial : spatNode.getChildren()) {
        if (currentSpatial instanceof Geometry) {
          terrain = (Geometry) currentSpatial;
          break;
        }
      }
    }

    if (terrain == null || spatNode.getChildren().isEmpty()) {
      Logger.getLogger(GrassLayerUtil.class.getName()).log(Level.SEVERE,
          "Could not find terrain object.", new Exception());
      System.exit(0);
    }

    // Generate grass uniformly with random offset.
    float terrainWidth = 1f * 256; // get width length of terrain(assuming
                    // its a square)
    BoundingVolume bounds = ((Spatial) terrain).getWorldBound();
    if (BoundingVolume.Type.AABB.equals(bounds.getType())) {
      BoundingBox bb = ((BoundingBox) bounds);
      terrainWidth = Math.max(bb.getXExtent(), bb.getZExtent());
      terrainWidth *= 2f;
    } else if (BoundingVolume.Type.Sphere.equals(bounds.getType())) {
      terrainWidth = ((BoundingSphere) bounds).getRadius();
      terrainWidth *= 2f;
    }
    Vector3f centre = bounds.getCenter(); // get the centr location of the
                        // terrain
    Vector2f grassPatchRandomOffset = new Vector2f().zero();
    Vector3f candidateGrassPatchLocation = new Vector3f();

    Random rand = new Random();
    Ray ray = new Ray(Vector3f.ZERO, Vector3f.UNIT_Y.mult(-1f));
    CollisionResults results = new CollisionResults();
    float ax, az;
    for (float x = centre.x - terrainWidth / 2 + inc; x < centre.x
        + terrainWidth / 2 - inc; x += inc) {
      for (float z = centre.z - terrainWidth / 2 + inc; z < centre.z
          + terrainWidth / 2 - inc; z += inc) {
        grassPatchRandomOffset.set(inc, inc);
        grassPatchRandomOffset.multLocal(rand.nextFloat()); // make the
                                  // off set
                                  // length a
                                  // random
                                  // distance
                                  // smaller
                                  // than the
                                  // increment
                                  // size
        grassPatchRandomOffset
            .rotateAroundOrigin(
                (float) (((int) (rand.nextFloat() * 359)) * (Math.PI / 180)),
                true); // rotate the offset by a random angle

        ax = x + grassPatchRandomOffset.x;
View Full Code Here

      matParam = terrain.getMaterial().getParam("DiffuseMap");
    if (matParam == null)
      return false;
    Texture tex = (Texture) matParam.getValue();
    Image image = tex.getImage();
    Vector2f uv = getPointPercentagePosition(terrain, pos, scaledWidth);

    ByteBuffer buf = image.getData(0);
    int width = image.getWidth();
    int height = image.getHeight();
View Full Code Here

    }
  }

  private static Vector2f getPointPercentagePosition(Geometry terrain,
      Vector3f worldLoc, float scaledWidth) {
    Vector2f uv = new Vector2f(worldLoc.x, worldLoc.z);
    uv.subtractLocal(terrain.getWorldTranslation().x,
        terrain.getWorldTranslation().z); // center it on 0,0
    // float scaledSize = terrain.getTerrainSize()*scale;
    uv.addLocal(scaledWidth / 2, scaledWidth / 2); // shift the bottom left
                            // corner up to 0,0
    uv.divideLocal(scaledWidth); // get the location as a percentage

    return uv;
  }
View Full Code Here

TOP

Related Classes of com.jme3.math.Vector2f

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.