Hello everyone!
Can somebody help me with this code snippet?
import javax.media.j3d.*;
import javax.vecmath.*;
public class ViewPoint extends TransformGroup implements Viewable
{
private ViewSite[] site;
public ViewPoint(String name, Vector3d location, Point3d look_to)
{
Vector3d negzaxis = new Vector3d(0.0, 0.0, -1.0);
Vector3d yaxis = new Vector3d(0.0, 1.0, 0.0);
Vector3d lk_vector = new Vector3d();
Vector3d tmp = new Vector3d();
double lk_angle;
double tilt;
Matrix3d m1 = new Matrix3d();
Matrix3d m2 = new Matrix3d();
TransformGroup vtg;
Transform3D t3d;
//
// Determin the angle and normal from the normal look angle (straight
// down the Z axis, to the look_to point
//
lk_vector.sub(look_to, location);
//System.out.println("Vector " + lk_vector);
// Get
tmp.set(lk_vector.x, 0.0, lk_vector.z);
lk_angle = negzaxis.angle(tmp);
if (tmp.x < 0)
lk_angle = -lk_angle;
m1.setIdentity();
if (!Double.isNaN(lk_angle))
m1.rotY(lk_angle);
m1.transform(lk_vector);
tilt = lk_vector.angle(negzaxis);
if (lk_vector.y < 0)
tilt = -tilt;
m1.setIdentity();
if (!Double.isNaN(lk_angle))
m1.rotY(-lk_angle);
m2.rotX(tilt);
m1.mul(m2);
t3d = new Transform3D(m1, location, 1.0);
this.setTransform(t3d);
Vector3d vec = new Vector3d(0.0, 0.0, (double)-lk_vector.length());
m1.transform(vec);
site = new ViewSite[1];
site[0] = new ViewSite(name);
vtg = site[0].makeViewPlatform();
this.addChild(vtg);
site[0].setViewControl(new LookViewControl(vtg));
}
public ViewSite[] getViewSites() { return site; }
}
This code was taken from Mr. Douglas Pew's Virtual carnival and have been trying to
contact him.
Anyway,is it right for me to say that this class creates the parent transformgroup for
the viewplatform?
How will a point and a vector generate another vector with the statement:
lk_vector.sub(look_to, location);
When Mr. Pew declared matrix,m1 to be set to identity,what happened to the previous
calculations?Did it make another matrix object or set the current matrix? (There are
two parts of code that performs calculations on m1).Below is the second one....
m1.setIdentity();
if (!Double.isNaN(lk_angle))
m1.rotY(-lk_angle);
m2.rotX(tilt);
m1.mul(m2);
t3d = new Transform3D(m1, location, 1.0);
this.setTransform(t3d);
Vector3d vec = new Vector3d(0.0, 0.0, (double)-lk_vector.length());
m1.transform(vec);
Sorry, for this very long letter.But I really need someone's advise because I am
having a hard time visualizing this part of Mr. Pew's code.
Thanks!
Jonathan Vallar
__________________________________
www.edsamail.com
===========================================================================
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff JAVA3D-INTEREST". For general help, send email to
[EMAIL PROTECTED] and include in the body of the message "help".