Hello.
First of all i would like to thank you for providing the code for keyboard
event handling.
Your Code helped me alot.
I am only facing one problem, as mentioned by urself, while pasting that
code on java3d mailing list that
if you were to hold down the left key, there would be a split second
delay after the initial incremental move before it continuously moves left

this really effects the performance of my game.
I would highly appreciate if u (or someone else) can provde me the solution
 to this problem
Thanking you in Anticipation


Fahad
I have pasted the code your code below for reference.




import java.awt.*;
import java.awt.event.*;
import java.util.*;
import javax.media.j3d.*;
import javax.vecmath.*;

public class KeyboardBehavior extends Behavior {
        WakeupCriterion[] keyboardEvents;
        WakeupOr keyboardCriterion;
        TransformGroup transformGroup;  // the transform group that the
viewplatform is attached to
        Transform3D     move;
        float           change;

        public KeyboardBehavior(TransformGroup transformGroup)
        {
                super();
                this.transformGroup = transformGroup;
                move = new Transform3D();
                change=0.5f;
        }

        public void initialize()
        {
                keyboardEvents = new WakeupCriterion[2];
                // Only wake up when a key is pressed or released
                keyboardEvents[0] = new
WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
                keyboardEvents[1] = new
WakeupOnAWTEvent(KeyEvent.KEY_RELEASED);
                keyboardCriterion = new WakeupOr(keyboardEvents);
                wakeupOn (keyboardCriterion);
        }


        public void processStimulus (Enumeration criteria)
        {
                WakeupCriterion wakeup;
                AWTEvent[] event;
                KeyEvent evt;

                while (criteria.hasMoreElements()) {
                        wakeup = (WakeupCriterion) criteria.nextElement();
                        if (wakeup instanceof WakeupOnAWTEvent) {
                                event =
((WakeupOnAWTEvent)wakeup).getAWTEvent();
                                for (int i=0; i<event.length; i++) {
                                        evt = (KeyEvent) event[i];
                                        if
(evt.getID()==KeyEvent.KEY_PRESSED) {
                                                KEY_PRESSED=true;
                                                switch(evt.getKeyCode()) {
                                                        case
KeyEvent.VK_NUMPAD4:       // move left

move.set(new Vector3f(-1*change, 0, 0));

transformGroup.setTransform(move);
                                                                break;
                                                        case
KeyEvent.VK_NUMPAD6:       // move right

move.set(new Vector3f(change, 0, 0));

transformGroup.setTransform(move);
                                                                break;
                                                } // end switch
                                        } // end if keypressed
                                } // end for loop that processes all events
                        } //end if wakeup
                } // end while
                wakeupOn(keyboardCriterion);    // VERY IMPORTANT TO CALL
THIS AGAIN AT THE END OF THE FUNCTION
        } // end process stimulus
} // end class

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