예제 #1
0
        public void drawMesh(Model myModel, Vector3 modelPosition, float modelRotation, Camera camera)
        {
            float aspectRatio = (float)Tools.Quick.graphics.GraphicsDevice.Viewport.Width /
               (float)Tools.Quick.graphics.GraphicsDevice.Viewport.Height;
            // Copy any parent transforms.
            Matrix[] transforms = new Matrix[myModel.Bones.Count];
            myModel.CopyAbsoluteBoneTransformsTo(transforms);
            Tools.Quick.device.RasterizerState = RasterizerState.CullNone;  // vertex order doesn't matter
            Tools.Quick.device.BlendState = BlendState.Opaque;    // use alpha blending
            Tools.Quick.device.DepthStencilState = DepthStencilState.Default;  // don't bother with the depth/stencil buffer

            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in myModel.Meshes)
            {
                // This is where the mesh orientation is set, as well as our camera and projection.
                foreach (BasicEffect effect in mesh.Effects)
                {
                    effect.EnableDefaultLighting();
                    effect.World = transforms[mesh.ParentBone.Index] * Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition); //modelPosition
                    effect.View = camera.getview();
                    effect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(45.0f),

                        aspectRatio, 1.0f, 1000000.0f);

                }
                // Draw the mesh, using the effects set above.
                mesh.Draw();
            }
        }
예제 #2
0
        public void drawBigbuffer(DrawabeElement element, int[] index, Camera came, GraphicsDevice graphicsDevice, bool trans)
        {
            WIREFRAME_RASTERIZER_STATE = new RasterizerState() { CullMode = CullMode.CullClockwiseFace, FillMode = FillMode.Solid };

            graphicsDevice.RasterizerState = WIREFRAME_RASTERIZER_STATE;

            // draw in wireframe

            if (trans)
            {
                graphicsDevice.BlendState = BlendState.AlphaBlend;

            }
            else
            {
                graphicsDevice.BlendState = BlendState.Opaque;
            }

            graphicsDevice.DepthStencilState = DepthStencilState.Default;

            //   effect.DiffuseColor = Color.Red.ToVector3();
            element.effect.View = came.getview();
            element.effect.CurrentTechnique.Passes[0].Apply();
            // vb.GetData<VertexPositionNormalTexture>(vertexData);

            graphicsDevice.DrawUserPrimitives(PrimitiveType.TriangleList, element.vpc, 0, element.vpc.Count() / 3);
            // graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexData, 0, vertexData.Count(), index, 0, index.Count() / 3);
        }
예제 #3
0
        public void DrawClippedSky(GraphicsDevice device, Effect effect, Camera camera)
        {
            DepthStencilState s = new DepthStencilState();
            s.DepthBufferWriteEnable = false;
            DepthStencilState bak = device.DepthStencilState;
            device.DepthStencilState = s;
            device.RasterizerState = new RasterizerState() { CullMode = CullMode.None, FillMode = FillMode.Solid };

            Matrix wMatrix = Matrix.CreateScale(scale) * Matrix.CreateTranslation(camera.position);

            effect.CurrentTechnique = effect.Techniques["SkyBox"];
            effect.Parameters["xView"].SetValue(camera.getview());
            effect.Parameters["xProjection"].SetValue(camera.GetProjection());
            effect.Parameters["xWorld"].SetValue(wMatrix);
            effect.Parameters["xCamPos"].SetValue(camera.position);
            effect.Parameters["xSkyBoxTexture"].SetValue(cloudMap);
            effect.Parameters["xEnableLighting"].SetValue(false);
            //currentEffect.Parameters["xClipping"].SetValue(true);

            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.SetVertexBuffer(vertexBuffer);
                device.Indices = indexBuffer;
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, indexBuffer.IndexCount, 0, indexBuffer.IndexCount / 3);
            }

            device.DepthStencilState = bak;
        }
예제 #4
0
        public void DrawRefractionMap(Camera c)
        {
            viewMatrix = c.getview();
            projectionMatrix = c.GetProjection();
            cameraPosition = c.position;

            Plane refractionPlane = CreatePlane(waterHeight + 50f, new Vector3(0, -1, 0), viewMatrix, projectionMatrix, false);
            effect.CurrentTechnique = effect.Techniques["Textured"];
            effect.Parameters["xClipPlane0"].SetValue(new Vector4(refractionPlane.Normal, refractionPlane.D));
            effect.Parameters["xClipping"].SetValue(true);

            device.SetRenderTarget(refractionRenderTarget);

            device.DepthStencilState = new DepthStencilState();
            device.Clear(ClearOptions.Target | ClearOptions.DepthBuffer, Color.CornflowerBlue, 5.0f, 0);

            ground.DrawClippedGround(device, effect, c);

            effect.Parameters["xClipping"].SetValue(false);

            device.SetRenderTarget(null);

            refractionMap = (Texture2D)refractionRenderTarget;
        }
예제 #5
0
        public void DrawClippedGround(GraphicsDevice device, Effect effect, Camera camera)
        {
            effect.CurrentTechnique = effect.Techniques["MultiTextured"];
            effect.Parameters["xTexturesMap"].SetValue(biomeTexture);
            effect.Parameters["xView"].SetValue(camera.getview());
            effect.Parameters["xProjection"].SetValue(camera.GetProjection());
            effect.Parameters["xWorld"].SetValue(Matrix.Identity);

            device.RasterizerState = new RasterizerState() { CullMode = CullMode.CullClockwiseFace, FillMode = FillMode.Solid };
            device.BlendState = BlendState.Opaque;
            device.DepthStencilState = DepthStencilState.Default;

            //effect.Parameters["xTexture"].SetValue(Tools.Quick.groundTexture[gt]);
            foreach (EffectPass pass in effect.CurrentTechnique.Passes)
            {
                pass.Apply();
                device.SetVertexBuffer(GroundVertices);
                device.Indices = GroundIndices;
                device.DrawIndexedPrimitives(PrimitiveType.TriangleList, 0, 0, GroundIndices.IndexCount, 0, GroundIndices.IndexCount / 3);
            }
        }
예제 #6
0
        public void drawSquarre(VertexPositionNormalTexture[] vertexData, int[] indexData, Camera came, BasicEffect effect, GraphicsDevice graphicsDevice)
        {
            Texture2D texture = Tools.Quick.groundTexture[BiomeType.SubtropicalDesert];
            effect.Projection = projectionMatrix;
            effect.Texture = texture;
            effect.TextureEnabled = true; ;

            graphicsDevice.RasterizerState = WIREFRAME_RASTERIZER_STATE;    // draw in wireframe
            graphicsDevice.BlendState = BlendState.Opaque;                  // no alpha this time

            //   effect.DiffuseColor = Color.Red.ToVector3();
            effect.CurrentTechnique.Passes[0].Apply();

            effect.View = came.getview();
            effect.CurrentTechnique.Passes[0].Apply();
            graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexData, 0, 4, indexData, 0, 2);

            /*  // Draw wireframe box
              graphicsDevice.RasterizerState = WIREFRAME_RASTERIZER_STATE;    // draw in wireframe
              graphicsDevice.BlendState = BlendState.Opaque;                  // no alpha this time

              effect.TextureEnabled = false;
             // effect.DiffuseColor = Color.Black.ToVector3();
              effect.CurrentTechnique.Passes[0].Apply();

              graphicsDevice.DrawUserIndexedPrimitives(PrimitiveType.TriangleList, vertexData, 0, 4, indexData, 0, 2);
                 */
        }