Package org.earth3d.jearth.math

Examples of org.earth3d.jearth.math.Point3D


    }
    nav.step(step/10);

    if (Global.flyMode) {
      // gravitation
      Point3D axis = nav.viewer.crossproduct(nav.getDirection()).normalize();
      float matrix[] = new float[16];
      Quaternion quat = new Quaternion();
      quat.createFromAxisAngle((float) axis.x, (float) axis.y, (float) axis.z, -1);
      quat.createMatrix(matrix);
View Full Code Here


    float depth1 = depthbuffer.get(dy*depthWidth+mx);
    double sd[] = new double[3];
    glu.gluUnProject(mx, size().height-my, depth1, modl, 0, proj, 0, viewport, 0, sd, 0);

    Point2D mappos = sphere.inverse(new Point3D(sd[0], sd[1], sd[2]));

    /* get texture at coordinates */

    return(mappos);
  }
 
View Full Code Here

    /* show an XML marker of the current position and copy it to the clipboard */
    Point2D v = getCurrentCoordinates();
    double x = v.x;
    double y = v.y;
    double z = nav.getViewer().length();
    Point3D dir = nav.getDirection();
    dir = nav.getEarthIntersection(dir, nav.getViewer());
    Point3D up = nav.getUp();

    String msg = "<mark name=\"noname\" x=\""+x+"\" y=\""+y+"\" z=\""+z+"\" dirx=\""+dir.x+"\" diry=\""+dir.y+"\" dirz=\""+dir.z+"\" upx=\""+up.x+"\" upy=\""+up.y+"\" upz=\""+up.z+"\" />";
    System.out.println(msg);
  }
View Full Code Here

    if (!done) {
      /* zoom to selected point */

      if (matrix_valid) {
        Point2D newcoordinates = getWorldCoordinates(e.getX(), e.getY());
        Point3D newcoordinates3D = sphere.getPoint(newcoordinates, 1.);
//        newcoordinates3D = nav.getViewer().add(newcoordinates3D.sub(nav.getViewer()).multiply(0.5));

        Point2D currentcoordinates = getCurrentCoordinates();
        Point2D destcoordinates = newcoordinates/*+currentcoordinates)*//*2.*/;

        moveToPosition(new Point3D(destcoordinates.x, destcoordinates.y, (nav.getViewer().length()-1)/2+1), new Point3D(0,0,0), nav.getUp(), false);
//        moveToCoordinate(newcoordinates3D, nav.getDirection(), nav.getUp(), false);
      }
    }
  }
View Full Code Here

  protected MapTileUncompressed newtile = new MapTileUncompressed();

  public TextureTreeNodeCore(MapTileTree mtree) {
    super(mtree);

    vertex[0] = new Point3D(0,0,0);
    vertex[1] = new Point3D(1,0,0);
    vertex[2] = new Point3D(1,1,0);
    vertex[3] = new Point3D(0,1,0);

    textureBound = false;

    newtextureBound = false;
View Full Code Here

    }

    assert(result2d.x>=rect.p.x && result2d.x<=rect.p.x+rect.size.x &&
        result2d.y>=rect.p.y && result2d.y<=rect.p.y+rect.size.y);

    Point3D result3d = gSphere.getPoint(result2d);

    double distance = (p.sub(result3d)).length();
    return(distanceFunction(surfacedistance, distance));
  }
View Full Code Here

  }


  public double getDistance(Point3D p, Point3D rect[]) {
    // for now I calculate the distance between the middle of the rectangle and the point
    Point3D middle = rect[0].add(rect[1]).add(rect[2]).add(rect[3]).divide(4);
    Point3D distvector = middle.sub(p);
    double distance_m = distvector.length();
    double distance0 = (rect[0].sub(p)).length();
    double distance1 = (rect[1].sub(p)).length();
    double distance2 = (rect[2].sub(p)).length();
    double distance3 = (rect[3].sub(p)).length();
View Full Code Here

    /* check if the object/tree should be drawn at all
     */

    //   checkHeightfields(&wasSelectedNodes);
    /* distance to surface */
    double distsurface = (viewer.minus(new Point3D(0,0,0))).length()-1;

    Point3D virtualviewer;
    if (Global.FORWARD_VIEW) {
      /* get projection and modelview matrix and multiply forward vector (0,0,1,1) with them */
      virtualviewer = getVirtualViewer(new Point3D(0,0,1), viewer);
      if (virtualviewer.equals(new Point3D(0,0,0))) { // square root cannot be solved, earth not visible in center
        virtualviewer = getVirtualViewer(new Point3D(0,-0.2,1), viewer);
      }
      if (virtualviewer.equals(new Point3D(0,0,0))) { // square root cannot be solved, earth not visible in center
        virtualviewer = getVirtualViewer(new Point3D(0,-0.4,1), viewer);
      }
      if (virtualviewer.equals(new Point3D(0,0,0))) { // square root cannot be solved, earth not visible in center
        virtualviewer = getVirtualViewer(new Point3D(0,-1,1), viewer);
      }
      if (virtualviewer.equals(new Point3D(0,0,0))) { // square root cannot be solved, earth not visible in center
        virtualviewer = getVirtualViewer(new Point3D(0,-3,1), viewer);
      }
      if (virtualviewer.equals(new Point3D(0,0,0))) { // square root cannot be solved, earth not visible in center
//        distance = getDistance(&(viewer->normalize()*(1+distsurface/CENTERWEIGHT)), ((HeightfieldTreeNodeCore *)(currentNode->getCore(1)))->getRect());
//        edgeSize = getMaxEdgeSize(viewer, ((TextureTreeNodeCore *)(currentNode->getCore(0)))->vertex, distance);
      } else {
        virtualviewer = virtualviewer.multiply(1+distsurface/Global.CENTERWEIGHT);
      }
    } else {
      virtualviewer = viewer;

      // Calculate distance between viewer and tile
View Full Code Here

//        gl.glPushMatrix();
//        gl.glTranslatef(hcore.vertexorigin.x, hcore.vertexorigin.y, hcore.vertexorigin.z);
//        gl.glScalef(hcore.vertexscale, hcore.vertexscale, hcore.vertexscale);
//        }

        Point3D vertexarray[] = hcore.vertexarray;
        Point2D texcoordarray[] = hcore.texcoordarray;

        float heightblendvalue = node.getInterpolationCounter();
        Point3D vertex[] = hcore.getInterpolationVertexArray(heightblendvalue); // vertexarray;
        int vertex_i = 0;
        Point2D texcoord[] = texcoordarray;
        int texcoord_i = 0;

        /* Initialize texture units */
        gl.glActiveTexture(GL.GL_TEXTURE0);
        gl.glClientActiveTexture(GL.GL_TEXTURE0);
        gl.glEnableClientState(GL.GL_VERTEX_ARRAY);
        gl.glEnableClientState(GL.GL_NORMAL_ARRAY);
        gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);
        gl.glTexEnvi(GL.GL_TEXTURE_ENV, GL.GL_TEXTURE_ENV_MODE, GL.GL_REPLACE);
        gl.glEnable(GL.GL_COLOR_MATERIAL);
        gl.glColor4f(1.f, 1.f, 1.f, 1.f);

        /* Set second texture only if the user wants multitexturing */
        if (Global.cacheUseMultiTexturing) {
          gl.glActiveTexture(GL.GL_TEXTURE1);
          gl.glClientActiveTexture(GL.GL_TEXTURE1);
          gl.glEnable(GL.GL_TEXTURE_2D);
          gl.glEnableClientState(GL.GL_TEXTURE_COORD_ARRAY);

          Texture interpolationtextureID = null;
          try {
            interpolationtextureID = core.getInterpolationTextureID(gl);
          } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
          }
          if (interpolationtextureID == null) {
            blendvalue = 0;
          }
          else {
            gl.glColor4f(blendvalue, blendvalue, blendvalue, 1.f);
            gl.glEnable(GL.GL_TEXTURE_2D);
            interpolationtextureID.bind();
          }
        }
        else {
          blendvalue = 0;
        }


        for(int row=0; row<hcore.vertexcount/hcore.stripsize; row++) {
          gl.glActiveTexture(GL.GL_TEXTURE0);
          gl.glClientActiveTexture(GL.GL_TEXTURE0);
         
          DoubleBuffer db = hcore.getVertexDb();
          db.position(vertex_i*3);
          gl.glVertexPointer(3, GL.GL_DOUBLE, 0, db);
          gl.glNormalPointer(GL.GL_DOUBLE, 0, db);
         
          DoubleBuffer texDb = hcore.getTexDb();
          texDb.position(texcoord_i*2);
          gl.glTexCoordPointer(2, GL.GL_DOUBLE, 0, texDb);

          // TODO can be removed when texture blending is not used
          gl.glActiveTexture(GL.GL_TEXTURE1);
          gl.glClientActiveTexture(GL.GL_TEXTURE1);
          gl.glTexCoordPointer(2, GL.GL_DOUBLE, 0, texDb);

          gl.glActiveTexture(GL.GL_TEXTURE0);
          gl.glClientActiveTexture(GL.GL_TEXTURE0);

//          #ifdef LINE_MODE
//gl.glDrawArrays(GL.GL_LINE_STRIP, 0, hcore.stripsize);
//          #else
          if (Global.maptiledrawtype==0) {
            gl.glDrawArrays(GL.GL_TRIANGLE_STRIP, 0, hcore.stripsize);
          }
          else {
            if (Global.maptiledrawtype==1) {
              gl.glDrawArrays(GL.GL_LINE_STRIP, 0, hcore.stripsize);
            }
            else {
              gl.glBegin(GL.GL_LINE_STRIP);
              gl.glVertex3d(hcore.vertex[0].x, hcore.vertex[0].y, hcore.vertex[0].z);
              gl.glVertex3d(hcore.vertex[1].x, hcore.vertex[1].y, hcore.vertex[1].z);
              gl.glVertex3d(hcore.vertex[2].x, hcore.vertex[2].y, hcore.vertex[2].z);
              gl.glVertex3d(hcore.vertex[3].x, hcore.vertex[3].y, hcore.vertex[3].z);
              gl.glVertex3d(hcore.vertex[0].x, hcore.vertex[0].y, hcore.vertex[0].z);
              gl.glEnd();
            }
          }
//          #endif
          vertex_i+=hcore.stripsize;
          texcoord_i+=hcore.stripsize;
        }

        /* draw fans */
        for(int direction=0; direction<4; direction++) {
          Point3D fanvertexarray[] = hcore.fanvertexarray[direction];
          Point2D fantexcoordarray[] = hcore.fantexcoordarray[direction];
//          glColor3f(0.f, 1.f, 0.f);
//          glBindTexture(GL.GL_TEXTURE_2D, null);

          vertex = fanvertexarray;
View Full Code Here

    for(int x=0; x<4; x++) {
      v[x] = (float) (direction.x*frustum.clip[0+x*4] + direction.y*frustum.clip[1+x*4] + direction.z*frustum.clip[2+x*4] + frustum.clip[3+x*4]);
    }

    /* find intersection with sphere */
    Point3D pv = new Point3D(v[0], v[1], v[2]);
    pv = pv.normalize();

    Point3D pp = new Point3D(viewer);
    double pvpp = pv.skalarproduct(pp);
    double pvpv = pv.skalarproduct(pv);
    double p = 2*pvpp/pvpv;
    double q = ((pp.skalarproduct(pp))-1)/pvpv;

    double intersection1 = -p/2.+Math.sqrt(p*p/4-q);
    double intersection2 = -p/2.-Math.sqrt(p*p/4-q);
    double intersection = Math.min(intersection1, intersection2);

    if (p*p/4-q<0) { // square root cannot be solved, earth not visible in center
      return(new Point3D(0,0,0));
    }
    else {
      return(new Point3D(viewer.x+pv.x*intersection,
          viewer.y+pv.y*intersection,
          viewer.z+pv.z*intersection));
   
  }
View Full Code Here

TOP

Related Classes of org.earth3d.jearth.math.Point3D

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.