コード例 #1
0
ファイル: Recorder.cs プロジェクト: lochrist/UniVer
 public Recorder(World world)
 {
     this.world = world;
     data       = new RecordingData()
     {
         frames        = new List <Frame>(),
         gravity       = World.gravity,
         friction      = World.friction,
         frictionFloor = World.frictionFloor,
         viscosity     = World.viscosity,
         forceDrag     = World.forceDrag
     };
 }
コード例 #2
0
ファイル: JsonSerialization.cs プロジェクト: lochrist/UniVer
        public void JsonSerializing3()
        {
            var baseDataFile = TestUtils.folder + "/single_body_data";
            var srcData      = RecordingData.Read(baseDataFile + "_src_js.txt");

            srcData.Write(baseDataFile + "_test1.txt");

            var src2Data = RecordingData.Read(baseDataFile + "_test1.txt");

            src2Data.Write(baseDataFile + "_test2.txt");

            var src3Data = RecordingData.Read(baseDataFile + "_test2.txt");

            src3Data.Write(baseDataFile + "_test3.txt");
        }
コード例 #3
0
        private void ValidateWithSrcData(World world, int nbFrames, string testDataBaseName)
        {
            for (var i = 0; i < nbFrames; ++i)
            {
                world.Step(0.16f);
            }

            var baseDataFile = TestUtils.folder + "/" + testDataBaseName;

            if (!File.Exists(baseDataFile + "_src_sharp.txt"))
            {
                var srcData = RecordingData.Read(baseDataFile + "_src_js.txt");
                srcData.Write(baseDataFile + "_src_sharp.txt");
            }

            var refData = RecordingData.Read(baseDataFile + "_src_sharp.txt");

            world.recorder.data.Write(baseDataFile + "_dst_sharp.txt");
            Validate(refData, world.recorder.data);
        }
コード例 #4
0
        private static void Validate(RecordingData refData, RecordingData dstData)
        {
            if (refData.frames.Count != dstData.frames.Count)
            {
                throw new Exception("Not same number of frame");
            }

            for (var frameIndex = 0; frameIndex < dstData.frames.Count; ++frameIndex)
            {
                var refFrame = refData.frames[frameIndex];
                var dstFrame = dstData.frames[frameIndex];

                if (refFrame.steps.Count != dstFrame.steps.Count)
                {
                    throw new Exception("Not same number of steps in frame: " + frameIndex);
                }

                for (var stepIndex = 0; stepIndex < refFrame.steps.Count; ++stepIndex)
                {
                    var refStep = refFrame.steps[stepIndex];
                    var dstStep = dstFrame.steps[stepIndex];

                    Assert.AreEqual(refStep.name, dstStep.name);
                    if (refStep.bodies.Count != dstStep.bodies.Count)
                    {
                        throw new Exception(string.Format("Not same number of bodies in frame: {0} and step {1}",
                                                          frameIndex, refStep.name));
                    }

                    for (var bodyIndex = 0; bodyIndex < refStep.bodies.Count; ++bodyIndex)
                    {
                        var refBody = refStep.bodies[bodyIndex];
                        var dstBody = dstStep.bodies[bodyIndex];

                        Assert.AreEqual(refBody.id, dstBody.id);

                        var msg = string.Format("Not same value in frame: {0} and step {1} and body {2}", frameIndex,
                                                refStep.name, refBody.id);
                        Validate(msg + " - mass", refBody.mass, dstBody.mass);
                        Validate(msg + " - min", refBody.min, dstBody.min);
                        Validate(msg + " - max", refBody.max, dstBody.max);
                        Validate(msg + " - center", refBody.center, dstBody.center);
                        Validate(msg + " - halfExtent", refBody.halfExtent, dstBody.halfExtent);

                        if (dstBody.vertices == null && refBody.vertices != null && refBody.vertices.Count > 0)
                        {
                            throw new Exception(string.Format(
                                                    "Not same number of vertices in frame: {0} and step {1} and body {2}", frameIndex,
                                                    refStep.name, refBody.id));
                        }

                        if (dstBody.vertices != null)
                        {
                            if (refBody.vertices.Count != dstBody.vertices.Count)
                            {
                                throw new Exception(string.Format(
                                                        "Not same number of vertices in frame: {0} and step {1} and body {2}", frameIndex,
                                                        refStep.name, refBody.id));
                            }

                            for (var vertexIndex = 0; vertexIndex < dstBody.vertices.Count; ++vertexIndex)
                            {
                                var refVertex = refBody.vertices[vertexIndex];
                                var dstVertex = dstBody.vertices[vertexIndex];

                                var vertextMsg = msg + " - vertices " + vertexIndex;
                                Validate(vertextMsg + " - x ", refVertex.x, dstVertex.x);
                                Validate(vertextMsg + " - y ", refVertex.y, dstVertex.y);
                                Validate(vertextMsg + " - ox ", refVertex.ox, dstVertex.ox);
                                Validate(vertextMsg + " - oy ", refVertex.oy, dstVertex.oy);
                            }
                        }
                    }
                }
            }
        }