Home > cinder, cpp > Containers of pointers and native cinder types

Containers of pointers and native cinder types

A very simple example on that topic using cinder.


#include “cinder/app/AppBasic.h”
#include “cinder/gl/gl.h”
#include “cinder/Rand.h”
#include

using namespace ci;
using namespace ci::app;
using namespace std;

static const int total= 10;
class Pointer2NativeApp : public AppBasic {
public:
void setup();
void mouseDown( MouseEvent event );
void update();
void draw();

protected:
int x,y;
int* px;
int* py;
vector mXFloats;
vector mYFloats;
vector mV2;
vector mV3;
typedef vector::iterator fIter;
typedef vector::iterator v2Iter;
};

void Pointer2NativeApp::setup(){
x=100;
y=200;

//int xxx=x;
px=&x;
py=&y;

for(unsigned int i=0;i<total;i++){
float _x=Rand::randFloat(0.0f,(float)getWindowWidth());
float _y=Rand::randFloat(0.0f,(float)getWindowHeight());
mXFloats.push_back(new float(Rand::randFloat(0.0f,(float)getWindowWidth())));
mYFloats.push_back(new float(Rand::randFloat(0.0f,(float)getWindowHeight())));
mV2.push_back(new Vec2f(_x,_y));

}

for(unsigned int i=0;i<total;i++){
float _x=Rand::randFloat(0.0f,(float)getWindowWidth());
float _y=Rand::randFloat(0.0f,(float)getWindowHeight());
float _z=Rand::randFloat(-3.0f,3.0f);
mV3.push_back(new Vec3f(_x,_y,_z));
}

// for(unsigned int i=0;i<total;i++){
// cout<<*mXFloats[i]<<endl;
// }

gl::enableWireframe();
}

void Pointer2NativeApp::mouseDown( MouseEvent event )
{
}

void Pointer2NativeApp::update(){

}

void Pointer2NativeApp::draw()
{
// clear out the window with black
gl::clear( Color( 0, 0, 0 ) );

gl::color(ColorA(1.0f,0.9f,0.9f,0.2f));
//cout<<*px<<endl;
gl::drawStrokedCircle(Vec2f(*px,*py),100);

// for(v2Iter v=mV2.begin();v!=mV2.end();++v){
// }

for(unsigned int i=0;i<total;i++){
gl::drawSphere(*mV3[i],20);
gl::drawStrokedCircle(*mV2[i],20);
}
}

CINDER_APP_BASIC( Pointer2NativeApp, RendererGl )

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: