2011-10-10 5 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; 
:

일반적으로,이 같은 뭔가를 갈 것

관련 문제