How to trace something in C++

Coming from an Actionscript background, i’ve become accustomed to being able to at will at any given point
tracing an object, or a value. It’s something i actually took for granted.

When I started using Cinder ( http://libcinder.org ) – and in the process doing C++. A language
at the time I had only barely used – but now i love. I realized that – trace, or speaking to my PHP background
printf is something that is not actually built in at all.

It’s something you have to turn into a c_string, which is basically a char* as i understand it.
Devnote: What is a Char* – it’s a pointer to the first character in a string of character, whose ASCI values ( 0 – 255 ) are mapped to strings.

So,
How do you trace a value in C++, be it an interger, string, float, double, or class?

In C++ ( and C? ) – it’s not as straigh forward, but fortunately we have something called operators.
An operator, is actualyl something you’re very accustomed to, such as:

+
-
*
/

Those are actually operators, and what does that mean? Well it means you can define one and when you’re
Type, comes across it it will run this function. We’ll get into it another time, cus its a great topic, but…
What that means right now, is that we can define a “<<" operator, so we can turn out data into a C-String with the relavent info. So we can say:
friend std::ostream& operator<<( std::ostream& lhs, const Vec2& rhs )
{
lhs << "[" << rhs.x << "," << rhs.y << "]"; return lhs; }

Which will make our console function return useful info.
For example:

console << Vec2f(10.0f, 11.1f) << std::endl;

One thing to note is that std::endl, what the heck is that?
It just means go into the STD namespace ( or package if you wanna use a different term )
and grab the "endl" constant... put that there.

Also - for POD ( Plain Old Data ) - we can call a toString function such as

template inline std::string toString (const T& t)
{
std::stringstream ss;
ss << t; return ss.str(); }

Which can be used as:

float pie = 3.1415
Console() << toString( pie ) << std::endl;

And that's how you get values out into the console in C++ / Cinder.

Shipping data visualization

I was tasked with the idea of creating some proof-of-concept (I notice i do a lot of those, imo they’re the most fun part of the project) data-visualizations involving the movement of objects on an international scale. You can obviously tell i’m trying to give out as few specific details as possible that could get me into trouble, so sorry for being so seemingly mysterious.

The first concept I had was to take the data, and use various classic key elements of infographics to denote and show at a glance the voluminous information displayed. One of the problems I came across was that I basically had more data than my computer could handle, so I had to truncate it, but that left me with information that heavily favored specific ports. In the end I used Perlin Noise to generate realistic feeling randomness to these proof-of-concepts.

(Sorry. Again, cant get into specifics, but this might be as close as this project gets to getting made so i thought i’d share.)
The key is as follows:
X axis represents something
Y axis represents a different value Logarithmicly scaled
Size is controlled by weight
Color is controlled by destination country


Continue reading Shipping data visualization

Gravity Swarm for ipad

GravitySwarm is an application I’m creating for the ipad.

It’s a gravity swarm simulation, you create gravitational forces with your fingers and watch how the swarm interacts.
The swarm moves via low-octave perlin noise combined with proximity attraction.

I created it using Cinder which I’ve been using a lot lately and its really tons of fun.

Gravity Swarm from mario gonzalez on Vimeo.

Hello world!

My name is Mario Gonzalez
I am a programmer in New York City.

I’m currently a Senior Application Developer at Ogilvy & Mather NYC.

I love making things.
Especially making visual things.
Even more especially making visual interactive things.

I have created applications on or in:
Web (Actionscript 3.0 / Php-Mysql / html-css-javascript)
iPhone (Objective-C / C++ / OpenGL-ES)
OSX (C++ / OpenGL)