コード例 #1
0
        public void Prerender(ComponentizedEntity entity, IGameContext gameContext, IRenderContext renderContext)
        {
            var enabled      = Enabled && renderContext.IsCurrentRenderPass <I3DRenderPass>();
            var debugEnabled = DebugEnabled && renderContext.IsCurrentRenderPass <IDebugRenderPass>();

            if (enabled || DebugEnabled)
            {
                var parentFinalTransform = (_node?.Parent?.UntypedValue as IHasTransform)?.FinalTransform;
                if (parentFinalTransform == null)
                {
                    return;
                }

                var sourceLocal = HeadOffset;
                var lookAtLocal = HeadOffset + Vector3.Transform(Vector3.Forward, Transform.LocalMatrix);
                var upLocal     = HeadOffset + Vector3.Up;

                var sourceAbsolute = Vector3.Transform(sourceLocal, parentFinalTransform.AbsoluteMatrix);
                var lookAtAbsolute = Vector3.Transform(lookAtLocal, parentFinalTransform.AbsoluteMatrix);
                var upAbsolute     = Vector3.Transform(upLocal, parentFinalTransform.AbsoluteMatrix) -
                                     Vector3.Transform(sourceLocal, parentFinalTransform.AbsoluteMatrix);

                if (enabled)
                {
                    _firstPersonCamera.Apply(
                        renderContext,
                        sourceAbsolute,
                        lookAtAbsolute,
                        upAbsolute,
                        FieldOfView);
                }
                else if (debugEnabled)
                {
                    _debugRenderer.RenderDebugLine(
                        renderContext,
                        sourceAbsolute,
                        lookAtAbsolute,
                        Color.Cyan,
                        Color.Cyan);
                    _debugRenderer.RenderDebugLine(
                        renderContext,
                        sourceAbsolute,
                        sourceAbsolute + upAbsolute,
                        Color.Cyan,
                        Color.Lime);
                }
            }
        }
コード例 #2
0
        public void Render(ComponentizedEntity entity, IGameContext gameContext, IRenderContext renderContext)
        {
            if (!Enabled)
            {
                return;
            }

            if (_physicsControllerConstraint != null && _physicalComponent.RigidBodies.Length > 0)
            {
                _debugRenderer.RenderDebugLine(
                    renderContext,
                    _physicalComponent.RigidBodies[0].Position.ToXNAVector(),
                    _physicalComponent.RigidBodies[0].Position.ToXNAVector() + TargetVelocity,
                    Color.Yellow,
                    Color.Yellow);
            }
        }
コード例 #3
0
        public void Render(ComponentizedEntity entity, IGameContext gameContext, IRenderContext renderContext)
        {
            if (!_enabled || _serverOnly)
            {
                return;
            }

            if (renderContext.IsCurrentRenderPass <IDebugRenderPass>())
            {
                var debugRenderPass     = renderContext.GetCurrentRenderPass <IDebugRenderPass>();
                var entityTransformSync = _synchronisedData.Select(x => x.Value).FirstOrDefault(x => x.Name == "entity.transform");

                if (entityTransformSync != null && debugRenderPass.EnabledLayers.OfType <ServerStateDebugLayer>().Any())
                {
                    var lastValueSerialized = entityTransformSync.LastValueFromServer as NetworkTransform;
                    if (lastValueSerialized != null)
                    {
                        var timeMachine = entityTransformSync.TimeMachine;
                        if (timeMachine != null)
                        {
                            var lastValueRelative = lastValueSerialized.DeserializeFromNetwork();
                            var lastValueAbsolute = DefaultFinalTransform.Create(entity.FinalTransform.ParentObject,
                                                                                 new TransformContainer(lastValueRelative));

                            var clientLocalTickValueRelative = timeMachine.Get(_localTick) as ITransform;
                            var clientLocalTickValueAbsolute = DefaultFinalTransform.Create(entity.FinalTransform.ParentObject,
                                                                                            new TransformContainer(clientLocalTickValueRelative));

                            var clientRewindValueRelative = timeMachine.Get(_localTick - _networkEngine.ClientRenderDelayTicks) as ITransform;
                            var clientRewindValueAbsolute = DefaultFinalTransform.Create(entity.FinalTransform.ParentObject,
                                                                                         new TransformContainer(clientRewindValueRelative));

                            var lastValuePoint   = Vector3.Transform(Vector3.Zero, lastValueAbsolute.AbsoluteMatrix);
                            var lastValueUp      = Vector3.Transform(Vector3.Up, lastValueAbsolute.AbsoluteMatrix);
                            var lastValueForward = Vector3.Transform(Vector3.Forward, lastValueAbsolute.AbsoluteMatrix);
                            var lastValueLeft    = Vector3.Transform(Vector3.Left, lastValueAbsolute.AbsoluteMatrix);

                            var clientLocalTickPoint   = Vector3.Transform(Vector3.Zero, clientLocalTickValueAbsolute.AbsoluteMatrix);
                            var clientLocalTickUp      = Vector3.Transform(Vector3.Up, clientLocalTickValueAbsolute.AbsoluteMatrix);
                            var clientLocalTickForward = Vector3.Transform(Vector3.Forward, clientLocalTickValueAbsolute.AbsoluteMatrix);
                            var clientLocalTickLeft    = Vector3.Transform(Vector3.Left, clientLocalTickValueAbsolute.AbsoluteMatrix);

                            var clientRewindValueTickPoint   = Vector3.Transform(Vector3.Zero, clientRewindValueAbsolute.AbsoluteMatrix);
                            var clientRewindValueTickUp      = Vector3.Transform(Vector3.Up, clientRewindValueAbsolute.AbsoluteMatrix);
                            var clientRewindValueTickForward = Vector3.Transform(Vector3.Forward, clientRewindValueAbsolute.AbsoluteMatrix);
                            var clientRewindValueTickLeft    = Vector3.Transform(Vector3.Left, clientRewindValueAbsolute.AbsoluteMatrix);

                            if (entity.GetType().Name == "CubeEntity")
                            {
                                Console.WriteLine(lastValueSerialized);
                            }

                            // Render the previous and next server states.
                            _debugRenderer.RenderDebugLine(renderContext, lastValuePoint, lastValueUp, Color.Red, Color.Red);
                            _debugRenderer.RenderDebugLine(renderContext, lastValuePoint, lastValueForward, Color.Red, Color.Red);
                            _debugRenderer.RenderDebugLine(renderContext, lastValuePoint, lastValueLeft, Color.Red, Color.Red);
                            _debugRenderer.RenderDebugLine(renderContext, clientLocalTickPoint, clientLocalTickUp, Color.Orange, Color.Orange);
                            _debugRenderer.RenderDebugLine(renderContext, clientLocalTickPoint, clientLocalTickForward, Color.Orange, Color.Orange);
                            _debugRenderer.RenderDebugLine(renderContext, clientLocalTickPoint, clientLocalTickLeft, Color.Orange, Color.Orange);
                            _debugRenderer.RenderDebugLine(renderContext, clientRewindValueTickPoint, clientRewindValueTickUp, Color.Yellow, Color.Yellow);
                            _debugRenderer.RenderDebugLine(renderContext, clientRewindValueTickPoint, clientRewindValueTickForward, Color.Yellow, Color.Yellow);
                            _debugRenderer.RenderDebugLine(renderContext, clientRewindValueTickPoint, clientRewindValueTickLeft, Color.Yellow, Color.Yellow);
                        }
                    }
                }
            }
        }