Пример #1
0
        private void SetupScene()
        {
            RenderTechnique = new RenderTechnique("RenderCustom");

            WhiteMaterial = new PhongMaterial
            {
                Name              = "White",
                AmbientColor      = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0),
                DiffuseColor      = defaultMaterialColor,
                SpecularColor     = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0),
                EmissiveColor     = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0),
                SpecularShininess = 12.8f,
            };

            SelectedMaterial = new PhongMaterial
            {
                Name              = "White",
                AmbientColor      = PhongMaterials.ToColor(0.1, 0.1, 0.1, 1.0),
                DiffuseColor      = defaultSelectionColor,
                SpecularColor     = PhongMaterials.ToColor(0.0225, 0.0225, 0.0225, 1.0),
                EmissiveColor     = PhongMaterials.ToColor(0.0, 0.0, 0.0, 1.0),
                SpecularShininess = 12.8f,
            };

            Model1Transform = new TranslateTransform3D(0, -0, 0);

            // camera setup
            Camera = new PerspectiveCamera();

            SetCameraData(new CameraData());

            DrawGrid();
        }
Пример #2
0
 /// <summary>
 /// Draw all projectiles
 /// </summary>
 public void Draw(GraphicsDevice gd, RenderTechnique technique, 
     Vector3 cameraPosition, Matrix viewProjection, LightList lights)
 {
     // draw all projectiles
     foreach(Projectile p in projectiles)
         p.Draw(game, gd, technique, cameraPosition, viewProjection, lights);
 }
Пример #3
0
 /// <summary>
 /// Draw all powerups
 /// </summary>
 public void Draw(GraphicsDevice gd, RenderTechnique technique,
                  Vector3 cameraPosition, Matrix viewProjection, LightList lights)
 {
     // draw all powerups
     foreach (Powerup p in powerups)
     {
         p.Draw(game, gd, technique, cameraPosition, viewProjection, lights);
     }
 }
Пример #4
0
 /// <summary>
 /// Renders the player ship model and
 /// blaster and missile if available and charged
 /// </summary>
 public void Draw(GraphicsDevice gd, RenderTechnique technique,
                  Vector3 cameraPosition, Matrix viewProjection, LightList lights)
 {
     // if not dead
     if (deadTime == 0.0f)
     {
         // render ship model
         gameManager.DrawModel(gd, shipModel, technique, cameraPosition,
                               bobbing * transform, viewProjection, lights);
     }
 }
Пример #5
0
        public void Tick(float dtime)
        {
            if (I.Status != EngineStatus.LoadedWorld ||
                RenderTechnique.IsNotSet() ||
                !RenderTechnique.IsInitialized)
            {
                return;
            }

            RenderTechnique.Simulate(dtime);
            RenderTechnique.Render();
            GameWindow.SwapBuffers();
        }
Пример #6
0
        /// <summary>
        /// Draw powerup
        /// </summary>
        public void Draw(GameManager game, GraphicsDevice gd,
                         RenderTechnique technique, Vector3 cameraPosition,
                         Matrix viewProjection, LightList lights)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }

            // if now waiting to respawn
            if (waitTime == 0)
            {
                // draw powerup model
                game.DrawModel(gd, model, technique, cameraPosition,
                               bobbing * transform, viewProjection, lights);
            }
        }
Пример #7
0
        /// <summary>
        /// Draw powerup
        /// </summary>
        public void Draw(GameManager game, GraphicsDevice gd, 
            RenderTechnique technique, Vector3 cameraPosition,
            Matrix viewProjection, LightList lights)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }

            // if now waiting to respawn
            if (waitTime == 0)
            {
                // draw powerup model
                game.DrawModel(gd, model, technique, cameraPosition,
                    bobbing * transform, viewProjection, lights);
            }
        }
Пример #8
0
        /// <summary>
        /// Draw projectile
        /// </summary>
        public void Draw(GameManager game, GraphicsDevice gd,
                         RenderTechnique defaultTechnique, Vector3 cameraPosition,
                         Matrix viewProjection, LightList lights)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }

            if (technique == RenderTechnique.ViewMapping)
            {
                game.DrawModel(gd, model, technique,
                               cameraPosition, transform, viewProjection, null);
            }
            else
            {
                game.DrawModel(gd, model, defaultTechnique,
                               cameraPosition, transform, viewProjection, lights);
            }
        }
Пример #9
0
        /// <summary>
        /// Draw projectile
        /// </summary>
        public void Draw(GameManager game, GraphicsDevice gd,
            RenderTechnique defaultTechnique, Vector3 cameraPosition,
            Matrix viewProjection, LightList lights)
        {
            if (game == null)
            {
                throw new ArgumentNullException("game");
            }

            if (technique == RenderTechnique.ViewMapping)
            {
                game.DrawModel(gd, model, technique,
                        cameraPosition, transform, viewProjection, null);
            }
            else
            {
                game.DrawModel(gd, model, defaultTechnique,
                        cameraPosition, transform, viewProjection, lights);
            }
        }
Пример #10
0
        Matrix transform; // current projectile transform matrix

        #endregion Fields

        #region Constructors

        /// <summary>
        /// Create a new projectile
        /// </summary>
        public Projectile(
            ProjectileType type, Model model,
            int player, float velocity, float damage,
            Matrix source, Vector3 destination,
            RenderTechnique technique)
        {
            projectileType = type;
            this.model = model;
            this.player = player;

            sourcePosition = source.Translation;
            destinationPosition = destination;

            this.technique = technique;

            contactDamage = damage;

            elapsedTime = 0;
            totalTime = (source.Translation - destination).Length() / velocity;
            transform = source;
        }
Пример #11
0
        Matrix systemTransform;          // local transform to position particle system

        /// <summary>
        /// Create a new projectile
        /// </summary>
        public Projectile(
            ProjectileType type, Model model,
            int player, float velocity, float damage,
            Matrix source, Vector3 destination,
            RenderTechnique technique)
        {
            projectileType = type;
            this.model     = model;
            this.player    = player;

            sourcePosition      = source.Translation;
            destinationPosition = destination;

            this.technique = technique;

            contactDamage = damage;

            elapsedTime = 0;
            totalTime   = (source.Translation - destination).Length() / velocity;
            transform   = source;
        }
        public void AddRenderTechnique(string techniqueName, byte[] techniqueSource)
        {
            var technique = new RenderTechnique(techniqueName);
            if (!TechniquesSourceDict.ContainsKey(technique))
            {
                TechniquesSourceDict.Add(technique, techniqueSource);
            }

            renderTechniques.Add(techniqueName, technique);
        }
Пример #13
0
        /// <summary>
        /// Create a new projectile and add it to the projectile manager
        /// </summary>
        public Projectile AddProjectile(
            ProjectileType type,
            int player,
            Matrix transform,
            float velocity,
            float damage,
            RenderTechnique technique)
        {
            // get source and destination positions for projectile
            Vector3 source = transform.Translation;
            Vector3 destination = source + transform.Forward * 10000;

            // ray intersect level to find out where projetile is going to hit
            float hitDist;
            Vector3 hitPos, hitNormal;
            if (levelCollision.PointIntersect(source, destination,
                                        out hitDist, out hitPos, out hitNormal))
                destination = hitPos;
            else
                hitNormal = transform.Backward;

            // create projectile
            Projectile p = new Projectile(type, projectileModels[(int)type],
                player, velocity, damage, transform, destination, technique);

            // add it to the projectile manager
            projectile.Add(p);

            return p;
        }
Пример #14
0
        /// <summary>
        /// Draw the 3D game scene
        /// </summary>
        void DrawScene(GraphicsDevice gd, RenderTechnique technique)
        {
            if (gd == null)
            {
                throw new ArgumentNullException("gd");
            }

            if (gameMode == GameMode.SinglePlayer)
            {
                // camera position and view projection matrix
                Vector3 cameraPosition = players[0].CameraPosition;
                Matrix viewProjection = players[0].ViewMatrix * projectionFull;

                // draw the level geomery
                DrawModel(gd, levelColor, technique, cameraPosition,
                    Matrix.Identity, viewProjection, levelLights);

                // if in 3rd person mode draw player ship
                bool camera3rdPerson = players[0].Camera3rdPerson;
                if (camera3rdPerson)
                    players[0].Draw(gd, technique,
                        cameraPosition, viewProjection, levelLights);

                // draw projectiles
                projectile.Draw(gd, technique, cameraPosition, viewProjection,
                    levelLights);

                // draw powerups
                powerup.Draw(gd, technique, cameraPosition, viewProjection, levelLights);

                // draw animated sprites
                animatedSprite.Draw(gd, cameraPosition, players[0].ViewUp,
                    viewProjection, 0, camera3rdPerson);

                // draw particle systems
                particle.Draw(gd, viewProjection);
            }
            else
            {
                // set left viewport
                gd.Viewport = viewportLeft;

                // camera position and view projection matrix for player 1
                Vector3 cameraPosition = players[0].CameraPosition;
                Matrix viewProjection = players[0].ViewMatrix * projectionSplit;

                // draw the level geomery
                DrawModel(gd, levelColor, technique, cameraPosition,
                    Matrix.Identity, viewProjection, levelLights);

                // draw player 2 ship
                players[1].Draw(gd, technique, cameraPosition, viewProjection,
                    levelLights);

                // if in 3rd person mode draw player 1 ship
                bool camera3rdPerson = players[0].Camera3rdPerson;
                if (camera3rdPerson)
                    players[0].Draw(gd, technique,
                        cameraPosition, viewProjection, levelLights);

                // draw projectiles
                projectile.Draw(gd, technique, cameraPosition, viewProjection,
                    levelLights);

                // draw powerups
                powerup.Draw(gd, technique, cameraPosition, viewProjection, levelLights);

                // draw animated sprites
                animatedSprite.Draw(gd, cameraPosition, players[0].ViewUp,
                    viewProjection, 0, camera3rdPerson);

                // draw particle systems
                particle.Draw(gd, viewProjection);

                // setup right viewport
                gd.Viewport = viewportRight;

                // camera position and view projection matrix for player 2
                cameraPosition = players[1].CameraPosition;
                viewProjection = players[1].ViewMatrix * projectionSplit;

                // draw the level geomery
                DrawModel(gd, levelColor, technique, cameraPosition,
                    Matrix.Identity, viewProjection, levelLights);

                // draw player 1 ship
                players[0].Draw(gd, technique, cameraPosition, viewProjection,
                    levelLights);

                // if in 3rd person mode draw player 2 ship
                camera3rdPerson = players[1].Camera3rdPerson;
                if (camera3rdPerson)
                    players[1].Draw(gd, technique,
                        cameraPosition, viewProjection, levelLights);

                // draw projectiles
                projectile.Draw(gd, technique, cameraPosition, viewProjection,
                    levelLights);

                // draw powerups
                powerup.Draw(gd, technique, cameraPosition, viewProjection, levelLights);

                // draw animated sprites
                animatedSprite.Draw(gd, cameraPosition, players[1].ViewUp,
                    viewProjection, 1, camera3rdPerson);

                // draw particle systems
                particle.Draw(gd, viewProjection);
            }
        }
Пример #15
0
        /// <summary>
        /// Draw a model using given technique and camera settings

#endregion


        /// </summary>
        public void DrawModel(GraphicsDevice gd, Model model,
            RenderTechnique technique, Vector3 cameraPosition,
            Matrix world, Matrix viewProjection, LightList lights)
        {


            if (gd == null)
            {
                throw new ArgumentNullException("gd");
            }

            // get model bones
            model.CopyAbsoluteBoneTransformsTo(bones);

            BlendState bs = gd.BlendState;
            DepthStencilState ds = gd.DepthStencilState;

            gd.DepthStencilState = DepthStencilState.DepthRead;
            gd.BlendState = BlendState.Additive;


            // for each mesh in model
            foreach (ModelMesh mesh in model.Meshes)
            {
                // get mesh world matrix
                Matrix worldBone = bones[mesh.ParentBone.Index] * world;
                Matrix worldBoneInverse = Matrix.Invert(worldBone);

                // compute camera position in object space
                Vector3 cameraObjectSpace = cameraPosition - worldBone.Translation;
                cameraObjectSpace = Vector3.TransformNormal(cameraObjectSpace,
                                                        worldBoneInverse);

                gd.SamplerStates[0] = SamplerState.LinearWrap;

                // for each mesh part
                foreach (ModelMeshPart meshPart in mesh.MeshParts)
                {
                    // if primitives to render
                    if (meshPart.PrimitiveCount > 0)
                    {
                        // setup vertices and indices
                        gd.SetVertexBuffer(meshPart.VertexBuffer);
                        gd.Indices = meshPart.IndexBuffer;

                        // setup effect
                        Effect effect = meshPart.Effect;
                        effect.Parameters["WorldViewProj"].SetValue(worldBone * viewProjection);
                        effect.Parameters["CameraPosition"].SetValue(cameraObjectSpace);

                        // setup technique
                        effect.CurrentTechnique =
                            meshPart.Effect.Techniques[(int)technique];


                        // if not lights specified
                        if (lights == null)
                        {
                            // begin effect
                            effect.CurrentTechnique.Passes[0].Apply();
                            // draw with plain mapping
                            gd.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                meshPart.VertexOffset, 0, meshPart.NumVertices,
                                meshPart.StartIndex, meshPart.PrimitiveCount);
                            gd.SetVertexBuffer(null);
                            gd.Indices = null;
                        }
                        else
                        {
                            gd.DepthStencilState = DepthStencilState.Default;
                            gd.BlendState = BlendState.Opaque;

                            // get light effect parameters
                            EffectParameter effectLightPosition =
                                                effect.Parameters[1];
                            EffectParameter effectLightColor =
                                                effect.Parameters[2];
                            EffectParameter effectLightAmbient =
                                                effect.Parameters[3];

                            // ambient light
                            Vector3 ambient = lights.ambient;

                            // for each light
                            foreach (Light light in lights.lights)
                            {
                                // setup light in effect
                                effectLightAmbient.SetValue(ambient);
                                light.SetEffect(effectLightPosition,
                                    effectLightColor, worldBoneInverse);

                                // begin effect
                                effect.CurrentTechnique.Passes[0].Apply();
                                // draw primitives
                                gd.DrawIndexedPrimitives(PrimitiveType.TriangleList,
                                    meshPart.VertexOffset, 0, meshPart.NumVertices,
                                    meshPart.StartIndex, meshPart.PrimitiveCount);

                                // setup additive blending with no depth write
                                gd.DepthStencilState = DepthStencilState.DepthRead;
                                gd.BlendState = BlendState.Additive;

                                // clear ambinet light (applied in first pass only)
                                ambient = Vector3.Zero;
                            }

                            // clear vertices and indices
                            gd.SetVertexBuffer(null);
                            gd.Indices = null;

                        }

                    }
                }
            }
            gd.DepthStencilState = ds;
            gd.BlendState = bs;
        }
Пример #16
0
 /// <summary>
 /// Draw a projectile
 /// </summary>
 public void DrawProjectile(GraphicsDevice gd, ProjectileType p,
     RenderTechnique technique, Vector3 cameraPosition,
     Matrix world, Matrix viewProjection, LightList lights)
 {
     DrawModel(gd, projectileModels[(int)p], technique,
         cameraPosition, world, viewProjection, lights);
 }
Пример #17
0
 public DynamoGeometryModel3D(RenderTechnique renderTechnique)
 {
     renderTechniqueInternal = renderTechnique;
 }
Пример #18
0
 /// <summary>
 /// Renders the player ship model and 
 /// blaster and missile if available and charged
 /// </summary>
 public void Draw(GraphicsDevice gd, RenderTechnique technique, 
     Vector3 cameraPosition, Matrix viewProjection, LightList lights)
 {
     // if not dead
     if (deadTime == 0.0f)
     {
         // render ship model
         gameManager.DrawModel(gd, shipModel, technique, cameraPosition,
             bobbing * transform, viewProjection, lights);
     }
 }