Stefan Dachwitz wrote:
>
> Hello Joerg,
>
> I wasn't able to find keyboard navigation in the examples you
> mention. Is there something wrong with my eyes?
> I downloaded the course notes, and I couldn�t find anything
> but keyboard modifiers to increase speed.
> I would be glad if you could point me to it!
>
> Cheers,
>
>      Stefan
>

Dear Stefan,
I'm sorry to point you to the wrong place. In the piece of software I
wrote I've used David's viewer behaviors, but you are right these behaviors
are mouse behaviors. Attached, is the key navigation behavior I wrote,
which doesn't use wakeup on elapsedframes. So I had to appologize to all the
people, who downloaded 15MB. Mea culpa.

Keep things simple

Joerg
--

  http://w5.cs.uni-sb.de/~baus

  Email : [EMAIL PROTECTED]
  Phone : +49-681-302-2016
  Fax   : +49-681-302-4136
import javax.media.j3d.Behavior;
import javax.media.j3d.TransformGroup;
import javax.media.j3d.Transform3D;
import javax.media.j3d.WakeupOnAWTEvent;
import java.awt.AWTEvent;
import java.awt.event.*;
import javax.vecmath.Vector3f;


public class MyKeyNavigatorBehavior extends Behavior {
        private Transform3D tr, tgr;
        private TransformGroup tg;
        private WakeupOnAWTEvent wup;
        private Vector3f vec;
        private float step;
        private double angle;

        public MyKeyNavigatorBehavior(TransformGroup targetTG, float moveStep, double 
rotStep ){
                super();
                this.tgr = new Transform3D();
                this.tg = targetTG;
                this.wup = new WakeupOnAWTEvent(KeyEvent.KEY_PRESSED);
                this.step = moveStep;
                this.angle = rotStep;
        }

        public void initialize(){
                System.out.println("Key Behavior init");
                wakeupOn(wup);
                tg.getTransform(tgr);
                System.out.println(tgr.toString());
        }

        public void processStimulus(java.util.Enumeration       criteria){
                KeyEvent event = (KeyEvent) (wup.getAWTEvent())[0];
                int keyCode = event.getKeyCode();

                if (keyCode == KeyEvent.VK_UP || keyCode == KeyEvent.VK_DOWN ||
                          keyCode == KeyEvent.VK_LEFT || keyCode == KeyEvent.VK_RIGHT)
                         {
                                switch (keyCode) {
                                        case KeyEvent.VK_UP:
                                        tr = new Transform3D();
                                        vec = new Vector3f(0.0f,0.0f,-step);
                                        tr.setTranslation(vec);
                                        tg.getTransform(tgr);
                                        tgr.mul(tr);
                                        tg.setTransform(tgr);
                                        wakeupOn(wup);
                                return;
                                case KeyEvent.VK_DOWN:
                                        tr = new Transform3D();
                                        vec = new Vector3f(0.0f,0.0f,step);
                                        tr.setTranslation(vec);
                                        tg.getTransform(tgr);
                                        tgr.mul(tr);
                                        tg.setTransform(tgr);
                                        wakeupOn(wup);
                                return;
                                case KeyEvent.VK_LEFT:
                                        tr = new Transform3D();
                                        tr.rotY(Math.toRadians(angle));
                                        tg.getTransform(tgr);
                                        tgr.mul(tr);
                                        tg.setTransform(tgr);
                                        wakeupOn(wup);
                                return;
                                case KeyEvent.VK_RIGHT:
                                        tr = new Transform3D();
                                        tr.rotY(-Math.toRadians(angle));
                                        tg.getTransform(tgr);
                                        tgr.mul(tr);
                                        tg.setTransform(tgr);
                                wakeupOn(wup);
                        return;
                        }
                } else {wakeupOn(wup);}
        }
}

Reply via email to