Forum Stats

  • 3,852,847 Users
  • 2,264,142 Discussions
  • 7,905,157 Comments

Discussions

how to add to viewPlatformBehavior an Action Event - a button press

843799
843799 Member Posts: 49,999
And the main problem I have is to by pressing buttons to change the Viewing Platform?
I made same transformation to object, which reacts to key pressin:
 public class LewoPrawo extends Behavior{
    private TransformGroup targetLP;
    private Transform3D wysuwanie = new Transform3D();
    private float krok2 = (float) 0.0;
     // create LewoPrawo
    LewoPrawo(TransformGroup targetLP){
    this.targetLP = targetLP;
    }

     public void initialize(){            
            this. wakeupOn(new WakeupOnAWTEvent(AWTEvent.KEY_EVENT_MASK));
    }

    public void processStimulus(Enumeration enumeration){
        this.wakeupOn(new WakeupOnAWTEvent(AWTEvent.KEY_EVENT_MASK));

            KeyEvent event = (KeyEvent) ((WakeupOnAWTEvent) enumeration.nextElement()).getAWTEvent()[0];

           if (event.getKeyCode() == KeyEvent.VK_Q) {
               krok2 += 0.01;
           }
           if (event.getKeyCode() == KeyEvent.VK_W) {
               krok2 -= 0.01;
           }
           wysuwanie.set(new Vector3f(krok2, 0.0f, 0.0f));
           wysuwanie.mul(przewrocenie);
           targetLP.setTransform(wysuwanie);
    }
And this is the one that I made up to move the viewing platform, but it doesn't work!!!
public class Perspektywa extends ViewPlatformBehavior{

private TransformGroup targetVP;
private Transform3D obrot_obserwatora = new Transform3D();
private double kat=0.0;

//create Perspektywa

	Perspektywa(){
// ???	
	}

	public void initialize(){
	this.wakeupOn(new WakeupOnAWTEvent(AWTEvent.ACTION_EVENT_MASK));
	}

	
	public void processStimulus(Enumeration enumeration){
	this.wakeupOn(new WakeupOnAWTEvent(AWTEvent.ACTION_EVENT_MASK));
 	
ActionEvent event = (ActionEvent) ((WakeupOnAWTEvent) enumeration.nextElement()).getAWTEvent()[0];


	if (event.getSource()== przyciski[0])  {
           kat += 0.1;
       }
       if (event.getSource() == przyciski[3]) {
           kat -= 0.1;
       }

        obrot_obserwatora.rotY(kat);

        TransformGroup targetVP =
            simpleU.getViewingPlatform().getViewPlatformTransform();
        targetVP.getTransform( obrot_obserwatora);
        
        }
}
And what's worse, action events doesnt even work when i replace key events with them, but i don;t know why ;(
This discussion has been closed.