Package com.jme3.math

Examples of com.jme3.math.Vector3f


  public void testSelf(){
   
//    Vector3f[] vs = {new Vector3f(0,0,0),new Vector3f(1,0,0),new Vector3f(0,0,1),new Vector3f(1,0,1)};
    TiledNavMesh m = new TiledNavMesh();
      m.loadFromData(new Vector3f[] {new Vector3f(-1,0,1),new Vector3f(-1,0,-1), new Vector3f(1,0,-1), new Vector3f(1,0,1)}, new short[][] {{0,2,1},{0,3,2}}, Vector3f.ZERO);
      assertTrue(m.getCell(0).m_Link[0]!= null);
      assertTrue(m.getCell(0).m_WallMidpoint[0].equals(m.getCell(1).m_WallMidpoint[2]));
      assertTrue(m.getCell(0).IsPointInCellCollumn(new Vector3f(-0.2f,0,-0.8f)));
      assertTrue(m.getCell(1).IsPointInCellCollumn(new Vector3f(0.2f,0,0.8f)));
  }
View Full Code Here


      EntityNavigationManager em = Singleton.get().getNavManager();

       
        TiledNavMesh n1 = getNavMesh("0/0", Vector3f.ZERO);
        em.attachMesh(n1);
        TiledNavMesh n2 = getNavMesh(""+IArea.TERRAIN_SIZE+"/0", new Vector3f(IArea.TERRAIN_SIZE,0,0));
        em.attachMesh(n2);
        TiledNavMesh n3 = getNavMesh("0/-"+IArea.TERRAIN_SIZE, new Vector3f(0,0,-IArea.TERRAIN_SIZE));
        em.attachMesh(n3);       

        TiledNavMesh n11 = em.getNavMesh(10,10);
        System.out.println("Navmesh with 10/10 in it is:"+n11+" ? 0/0 ?");
        assertEquals(n1, n11);
        TiledNavMesh n22 = em.getNavMesh(IArea.TERRAIN_SIZE+10,10);
        System.out.println("Navmesh with "+(IArea.TERRAIN_SIZE+10)+"/10 in it is:"+n22+" ? "+IArea.TERRAIN_SIZE+"/0 ?");
        assertEquals(n2, n22);
        TiledNavMesh n33 = em.getNavMesh(10,-IArea.TERRAIN_SIZE+10);
        System.out.println("Navmesh with 10/-"+(IArea.TERRAIN_SIZE+10)+" in it is:"+n33+" ? 0/-"+IArea.TERRAIN_SIZE+" ?");
        assertEquals(n3, n33);
        TiledNavMesh n44 = em.getNavMesh(10,10);
        assertEquals(n11, n44);

        Vector3f sPos = new Vector3f(10,0,10);
        Vector3f ePos = new Vector3f(30,0,30);
        Path p = null;
        p= NavTestHelper.findPath(em, sPos, ePos);
        assertNotNull(p);//path inside tile
        assertTrue(NavTestHelper.areCellsConnected(p));
        sPos = new Vector3f(10,0,-10);
        ePos = new Vector3f(30,0,30);
        p =NavTestHelper.findPath(em, sPos, ePos);//path inside tile
        assertNotNull(p);
        assertTrue(NavTestHelper.areCellsConnected(p));
        assertNotNull(NavTestHelper.walkPath(em, sPos, ePos, 4f));
        assertNull(NavTestHelper.findPath(em, sPos, new Vector3f(0,0,IArea.TERRAIN_SIZE+1)));//target is no tile
        assertNotNull(NavTestHelper.findPath(em, sPos, new Vector3f(0,0,IArea.TERRAIN_SIZE-1)));//crossing from one to the other
        assertNull(NavTestHelper.findPath(em, new Vector3f(-IArea.TERRAIN_SIZE_HALF,0,0), new Vector3f(IArea.TERRAIN_SIZE_HALF,0,1)));//target further way than tile side length, should fail
    }
View Full Code Here

     * @param worldtrans  center position of quad
     * @return
     */
    private TiledNavMesh getNavMesh(String name, Vector3f worldtrans){
      TiledNavMesh m = new TiledNavMesh();
      m.loadFromData(new Vector3f[] {new Vector3f(0,0,IArea.TERRAIN_SIZE),
          new Vector3f(0,0,0),
          new Vector3f(IArea.TERRAIN_SIZE,0,0),
          new Vector3f(IArea.TERRAIN_SIZE,0,IArea.TERRAIN_SIZE)},
          new short[][] {{0,2,1},{0,3,2}}, worldtrans);
      return m;
    }
View Full Code Here

   * @param worldtrans  The final world translation of the tile center
   */
    public void loadFromData(Vector3f[] positions, short[][] indices, Vector3f worldtrans){

    this.worldTranslation = worldtrans.clone();
        Vector3f offset = Vector3f.ZERO;
        int down = 0;
        int total = 0;
       
    clearBorderPoints();
    createBounds();
   
        Plane up = new Plane();
        up.setPlanePoints(Vector3f.UNIT_X, Vector3f.ZERO, Vector3f.UNIT_Z);
        up.getNormal();

        Vector3f vertA = null;
        Vector3f vertB = null;
        Vector3f vertC = null;
        Cell c = null;
        for (int i = 0; i < indices.length; i++) {
          total++;
            vertA = positions[indices[i][0]];
            vertB = positions[indices[i][1]];
            vertC = positions[indices[i][2]];
           
            Plane p = new Plane();
            p.setPlanePoints(vertA, vertB, vertC);
            if (up.pseudoDistance(p.getNormal()) <= 0.0f) {
                down++;
                continue;
            }
           
      borderCorrection(vertA, offset);
            borderCorrection(vertB, offset);
            borderCorrection(vertC, offset);
           
            vertA = vertA.add(worldtrans);
            vertB = vertB.add(worldtrans);
            vertC = vertC.add(worldtrans);

            c = AddCell(vertA, vertB, vertC);
            storeBorderCell(c);
        }

View Full Code Here

     * @param worldtrans    The final center of the tile used for border creation
     * @param isRelative    true if the mesh is in local coordinates, false if already translated to worldtrans
     */
    public void loadFromMesh(Mesh mesh, Vector3f worldtrans, boolean isRelative) {
      worldTranslation = worldtrans.clone();
    Vector3f offset;
   
    int down = 0;
    int slope = 0;
    int total = 0;
    float maxSlope = 82f;
   
    if(isRelative)
      offset = Vector3f.ZERO;
    else
      offset = worldtrans;
   
    clearBorderPoints();
    createBounds();

        Plane up = new Plane();
        up.setPlanePoints(Vector3f.UNIT_X, Vector3f.ZERO, Vector3f.UNIT_Z);
        up.getNormal();
        float minNormalY = (float)Math.cos(Math.abs(maxSlope)/180 * Math.PI);

        IndexBuffer ib = mesh.getIndexBuffer();
        FloatBuffer pb = mesh.getFloatBuffer(Type.Position);
        pb.clear();
        for (int i = 0; i < mesh.getTriangleCount()*3; i+=3){
          total++;
            int i1 = ib.get(i+0);
            int i2 = ib.get(i+1);
            int i3 = ib.get(i+2);
            Vector3f a = new Vector3f();
            Vector3f b = new Vector3f();
            Vector3f c = new Vector3f();
            BufferUtils.populateFromBuffer(a, pb, i1);
            BufferUtils.populateFromBuffer(b, pb, i2);
            BufferUtils.populateFromBuffer(c, pb, i3);
           
            borderCorrection(a, offset);
            borderCorrection(b, offset);
            borderCorrection(c, offset);
       
            if(isRelative){
              a=a.add(worldtrans);
              b=b.add(worldtrans);
              c=c.add(worldtrans);
            }
           
            Plane p = new Plane();
            p.setPlanePoints(a, b, c);
            if (up.pseudoDistance(p.getNormal()) <= 0.0f) {
View Full Code Here

    return borders.containsKey(c);
  }

  //distance between must be within SimpleTerrainManger.TERRAIN_SIZE
  boolean isNeighbourOf(TiledNavMesh endMesh) {
    Vector3f dist = worldTranslation.subtract(endMesh.worldTranslation);
    if(FastMath.abs(dist.x)>TERRAIN_SIZE ||
        FastMath.abs(dist.y)>TERRAIN_SIZE)
      return false;
   
    return true;
View Full Code Here

        //max dist can not be more than the span of a mesh tile
        float max = (TERRAIN_SIZE*TERRAIN_SIZE) +
              (TERRAIN_SIZE*TERRAIN_SIZE) + 0.01f;
        float dist = 0f;
        Cell targetCell = null;
        Vector3f goal = null;
        //loop over them and find the closest one //what if none on that sides, why loop at some which are completely off ???
        for(Cell c : targets){
          //prefere computed cross section over midpoints
          if(c.IsPointInCellCollumn(cross)){
            targetCell = c;
            goal = new Vector3f(cross.x, 0, cross.y);
            c.MapVectorHeightToCell(goal);
            break;
          }
          //all cell midpoints
          for(Vector3f point : c.m_WallMidpoint){
View Full Code Here

  }
 

  public Geometry getDebugBounds(float y){
    Collection<Geometry> geometries = new ArrayList<Geometry>();
    Line l = new Line(new Vector3f(top.EndPointA().x, y, top.EndPointA().y),
              new Vector3f(top.EndPointB().x, y, top.EndPointB().y));
    geometries.add(new Geometry("top", l));

   
    l = new Line(new Vector3f(right.EndPointA().x, y, right.EndPointA().y),
          new Vector3f(right.EndPointB().x, y, right.EndPointB().y));
    geometries.add(new Geometry("right", l));
   
    l = new Line(new Vector3f(bottom.EndPointA().x, y, bottom.EndPointA().y),
          new Vector3f(bottom.EndPointB().x, y, bottom.EndPointB().y));
    geometries.add(new Geometry("bottom", l));
   
    l = new Line(new Vector3f(left.EndPointA().x, y, left.EndPointA().y),
          new Vector3f(left.EndPointB().x, y, left.EndPointB().y));
    geometries.add(new Geometry("left", l));

    Mesh m = new Mesh();
    GeometryBatchFactory.mergeGeometries(geometries, m);
    Geometry g = new Geometry("bounds of "+toString(), m);
View Full Code Here

  }
 
  public void setPosition(Vector3f position){
    //if a position has already been set we do this only by the offset if it is really of any value
    Vector3f offset = position.subtract(worldTranslation);
    if(offset.length() > 0.0001f){
      //update all cells
      for(Cell c : mCellArray){
//        c.Initialize(c.m_Vertex[0].add(offset), c.m_Vertex[1].add(offset), c.m_Vertex[2].add(offset));
        //update all centers
        c.m_CenterPoint.addLocal(offset);
View Full Code Here

          ret = (TiledNavMesh) BinaryImporter.getInstance().load(is);
          //add it to the navmanager
          if(ret != null){
            //nav meshes are from 0/0 to tile.x/tile.y for conveniance so move it
            //nm.setPosition(new Vector3f(Tile.getWorldPositionOfXTile(x), 0f,Tile.getWorldPositionOfZTile(z)));
            ret.setPosition(new Vector3f((x-160)<<8, 0f, (z-144)<<8));
          }
        } catch (IOException e) {
          e.printStackTrace();
        }
      }
View Full Code Here

TOP

Related Classes of com.jme3.math.Vector3f

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.