We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Scaling + lines == flipping
Page Index Toggle Pages: 1
Scaling + lines == flipping (Read 543 times)
Scaling + lines == flipping
Mar 17th, 2010, 10:14am
 
Hi all,

I have a problem I'm trying to figure out, so I thought
I would create a simple test example and post here.

The example draws 12 lines to create the outline of
a box, and it uses the mousewheel to zoom in and
out. I've included the source at the end of this
message, but I've also put an applet here:

bebop.cns.ualberta.ca/~cwant/zoom_test/
(website won't let me post a URL, so protocol stripped).

Why is an 'X' drawn when one zooms in close?
An alternate phrasing for this question:why do lines
flip when one scales by a large(ish) amount?

I'd appreciate any tips for detecting and avoiding
this behavior.

Cheers,
Chris

Quote:
import java.awt.event.MouseWheelListener;

ZoomBox zoomBox;

void setup() {
  size(500,600,P3D);
  zoomBox = new ZoomBox();
}

void draw() {
  zoomBox.draw();
}

class ZoomBox implements MouseWheelListener {
  float zoom = 1.0;
  float zoomFactor = 1.10;

  ZoomBox(){
    addMouseWheelListener(this);
  }
  
  void draw() {
    background(255);
    pushMatrix();
    translate(width/2, height/2);
    scale(zoom);

    beginShape(LINES);
    vertex(-100, -100, -100); vertex(-100,  100, -100);
    vertex( 100, -100, -100); vertex( 100,  100, -100);
    vertex(-100, -100, -100); vertex( 100, -100, -100);
    vertex(-100,  100, -100); vertex( 100,  100, -100);
    vertex(-100, -100,  100); vertex(-100,  100,  100);
    vertex( 100, -100,  100); vertex( 100,  100,  100);
    vertex(-100, -100,  100); vertex( 100, -100,  100);
    vertex(-100,  100,  100); vertex( 100,  100,  100);
    vertex(-100, -100,  100); vertex(-100, -100, -100);
    vertex( 100, -100,  100); vertex( 100, -100, -100);
    vertex(-100,  100,  100); vertex(-100,  100, -100);
    vertex( 100,  100,  100); vertex( 100,  100, -100);
    endShape();

    popMatrix();
  }

  void mouseWheelMoved(java.awt.event.MouseWheelEvent e) {
    int notches = e.getWheelRotation();
    if (notches < 0) {
      zoom *= zoomFactor;
    }
    else {
      zoom /= zoomFactor;
    }
    println(zoom);
  }
}

Re: Scaling + lines == flipping
Reply #1 - Mar 17th, 2010, 10:39am
 
known processing bug caused by things being behind the camera.

have you tried opengl? failing that you need to limit your zooming.
Re: Scaling + lines == flipping
Reply #2 - Mar 17th, 2010, 11:17am
 
No, I haven't tried OpenGL -- the sketch I'm writing needs to do
offscreen rendering (which I've read doesn't work with processing's
OpenGL renderer).

Is there a test for whether something is behind the camera? I've tried
weeding out cases when screenZ() is negative, but that doesn't seem
to solve the issue.

Cheers,
Chris
Re: Scaling + lines == flipping
Reply #3 - Mar 17th, 2010, 11:58am
 
I just upgraded to processing 1.1 and it seems the problems with my sketch have gone away (the example I provided in this post still has problems though).

Chris
Page Index Toggle Pages: 1