示例#1
0
        public void Render(Moment now, GraphicsDevice graphicsDevice, ISpriteBatch spriteBatch, TextureContent content, HolofunkView view)
        {
            if (RootNode != null) {
                RootNode.Render(now, graphicsDevice, spriteBatch, content, view, Transform.Identity, 0);
            }

            Spam.Graphics.WriteLine("End Render");
        }
示例#2
0
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice,
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform,
            int depth)
        {
            bool positionMirrored =
                SecondaryViewOption == SecondaryViewOption.PositionMirrored
                && view == HolofunkView.Secondary;

            Vector2 p0 = m_p0 + parentTransform.Translation;
            Vector2 p1 = m_p1 + parentTransform.Translation;

            if (positionMirrored) {
                p0 = new Vector2(spriteBatch.Viewport.X - p0.X, p0.Y);
                p1 = new Vector2(spriteBatch.Viewport.X - p1.X, p1.Y);
            }

            Vector2 diff = Vector2.Subtract(p1, p0);
            float angleRadians = (float)Math.Atan2(diff.Y, diff.X);
            float length = (float)Math.Sqrt(diff.X * diff.X + diff.Y * diff.Y) / 2;

            // Use NonPremultiplied, as our sprite textures are not premultiplied
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            spriteBatch.Draw(
                content.TinyDot,
                p0,
                null,
                Color,
                angleRadians,
                new Vector2(0f, 1f), // we pivot around the center of the left edge of the 2x2 square
                new Vector2(length, LocalTransform.Scale.Y),
                SpriteEffects.None,
                0);

            spriteBatch.End();
        }
示例#3
0
        protected override void DoRender(Moment now, GraphicsDevice graphicsDevice, ISpriteBatch spriteBatch, TextureContent content, HolofunkView view, Transform parentTransform, int depth)
        {
            m_videoRateCounter += m_videoRateFunc();
            if (m_videoRateCounter >= 1f) {
                m_videoRateCounter -= 1f;
                lock (this) {
                    if (VideoStream != null) {
                        s_totalRenders++;

                        Slice<Frame, byte> videoImage = VideoStream.GetClosestSliver(now.Time + MagicNumbers.LatencyCompensationDuration);

                        if (!videoImage.IsEmpty()) {
                            if (videoImage.Equals(m_lastVideoFrame)) {
                                // skip the setData
                                s_redundantSetDatas++;
                            }
                            else {
                                // blast the data in there with a single pointer-based memory copy
                                videoImage.RawAccess((array, offset, count) => m_videoNode.Texture.SetData(array, (int)offset, (int)count));
                                m_lastVideoFrame = videoImage;
                            }
                        }
                    }
                    else {
                        // ain't nothing to show
                        m_videoNode.Texture.SetData(BlankTextureData);
                    }
                }
            }

            base.DoRender(now, graphicsDevice, spriteBatch, content, view, parentTransform, depth);
        }
        /// <summary>Render this AParentSceneNode by rendering all its children.</summary>
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice, 
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform, 
            int depth)
        {
            Transform combinedTransform = parentTransform.CombineWith(LocalTransform);

            if (view == HolofunkView.Secondary && SecondaryViewOption == SecondaryViewOption.PositionMirrored) {
                combinedTransform = new Transform(
                    new Vector2(
                        spriteBatch.Viewport.X - combinedTransform.Translation.X,
                        combinedTransform.Translation.Y),
                    combinedTransform.Scale);
            }

            Spam.Graphics.WriteLine(new string(' ', depth * 4) + Label + ": parentTransform " + parentTransform + ", localTransform " + LocalTransform + ", combinedTransform " + combinedTransform);

            // m_children must only be enumerated / mutated under lock (this)
            lock (this) {
                m_childSnapshot.AddRange(m_children);
            }

            for (int i = 0; i < m_childSnapshot.Count; i++) {
                m_childSnapshot[i].Render(now, graphicsDevice, spriteBatch, content, view, combinedTransform, depth + 1);
            }

            // note that clearing preserves the capacity in the list, so no reallocation on next render
            m_childSnapshot.Clear();
        }
示例#5
0
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice, 
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform, 
            int depth)
        {
            Transform combinedTransform = parentTransform.CombineWith(LocalTransform);

            spriteBatch.Begin();

            Vector2 textSize = content.SpriteFont.MeasureString(m_text);
            Vector2 origin = Vector2.Zero;

            if (Alignment == Alignment.Centered) {
                origin = textSize / 2;
            }
            else if (Alignment == Alignment.TopRight) {
                origin = new Vector2(textSize.X, 0);
            }

            spriteBatch.DrawString(
                content.SpriteFont,
                m_text,
                combinedTransform.Translation,
                Color,
                Rotation,
                origin,
                combinedTransform.Scale.X,
                SpriteEffects.None,
                0);

            spriteBatch.End();
        }
示例#6
0
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice,
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform,
            int depth)
        {
            if (m_totalBeats == 0) {
                // there is no actual track here; we do not render
                return;
            }

            Transform combinedTransform = parentTransform.CombineWith(LocalTransform);

            // How many measures?
            long measureCount = (m_totalBeats + 3) / 4;

            // note that the quarter-circle only takes up one quarter of quarterCircleRect; this is deliberate
            Rectangle quarterCircleRect = TextureRect(content.QuarterHollowCircle, combinedTransform.Scale * m_textureScale);

            Vector2 measuresOrigin = combinedTransform.Translation;
            measuresOrigin.X -= ((Math.Min(4, measureCount) * quarterCircleRect.Width) / 2);

            Color color = m_colorFunc();

            Spam.Graphics.WriteLine(new string(' ', depth * 4) + Label + ": parentTransform " + parentTransform + ", localTransform " + LocalTransform + ", combinedTransform " + combinedTransform + ", color " + color.ToString());

            for (int b = 0; b < m_totalBeats; b++) {
                float filledness;
                if (m_fillInEveryBeat) {
                    if (b < m_currentBeat) {
                        filledness = 1;
                    }
                    else if (b == m_currentBeat) {
                        filledness = (float)m_fractionalBeat;
                    }
                    else {
                        filledness = 0;
                    }
                }
                else {
                    if (b == m_currentBeat) {
                        filledness = (float)(1 - m_fractionalBeat);
                    }
                    else {
                        filledness = 0;
                    }
                }

                DrawQuarterCircle(spriteBatch, content, quarterCircleRect, measuresOrigin, b, color, filledness, depth);
            }
        }
示例#7
0
        internal void Render(Moment now, GraphicsDevice graphicsDevice, ISpriteBatch spriteBatch, GameTime gameTime, HolofunkView view, Color backgroundColor)
        {
            graphicsDevice.Clear(backgroundColor);

            m_model.SceneGraph.Render(now, graphicsDevice, spriteBatch, m_model.Content, view);
        }
示例#8
0
        protected override void DoRender(
            Moment now,
            GraphicsDevice graphicsDevice, 
            ISpriteBatch spriteBatch,
            TextureContent content,
            HolofunkView view,
            Transform parentTransform,
            int depth)
        {
            // no texture = no-op
            if (m_texture == null) {
                return;
            }

            int left = -(int)((float)m_texture.Width * m_origin.X);
            int top = -(int)((float)m_texture.Height * m_origin.Y);
            Rectangle rect = new Rectangle(left, top, m_texture.Width, m_texture.Height);

            Transform combinedTransform = parentTransform.CombineWith(LocalTransform);

            Rectangle transformedRect = rect * combinedTransform;

            Spam.Graphics.WriteLine(new string(' ', depth * 4) + Label + ": parentTransform " + parentTransform + ", localTransform " + LocalTransform + ", combinedTransform " + combinedTransform + "; start rect " + rect.FormatToString() + "; transformedRect " + transformedRect.FormatToString());

            Texture2D texture = m_texture;
            SpriteEffects effects = SpriteEffects.None;

            if (view == HolofunkView.Secondary) {
                if ((SecondaryViewOption & SecondaryViewOption.TextureMirrored) != 0) {
                    effects = SpriteEffects.FlipHorizontally;
                }

                if ((SecondaryViewOption & SecondaryViewOption.PositionMirrored) != 0) {
                    // need to flip transformedRect around center of viewport
                    int newLeft = (int)spriteBatch.Viewport.X - transformedRect.Right;

                    transformedRect = new Rectangle(newLeft, transformedRect.Y, transformedRect.Width, transformedRect.Height);
                }

                if ((SecondaryViewOption & SecondaryViewOption.SecondTexture) != 0) {
                    HoloDebug.Assert(m_secondaryTexture != null);
                    texture = m_secondaryTexture;
                }
            }

            Color color = m_color;
            if (view == HolofunkView.Secondary && m_secondaryColor.HasValue) {
                color = m_secondaryColor.Value;
            }

            // Use NonPremultiplied, as our sprite textures are not premultiplied
            spriteBatch.Begin(SpriteSortMode.Deferred, BlendState.NonPremultiplied);

            spriteBatch.Draw(
                texture,
                transformedRect,
                null,
                color,
                0,
                m_origin,
                effects,
                0);

            spriteBatch.End();
        }