I’m working on a project using the MovieGrabber example as a basis for my work. For my purposes I changed testApp.cpp to update an pixels array with grayscale pixels for the image…
pixels = vidGrabber.getPixels();
grayImage.setFromPixels(pixels, camWidth, camHeight, OF_IMAGE_COLOR, true);
pixels = grayImage.getPixels();
The next step in my code is to update all particles in a simple particle system I’ve written. Each particle is an instance of a separate class, born of a separate header file from testApp.h.
Question is… how do I give those particles access to the pixels array which is inside the testApp class???
I need to do this because I want the particles to behave differently based on the luminance of the pixel they are positioned above.
Any help would be greatly appreciated, I’m converting this app from Processing and I’m missing vital knowledge about passing data between objects in C++
i hope i understand you right but i think you have to iterate over every pixel and pass the value of the pixel to an method from your particle.
something like this
You’ve inspired a different approach - rather than have particles read from a variable in the testApp class - I’m going to have the testApp class get the x and y locations for each particle, find the luminance of that location in the pixels array and then send it to the particle as it updates.
Only trouble is this…
Say (for example) my particle is at point(860, 640) in my display area (which is 960*720). How to I access that specific point in the pixels array, considering I’ve executed getPixels() on a grayscale image???
I’ve read this post… but it deals with RGB values… http://forum.openframeworks.cc/t/learning-from-app-examples/2778/3
in a grayscale image every pixel has just one channel, so just one value. that means:
pixel = first pixel in the first line
pixel = second pixel in the first line
pixel = last pixel in the first line
pixel = first pixel in the second line
pixel = second pixel in the second line
the number 960 depends on your size of the picture.
so you can get your pixel with a little math
i = (y * pixelperline) + x
in your case:
i = (640 * 960) + 860
hope this is correct. totally untested!
I was *nearly* there - your pseudocode delivered!
Really, really impressed with OF’s performance - unbelievable!