reddit ( https://www.reddit.com/r/gameideas/comments/3dsy8m/revolt/ )でゲームのアイデアをすばやくプロトタイプ化するために、シーン グラフを使用したクイック WebGL エンジンに取り組んでいます。さて、いくつかの基本的なレンダリングを行った後、シーン グラフ内のノードを変換するために使用する正しい順序、つまりほとんどの人に正しく見える順序を理解できません。
何が起こっているのかを説明するのは難しいですが、他のエンジンで起こるとほとんどの人が予想するような回転ではないことを理解していただければ幸いです。
これは、私が現在行っていることの簡略化されたバージョンです。
- Mat4 = glMatrix 0.9.5
- ユーティリティ = カスタム ユーティリティ
ノード(レンダリング):
@param {parentMatrix}
// Create Local Matrix
self.lMatrix = mat4.create();
mat4.identity(self.lMatrix);
mat4.translate(self.lMatrix, self.position);
mat4.rotate(self.lMatrix, self.rotation[0], [1, 0, 0]);
mat4.rotate(self.lMatrix, self.rotation[1], [0, 1, 0]);
mat4.rotate(self.lMatrix, self.rotation[2], [0, 0, 1]);
var wMatrix = mat4.create();
mat4.identity(wMatrix);
if(parentMatrix){
mat4.multiply(self.lMatrix, parentMatrix, wMatrix);
}
else{
mat4.set(self.lMatrix, wMatrix);
}
// Render
var children = this.children,
numChildren = children.length,
child;
for(var i = 0; i < numChildren; i++){
child = children[i];
child.render(wMatrix);
}
エンティティ(レンダリング):
@param {parentMatrix}
// Set Transformation matrix
var tMatrix = mat4.create();
mat4.identity(tMatrix);
mat4.translate(tMatrix, self.position);
mat4.rotate(tMatrix, self.rotation[0], [1, 0, 0]);
mat4.rotate(tMatrix, self.rotation[1], [0, 1, 0]);
mat4.rotate(tMatrix, self.rotation[2], [0, 0, 1]);
mat4.scale(tMatrix, self.scale || [1, 1, 1]);
var wMatrix = mat4.create();
mat4.identity(wMatrix);
mat4.multiply(tMatrix, parentMatrix, wMatrix);
Utils.loadTMatrix(wMatrix);
this.texture.bind();
this.mesh.render();