Here you go.  Use it like this:

  viewingPlatform.setViewPlatformBehavior(new SpinBehavior());


import com.sun.j3d.utils.behaviors.vp.ViewPlatformBehavior;
import javax.media.j3d.RotationInterpolator;
import javax.media.j3d.Alpha;
import javax.media.j3d.Transform3D;
import java.util.Enumeration;
import javax.vecmath.Vector3d;
import javax.vecmath.Matrix3f;
import javax.media.j3d.WakeupOnElapsedFrames;
import javax.media.j3d.BoundingSphere;
import javax.vecmath.Point3d;

public class SpinBehavior extends ViewPlatformBehavior {

    private Alpha rotationAlpha = new Alpha(-1, Alpha.INCREASING_ENABLE,
                                            0, 0, 4000, 0, 0, 0, 0, 0);
    private WakeupOnElapsedFrames nextFrame = new WakeupOnElapsedFrames(0);

    private static final double radius = 2.0;

    public void processStimulus(Enumeration criteria) {
        // get angle
        double theta = rotationAlpha.value() * 2.0 * Math.PI;

        Transform3D t = new Transform3D();
        t.lookAt(new Point3d(radius * Math.cos(theta), 0.0,
                             radius * Math.sin(theta)),
                 new Point3d(), new Vector3d(0.0, 1.0, 0.0));
        t.invert();
        targetTG.setTransform(t);

        wakeupOn(nextFrame);
    }

    public void initialize() {
        wakeupOn(nextFrame);
        setSchedulingBounds(
            new BoundingSphere(new Point3d(0.0, 0.0, 0.0), 100.0));
    }
}


***************************************************************
"Copyright (c) 2001 Sun Microsystems, Inc. All Rights Reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

-Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

-Redistribution in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.

Neither the name of Sun Microsystems, Inc. or the names of contributors may be
used to endorse or promote products derived from this software without
specific prior written permission.

This software is provided "AS IS," without a warranty of any kind. ALL
EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, INCLUDING ANY
IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR
NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN AND ITS LICENSORS SHALL NOT BE
LIABLE FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
OR DISTRIBUTING THE SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR ITS
LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR DIRECT,
INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE DAMAGES, HOWEVER
CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, ARISING OUT OF THE USE OF
OR INABILITY TO USE SOFTWARE, EVEN IF SUN HAS BEEN ADVISED OF THE
POSSIBILITY OF SUCH DAMAGES.

You acknowledge that Software is not designed,licensed or intended for use in
the design, construction, operation or maintenance of any nuclear facility."

****************************************************************************


> Delivered-To: [EMAIL PROTECTED]
> MIME-Version: 1.0
> Content-Transfer-Encoding: 7bit
> X-Priority: 3 (Normal)
> X-MSMail-Priority: Normal
> X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400
> Importance: Normal
> Date: Thu, 25 Oct 2001 16:33:10 -0400
> From: Dean Keeler <[EMAIL PROTECTED]>
> Subject: [JAVA3D] Rotating a view around an object in the world
> To: [EMAIL PROTECTED]
>
> To All,
>
> I am trying to rotate my view around a point (specifically part in the
> world) other than the view's origin point in the view's local csys.  I have
> tried various different techniques but have not achieved any success.  I am
> currently rotating the world by
>
> 1. determining the translation distance based on the angle or rotation (this
> is a delta value e.g. 5 degrees)
> 2. determining the translation of the view to the origin point of the world.
> 3. determining the translation to move the view back once it is rotated
> 4. determining the rotation matrix when the view is at the origin of the
> world
>
> Then I multiply the matrices together to get a transformation matrix to do
> all those moves.
>
> The only thing it does is move the view to the origin point of the world and
> and never comes back out or rotates.
>
> Can anybody help me.  I am getting very frustrated.
>
> Thankyou,
>
> Dean
>
> ===========================================================================
> 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