Exemplo n.º 1
0
        public void AttachBatchedPhysics(CompoundShape shape)
        {
            var component = _batchedControlFactory.CreatePhysicalBatchedStaticCompoundComponent(shape);

            _hierarchy.MoveNode(_node, _hierarchy.Lookup(component));

            component.Static                  = true;
            component.StaticAndImmovable      = true;
            component.Target                  = PhysicsTarget.Component;
            component.Transform.LocalPosition = -shape.Shift.ToXNAVector();
        }
        public PROJECT_SAFE_NAMEWorld(
            INode worldNode,
            IHierarchy hierarchy,
            I2DRenderUtilities twoDRenderUtilities,
            IAssetManagerProvider assetManagerProvider,
            IEntityFactory entityFactory)
        {
            this.Entities = new List<IEntity>();

            _renderUtilities = twoDRenderUtilities;
            _assetManager = assetManagerProvider.GetAssetManager();
            _defaultFont = this._assetManager.Get<FontAsset>("font.Default");

            // You can also save the entity factory in a field and use it, e.g. in the Update
            // loop or anywhere else in your game.
            var entityA = entityFactory.CreateExampleEntity("EntityA");
            entityA.Transform.LocalPosition = new Vector3(100, 50, 0);
            var entityB = entityFactory.CreateExampleEntity("EntityB");
            entityB.Transform.LocalPosition = new Vector3(120, 100, 0);

            // Don't forget to add your entities to the world!
            hierarchy.MoveNode(worldNode, hierarchy.Lookup(entityA));
            hierarchy.MoveNode(worldNode, hierarchy.Lookup(entityB));
        }
Exemplo n.º 3
0
        private BatchedControlEntity BatchPhysics(IGameContext gameContext, INode node, BatchedControlEntity entity)
        {
            var physicsComponentsToProcess = new List <Tuple <INode, PhysicalBaseRigidBodyComponent> >();

            FindPhysicsComponentsUnderNode(node, physicsComponentsToProcess);

            var transformedShapes = new List <CompoundShape.TransformedShape>();

            foreach (var pair in physicsComponentsToProcess)
            {
                foreach (var body in pair.Item2.RigidBodies)
                {
                    transformedShapes.Add(new CompoundShape.TransformedShape(
                                              body.Shape,
                                              JMatrix.CreateFromQuaternion(pair.Item2.FinalTransform.AbsoluteRotation.ToJitterQuaternion()),
                                              pair.Item2.FinalTransform.AbsolutePosition.ToJitterVector()));
                }
            }

            if (transformedShapes.Count == 0)
            {
                return(entity);
            }

            var compoundShape = new CompoundShape(transformedShapes);

            if (entity == null)
            {
                entity = CreateBatchedControlEntity();
            }

            foreach (var pair in physicsComponentsToProcess)
            {
                pair.Item2.SetBatchedEntity(entity);
            }

            entity.AttachBatchedPhysics(compoundShape);

            _hierarchy.MoveNode(node, _hierarchy.Lookup(entity));

            _consoleHandle.LogInfo("Batching physics objected combined " + transformedShapes.Count + " shapes.");

            return(entity);
        }