Archive

Archive for the ‘cpp’ Category

Cinder to touchdesigner # 2

note: I will migrate this blog to my webpage very soon thus having a proper display of the source code.

Next step on having a kind of template for porting OFW/Cinder patches into TD. So, I have the next class called ‘Lines’:


#pragma once
#include “TOP_CPlusPlusBase.h”

class Lines
{
public:
Lines();
~Lines();

virtual void draw(int _x1, int _y1, int _x2, int _y2);

int x1,x2,y1,y2;

};

the body of the class:

#include “Lines.h”

Lines::Lines(){
x1 = x2 = y2 = y1 = 0;
}

Lines::~Lines(){

}

void Lines::draw(int _x1, int _y1, int _x2, int _y2){

x1 = _x1;
y1 = _y1;
x2 = _x2;
y2 = _y2;

::glVertex2i(x1,y1);
::glVertex2i(x2,y2);
}

then i declare a vector on the Parent class:

std::vector mLines;

body:

for(unsigned int i=0;i<amount;i++){
//starting all the lines as 0 value
mLines.push_back(Lines());
}

and the calling the drawing method within the execution loop:

::glBegin(GL_LINES);
::glLineWidth(1.0f);

for(unsigned int i=0; i < amount; i++;
int _y1 = rand()% outputFormat->height;
int _x2 = rand()% outputFormat->width;
int _y2 = rand()% outputFormat->height;

mLines[i].draw(_x1, _y1, _x2, _y2);
}
::glEnd();

::glBegin(GL_LINE_LOOP);
::glVertex2i(0,0);
::glVertex2i(outputFormat -> width, outputFormat->height);
::glEnd();

next step might be to implement containers with pointers and shared pointers.

Categories: cpp, touchdesigner

Cinder to touchdesigner # 1

When I am about to start a project I always ask myself ‘spaghetti or code?’. Indeed, choosing the correct tool for the correct job/piece/toy is, from MHO, one of the most important steps of media design. However, I often find myself willing to have the benefits of one tool available into another. That has been the reason behind porting java and processing code into jitter as I can benefit a performing tool with data management resources( just to put an example). Of course working with such idea always provides interesting insights about the tools themselves, their possibilities and limitations. It also exposes the many things that I need to learn in order to implement my ideas. In other words, turns the world slightly upside down.
Today I managed to compile my first, very simple simple, TOP object for TouchDesigner. I need to admit that the most difficult past was not to deal with the internal logic of the c++ file but to compile it: TouchDesigner is only available for the windows system, meaning that I am learning how to do all this compilation management with Visual Studio c++. So far so good although I still use too many concepts from XCode in order to deal with the new IDE( which is probably not a good idea).
The TouchDesigner gl externals are quite straight forward. Basically you are calling gl commands ‘as they are’. So for a cluster of lines you would do something like this:

::glBegin(GL_LINES);
::glLineWidth(1.0f);
for(unsigned int i=0; i<amount;i++);
int x1 = rand()% outputFormat->width;
int y1 = rand()% outputFormat->height;
int x2 = rand()% outputFormat->width;
int y2 = rand()% outputFormat->height;
::glVertex2i(x1 ,y1);
::glVertex2i(x2, y2);
}
::glEnd();

pretty direct, right?

So now to plan the proper way to port my Cinder and OFW apps into TouchDesigner. Let’s see how it goes…

Categories: cinder, cpp, touchdesigner

Containers of pointers and native cinder types

January 20, 2011 Leave a comment

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 )

Categories: cinder, cpp

Garden of geometries

December 6, 2010 Leave a comment

Past month I finished a really nice project called ‘Electric Gardens’ with the trio ‘Electronic Hammer’:

http://www.electronichammer.com/main/index.php;

One of the premises of the project was to design an interactive system that would react to the gestures of the performers, either as audio analysis or data coming from their computers/instruments. As a result I designed a system that would keep me occupied for a while as it presents a lot of possibilities.
I designed most of the piece thinking in ‘scenes’ hosted on a system that would allow fast and simple transitions. The image is a kind of ‘modular cinema’ where each one of the parts could have their own visual ‘world’ encapsulated.
In terms of technique, I designed most of the piece using glsl shaders and lots of java classes for deforming and handling the geometries. Many of the materials were sketched using code tools( basically Cinder) and then ported to jitter, which has a more ‘performing’ profile and has a range of friendly facilities for MIDI and audio analysis. Some of the shaders( those of light models) are ports of hlsl shaders.

specular sound

specular sound

specular sound

Categories: code, cpp, jitter, openGL, shaders

How to be baroque with pointers

December 6, 2010 Leave a comment

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!

Categories: cinder, cpp