Hi all!
I have an application where the user can choose points. The application then
will interpolate with a spline interpolator between those points, always
facing into the direction of the next point. The points always have the same y
value, but different x and z values (e.g. P1(1.0;0.5;2.0), P2(2.0;0.5,3.0). In
the end, you can save this as a "video".
This is the code that calculates out the vectors and passes the angle to the
quaternion:
for (int n = 0; n<(size-1);n++) {
Vector3f vec = new Vector3f();
vec.sub(positions[n+1],positions[n]);
laenge_vec[n] = vec.length();
gesamtlaenge = gesamtlaenge + laenge_vec[n];
double winkel = vec.angle(new Vector3f(0.0f,0.0f,-1.0f));
if (vec.x > 0) {
winkel = -winkel;
}
quats[n] = new Quat4f(createQuaternionFromEuler(0 ,winkel,0 ));
The quats array is then added to the keyframe array.
The code for the method createQuaternionFromEuler is attached. (I took this
code out of the Java3D online book from Daniel Selman)
Then I call the interpolator:
RotPosScaleTCBSplinePathInterpolator interpolator = new
RotPosScaleTCBSplinePathInterpolator(transAlpha, vpTrans, new
Transform3D(),splineKeyFrames);
Now I am trying to allow the user to enter a camera angle, so that it is
possible to look down/up slightly while still facing into the direction of the
next point.
I think that I need to rotate around -x when I move in the world from south
to north and around +x when I move from north to south. When I move from east
to west and vice versa I need to rotate around the z axis. I tested the last
case (east to west) but I got the same result as when I rotated around the x
axis. Does anybody know why? Is there is formula that I can use so it
calculates it out automatically? What do I have to do if I want to go e.g.
north-east?
Thanks in advance!
Regards,
Katja
--
+++ GMX - Mail, Messaging & more http://www.gmx.net +++
NEU: Mit GMX ins Internet. Rund um die Uhr f�r 1 ct/ Min. surfen!
static Quat4f createQuaternionFromAxisAndAngle( Vector3d axis, double angle )
{
double sin_a = Math.sin( angle / 2 );
double cos_a = Math.cos( angle / 2 );
// use a vector so we can call normalize
Vector4f q = new Vector4f( );
q.x = (float) (axis.x * sin_a);
q.y = (float) (axis.y * sin_a);
q.z = (float) (axis.z * sin_a);
q.w = (float) cos_a;
// It is necessary to normalise the quaternion
// in case any values are very close to zero.
q.normalize( );
// convert to a Quat4f and return
return new Quat4f( q );
}
static Quat4f createQuaternionFromEuler( double angleX, double angleY, double
angleZ )
{
// simply call createQuaternionFromAxisAndAngle
// for each axis and multiply the results
Quat4f qx = createQuaternionFromAxisAndAngle( new Vector3d( 1,0,0 ),
angleX );
Quat4f qy = createQuaternionFromAxisAndAngle( new Vector3d( 0,1,0 ),
angleY );
Quat4f qz = createQuaternionFromAxisAndAngle( new Vector3d( 0,0,1 ),
angleZ );
// qx = qx * qy
qx.mul( qy );
// qx = qx * qz
qx.mul( qz );
return qx;
}