コード例 #1
0
ファイル: CockpitView.cs プロジェクト: sikora507/OpenC1
        public CockpitView(Vehicle vehicle, string cockpitFile)
        {
            _vehicle = vehicle;
            if (GameVars.Emulation == EmulationMode.Demo)
                cockpitFile = Path.GetDirectoryName(cockpitFile) + "\\blkeagle.txt";
            else if (GameVars.Emulation == EmulationMode.SplatPackDemo)
                cockpitFile = Path.GetDirectoryName(cockpitFile) + "\\neweagle.txt";
            else if (!File.Exists(cockpitFile))
                cockpitFile = Path.GetDirectoryName(cockpitFile) + "\\blkeagle.txt";

            if (File.Exists(cockpitFile))
            {
                _cockpitFile = new CockpitFile(cockpitFile);

                ActFile actFile = new ActFile(vehicle.Config.BonnetActorFile);
                if (!actFile.Exists)
                    actFile = new ActFile("EBONNET.ACT");
                _actors = actFile.Hierarchy;
                DatFile modelsFile = new DatFile(_actors.Root.ModelName);
                _actors.AttachModels(modelsFile.Models);
                _actors.ResolveTransforms(false, null);

                //move head back
                _vehicle.Config.DriverHeadPosition.Z += 0.11f;
            }

            _camera = new SimpleCamera();
            _camera.FieldOfView = MathHelper.ToRadians(55.55f);
        }
コード例 #2
0
ファイル: CockpitView.cs プロジェクト: vaginessa/OpenC1
        public CockpitView(Vehicle vehicle, string cockpitFile)
        {
            _vehicle = vehicle;
            if (GameVars.Emulation == EmulationMode.Demo)
            {
                cockpitFile = Path.GetDirectoryName(cockpitFile) + "\\blkeagle.txt";
            }
            else if (GameVars.Emulation == EmulationMode.SplatPackDemo)
            {
                cockpitFile = Path.GetDirectoryName(cockpitFile) + "\\neweagle.txt";
            }
            else if (!File.Exists(cockpitFile))
            {
                cockpitFile = Path.GetDirectoryName(cockpitFile) + "\\blkeagle.txt";
            }

            if (File.Exists(cockpitFile))
            {
                _cockpitFile = new CockpitFile(cockpitFile);

                ActFile actFile = new ActFile(vehicle.Config.BonnetActorFile);
                if (!actFile.Exists)
                {
                    actFile = new ActFile("EBONNET.ACT");
                }
                _actors = actFile.Hierarchy;
                DatFile modelsFile = new DatFile(_actors.Root.ModelName);
                _actors.AttachModels(modelsFile.Models);
                _actors.ResolveTransforms(false, null);

                //move head back
                _vehicle.Config.DriverHeadPosition.Z += 0.11f;
            }

            _camera             = new SimpleCamera();
            _camera.FieldOfView = MathHelper.ToRadians(55.55f);
        }
コード例 #3
0
ファイル: TrackProcessor.cs プロジェクト: q4a/OpenC1
        public static Actor GenerateTrackActor(RaceFile file, CActorHierarchy actors, out List <NonCar> nonCarInstances)
        {
            List <Vector3>       verts           = new List <Vector3>();
            List <ushort>        indices         = new List <ushort>();
            List <ushort>        materialIndices = new List <ushort>();
            List <OpenC1.CActor> actorsList      = actors.All();

            nonCarInstances = new List <NonCar>();

            for (int i = 0; i < actorsList.Count; i++)
            {
                CActor actor = actorsList[i];
                if (actor.Model == null)
                {
                    continue;
                }
                if (actor.Name.StartsWith("&"))
                {
                    if (Char.IsDigit(actor.Name[1]) && Char.IsDigit(actor.Name[2]))
                    {
                        NonCar nc = GenerateNonCar(actor, file.NonCars);
                        if (nc != null)
                        {
                            nonCarInstances.Add(nc);
                            continue;                              //dont-merge with track
                        }
                    }
                }

                int baseIndex = verts.Count;
                for (int j = 0; j < actor.Model.VertexCount; j++)
                {
                    verts.Add(Vector3.Zero);
                }

                foreach (Polygon poly in actor.Model.Polygons)
                {
                    if (poly.MaterialIndex < 0)
                    {
                        continue;
                    }

                    string materialName = actor.Model.MaterialNames == null ? "none" : actor.Model.MaterialNames[poly.MaterialIndex];
                    //this is a non-solid material
                    if (materialName.StartsWith("!"))
                    {
                        continue;
                    }

                    int index = baseIndex + poly.Vertex1;

                    indices.Add((ushort)index);
                    if (verts[index] == Vector3.Zero)
                    {
                        Vector3 transformedVec = Vector3.Transform(actors.Models._vertexPositions[actor.Model.VertexBaseIndex + poly.Vertex1], actor.Matrix);
                        verts[index] = transformedVec;
                    }
                    index = baseIndex + poly.Vertex2;
                    indices.Add((ushort)index);
                    if (verts[index] == Vector3.Zero)
                    {
                        Vector3 transformedVec = Vector3.Transform(actors.Models._vertexPositions[actor.Model.VertexBaseIndex + poly.Vertex2], actor.Matrix);
                        verts[index] = transformedVec;
                    }
                    index = baseIndex + poly.Vertex3;
                    indices.Add((ushort)index);
                    if (verts[index] == Vector3.Zero)
                    {
                        Vector3 transformedVec = Vector3.Transform(actors.Models._vertexPositions[actor.Model.VertexBaseIndex + poly.Vertex3], actor.Matrix);
                        verts[index] = transformedVec;
                    }

                    if (Char.IsDigit(materialName[0]))
                    {
                        ushort matModiferId = (ushort)(ushort.Parse(materialName.Substring(0, 1)) + 1);
                        if (matModiferId >= file.MaterialModifiers.Count)
                        {
                            matModiferId = 0;
                        }

                        materialIndices.Add(matModiferId);
                    }
                    else
                    {
                        materialIndices.Add(0);
                    }
                }
            }

            TriangleMeshDescription meshDesc = new TriangleMeshDescription();

            meshDesc.TriangleCount = indices.Count / 3;
            meshDesc.VertexCount   = verts.Count;

            meshDesc.AllocateVertices <Vector3>(meshDesc.VertexCount);
            meshDesc.AllocateTriangles <ushort>(meshDesc.TriangleCount);
            meshDesc.AllocateMaterialIndices <ushort>(materialIndices.Count);

            meshDesc.TriangleStream.SetData(indices.ToArray());
            meshDesc.VerticesStream.SetData(verts.ToArray());
            meshDesc.MaterialIndicesStream.SetData(materialIndices.ToArray());
            meshDesc.Flags = MeshFlag.Indices16Bit;

            MemoryStream s = new MemoryStream();

            Cooking.InitializeCooking();
            Cooking.CookTriangleMesh(meshDesc, s);
            Cooking.CloseCooking();

            s.Position = 0;
            TriangleMesh triangleMesh = PhysX.Instance.Core.CreateTriangleMesh(s);

            TriangleMeshShapeDescription shape = new TriangleMeshShapeDescription()
            {
                TriangleMesh = triangleMesh,
            };

            ActorDescription actorDescription = new ActorDescription()
            {
                GlobalPose = Matrix.CreateTranslation(0, 0, 0),
                Shapes     = { shape }
            };

            foreach (Checkpoint checkpoint in file.Checkpoints)
            {
                ActorDescription actorDesc = new ActorDescription();

                BoxShapeDescription box = new BoxShapeDescription(checkpoint.BBox.GetSize());
                box.Flags = ShapeFlag.TriggerOnEnter | ShapeFlag.Visualization;
                actorDesc.Shapes.Add(box);
                Actor actor = PhysX.Instance.Scene.CreateActor(actorDesc);
                actor.GlobalPosition = checkpoint.BBox.GetCenter();
                actor.UserData       = checkpoint;
            }

            StillDesign.PhysX.Actor environment = PhysX.Instance.Scene.CreateActor(actorDescription);
            environment.Group = PhysXConsts.TrackId;
            environment.Shapes[0].SetFlag(ShapeFlag.Visualization, false);


            CreateDefaultWaterSpecVols(file, actorsList, actors.Models);


            for (int i = 1; i < file.SpecialVolumes.Count; i++)
            {
                SpecialVolume vol = file.SpecialVolumes[i];

                Vector3    scale   = new Vector3();
                Vector3    trans   = new Vector3();
                Quaternion q       = new Quaternion();
                Matrix     matrix  = vol.Matrix;
                bool       success = matrix.Decompose(out scale, out q, out trans);
                if (scale.Z == 0)
                {
                    scale.Z = 0.1f;
                }

                ActorDescription    actorDesc = new ActorDescription();
                BoxShapeDescription box       = new BoxShapeDescription(scale);

                if (success)
                {
                    if (float.IsNaN(q.X))
                    {
                        continue;
                    }
                    box.LocalRotation = Matrix.CreateFromQuaternion(q);
                }
                else
                {
                    //if the matrix cannot be decomposed, like part of the long tunnel in coasta...
                    // get the rotation by calculating some points and working out rotation from them
                    Vector3 v1       = Vector3.Transform(new Vector3(-1, -1, 1), matrix);
                    Vector3 v2       = Vector3.Transform(new Vector3(-1, 1, -1), matrix);
                    Vector3 forwards = v2 - v1;
                    forwards.Normalize();
                    box.LocalRotation = Matrix.CreateWorld(Vector3.Zero, forwards, Vector3.Up);
                }

                box.Flags = ShapeFlag.TriggerOnEnter | ShapeFlag.TriggerOnLeave | ShapeFlag.Visualization;
                actorDesc.Shapes.Add(box);
                Actor actor = PhysX.Instance.Scene.CreateActor(actorDesc);

                actor.GlobalPosition = vol.Matrix.Translation;
                actor.UserData       = vol;
            }

            return(environment);
        }
コード例 #4
0
ファイル: TrackProcessor.cs プロジェクト: sikora507/OpenC1
        public static Actor GenerateTrackActor(RaceFile file, CActorHierarchy actors, out List<NonCar> nonCarInstances)
        {
            List<Vector3> verts = new List<Vector3>();
            List<ushort> indices = new List<ushort>();
            List<ushort> materialIndices = new List<ushort>();
            List<OpenC1.CActor> actorsList = actors.All();
            nonCarInstances = new List<NonCar>();

            for (int i = 0; i < actorsList.Count; i++)
            {
                CActor actor = actorsList[i];
                if (actor.Model == null) continue;
                if (actor.Name.StartsWith("&"))
                {
                    if (Char.IsDigit(actor.Name[1]) && Char.IsDigit(actor.Name[2]))
                    {
                        NonCar nc = GenerateNonCar(actor, file.NonCars);
                        if (nc != null)
                        {
                            nonCarInstances.Add(nc);
                            continue;  //dont-merge with track
                        }
                    }
                }

                int baseIndex = verts.Count;
                for (int j = 0; j < actor.Model.VertexCount; j++)
                    verts.Add(Vector3.Zero);

                foreach (Polygon poly in actor.Model.Polygons)
                {
                    if (poly.MaterialIndex < 0)
                        continue;

                    string materialName = actor.Model.MaterialNames == null ? "none" : actor.Model.MaterialNames[poly.MaterialIndex];
                    //this is a non-solid material
                    if (materialName.StartsWith("!"))
                        continue;

                    int index = baseIndex + poly.Vertex1;

                    indices.Add((ushort)index);
                    if (verts[index] == Vector3.Zero)
                    {
                        Vector3 transformedVec = Vector3.Transform(actors.Models._vertexPositions[actor.Model.VertexBaseIndex + poly.Vertex1], actor.Matrix);
                        verts[index] = transformedVec;
                    }
                    index = baseIndex + poly.Vertex2;
                    indices.Add((ushort)index);
                    if (verts[index] == Vector3.Zero)
                    {
                        Vector3 transformedVec = Vector3.Transform(actors.Models._vertexPositions[actor.Model.VertexBaseIndex + poly.Vertex2], actor.Matrix);
                        verts[index] = transformedVec;
                    }
                    index = baseIndex + poly.Vertex3;
                    indices.Add((ushort)index);
                    if (verts[index] == Vector3.Zero)
                    {
                        Vector3 transformedVec = Vector3.Transform(actors.Models._vertexPositions[actor.Model.VertexBaseIndex + poly.Vertex3], actor.Matrix);
                        verts[index] = transformedVec;
                    }

                    if (Char.IsDigit(materialName[0]))
                    {
                        ushort matModiferId = (ushort)(ushort.Parse(materialName.Substring(0, 1)) + 1);
                        if (matModiferId >= file.MaterialModifiers.Count) matModiferId = 0;

                        materialIndices.Add(matModiferId);
                    }
                    else
                        materialIndices.Add(0);
                }
            }

            TriangleMeshDescription meshDesc = new TriangleMeshDescription();
            meshDesc.TriangleCount = indices.Count / 3;
            meshDesc.VertexCount = verts.Count;

            meshDesc.AllocateVertices<Vector3>(meshDesc.VertexCount);
            meshDesc.AllocateTriangles<ushort>(meshDesc.TriangleCount);
            meshDesc.AllocateMaterialIndices<ushort>(materialIndices.Count);

            meshDesc.TriangleStream.SetData(indices.ToArray());
            meshDesc.VerticesStream.SetData(verts.ToArray());
            meshDesc.MaterialIndicesStream.SetData(materialIndices.ToArray());
            meshDesc.Flags = MeshFlag.Indices16Bit;

            MemoryStream s = new MemoryStream();

            Cooking.InitializeCooking();
            Cooking.CookTriangleMesh(meshDesc, s);
            Cooking.CloseCooking();

            s.Position = 0;
            TriangleMesh triangleMesh = PhysX.Instance.Core.CreateTriangleMesh(s);

            TriangleMeshShapeDescription shape = new TriangleMeshShapeDescription()
            {
                TriangleMesh = triangleMesh,
            };

            ActorDescription actorDescription = new ActorDescription()
            {
                GlobalPose = Matrix.CreateTranslation(0, 0, 0),
                Shapes = { shape }
            };

            foreach (Checkpoint checkpoint in file.Checkpoints)
            {
                ActorDescription actorDesc = new ActorDescription();

                BoxShapeDescription box = new BoxShapeDescription(checkpoint.BBox.GetSize());
                box.Flags = ShapeFlag.TriggerOnEnter | ShapeFlag.Visualization;
                actorDesc.Shapes.Add(box);
                Actor actor = PhysX.Instance.Scene.CreateActor(actorDesc);
                actor.GlobalPosition = checkpoint.BBox.GetCenter();
                actor.UserData = checkpoint;
            }

            StillDesign.PhysX.Actor environment = PhysX.Instance.Scene.CreateActor(actorDescription);
            environment.Group = PhysXConsts.TrackId;
            environment.Shapes[0].SetFlag(ShapeFlag.Visualization, false);

            CreateDefaultWaterSpecVols(file, actorsList, actors.Models);

            for (int i = 1; i < file.SpecialVolumes.Count; i++)
            {
                SpecialVolume vol = file.SpecialVolumes[i];

                Vector3 scale = new Vector3();
                Vector3 trans = new Vector3();
                Quaternion q = new Quaternion();
                Matrix matrix = vol.Matrix;
                bool success = matrix.Decompose(out scale, out q, out trans);
                if (scale.Z == 0) scale.Z = 0.1f;

                ActorDescription actorDesc = new ActorDescription();
                BoxShapeDescription box = new BoxShapeDescription(scale);

                if (success)
                {
                    if (float.IsNaN(q.X))
                        continue;
                    box.LocalRotation = Matrix.CreateFromQuaternion(q);
                }
                else
                {
                    //if the matrix cannot be decomposed, like part of the long tunnel in coasta...
                    // get the rotation by calculating some points and working out rotation from them
                    Vector3 v1 = Vector3.Transform(new Vector3(-1, -1, 1), matrix);
                    Vector3 v2 = Vector3.Transform(new Vector3(-1, 1, -1), matrix);
                    Vector3 forwards = v2 - v1;
                    forwards.Normalize();
                    box.LocalRotation = Matrix.CreateWorld(Vector3.Zero, forwards, Vector3.Up);
                }

                box.Flags = ShapeFlag.TriggerOnEnter | ShapeFlag.TriggerOnLeave | ShapeFlag.Visualization;
                actorDesc.Shapes.Add(box);
                Actor actor = PhysX.Instance.Scene.CreateActor(actorDesc);

                actor.GlobalPosition = vol.Matrix.Translation;
                actor.UserData = vol;
            }

            return environment;
        }