public override void Draw(GameTime gameTime) { Prepare3DRenderer.PrepareGraphicsDevice(); Game.GraphicsDevice.SamplerStates[0] = SamplerState.LinearClamp; //draw the skybox Game.GraphicsDevice.DepthStencilState = DepthStencilState.DepthRead; skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms); foreach (ModelMesh mesh in skyboxModel.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.World = skyboxTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(_camera.Position); effect.View = _camera.View; effect.Projection = _camera.Projection; } mesh.Draw(); } GraphicsDevice.DepthStencilState = DepthStencilState.Default; base.Draw(gameTime); }
public override void Draw(GameTime gameTime) { Prepare3DRenderer.PrepareGraphicsDevice(); GraphicsDevice.SamplerStates[0] = SamplerState.LinearWrap; GraphicsDevice.RasterizerState = actualRasterizer; _effect.World = Matrix.Identity; _effect.View = _camera.View; _effect.Projection = _camera.Projection; _effect.EnableDefaultLighting(); _effect.DirectionalLight0.Direction = new Vector3(1, -1, 1); _effect.DirectionalLight0.Enabled = true; _effect.AmbientLightColor = new Vector3(0.3f, 0.3f, 0.3f); _effect.DirectionalLight1.Enabled = false; _effect.DirectionalLight2.Enabled = false; _effect.SpecularColor = new Vector3(0, 0, 0); _effect.PreferPerPixelLighting = false; _effect.Texture = _texture; _effect.TextureEnabled = true; _effect.FogEnabled = false; _effect.FogColor = new Vector3(1, 0, 0); _effect.FogStart = 1; _effect.FogEnd = 250; if (_showNormals) { GraphicsDevice.DrawUserPrimitives(PrimitiveType.LineList, _normalsList, 0, _normalsList.Length / 2); } GraphicsDevice.SetVertexBuffer(_vertexBuffer); GraphicsDevice.Indices = _indexBuffer; foreach (EffectPass pass in _effect.CurrentTechnique.Passes) { pass.Apply(); GraphicsDevice.DrawIndexedPrimitives(PrimitiveType.TriangleStrip, 0, 0, _width * _height, 0, _width * 2 * (_height - 1) - 2); } base.Draw(gameTime); }
public override void Draw(GameTime gameTime) { Prepare3DRenderer.PrepareGraphicsDevice(); basicEffect.CurrentTechnique.Passes[0].Apply(); basicEffect.World = Matrix.Identity; basicEffect.View = _camera.View; basicEffect.Projection = _camera.Projection; GraphicsDevice.DrawUserPrimitives <VertexPositionColor>(PrimitiveType.LineList, vertices, 0, 3); base.Draw(gameTime); }
public override void DrawModel(Camera camera) { Prepare3DRenderer.PrepareGraphicsDevice(); // Set the world matrix as the root transform of the model. //_model.Root.Transform = Matrix.CreateScale(_scale) * _orientation * Matrix.CreateTranslation(Position); leftBackWheelBone.Transform = _wheelRollMatrix * leftBackWheelTransform; rightBackWheelBone.Transform = _wheelRollMatrix * rightBackWheelTransform; leftFrontWheelBone.Transform = _wheelRollMatrix * leftFrontWheelTransform; rightFrontWheelBone.Transform = _wheelRollMatrix * rightFrontWheelTransform; _model.CopyAbsoluteBoneTransformsTo(_boneTransforms); Matrix worldMatrix = _orientation * Matrix.CreateTranslation(Position); Matrix turretMatrix = _turretOrientation * Matrix.CreateTranslation(Position); Matrix canonMatrix = Matrix.CreateScale(_scale) * _canonOrientation * Matrix.CreateTranslation(Position); _model.CopyAbsoluteBoneTransformsTo(_boneTransforms); WZGame.GraphicsDevice.BlendState = BlendState.AlphaBlend; foreach (ModelMesh mesh in _model.Meshes) { foreach (BasicEffect effect in mesh.Effects) { switch (mesh.Name) { case "canon_geo": //effect.World = _boneTransforms[mesh.ParentBone.Index] * canonMatrix; effect.World = _boneTransforms[mesh.ParentBone.Index] * turretMatrix; break; case "hatch_geo": case "turret_geo": effect.World = _boneTransforms[mesh.ParentBone.Index] * turretMatrix; break; default: effect.World = _boneTransforms[mesh.ParentBone.Index] * worldMatrix; break; } //effect.World = _boneTransforms[mesh.ParentBone.Index]; effect.View = camera.View; effect.Projection = camera.Projection; effect.EnableDefaultLighting(); effect.PreferPerPixelLighting = true; if (IsGhost) { effect.Alpha = 0.5f; } else { effect.Alpha = 1f; } if (isAiEnemy) { effect.SpecularColor = _specularColor_red; } else { effect.SpecularColor = _specularColor_original; } } mesh.Draw(); } WZGame.GraphicsDevice.BlendState = BlendState.Opaque; }
/// <summary> /// Allows the game to perform any initialization it needs to before starting to run. /// This is where it can query for any required services and load any non-graphic /// related content. Calling base.Initialize will enumerate through any components /// and initialize them as well. /// </summary> protected override void Initialize() { Window.Title = "WarZ v" + System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; Prepare3DRenderer.Initialize(this); Song mainTheme = Content.Load <Song>(@"Music/main1"); MediaPlayer.Play(mainTheme); MediaPlayer.Volume *= 0.7f; _fpsCamera = new FPSCamera(this, new Vector3(0, 10, 3), Vector3.Zero, Vector3.Up); _topViewCamera = new TopViewCamera(this, new Vector3(0, 10, 0), Vector3.Zero, Vector3.Forward); // _chaseCamera = new ChaseCamera(this, new Vector3(0, 10, 3), Vector3.Zero, Vector3.Up); SimpleCamera simpleCam = new SimpleCamera(this, Vector3.Zero, Vector3.Forward, Vector3.Up); _aiCamera = new SimpleCamera(this, Vector3.Backward, Vector3.Zero, Vector3.Up); GodViewCamera godView = new GodViewCamera(this, Vector3.Up * 50, Vector3.Forward * 62.5f + Vector3.Right * 62.5f, Vector3.Up); _cameras = new Camera[3]; _cameras[0] = _fpsCamera; _cameras[1] = _topViewCamera; _cameras[2] = godView; cameraNumber = 0; _activeCamera = _fpsCamera; _3DAxis = new Axis(this, _activeCamera); _GUI = new GUIManager(this); _GUI.CrossairVisible = true; Terrain = new Terrain(this, _activeCamera); _skybox = new Skybox(this, _activeCamera); Tank tank = new Tank(this, Content.Load <Model>(@"Models\Tank\DXTank")); Player1 = new Player(this, _activeCamera, tank, Terrain); _aiPlayerManager = new AiPlayerManager(this, tank); _collisionSystem = new CollisionSystem(this, _player1, _aiPlayerManager); _particlesManager = new ParticlesManager(this); Components.Add(_skybox); //Components.Add(_activeCamera); Components.Add(Player1); Components.Add(_3DAxis); Components.Add(Terrain); Components.Add(_aiPlayerManager); Components.Add(_collisionSystem); Components.Add(_particlesManager); Components.Add(_GUI); _aiPlayerManager.AddBot(_aiCamera, Vector3.Backward * 10 + Vector3.Right * 20); _aiPlayerManager.AddBot(_aiCamera, Vector3.Backward * 10 + Vector3.Right * 10); _aiPlayerManager.AddBot(_aiCamera, Vector3.Backward * 10 + Vector3.Right * 10); _aiPlayerManager.AddBot(_aiCamera, Vector3.Backward * 10 + Vector3.Right * 10); _aiPlayerManager.AddBot(_aiCamera, Vector3.Backward * 10 + Vector3.Right * 10); base.Initialize(); }