Hi...
 
Like I've told you before, I got difficulty in finding texture coordinate in a sphere from one point in mouse event.
I divided the original image into several parts so that the centre of the image is the centre of the sphere..and continue to retrieve s and t value by implementing sphere equation as follows :
 
// transforming first...
 Point3d imagePoint = new Point3d();
 c.getPixelLocationInImagePlate(e.getX(),e.getY(),imagePoint);
 
 // change coordinates of image plate to virtual world
 Transform3D tr = new Transform3D();
 System.out.println("Image Point before: " +imagePoint.x + "," + imagePoint.y + "," + imagePoint.z);
 c.getImagePlateToVworld(tr);
 tr.transform(imagePoint);
 
 System.out.println("Image Point : " +imagePoint.x + "," + imagePoint.y + "," + imagePoint.z);
 if (imagePoint.y == 0)
 {  
    double keliling = (Math.PI) * 2 * radius;
    theta = Math.atan(imagePoint.x/imagePoint.z);
//    t = ((Math.abs(theta))/(2*Math.PI)) * keliling;
    t = ((Math.toDegrees(Math.abs(theta)))/360 )* keliling;
    System.out.println("t before : " + t);
    if (imagePoint.x < 0)
    { if (imagePoint.z < 0)
        { t = t/keliling;
      } else {
     t = 0.5 - (t/keliling);
   }
    } else {
      if (imagePoint.z < 0)
      { t = 1 - (t/keliling);
      } else {
     t = 0.5 + (t/keliling);
   }
    }
    s = 0.5;
    System.out.println("s,t : " + s +"," + t);
 
 } // end if y=0
 else {
    // find new radius
    double r = Math.sqrt((radius*radius) - (imagePoint.y * imagePoint.y));
    System.out.println("radius : " + r);
    double kelilingSmall = (Math.PI) * 2 * r;
    System.out.println("Kel : " + kelilingSmall);
    theta = Math.atan(imagePoint.x/imagePoint.z);
    System.out.println("Theta : " + theta);
    t = ((Math.abs(theta))/(2*Math.PI)) * kelilingSmall;
//    t = ((Math.toDegrees(Math.abs(theta)))/360) * kelilingSmall;
    System.out.println("t before : " + t);
    if (imagePoint.x < 0)
    { if (imagePoint.z < 0)
        { t = t/kelilingSmall;
      } else {
     t = 0.5 - (t/kelilingSmall);
   }
    } else {
      if (imagePoint.z < 0)
      { t = 1 - (t/kelilingSmall);
      } else {
     t = 0.5 + (t/kelilingSmall);
   }
    }
 
    s = imagePoint.y;
    if (imagePoint.y<0)
    {s = 0.5 - s;
    } else {
     s = 0.5 + s;   
    }
 
    System.out.println("s,t : " + s +"," + t);
 } // end else y=0
 
// move to u and v
 int u = (int) (s*320);
 int v = (int) (t*640);
 System.out.println("(" + v + "," + u +")");
 
But from the first time, when I get coordinate from getPixelLocationInImagePlate and getImagePlateToVWorld, the value of z always 0.0 for image plate and almost 0.0 for vworld. It's never changed whereever I clicked my button. Why it's always 0.0?
In my logic, if that image is put on sphere, we will get z value for each point.
 
Help me with this..
 
Regards,
Tria

Reply via email to