/// <summary> /// Draws the effect on the screen. /// </summary> /// <param name="device"></param> /// <param name="camera"></param> public override void Draw(GraphicsDevice device, Camera camera) { device.BlendState = BlendState.AlphaBlend; device.DepthStencilState = DepthStencilState.Default; if (mGameObject is IMovable) { //calc direction and angle Vector3 direction = GetPosition() - mLastPosition; if (direction != Vector3.Zero) { direction.Normalize(); var modelOrientation = new Vector3(0, 1, 0); float factor = (direction.X - modelOrientation.X) > 0 ? 1 : -1; var angle = (float) Math.Acos(Vector3.Dot(modelOrientation, direction)); mOrientationAngle = (float) Math.PI - angle * factor; } mLastPosition = GetPosition(); } device.BlendState = BlendState.AlphaBlend; device.RasterizerState = RasterizerState.CullNone; Matrix worldMatrix = Matrix.CreateScale(mScale) * Matrix.CreateRotationY(mRot.Y) * Matrix.CreateRotationZ(mOrientationAngle) * Matrix.CreateTranslation(GetPosition()); mModel.Draw(worldMatrix, camera.mViewMatrix, camera.mProjectionMatrix); }
/// <summary> /// Draws the current subsprite on the screen. /// </summary> /// <param name="spriteBatch"></param> /// <param name="camera"></param> public void Draw(SpriteBatch spriteBatch, Camera camera) { Vector3 screenPos = camera.SpaceToScreenPosition(mPosition); Vector3 scale = camera.SpaceToScreenPosition(mPosition + Vector3.UnitX) - screenPos; scale *= mScale; var currentSpriteInt = (int) mCurrentSprite; var destRect = new Rectangle((int) (screenPos.X - mSpriteWidth / 2f * scale.X), (int) (screenPos.Y - mSpriteHeight / 2f * scale.X), (int) (mSpriteWidth * scale.X), (int) (mSpriteHeight * scale.X)); var sourceRect = new Rectangle((currentSpriteInt % mSpriteCollums) * mSpriteWidth, (currentSpriteInt / mSpriteRows) * mSpriteHeight, mSpriteWidth, mSpriteHeight); spriteBatch.Draw(mTexture, destRect, sourceRect, mColor); // proceed to next sprite mCurrentSprite += mSpeed; if (mCurrentSprite > mSpriteCollums * mSpriteRows) { if (mSelfDestruction) GraphicObjectManager.GetInstance().RemoveExplosion(this); else mCurrentSprite %= mSpriteCollums * mSpriteRows; } }
/// <summary> /// Inits the reference vars and the parallax effect /// </summary> /// <param name="device"></param> /// <param name="camera"></param> /// <param name="content"> </param> public void Init(GraphicsDevice device, Camera camera, ContentManager content) { mDevice = device; mContent = content; mSpriteBatch = new SpriteBatch(mDevice); mCamera = camera; mEffect = mContent.Load<Effect>("Shader/parallax"); }
public void Init(Camera camera, List<GraphicObject> list) { mCamera = camera; mGraphicObjects = list; mRectOriginX = Mouse.GetState().X; mRectOriginY = Mouse.GetState().Y; mRectSelectEnable = false; mSelectedObjects = new List<GraphicObject>(); }
public override void Draw(GraphicsDevice device, Camera camera) { Color color = Color.LightBlue; float width = 10 + (float) Math.Sin(mBeamWobble) * 2; mBeamWobble += 0.5f; var beam = mGameObject as Laser; if (beam == null) return; var startPos = new Vector3(beam.mStartPosition, 0); var endPos = new Vector3(beam.mTargetPosition, 0); Vector3 startPosSurface = startPos + 100 / (endPos - startPos).Length() * (endPos - startPos); Vector3 endPosSurface = endPos - 100 / (endPos - startPos).Length() * (endPos - startPos); double angle = Math.PI / 2 + Math.Atan2(endPos.Y - startPos.Y, endPos.X - startPos.X); Vector3 side = new Vector3((float) Math.Cos(angle), (float) Math.Sin(angle), 0) * width; mVertices[0] = new VertexPositionColor(startPosSurface, color); mVertices[1] = new VertexPositionColor(startPosSurface + side, Color.Transparent); mVertices[2] = new VertexPositionColor(endPosSurface + side, Color.Transparent); mVertices[3] = new VertexPositionColor(startPosSurface, color); mVertices[4] = new VertexPositionColor(endPosSurface + side, Color.Transparent); mVertices[5] = new VertexPositionColor(endPosSurface, color); mVertices[6] = new VertexPositionColor(startPosSurface, color); mVertices[7] = new VertexPositionColor(endPosSurface, color); mVertices[8] = new VertexPositionColor(endPosSurface - side, Color.Transparent); mVertices[9] = new VertexPositionColor(startPosSurface, color); mVertices[10] = new VertexPositionColor(endPosSurface - side, Color.Transparent); mVertices[11] = new VertexPositionColor(startPosSurface - side, Color.Transparent); Matrix worldMatrix = Matrix.CreateScale(mScale); mEffect.Parameters["World"].SetValue(worldMatrix); mEffect.Parameters["View"].SetValue(camera.mViewMatrix); mEffect.Parameters["Projection"].SetValue(camera.mProjectionMatrix); mEffect.Techniques[0].Passes[0].Apply(); device.BlendState = BlendState.AlphaBlend; device.DrawUserPrimitives(PrimitiveType.TriangleList, mVertices, 0, 4, VertexPositionColor.VertexDeclaration); }
public void Init(GraphicsDevice device, ContentManager content, GraphicObjectManager graphicObjMgr, Renderer renderer) { mSelectionManager.Init(renderer.GetCamera(), graphicObjMgr.GetList()); mSound.Init(content); graphicObjMgr.SetSoundRef(mSound); mGom = GameObjectManager.GetInstance(); mDevice = device; mRenderer = renderer; mCamera = mRenderer.GetCamera(); mInput.Init(); mInput.SetKey(new KeyAssignment(Keys.Escape, MenuSwitch)); mInput.SetKey(new KeyAssignment(Keys.F1, ShowHelpScreen)); mInput.SetKey(new KeyAssignment(Keys.F2, ShowStatsScreen)); mInput.SetKey(new KeyAssignment(Keys.F4, LoadGame)); mInput.SetKey(new KeyAssignment(Keys.F5, SaveGame)); mInput.SetKey(new KeyAssignment(Keys.LeftControl, LeftControlHelper)); mInput.SetKey(new KeyAssignment(Keys.RightControl, mSelectionManager.SetMultiSelection)); mInput.SetKey(new KeyAssignment(Keys.LeftShift, ShiftClickHelper)); mInput.SetKey(new KeyAssignment(Keys.W, mCamera.MoveCameraUp, false)); mInput.SetKey(new KeyAssignment(Keys.A, mCamera.MoveCameraLeft, false)); mInput.SetKey(new KeyAssignment(Keys.S, mCamera.MoveCameraDown, false)); mInput.SetKey(new KeyAssignment(Keys.D, mCamera.MoveCameraRight, false)); mInput.SetKey(new KeyAssignment(Keys.OemPlus, mCamera.ZoomIn, false)); mInput.SetKey(new KeyAssignment(Keys.OemMinus, mCamera.ZoomOut, false)); mInput.SetKey(new KeyAssignment(Keys.X, mInput.SetHotkey, 0)); // StarFleet/Interceptor mInput.SetKey(new KeyAssignment(Keys.C, mInput.SetHotkey, 1)); // MinionBoost/Predator mInput.SetKey(new KeyAssignment(Keys.V, mInput.SetHotkey, 2)); // Satelite/Defender mInput.SetKey(new KeyAssignment(Keys.B, mInput.SetHotkey, 3)); // Shield mInput.SetKey(new KeyAssignment(Keys.N, mInput.SetHotkey, 4)); // Deathstar mInput.SetKey(new KeyAssignment(Keys.F10, mRenderer.ToggleFogOfWar)); }
public Renderer() { mCamera = new Camera(); }
/// <summary> /// Draws the object on the screen. /// </summary> /// <param name="device"></param> /// <param name="camera"></param> public abstract void Draw(GraphicsDevice device, Camera camera);
/// <summary> /// Draws the model on the screen. /// </summary> /// <param name="device"></param> /// <param name="camera"></param> public override void Draw(GraphicsDevice device, Camera camera) { device.BlendState = BlendState.Opaque; device.DepthStencilState = DepthStencilState.Default; device.RasterizerState = RasterizerState.CullCounterClockwise; if (mGameObject is IMovable && !(mGameObject is DeathStar)) { //calc direction and angle Vector3 direction = GetPosition() - mLastPosition; if (direction != Vector3.Zero) { direction.Normalize(); var modelOrientation = new Vector3(0, 1, 0); float factor = (direction.X - modelOrientation.X) > 0 ? 1 : -1; var angle = (float) Math.Acos(Vector3.Dot(modelOrientation, direction)); mOrientationAngle = (float) Math.PI - angle * factor; } mLastPosition = GetPosition(); } if (mGameObject is Planet) mRot.Y += 0.001f; else if (mGameObject is Asteroid) { mRot.X += 0.001f; mRot.Y += 0.001f; mRot.Z += 0.001f; } Matrix worldMatrix = Matrix.CreateScale(mScale) * Matrix.CreateRotationX(mRot.X) * Matrix.CreateRotationY(mRot.Y) * Matrix.CreateRotationZ(mRot.Z + mOrientationAngle) * Matrix.CreateTranslation(GetPosition()); mEffect.Parameters["xWorldViewProjection"].SetValue(worldMatrix * camera.mViewMatrix * camera.mProjectionMatrix); mEffect.Parameters["xWorld"].SetValue(worldMatrix); mEffect.Parameters["xTexture"].SetValue(mTexture); mEffect.Parameters["xLightPos"].SetValue(GetPosition() + new Vector3(1, -1, 0) * 10000); mEffect.Parameters["xLightPower"].SetValue(2); mEffect.Parameters["xAmbient"].SetValue(0.2f); mEffect.CurrentTechnique = mEffect.Techniques["Simplest"]; if (!(mGameObject is DeathStar)) { foreach (ModelMesh modelMesh in mModel.Meshes) { foreach (ModelMeshPart modelMeshPart in modelMesh.MeshParts) { modelMeshPart.Effect = mEffect; } modelMesh.Draw(); } } else mModel.Draw(worldMatrix, camera.mViewMatrix, camera.mProjectionMatrix); }