[Bprocessor-commit] model/src/net/sourceforge/bprocessor/model Camera.java,NONE,1.1
Status: Pre-Alpha
Brought to you by:
henryml
From: rimestad <rim...@us...> - 2005-12-12 14:17:26
|
Update of /cvsroot/bprocessor/model/src/net/sourceforge/bprocessor/model In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23331/src/net/sourceforge/bprocessor/model Added Files: Camera.java Log Message: Camera added to the model (there still needs functionality to fetch it from the porject class and an facade so that there can be more than one camera at a time. Conversion to xml is not impl. --- NEW FILE: Camera.java --- //--------------------------------------------------------------------------------- // $Id: Camera.java,v 1.1 2005/12/12 14:17:12 rimestad Exp $ // // Copyright (c) 2005 The BProcessor Team (http://bprocessor.sourceforge.net) // Released under the Lesser GNU Public License v2.1 //--------------------------------------------------------------------------------- package net.sourceforge.bprocessor.model; import org.apache.log4j.Logger; /** * Camera for view placement in the model have a center and at camera position * as well as a up vector */ public class Camera { /** The 3D view view */ public static final int VIEW_3D = 1; /** The x z plane view */ public static final int VIEW_XZ = 2; /** The x y plane view */ public static final int VIEW_XY = 3; /** The y z plane view */ public static final int VIEW_YZ = 4; /** The logger */ private static Logger log = Logger.getLogger(Camera.class); /** The id of the camera */ private Long id; /** double arrays for modelView setup */ private double[] center, roll, camera; /** The focal width */ private double focalwidth; /** The name of the camera */ private String name; /** * The constructor for the persistence layer */ Camera() { } /** * Create a default camera of your choice * @param type the camera type * @return a new camera */ public static Camera create(int type) { Camera res = null; if (type == VIEW_3D) { res = new Camera("3d", new double[]{0, 0, 0}, new double[]{20, 5, 5}, new double[] {0, 0, 1}); } else if (type == VIEW_XZ) { res = new Camera("xz", new double[]{0, 0, 0}, new double[]{0, 20, 0}, new double[] {0, 0, 1}); } else if (type == VIEW_XY) { res = new Camera("xy", new double[]{0, 0, 0}, new double[]{0, 0, 20}, new double[] {0, 1, 0}); } else if (type == VIEW_YZ) { res = new Camera("yz", new double[]{0, 0, 0}, new double[]{20, 0, 0}, new double[] {0, 0, 1}); } return res; } /** * Constructor with arguments * @param center The center position * @param camera The camera positon * @param roll The roll of the camera (up vector) * @param name The name of the cam setting */ public Camera(String name, double[] center, double[] camera, double[] roll) { this.name = name; this.center = center; this.camera = camera; this.roll = roll; this.focalwidth = 65; } /** * Getter for the id * @return The id * @hibernate.id * column="CAMERA_ID" * generator-class="increment" */ public Long getId() { return id; } /** * Setter for the id * @param id The id */ public void setId(Long id) { this.id = id; } /** * Getter for the name * @return The name * @hibernate.property */ public String getName() { return name; } /** * Setter for the name * @param name The name */ public void setName(String name) { this.name = name; } /** * @return Returns the camera. * @hibernate.property */ public double[] getCamera() { return camera; } /** * @param camera The camera to set. */ public void setCamera(double[] camera) { this.camera = camera; } /** * @return Returns the center. * @hibernate.property */ public double[] getCenter() { return center; } /** * @param width The width of the camera. */ public void setFocalwidth(double width) { this.focalwidth = width; } /** * @return Returns the focalwidth. * @hibernate.property */ public double getFocalwidth() { return focalwidth; } /** * @param center The center to set. */ public void setCenter(double[] center) { this.center = center; } /** * @return Returns the roll. * @hibernate.property */ public double[] getRoll() { return roll; } /** * @param roll The roll to set. */ public void setRoll(double[] roll) { this.roll = roll; } /** * The distance from camera to center * @return The distance */ public double dist() { return Math.sqrt((camera[0] - center[0]) * (camera[0] - center[0]) + (camera[1] - center[1]) * (camera[1] - center[1]) + (camera[2] - center[2]) * (camera[2] - center[2])); } /** * Move the center left/right, up/down, forward/backward * @param mv the move vector */ public void translate(double [] mv) { if (mv.length == 3) { center[0] += mv[0]; center[1] += mv[1]; center[2] += mv[2]; camera[0] += mv[0]; camera[1] += mv[1]; camera[2] += mv[2]; } else { log.error("[translateViewMatrix] Wrong parameter size"); } } /** * Function to zoom in */ public void zoomin() { camera[0] -= (camera[0] - center[0]) * 0.1; camera[1] -= (camera[1] - center[1]) * 0.1; camera[2] -= (camera[2] - center[2]) * 0.1; } /** * Function to zoom out */ public void zoomout() { camera[0] += (camera[0] - center[0]) * 0.1; camera[1] += (camera[1] - center[1]) * 0.1; camera[2] += (camera[2] - center[2]) * 0.1; } } |