/* * LineTest.cs * Authors: * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ using System; using System.Collections.Generic; using System.Text; using Util; using Microsoft.Xna.Framework.Graphics; using Microsoft.Xna.Framework; namespace StarJack { class LineTest:GameScreen { SpriteBatch spriteBatch; GraphicsDevice device; Effect effect; VertexPositionColor[] vertices; VertexDeclaration myVertexDeclaration; int[] indices; Matrix viewMatrix; Matrix projectionMatrix; private float angle = 0f; VertexBuffer mVertexBuffer; BasicEffect basic; VertexPositionColor[] pointList; int[] indexs; public LineTest() :base() { } public override void Initialize() { indexs = new int[]{0,1,1,2,2,0}; //Init Points for lines pointList = new VertexPositionColor[3]; pointList[0] = new VertexPositionColor(new Vector3(0, 0, 0), Color.Red); pointList[1] = new VertexPositionColor(new Vector3(100.5f, 0, 0), Color.Red); pointList[2] = new VertexPositionColor(new Vector3(50.5f, 50, 0), Color.Red); base.Initialize(); basic = new BasicEffect(GraphicsDevice, new EffectPool()); basic.VertexColorEnabled = true; } protected override void LoadContent() { base.LoadContent(); //effect = Content.Load("effects"); SetUpVertices(); SetUpCamera(); SetUpIndices(); mVertexBuffer = new VertexBuffer(GraphicsDevice, VertexPositionColor.SizeInBytes * (3 + 2), BufferUsage.WriteOnly); } private void SetUpVertices() { vertices = new VertexPositionColor[5]; vertices[0].Position = new Vector3(0f, 0f, 0f); vertices[0].Color = Color.White; vertices[1].Position = new Vector3(5f, 0f, 0f); vertices[1].Color = Color.White; vertices[2].Position = new Vector3(10f, 0f, 0f); vertices[2].Color = Color.White; vertices[3].Position = new Vector3(5f, 0f, -5f); vertices[3].Color = Color.White; vertices[4].Position = new Vector3(10f, 0f, -5f); vertices[4].Color = Color.White; myVertexDeclaration = new VertexDeclaration(GraphicsDevice, VertexPositionColor.VertexElements); } private void SetUpIndices() { indices = new int[6]; indices[0] = 3; indices[1] = 1; indices[2] = 0; indices[3] = 4; indices[4] = 2; indices[5] = 1; } private void SetUpCamera() { viewMatrix = Matrix.CreateLookAt(new Vector3(0, 50, 0), new Vector3(0, 0, 0), new Vector3(0, 0, -1)); projectionMatrix = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, GraphicsDevice.Viewport.AspectRatio, 1.0f, 300.0f); } public override void Update(Microsoft.Xna.Framework.GameTime gameTime) { base.Update(gameTime); } public override void Draw(Microsoft.Xna.Framework.GameTime gameTime) { GraphicsDevice.Clear(Color.CornflowerBlue); GraphicsDevice.RenderState.CullMode = CullMode.None; GraphicsDevice.RenderState.FillMode = FillMode.WireFrame; GraphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.LineList, pointList, 0, 3, indexs, 0, 2); base.Draw(gameTime); } } }