Last active
August 29, 2015 14:04
-
-
Save SleepingFoxNEKO/0ef9ad4cc85dae6be2e8 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// L2DModelMatrixを使うサンプル | |
void OnRenderObject() | |
{ | |
//キャンパスサイズはlive2DModelから取得できる | |
var height = live2DModel.getCanvasHeight(); | |
var width = live2DModel.getCanvasWidth(); | |
// 初期化の時にキャンパスサイズが必要 | |
// 縦横比は維持したまま、移動やサイズの変更ができる。 | |
// この場合は横幅を10に、スプライトの中心を原点にしている。 | |
L2DModelMatrix mmat = new L2DModelMatrix(width, height); | |
mmat.setWidth( 10 ); | |
mmat.setCenterPosition(0,0); | |
// 配列でデータを持っているので、Matrix4x4に変換しないといけない | |
Matrix4x4 modelMatrix = Matrix4x4.identity; | |
var array = mmat.getArray(); | |
for ( int i=0; i < 16; i++ ) { | |
modelMatrix[i] = array[i]; | |
} | |
// ローカル座標をワールド座標に変換する行列 | |
// これを最後(左端)にかけておかないとGameobjectの座標が反映されない。 | |
Matrix4x4 L2W = transform.localToWorldMatrix; | |
var matrix = L2W * modelMatrix; | |
live2DModel.setMatrix( matrix ); | |
//頂点の更新 | |
live2DModel.update(); | |
//モデルの描画 | |
live2DModel.draw(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment