This entity contains and controls the results of a batching operation.
Inheritance: Protogame.ComponentizedEntity
コード例 #1
0
        public void SetBatchedEntity(BatchedControlEntity entity)
        {
            if (!StaticAndImmovable)
            {
                throw new InvalidOperationException(
                          "Attempted to set associated batched control entity for physics component that is not static and immovable!");
            }

            _batchedControlEntity = entity;

            IHasTransform targetTransform;

            switch (_target)
            {
            case PhysicsTarget.ComponentOwner:
                targetTransform = _node.Parent?.UntypedValue as IHasTransform;
                break;

            case PhysicsTarget.Component:
                targetTransform = this;
                break;

            default:
                throw new InvalidOperationException();
            }

            _physicsEngine.UnregisterRigidBodyForHasMatrixInCurrentWorld(_rigidBody, targetTransform);
            _addedRigidBody = false;
        }
コード例 #2
0
        public INode Batch(IGameContext gameContext, INode node, IBatchingOptions options)
        {
            BatchedControlEntity entity = null;

            if (options.BatchPhysics)
            {
                entity = BatchPhysics(gameContext, node, entity);
            }

            if (entity != null)
            {
                _consoleHandle.LogDebug("Attached batched control entity to parent of batch request.");

                _hierarchy.AddChildNode(node, entity.Node);
            }

            return(entity?.Node);
        }
コード例 #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);
        }