Show same image many times

TL:DR See the image

Hey all
To give you a bit of background, I’m a 21 year old college student on my second year.
This is my first semester doing C++, and my only other “coding” experience is Action Script 3.0.
I’m doing a group project with a touch table - sort of like Microsoft Surface.
We are using oF version 0061 FAT.

I’m trying to solve a problem that could be done with a hell of a lot of code repetition, but I refuse to resolve to the slavery solution :wink:

I hope the attached image can explain my problem but here it is:

I want to load/draw 7 (eventually more) different images, and there needs to be drawn a specific number of copies of each image, placed in order.

That alone poses a problem to me as I don’t know exactly how to do this

I think that could be done like such:

  
for(int i = 0; i < 5; i++) {  
Projector.imageA.draw(500 + i * 10 ,500);  
}  
  

The real problem is that I need to be able to move each image around individually!

I see no other solution than somehow dynamically name each loaded image, in ways I don’t think is possible.

I am working on a multidimensional integer array that will hold the type of image as a number 1-7 and x and y positions.

  
int array[3][total_number_of_images]  

“All” there is left to do is to read the array one integer at a time, create/load/draw an image there from and assign coordinates. My idea is that later on the coordinates for these images can be manipulated, i.e. moved around on screen. Using the same array.

Hello Beermaster;

My english is not really good but I hope it could help.
Do you know how to work with objects? and pointers?

I think one easy way it could be making a basic object that holds to int variables x and y and the ofImage.
If you know how to deal with pointers you can populate a Vector of that object loading to them a pointer to a ofImage like A or B

Here I have an example http://www.patriciogonzalezvivo.com/blog/?p=5

The objects are the particles
And the xParticles is the Class that handle the vector of objets(particles)

Look how seting a default ofImage in the particle handler (xParticle) set the image on the particles

xParticle.h

  
ofImage			*img;  
void				setImg(ofImage *nImg)	{ img = nImg; };    

xParticle.cpp

  
void xParticle::addParticle(Vec2f l){  
	particle p = particle(l);  
	if (img != NULL) p.setImg(img);  
	particles.push_back(p);  
}  

Particle.h

  
ofImage		* img;  
void		setImg(ofImage *nImg)	{ img = nImg; };  

So in your case you could have you could create a class call object with something like

  
class object{  
public:  
	object();  
	  
	object(int _x, int _y);  
	int x, y;  
  
	ofImage		* img;  
	void		setImg(ofImage *nImg)	{ img = nImg; };  
  
        bool     checkIfOver(int _x, int _y);  // here it checks if the mouse or some TUIO cursor is over the image  
          
        void draw(); // here draws the image  
}  
  

Then on your appTest some thing like

  
#include "object.h"  
  
class testApp : public ofBaseApp{  
public:  
	vector<object>  objects  
        ofImage A;  
        ofImage B;  
  
       void addObject(int _x, int _y, ofImage _img);      
       ....  
       ....  
}  

Then on the .cpp something like

  
void testApp::setup(){  
    A = loadImage....  
    B = loadImage....  
  
    for (int i = 0; i < 7; i++){   
       addObject(random,random,A);  
   }  
  
   for (int i = 0; i < 7; i++){   
       addObject(random,random,B);  
   }  
}  
  
void testApp::draw(){  
    for (int i = 0; i < objects.size(); i++){   
       objects[i].draw();;  
   }  
}  
  
void testApp::addObject(int _x, int _y, ofImage _img){  
        object o = object(_x,_y);  
	if (img != NULL) o.setImg(img);  
	objects.push_back(o);  
}  

I hope this is understandable and right

Thank you very much for the reply :slight_smile: I have been working to implement your suggested code into ours.
One thing that is not working, and not easy to understand is how the following works:

  
ofImage      * img;  

It’s not something the compiler accepts. I’m using Code::blocks by the way.
I will be looking closer at your source code to see if I might have forgotten to #include something…

Edit:
Some searching online shows that there is nothing odd about declaring a class as a pointer. I will just have to figure out why the program does not accept it.

I guess I should add that our lecturer decided we don’t need to learn about Classes at this moment, and so I have no real knowledge about it, though it is in my book. That could be the reason I get the error above.

I have also encountered another problem as shown here:

  
 object o = object(_x, _y);  
  
        if (img != NULL) //this line is giving the error  
        {  
        o.setImg(img);  

examples\_mea3_project\src\testApp.cpp|286|error: no match for ‘operator!=’ in ‘((testApp*)this)->testApp::img != 0’|