public void Draw(CameraComponent camera, GraphicsDevice device) { SamplerState ss = new SamplerState(); ss.AddressU = TextureAddressMode.Clamp; ss.AddressV = TextureAddressMode.Clamp; device.SamplerStates[0] = ss; DepthStencilState dss = new DepthStencilState(); dss.DepthBufferEnable = false; device.DepthStencilState = dss; Matrix[] skyboxTransforms = new Matrix[skyboxModel.Bones.Count]; skyboxModel.CopyAbsoluteBoneTransformsTo(skyboxTransforms); int i = 0; foreach (ModelMesh mesh in skyboxModel.Meshes) { foreach (Effect currentEffect in mesh.Effects) { Matrix worldMatrix = skyboxTransforms[mesh.ParentBone.Index] * Matrix.CreateTranslation(camera.Position); currentEffect.CurrentTechnique = currentEffect.Techniques["Textured"]; currentEffect.Parameters["xWorld"].SetValue(worldMatrix); currentEffect.Parameters["xView"].SetValue(camera.ViewMatrix); currentEffect.Parameters["xProjection"].SetValue(camera.ProjectionMatrix); currentEffect.Parameters["xTexture"].SetValue(skyboxTextures[i++]); } mesh.Draw(); } dss = new DepthStencilState(); dss.DepthBufferEnable = true; device.DepthStencilState = dss; }
/// <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() { //This will get overridden in the LevelManager constructor camera = new CameraComponent(this, Vector3.Zero); Components.Add(camera); base.Initialize(); }
/// <summary> /// Method to draw the character on the screen /// at its location /// </summary> /// <param name="c"></param> public void Draw(CameraComponent c) { Matrix[] transforms = new Matrix[model.Bones.Count]; model.CopyAbsoluteBoneTransformsTo(transforms); foreach (ModelMesh mesh in model.Meshes) { foreach (BasicEffect be in mesh.Effects) { be.EnableDefaultLighting(); be.Projection = c.ProjectionMatrix; be.View = c.ViewMatrix; be.World = GetWorld() * mesh.ParentBone.Transform; } mesh.Draw(); } }