Hi, ich hab n problem: ich will mit xna ein dreick, das sich um die y-achse dreht machen.
Nun, 1. das Dreieck bleibt schwarz(?) und zweitens verschwindet es immer zwischendurch mal wieder(??).
Nun, hier der Code:
Konstruktor der Game-Klasse
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
public GDreieck(bool bFullscreen)
: base()
{
graphics = new GraphicsDeviceManager(this);
// Fenster- bzw. Vollbildmodus...
graphics.IsFullScreen = bFullscreen;
this.IsFixedTimeStep = true;
Content.RootDirectory = "Content";
Triangle = new CTriangle(new VertexPositionColor[]
{new VertexPositionColor(new Vector3(-1.0f,-1.0f,1.0f),new Color(0xFF,0,0)),
new VertexPositionColor(new Vector3(1.0f,-1.0f,1.0f),new Color(0,0xFF,0)),
new VertexPositionColor(new Vector3(0.0f,1.0f,1.0f), new Color(0,0,0xFF))
});
}
|
CTriangle ist ne klasse die drei vertizes enthält.
Hier meine Initialize-Methode:
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
GraphicsDevice.VertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements);
fxbasic = new BasicEffect(GraphicsDevice, null);
fxbasic.FogEnabled = false;
fxbasic.AmbientLightColor = Vector3.Zero;
fxbasic.DiffuseColor = Vector3.Zero;
fxbasic.EmissiveColor = Vector3.Zero;
fxbasic.VertexColorEnabled = true;
fxbasic.LightingEnabled = false;
fxbasic.PreferPerPixelLighting = false;
fxbasic.EnableDefaultLighting();
fxbasic.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(90.0f), GraphicsDevice.DisplayMode.AspectRatio, 0.00000001f, 100.0f);
fxbasic.View = Matrix.CreateLookAt(new Vector3(0.0f, 0.0f, -10.0f), Vector3.Zero, Vector3.Up);
fxbasic.World = Matrix.CreateRotationY(MathHelper.ToRadians(1));
base.Initialize();
|
Meine Update-Methode
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
|
protected override void Update(GameTime gameTime)
{
// Allows the game to exit
if (GamePad.GetState(PlayerIndex.One).Buttons.Back == ButtonState.Pressed || Keyboard.GetState(PlayerIndex.One).IsKeyDown(Keys.Escape))
this.Exit();
fxbasic.World *= Matrix.CreateRotationY(MathHelper.ToRadians(45.0f * (float)gameTime.ElapsedRealTime.TotalSeconds));
base.Update(gameTime);
}
|
Die Draw-Methode:
|
Quellcode
|
1
2
3
4
5
6
7
8
9
|
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Clear(Color.Blue);
// Dreieck rendern
Triangle.Render(GraphicsDevice, fxbasic);
base.Draw(gameTime);
}
|
Hier CTriangle.Render
|
Quellcode
|
1
2
3
4
5
6
7
8
9
10
11
|
public void Render(GraphicsDevice graphics, Effect fx)
{
fx.Begin();
foreach (EffectPass pass in fx.CurrentTechnique.Passes)
{
pass.Begin();
graphics.DrawUserPrimitives<VertexPositionColor>(PrimitiveType.TriangleStrip, _Vertices, 0, 1);
pass.End();
}
fx.End();
}
|
Hoffe jemand kann mir helfen...
mfg C--