Esempio n. 1
0
        public FBXModel clone()
        {
            FBXModel fbxmodel = new FBXModel(filename);
            fbxmodel.scale = scale;
            fbxmodel.model = model;

            fbxmodel.visible = visible;
            fbxmodel.lighted = lighted;

            return fbxmodel;
        }
Esempio n. 2
0
        /// <summary>
        /// Render an object based on an FBX file within a given camera matrix.
        /// </summary>
        /// <param name="gameObject">The GameObject the model belongs to.</param>
        /// <param name="fbxmodel">The FBX model to draw.</param>
        /// <param name="cameraMatrix">The camera matrix.</param>
        /// <param name="objectMatrix">The object matrix.</param>
        /// <param name="player">What player's view is being rendered.</param>
        private void renderFBXModel(GameObject gameObject, FBXModel fbxmodel, Matrix cameraMatrix, Matrix objectMatrix, Player player)
        {
            Matrix modelMatrix;
            if (fbxmodel == null || !fbxmodel.visible)
            {
                return;
            }
            // TODO: We need to get an appropriate colored fog if we really want to not fog the skybox
            bool enableFog = false; // || !(gameObject is Skybox);
            if (gameObject is Checkpoint)
            {
                int currentLocation = Engine.GetInstance().race.status(player, true).checkpoint;
                int checkpointPosition = ((Checkpoint)gameObject).racePosition;
                if (checkpointPosition > currentLocation)
                {
                    // TODO: change differentiation from visible/invisible to differences in how the checkpoints are rendered (color? brightness?)
                    fbxmodel.visible = true;
                }
                else
                {
                    fbxmodel.visible = false;
                }
            }
            modelMatrix = Matrix.CreateScale(fbxmodel.scale) * objectMatrix * fbxmodel.offset.matrix();
            Model model = fbxmodel.model;

            // Copy any parent transforms.
            Matrix[] transforms = new Matrix[model.Bones.Count];
            model.CopyAbsoluteBoneTransformsTo(transforms);

            // Draw the model. A model can have multiple meshes, so loop.
            foreach (ModelMesh mesh in model.Meshes)
            {
                bool meshbloom = false;
                foreach (BasicEffect mesheffect in mesh.Effects)
                {
                    if (mesheffect.EmissiveColor != Vector3.Zero)
                    {
                        meshbloom = true;
                    }
                }

                // This is where the mesh orientation is set, as well as our camera and projection.
                foreach (BasicEffect mesheffect in mesh.Effects)
                {
                    mesheffect.PreferPerPixelLighting = Properties.Settings.Default.PerPixelLighting;
                    mesheffect.FogEnabled = enableFog;
                    mesheffect.FogStart = viewingDistance / 2;
                    mesheffect.FogEnd = viewingDistance * 1.25f;
                    mesheffect.FogColor = new Vector3(0, 0, 0);

                    mesheffect.World = transforms[mesh.ParentBone.Index] * modelMatrix;
                    //effect.View = Matrix.CreateLookAt(cameraPosition, Vector3.Zero, Vector3.Up);
                    mesheffect.View = cameraMatrix;
                    mesheffect.Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.ToRadians(viewingAngle),
                        GammaDraconis.GetInstance().GraphicsDevice.Viewport.AspectRatio, 10f, viewingDistance);

                    if (renderBloom)
                    {
                        if (meshbloom)
                        {
                            applyLights(mesheffect, fbxmodel.lighted);
                        }
                        else
                        {
                            mesheffect.LightingEnabled = true;
                            mesheffect.DirectionalLight0.Enabled = false;
                            mesheffect.DirectionalLight1.Enabled = false;
                            mesheffect.DirectionalLight2.Enabled = false;
                            mesheffect.AmbientLightColor = Vector3.Zero;
                        }
                    }
                    else
                    {
                        applyLights(mesheffect, fbxmodel.lighted);
                    }
                }

                mesh.Draw();

            }
        }
Esempio n. 3
0
        /// <summary>
        /// Explode an explosion.
        /// </summary>
        /// <param name="spot">The starting point for the explosion.</param>
        /// <param name="vel">The starting velocity for the explosion.</param>
        public void explode(Coords spot, Coords vel)
        {
            Coords velocity = new Coords(vel.pos());
            Coords position = new Coords(spot.pos());
            Bullet bullet;
            FBXModel model;

            if (bullets.Count < 1)
            {
                Console.WriteLine("Loading Explosion Bullets.");
                bullet = new Bullet();
                bullet.damage = 100 * power;
                bullet.rateL = 35 * size;
                bullet.dragL = 0.3f;
                bullet.dragR = 0.2f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember1", "", 1.0f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = bullet.clone();
                bullet.damage = 100 * power;
                bullet.rateL = 35 * size;
                bullet.dragL = 0.3f;
                bullet.dragR = 0.2f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember1", "", 1.0f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = new Bullet();
                bullet.damage = 150 * power;
                bullet.rateL = 20 * size;
                bullet.dragL = 0.5f;
                bullet.dragR = 0.3f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember1", "", 2.0f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = new Bullet();
                bullet.damage = 80 * power;
                bullet.rateL = 30 * size;
                bullet.dragL = 0.5f;
                bullet.dragR = 0.3f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember2", "", 1.0f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = new Bullet();
                bullet.damage = 100 * power;
                bullet.rateL = 45 * size;
                bullet.dragL = 0.3f;
                bullet.dragR = 0.3f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember2", "", 0.6f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);

                bullet = new Bullet();
                bullet.damage = 100 * power;
                bullet.rateL = 45 * size;
                bullet.dragL = 0.3f;
                bullet.dragR = 0.3f;
                bullet.size = 2;
                bullet.timeToLive = 5;
                model = new FBXModel("Resources/Models/Ember2", "", 0.6f);
                model.lighted = false;
                bullet.models.Add(model);
                bullets.Add(bullet);
            }

            for (int i = 0; i < particles; i++)
            {
                Console.WriteLine("Explosion Bullet");
                int m = rand.Next(bullets.Count);
                bullet = bullets[m].clone();
                bullet.scaleModels(size);

                bullet.lastPosition = position.Clone();
                bullet.velocity = velocity.Clone();

                bullet.position.T = position.T;
                bullet.position.R = Quaternion.CreateFromAxisAngle(Vector3.Up, (float)(MathHelper.TwoPi * rand.NextDouble())) *
                    Quaternion.CreateFromAxisAngle(Vector3.Backward, (float)(MathHelper.TwoPi * rand.NextDouble())) *
                    Quaternion.CreateFromAxisAngle(Vector3.Right, (float)(MathHelper.TwoPi * rand.NextDouble()));

                bullet.throttle(1f);

                Engine.GetInstance().gameScene.track(bullet, GO_TYPE.BULLET);
            }
        }