public void render(GraphicsDevice device, ViewTransformations viewTrans) { _effect.CurrentTechnique = _effect.Techniques["Colored"]; Matrix worldMatrix = Matrix.CreateTranslation(new Vector3(0, 0, _size.Y)) * Matrix.CreateScale(2); _effect.Parameters["xWorld"].SetValue(worldMatrix); _effect.Parameters["xView"].SetValue(viewTrans.viewMatrix); _effect.Parameters["xProjection"].SetValue(viewTrans.projectionMatrix); _effect.Parameters["xEnableLighting"].SetValue(true); Vector3 lightDirection = new Vector3(1.0f, -1.0f, -1.0f); lightDirection.Normalize(); _effect.Parameters["xLightDirection"].SetValue(lightDirection); _effect.Parameters["xAmbient"].SetValue(0.2f); _effect.Begin(); foreach (EffectPass pass in _effect.CurrentTechnique.Passes) { pass.Begin(); device.Vertices[0].SetSource(_vertexBuffer, 0, VertexPositionNormalColored.SizeInBytes); device.Indices = _indexBuffer; device.VertexDeclaration = _vertexDeclaration; int noVertices = _vertexBuffer.SizeInBytes / VertexPositionNormalColored.SizeInBytes; int noTriangles = _indexBuffer.SizeInBytes / sizeof(int) / 3; device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, noVertices, 0, noTriangles); pass.End(); } _effect.End(); }
public void render(GraphicsDevice device, ViewTransformations viewTrans) { device.RenderState.DepthBufferWriteEnable = false; Matrix[] modelTransforms = new Matrix[_skyModel.Bones.Count]; _skyModel.CopyAbsoluteBoneTransformsTo(modelTransforms); Matrix wMatrix = Matrix.CreateTranslation(0, -0.3f, 0) * Matrix.CreateScale(100) * Matrix.CreateTranslation(viewTrans.cameraPosition); foreach (ModelMesh mesh in _skyModel.Meshes) { foreach (Effect currentEffect in mesh.Effects) { Matrix worldMatrix = modelTransforms[mesh.ParentBone.Index] * wMatrix; currentEffect.CurrentTechnique = currentEffect.Techniques["SkyDome"]; currentEffect.Parameters["xWorld"].SetValue(worldMatrix); currentEffect.Parameters["xView"].SetValue(viewTrans.viewMatrix); currentEffect.Parameters["xProjection"].SetValue(viewTrans.projectionMatrix); currentEffect.Parameters["xTexture"].SetValue(_skyMap); currentEffect.Parameters["xEnableLighting"].SetValue(false); } mesh.Draw(); } device.RenderState.DepthBufferWriteEnable = true; }
public void render(GraphicsDevice device, ViewTransformations viewTrans) { device.RenderState.DepthBufferWriteEnable = true; Matrix[] transforms = new Matrix[_carModel.Bones.Count]; _carModel.CopyAbsoluteBoneTransformsTo(transforms); Matrix wMatrix = Matrix.CreateScale(2.8f) * Matrix.CreateFromQuaternion(_rotation) * Matrix.CreateTranslation(_position); foreach (ModelMesh mesh in _carModel.Meshes) { foreach (BasicEffect effect in mesh.Effects) { effect.EnableDefaultLighting(); effect.World = transforms[mesh.ParentBone.Index] * wMatrix; effect.View = viewTrans.viewMatrix; effect.Projection = viewTrans.projectionMatrix; } mesh.Draw(); } _boundingSphere.Transform(wMatrix); device.RenderState.DepthBufferWriteEnable = true; }