Can anyone help me by supplying an example of returning a depth data from a
Raster?

I have the following code now, based on a mouseclick positioning, but it is
just not happening...


I'm trying to fill an array with the 1x1 depth value at that pixel.  The
theory is, if I can get the depth from the Z-Buffer, then I can invert the
world transform, and get a screen to world transform that has an accurate Z
value instead of always getting 0.

public double getZ(int x2, int y2){
        DepthComponentFloat dpf=new DepthComponentFloat(1,1);

                                                
        dpf.setCapability(DepthComponentFloat.ALLOW_DATA_READ);
        dpf.setCapability(DepthComponentFloat.ALLOW_SIZE_READ);
  
        
  //I have no idea what this Point3f(0,0,0) is for, it isn't documented
well.
        
        Raster r=new Raster(new Point3f(0,0,0), 
                                      Raster.RASTER_DEPTH,
                                      x2,
                                      y2,
                                      1,        
                                      1,
                                      null,
                                      dpf);
        r.setCapability(Raster.ALLOW_DEPTH_COMPONENT_READ);


    GraphicsContext3D g=rememberCanvas.getGraphicsContext3D();
    g.readRaster(r);


    
    float[] ddata= new float[1];
    dpf=(DepthComponentFloat)r.getDepthComponent();
    dpf.getDepthData(ddata);    
    double d=ddata[1];

    System.out.println("depth: "+ new Float(d).toString());
    return ddata[1];   
    
  }

=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to