[JAVA3D] Minuterie d'un WakeupOnElapsedTime dui déconne
Bonjour, je suis en train de réaliser un manege en java3D pour mes études,
J'ai réaliser les objets et je dois fair bouger une nacelle prédéfinie suivant la touche utilisé et suivant un temps voulu.
Mon problème se base sur ma classe des touches utilisé, suivant cette classe quand j'appuie sur une touche un nacelle tourne durant un moment prédefini mais il faut que je reste appuyer sur cette touche pour la faire tourner.
Voici le code de ma classe KeyBehavior :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
import java.util.Enumeration;
import java.awt.event.KeyEvent;
import java.awt.AWTEvent;
import javax.vecmath.Point3d;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.Behavior;
import javax.media.j3d.WakeupCriterion;
import javax.media.j3d.WakeupCondition;
import javax.media.j3d.WakeupOr;
import javax.media.j3d.WakeupOnElapsedTime;
import javax.media.j3d.WakeupOnAWTEvent;
public class KeyBehavior extends Behavior
{
private WakeupCriterion[] wakeup;
private WakeupCondition wakeupCombi;
private Controlable ctrl;
private boolean fixed = true;
public KeyBehavior (Controlable ctrl)
{
wakeup = new WakeupCriterion[2];
wakeup[0] = new WakeupOnAWTEvent (KeyEvent.KEY_PRESSED );
wakeup[1] = new WakeupOnElapsedTime (50L); // minuterie
wakeupCombi = new WakeupOr (wakeup);
this.ctrl = ctrl;
setSchedulingBounds (new BoundingSphere (new Point3d (), 300.0));
}
public void initialize()
{
this.wakeupOn (wakeup[0]);
}
public void processStimulus(Enumeration Criteria)
{
AWTEvent[] tabEvent = ( (WakeupOnAWTEvent) wakeup[0]).getAWTEvent();
AWTEvent event;
for (int i = 0; i < tabEvent.length; i++)
{
event = tabEvent[i];
switch (((KeyEvent) event).getKeyCode())
{
case KeyEvent.VK_UP :
System.out.println("UP");
if (fixed = !fixed) this.wakeupOn (wakeup[0]);
else this.wakeupOn (wakeupCombi);
if (ctrl.incrementer ()) this.wakeupOn (wakeupCombi);
else
{
this.wakeupOn (wakeup[0]);
fixed = true;
}
break;
case KeyEvent.VK_DOWN :
System.out.println("DOWN");
if (ctrl.incrementer ()) this.wakeupOn (wakeupCombi);
else
{
this.wakeupOn (wakeup[0]);
fixed = true;
}
break;
case KeyEvent.VK_LEFT :
System.out.println("LEFT");
if (ctrl.incrementer ()) this.wakeupOn (wakeupCombi);
else
{
this.wakeupOn (wakeup[0]);
fixed = true;
}
break;
case KeyEvent.VK_RIGHT :
System.out.println("RIGHT");
if (ctrl.incrementer ()) this.wakeupOn (wakeupCombi);
else
{
this.wakeupOn (wakeup[0]);
fixed = true;
}
break;
}
// System.out.println(" fin switch");
}wakeupOn(wakeupCombi);
}
} |
Auriez vous une solution pour mon problème ? C'est à dire j'appuie sur une touche et une nacelle tourne durant un moment?
Merci par avance.
[JAVA3D] Minuterie d'un WakeupOnElapsedTime dui déconne
voici mon nouveau algo :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
|
import java.util.Enumeration;
import java.awt.event.KeyEvent;
import java.awt.AWTEvent;
import javax.vecmath.Point3d;
import javax.media.j3d.BoundingSphere;
import javax.media.j3d.Behavior;
import javax.media.j3d.WakeupCriterion;
import javax.media.j3d.WakeupCondition;
import javax.media.j3d.WakeupOr;
import javax.media.j3d.WakeupOnElapsedTime;
import javax.media.j3d.WakeupOnAWTEvent;
/** Tache de fond applicable a un objet KeyPressedControlable. */
public class KeyBehavior extends Behavior
{
private WakeupCriterion[] wakeup;
private WakeupCondition wakeupCombi;
private Controlable ctrl;
private boolean fixed = true;
public KeyBehavior (Controlable ctrl)
{
wakeup = new WakeupCriterion[2];
wakeup[0] = new WakeupOnAWTEvent (KeyEvent.KEY_PRESSED );
wakeup[1] = new WakeupOnElapsedTime (50L); // minuterie
wakeupCombi = new WakeupOr (wakeup);
this.ctrl = ctrl;
setSchedulingBounds (new BoundingSphere (new Point3d (), 300.0));
}
public void initialize()
{
this.wakeupOn (wakeup[0]);
}
public void processStimulus(Enumeration Criteria)
{
AWTEvent[] tabEvent = ( (WakeupOnAWTEvent) wakeup[0]).getAWTEvent();
AWTEvent event;
for (int i = 0; i < tabEvent.length; i++)
{
event = tabEvent[i];
switch (((KeyEvent) event).getKeyCode())
{
case KeyEvent.VK_UP :
System.out.println("UP");
if (fixed = !fixed) this.wakeupOn (wakeup[0]);
else this.wakeupOn (wakeupCombi);
if (ctrl.incrementer ()) this.wakeupOn (wakeupCombi);
else
{
this.wakeupOn (wakeup[0]);
fixed = true;
}
break;
case KeyEvent.VK_DOWN :
System.out.println("DOWN");
if (fixed = !fixed) this.wakeupOn (wakeup[0]);
else this.wakeupOn (wakeupCombi);
if (ctrl.incrementer ()) this.wakeupOn (wakeupCombi);
else
{
this.wakeupOn (wakeup[0]);
fixed = true;
}
break;
case KeyEvent.VK_LEFT :
System.out.println("LEFT");
if (fixed = !fixed) this.wakeupOn (wakeup[0]);
else this.wakeupOn (wakeupCombi);
if (ctrl.incrementer ()) this.wakeupOn (wakeupCombi);
else
{
this.wakeupOn (wakeup[0]);
fixed = true;
}
break;
case KeyEvent.VK_RIGHT :
System.out.println("RIGHT");
if (fixed = !fixed) this.wakeupOn (wakeup[0]);
else this.wakeupOn (wakeupCombi);
if (ctrl.incrementer ()) this.wakeupOn (wakeupCombi);
else
{
this.wakeupOn (wakeup[0]);
fixed = true;
}
break;
}
// System.out.println(" fin switch");
}wakeupOn(wakeupCombi);
}
} |
et il me marque parfois (durant l'utilisation d'une touche) :
wglMakeCurrent Failed: L'operation de transfoemation demandée n'est pas prise en charge
wglMakeCurrent Failed: Descripteur non valide
Je connais pas du tout cette erreur et je ne vois pas ou elle se trouve.
Si vous avez une iddée je suis tout ouie. Merci d'avance pour votre aide