<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>tag:www.local-guru.net,2005:/blog/tag/cpp</id>
  <link type="text/html" href="http://www.local-guru.net" rel="alternate"/>
  <link type="application/atom+xml" href="http://www.local-guru.net/blog/tag/cpp.atom" rel="self"/>
  <title>GuruBlog : Articles about cpp</title>
  <subtitle>local-guru.net</subtitle>
  <updated>2009-04-06T06:47:00+02:00</updated>
  <generator>GuruBlog engine</generator>
  <entry>
    <id>tag:www.local-guru.net,2005:Article/147</id>
    <published>2009-04-06T06:47:00+02:00</published>
    <updated>2009-04-06T06:47:00+02:00</updated>
    <link type="text/html" href="http://www.local-guru.net//blog/2009/4/6/feeling-watched-in-openframeworks" rel="alternate"/>
    <author>
      <name>Nikolaus Gradwohl</name>
    </author>
    <title type="html">feeling watched in openframeworks</title>
    <category term="openframeworks" scheme="http://www.local-guru.net/blog/tag/openframeworks"/>
    <category term="cpp" scheme="http://www.local-guru.net/blog/tag/cpp"/>
    <content type="html">&lt;p&gt;I wrote another little app in &lt;a href="http://www.openframeworks.cc"&gt;openframeworks&lt;/a&gt; today to test of006 which came out a couple of days ago.&lt;/p&gt;

&lt;p&gt;i always liked those little xeyes apps (and all its windows, mac, whatever clones) so i took it
to the extrem and made a LOT of them - feel beeing watched :-)&lt;/p&gt;

&lt;p&gt;&lt;img src="http://www.local-guru.net/img/guru/eyes_sc.png" alt="eyes" /&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <id>tag:www.local-guru.net,2005:Article/130</id>
    <published>2009-03-06T04:21:00+01:00</published>
    <updated>2009-03-06T04:21:00+01:00</updated>
    <link type="text/html" href="http://www.local-guru.net//blog/2009/3/6/osc-app-using-openframeworks" rel="alternate"/>
    <author>
      <name>Nikolaus Gradwohl</name>
    </author>
    <title type="html">osc app using openframeworks</title>
    <category term="osc" scheme="http://www.local-guru.net/blog/tag/osc"/>
    <category term="openframeworks" scheme="http://www.local-guru.net/blog/tag/openframeworks"/>
    <category term="cpp" scheme="http://www.local-guru.net/blog/tag/cpp"/>
    <content type="html">&lt;p&gt;I have written a little demo app in &lt;a href="http://www.openframeworks.cc"&gt;openframeworks&lt;/a&gt; that shows how to react to
osc events. Openframeworks uses &lt;a href="http://frey.co.nz/projects/ofxosc/"&gt;ofxOsc&lt;/a&gt; as OSC library, which comes
preinstalled in the FAT distribution.&lt;/p&gt;

&lt;p&gt;the programm shows a square on a black background. the gray level of the square can be adjusted
by sending osc messages to port 1234.&lt;/p&gt;

&lt;p&gt;the following little ruby program sets the color to #808080&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;require 'osc'
msg = OSC::Message.new("/color", "i", 128 )
c = OSC::UDPSocket.new
c.send( msg, 0, "localhost", 1234 )
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;in the 'setup' method a osc receiver is initalized, and in the 'update' method, the messages
are fetched from a queue and parsed.&lt;/p&gt;

&lt;p&gt;I didn't generate any real complex osc messages for now, but as far as i can tell it
is a very nice osc framework.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <id>tag:www.local-guru.net,2005:Article/79</id>
    <published>2008-10-12T20:40:00+02:00</published>
    <updated>2008-10-12T20:40:00+02:00</updated>
    <link type="text/html" href="http://www.local-guru.net//blog/2008/10/12/slr-controlling-via-computer" rel="alternate"/>
    <author>
      <name>Nikolaus Gradwohl</name>
    </author>
    <title type="html">SLR controlling via computer</title>
    <category term="cpp" scheme="http://www.local-guru.net/blog/tag/cpp"/>
    <category term="D40x" scheme="http://www.local-guru.net/blog/tag/d40x"/>
    <category term="Nikon" scheme="http://www.local-guru.net/blog/tag/nikon"/>
    <category term="SLR" scheme="http://www.local-guru.net/blog/tag/slr"/>
    <category term="gphoto2" scheme="http://www.local-guru.net/blog/tag/gphoto2"/>
    <content type="html">&lt;p&gt;Today i managed to shoot photos and download them in one step
using a little c++ programm. the camera must be set to the MTP/PTP-Mode for this to
work. The programm below uses the &lt;a href="http://www.gphoto.org/"&gt;libgphoto2-API&lt;/a&gt; to control the camera and
send it a capture command followed by a download command. the library is realy nice to code with, but very badly documented.&lt;/p&gt;
</content>
  </entry>
  <entry>
    <id>tag:www.local-guru.net,2005:Article/76</id>
    <published>2008-10-09T20:49:00+02:00</published>
    <updated>2008-10-09T20:49:00+02:00</updated>
    <link type="text/html" href="http://www.local-guru.net//blog/2008/10/9/nds-line-demo" rel="alternate"/>
    <author>
      <name>Nikolaus Gradwohl</name>
    </author>
    <title type="html">nds line-demo</title>
    <category term="nintendo" scheme="http://www.local-guru.net/blog/tag/nintendo"/>
    <category term="cpp" scheme="http://www.local-guru.net/blog/tag/cpp"/>
    <category term="DS" scheme="http://www.local-guru.net/blog/tag/ds"/>
    <content type="html">&lt;p&gt;Since my first demo for the Nintendo DS used the bresenham circle algorith, i had
to write another starring its famouse brother - the bresenhaml line-algorithm.
Which is a bit trickier than it seems when you first look at it. it took me 4 tries
to make it work in all quadrants.&lt;/p&gt;

&lt;p&gt;For those of you who don't own a nds i included a screenshot this time made
using a emulator. imagine the upper part of the screenshot beeing displayed on
the upper screen of the DS.&lt;/p&gt;

&lt;p&gt;&lt;img src="http://www.local-guru.net/img/guru/nds-linedemo.png" alt="linedemo" /&gt;&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#include &amp;lt;nds.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;unistd.h&amp;gt;

void setPixel( int x, int y, int color ) {
    VRAM_A[x + y * 256] = color;
}

void line( int x1, int y1, int x2, int y2, int c ) {
    bool swap = abs( y2 - y1 ) &amp;gt; abs ( x2 - x1 );
    int x1t =  swap ? y1 : x1;
    int y1t =  swap ? x1 : y1;
    int x2t =  swap ? y2 : x2;
    int y2t =  swap ? x2 : y2;

    int xs =  x1t &amp;lt; x2t ? x1t : x2t;
    int ys =  x1t &amp;lt; x2t ? y1t : y2t;
    int xt =  x1t &amp;lt; x2t ? x2t : x1t;
    int yt =  x1t &amp;lt; x2t ? y2t : y1t;

    int dx = xt - xs;
    int dy = abs(yt - ys);

    int dT = 2 * ( dy - dx );
    int dS = 2 * dy;
    int d = 2 * dy - dx;
    int x = xs;
    int y = ys;

    if ( swap )  {
        setPixel( y, x, c );
    } else {
        setPixel( x, y, c );
    }

    while ( x &amp;lt; xt ) {
        x++;
        if ( d &amp;lt; 0 ) {
            d = d + dS;
        } else {
            if ( ys &amp;lt; yt ) {
                y++;
            } else {
                y--;
            }
            d = d + dT;
        }
        if ( swap )  {
            setPixel( y, x, c );
        } else {
            setPixel( x, y, c );
        }
    }
}

int main(void) {
    touchPosition touch;
    // set lower screen to FB
    videoSetMode(MODE_FB0);
    vramSetBankA(VRAM_A_LCD);

    // set upper stcreen to textmode
    videoSetModeSub(MODE_0_2D | DISPLAY_BG0_ACTIVE);
    vramSetBankC(VRAM_C_SUB_BG);
    SUB_BG0_CR = BG_MAP_BASE(31);
    BG_PALETTE_SUB[255] = RGB15(31,31,31);
    consoleInitDefault((u16*)SCREEN_BASE_BLOCK_SUB(31), (u16*)CHAR_BASE_BLOCK_SUB(0), 16);

    iprintf("coded by guru
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;");&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    // make sure main screen is on bottom
    lcdMainOnBottom();

    while(1) {
        scanKeys();

        if(keysHeld() &amp;amp; KEY_TOUCH) {
            touch=touchReadXY();
            line( 128, 96, touch.px, touch.py, RGB15( 
                31 * abs(touch.px - 128) / 128, 
                31 * abs(touch.py-96) / 96,
                0
            ));
        }

        // clear screen if key A is pressed
        if (keysHeld() &amp;amp; KEY_A) {
            for ( int y = 0; y &amp;lt; 192; y ++ ) {
                for ( int x = 0; x &amp;lt; 256; x ++ ) {
                    setPixel( x, y, 0);
                }
            }
        }
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <id>tag:www.local-guru.net,2005:Article/70</id>
    <published>2008-09-29T19:17:00+02:00</published>
    <updated>2008-09-29T19:17:00+02:00</updated>
    <link type="text/html" href="http://www.local-guru.net//blog/2008/9/29/rotating-box-in-openframeworks" rel="alternate"/>
    <author>
      <name>Nikolaus Gradwohl</name>
    </author>
    <title type="html">rotating box in openframeworks</title>
    <category term="openframeworks" scheme="http://www.local-guru.net/blog/tag/openframeworks"/>
    <category term="cpp" scheme="http://www.local-guru.net/blog/tag/cpp"/>
    <content type="html">&lt;p&gt;I tried to write something simmilar to my &lt;a href="http://www.local-guru.net/blog/articles/2008/09/06/rotating-neonbox"&gt;neonbox-demo&lt;/a&gt;
in openframeworks. At first a have been a bit puzzled because there is no rotate command.&lt;/p&gt;

&lt;p&gt;Then i remembered that openframeworks uses OpenGL for drawing so glRotatef and
glTranslatef can be used for rotating the image&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;    ...
int ang = 0;

void testApp::setup(){
    ofSetVerticalSync( true );
    ofSetFrameRate( 25 );
}

void testApp::draw(){
    int width = ofGetWidth() / 2;
    int height = ofGetHeight() / 2;

    ofBackground( 0,0,0 );
    glPushMatrix();
    glTranslatef( width, height, 0 );
    glRotatef( ang , 0, 0, 1);

    ang++;
    if (ang == 360) {
        ang = 0;
    }

    ofFill();
    ofSetColor( 255 * ( 1 + sin( ang * 2 * PI / 360 )) / 2, 
        255 * ( 1 + sin( PI + ang * 2 * PI / 360 )) / 2, 0 );

    ofRect(  -300,  -50, 100, 100 );
    ofRect(  -100,  -100, 200, 200 );
    ofRect(  200,  -50, 100, 100 );


    glPopMatrix();
}
    ...
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;This time i also made a little screenshot for those who don't have openframeworks installed (yet :-) )&lt;/p&gt;

&lt;p&gt;&lt;img src="http://www.local-guru.net/img/guru/rotate-of-screenshot.png" alt="screenshot" /&gt;&lt;/p&gt;
</content>
  </entry>
  <entry>
    <id>tag:www.local-guru.net,2005:Article/61</id>
    <published>2008-08-11T07:13:00+02:00</published>
    <updated>2008-08-11T07:13:00+02:00</updated>
    <link type="text/html" href="http://www.local-guru.net//blog/2008/8/11/first-nds-demo" rel="alternate"/>
    <author>
      <name>Nikolaus Gradwohl</name>
    </author>
    <title type="html">first nds demo</title>
    <category term="nintendo" scheme="http://www.local-guru.net/blog/tag/nintendo"/>
    <category term="cpp" scheme="http://www.local-guru.net/blog/tag/cpp"/>
    <category term="DS" scheme="http://www.local-guru.net/blog/tag/ds"/>
    <content type="html">&lt;p&gt;I got a nintendo DS 2 weeks ago and have hacked my first demo
using the arm compilers from &lt;a href="http://www.devkitpro.org/"&gt;devkitPro&lt;/a&gt;. To
compile the code follow the &lt;a href="http://www.drunkencoders.com/"&gt;drunkencoders-Tutorial&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;the program initializes the lower screen in a 2d graphics mode, and draws a circle (using the bresenham-algorithm for circles)
wherever the screen is touched by the stylus. if the A button is pressed the screen is cleared. No sophisticated doublebuffering, 3d or
sound stuff this time - but hey! it's the first program for a nds! and it works! :-)&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#include &amp;lt;nds.h&amp;gt;
#include &amp;lt;stdio.h&amp;gt;
#include &amp;lt;stdlib.h&amp;gt;
#include &amp;lt;unistd.h&amp;gt;

void setPixel( int x, int y, int color ) {
    VRAM_A[x + y * 256] = color;
}

void circle( int mx, int my, int r, int color ) {
    int x = 0;
    int y = r;
    int d = 3 - 2 * r;

    while (x &amp;lt;= y) {
        setPixel( mx  + x, my + y, color );
        setPixel( mx  - x, my + y, color );
        setPixel( mx  - x, my - y, color );
        setPixel( mx  + x, my - y, color );
        setPixel( mx  + y, my + x, color );
        setPixel( mx  - y, my + x, color );
        setPixel( mx  - y, my - x, color );
        setPixel( mx  + y, my - x, color );

        if (d &amp;lt; 0) {
            d = d + 4 * x + 6;
        } else {
            d = d + 4 * ( x - y ) + 10;
            y --;
        }
        x++;
    }
}

int main(void) {
    touchPosition touch;

    videoSetMode(MODE_FB0);
    vramSetBankA(VRAM_A_LCD);

    lcdMainOnBottom();

    while(1) {
        scanKeys();

        if(keysHeld() &amp;amp; KEY_TOUCH) {
            touch=touchReadXY();
            circle( touch.px, touch.py, 20, rand());
        }

        if (keysHeld() &amp;amp; KEY_A) {
            for ( int y = 0; y &amp;lt; 192; y ++ ) {
                for ( int x = 0; x &amp;lt; 256; x ++ ) {
                    setPixel( x, y, 0);
                }
            }
        }
    }
    return 0;
}
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
  <entry>
    <id>tag:www.local-guru.net,2005:Article/56</id>
    <published>2008-07-20T20:02:00+02:00</published>
    <updated>2008-07-20T20:02:00+02:00</updated>
    <link type="text/html" href="http://www.local-guru.net//blog/2008/7/20/openframeworks-demo" rel="alternate"/>
    <author>
      <name>Nikolaus Gradwohl</name>
    </author>
    <title type="html">OpenFrameworks Demo</title>
    <category term="openframeworks" scheme="http://www.local-guru.net/blog/tag/openframeworks"/>
    <category term="cpp" scheme="http://www.local-guru.net/blog/tag/cpp"/>
    <content type="html">&lt;p&gt;this weekend i have written a little c++ program with &lt;a href="http://www.openframeworks.cc"&gt;openframeworks&lt;/a&gt;. This
is a framework for writing creative programs. it is heavily inspired by
processing.&lt;/p&gt;

&lt;p&gt;While still in the prerelease state it has some very interesting features
and it is realy fun to code with. To get to the download page one has
to register for the mailinglist.&lt;/p&gt;

&lt;p&gt;To get started copy the emptyExample folder from the apps/examples
folder. in the src folder is a empty testApp.cpp and a testApp.h.&lt;/p&gt;

&lt;p&gt;the program i have written draws little yellow squares on the screen, that get scared when
they hear a sudden loud noise.&lt;/p&gt;

&lt;p&gt;my testApp.h looks like this&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#ifndef _TEST_APP
#define _TEST_APP


#include "ofMain.h"
#include "ofAddons.h"

class testApp : public ofSimpleApp{

    public:

        void setup();
        void update();
        void draw();

        void keyPressed(int key);
        void keyReleased(int key);
        void mouseMoved(int x, int y );
        void mouseDragged(int x, int y, int button);
        void mousePressed(int x, int y, int button);
        void mouseReleased();
        void audioReceived( float *input, int bufferSize, int nChannels );

        int boom;
};

#endif
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;my testApp.cpp looks like this&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;#include "testApp.h"
//--------------------------------------------------------------
void testApp::setup(){
    boom = 0;
    ofSetVerticalSync( true );
    ofSetFrameRate( 25 );
    ofSoundStreamSetup(0,1,this);
}   

//--------------------------------------------------------------
void testApp::update(){
}
//--------------------------------------------------------------
void testApp::draw(){
    ofBackground( 0,0,0 );
    int sx = 0;
    int sy = 0;
    if (boom&amp;gt;0) {
        ofSetColor(255,0,0);
        boom = boom -2;
    } else {
        ofSetColor(255,255,0);
    }
    ofFill();
    for ( int x=0; x &amp;lt; 11; x++ ) {
        for ( int y = 0; y &amp;lt; 7; y++ ) {
            if ( boom &amp;gt; 0 ) {
                sx = 10 * ofRandomf();
                sy = 10 * ofRandomf();
            }
            ofRect(sx + x*120 + 20, sy + y*120 + 20, 100, 100);
        }
    }
}

//--------------------------------------------------------------
void testApp::keyPressed  (int key){ 
}

//--------------------------------------------------------------
void testApp::keyReleased  (int key){ 
}

//--------------------------------------------------------------
void testApp::mouseMoved(int x, int y ){
}

//--------------------------------------------------------------
void testApp::mouseDragged(int x, int y, int button){
}

//--------------------------------------------------------------
void testApp::mousePressed(int x, int y, int button){
}

//--------------------------------------------------------------
void testApp::mouseReleased(){
}

void testApp::audioReceived (float * input, int bufferSize, int nChannels) {
    int count = 0;
    for( int i=0; i&amp;lt;bufferSize; i++ ) {
        if (input[i] &amp;gt; 0.3 || input[i] &amp;lt; -0.3 ) {
            count++;
        } 
    }
    if ( count &amp;gt; 10 ) {
        boom = 25;
    }
}
&lt;/code&gt;&lt;/pre&gt;
</content>
  </entry>
</feed>

