private MyRay shootRay(MyPoint3D from, MyPoint3D dir) { MyRay ray = new MyRay(); ray.setOrigin(from); dir.normalize(); ray.setDirection(dir); return ray; }
private MyRay shootPixelRay(int x, int y) { MyRay out = new MyRay(); float xPart, yPart; xPart = (rightViewPlane - leftViewPlane) / widthPix; yPart = (topViewPlane - bottomViewPlane) / heightPix; xPart = leftViewPlane + (float) 0.5 * xPart + ((float) x) * xPart; yPart = bottomViewPlane + (float) 0.5 * yPart + ((float) y) * yPart; // get ray direction and origin: perspective // out.setOrigin(viewer); // MyPoint3D dir = new MyPoint3D(xPart - viewer.getX(), yPart - viewer.getY(), zViewPlane - // viewer.getZ()); // get ray direction and origin: perpendicular out.setOrigin(new MyPoint3D(xPart, yPart, viewer.getZ())); MyPoint3D dir = new MyPoint3D(0, 0, 1); // normalize dir.normalize(); out.setDirection(dir); return out; }