The following code sets the camera viewtranform given the camera
frame:  location LOCw,  up vector UPw, direction vector DIRw, and
right wing vector RTw in world coordinates.

    private void setViewTrans() {                // scene graph view
transform
        Matrix3d mat = new Matrix3d();
        mat.setColumn( 0, RTw);
        mat.setColumn( 1, UPw);
        mat.setColumn( 2, DIRw);
        Transform3D trans = new Transform3D();
        trans.frustum( -width, width, -height, height, near, far);
        trans.set( mat, LOCw, 1.0);
        viewTrans.setTransform( trans);
    }

and the following code updates the camera frame from the camera's linear
and angular velocity by computing a difference quaternion for the rotation,
converting that to a differential rotation matrix deltaR.  deltaR is used to
rotate the camera frame then the linear velocity is added to the camera
position.

    public void step( double deltaT) {    // move camera one time step
        double q1, q2, q3, q4;                  // normalized Euler
parameters
        Matrix3d m1 = new Matrix3d(), m2 = new Matrix3d();
        Vector3d vec = new Vector3d();
        q1 = 0.5 * angularVel.x * deltaT;       // q123 = 0.5*omega*deltaT
        q2 = 0.5 * angularVel.y * deltaT;
        q3 = 0.5 * angularVel.z * deltaT;
        q4 = 1.0 - (q1*q1+q2*q2+q3*q3);         // q4 from normalization
        if ( q4 > 0.0) {
            q4 = Math.sqrt( q4);
            Matrix3d deltaR = new Matrix3d(  0.0, -q3,  q2,
                                                                  q3,
0.0, -q1,
                                                                 -q2,  q1,
0.0 );
            m1.mul( deltaR, deltaR);            // convert difference
quaternion to
            m2.mul( q4, deltaR);                // difference rotation
matrix
            deltaR.sub( m1, m2);
            deltaR.mul( 2.0);
            m1.setIdentity();
            deltaR.add( m1);                    // deltaR =
I+2(dqxdqx-q4*dqx)
            deltaR.transpose();
                // camera position += dt * velocity
            vec.set( DIRw);  deltaR.transform( vec, DIRw);
            vec.set( UPw);  deltaR.transform( vec, UPw);
            vec.set( RTw);  deltaR.transform( vec, RTw);
            LOCw.scaleAdd( deltaT, linearVel, LOCw);
            RTw.y = 0.0;                        // force the wing to stay
level
            UPw.cross( DIRw, RTw);
            RTw.cross( UPw, DIRw);
            RTw.normalize();  UPw.normalize();  DIRw.normalize();
        }
        setViewTrans();
    }

So, if angularVel = inc*UPw  there will be an incremental rotation
about the camera's up vector and so on.
Works great for any moving camera.  You might not want to force the
wings level.  I'm not allowing roll in this application.

Mike Shantz


----- Original Message -----
From: "Dipl. Ing. Paul Szawlowski" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, November 26, 2002 11:53 PM
Subject: Re: [JAVA3D] rotation problem


> Lan Wu-Cavener schrieb:
> > Hi, every one:
> >
> > I have the following rotation problem. What I need is to rotate the
> > ViewPlatform around its local x axis and  local original y(0,1,0), or
the
> > vector (0,1,0) in the local coordinates. Could anyone please help to
figure
> > out how to make it work.
> >
> > Thanks in advance!
> > Lan
> >
> > Lan Wu-Cavener
> > Dept. of Landscape Architecture
> >
> >
===========================================================================
> > 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".
> >
>
> Get the localToVworld transformation A of the Viewplatform. Then
> calculate the inverse A^-1 then calculate the transforamtion in the
> local coordinate system B and set the combination of the 3
> transformations: A * B * (A^-1).
> Hope i got the right order. Example code can be found in the j3d.org
> repositiry. Look for DefaultManipulator class in the
> org.j3d.input.spaceball.transformation package.
>
> regards
> Paul
>
>
===========================================================================
> 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".

===========================================================================
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".

Reply via email to