/* * Asteroid.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 Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Content; using Microsoft.Xna.Framework.Graphics; using tAC_Engine.Graphics.Entities; using TACParticleEngine; using TACParticleEngine.Particles; using Random = Util.Random; namespace ColonySim { class Asteroid : EntityModel { Vector2 mPosition = Vector2.Zero; Vector3 mCurrentRotation = Vector3.Zero; Vector3 mRotationSpeed = Vector3.Zero; ParticleEngine effect; //Vector3[] mParticlePositions = new Vector3[2]; Vector2? mGrabPosition; public Vector2? GrabPosition { get { return mGrabPosition; } //set { mGrabPosition = value; } } public void Grab(Vector2? pPosition, ParticleManager pParticleManager) { mGrabPosition = pPosition; effect = pParticleManager.Load(@"ParticleEffects\AsteroidBeam"); Vector3[] mParticlePositions = new Vector3[2]; mParticlePositions[0] = new Vector3(mPosition.X, -3, mPosition.Y); mParticlePositions[1] = new Vector3(((Vector2)mGrabPosition).X, 0, ((Vector2)mGrabPosition).Y); effect.SetEnginePositions(mParticlePositions); effect.SetEngineColor(Color.White.ToVector4(), true); effect.SetActive(true); } // NOTE: Unused? const float VIEW_BUFFER = 4f; public Asteroid(Vector2 pPosition, ContentManager pContent) : base(pContent, @"Models\Asteroid", null) { mPosition = pPosition; TransformationMatrix = Matrix.CreateTranslation(new Vector3(mPosition.X, -.75f, mPosition.Y)); mRotationSpeed = new Vector3(Random.NextFloat(-1, 1), Random.NextFloat(-1, 1), Random.NextFloat(-1, 1)); } public override void Update(GameTime gameTime) { // Only if we're visible if (Visible) { TransformationMatrix = Matrix.CreateRotationX(mCurrentRotation.X) * Matrix.CreateRotationY(mCurrentRotation.Y) * Matrix.CreateRotationZ(mCurrentRotation.Z) * Matrix.CreateTranslation(new Vector3(mPosition.X, -.75f, mPosition.Y)); mCurrentRotation += mRotationSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds; } } } }