Пример #1
0
 public Crane(Game game, Camera camera)
     : base(game)
 {
     // TODO: Construct any child components here
     input = (IInputHandler)Game.Services.GetService(typeof(IInputHandler));
     this.camera = camera;
 }
Пример #2
0
        public CubesGame()
        {
            graphics = new GraphicsDeviceManager(this);
            Content.RootDirectory = "Content";

            input = new InputHandler(this);
            this.Components.Add(input);

            theCamera = new Camera(this);
            this.Components.Add(theCamera);

            theCrane = new Crane(this, theCamera);
            this.Components.Add(theCrane);

            theHook = new Hook(this);
            this.Components.Add(theHook);

            theTerrain = new Terrain(this);
            this.Components.Add(theTerrain);

            theSky = new SkyDome(this);
            this.Components.Add(theSky);

            theCity = new Building(this);
            this.Components.Add(theCity);

            theSmokeEffect = new SmokeEffect(this);
            this.Components.Add(theSmokeEffect);
        }
Пример #3
0
        /// <summary>
        /// Tegner kuben
        /// </summary>
        /// <param name="world">Verdensmatrisen kuben skal tegnes i dersom den er plukket opp</param>
        /// <param name="camera">Spillets kamera</param>
        public void Draw(Matrix world, Camera camera)
        {
            Matrix matWorld, matCubeTrans, matScale;

            matWorld = Matrix.Identity;
            if (hooked)
            {
                matScale = Matrix.CreateScale(5.0f);
                matCubeTrans = Matrix.CreateTranslation(new Vector3(0.0f, -65.0f, 0.0f));
                matWorld = matScale * matCubeTrans * world;

            }
            else
            {
                    matWorld =  Matrix.CreateTranslation(position);
            }
            if (!position.Equals(matWorld.Translation))
                position = matWorld.Translation;

            this.world = matWorld;

            effect.CurrentTechnique = effect.Techniques["PhongTexturedShader"];

            Matrix[] modelTransformations = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(modelTransformations);

            foreach (ModelMesh mm in model.Meshes)
            {
                foreach (Effect currentEffect in mm.Effects)
                {
                    // Setter alle parameterene til effekten.
                    currentEffect.CurrentTechnique = effect.CurrentTechnique;
                    currentEffect.Parameters["xWorld"].SetValue(modelTransformations[mm.ParentBone.Index] * matWorld);
                    currentEffect.Parameters["xView"].SetValue(camera.View);
                    currentEffect.Parameters["xProjection"].SetValue(camera.Projection);
                    currentEffect.Parameters["xEnableLightingTexture"].SetValue(true);
                    currentEffect.Parameters["xDiffuseLight"].SetValue(LightSettings.DiffuseLight);
                    currentEffect.Parameters["xDiffuseMaterial"].SetValue(LightSettings.DiffuseMaterial);
                    currentEffect.Parameters["xAmbientLight"].SetValue(LightSettings.AmbientLight);
                    currentEffect.Parameters["xAmbientMaterial"].SetValue(LightSettings.AmbientMaterial);
                    currentEffect.Parameters["xLightDirection"].SetValue(LightSettings.LightDirection);

                    if (mm.Name.Equals("Box"))
                        currentEffect.Parameters["xTexture"].SetValue(textureSide);
                    else
                        currentEffect.Parameters["xTexture"].SetValue(textureTop);
                }
                mm.Draw();
            }

            //model.Draw(matWorld, camera.View, camera.Projection);
        }
Пример #4
0
 public void Draw(Effect effect, Camera camera, GraphicsDevice device)
 {
     // Only draw if there are live particles
     if (endOfLiveParticlesIndex - endOfDeadParticlesIndex > 0)
     {
         // Set HLSL parameters
         effect.Parameters["WorldViewProjection"].SetValue(camera.View * camera.Projection);
         // Draw particles
         foreach (EffectPass pass in effect.CurrentTechnique.Passes)
         {
             pass.Apply();
             device.DrawUserPrimitives(PrimitiveType.TriangleList, vertexes, endOfDeadParticlesIndex * 3, endOfLiveParticlesIndex - endOfDeadParticlesIndex, ParticleVertex.VertexDeclaration);
         }
     }
 }
Пример #5
0
        public void Draw(Camera camera, GraphicsDevice device)
        {
            explosionEffect.CurrentTechnique = explosionEffect.Techniques["Technique1"];
            explosionEffect.Parameters["theTexture"].SetValue(explosionTexture);

            foreach (ParticleExplosion explosion in explosions)
            {
                explosion.Draw(explosionEffect, camera, device);
            }
        }
Пример #6
0
        /// <summary>
        /// Draws the crane.
        /// </summary>
        /// <param name="gametime">Provides a snapshot of timing values</param>
        /// <param name="camera">Camera to draw object in correct areas</param>
        /// <param name="world">World matrix for translations, if neccesary</param>
        /// <returns name="world">The generated world matrix</returns>
        public Matrix Draw(GameTime gametime, Camera camera, Matrix world)
        {
            Matrix matY, matTrans, matScale;

            //Transformerer krana.
            matY = Matrix.CreateRotationY(rotation);
            matTrans = Matrix.CreateTranslation(0.0f, 0.0f, 0.0f);
            matScale = Matrix.CreateScale(0.01f);
            world = matScale * matY * matTrans;

            effect.CurrentTechnique = effect.Techniques["PhongTexturedShader"];

            Matrix[] modelTransformations = new Matrix[theCraneModel.Bones.Count];
            theCraneModel.CopyAbsoluteBoneTransformsTo(modelTransformations);

            foreach (ModelMesh mm in theCraneModel.Meshes)
            {
                foreach (Effect currentEffect in mm.Effects)
                {
                    // Setter alle parameterene til effekten.
                    currentEffect.CurrentTechnique = effect.CurrentTechnique;
                    currentEffect.Parameters["xWorld"].SetValue(modelTransformations[mm.ParentBone.Index] * world);
                    currentEffect.Parameters["xView"].SetValue(camera.View);
                    currentEffect.Parameters["xProjection"].SetValue(camera.Projection);
                    currentEffect.Parameters["xEnableLightingTexture"].SetValue(true);
                    currentEffect.Parameters["xDiffuseLight"].SetValue(LightSettings.DiffuseLight);
                    currentEffect.Parameters["xDiffuseMaterial"].SetValue(LightSettings.DiffuseMaterial);
                    currentEffect.Parameters["xAmbientLight"].SetValue(LightSettings.AmbientLight);
                    currentEffect.Parameters["xAmbientMaterial"].SetValue(LightSettings.AmbientMaterial);
                    currentEffect.Parameters["xLightDirection"].SetValue(LightSettings.LightDirection);

                    //Sjekker hvilken del av krana, setter så teksturen til elementet.
                    if (mm.Name.Equals("Weight"))
                        currentEffect.Parameters["xTexture"].SetValue(theWeightTexture);
                    else if (mm.Name.Equals("Base"))
                        currentEffect.Parameters["xTexture"].SetValue(theBaseTexture);
                    else if (mm.Name.Equals("TopWire"))
                        currentEffect.Parameters["xTexture"].SetValue(theWireTexture);
                    else
                        currentEffect.Parameters["xTexture"].SetValue(theCraneTexture);
                }

                mm.Draw();
            }

            return world;
        }
Пример #7
0
        /// <summary>
        /// Tegner kroken og vaieren.
        /// </summary>
        /// <param name="gametime">Provides a snapshot of timing values</param>
        /// <param name="camera">Camera to draw object in correct areas</param>
        /// <param name="world">World matrix for translations, if neccesary</param>
        /// <returns name="world">The generated world matrix</returns>
        public Matrix Draw(GameTime gametime, Camera camera, Matrix _world, float craneRotation)
        {
            Matrix matHookTrans, matHookScale, matHookOrbit, hookWorld, matWireScale, matWireTrans, matWireOrb, wireWorld;

            //Transformerer Kroken
            matHookScale = Matrix.CreateScale(20.0f);
            matHookTrans = Matrix.CreateTranslation(0.0f, 80.0f - position.Y, position.X);
            matHookOrbit = matHookTrans * Matrix.CreateRotationY(craneRotation);
            hookWorld = _world * matHookScale * matHookOrbit;

            //Transformerer vaieren
            matWireScale = Matrix.CreateScale(new Vector3(5.0f, position.Y*2, 5.0f));
            matWireTrans = Matrix.CreateTranslation(0.0f, 86.0f - position.Y, position.X);
            matWireOrb = matWireTrans * Matrix.CreateRotationY(craneRotation);
            wireWorld = _world * matWireScale * matWireOrb;

            world = hookWorld;

            effect.CurrentTechnique = effect.Techniques["PhongTexturedShader"];

            Matrix[] modelTransformations = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(modelTransformations);

            #region Magnet foreach
            foreach (ModelMesh mm in model.Meshes)
            {
                foreach (Effect currentEffect in mm.Effects)
                {
                    // Setter alle parameterene til effekten.
                    currentEffect.CurrentTechnique = effect.CurrentTechnique;
                    currentEffect.Parameters["xWorld"].SetValue(modelTransformations[mm.ParentBone.Index] * hookWorld);
                    currentEffect.Parameters["xView"].SetValue(camera.View);
                    currentEffect.Parameters["xProjection"].SetValue(camera.Projection);
                    currentEffect.Parameters["xEnableLightingTexture"].SetValue(true);
                    currentEffect.Parameters["xDiffuseLight"].SetValue(LightSettings.DiffuseLight);
                    currentEffect.Parameters["xDiffuseMaterial"].SetValue(LightSettings.DiffuseMaterial);
                    currentEffect.Parameters["xAmbientLight"].SetValue(LightSettings.AmbientLight);
                    currentEffect.Parameters["xAmbientMaterial"].SetValue(LightSettings.AmbientMaterial);
                    currentEffect.Parameters["xLightDirection"].SetValue(LightSettings.LightDirection);

                    currentEffect.Parameters["xTexture"].SetValue(magnetTexture);

                }
                mm.Draw();
            }
            #endregion

            theWireModel.Draw(wireWorld, camera.View, camera.Projection);

            return hookWorld;
        }