Looks like a problem with the Bounds on the Mouse Behaviors....
or java3d has a problem if an 3d shape becomes to small or to big...
 
and is your line correct?? should it not be?:
transformX.set(old_scale_factor *(1+dy*scale_factor)); 
 
----- Original Message -----
Sent: Monday, February 17, 2003 10:05 AM
Subject: [JAVA3D] Modified MouseZoom but canvas hangs

Hi all,
 
I modified the MouseZoom.java class to work such that it uses scaling instead of translation. However,
there is a tendency for the canvas to "hang" after zooming in/out continuously. 
The frame still works but no mouse activity within the canvas can be carried out (i.e. MouseRotate, MouseTranslate).
What can be the problem?
Apparantly, I only changed significantly one line of code (in red) , which is from set(Vector 3d) to set(double).
 
 
 
 
public class MouseZoom extends MouseBehavior {
 double scale_factor;
 
 private MouseBehaviorCallback callback = null;
 
  /**
  * Creates a zoom behavior given the transform group.
  * @param transformGroup The transformGroup to operate on.
  */
 public MouseZoom(TransformGroup transformGroup) {
  super(transformGroup);
 }
 
  /**
  * Creates a default mouse zoom behavior.
  **/
 public MouseZoom(){
  super(0);
 }
 
  /**
  * Creates a zoom behavior.
  * Note that this behavior still needs a transform
  * group to work on (use setTransformGroup(tg)) and
  * the transform group must add this behavior.
  * @param flags
  */
 public MouseZoom(int flags) {
  super(flags);
 }
 
 public void initialize() {
  super.initialize();
  scale_factor = .04;
  
  if ((flags & INVERT_INPUT) == INVERT_INPUT) {
   scale_factor *= -1;
   invert = true;
  }
  
 }
 
  /**
  * Return the y-axis movement multipler.
  **/
 
 public double getFactor() {
  return scale_factor;
 }
 
  /**
  * Set the y-axis movement multipler with factor.
  **/
 
 public void setFactor( double factor) {
  scale_factor = factor;
  
 }
 
 public void processStimulus (Enumeration criteria) {
  WakeupCriterion wakeup;
  AWTEvent[] event;
  int id;
  int dx, dy;
  
  while (criteria.hasMoreElements()) {
   wakeup = (WakeupCriterion) criteria.nextElement();
   if (wakeup instanceof WakeupOnAWTEvent) {
    event = ((WakeupOnAWTEvent)wakeup).getAWTEvent();
    for (int i=0; i<event.length; i++) {
     processMouseEvent((MouseEvent) event[i]);
     
     if (((buttonPress)&&((flags & MANUAL_WAKEUP) == 0)) ||
      ((wakeUp)&&((flags & MANUAL_WAKEUP) != 0))){
      id = event[i].getID();
      if ((id == MouseEvent.MOUSE_DRAGGED) &&
       ((MouseEvent)event[i]).isAltDown() &&
       !((MouseEvent)event[i]).isMetaDown()){
       
       
       x = ((MouseEvent)event[i]).getX();
       y = ((MouseEvent)event[i]).getY();
       
       dx = x - x_last;
       dy = y - y_last;
       
       if (!reset){
        transformGroup.getTransform(currXform);

        transformX.set(1+(dy*scale_factor));  //*****************CHANGED******************//
        
        if (invert) {
         currXform.mul(currXform, transformX);
        } else {
         currXform.mul(transformX, currXform);
        }
        
        transformGroup.setTransform(currXform);
        
        transformChanged( currXform );
        
        if (callback!=null)
         callback.transformChanged( MouseBehaviorCallback.ZOOM,
         currXform );
        
       }
       else {
        reset = false;
       }
       
       x_last = x;
       y_last = y;
      }
      else if (id == MouseEvent.MOUSE_PRESSED) {
       x_last = ((MouseEvent)event[i]).getX();
       y_last = ((MouseEvent)event[i]).getY();
      }
     }
    }
   }
  }
  
  wakeupOn (mouseCriterion);
 }
  /**
  * Users can overload this method  which is called every time
  * the Behavior updates the transform
  *
  * Default implementation does nothing
  */
 public void transformChanged( Transform3D transform ) {
 }
 
  /**
  * The transformChanged method in the callback class will
  * be called every time the transform is updated
  */
 public void setupCallback( MouseBehaviorCallback callback ) {
  this.callback = callback;
 }
}
 
 
 

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.449 / Virus Database: 251 - Release Date: 27.01.2003

Reply via email to