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 › camera() call changes image.pixels
Page Index Toggle Pages: 1
camera() call changes image.pixels (Read 927 times)
camera() call changes image.pixels
Mar 21st, 2008, 3:57pm
 
Hi all,

I encountered a problem I can't grasp. When I change the camera perspective, load the pixels, get these into an image, and draw this image, the image's perspective is somehow different. But the thing I really don't get is that when I subsequently reset the camera's perspective, the image's pixels are changed as well; somehow these reset to the new perspective, as if some 3d information is still present.

This is my code; you can comment out 1. camera(), 2. image() and camera()...

PImage im;

void setup() {
 size(400, 200, P3D);
 im = createImage(width, height, RGB);
}

void draw() {
 background(127, 127, 127);
 translate(width/2, height/2, height/-2);
 box(width/4);
 camera(width/2.0 - 100, height/2.0, (height/2.0) / tan(PI*60.0 / 360.0), width/2.0 - 100, height/2.0, 0, 0, 1, 0);
 loadPixels();
 for(int i=0; i<pixels.length; i++) {
   im.pixels[i] = blendColor(pixels[i], color(0, 255, 255), SUBTRACT);
 }
 image(im, 0, 0);
 camera();
}  

Hope I explained things clear...

Thanks in advance, BEnm
Re: camera() call changes image.pixels
Reply #1 - Mar 21st, 2008, 8:20pm
 
Where's the updatePixels() call? That might help? I'm no expert though
Re: camera() call changes image.pixels
Reply #2 - Mar 22nd, 2008, 11:51am
 
Hi Manic,

The same problem occurs if I use get() instead of loadPixels():

im = get();
for(int i=0; i<im.pixels.length; i++) {
 // pixel manipulation...
}
...etc...

I write "im" to the screen, so I don't have to update the pixels.
Re: camera() call changes image.pixels
Reply #3 - Mar 22nd, 2008, 12:55pm
 
I think what's happening is that you are drawing the image to the previous camera call's perspective.

If you call camera() before you paste the image, you get the results i think you were expecting.
Re: camera() call changes image.pixels
Reply #4 - Mar 22nd, 2008, 2:55pm
 
If you comment out the last camera call (and also the last image call) you see the perspective I want: you see two sides of the box.
Two things go wrong:
1. If I draw the image (only comment out the last camera call) the camera seems to close in on the box
2. When I subsequently call camera the image seems to change - as if the future somehow changes the past, because now the image only shows one side of the box!?!

.ben (aka BEnm)
Re: camera() call changes image.pixels
Reply #5 - Mar 22nd, 2008, 3:20pm
 
try this

Quote:
PImage im;

void setup() {
 size(400, 200, P3D);
 im = createImage(width, height, RGB);
}

void draw() {
 background(127, 127, 127);
 translate(width/2, height/2, height/-2);
 box(width/4);
 camera(width/2.0 - 100, height/2.0, (height/2.0) / tan(PI*60.0 / 360.0), width/2.0 - 100, height/2.0, 0, 0, 1, 0);
 loadPixels();
 for(int i=0; i<pixels.length; i++) {
   im.pixels[i] = blendColor(pixels[i], color(0, 255, 255), SUBTRACT);
 }
 im.pixels = pixels;
 
//image(im, 0, 0); leave commented, if you add these it goes wrong.
 //camera();
}  


To be honest, I don't really know whats going on here, but it seems to work.
Re: camera() call changes image.pixels
Reply #6 - Mar 22nd, 2008, 3:42pm
 
Hi Manic!

This is indeed the perspective I want.. But the way it's done seems a bit odd..

im.pixels = pixels !?!

It seems that a camera perspective is some sort of metadata in pixel arrays. That would explain why a subsequent camera call changes the perspective captured in previous image calls (and, maybe, your solution).
But, I need to change the camera perspective at least three times, and that would wreck previously drawn images. I want to make a stereoscopic (anaglyph) animation, that's why..

Thanks for thinking with me!
Re: camera() call changes image.pixels
Reply #7 - Mar 23rd, 2008, 2:07pm
 
You could maybe do that through 2 loops, or by creating 2 pGraphics and combining them?
Re: camera() call changes image.pixels
Reply #8 - Mar 23rd, 2008, 3:19pm
 
I think a potential problem is that im.pixels=pixels doesn't quite do what you think it does.. that will make both the display pixels, and the images pixels point to the same array of data. So if you edit im.pixels, you're editing pixels too, as it doesn't *copy* the array, it just sets both pointing to the same array.

You need to actually copy the pixels array instead of just assigning one to the other.
Re: camera() call changes image.pixels
Reply #9 - Mar 24th, 2008, 1:19pm
 
JohnG,

How do I *copy* pixels, and not make the image's pixels point to the same array of data (as pixels does)?

.ben

Re: camera() call changes image.pixels
Reply #10 - Mar 24th, 2008, 2:40pm
 
You want arraycopy(pixels,0,img.pixels,0,pixels.length); I think, assuming that img.pixels is big enough.
Page Index Toggle Pages: 1