Home > cinder, cpp > How to be baroque with pointers

How to be baroque with pointers

I did a small experiment in Cinder using STL and pointers. Instead of creating a big array of objects I created a series of pointers to values:

vector<float*> x

vector<float*> y

then I generated some values for the container:

for(int i=0;i<NR_OF_DOTS_TO_STORE;i++){

float* _nx=new float(Rand::randFloat(wSize));

float* _ny=new float(Rand::randFloat(hSize));

x.push_back(_nx);

y.push_back(_ny);

}

the destructor would look like:

Particle::~Particle(){

xIter xVariable=x.begin();

while(xVariable!=x.end()){

delete(*xVariable);

++xVariable;

}

yIter yVariable=y.begin();

while(yVariable!=y.end()){

delete(*yVariable);

++yVariable;

}

}

funny enough I finished casting them because the Cinder types don’t accept pointers directly. So, instead of doing something like this at the moment of using the data:

gl::drawLine(Vec2f(x[i],y[i]),Vec2f(x[i+1],y[i+1]));

I finished with something like this:

glBegin(GL_LINES);

glVertex2f(reinterpret_cast<float>(x[i]),reinterpret_cast<float>(y[i]));

glVertex2f(x[i+1],y[i+1]);

glEnd();

in conclusion, a rather impractical way of doing things!

Advertisements
Categories: cinder, cpp
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: