2011-10-10 2 views
0

私は、レイをトレースする前にワールド空間にモデルをスケールする必要があるため、グラフィックスクラスのレイトレーサを作成しています。私は必要な世界を作り出しました。しかし、私の最初の試みは、モデルのバウンディングボックスが変化しますが、VertexBufferの頂点は変化しません。レンダリングなしのモデルへの変形の適用

これが私の最初の試みである:私もチュートリアルショーを描くすべてのモデルのように噛み合っているモデルで見つかった効果値を設定しようとしました

foreach (ModelBone b in model.Bones) 
{ 
    // apply the model transforms and the worldMatrix transforms to the bone 
    b.Transform = model.Root.Transform * worldMatrix; 
} 

が、それは無駄です。

モデルを変換しようとする必要がある別の方法はありますか?

答えて

1

b.Transform = root * world;骨そのもののデータは考慮していません。

おそらく必要とします:b.Transform = root * b * world;

頂点バッファ内のデータは、ゲーム/アプリの生涯を通じて変化しないようにしてください。何が起こるかは、元の(変更されていない)頂点データが、各フレームを頂点シェーダ内で、新しいエフェクトを介して送信した別のワールドマトリックスによって新たに変換されることです。

//class scope fields 
Matrix[] modelTransforms; 
Matrix worldMatrix; 

//in the loadContent method just after loading the model 
modelTransforms - new Matrix[model.Bones.Count]; 
model.CopyAbsoluteTransformsTo(modelTransforms);//this line does what your foreach does but will work on multitiered hierarchy systems 

//in the Update methos 
worldMatrix = Matrix.CreateScale(scale); 
boundingBox.Min *= scale; 
boundingBox.Max *= scale 
//raycast against the boundingBox here 

//in the draw call 
eff.World = modelTransforms[mesh.ParentBone.Index] * worldMatrix; 

一般的に、それはこのような何かを行くだろう

関連する問題