001: /*
002: * Copyright (c) 2001 Silvere Martin-Michiellot All Rights Reserved.
003: *
004: * Silvere Martin-Michiellot grants you ("Licensee") a non-exclusive,
005: * royalty free, license to use, modify and redistribute this
006: * software in source and binary code form,
007: * provided that i) this copyright notice and license appear on all copies of
008: * the software; and ii) Licensee does not utilize the software in a manner
009: * which is disparaging to Silvere Martin-Michiellot.
010: *
011: * This software is provided "AS IS," without a warranty of any kind. ALL
012: * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
013: * IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
014: * NON-INFRINGEMENT, ARE HEREBY EXCLUDED. Silvere Martin-Michiellot
015: * AND ITS LICENSORS SHALL NOT BE LIABLE FOR ANY DAMAGES
016: * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
017: * OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL
018: * Silvere Martin-Michiellot OR ITS LICENSORS BE LIABLE
019: * FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
020: * INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
021: * CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
022: * OR INABILITY TO USE SOFTWARE, EVEN IF Silvere Martin-Michiellot HAS BEEN
023: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
024: *
025: * This software is not designed or intended for use in on-line control of
026: * aircraft, air traffic, aircraft navigation or aircraft communications; or in
027: * the design, construction, operation or maintenance of any nuclear
028: * facility. Licensee represents and warrants that it will not use or
029: * redistribute the Software for such purposes.
030: *
031: * @Author: Silvere Martin-Michiellot
032: *
033: */
034:
035: package com.db.viewpoint;
036:
037: // This code is repackaged after the software The Carnival by Douglas Pew
038: // Site http://www.access.digex.net/~dpew/carnival (link is dead)
039: // Email dpew@gmu.edu
040:
041: /*
042: *
043: * This program is free software; you can redistribute it and/or modify
044: * it under the terms of the GNU General Public License as published by
045: * the Free Software Foundation; either version 2 of the License, or
046: * (at your option) any later version.
047: *
048: * This program is distributed in the hope that it will be useful,
049: * but WITHOUT ANY WARRANTY; without even the implied warranty of
050: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
051: * GNU General Public License for more details.
052: *
053: * You should have received a copy of the GNU General Public License
054: * along with this program; if not, write to the Free Software
055: * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
056: *
057: */
058:
059: import javax.media.j3d.*;
060: import javax.vecmath.*;
061:
062: /** A class that defines a ViewPoint to be used in a Java3D scenegraph. */
063: public class ViewPoint extends TransformGroup implements Viewable {
064:
065: private ViewSite[] site;
066:
067: /** Builds a new ViewPoint
068: * @param name The human readable name of the ViewPoint
069: * @param location The location at which the View is to be.
070: * @param look_to The direction towards which the View is oriented.
071: */
072: public ViewPoint(String name, Vector3d location, Point3d look_to) {
073:
074: Vector3d negzaxis = new Vector3d(0.0, 0.0, -1.0);
075: Vector3d yaxis = new Vector3d(0.0, 1.0, 0.0);
076: Vector3d lk_vector = new Vector3d();
077: Vector3d tmp = new Vector3d();
078: double lk_angle;
079: double tilt;
080: Matrix3d m1 = new Matrix3d();
081: Matrix3d m2 = new Matrix3d();
082: TransformGroup vtg;
083: Transform3D t3d;
084:
085: //
086: // Determin the angle and normal from the normal look angle (straight
087: // down the Z axis, to the look_to point
088: //
089: lk_vector.sub(look_to, location);
090: //System.out.println("Vector " + lk_vector);
091:
092: // Get
093: tmp.set(lk_vector.x, 0.0, lk_vector.z);
094: lk_angle = negzaxis.angle(tmp);
095: if (tmp.x < 0)
096: lk_angle = -lk_angle;
097: m1.setIdentity();
098: if (!Double.isNaN(lk_angle))
099: m1.rotY(lk_angle);
100: m1.transform(lk_vector);
101: tilt = lk_vector.angle(negzaxis);
102: if (lk_vector.y < 0)
103: tilt = -tilt;
104:
105: m1.setIdentity();
106: if (!Double.isNaN(lk_angle))
107: m1.rotY(-lk_angle);
108: m2.rotX(tilt);
109: m1.mul(m2);
110:
111: t3d = new Transform3D(m1, location, 1.0);
112: this .setTransform(t3d);
113:
114: Vector3d vec = new Vector3d(0.0, 0.0, (double) -lk_vector
115: .length());
116: m1.transform(vec);
117:
118: site = new ViewSite[1];
119: site[0] = new ViewSite(name);
120: vtg = site[0].makeViewPlatform();
121: this .addChild(vtg);
122:
123: site[0].setViewControl(new LookViewControl(vtg));
124:
125: }
126:
127: /** Retrieves the array of ViewSites associated with this ViewPoint. This should be
128: * an array of length 1.
129: * @return The ViewSite array.
130: */
131: public ViewSite[] getViewSites() {
132:
133: return site;
134:
135: }
136:
137: }
|