모델을 그리기 위해 다음 코드가 부분적으로 작동합니다. 저는이 모델의 인스턴스를 여러 개 만들고 모델의 각 인스턴스를 다른 렌더링 타겟으로 렌더링하고 있습니다. 제 질문은 어떻게 각 인스턴스에 대한 행렬을 저장할 수 있습니까? 왜냐하면 하나를 회전시키고 싶을 때 행렬의 참조를 취하는 것 같고 회전 할 때 업데이트 된 행렬이 필요하기 때문입니다.
감사합니다. 감사XNA에서 모델의 각 인스턴스에 대한 행렬의 상태를 저장하는 방법은 무엇입니까?
mesheffect.World = worldtransform;
에 변수 worldtransform
를 사용하여 업데이트에서 그 값을 설정하는 무엇을 말할 수에서
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using gamacherclone.Sources.Model;
namespace gamacherclone
{
public class Case360 : DrawableComponent
{
private Model _model ;//= new Model();
Matrix[] _boneTransforms,world;
public int coverflowposition = 0;
public bool rotate = false;
Matrix view, proj,worldtransform,tempbones;
public Matrix[] boneTransforms;
public Matrix[] originalBoneTransforms;
Matrix[] worldTransforms;
float i = 0;
public DashBoard dash;
Cover cover;
public Case360(Game game, Cover _cover)
: base(game)
{
this.dash = (DashBoard)game;
this.cover = _cover;
}
protected override void LoadContent(){
this._model = this.dash.Content.Load<Model>(@"Models\case360");
this.initialize();
}
public void initialize() {
this._boneTransforms = new Matrix[this._model.Bones.Count];
this.originalBoneTransforms = new Matrix[this._model.Bones.Count];
this.worldTransforms = new Matrix[this._model.Bones.Count];
this._model.CopyAbsoluteBoneTransformsTo(_boneTransforms);
this._model.CopyAbsoluteBoneTransformsTo(originalBoneTransforms);
}
public override void Update(GameTime gameTime)
{
// Calculate the new position of the forks.
float time = (float)gameTime.TotalGameTime.TotalSeconds;
if (this.rotate) {
worldtransform = worldTransforms[0];
UpdateWorldTransforms(time);
}
base.Update(gameTime);
}
public void UpdateWorldTransforms(float time)
{
worldTransforms[0] = _boneTransforms[0] * Matrix.CreateRotationY(time * 2f);
}
public override void Draw(GameTime gameTime)
{
this._model.CopyAbsoluteBoneTransformsTo(_boneTransforms);
base.GraphicsDevice.SetRenderTarget(cover.caseRender);
base.GraphicsDevice.Clear(Color.Transparent);
base.GraphicsDevice.BlendState = BlendState.AlphaBlend;
//GraphicsDevice.RasterizerState = RasterizerState.CullCounterClockwise;
base.GraphicsDevice.DepthStencilState = DepthStencilState.Default;
view = Matrix.CreateLookAt(new Vector3(1, 10, 10), new Vector3(0, 7, -10), Vector3.Up);
proj = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45f),
GraphicsDevice.Viewport.Width/GraphicsDevice.Viewport.Height,
1f, 1000.0f);
// Draw the model.
foreach (ModelMesh mesh in this._model.Meshes)
{
foreach (BasicEffect mesheffect in mesh.Effects)
{
mesheffect.Parameters["Texture"].SetValue(this.cover.coverImage);
mesheffect.EnableDefaultLighting();
mesheffect.View = view;
mesheffect.Projection = proj;
mesheffect.World = worldtransform;
}
mesh.Draw();
}
base.GraphicsDevice.SetRenderTarget(null);
base.GraphicsDevice.SetRenderTarget(dash.renderTarget2D);
base.Draw(gameTime);
}
}
}