Hi I have written a small code to ResetmyImage on the screen when a button
is pressed, I used the same steps as suggested, but I want to know how i
can activate this event from my application so that my application
listens to this event.I have created a constructor for the program given
below and have passed my transform group.

Assume I have created my Object

ResetkeyBehavior rkb = new ResetKeyBehavior(sceneTransformGroup);
rkb.initilize(); // gives an error

Please help.



> From: Gautam Jindal <[EMAIL PROTECTED]>
>
> 1> How can I stop an object from getting lost from the screen?ie.
whenever
> I translate,rotate sometimes the object gets lost and it becomes very
> difficult to track it down.Is there a way to make the object stay put on
> the screen.Please let me know how can I do this.

You can turn down the sensisitivity of the mouse behaviors so that the
object 
doesn't "fly off" so quickly (see the answer to 3> below).

You can also setup a KeyBehavior which resets the transform to identity
when the
user hits a key.  See ExitKeyBehavior.java attached below for an example
of a 
KeyBehavior.  What you need to do is:

        Make a new class ResetKeyBehavior, using ExitKeyBehavior as a
guide
        Make the constructor for this behavior take the TransformGroup
that
           the MouseBehaviors are acting on, save this in a field.
        Modify the WakeupCriterion to look only for KEY_PRESS events
        Modify processKeyEvent to look for your "reset" key, for example,
to
            make the "r" key reset the transform, use KeyEvent.VK_R.
        When the key is pressed, call ;
                TransformGroup.setTransform(new Transform3D())
           To reset the transform.
        


> 2> Every time I run my application ,the object..which is a surface
appears
> from the center of the screen ,I am interested in starting it from left
> bottom of my screen ,any ideas?

Set up a TransformGroup above your object to hold the translation.  Set up
a 
Trasnform3D with the desired translation (you probably want (-0.8, -0.8,
0.0)) 
and call setTransform on the TransformGroup to set the transform.

> 3> I am using mouse behaviour class provided my java 3.Anyway that I can
> change the translation steps and rotational  angle.

Decrease the sensitivity of the mouse behaviors by calling setFactor().  I
find 
that setting the factor to 0.007 works well for a MouseRotate behavior.

Doug Gehringer
Sun Microsystems




/*
 *      @(#)ExitKeyBehavior.java 1.1 98/12/04 14:43:14
 *
 * Copyright (c) 1996-1998 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Sun grants you ("Licensee") a non-exclusive, royalty free, license to
use,
 * modify and redistribute this software in source and binary code form,
 * provided that i) this copyright notice and license appear on all copies
of
 * the software; and ii) Licensee does not utilize the software in a
manner
 * which is disparaging to Sun.
 *
 * 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.
 *
 * This software is not designed or intended for use in on-line control of
 * aircraft, air traffic, aircraft navigation or aircraft communications;
or in
 * the design, construction, operation or maintenance of any nuclear
 * facility. Licensee represents and warrants that it will not use or
 * redistribute the Software for such purposes.
 */
import javax.media.j3d.*;
import java.util.*;
import java.awt.Event;
import java.awt.Point;
import java.awt.AWTEvent;
import java.awt.Dimension;
import java.awt.event.KeyEvent;
import java.awt.event.MouseEvent;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.awt.event.WindowEvent;
import javax.vecmath.*;

/** 
 * A KeyBehavior which called exit when the ESC key is pressed
 */

public class ExitKeyBehavior extends Behavior {

    // look for released events since sometimes ESCAPE only generates a 
    // RELEASE event
    WakeupCriterion criterion[] = { 
                new WakeupOnAWTEvent( Event.KEY_PRESS ),
                new WakeupOnAWTEvent( Event.KEY_RELEASE ),
                };

    WakeupCondition conditions = new WakeupOr( criterion );

    public void initialize() {
        wakeupOn(conditions);
    }

    public void processStimulus( Enumeration criteria ) {
        WakeupCriterion wakeup;
        AWTEvent[] evt=null;

        while( criteria.hasMoreElements() ) {
            wakeup = (WakeupCriterion)criteria.nextElement();
            if (wakeup instanceof WakeupOnAWTEvent) {
                 evt=((WakeupOnAWTEvent)wakeup).getAWTEvent();
            }

            if (evt!=null) {
                for(int i=0; i<evt.length; i++) {
                    if (evt[i] instanceof KeyEvent)  {
                        processKeyEvent( (KeyEvent)evt[i] );
                    }
                }
            }
        }
        wakeupOn( conditions );
    }

    private void processKeyEvent( KeyEvent evt ) {
        int key = evt.getKeyCode();
        switch (key) {
          case KeyEvent.VK_ESCAPE:
            System.exit(0);
            break;
        }
    }
}



Gautam Jindal
CSE Department
University of Nebraska,Lincoln.


=====================================================================
To subscribe/unsubscribe, send mail to [EMAIL PROTECTED]
Java 3D Home Page: http://java.sun.com/products/java-media/3D/

Reply via email to