LoginSignup
23
24

More than 5 years have passed since last update.

oFを書くためのc++メモ

Last updated at Posted at 2016-08-18

クソ初心者がメモしてゆきます。
0.9.3で確認してます。

ofApp.cpp

  • まず最初に処理を書くクラス
  • ofBaseApp を継承している
  • 便利メソッドがあらかじめ定義されてる
  • setup() 初期化
  • update() // 毎フレーム更新
  • draw() //毎フレーム更新, updateの後に呼ばれる。

ログを出す

ofLog(OF_LOG_NOTICE, ofToString(10));
ofLogNotice() << "hoge" << 10;//hoge10

参考:変数の値を見る
http://openframeworks.cc/ja/learning/01_basics/how_to_view_value/

for文

//for文で画面中心を始点にし、画面上にランダムな線を書く。
for(int i=0;i<1000;i++){     
    ofDrawLine(
       ofGetWidth()/2,
       ofGetHeight()/2,
        ofGetWidth() * ofRandom(0, 1),//ofGetWidth() で画面幅
        ofGetHeight()* ofRandom(0, 1)//ofGetHeight() で画面高
    );
}

配列

静的と動的なのがある。

/**静的配列**/
int ary[4] = {1,2,3,4};
/**動的配列**/
vector<int> ary;//定義
ary.push_back(3);//push
ary.push_back(2);//push
ary.push_back(1);//push
//size()でlength
for(int i=0;i<ary.size();i++){
    ofLogNotice() << ofToString(ary[i]);
}
ary.clear();//データがクリアされる?

乱数

float r1 = ofRandomf();//return between -1 and 1 
float r2 = ofRandom(startVal,endVal);

定数

ヘッダファイルにこんな感じで定義

#define HOST "localhost" // 受信側のIPアドレス
#define PORT 6666 // 受信側のポート番号

演算子・記号

見慣れないやつが多々ある・・。

std::find(); //std名前空間のfindを呼び出し
Test::hoge(); //Testクラスのスタティックなメソッド呼び出しhoge()
p->append("hello");//ポインタを経由して変数へアクセス
ofLogNotice() << "hoge" << 100;//log に hoge100 と表示。左シフト演算子

参考 : http://d.hatena.ne.jp/gununu/20131012/1381578689

math関係

math.h

sin(M_PI);//M_PI==3.14..
abs(-10);
ceil(3.14);
floor(3.14);
round(3.14);
max(0,10);
fmod(3.14,1);//==0.14 余剰の計算
//などなど・・

参考 : http://www.c-tipsref.com/reference/math.html

インスタンス化について

スタティックなメソッド

test.h
class test {
public:
   static void hogehoge();//static method
};
tect.cpp
#include "test.h"
#include "ofApp.h"

void test::hogehoge(){
    ofLogNotice() << "hoge";
    //test::hogehoge(); のように呼び出す。
}

継承する

スーパークラスのメソッドにvirtual をつけるらしい。

シングルトン

ポインタについて

addon memo

addon解説

optical flowを使う

OSCを使う

osc アドオンがデフォで入っている。Unityと通信するときは以下を注意。
Unity x oFの注意点
http://qiita.com/yohki/items/496d9ad345fdd1c9b779

websocket を使う

datguiを使う

kinect2 を使う

OpenCV

json

資料

おまけ:xcodeのショートカット

  • Cmd + R ビルドしてラン
  • Cmd + . ラン終了
  • Cmd + Q シミュレータ終了
  • Cmd + Shift + K クリーン。
  • Ctrl + Space コードヒントを表示する
23
24
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
23
24