非弾性衝突
const auto r = (r0 + r1) * 0.5f; // 反発係数 const auto m0 = 1.0f; // Aの質量 const auto m1 = 1.0f; // Bの質量 const auto u0 = n * dot(vel0, n); // 衝突面(法線N)に対しての垂直方向のAの速度 const auto u1 = n * dot(vel1, n); // 衝突面(法線N)に対しての垂直方向のBの速度 const auto v0 = vel0 - u0; // 水平方向のAの速度 const auto v1 = vel1 - u1; // 水平方向のBの速度 const auto f0 = ((u1 - u0) * (r * m1) + (u0 * m0) + (u1 * m1)) / (m0 + m1); // 衝突後の垂直方向のAの速度 const auto f1 = ((u0 - u1) * (r * m0) + (u0 * m0) + (u1 * m1)) / (m0 + m1); // 衝突後の垂直方向のBの速度 vel0 = v0 + f0; // 水平方向と足して新しい速度ベクトルを作成 vel1 = v1 + f1; // 水平方向と足して新しい速度ベクトルを作成
摩擦を考慮する場合は摩擦係数で水平方向のベクトルを減衰させる
2D Perlin Noise in C++
こんな感じやろか?
float interp(float x, float y, float t) { return x + (y - x) * t; // とりあえず線形 } float noise(int32_t x, int32_t y) { auto n = x + y * 57; n = (n << 13) ^ n; return (1.0f - ((n * (n * n * 15731 + 789221) + 1376312589) & 0x7fffffff) / 1073741824.0f); } float smooth(int32_t x, int32_t y) { float corners = (noise(x - 1, y - 1) + noise(x + 1, y - 1) + noise(x - 1, y + 1) + noise(x + 1, y + 1)) / 16.0f; float sides = (noise(x - 1, y) + noise(x + 1, y) + noise(x, y - 1) + noise(x, y + 1)) / 8.0f; float center = noise(x, y) / 4.0f; return corners + sides + center; } float interpNoise(float x, float y) { auto ix = static_cast<int32_t>(x); auto fx = x - ix; auto iy = static_cast<int32_t>(y); auto fy = y - iy; auto v1 = smooth(ix, iy); auto v2 = smooth(ix + 1, iy); auto v3 = smooth(ix, iy + 1); auto v4 = smooth(ix + 1, iy + 1); auto i1 = interp(v1, v2, fx); auto i2 = interp(v3, v4, fx); return interp(i1, i2, fy); } float perlinNoise(float x, float y, float persistence, int octaves) { float total = 0.0f; for (int i = 0; i < octaves; ++i) { auto f = powf(2.0f, static_cast<float>(i)); auto a = powf(persistence, static_cast<float>(i)); total += interpNoise(x * f, y * f) * a; } return total; }
参考
http://www.technotype.net/hugo.elias/models/m_perlin.html
これは古いやり方(Classic way)と呼ばれていて現在はハッシュテーブルを使った実装が多いようだ
https://mrl.nyu.edu/~perlin/noise/
Understanding Perlin Noise
noise/_perlin.c at master · caseman/noise · GitHub
時間があれば読んでおきたい
Texturing & Modeling A Procedural Approach Third Edition 日本語版
カスタムビルドツールが毎回ビルドされる
出力ファイルにファイル名だけじゃなくパスも書くと大丈夫っぽい
ソースと同じ場所に出力したいなら%(RelativeDir)hoge
とか
今更PerfHUD ESでTegraのGLESデバッグ
面倒くさいけど先にUser Accountを作成しておく必要がある https://developer.nvidia.com/
んでここからPerfHUD ESをダウンロードしておく https://developer.nvidia.com/gameworksdownload
Android Studio起動してTerminalから
adb shell setprop debug.perfhudes 1 adb forward tcp:7876 tcp:7876
apkを実行なりデバッグなりしてPerfHUD ESを立ち上げる
File -> IP Addressからプロセスが見えるようになっているので選択してConnect
あとは知らん
早くTegra2と3をこの世から消
PySide2 メモ
Qt for Python is coming to a computer near you
https://blog.qt.io/blog/2018/04/13/qt-for-python-is-coming-to-a-computer-near-you/