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 & HelpSyntax Questions › problem with 3D and camera
Page Index Toggle Pages: 1
problem with 3D and camera (Read 1160 times)
problem with 3D and camera
Jun 24th, 2009, 4:43am
 
I'm programming a sound equalizer for a university project, see code below.

the code below is a sketch at 1024x640 where everything works fine.

But the final project needs to be 6144x640 and I then get the problem that it puts the start of the equalizer in the middle of the screen, whereas I need it to start on the left side.
When putting a simple offset value I can get it to the left side but it looks totally different due to camera settings/distortion...

What I basically need is the equalizer to look exactly like the one in my 1024px sketch, but on the left side of the 6144px sketch!

can anybody help me with my camera settings, or is there an easier way to achieve the look?
thanks for your help!

here is the code, it reacts to audio input, so plug in a mic and leave some music running...
_____________
import ddf.minim.*;

Minim minim;
AudioInput in;

float randomhue;

void setup () {
 size(1024, 640, P3D);
 background(0);
 colorMode(HSB, 500, 100, 100);


 minim = new Minim(this);  
 minim.debugOn();

 // get a line in from Minim, default bit depth is 16
 in = minim.getLineIn(Minim.MONO, 96);

}

void draw(){
 camera(140.0, 420.0, 120.0, 150.0, 150.0, 0.0, 0.0, 1.0, 0.0);


 background(0);
 /*  if(frameCount % 100 == 0){
  randomhue = random(500);
  }
  stroke(random(randomhue,randomhue-20),50,75, 30); */
 for (int i=1; i < in.mix.level()*500; i = i+1)
 {
   for(int j=0; j < 30; j = j+1){
     for(int k = 0; k < in.bufferSize() - 1; k++)
     {
       stroke(i*in.mix.get(k+1)*100,75,(k+1)*4, 50);
       point(i*10, j*5, in.mix.get(k+1)*400);



     }
   }
 }

}
void stop()
{
 // always close Minim audio classes when you are done with them
 in.close();
 minim.stop();

 super.stop();
}


_________________
Re: problem with 3D and camera
Reply #1 - Jun 24th, 2009, 6:16am
 
You should just be able to use width and height with an offset, work from the corner of the screen.
3D will often put 0,0,0 in the center of the screen.  So use your width and height settings to offset it.
i*10-width/3
Re: problem with 3D and camera
Reply #2 - Jun 24th, 2009, 7:02am
 
I would have thought it would be as simple as that too, but maybe it's not.  camera takes arguments that set two points: one is the position of the eye/camera the other is the 'centre of the scene' - i.e. the target the camera is pointing at.  It looks to me like he's made adjustments to camera to get it facing his points, when in fact he might be better off leaving camera alone and looking into how to position the points where he needs them...  My initial hunch was that a translate operation would do the trick...

I'm assuming the final piece is going to be split over several monitors - perhaps an alternative solution might be to render separate windows (assuming that's straightforward - I'm thinking aloud here...)
Re: problem with 3D and camera
Reply #3 - Jun 24th, 2009, 7:34am
 
A simple translate operation will not work here because of the camera perspective.

blindfish said
Quote:
It looks to me like he's made adjustments to camera to get it facing his points, when in fact he might be better off leaving camera alone and looking into how to position the points where he needs them...


and I agree with that.

An alternative would be to use OPENGL and define a 2 OpenGL viewports, one on the left for the equaliser and the other for whatever.

It is a hack but this discussion shows how it can be done

http://processing.org/discourse/yabb2/board_OpenGL_3Baction_display_3Bnu___.html
Re: problem with 3D and camera
Reply #4 - Jun 25th, 2009, 1:35am
 
there must be an easier way to just offset it to not have it start in the center but on the left side of the screen.....I'm very new to processing and quite stuck, plus the project has to be finished by monday....

Re: problem with 3D and camera
Reply #5 - Jun 25th, 2009, 2:13am
 
Then I think the simplest solution is probably to forget about camera and figure out how to get your points rendering in the right portion of the screen.  I suspect that even if you 'fix' the camera you may still have problems when trying to render anything else in the rest of the screen; if you figure out how to position things correctly I suspect that will make the rest easier also...  I'll see if I can come up with an example Wink
Re: problem with 3D and camera
Reply #6 - Jun 25th, 2009, 2:36am
 
OK 2 things:

1. From size: "The maximum width and height is limited by your operating system, and is usually the width and height of your actual screen. On some machines it may simply be the number of pixels on your current screen, meaning that a screen that's 800x600 could support size(1600, 300), since it's the same number of pixels. This varies widely so you'll have to try different rendering modes and sizes until you get what you're looking for. If you need something larger, use createGraphics to create a non-visible drawing surface."

So what you're trying may not be possible anyway.  Sorry not to spot this sooner, but I guess we were assuming that you'd verified you could do it.  Assuming you can then:

2.  I'm not going to do your homework for you but here's a hint: comment out your camera line and try changing the order of variables in your point call:

point(i*10, j*5, in.mix.get(k+1)*400);

...remembering that the order of the parameters is x, y and z.  You currently have the minim input on the Z (depth) axis.  You can then add offset values to each to adjust the position.  Having said that it may still not look the way you want because of the effects of perspective, unless you rotate the whole construction to face the camera.  To put it another way: if you fix the camera so this section looks right you'll probably have problems with anything else being rendered...
Re: problem with 3D and camera
Reply #7 - Jun 25th, 2009, 10:54am
 
Quote:
When putting a simple offset value I can get it to the left side but it looks totally different due to camera settings/distortion...

What I basically need is the equalizer to look exactly like the one in my 1024px sketch, but on the left side of the 6144px sketch!


Two suggestions
(1) After you perform the translate to move it to the left try a rotation about the Y axis to reverse the effects of perspective, try different values remembering rotations are set in radians. You may get something similar to what you want.
(2) Does it have to be 3D Can you get away with using 2D

I have not come across a display with a 6144px resolution - where did this figure come from. If it is due to the vaules you get back from Minim you could  scale these values done to fit 512 and leave some space in your display for something else, alternatively you could try using perspective http://processing.org/reference/perspective_.html to increase the field of view angle - this is similar to using a wide angle lens on a camera.

Best of luck for Monday, I suspect you are going to have a very busy weekend. Smiley

Re: problem with 3D and camera
Reply #8 - Jun 26th, 2009, 12:47am
 
Quark wrote on Jun 25th, 2009, 10:54am:
I have not come across a display with a 6144px resolution


6144/6 = 1024

Which would suggest a multiple monitor setup set in the OS to be a single extending screen.  The only way I can think to get 6 monitors on a single PC is using DisplayLink.  Assuming that's the case be warned that whilst this technology is very cool it does have its limitations, namely in terms of the speed with which it can process and render output - it's great for day-to-day tasks, but not so good with content dependent on high framerates (e.g. video, games etc...).  Again something to consider before spending too much time trying to get a 6144px wide sketch running the way you want it.
Page Index Toggle Pages: 1