Camera Model
Point3 ptViewRef = new Point3(0, 0, 0); // 注視点の3次元座標
double theta, phi, R; // 視点位置(R、θ、Φ)
double cos_theta=1., cos_phi=1., sin_theta=0., sin_phi=0.;
public void setVRpnt( double x, double y, double z) {
ptViewRef = new Point3(x,y,z); } // 注視点の設定
public void setview(double r, double the, double ph) {
theta=the; phi=ph; R=r; } // 視点の設定
public void preper() { // 変換マトリックスの係数計算
double d2r= Math.PI/180.;
cos_theta =Math.cos(theta*d2r); sin_theta = Math.sin(theta*d2r);
cos_phi = Math.cos(phi*d2r); sin_phi = Math.sin(phi*d2r);
public Point3 tranfrm(Point3 point) { // 透視変換(3次元?3次元)
Point3 p1 = new Point3(); Point3 p2 = new Point3();
p1.x = point.x ? ptViewRef.x;
p1.y = point.y ? ptViewRef.y;
p1.z = point.z ? ptViewRef.z;
double xy = cos_theta*p1.x+sin_theta*p1.y;
p2.z =(R-cos_phi*xy-sin_phi*p1.z)/R;
p2.x = cos_theta*p1.y-sin_theta*p1.x;
p2.y = cos_phi * p1.z ? sin_phi * xy;
public Point project (Point3 point) { // 投影(3次元?2次元)
Point3 p1= tranfrm(point);
Return new Point((int)(p1.x/p1.z), (int)(p1.y/p1.z));
Point3(double ox, double oy, double oz) {
x = ox; y = oy; z = oz; }