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 & HelpOpenGL and 3D Libraries › openGL, zooming out and objects disappear
Page Index Toggle Pages: 1
openGL, zooming out and objects disappear (Read 2425 times)
openGL, zooming out and objects disappear
Jun 12th, 2009, 9:55am
 
Hello there,

i want to develope a simple presentation tool with processing.
Basicly is should work like this:
The various slides  ( .png`s and .jpgs) are arrangend on one big surface. When changing the slides the camera zooms out,
heads towards the new slide and zooms in again.

Im using openGL and here is the problem:
When zooming out and the z-axis reaches values
more than 6000 the slides seem to disappear.
I`m not really into openGL and couldn`t  
figure out a sollution yet.

P3D works well but is slow and the zoomed out slides look ugly.
I`m on Leopard 10.5.7 and NetBeans 6.5.1 IDE.

Thanks in advance.

sim



Re: openGL, zooming out and objects disappear
Reply #1 - Jun 12th, 2009, 11:04am
 
sounds like things are being clipped by the far clipping plane

http://www.falloutsoftware.com/tutorials/gl/gl0.htm

how are you setting up your view?
Re: openGL, zooming out and objects disappear
Reply #2 - Jun 12th, 2009, 11:24am
 
Hello,

thanks for the quick answer.
The view is set with the camera() command.

here`s the code. No x- and y-movement of camera yet, only zooming :).


import processing.core.*;
import processing.opengl.*;

   PImage a;
   PImage b;
   PImage c;
   PImage d;


void setup() {
       size(1024, 768, OPENGL);
       imageMode(CENTER);
       a = loadImage("data/alex.png");
       b = loadImage("data/black_forest.jpg");
       c = loadImage("data/mouse.jpg");
       d = loadImage("data/abgabe_8.png");
   }

   public void draw() {
       background(200);
     
       camera(width / 2, height / 2,(float) ((height/2.0) / tan((float) (PI * 60.0 / 360.0)))+ mouseY * 100,
               width / 2, height / 2, 0,
               0, 1, 0);
       System.out.println(mouseY * 100);
       image(a, 200, 200);
       image(b, 200, 800);
       image(c, 800, 200);
       image(d, 800, 800);

   }

Re: openGL, zooming out and objects disappear
Reply #3 - Jun 12th, 2009, 2:19pm
 
the frustum() function allows you to define near and far.

file:///opt/processing-1.0.3/reference/frustum_.html

i've no idea whether that interferes with camera() though. i will have a play with your code.
Re: openGL, zooming out and objects disappear
Reply #4 - Jun 13th, 2009, 1:56am
 
actually, perspective() is what you need.

http://processing.org/reference/perspective_.html
Re: openGL, zooming out and objects disappear
Reply #5 - Jun 13th, 2009, 1:56am
 
i added this after the camera call and the clipping at 6000 stopped (see above - by default the backplane is set to 10 * cameraZ)

// see manpage
float fov = PI / 3.0;  // 60 degrees
float cameraZ = (height / 2.0) / tan(fov / 2.0);
perspective(fov, float(width)/float(height), cameraZ / 10.0, 10000);  // 10000 = backplane
Re: openGL, zooming out and objects disappear
Reply #6 - Jun 13th, 2009, 1:57am
 
(i also changed the camera to

float distance = (mouseX * 10) - 20;
camera(0, 0, (float) ((height/2.0) / tan((float) (PI * 60.0 / 360.0))) + distance,
 0, 0, 0,
 0, 1, 0);

which puts the camera on the z axis and the image centre at the origin - i find it easier to visualise. you'll need to change the image positions to match this. i used:

// 4 images resized to 200x200 each, centred on origin
image(a,  100,  100, 200, 200);
image(b,  100, -100, 200, 200);
image(c, -100,  100, 200, 200);
image(d, -100, -100, 200, 200);
)

(apologies for multiple messages, i can't for some reason, post anything complex)
Re: openGL, zooming out and objects disappear
Reply #7 - Jun 13th, 2009, 12:15pm
 
Hey,

works great. Thanks for helping.

Unfortunately there seems to be another problem.
The slides are stretched.  
Guess that this is initiated by the perspective(); call.
The display of the slides has to be pixel accurate.

I need to change the position of the clipping plane without applying a perspective.







Re: openGL, zooming out and objects disappear
Reply #8 - Jun 13th, 2009, 1:00pm
 
strange things,

when i call default perspective(); without values there is no image stretching.

when i call perspective(); and insert the default values given in the reference the images are streched.


Page Index Toggle Pages: 1