Más contenido relacionado La actualidad más candente (20) Similar a デジタルアートセミナー#2 openFrameworksで学ぶ、 クリエイティブ・コーディング Session 2: 構造をつくる (20) Más de Atsushi Tadokoro (20) デジタルアートセミナー#2 openFrameworksで学ぶ、 クリエイティブ・コーディング Session 2: 構造をつくる7. #include "testApp.h"
void testApp::setup(){
// 画面基本設定
ofSetFrameRate(60);
ofBackground(63);
ofSetCircleResolution(32);
}
void testApp::update(){
}
void testApp::draw(){
// ランダムな場所に半径40pxの円を描く
ofCircle(ofRandom(ofGetWidth()), ofRandom(ofGetHeight()), 40);
}
... 後略
Q1: 乱数について
‣ よくある間違い - testApp.cpp
‣ どうなるか、実験してみる
9. Q1: 乱数について - 解答
‣ setup() であらかじめランダムな座標を生成しておく
‣ 生成した座標は、グローバルな変数に格納 (testApp.hに)
‣ その変数の値を参照して、draw() で円を描く
11. #include "testApp.h"
void testApp::setup(){
// 画面基本設定
ofSetFrameRate(60);
ofBackground(63);
ofSetCircleResolution(32);
// 画面内のランダムな場所を指定
posX = ofRandom(ofGetWidth());
posY = ofRandom(ofGetHeight());
}
...
void testApp::draw(){
// 設定した場所に円を描く
ofSetHexColor(0x3399cc);
ofCircle(posX, posY, 20);
}
...
Q1: 乱数について - 解答
‣ testApp.cpp
15. Q2: たくさんの図形をランダムな場所に描く
‣ ヒント 1: 配列 - たくさんの値を保存する
‣ 例えば、100個のposXを保存するための「箱」は以下のように
したら準備できる
‣ この箱には、[] で囲まれた部分に連番でナンバリングされる
‣ この仕組みで、100個の、posXとposYが確保できる
float posX[100];
posX[0]
posX[1]
posX[2]
...
posX[99]
← 0から開始する
← 0∼99までで100個ぶん
16. Q2: たくさんの図形をランダムな場所に描く
‣ ヒント 2: くりかえし
‣ for文を使用する
‣ 例えば、0∼99の100回くりかえす構文
‣ カウンタ変数 i を賢く利用する
for (int i = 0; i < 100; i++) {
《処理の内容》
}
for (int i = 0; i < 100; i++) {
posX[i] = ????;
posY[i] = ????;
}
18. #pragma once
#include "ofMain.h"
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
...
// 位置の配列を生成
float posX[100];
float posY[100];
};
Q2: 解答
‣ testApp.h
19. #include "testApp.h"
void testApp::setup(){
// 画面基本設定
ofSetFrameRate(60);
ofBackground(63);
ofSetCircleResolution(32);
// 画面内のランダムな場所を円の数だけ指定
for (int i = 0; i < 100; i++) {
posX[i] = ofRandom(ofGetWidth());
posY[i] = ofRandom(ofGetHeight());
}
}
...
void testApp::draw(){
ofSetHexColor(0x3399cc);
// 画面内のランダムな場所を円の数だけ描画
for (int i = 0; i < 100; i++) {
ofCircle(posX[i], posY[i], 20);
}
}
Q2: 解答
‣ testApp.cpp
21. Q2: 解答
‣ 参考:
‣ 数を変更したい場合、いろいろ修正箇所あり
‣ 1箇所だけを変更すると、数がすぐに変更できるようにしたい!
‣ testApp.hに、クラスの定数(const)として数を指定する
‣ 正式には、静的メンバ変数による定数
‣ クラスの定数は、以下のような書式になる
‣ 例: 定数「CIRCLE_NUM」を100と定義
static const int 変数名 = 値;
static const int CIRCLE_NUM = 100;
22. #pragma once
#include "ofMain.h"
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
...
// 描画する円の数を指定
static const int CIRCLE_NUM = 100;
// 位置の配列を生成
float posX[CIRCLE_NUM];
float posY[CIRCLE_NUM];
};
Q2: 解答
‣ 定数で数を定義バージョン: testApp.h
23. #include "testApp.h"
void testApp::setup(){
// 画面基本設定
ofSetFrameRate(60);
ofBackground(63);
ofSetCircleResolution(32);
// 画面内のランダムな場所を円の数だけ指定
for (int i = 0; i < CIRCLE_NUM; i++) {
posX[i] = ofRandom(ofGetWidth());
posY[i] = ofRandom(ofGetHeight());
}
}
...
void testApp::draw(){
ofSetHexColor(0x3399cc);
// 画面内のランダムな場所を円の数だけ描画
for (int i = 0; i < CIRCLE_NUM; i++) {
ofCircle(posX[i], posY[i], 20);
}
}
Q2: 解答
‣ 定数で数を定義バージョン: testApp.cpp
27. #pragma once
#include "ofMain.h"
class testApp : public ofBaseApp{
public:
void setup();
void update();
void draw();
...
// 位置
float positionX;
float positionY;
// 速度
float velocityX;
float velocityY;
};
Q3: たくさんの図形をアニメーション
‣ ヒントプログラム: testApp.h
28. #include "testApp.h"
void testApp::setup(){
// 画面基本設定
ofSetFrameRate(60);
ofBackground(63);
ofSetCircleResolution(32);
// ランダムな場所と速度を指定
positionX = ofRandom(ofGetWidth());
positionY = ofRandom(ofGetHeight());
velocityX = ofRandom(-10, 10);
velocityY = ofRandom(-10, 10);
}
void testApp::update(){
// 円の座標を更新
positionX += velocityX;
positionY += velocityY;
// 画面からはみ出ないように
if (positionX < 0 || positionX > ofGetWidth()) {
velocityX *= -1;
}
if (positionY < 0 || positionY > ofGetHeight()) {
velocityY *= -1;
}
}
Q3: たくさんの図形をアニメーション
‣ ヒントプログラム: testApp.cpp
30. Q3: たくさんの図形をアニメーション
‣ ヒント: 位置と速度をそれぞれ配列にする
‣ 定数を定義して、数はすぐに変更できるように
‣ static const int CIRCLE_NUM
‣ positionX[CIRCLE_NUM]
‣ positionY[CIRCLE_NUM]
‣ velocity X[CIRCLE_NUM]
‣ velocityY[CIRCLE_NUM]
‣ 最初の位置と速度、座標の変更、描画、すべての処理をくりか
えして100回行う → for文
32. #pragma once
#include "ofMain.h"
class testApp : public ofBaseApp{
public:
...
// 描画する円の数を指定
static const int CIRCLE_NUM = 100;
// 位置の配列を生成
float posX[CIRCLE_NUM];
float posY[CIRCLE_NUM];
// 速度の配列を生成
float speedX[CIRCLE_NUM];
float speedY[CIRCLE_NUM];
};
Q3: 解答
‣ testApp.h
33. #include "testApp.h"
void testApp::setup(){
// 画面基本設定
ofSetFrameRate(60);
ofBackground(63);
ofSetCircleResolution(32);
// 画面内のランダムな場所と速度を円の数だけ指定
for (int i = 0; i < CIRCLE_NUM; i++) {
posX[i] = ofRandom(ofGetWidth());
posY[i] = ofRandom(ofGetHeight());
speedX[i] = ofRandom(-10, 10);
speedY[i] = ofRandom(-10, 10);
}
}
void testApp::update(){
// 円の座標を全て更新
for (int i = 0; i < CIRCLE_NUM; i++) {
posX[i] += speedX[i];
posY[i] += speedY[i];
Q3: 解答
‣ testApp.cpp
34. // 画面からはみ出たらバウンドさせる
if (posX[i] < 0 || posX[i] > ofGetWidth()) {
speedX[i] *= -1;
}
if (posY[i] < 0 || posY[i] > ofGetHeight()) {
speedY[i] *= -1;
}
}
}
//--------------------------------------------------------------
void testApp::draw(){
ofSetHexColor(0x3399cc);
// 画面内のランダムな場所を円の数だけ描画
for (int i = 0; i < CIRCLE_NUM; i++) {
ofCircle(posX[i], posY[i], 20);
}
}
...
Q3: 解答
‣ testApp.cpp
43. ベクトルによる運動の表現
‣ 速度ベクトル
‣ 「速度 (velocity)」とは、単位時間あたりの物体の移動の変位
‣ 日常的な「速さ (speed)」と「速度 (velocity)」を区分する
‣ 1フレームごとの座標の変化 = 向きと大きさをもった「速度ベ
クトル」
位置ベクトル a
位置ベクトル b
速度ベクトル
44. ベクトルによる運動の表現
‣ openFrameworksで、ベクトルを表現
‣ 2次元のベクトルは「ofVec2f」を使用する
‣ 例:位置ベクトルと速度ベクトルの宣言
‣ 「ベクトル名.x」「ベクトル名.y」: ベクトルの、x方向の成分
と y方向の成分をとりだす
‣ 例:位置ベクトルの(x, y)座標を設定する
‣
ofVec2f position; // 位置ベクトルpositionを宣言
ofVec2f velocity; // 速度ベクトルvelocityを宣言
position.x = 100; // 位置ベクトルpositionのx成分を100に
position.y = 100; // 位置ベクトルpositionのx成分を50に
46. Q4: ベクトルで運動を表現する
‣ Q3 で作成した、たくさんの図形を動かすサンプルを、ベクト
ル(ofVec2f)で書き直してみる
‣ ヒント:100個ぶんの位置ベクトルと速度ベクトルは以下のよ
うに宣言される
// 描画する円の数を指定
static const int CIRCLE_NUM = 100;
// 位置ベクトルの配列
ofVec2f position[CIRCLE_NUM];
// 速度ベクトルの配列
ofVec2f velocity[CIRCLE_NUM];
48. #pragma once
#include "ofMain.h"
class testApp : public ofBaseApp{
public:
...
// 描画する円の数を指定
static const int CIRCLE_NUM = 100;
// 位置ベクトルの配列
ofVec2f position[CIRCLE_NUM];
// 速度ベクトルの配列
ofVec2f velocity[CIRCLE_NUM];
};
Q4: 解答
‣ testApp.h
49. #include "testApp.h"
void testApp::setup(){
// 画面基本設定
ofSetFrameRate(60);
ofBackground(63);
ofSetCircleResolution(32);
// 画面内のランダムな場所と速度を円の数だけ指定
for (int i = 0; i < CIRCLE_NUM; i++) {
position[i].x = ofRandom(ofGetWidth());
position[i].y = ofRandom(ofGetHeight());
velocity[i].x = ofRandom(-10, 10);
velocity[i].y = ofRandom(-10, 10);
}
}
void testApp::update(){
// 円の座標を全て更新
for (int i = 0; i < CIRCLE_NUM; i++) {
position[i] += velocity[i];
// 画面からはみ出たらバウンドさせる
if (position[i].x < 0 || position[i].x > ofGetWidth()) {
velocity[i].x *= -1;
}
Q4: 解答
‣ testApp.cpp
50. if (position[i].y < 0 || position[i].y > ofGetHeight()) {
velocity[i].y *= -1;
}
}
}
void testApp::draw(){
ofSetHexColor(0x3399cc);
// 画面内のランダムな場所を円の数だけ描画
for (int i = 0; i < CIRCLE_NUM; i++) {
ofCircle(position[i], 20);
}
}
Q4: 解答
‣ testApp.cpp
56. 応用: さらにリアルな運動の表現
‣ 関数 (function)
‣ 引数 (ひきすう, argument) - 関数に渡す値 (入力)
‣ 返り値 (return value) - 関数が返す値 (出力)
関数
引数1 引数2 引数3
戻り値
57. 応用: さらにリアルな運動の表現
‣ C++での関数の書き方
‣ 例えば、int型の数の二乗を計算する関数
‣ もし戻り値がない関数の場合、戻り値の型は「void」にする
戻り値の型 名前空間::関数名(引数1, 引数2, 引数3...){
関数の処理の内容
}
int testApp::poweroftwo(int a){
! return a * a;
}
59. #pragma once
#include "ofMain.h"
class testApp : public ofBaseApp{
public:
...
void setInit(); // 初期設定
void resetForce(); // 力をリセット
void updateForce(); // 力を更新
void updatePos(); // 位置の更新
void checkBounds(); // 画面からはみ出たらバウンドさせる
static const int CIRCLE_NUM = 100; // 描画する円の数を指定
ofVec2f position[CIRCLE_NUM]; // 位置ベクトルの配列
ofVec2f velocity[CIRCLE_NUM]; // 速度ベクトルの配列
ofVec2f force[CIRCLE_NUM]; // 力ベクトルの配列
float friction = 0.01; // 摩擦係数
};
応用: さらにリアルな運動の表現
‣ testApp.h
61. void testApp::setInit(){
// 画面内のランダムな場所と速度を円の数だけ指定
for (int i = 0; i < CIRCLE_NUM; i++) {
position[i].x = ofGetWidth()/2;
position[i].y = ofGetHeight()/2;
velocity[i].set(ofRandom(-30, 30), ofRandom(-30, 30));
force[i].set(0, 0);
}
}
void testApp::resetForce(){
// 力をリセット
for (int i = 0; i < CIRCLE_NUM; i++) {
force[i].set(0, 0);
}
}
void testApp::updateForce(){
// 力の更新 (摩擦)
for (int i = 0; i < CIRCLE_NUM; i++) {
force[i] = force[i] - velocity[i] * friction;
}
}
応用: さらにリアルな運動の表現
‣ testApp.cpp
62. void testApp::updatePos(){
// 円の座標を全て更新
for (int i = 0; i < CIRCLE_NUM; i++) {
velocity[i] += force[i];
position[i] += velocity[i];
}
}
void testApp::checkBounds(){
// 画面からはみ出たらバウンドさせる
for (int i = 0; i < CIRCLE_NUM; i++) {
if (position[i].x < 0 || position[i].x > ofGetWidth()) {
velocity[i].x *= -1;
}
if (position[i].y < 0 || position[i].y > ofGetHeight()) {
velocity[i].y *= -1;
}
}
}
応用: さらにリアルな運動の表現
‣ testApp.cpp
66. #pragma once
#include "ofMain.h"
class testApp : public ofBaseApp{
public:
...
void setInit(); // 初期設定
void resetForce(); // 力をリセット
void addForce(ofVec2f force); // 力を加える
void updateForce(); // 力を更新
void updatePos(); // 位置の更新
// 画面からはみ出たらバウンドさせる
void checkBounds(float xmin, float ymin, float xmax, float ymax);
// 位置を枠内に収める
void constrain(float xmin, float ymin, float xmax, float ymax);
// 描画する円の数を指定
static const int CIRCLE_NUM = 100;
応用: さらにリアルな運動の表現
‣ testApp.h
68. #include "testApp.h"
void testApp::setup(){
// 画面基本設定
ofSetFrameRate(60);
ofBackground(63);
ofSetCircleResolution(32);
setInit(); // 円を初期化
}
void testApp::update(){
resetForce(); // 力をリセット
addForce(ofVec2f(0, 0.5)); // 重力を加える
updateForce(); // 力の更新 (摩擦)
updatePos(); // 円の座標を全て更新
// 画面からはみ出たらバウンドさせる
checkBounds(0, 0, ofGetWidth(), ofGetHeight());
// 枠内に収める
constrain(0, 0, ofGetWidth(), ofGetHeight());
}
応用: さらにリアルな運動の表現
‣ testApp.cpp
69. void testApp::draw(){
ofSetHexColor(0x3399cc);
// 画面内のランダムな場所を円の数だけ描画
for (int i = 0; i < CIRCLE_NUM; i++) {
ofCircle(position[i], 20);
}
}
void testApp::setInit(){
// 画面内のランダムな場所と速度を円の数だけ指定
for (int i = 0; i < CIRCLE_NUM; i++) {
position[i].x = ofGetWidth()/2;
position[i].y = ofGetHeight()/2;
velocity[i].set(ofRandom(-30, 30), ofRandom(-30, 30));
force[i].set(0, 0);
}
}
void testApp::resetForce(){
// 力をリセット
for (int i = 0; i < CIRCLE_NUM; i++) {
force[i].set(0, 0);
}
}
応用: さらにリアルな運動の表現
‣ testApp.cpp
70. void testApp::addForce(ofVec2f _force){
// 力を加える
for (int i = 0; i < CIRCLE_NUM; i++) {
force[i] += _force;
}
}
void testApp::updateForce(){
// 力の更新 (摩擦)
for (int i = 0; i < CIRCLE_NUM; i++) {
force[i] = force[i] - velocity[i] * friction;
}
}
void testApp::updatePos(){
// 円の座標を全て更新
for (int i = 0; i < CIRCLE_NUM; i++) {
velocity[i] += force[i];
position[i] += velocity[i];
}
}
応用: さらにリアルな運動の表現
‣ testApp.cpp
71. void testApp::constrain(float xmin, float ymin, float xmax, float ymax){
// 枠内に収める
for (int i = 0; i < CIRCLE_NUM; i++) {
if (position[i].x < xmin) {
position[i].x = xmin;
}
if (position[i].y < ymin) {
position[i].y = ymin;
}
if (position[i].x > xmax) {
position[i].x = xmax;
}
if (position[i].y > ymax) {
position[i].y = ymax;
}
}
}
void testApp::checkBounds(float xmin, float ymin, float xmax, float ymax){
// 画面からはみ出たらバウンドさせる
for (int i = 0; i < CIRCLE_NUM; i++) {
if (position[i].x < xmin || position[i].x > xmax) {
velocity[i].x *= -1;
}
応用: さらにリアルな運動の表現
‣ testApp.cpp
72. if (position[i].y < ymin || position[i].y > ymax) {
velocity[i].y *= -1;
}
}
}
応用: さらにリアルな運動の表現
‣ testApp.cpp
76. ‣ オブジェクト指向プログラミング
‣ Object Oriented Programming (OOP)
‣ オブジェクト指向でProcessingのプログラムを作る
‣ そもそもオブジェクト指向とは?
‣ 簡単なプログラムを、オブジェクト指向で書いてみる
‣ クラスの定義
‣ クラスの呼びだし
オブジェクト指向プログラミングとは?
83. ‣ オブジェクト指向プログラムのポイント:その3
‣ 必要のない情報は隠す (カプセル化)
‣ プログラムの実装全てを知る必要はない
‣ 必要なインターフェイス(接点)だけ見せて、あとは隠す
To invent programs, you need to be able to capture abstractions and ex
design. It’s the job of a programming language to help you do this. The
process of invention and design by letting you encode abstractions tha
It should let you make your ideas concrete in the code you write. Surf
the architecture of your program.
All programming languages provide devices that help express abstrac
are ways of grouping implementation details, hiding them, and giving
a common interface—much as a mechanical object separates its interfa
illustrated in “Interface and Implementation” .
Figure 2-1 Interface and Implementation
9
10
11
8
7
6
implementationinterface
インターフェイス 実装
OOP:ポイントその3
86. ‣ クラス
‣ クラスとは:オブジェクトの「型紙」
‣ クラスをインスタンス化 (実体化) することでインスタンス
(オブジェクト)となる
色
重さ(g)
味
リンゴ
(クラス)
実
が
な
る
成
長
す
る
落
ち
る
腐
る
赤
5.0
甘い
ふじ
(インスタンスオブジェクト)
実
が
な
る
成
長
す
る
落
ち
る
腐
る
青
4.0
すっぱい
青リンゴ
(インスタンスオブジェクト)
実
が
な
る
成
長
す
る
落
ち
る
腐
る
インスタンス化
クラス
87. ‣ いままで扱ってきた、testApp も一つのクラス
‣ メソッド - setup(), update(), draw() ...etc.
‣ プロパティ - testApp全体で使用する変数
testAppもクラス
クラス変数
setup()
update()
draw
()
exit()
testApp
92. OOP実践編 - クラスを作る
‣ ランダムな場所に、1つ静止したパーティクルを描く
‣ https://gist.github.com/tado/6709701
93. #include "testApp.h"
void testApp::setup(){
// 画面基本設定
ofSetFrameRate(60);
ofBackground(63);
ofSetCircleResolution(32);
// 画面内のランダムな場所を指定
position.x = ofRandom(ofGetWidth());
position.y = ofRandom(ofGetHeight());
}
...
void testApp::draw(){
// 設定した場所に円を描く
ofSetHexColor(0x3399cc);
ofCircle(position, 10);
}
OOP実践編 - クラスを作る
‣ testApp.cpp - コード抜粋
94. OOP実践編 - クラスを作る
‣ このプログラムをクラス化してみる
‣ クラス名:Particle
‣ プロパティ (状態、変数):
‣ ofVec2f position : 初期位置
‣ メソッド (ふるまい、関数):
‣ draw( ) : パーティクルを描く
95. OOP実践編 - クラスを作る
‣ こんな風に図示します (UMLクラス図)
Particle
+ position:ofVec2f
+ draw():void
←クラス名
←プロパティ
←メソッド
102. クラスの記述
‣ まずはヘッダーファイル (Particle.h) から
‣ レシピの材料と手順の一覧!
‣ 材料 → 状態、性質 → つまり、プロパティ(変数)
‣ 手順 → ふるまい、動作 → つまり、メソッド(関数)
‣ そのクラスのプロパティとメソッドを記述
‣ 外部から参照するものは、public: 以下に書く
104. #pragma once
#include "ofMain.h"
class Particle {
public:
void draw();
ofVec2f position;
};
クラスの記述
‣ Particle.h
‣ https://gist.github.com/tado/6710045
インクルードガード
Buildの際に複数回読みこまれないためのしくみ
110. #pragma once
#include "ofMain.h"
class Particle {
public:
void draw();
ofVec2f position;
};
クラスの記述
‣ Particle.h
‣ https://gist.github.com/tado/6710045#file-oneparticleclass01-particle-h
最後に必ずセミコロンをつける
116. クラスの記述
‣ 最後に作成したクラスを、testAppから呼び出します
‣ ヘッダーファイル testApp.h で MoveCircle を宣言
‣ これだけで、クラスが実体化(インスタンス化)される
‣ クラス名:Particle
‣ インスタンス:particle
‣ testApp.h
‣ https://gist.github.com/tado/6710045#file-oneparticleclass01-testapp-h
Particle particle;
117. クラスの記述
‣ メインの実装ファイル、testApp.cpp で作成したインスタンス
を使用して円を描かせる
‣ https://gist.github.com/tado/6710045#file-oneparticleclass01-testapp-cpp
‣ testApp::setup( ) で円の初期位置を指定
‣ testApp::draw( ) でParticleのdraw( )メソッドを呼びだし
particle.position.x = ofRandom(ofGetWidth());
particle.position.y = ofRandom(ofGetHeight());
particle.draw();
122. クラスの配列
‣ あとは for文を使用して反復して処理していく
‣ testApp::setup() で初期化
‣ testApp::draw() で描画
‣
for(int i = 0; i < NUM; i++){
float posX = ofRandom(ofGetWidth());
float posY = ofRandom(ofGetHeight());
particle[i].setup(ofVec2f(posX, posY));
}
for(int i = 0; i < NUM; i++){
particle[i].draw();
}
127. パーティクルシステムを作る!
‣ UMLクラス図で表現
Particle
+ position:ofVec2f
+ velocity:ofVec2f
+ force:ofVec2f
+ friction:float
+ radius:float
+ setup(ofVec2f position, ofVec2f velocity):void
+ resetForce():void
+ addForce(ofVec2f force):void
+ updateForce():void
+ updatePos():void
+ checkBounds(float xmin, float ymin, float xmax, float ymax):void
+ draw():void
133. vector (動的配列) の活用
‣ Particleクラス、さらに応用
‣ 次のようなインタラクションを実現したい:
‣ マウスをドラッグしている間、パーティクルがマウスの場所か
ら生成され続ける
‣ 生成されたパーティクルは、そのまま画面に残る
‣ キーボードで「c」のキーを押すとクリア
‣ Particleの配列は、いくつ確保すれば良いのか?
‣ 1000? 10000? 1000000?
‣ 無限大のArrayを作成することはできない…
134. vector (動的配列) の活用
‣ Arrayの数が確定しない
particle[0]
particle[1]
particle[2]
.
.
.
Particle particle[NUM]
NUM個
particle[NUM]
→ 不明
→ 不明
→ 不明
135. vector (動的配列) の活用
‣ 配列の上限の数がわからない場合
‣ Array (静的配列) ではなく、要素数を自由に変更できる動的な
配列を使用すると便利
‣ C++ では 「vector」 が比較的扱いやすい
‣ 「vector<型の種類> 配列名」となる
‣ 例: Particleクラスの動的配列、particleを宣言
vector<Particle> particle;
136. vector (動的配列) の活用
‣ vector (動的配列) のイメージ
particle[0]
particle[1]
particle[2]
.
.
.
vector<Particle> particle
数は可変
137. vector (動的配列) の活用
‣ Vectorの配列要素の操作
‣ 配列の末尾に要素を追加 → push_back()
‣ 例:Particleのオブジェクトpを、particleに追加
‣ 配列の末尾に要素を削除 → pop_back()
‣ 配列の全ての要素をクリア → clear()
particle.push_back(p);
particle.clear();
particle.pop_back();
138. vector (動的配列) の活用
‣ 実装例
‣ こちらもGistを参照 (ParticleクラスはそのままでOK!)
‣ testApp.h
‣ https://gist.github.com/tado/6712412#file-particlevector-
testapp-h
‣ testApp.cpp
‣ https://gist.github.com/tado/6712412#file-particlevector-
testapp-cpp