Java程序辅导

C C++ Java Python Processing编程在线培训 程序编写 软件开发 视频讲解

客服在线QQ:2653320439 微信:ittutor Email:itutor@qq.com
wx: cjtutor
QQ: 2653320439
/** * Camera extends simple camera with the ability to specify the VPN, * VUV and VRP. * * @author Anthony Steed * @version 1.0 */ public class Camera extends SimpleCamera { // The following value are private to prevent internal // inconsistencies /* The view plane normal */ private Vector VPN; /* The view up vector */ private Vector VUV; /* The view reference point */ private Point VRP; /* Matrix mapping WC to VC */ private Matrix M; /* Matrix mapping VC to WC */ private Matrix InvM; /** * Create a default camera that behaves as a SimpleCamera */ public Camera() { initBasic(100,100); // from SimpleCamera VPN = new Vector(0.0,0.0,-1.0); VUV = new Vector(0.0,1.0,0.0); VRP = new Point(0.0,0.0,0.0); computeMatrix(); } /** * Create a camera by copying an existing camera * @param c the camera to copy */ public Camera(Camera c) { initBasic(100,100); // SimpleCamera VPN = c.getVPN(); VUV = c.getVUV(); VRP = c.getVRP(); M = c.getViewMatrix(); InvM = c.getInvViewMatrix(); } /** * Set the view plane normal. * * Note the vector is copied not referenced. * @param v the vector with the VPN value */ public void setVPN(Vector v) { VPN = new Vector(v); } /** * Set the view up vector. * * Note the vector is copied not referenced. * @param v the vector with the VUV value */ public void setVUV(Vector v) { VUV = new Vector(v); } /** * Set the view reference point * * Note the point is copied not referenced. * @param v the point with the VRP value */ public void setVRP(Point p) { VRP = new Point(p); } /** * Get the view plane normal. * * Note the vector is copied not referenced. * @return new vector with the VPN value */ public Vector getVPN() { return new Vector(VPN); } /** * Get the view up vector * * Note the vector is copied not referenced. * @return new vector with the VUV value */ public Vector getVUV() { return new Vector(VUV); } /** * Get the view reference point * * Note the point is copied not referenced. * @return new point with the VRP value */ public Point getVRP() { return new Point(VRP); } /* * Compute both the WC to VC mapping and its inverse */ private void computeMatrix () { Vector u, v, n; n = new Vector(VPN); n.normalise(); u = Vector.cross(n,VUV); u.normalise(); v = Vector.cross(u,n); Vector vrp = new Vector(VRP); M.setValue(0,0,u.X); M.setValue(1,0,u.Y); M.setValue(2,0,u.Z); M.setValue(0,1,v.X); M.setValue(1,1,v.Y); M.setValue(2,1,v.Z); M.setValue(0,2,-n.X); M.setValue(1,2,-n.Y); M.setValue(2,2,-n.Z); M.setValue(0,3,0); M.setValue(1,3,0); M.setValue(2,3,0); M.setValue(3,3,1); M.setValue(3,0,-(Vector.dot(vrp,u))); M.setValue(3,1,-(Vector.dot(vrp,v))); M.setValue(3,2,Vector.dot(vrp,n)); InvM.setValue(0,0,u.X); InvM.setValue(0,1,u.Y); InvM.setValue(0,2,u.Z); InvM.setValue(1,0,v.X); InvM.setValue(1,1,v.Y); InvM.setValue(1,2,v.Z); InvM.setValue(2,0,-n.X); InvM.setValue(2,1,-n.Y); InvM.setValue(2,2,-n.Z); InvM.setValue(0,3,0); InvM.setValue(1,3,0); InvM.setValue(2,3,0); InvM.setValue(3,3,1); InvM.setValue(3,0,vrp.X); InvM.setValue(3,1,vrp.Y); InvM.setValue(3,2,vrp.Z); } /** * Get the WC to VC mapping matrix * * Note the matrix is copied not referenced. * @return new matrix */ public Matrix getViewMatrix () { return new Matrix(M); } /** * Get the VC to WC mapping matrix * * Note the matrix is copied not referenced. * @return new matrix */ public Matrix getInvViewMatrix () { return new Matrix(InvM); } }