Exemple #1
0
 public BasicSprite(GraphicsDevice _device, Quad _quad, BasicEffect _effect, Texture2D _texture)
 {
     quad = _quad;
     effect = _effect;
     texture = _texture;
     device = _device;
 }
Exemple #2
0
        /// <summary>
        /// Calculates the log (base 2) of a Quad.            
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static double Log2(Quad value)
        {
            if (value.SignificandBits >= QuadhighestBit) return double.NaN;
            if (value.Exponent == long.MinValue) return double.NegativeInfinity; //Log(0)

            return Math.Log(value.SignificandBits | QuadhighestBit, 2) + value.Exponent;
        }
Exemple #3
0
 public CaptureCamera(Capture capture, PointF principalPointEstimate, double focalLength, double nearPlaneDistance, double farPlaneDistance, int numRadialDistortionCoefficients)
     : base(capture.Name, capture.Uuid, capture.Size, principalPointEstimate, focalLength, nearPlaneDistance, farPlaneDistance, numRadialDistortionCoefficients)
 {
     Capture = capture;            
     Quad = new Quad(capture.Size, Capture.RgbaTexture2D) { Color = Color.White.Alpha(0.4f), };
     Quad.World = Matrix.CreateTranslation(0, 0, 0.1f);
 }
Exemple #4
0
 public void forwardIsStillForwardWhenUpVectorIsNegative()
 {
     var upScale = 2f;
     var quad = new Quad(Vector3.Zero, Vector3.Backward, new Vector3(0f, upScale, 0f), new Vector3(1f, 0, 0), 1, 1);
     Assert.That(quad.Right, Is.EqualTo(new Vector3(1f, 0, 0)));
     Assert.That(quad.LowerRight, Is.EqualTo(new Vector3(1f, -upScale, 0f)));
 }
        public LightingComponent(GraphicsDevice device)
        {
            quad = new Quad(device);
            quad.SetPosition(depth: 0.99999f);

            restoreDepth = new Material(Content.Load<Effect>("RestoreDepth"));
            copyTexture = new Material(Content.Load<Effect>("CopyTexture"));
        }
Exemple #6
0
 public Ssao(GraphicsDevice device)
 {
     _ssaoMaterial = new Material(Content.Load<Effect>("SSAO"));
     _ssaoBlurMaterial = new Material(Content.Load<Effect>("BlurSSAO"));
     Random rand = new Random();
     _ssaoMaterial.Parameters["Random"].SetValue(GenerateRandomNormals(device, 4, 4, rand));//content.Load<Texture2D>("randomnormals"));
     _ssaoMaterial.Parameters["RandomResolution"].SetValue(4);
     _quad = new Quad(device);
 }
Exemple #7
0
        public Gaussian(GraphicsDevice device)
        {
            _effect = Content.Load<Effect>("Gaussian");
            _quad = new Quad(device);
            _device = device;

            var sampleCount = _effect.Parameters["Weights"].Elements.Count;
            _weights = new float[sampleCount];
            _offsets = new float[sampleCount];
        }
Exemple #8
0
 public Ssao(GraphicsDevice device)
 {
     this.ssaoMaterial = new Material(Content.Load<Effect>("SSAO"));
     this.ssaoBlurMaterial = new Material(Content.Load<Effect>("BlurSSAO"));
     this.ssaoMaterial.Parameters["Random"].SetValue(GenerateRandomNormals(device, 4, 4));//content.Load<Texture2D>("randomnormals"));
     this.ssaoMaterial.Parameters["RandomResolution"].SetValue(4);
     this.ssaoMaterial.Parameters["Samples"].SetValue(GenerateRandomSamplePositions(16));
     this.gaussian = new Gaussian(device);
     this.quad = new Quad(device);
 }
Exemple #9
0
 /// <summary>
 /// Removes any fractional part of the provided value (rounding down for positive numbers, and rounding up for negative numbers)            
 /// </summary>
 /// <param name="value"></param>
 /// <returns></returns>
 public static Quad Truncate(Quad value)
 {
     if (value.Exponent <= -64) 
         return Quad.Zero;
     else if (value.Exponent >= 0)
         return value;
     else
     {
         //clear least significant "-value.exponent" bits that come after the binary point by shifting
         return new Quad((value.SignificandBits >> (int)(-value.Exponent)) << (int)(-value.Exponent), value.Exponent);
     }
 }
Exemple #10
0
        public ToneMapComponent(GraphicsDevice device)
        {
            _quad = new Quad(device);
            var effect = Content.Load<Effect>("CalculateLuminance");
            _calculateLuminance = new Material(effect.Clone(), "ExtractLuminance");
            _adaptLuminance = new Material(effect.Clone(), "AdaptLuminance");
            _readLuminance = new Material(effect.Clone(), "ReadLuminance");
            _toneMap = new Material(Content.Load<Effect>("ToneMap"), null);
            _bloom = Content.Load<Effect>("Bloom");
            _gaussian = new Gaussian(device);

            _adaptedLuminance = new RenderTarget2D[2];
            _adaptedLuminance[0] = new RenderTarget2D(device, 1, 1, false, SurfaceFormat.Single, DepthFormat.None);
            _adaptedLuminance[1] = new RenderTarget2D(device, 1, 1, false, SurfaceFormat.Single, DepthFormat.None);
        }
Exemple #11
0
        /// <summary>
        /// Returns only the fractional part of the provided value.  Equivalent to value % 1.
        /// </summary>
        /// <param name="value"></param>
        /// <returns></returns>
        public static Quad Fraction(Quad value)
        {
            if (value.Exponent >= 0) return Quad.Zero; //no fraction
            else if (value.Exponent <= -64) return value; //all fraction (or zero)
            else
            {
                //clear most significant 64+value.exponent bits before the binary point
                ulong bits = (value.SignificandBits << (int)(64 + value.Exponent)) >> (int)(64 + value.Exponent);
                if (bits == 0) return Quad.Zero; //value is an integer

                int shift = Quadnlz(bits); //renormalize                

                return new Quad((~QuadhighestBit & (bits << shift)) | (QuadhighestBit & value.SignificandBits), value.Exponent - shift);
            }
        }
Exemple #12
0
        public void cropToRectangle()
        {
            var quadWidth = 10;
            var quadHeight = 10;
            var quad = new Quad(Vector3.Zero, Vector3.Backward, Vector3.Up, Vector3.Right, quadWidth, quadHeight);

            const int cropSize = 4;
            quad.cropTextureToRectangle(new Rectangle(2, 2, cropSize, cropSize), quadWidth, quadHeight);

            var upperLeft = quad.Vertices[1];
            var lowerRight = quad.Vertices[2];

            Assert.That(upperLeft.TextureCoordinate, Is.EqualTo(new Vector2(2 / (float) quadWidth, 2 / (float) quadHeight)));
            Assert.That(lowerRight.TextureCoordinate, Is.EqualTo(new Vector2((2 + cropSize) / (float) quadWidth, (2 + cropSize) / (float) quadHeight)));
        }
        public ToneMapComponent(GraphicsDevice device)
        {
            quad = new Quad(device);
            var effect = Content.Load<Effect>("CalculateLuminance");
            calculateLuminance = new Material(effect.Clone(), "ExtractLuminance");
            adaptLuminance = new Material(effect.Clone(), "AdaptLuminance");
            readLuminance = new Material(effect.Clone(), "ReadLuminance");
            copyLuminance = new Material(effect.Clone(), "Copy");
            toneMap = new Material(Content.Load<Effect>("ToneMap"), null);
            bloom = Content.Load<Effect>("Bloom");
            gaussian = new Gaussian(device);
            scale = new Resample(device);

            adaptedLuminance = new RenderTarget2D[2];
            adaptedLuminance[0] = new RenderTarget2D(device, 1, 1, false, SurfaceFormat.Single, DepthFormat.None);
            adaptedLuminance[1] = new RenderTarget2D(device, 1, 1, false, SurfaceFormat.Single, DepthFormat.None);

            device.SetRenderTarget(adaptedLuminance[previous]);
            device.Clear(Color.Transparent);
            device.SetRenderTarget(null);
        }
Exemple #14
0
        /// <summary>
        /// Initializes the control.
        /// </summary>
        protected override void Initialize()
        {
            content = new ContentManager(Services, "Content");

            // Hook the idle event to constantly redraw our animation.
            Application.Idle += delegate { Invalidate(); };

            this.monsterTexture = content.Load<Texture2D>(@"mineplayer");
            this.grassTexture = content.Load<Texture2D>(@"grass");

            this.SetupViewport();

            quad = new Quad(Vector3.Zero, Vector3.Backward, Vector3.Up, 2, 2);
            quadEffect = new BasicEffect(this.GraphicsDevice);
            quadEffect.EnableDefaultLighting();

            quadEffect.World = this.World;
            quadEffect.View = this.View;
            quadEffect.Projection = this.Projection;
            quadEffect.TextureEnabled = true;
            quadEffect.Texture = grassTexture;
        }
Exemple #15
0
 /// <summary>
 /// Efficiently divides the Quad by 2^shift.
 /// </summary>
 /// <param name="qd"></param>
 /// <param name="shift"></param>
 /// <returns></returns>
 public static Quad RightShift(Quad qd, long shift)
 {
     if (qd.Exponent == long.MinValue)
         return Zero;
     else
         return new Quad(qd.SignificandBits, qd.Exponent - shift);
 }
Exemple #16
0
        /// <summary>
        /// Divides the current instance by the specified value.
        /// </summary>
        /// <param name="divisor"></param>
        public void Divide(Quad divisor)
        {
            #region Division
            if (divisor.Exponent == long.MinValue) // something / 0
                throw new DivideByZeroException();
            else if (this.Exponent == long.MinValue) //0 / non-zero == 0
                return; //we're already 0

            ulong un1 = 0,     // Norm. dividend LSD's.
                     vn1, vn0,        // Norm. divisor digits.
                     q1, q0,          // Quotient digits.
                     un21,// Dividend digit pairs.
                     rhat;            // A remainder.            

            //result.Significand = highestBit & (this.Significand ^ divisor.Significand); //determine the sign bit

            //this.Significand |= highestBit; //de-implicitize the 1 before the binary point
            //divisor.Significand |= highestBit;

            long adjExponent = 0;
            ulong thisAdjSignificand = this.SignificandBits | highestBit;
            ulong divisorAdjSignificand = divisor.SignificandBits | highestBit;

            if (thisAdjSignificand >= divisorAdjSignificand)
            {
                //need to make this's significand smaller than divisor's
                adjExponent = 1;
                un1 = (this.SignificandBits & 1) << 31;
                thisAdjSignificand = thisAdjSignificand >> 1;
            }

            vn1 = divisorAdjSignificand >> 32;            // Break divisor up into
            vn0 = divisor.SignificandBits & 0xFFFFFFFF;         // two 32-bit digits.            

            q1 = thisAdjSignificand / vn1;            // Compute the first
            rhat = thisAdjSignificand - q1 * vn1;     // quotient digit, q1.
        again1:
            if (q1 >= b || q1 * vn0 > b * rhat + un1)
            {
                q1 = q1 - 1;
                rhat = rhat + vn1;
                if (rhat < b) goto again1;
            }

            un21 = thisAdjSignificand * b + un1 - q1 * divisorAdjSignificand;  // Multiply and subtract.

            q0 = un21 / vn1;            // Compute the second
            rhat = un21 - q0 * vn1;     // quotient digit, q0.
        again2:
            if (q0 >= b || q0 * vn0 > b * rhat)
            {
                q0 = q0 - 1;
                rhat = rhat + vn1;
                if (rhat < b) goto again2;
            }

            thisAdjSignificand = q1 * b + q0; //convenient place to store intermediate result

            //if (this.Significand == 0) //the final significand should never be 0
            //    result.Exponent = 0;
            //else

            if (thisAdjSignificand < (1UL << 63))
            {
                this.SignificandBits = (~highestBit & (thisAdjSignificand << 1)) | ((this.SignificandBits ^ divisor.SignificandBits) & highestBit);
                this.Exponent = this.Exponent - (divisor.Exponent + 64) - 1 + adjExponent;
            }
            else
            {
                this.SignificandBits = (~highestBit & thisAdjSignificand) | ((this.SignificandBits ^ divisor.SignificandBits) & highestBit);
                this.Exponent = this.Exponent - (divisor.Exponent + 64) + adjExponent;
            }
            #endregion            
        }
Exemple #17
0
        /// <summary>
        /// Subtracts the specified value from the current instance.
        /// </summary>
        /// <param name="value"></param>
        public void Subtract(Quad value)
        {
            #region Subtraction
            if ((this.SignificandBits ^ value.SignificandBits) >= highestBit) //this and value have different signs--use addition instead            
            {
                this.Add(new Quad(value.SignificandBits ^ highestBit, value.Exponent));
                return;
            }

            //as in addition, we handle 0's implicitly--they will have an exponent at least 64 less than any valid non-zero value.

            if (this.Exponent > value.Exponent)
            {
                if (this.Exponent >= value.Exponent + 64)
                    return; //value too small to make a difference
                else
                {
                    ulong bits = (this.SignificandBits | highestBit) - ((value.SignificandBits | highestBit) >> (int)(this.Exponent - value.Exponent));

                    //make sure MSB is 1                       
                    int highestBitPos = nlz(bits);
                    this.SignificandBits = ((bits << highestBitPos) & ~highestBit) | (this.SignificandBits & highestBit);
                    this.Exponent = this.Exponent - highestBitPos;
                }
            }
            else if (this.Exponent < value.Exponent) //must subtract our significand from value, and switch the sign
            {
                if (value.Exponent >= this.Exponent + 64)
                {
                    this.SignificandBits = value.SignificandBits ^ highestBit;
                    this.Exponent = value.Exponent;
                    return;
                }

                ulong bits = (value.SignificandBits | highestBit) - ((this.SignificandBits | highestBit) >> (int)(value.Exponent - this.Exponent));

                //make sure MSB is 1                       
                int highestBitPos = nlz(bits);
                this.SignificandBits = ((bits << highestBitPos) & ~highestBit) | (~value.SignificandBits & highestBit);
                this.Exponent = value.Exponent - highestBitPos;
            }
            else // (this.Exponent == value.Exponent)
            {                
                if (value.SignificandBits > this.SignificandBits) //must switch sign
                {
                    ulong bits = value.SignificandBits - this.SignificandBits; //notice that we don't worry about de-implicitizing the MSB--it'd be eliminated by subtraction anyway
                    int highestBitPos = nlz(bits);
                    this.SignificandBits = ((bits << highestBitPos) & ~highestBit) | (~value.SignificandBits & highestBit);
                    this.Exponent = value.Exponent - highestBitPos;
                }
                else if (value.SignificandBits < this.SignificandBits) //sign remains the same
                {
                    ulong bits = this.SignificandBits - value.SignificandBits; //notice that we don't worry about de-implicitizing the MSB--it'd be eliminated by subtraction anyway
                    int highestBitPos = nlz(bits);
                    this.SignificandBits = ((bits << highestBitPos) & ~highestBit) | (this.SignificandBits & highestBit);
                    this.Exponent = this.Exponent - highestBitPos;
                }
                else //this == value
                {
                    //result is 0
                    this.SignificandBits = 0;
                    this.Exponent = long.MinValue;
                }
            }
            #endregion
        }
Exemple #18
0
        /// <summary>
        /// Adds the specified value to the current instance.
        /// </summary>
        /// <param name="value"></param>
        public void Add(Quad value)
        {
            #region Addition

            if ((this.SignificandBits ^ value.SignificandBits) >= highestBit) //this and value have different signs--use subtraction instead
            {
                Subtract(new Quad(value.SignificandBits ^ highestBit, value.Exponent));
                return;
            }

            //note on zeros: adding 0 results in a nop because the exponent is 64 less than any valid exponent.

            if (this.Exponent > value.Exponent)
            {
                if (this.Exponent >= value.Exponent + 64)
                    return; //value too small to make a difference
                else
                {
                    ulong bits = (this.SignificandBits | highestBit) + ((value.SignificandBits | highestBit) >> (int)(this.Exponent - value.Exponent));

                    if (bits < highestBit) //this can only happen in an overflow  
                    {
                        this.SignificandBits = (this.SignificandBits & highestBit) | (bits >> 1);
                        this.Exponent = this.Exponent + 1;
                    }
                    else
                    {
                        this.SignificandBits = (this.SignificandBits & highestBit) | (bits & ~highestBit);
                        //this.Exponent = this.Exponent; //exponent stays the same
                    }
                }
            }
            else if (this.Exponent < value.Exponent)
            {
                if (value.Exponent >= this.Exponent + 64)
                {
                    this.SignificandBits = value.SignificandBits; //too small to matter
                    this.Exponent = value.Exponent;
                }
                else
                {
                    ulong bits = (value.SignificandBits | highestBit) + ((this.SignificandBits | highestBit) >> (int)(value.Exponent - this.Exponent));

                    if (bits < highestBit) //this can only happen in an overflow                    
                    {
                        this.SignificandBits = (value.SignificandBits & highestBit) | (bits >> 1);
                        this.Exponent = value.Exponent + 1;
                    }
                    else
                    {
                        this.SignificandBits = (value.SignificandBits & highestBit) | (bits & ~highestBit);
                        this.Exponent = value.Exponent;
                    }
                }
            }
            else //expDiff == 0
            {
                if (this.Exponent == long.MinValue) //verify that we're not adding two 0's
                    return; //we are already 0, so just return
                
                //the MSB must have the same sign, so the MSB will become 0, and logical overflow is guaranteed in this situation (so we can shift right and increment the exponent).
                this.SignificandBits = ((this.SignificandBits + value.SignificandBits) >> 1) | (this.SignificandBits & highestBit);
                this.Exponent = this.Exponent + 1;
            }

            #endregion
        }
Exemple #19
0
        /// <summary>
        /// Multiplies this instance by the specified value.
        /// </summary>
        /// <param name="multiplier"></param>
        public void Multiply(Quad multiplier)
        {
            
            ulong high1 = (this.SignificandBits | highestBit) >> 32; //de-implicitize the 1
            ulong high2 = (multiplier.SignificandBits | highestBit) >> 32;

            //because the MSB of both significands is 1, the MSB of the result will also be 1, and the product of low bits on both significands is dropped (and thus we can skip its calculation)
            ulong significandBits = high1 * high2 + (((this.SignificandBits & lowWordMask) * high2) >> 32) + ((high1 * (multiplier.SignificandBits & lowWordMask)) >> 32);

            if (significandBits < (1UL << 63))
            {                
                //Checking for zeros here is significantly faster (~15%) on my machine than at the beginning,
                //because this branch is rarely taken.  This is acceptable because a zero will have a significand of 0,
                //and thus (when the significant bit is erroneously OR'd to it) multiplying by that zero cannot yield a value
                //of significandBits greater than or equal to 1 << 63.
                if (this.Exponent == long.MinValue || multiplier.Exponent == long.MinValue)
                {
                    this.Exponent = long.MinValue;
                    this.SignificandBits = 0;
                }
                else
                {
                    this.SignificandBits = ((this.SignificandBits ^ multiplier.SignificandBits) & highestBit) | ((significandBits << 1) & ~highestBit);
                    this.Exponent = this.Exponent + multiplier.Exponent - 1 + 64;
                }

            }
            else
            {
                this.SignificandBits = ((this.SignificandBits ^ multiplier.SignificandBits) & highestBit) | (significandBits & ~highestBit);
                this.Exponent = this.Exponent + multiplier.Exponent + 64;
            }

            #region Multiply with reduced branching (slightly faster?)
            //zeros
            ////if (this.Exponent == long.MinValue)// || multiplier.Exponent == long.MinValue)
            ////{
            ////    this.Exponent = long.MinValue;
            ////    this.Significand = 0;
            ////    return;
            ////}  

            //ulong high1 = (this.Significand | highestBit ) >> 32; //de-implicitize the 1
            //ulong high2 = (multiplier.Significand | highestBit) >> 32;

            ////because the MSB of both significands is 1, the MSB of the result will also be 1, and the product of low bits on both significands is dropped (and thus we can skip its calculation)
            //ulong significandBits = high1 * high2 + (((this.Significand & lowWordMask) * high2) >> 32) + ((high1 * (multiplier.Significand & lowWordMask)) >> 32);

            //if (significandBits < (1UL << 63)) //first bit clear?
            //{
            //    long zeroMask = ((this.Exponent ^ -this.Exponent) & (multiplier.Exponent ^ -multiplier.Exponent)) >> 63;                    
            //    this.Significand = (ulong)zeroMask & ((this.Significand ^ multiplier.Significand) & highestBit) | ((significandBits << 1) & ~highestBit);
            //    this.Exponent = (zeroMask & (this.Exponent + multiplier.Exponent - 1 + 64)) | (~zeroMask & long.MinValue);
            //}
            //else
            //{
            //    this.Significand = ((this.Significand ^ multiplier.Significand) & highestBit) | (significandBits & ~highestBit);
            //    this.Exponent = this.Exponent + multiplier.Exponent + 64;
            //}

            ////long zeroMask = ((isZeroBit1 >> 63) & (isZeroBit2 >> 63));
            ////this.Significand = (ulong)zeroMask & ((this.Significand ^ multiplier.Significand) & highestBit) | ((significandBits << (int)(1 ^ (significandBits >> 63))) & ~highestBit);
            ////this.Exponent = (zeroMask & (this.Exponent + multiplier.Exponent - 1 + 64 + (long)(significandBits >> 63))) | (~zeroMask & long.MinValue);

            #endregion
        }
Exemple #20
0
        /// <summary>
        /// Retrieves the integer portion of the quad as a string,
        /// assuming that the quad's value is less than long.MaxValue.
        /// No sign ("-") is prepended to the result in the case of negative values.
        /// </summary>
        /// <returns></returns>
        private static string IntegerString(Quad quad,int digits)
        {
            if (quad.Exponent > 0) throw new ArgumentOutOfRangeException("The given quad is larger than long.MaxValue");
            if (quad.Exponent <= -64) return "0";

            ulong significand = quad.SignificandBits | highestBit; //make explicit the implicit bit
            return (significand >> (int)(-quad.Exponent)).ToString( new string('0', digits ));
        }
Exemple #21
0
 Quad MakeQuad(Packet in_packet)
 {
     if (in_packet.ContainsLayer(Protocol.TCP))
     {
         TCPPacket tcp = (TCPPacket)in_packet;
         Quad q = new Quad
         {
             dstIP = tcp.DestIP,
             dstPort = tcp.DestPort,
             srcPort = tcp.SourcePort,
             srcIP = tcp.SourceIP
         };
         return q;
     }
     return null;
 }
Exemple #22
0
        public ControlAxis()
        {
            _axisColors = new Color[3];
            _axisColors[0] = Color.Red;
            _axisColors[1] = Color.Green;
            _axisColors[2] = Color.Blue;
            _highlightColor = Color.Gold;

            // text projected in 3D
            _axisText = new string[3];
            _axisText[0] = "X";
            _axisText[1] = "Y";
            _axisText[2] = "Z";

            _font = Engine.ContentLoader.GetLoadedFont("DiplomFont");

            X_AxisDirection = Vector3.Right;
            Y_AxisDirection = Vector3.Up;
            Z_AxisDirection = Vector3.Forward;

            #region Line init
            _lineEffect = new BasicEffect(Engine.ActiveGraphicsDevice) { VertexColorEnabled = true, AmbientLightColor = Vector3.One, EmissiveColor = Vector3.One };

            var vertexList = new List<VertexPositionColor>(18);

            // helper to apply colors
            Color xColor = _axisColors[0];
            Color yColor = _axisColors[1];
            Color zColor = _axisColors[2];

            // -- X Axis -- // index 0 - 5
            vertexList.Add(new VertexPositionColor(new Vector3(halfLineOffset, 0, 0), xColor));
            vertexList.Add(new VertexPositionColor(new Vector3(LINE_LENGTH, 0, 0), xColor));

            vertexList.Add(new VertexPositionColor(new Vector3(LINE_OFFSET, 0, 0), xColor));
            vertexList.Add(new VertexPositionColor(new Vector3(LINE_OFFSET, LINE_OFFSET, 0), xColor));

            vertexList.Add(new VertexPositionColor(new Vector3(LINE_OFFSET, 0, 0), xColor));
            vertexList.Add(new VertexPositionColor(new Vector3(LINE_OFFSET, 0, LINE_OFFSET), xColor));

            // -- Y Axis -- // index 6 - 11
            vertexList.Add(new VertexPositionColor(new Vector3(0, halfLineOffset, 0), yColor));
            vertexList.Add(new VertexPositionColor(new Vector3(0, LINE_LENGTH, 0), yColor));

            vertexList.Add(new VertexPositionColor(new Vector3(0, LINE_OFFSET, 0), yColor));
            vertexList.Add(new VertexPositionColor(new Vector3(LINE_OFFSET, LINE_OFFSET, 0), yColor));

            vertexList.Add(new VertexPositionColor(new Vector3(0, LINE_OFFSET, 0), yColor));
            vertexList.Add(new VertexPositionColor(new Vector3(0, LINE_OFFSET, LINE_OFFSET), yColor));

            // -- Z Axis -- // index 12 - 17
            vertexList.Add(new VertexPositionColor(new Vector3(0, 0, halfLineOffset), zColor));
            vertexList.Add(new VertexPositionColor(new Vector3(0, 0, LINE_LENGTH), zColor));

            vertexList.Add(new VertexPositionColor(new Vector3(0, 0, LINE_OFFSET), zColor));
            vertexList.Add(new VertexPositionColor(new Vector3(LINE_OFFSET, 0, LINE_OFFSET), zColor));

            vertexList.Add(new VertexPositionColor(new Vector3(0, 0, LINE_OFFSET), zColor));
            vertexList.Add(new VertexPositionColor(new Vector3(0, LINE_OFFSET, LINE_OFFSET), zColor));

            // -- Convert to array -- //
            _lineVertices = vertexList.ToArray();
            #endregion

            #region Helpers geomerty init
            _meshEffect = new BasicEffect(Engine.ActiveGraphicsDevice);

            _modelLocalSpace = new Matrix[3];
            _modelLocalSpace[0] = Matrix.CreateWorld(new Vector3(LINE_LENGTH, 0, 0), Vector3.Left, Vector3.Up);
            _modelLocalSpace[1] = Matrix.CreateWorld(new Vector3(0, LINE_LENGTH, 0), Vector3.Down, Vector3.Left);
            _modelLocalSpace[2] = Matrix.CreateWorld(new Vector3(0, 0, LINE_LENGTH), Vector3.Forward, Vector3.Up);

            #endregion

            #region Quads init
            _quads = new Quad[3];
            _quads[0] = new Quad(new Vector3(halfLineOffset, halfLineOffset, 0), Vector3.Backward, Vector3.Up, LINE_OFFSET,
                                 LINE_OFFSET); //XY
            _quads[1] = new Quad(new Vector3(halfLineOffset, 0, halfLineOffset), Vector3.Up, Vector3.Right, LINE_OFFSET,
                                 LINE_OFFSET); //ZX
            _quads[2] = new Quad(new Vector3(0, halfLineOffset, halfLineOffset), Vector3.Right, Vector3.Up, LINE_OFFSET,
                                 LINE_OFFSET); //YZ

            _quadEffect = new BasicEffect(Engine.ActiveGraphicsDevice) { DiffuseColor = _highlightColor.ToVector3(), Alpha = 0.5f };
            _quadEffect.EnableDefaultLighting();
            #endregion
        }
		void SyncChanges(int SpreadMax)
		{
			//mark everything for clear
			foreach(var quad in FQuads)
			{
				quad.Value.MarkForClear = true;
				foreach(var content in quad.Value.Content)
				{
					content.Value.MarkForClear = true;
				}
			}
			
			//check and add
			for(int i = 0; i<SpreadMax; i++)
			{
				int id = FInID[i];
				string path = FInPath[i];
				
				Quad quad;
				if (FQuads.ContainsKey(id))
				{
					quad = FQuads[id];
					quad.MarkForClear = false;
				} else {
					quad = new Quad();
					FQuads.Add(id, quad);
				}
				
				Quad.ContentItem content;
				if (quad.Content.ContainsKey(path)) {
					content = quad.Content[path];
					content.MarkForClear = false;
				} else {
					content = new Quad.ContentItem();
					quad.Content.Add(path, content);
				}
			}
			
			//clear anything marked for clear
			var toRemove = new List<int>();
			foreach(var quad in FQuads)
			{
				if (quad.Value.MarkForClear)
				{
					toRemove.Add(quad.Key);
				}
			}
			foreach(var quad in toRemove)
			{
				FQuads.Remove(quad);
			}
			foreach(var quad in FQuads)
			{
				var contentToRemove = new List<string>();
				foreach(var content in quad.Value.Content)
				{
					if (content.Value.MarkForClear)
					{
						contentToRemove.Add(content.Key);
					}
				}
				foreach(var content in contentToRemove)
				{
					quad.Value.Content.Remove(content);
				}
			}
		}
Exemple #24
0
 public void upVectorDoesNotChangeRightVector()
 {
     var upScale = 2f;
     var quad = new Quad(Vector3.Zero, Vector3.Backward, new Vector3(0f, upScale, 0f), new Vector3(scale, 0, 0), 1, 1);
     Assert.That(quad.Right, Is.EqualTo(new Vector3(scale, 0, 0)));
 }
 public GeometryBufferComponent(GraphicsDevice device)
 {
     clear = new Material(Content.Load<Effect>("ClearGBuffer"));
     scale = new Resample(device);
     quad = new Quad(device);
 }
		protected override void LoadContent()
		{
			base.LoadContent();

			quad = new Quad(Vector3.Zero, Vector3.Backward, Vector3.Up, 1, 1);
			View = Matrix.CreateLookAt(new Vector3(0, 0, 2), Vector3.Zero, Vector3.Up);
			Projection = Matrix.CreatePerspectiveFieldOfView(MathHelper.PiOver4, 4.0f / 3.0f, 1, 500);

			texture = Game.Content.Load<Texture2D>(Paths.Texture("GlassPane"));
			quadEffect = new BasicEffect(GraphicsDevice);

			if (enableLighting)
				quadEffect.EnableDefaultLighting();

			quadEffect.World = Matrix.Identity;
			quadEffect.View = View;
			quadEffect.Projection = Projection;
			quadEffect.TextureEnabled = true;
			quadEffect.Texture = texture;

		}
        /// <summary>
        /// Renders the 2D hard-edged shadow that would be cast from this ConvexHull's polygonal
        /// geometry by a light positioned at lightPosWS.
        /// </summary>
        /// <param name="lightPosWS">The position of the light in world coordinates.</param>
        public void RenderShadow(Vector2 lightPosWS)
        {
            Vector3 UVOffset = new Vector3(0.0f, -0.5f, 0.0f);

            // Transform the light position into model space
            Vector2 lightPos = Vector2.TransformCoordinate(lightPosWS, Matrix.Invert(worldMatrix));

            List<Edge> contourEdges = new List<Edge>();

            for (int edgeIndex = 0; edgeIndex < polygonGeometry.NumEdges; ++edgeIndex)
            {
                Edge edge = polygonGeometry.GetEdge(edgeIndex);
                Vector2 edgeCenter = (edge.Vertex1Pos + edge.Vertex2Pos) * 0.5f;
                Vector2 incidentLightDir = edgeCenter - lightPos;

                // If the edge faces away from the light source
                if (Vector2.Dot(incidentLightDir, edge.Normal) >= 0.0f)
                {
                    contourEdges.Add(edge);
                }
            }

            if (contourEdges.Count < 1 || contourEdges.Count == polygonGeometry.NumEdges)
            {
                return;
            }

            const float ExtrudeMagnitude = 1000.0f;

            List<Quad> quads = new List<Quad>();

            int quadIndex = 0;
            foreach (Edge edge in contourEdges)
            {
                Vector3 lightPosVec3 = new Vector3(lightPos.X, lightPos.Y, 1.0f);

                Vector3 vertex1 = new Vector3(
                    edge.Vertex1Pos.X, edge.Vertex1Pos.Y, 1.0f);
                Vector3 vertex2 = new Vector3(
                    edge.Vertex2Pos.X, edge.Vertex2Pos.Y, 1.0f);

                // Transform the position data from model space to world space
                vertex1.TransformCoordinate(worldMatrix);
                vertex2.TransformCoordinate(worldMatrix);
                lightPosVec3.TransformCoordinate(worldMatrix);

                Quad quad = new Quad();
                Color shadowColor = Color.FromArgb((int)(1 * 255.0f), 0, 0, 0);

                quad.Vertices[2 * quadIndex + 0].Position = vertex1 + UVOffset;
                quad.Vertices[2 * quadIndex + 0].Color = shadowColor.ToArgb();

                quad.Vertices[2 * quadIndex + 1].Position = vertex1 + ExtrudeMagnitude * (vertex1 - lightPosVec3)
                    + UVOffset;
                quad.Vertices[2 * quadIndex + 1].Color = shadowColor.ToArgb();

                quad.Vertices[2 * quadIndex + 2].Position = vertex2 + UVOffset;
                quad.Vertices[2 * quadIndex + 2].Color = shadowColor.ToArgb();

                quad.Vertices[2 * quadIndex + 3].Position = vertex2 + ExtrudeMagnitude * (vertex2 - lightPosVec3)
                    + UVOffset;
                quad.Vertices[2 * quadIndex + 3].Color = shadowColor.ToArgb();

                quads.Add(quad);
            }

            renderer.Begin(effect);

            renderer.WorldMatrix = Matrix.Identity;
            effect.SetValue("world", renderer.WorldMatrix);
            effect.SetValue("worldViewProj", renderer.WorldViewProjectionMatrix);
            renderer.SetPass(3);
            renderer.Device.VertexFormat = Direct3D.CustomVertex.PositionColoredTextured.Format;

            foreach (Quad quad in quads)
            {
                renderer.Device.DrawUserPrimitives(Direct3D.PrimitiveType.TriangleStrip, 2, quad.Vertices);
            }

            renderer.End();
        }
Exemple #28
0
 public static Quad Deserialize(int[] data, int index)
 {
     Quad q = new Quad();
     q.S = data[index+0];
     q.P = data[index+1];
     q.O = data[index+2];
     q.M = data[index+3];
     return q;
 }
Exemple #29
0
        private void AttachPerformanceBar()
        {
            var desireable = 14;
            var warning = 28;
            var unacceptable = 43;

            var height = 30;

            var text = new Text("", new Vector2(height, 2 * height), Color.White);
            var minq = new Quad(new Rectangle(0, 0, 1, height), Program.Renderer.LeaseWhiteTexel(), Color.Lime);
            var avgq = new Quad(new Rectangle(0, 0, 1, height / 3 * 2), Program.Renderer.LeaseWhiteTexel(), Color.Yellow);
            var maxq = new Quad(new Rectangle(0, 0, 1, height / 3), Program.Renderer.LeaseWhiteTexel(), Color.Red);

            Monitor.Scene.Add(maxq, avgq, minq, text);

            var whenPerfWindowSize = TimeSpan.FromSeconds(2.3);
            var whenPerfWindow = Program.WhenTick
                                        .Timestamp()
                                        .Scan(Enumerable.Empty<Timestamped<TimeSpan>>(),
                                                (acum, value) => from e in acum.StartWith(value)
                                                                 where e.Timestamp > DateTime.Now.Subtract(whenPerfWindowSize)
                                                                 select e)
                                        .Where(window => window != null && !window.IsEmpty())
                                        .Select(window => new
                                            {
                                                Min = window.Min(ts => ts.Value.TotalMilliseconds),
                                                Average = window.Average(ts => ts.Value.TotalMilliseconds),
                                                Max = window.Max(ts => ts.Value.TotalMilliseconds),
                                            });

            whenPerfWindow.Subscribe(window =>
                {
                    var min = (float)window.Min;
                    var avg = (float)window.Average;
                    var max = (float)window.Max;

                    var gradient = new Func<float, Color>(val =>
                    {
                        var lerp = MathHelper.Clamp(val, desireable, unacceptable);
                        return lerp < warning
                             ? Color.Lerp(Color.Lime, Color.Yellow, (lerp - desireable) / (warning - desireable))
                             : Color.Lerp(Color.Yellow, Color.Red, (lerp - warning) / (unacceptable - warning));
                    });

                    text.String = "{0:0.0} {1:0.0} {2:0.0}".FormatWith(min, avg, max);
                    text.FillColor = gradient(avg);
                    avgq.Color = gradient(avg);
                    minq.Color = gradient(min);
                    maxq.Color = gradient(max);
                    avgq.World = Matrix.CreateScale(avg * 10, 1, 1) * Matrix.CreateTranslation(height, height, 0);
                    minq.World = Matrix.CreateScale(min * 10, 1, 1) * Matrix.CreateTranslation(height, height, 0);
                    maxq.World = Matrix.CreateScale(max * 10, 1, 1) * Matrix.CreateTranslation(height, height, 0);

                });
        }
Exemple #30
0
 private Quad RecalcOrientation(Quad q)
 {
     Quad t = q;
     t.y *= -1;
     return t;
 }