Пример #1
0
        public void RenderSingle(CActor actor)
        {
            Matrix m = actor.Matrix;

            m.Translation = Vector3.Zero;
            GameVars.CurrentEffect.World = m * GameVars.CurrentEffect.World;

            actor.Model.Render(actor.Material);
        }
Пример #2
0
        public void RecalculateActorParent(CActor actor)
        {
            actor.Parent.Children.Remove(actor); //remove it from current parent

            bool found = false;

            for (int i = 0; i < _actors.Count; i++)
            {
                MoveChildren(actor, _actors[i], null, ref found);
            }
        }
Пример #3
0
        private void ScaleTransformations(Vector3 scale, CActor actor)
        {
            if (actor.IsAnimated)
            {
                return;
            }
            actor.Matrix = actor.Matrix * Matrix.CreateScale(scale);

            foreach (CActor child in actor.Children)
            {
                ScaleTransformations(scale, child);
            }
        }
Пример #4
0
        private void ResolveTransformations(Matrix world, CActor actor, List <BaseGroove> grooves)
        {
            if (grooves != null && grooves.Exists(g => g.ActorName == actor.Name))
            {
                actor.ParentMatrix = world;
                actor.IsAnimated   = true;
                return;
            }
            //Debug.WriteLine(actor.Name + ", " + actor.ModelName + ", " + actor.Flags[0] + ":" + actor.Flags[1] + "Animated: " + actor.IsAnimated);
            actor.Matrix = world * actor.Matrix;

            foreach (CActor child in actor.Children)
            {
                ResolveTransformations(actor.Matrix, child, grooves);
            }
        }
Пример #5
0
        public Vehicle(string filename, IDriver driver)
        {
            Driver         = driver;
            Driver.Vehicle = this;

            Config = new VehicleFile(filename);

            if (driver is PlayerDriver)
            {
                if (Config.WindscreenMaterial != "none")
                {
                    Config.Funks.Add(new WindscreenFunk(Config.WindscreenMaterial, this));
                }
            }

            _model = new VehicleModel(Config, false);

            Audio = new VehicleAudio(this);

            Chassis = new VehicleChassis(this);

            CActor actor2 = _model.GetActor(Path.GetFileNameWithoutExtension(_model.ModelName));

            if (actor2 != null)
            {
                _deformableModel          = (CDeformableModel)actor2.Model;
                _deformableModel._actor   = Chassis.Actor;
                _deformableModel._carFile = Config;
            }

            _crushSection = Config.CrushSections[1];

            CMaterial crashMat = ResourceCache.GetMaterial(Config.CrashMaterialFiles[0]);

            _vehicleBitsEmitter = new ParticleEmitter(new VehicleBitsParticleSystem(crashMat), 3, Vector3.Zero);
            _vehicleBitsEmitter.DumpsPerSecond = 0.7f;

            DamageSmokeEmitter         = new ParticleEmitter(new DamageSmokeParticleSystem(Color.Gray), 5, Vector3.Zero);
            DamageSmokeEmitter.Enabled = false;

            _flames        = new PixmapBillboard(new Vector2(0.7f, 0.25f), "flames.pix");
            SkidMarkBuffer = new SkidMarkBuffer(this, 150);
        }
Пример #6
0
        private void MoveChildren(CActor actorToMove, CActor parent, CActor parentParent, ref bool found)
        {
            if (found || parent.BoundingBox.Max.X == 0)
            {
                return;
            }

            if (parent.BoundingBox.Contains(actorToMove.PhysXActor.GlobalPosition) == ContainmentType.Contains)
            {
                foreach (CActor child in parent.Children)
                {
                    MoveChildren(actorToMove, child, parent, ref found);
                }
                if (!found)
                {
                    if (!parent.Children.Contains(actorToMove))
                    {
                        parent.Children.Add(actorToMove);
                    }
                    found = true;
                }
            }
        }
Пример #7
0
        private void ScaleTransformations(Vector3 scale, CActor actor)
        {
            if (actor.IsAnimated) return;
            actor.Matrix = actor.Matrix * Matrix.CreateScale(scale);

            foreach (CActor child in actor.Children)
                ScaleTransformations(scale, child);
        }
Пример #8
0
        private void ResolveTransformations(Matrix world, CActor actor, List<BaseGroove> grooves)
        {
            if (grooves != null && grooves.Exists(g => g.ActorName == actor.Name))
            {
                actor.ParentMatrix = world;
                actor.IsAnimated = true;
                return;
            }
            //Debug.WriteLine(actor.Name + ", " + actor.ModelName + ", " + actor.Flags[0] + ":" + actor.Flags[1] + "Animated: " + actor.IsAnimated);
            actor.Matrix = world * actor.Matrix;

            foreach (CActor child in actor.Children)
                ResolveTransformations(actor.Matrix, child, grooves);
        }
Пример #9
0
        private void RenderChildren(BoundingFrustum frustum, CActor actor, Matrix world, bool parentAnimated)
        {
            if (RenderWheelsSeparately && actor.IsWheel) return;

            bool intersects;

            if (frustum == null)
            {
                intersects = true;
            }
            else
            {
                intersects = actor.BoundingBox.Max.X == 0;
                if (!intersects)
                {
                    frustum.Intersects(ref actor.BoundingBox, out intersects);
                    GameVars.NbrSectionsChecked++;
                }
            }

            if (intersects)
            {
                Matrix m = actor.GetDynamicMatrix();

                if (actor.IsAnimated || parentAnimated)
                {
                    if (actor.IsAnimated && !parentAnimated)
                    {
                        world = m * actor.ParentMatrix * GameVars.ScaleMatrix * world;
                    }
                    else
                    {
                        world = m * world;
                    }

                    GameVars.CurrentEffect.World = world;
                    parentAnimated = true;
                }
                else
                {
                    GameVars.CurrentEffect.World = m * world;
                }

                GameVars.CurrentEffect.CommitChanges();

                if (actor.Model != null)
                {
                    actor.Model.Render(actor.Material);
                    if (actor.Model is CDeformableModel)
                    {
                        Models.SetupRender();
                    }
                }

                GameVars.NbrSectionsRendered++;

                foreach (CActor child in actor.Children)
                    RenderChildren(frustum, child, world, parentAnimated);
            }
        }
Пример #10
0
        private void MoveChildren(CActor actorToMove, CActor parent, CActor parentParent, ref bool found)
        {
            if (found || parent.BoundingBox.Max.X == 0)
            {
                return;
            }

            if (parent.BoundingBox.Contains(actorToMove.PhysXActor.GlobalPosition) == ContainmentType.Contains)
            {
                foreach (CActor child in parent.Children)
                    MoveChildren(actorToMove, child, parent, ref found);
                if (!found)
                {
                    if (!parent.Children.Contains(actorToMove))
                    {
                        parent.Children.Add(actorToMove);
                    }
                    found = true;
                }
            }
        }
Пример #11
0
        public void RenderSingle(CActor actor)
        {
            Matrix m = actor.Matrix;
            m.Translation = Vector3.Zero;
            GameVars.CurrentEffect.World = m * GameVars.CurrentEffect.World;
            GameVars.CurrentEffect.CommitChanges();

            actor.Model.Render(actor.Material);
        }
Пример #12
0
 public void RenderSinglePart(CActor actor)
 {
     _actors.RenderSingle(actor);
 }
Пример #13
0
 public CWheelActor(CActor actor, bool driven, bool steerable)
 {
     Actor = actor;
     IsDriven = driven;
     IsSteerable = steerable;
 }
Пример #14
0
 public void Add(CActor actor)
 {
     _actors.Add(actor);
 }
Пример #15
0
        private void RenderChildren(BoundingFrustum frustum, CActor actor, Matrix world, bool parentAnimated)
        {
            if (RenderWheelsSeparately && actor.IsWheel)
            {
                return;
            }

            bool intersects;

            if (frustum == null)
            {
                intersects = true;
            }
            else
            {
                intersects = actor.BoundingBox.Max.X == 0;
                if (!intersects)
                {
                    frustum.Intersects(ref actor.BoundingBox, out intersects);
                    GameVars.NbrSectionsChecked++;
                }
            }

            if (intersects)
            {
                Matrix m = actor.GetDynamicMatrix();

                if (actor.IsAnimated || parentAnimated)
                {
                    if (actor.IsAnimated && !parentAnimated)
                    {
                        world = m * actor.ParentMatrix * GameVars.ScaleMatrix * world;
                    }
                    else
                    {
                        world = m * world;
                    }

                    GameVars.CurrentEffect.World = world;
                    parentAnimated = true;
                }
                else
                {
                    GameVars.CurrentEffect.World = m * world;
                }

                GameVars.CurrentEffect.CommitChanges();

                if (actor.Model != null)
                {
                    actor.Model.Render(actor.Material);
                    if (actor.Model is CDeformableModel)
                    {
                        Models.SetupRender();
                    }
                }

                GameVars.NbrSectionsRendered++;

                foreach (CActor child in actor.Children)
                {
                    RenderChildren(frustum, child, world, parentAnimated);
                }
            }
        }
Пример #16
0
 public void Add(CActor actor)
 {
     _actors.Add(actor);
 }
Пример #17
0
        public void RecalculateActorParent(CActor actor)
        {
            actor.Parent.Children.Remove(actor); //remove it from current parent

            bool found = false;
            for (int i = 0; i < _actors.Count; i++)
            {
                MoveChildren(actor, _actors[i], null, ref found);
            }
        }
Пример #18
0
 public void RenderSinglePart(CActor actor)
 {
     _actors.RenderSingle(actor);
 }
Пример #19
0
        public VehicleModel(VehicleFile file, bool forDisplayOnly)
        {
            Config = file;

            if (file.DrivenWheelRefs.Count == 0 || file.NonDrivenWheelRefs.Count == 0)
            {
                throw new Exception("No wheel refs specified");
            }

            foreach (string pixFileName in file.PixFiles)
            {
                PixFile pixFile = new PixFile(pixFileName);
                ResourceCache.Add(pixFile);
            }

            foreach (string matFileName in file.MaterialFiles)
            {
                MatFile matFile = new MatFile(matFileName);
                ResourceCache.Add(matFile);
            }

            foreach (string matFileName in file.CrashMaterialFiles)
            {
                MatFile matFile = new MatFile(matFileName);
                ResourceCache.Add(matFile);
            }

            ResourceCache.ResolveMaterials();

            _grooves = new List <BaseGroove>();
            foreach (BaseGroove g in file.Grooves)
            {
                if (!g.IsWheelActor)
                {
                    _grooves.Add(g);
                }
            }

            ActFile actFile = new ActFile(file.ActorFile);

            _actors = actFile.Hierarchy;
            DatFile modelFile = new DatFile(_actors.Root.ModelName, !forDisplayOnly);

            ModelName = _actors.Root.ModelName;

            _actors.AttachModels(modelFile.Models);
            _actors.ResolveTransforms(!forDisplayOnly, _grooves);

            foreach (BaseGroove g in _grooves)
            {
                g.SetActor(_actors.GetByName(g.ActorName));
            }

            // link the funks and materials
            foreach (BaseFunk f in file.Funks)
            {
                f.Resolve();
            }

            Vector3 tireWidth = new Vector3(0.034f, 0, 0) * GameVars.Scale;

            foreach (int id in file.DrivenWheelRefs)
            {
                BaseGroove g = file.Grooves.Find(a => a.Id == id);
                if (g == null)
                {
                    continue;
                }
                CActor      actor = _actors.GetByName(g.ActorName);
                CWheelActor ca    = new CWheelActor(actor, true, false);
                ca.Position = actor.Matrix.Translation + (ca.IsLeft ? -1 * tireWidth : tireWidth);
                file.WheelActors.Add(ca);
            }
            foreach (int id in file.NonDrivenWheelRefs)
            {
                BaseGroove g     = file.Grooves.Find(a => a.Id == id);
                CActor     actor = _actors.GetByName(g.ActorName);
                if (actor == null)
                {
                    continue;                 //BUSTER.TXT does some weird shit for cockpit view of the front wheels
                }
                CWheelActor ca = new CWheelActor(actor, false, true);
                ca.Position = actor.Matrix.Translation + (ca.IsLeft ? -1 * tireWidth : tireWidth);
                file.WheelActors.Add(ca);
            }

            if (forDisplayOnly)
            {
                _actors.RenderWheelsSeparately = false;
            }
        }
Пример #20
0
 public CWheelActor(CActor actor, bool driven, bool steerable)
 {
     Actor       = actor;
     IsDriven    = driven;
     IsSteerable = steerable;
 }