3軸XYZとモデルを描画して、空間内のどこにあり、どのように動くかを確認したかった
単純な回転で立方体を描くだけで、すべてが大丈夫です
しかし、軸描画メソッドを追加すると
レンドリングは大丈夫ではありません
using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Media;
namespace WindowsGame2
{
public class Game1 : Microsoft.Xna.Framework.Game
{
//Some declaration
float x = 30f;
float y = 0f;
float z = 30f;
//GraphicsDevice device;
VertexBuffer vertexBuffer;
VertexPositionColor[] lines;
GraphicsDeviceManager graphics;
SpriteBatch spriteBatch;
Model model;
Matrix view;
Matrix progection;
float xTans = 0.0f;
float yTans = 0.0f;
float zTans = 0.0f;
public Game1()
{
graphics = new GraphicsDeviceManager(this);
Content.RootDirectory = "Content";
}
protected override void Initialize()
{
//device = graphics.GraphicsDevice;
base.Initialize();
this.IsMouseVisible = true;
}
protected override void LoadContent()
{
// Create a new SpriteBatch, which can be used to draw textures.
spriteBatch = new SpriteBatch(GraphicsDevice);
model = Content.Load<Model>("cube");
DrawLines();
createCamera();
}
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back ==
ButtonState.Pressed)
this.Exit();
// TODO: Add your update logic here
base.Update(gameTime);
//update camera
}
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Azure);
foreach (ModelMesh mesh in model.Meshes)
{
foreach (BasicEffect fx in mesh.Effects)
{
fx.View = view;
//fx.World = Matrix.CreateRotationX(xTans);
fx.World = Matrix.CreateRotationY(yTans);
//fx.World = Matrix.CreateRotationZ(zTans);
fx.Projection = progection;
fx.EnableDefaultLighting();
}
mesh.Draw();
}
//xTans += 0.01f;
yTans += 0.01f;
//zTans += 0.01f;
BasicEffect effect = new BasicEffect(graphics.GraphicsDevice);
effect.VertexColorEnabled = true;
effect.View = view;
effect.Projection = progection;
effect.World = Matrix.Identity;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
// Begin Drawing
pass.Apply();
// Set the vertex buffer to graphic device
graphics.GraphicsDevice.SetVertexBuffer(vertexBuffer, 0);
// Draw the axes with LineList Type
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
PrimitiveType.LineList, lines, 0, 3);
//pass.Apply();
}
base.Draw(gameTime);
}
protected void DrawLines()
{
lines = new VertexPositionColor[6];
//Setting Size and Width and Color of the X axis
lines[0] = new VertexPositionColor(new Vector3(50, 0, 0), Color.Red);
lines[1] = new VertexPositionColor(new Vector3(-50, 0, 0), Color.Red);
//Setting Size and Width and Color of the Y axis
lines[2] = new VertexPositionColor(new Vector3(0, 50, 0), Color.Green);
lines[3] = new VertexPositionColor(new Vector3(0, -50, 0), Color.Green);
//Setting Size and Width and Color of the Z axis
lines[4] = new VertexPositionColor(new Vector3(0, 0, 50), Color.Blue);
lines[5] = new VertexPositionColor(new Vector3(0, 0, -50), Color.Blue);
vertexBuffer = new VertexBuffer(graphics.GraphicsDevice,
VertexPositionColor.VertexDeclaration, 6, BufferUsage.None);
vertexBuffer.SetData<VertexPositionColor>(lines);
}
protected void createCamera()
{
view = Matrix.CreateLookAt(
new Vector3(0f, 60.0f, 60f),
Vector3.Zero,
Vector3.Up);
progection = Matrix.CreatePerspectiveFieldOfView(
MathHelper.ToRadians(8.0f),
graphics.GraphicsDevice.Viewport.AspectRatio,
10.0f,
1000.0f);
}
} //end game class
} //end namespace
軸を描画する関数はdrawLines()です
メソッドdraw()内
私は本当に軸を描くためにこれを持っています
BasicEffect effect = new BasicEffect(graphics.GraphicsDevice);
effect.VertexColorEnabled = true;
effect.View = view;
effect.Projection = progection;
effect.World = Matrix.Identity;
foreach (EffectPass pass in effect.CurrentTechnique.Passes)
{
// Begin Drawing
pass.Apply();
// Set the vertex buffer to graphic device
graphics.GraphicsDevice.SetVertexBuffer(vertexBuffer, 0);
// Draw the axes with LineList Type
graphics.GraphicsDevice.DrawUserPrimitives<VertexPositionColor>(
PrimitiveType.LineList, lines, 0, 3);
//pass.Apply();
}
回転のレンディングの速度が遅い理由がわかりません