Beispiel #1
0
        private static EntityFullData CreateTwoPyramidEntity(EntityManagerService ems, float size1, float size2)
        {
            TaggedEntity ent = ems.CreateEntity();
            TaggedObject obj = ems.CreateObject();

            EntityFullData entityData = ent.GetTag <EntityFullData>();

            entityData.TaggedObject = obj;

            ModelFullData modelData = new ModelFullData();

            modelData.Positions    = CreatePyramidPositions();
            modelData.ObjectMatrix = Matrix.CreateScale(size1);
            modelData.CalculateBoundingBox();
            modelData.CalculateBoundingSphere();

            entityData.ObjectFullData.Models.Add(modelData);

            modelData              = new ModelFullData();
            modelData.Positions    = CreatePyramidPositions();
            modelData.ObjectMatrix = Matrix.CreateScale(size2);
            modelData.CalculateBoundingBox();
            modelData.CalculateBoundingSphere();

            entityData.ObjectFullData.Models.Add(modelData);


            return(entityData);
        }
            public async Task Should_not_call_http_client_if_response_is_cached()
            {
                // arrange

                string            cuit = "5050505050";
                CancellationToken cancellationToken = CancellationToken.None;

                EntityFullData expected = new EntityFullData()
                {
                    NaturalKey = 56
                };

                string url = $"EntityDataFull?key={cuit}";

                object value = expected;

                this.CacheAccessorMock
                .Setup(x => x.TryGetValue(It.Is <string>(u => u.ToString() == url), out value))
                .Returns(true);

                // act

                var actual = await this.Sut.GetEntityDataFullAsync(cuit, cancellationToken);

                // assert

                actual.Should().BeEquivalentTo(expected);

                this.HttpMessageHandlerMock
                .Protected()
                .Verify(
                    "SendAsync",
                    Times.Never(),
                    ItExpr.IsAny <HttpRequestMessage>(),
                    ItExpr.IsAny <CancellationToken>()
                    );

                this.CacheAccessorMock.Verify(
                    x => x.TryGetValue(
                        It.IsAny <string>(),
                        out value
                        ),
                    Times.Once()
                    );
            }
Beispiel #3
0
        public void TestCreateEntityActor()
        {
            XNAGame game = new XNAGame();

            Database.Database database = loadDatabaseServices();

            EntityManagerService ems = new EntityManagerService(database);


            BoundingBox boundingBox = new BoundingBox();

            PhysicsEngine           engine        = new PhysicsEngine();
            PhysicsDebugRendererXNA debugRenderer = null;



            game.InitializeEvent += delegate
            {
                engine.Initialize();
                debugRenderer = new PhysicsDebugRendererXNA(game, engine.Scene);
                debugRenderer.Initialize(game);


                EntityFullData entityData = CreateTwoPyramidEntity(ems, 5, 3);

                entityData.ObjectFullData.Models[0].ObjectMatrix *= Matrix.CreateTranslation(new Vector3(-3, 0, 3));
                entityData.ObjectFullData.Models[1].ObjectMatrix *= Matrix.CreateTranslation(new Vector3(3, 1, 2));

                entityData.Transform = new Transformation(
                    Vector3.One * 2,
                    Quaternion.Identity,
                    new Vector3(10, 10, 10));

                EntityPhysicsActorBuilder builder = new EntityPhysicsActorBuilder();
                builder.CreateActorForEntity(engine.Scene, entityData);

                BoundingBox bb;
                bb     = entityData.ObjectFullData.Models[0].BoundingBox;
                bb.Min = Vector3.Transform(bb.Min, entityData.ObjectFullData.Models[0].ObjectMatrix * entityData.Transform.CreateMatrix());
                bb.Max = Vector3.Transform(bb.Max, entityData.ObjectFullData.Models[0].ObjectMatrix * entityData.Transform.CreateMatrix());

                BoundingBox bb2;
                bb2     = entityData.ObjectFullData.Models[1].BoundingBox;
                bb2.Min = Vector3.Transform(bb2.Min, entityData.ObjectFullData.Models[1].ObjectMatrix * entityData.Transform.CreateMatrix());
                bb2.Max = Vector3.Transform(bb2.Max, entityData.ObjectFullData.Models[1].ObjectMatrix * entityData.Transform.CreateMatrix());


                boundingBox = BoundingBox.CreateMerged(bb, bb2);
            };

            game.DrawEvent += delegate
            {
                debugRenderer.Render(game);


                game.LineManager3D.AddBox(boundingBox, Color.Orange);
            };
            game.UpdateEvent += delegate
            {
                engine.Update(game.Elapsed);
                if (game.Keyboard.IsKeyPressed(Microsoft.Xna.Framework.Input.Keys.F))
                {
                    Actor actor = PhysicsHelper.CreateDynamicSphereActor(engine.Scene, 1, 1);
                    actor.GlobalPosition = game.SpectaterCamera.CameraPosition +
                                           game.SpectaterCamera.CameraDirection * 5;
                    actor.LinearVelocity = game.SpectaterCamera.CameraDirection * 5;
                }
            };


            game.Run();
        }