internal XNATextureCubeImplementation(XFG.GraphicsDevice device, int size, bool genMipMaps, SurfaceFormat format)
            : base(size, format)
        {
            _graphicsDevice = device;

            _textureCube = new XFG.TextureCube(device, size, genMipMaps, XNAHelper.ToXNASurfaceFormat(format));
        }
        public XNATexture2DImplementation(XFG.GraphicsDevice device, int width, int height, bool genMipmaps, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage)
            : base(width, height, format, depthFormat, multiSampleCount, usage)
        {
            _graphicsDevice = device;

            _texture2D = new XFG.RenderTarget2D(device, width, height, genMipmaps, XNAHelper.ToXNASurfaceFormat(format), XNAHelper.ToXNADepthFormat(depthFormat), multiSampleCount, XFG.RenderTargetUsage.PlatformContents);
        }
        internal XNATexture3DImplementation(XFG.GraphicsDevice device, int width, int height, int depth, bool genMipmap, SurfaceFormat format)
            : base(width, height, depth, format)
        {
            _graphicsDevice = device;

            _texture3D = new XFG.Texture3D(device, width, height, depth, genMipmap, XNAHelper.ToXNASurfaceFormat(format));
        }
Exemple #4
0
        /// <summary>
        /// Sets the value of the parameter.
        /// </summary>
        /// <param name="value">Matrix value</param>
        public void SetValue(Matrix value)
        {
            XNA.Matrix m;
            XNAHelper.ConvertMatrix(ref value, out m);

            _param.SetValue(m);
        }
Exemple #5
0
        public XNATexture1DImplementation(XFG.GraphicsDevice device, int width, bool genMipMaps, SurfaceFormat format)
            : base(width, format)
        {
            _graphicsDevice = device;

            _texture2D = new XFG.Texture2D(device, width, 1, genMipMaps, XNAHelper.ToXNASurfaceFormat(format));
        }
        internal XNATextureCubeImplementation(XFG.GraphicsDevice device, int size, bool genMipMaps, SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount, RenderTargetUsage usage)
            : base(size, format, depthFormat, multiSampleCount, usage)
        {
            _graphicsDevice = device;

            _textureCube = new XFG.RenderTargetCube(device, size, genMipMaps, XNAHelper.ToXNASurfaceFormat(format), XNAHelper.ToXNADepthFormat(depthFormat), multiSampleCount, (XFG.RenderTargetUsage)usage);
        }
Exemple #7
0
        /// <summary>
        /// Gets the value of the annotation as a matrix.
        /// </summary>
        /// <returns>
        /// The matrix value
        /// </returns>
        public Matrix GetValueMatrix()
        {
            XNA.Matrix xm = _annotation.GetValueMatrix();
            Matrix     m;

            XNAHelper.ConvertMatrix(ref xm, out m);
            return(m);
        }
Exemple #8
0
        /// <summary>
        /// Gets the value of the parameter as a matrix transpose.
        /// </summary>
        /// <returns>
        /// The matrix transpose value
        /// </returns>
        public Matrix GetValueMatrixTranspose()
        {
            XNA.Matrix xm = _param.GetValueMatrixTranspose();
            Matrix     m;

            XNAHelper.ConvertMatrix(ref xm, out m);
            return(m);
        }
Exemple #9
0
        /// <summary>
        /// Gets the value of the parameter as a quaternion.
        /// </summary>
        /// <returns>
        /// The quaternion value
        /// </returns>
        public Quaternion GetValueQuaternion()
        {
            XNA.Quaternion xq = _param.GetValueQuaternion();
            Quaternion     q;

            XNAHelper.ConvertQuaternion(ref xq, out q);
            return(q);
        }
Exemple #10
0
        /// <summary>
        /// Gets the value of the parameter as a vector2.
        /// </summary>
        /// <returns>
        /// The vector2 value
        /// </returns>
        public Vector2 GetValueVector2()
        {
            XNA.Vector2 xv = _param.GetValueVector2();
            Vector2     v;

            XNAHelper.ConvertVector2(ref xv, out v);
            return(v);
        }
Exemple #11
0
        /// <summary>
        /// Gets the value of the parameter as a vector3.
        /// </summary>
        /// <returns>
        /// The vector3 value
        /// </returns>
        public Vector3 GetValueVector3()
        {
            XNA.Vector3 xv = _param.GetValueVector3();
            Vector3     v;

            XNAHelper.ConvertVector3(ref xv, out v);
            return(v);
        }
Exemple #12
0
        /// <summary>
        /// Gets the value of the parameter as a vector4.
        /// </summary>
        /// <returns>
        /// The vector4 value
        /// </returns>
        public Vector4 GetValueVector4()
        {
            XNA.Vector4 xv = _param.GetValueVector4();
            Vector4     v;

            XNAHelper.ConvertVector4(ref xv, out v);
            return(v);
        }
 private void SetXNAPresentationParameters(PresentationParameters presentParams)
 {
     _pp.BackBufferFormat     = XNAHelper.ToXNASurfaceFormat(presentParams.BackBufferFormat);
     _pp.BackBufferHeight     = presentParams.BackBufferHeight;
     _pp.BackBufferWidth      = presentParams.BackBufferWidth;
     _pp.DepthStencilFormat   = XNAHelper.ToXNADepthFormat(presentParams.DepthStencilFormat);
     _pp.RenderTargetUsage    = XNAHelper.ToXNARenderTargetUsage(presentParams.RenderTargetUsage);
     _pp.PresentationInterval = XNAHelper.ToXNAPresentInterval(presentParams.PresentInterval);
 }
Exemple #14
0
        /// <summary>
        /// Queries if the specified format and sample counts are valid for a render target.
        /// </summary>
        /// <param name="format">Surface format</param>
        /// <param name="depthFormat">Depth format</param>
        /// <param name="multiSampleCount">Sample count</param>
        /// <returns>
        /// True if a valid combination
        /// </returns>
        public bool QueryRenderTargetFormat(SurfaceFormat format, DepthFormat depthFormat, int multiSampleCount)
        {
            XFG.SurfaceFormat xfgFormat;
            XFG.DepthFormat   xfgDepthFormat;
            int xfgMulti;

            return(_adapter.QueryRenderTargetFormat(_graphicsDevice.GraphicsProfile, XNAHelper.ToXNASurfaceFormat(format),
                                                    XNAHelper.ToXNADepthFormat(depthFormat), multiSampleCount, out xfgFormat, out xfgDepthFormat, out xfgMulti));
        }
Exemple #15
0
 /// <summary>
 /// Queries if the specified surface format is valid for vertex texture resources.
 /// </summary>
 /// <param name="surfaceFormat">Surface format</param>
 /// <param name="surfaceFormat">Surface format</param>
 /// <returns>True if valid, false otherwise</returns>
 public bool QueryVertexTextureFormat(SurfaceFormat surfaceFormat, TextureDimensions texType)
 {
     if (_graphicsDevice.GraphicsProfile == XFG.GraphicsProfile.HiDef)
     {
         return(_supportedVertexTextureFormats.Contains(XNAHelper.ToXNASurfaceFormat(surfaceFormat)));
     }
     else
     {
         return(false); //Vertex textures not supported
     }
 }
 public override void SetData <T>(CubeMapFace face, T[] data, int mipLevel, Rectangle?subimage, int startIndex, int elementCount)
 {
     if (subimage.HasValue)
     {
         XNA.Rectangle rect;
         Rectangle     v = subimage.Value;
         XNAHelper.ConvertRectangle(ref v, out rect);                _textureCube.SetData <T>(XNAHelper.ToXNACubeMapFace(face), mipLevel, rect, data, startIndex, elementCount);
     }
     else
     {
         _textureCube.SetData <T>(XNAHelper.ToXNACubeMapFace(face), mipLevel, null, data, startIndex, elementCount);
     }
 }
 /// <summary>
 /// Binds the implementation. This is called the first time an unbound state is set to the device or manually by the user in order to
 /// create the underlying state ahead of time (best practice). Once called the state properties are read-only.
 /// </summary>
 public override void BindSamplerState()
 {
     if (!base.IsBound)
     {
         _samplerState                         = new XFG.SamplerState();
         _samplerState.AddressU                = XNAHelper.ToXNATextureAddressMode(base.AddressU);
         _samplerState.AddressV                = XNAHelper.ToXNATextureAddressMode(base.AddressV);
         _samplerState.AddressW                = XNAHelper.ToXNATextureAddressMode(base.AddressW);
         _samplerState.Filter                  = XNAHelper.ToXNATextureFilter(base.Filter);
         _samplerState.MaxAnisotropy           = base.MaxAnisotropy;
         _samplerState.MipMapLevelOfDetailBias = base.MipMapLevelOfDetailBias;
         base.IsBound = true;
     }
 }
Exemple #18
0
 /// <summary>
 /// Binds the implementation. This is called the first time an unbound state is set to the device or manually by the user in order to
 /// create the underlying state ahead of time (best practice). Once called the state properties are read-only.
 /// </summary>
 public override void BindRasterizerState()
 {
     if (!base.IsBound)
     {
         _rasterizerState                      = new XFG.RasterizerState();
         _rasterizerState.CullMode             = XNAHelper.ToXNACullMode(base.Cull, base.VertexWinding);
         _rasterizerState.DepthBias            = base.DepthBias;
         _rasterizerState.FillMode             = XNAHelper.ToXNAFillMode(base.Fill);
         _rasterizerState.MultiSampleAntiAlias = base.EnableMultiSampleAntiAlias;
         _rasterizerState.ScissorTestEnable    = base.EnableScissorTest;
         _rasterizerState.SlopeScaleDepthBias  = base.SlopeScaledDepthBias;
         base.IsBound = true;
     }
 }
 public override void GetBackBufferData <T>(Rectangle?rect, T[] data, int startIndex, int elementCount)
 {
     if (rect.HasValue)
     {
         XNA.Rectangle r;
         Rectangle     temp = rect.Value;
         XNAHelper.ConvertRectangle(ref temp, out r);
         _graphicsDevice.GetBackBufferData <T>(r, data, startIndex, elementCount);
     }
     else
     {
         _graphicsDevice.GetBackBufferData <T>(null, data, startIndex, elementCount);
     }
 }
 public override void GetData <T>(T[] data, int mipLevel, Rectangle?subimage, int startIndex, int elementCount)
 {
     if (subimage.HasValue)
     {
         XNA.Rectangle rect;
         Rectangle     v = subimage.Value;
         XNAHelper.ConvertRectangle(ref v, out rect);
         _texture2D.GetData <T>(mipLevel, rect, data, startIndex, elementCount);
     }
     else
     {
         _texture2D.GetData <T>(mipLevel, null, data, startIndex, elementCount);
     }
 }
 public override void Clear(ClearOptions options, Color color, float depth, int stencil)
 {
     XNA.Color c;
     XNAHelper.ConvertColor(ref color, out c);
     XFG.ClearOptions xfgClear = XFG.ClearOptions.Target;
     if ((options & ClearOptions.Depth) == ClearOptions.Depth)
     {
         xfgClear |= XFG.ClearOptions.DepthBuffer;
     }
     if ((options & ClearOptions.Stencil) == ClearOptions.Stencil)
     {
         xfgClear |= XFG.ClearOptions.Stencil;
     }
     _graphicsDevice.Clear(xfgClear, c, depth, stencil);
 }
        /// <summary>
        /// Binds the implementation. This is called the first time an unbound state is set to the device or manually by the user in order to
        /// create the underlying state ahead of time (best practice). Once called the state properties are read-only.
        /// </summary>
        public override void BindBlendState()
        {
            if (!base.IsBound)
            {
                //If blending is enabled, create it
                if (this.GetBlendEnable(0))
                {
                    _blendState = new XFG.BlendState();
                    //Set alpha properties
                    _blendState.AlphaBlendFunction    = XNAHelper.ToXNABlendFunction(base.AlphaBlendFunction);
                    _blendState.AlphaSourceBlend      = XNAHelper.ToXNABlend(base.AlphaSourceBlend);
                    _blendState.AlphaDestinationBlend = XNAHelper.ToXNABlend(base.AlphaDestinationBlend);

                    //Set color properties
                    _blendState.ColorBlendFunction    = XNAHelper.ToXNABlendFunction(base.ColorBlendFunction);
                    _blendState.ColorSourceBlend      = XNAHelper.ToXNABlend(base.ColorSourceBlend);
                    _blendState.ColorDestinationBlend = XNAHelper.ToXNABlend(base.ColorDestinationBlend);

                    //Set blend factor
                    XNA.Color c;
                    Color     bf = base.BlendFactor;
                    XNAHelper.ConvertColor(ref bf, out c);
                    _blendState.BlendFactor = c;

                    //Set multisample bitmask
                    _blendState.MultiSampleMask = base.MultiSampleMask;

                    //Set color write bitmasks
                    _blendState.ColorWriteChannels  = (XFG.ColorWriteChannels) this.GetWriteChannels(0);
                    _blendState.ColorWriteChannels1 = (XFG.ColorWriteChannels) this.GetWriteChannels(1);
                    _blendState.ColorWriteChannels2 = (XFG.ColorWriteChannels) this.GetWriteChannels(2);
                    _blendState.ColorWriteChannels3 = (XFG.ColorWriteChannels) this.GetWriteChannels(3);
                }
                else
                {
                    //Otherwise if it is -not- enabled, just re-use the opaque state - guaranteed to never change
                    _blendState = XFG.BlendState.Opaque;
                }
                base.IsBound = true;
            }
        }
        /// <summary>
        /// Creates a new instance of <see cref="XNAVertexBufferImplementation"/>.
        /// </summary>
        /// <param name="renderer">The XNA renderer.</param>
        /// <param name="decl">The vertex declaration.</param>
        /// <param name="vertexCount">The vertex count.</param>
        /// <param name="usage">The resource usage.</param>
        /// <exception cref="Tesla.Core.TeslaException">Thrown if there was an error creating the XNA buffer</exception>
        internal XNAVertexBufferImplementation(XNARenderer renderer, VertexDeclaration decl, int vertexCount, ResourceUsage usage)
            : base(decl, vertexCount, usage)
        {
            _renderer       = renderer;
            _graphicsDevice = renderer.GraphicsDevice;

            try {
                XFG.VertexDeclaration xnaDecl = XNAHelper.ToXNAVertexDeclaration(decl);
                if (usage == ResourceUsage.Static)
                {
                    _vertexBuffer = new XFG.VertexBuffer(_graphicsDevice, xnaDecl, vertexCount, XFG.BufferUsage.None);
                }
                else
                {
                    _vertexBuffer = new XFG.DynamicVertexBuffer(_graphicsDevice, xnaDecl, vertexCount, XFG.BufferUsage.None);
                }
            } catch (Exception e) {
                Dispose();
                throw new TeslaException("Error creating XNA buffer: \n" + e.Message, e);
            }
        }
Exemple #24
0
        /// <summary>
        /// Initializes a new instance of the <see cref="XNAGraphicsAdapter"/> class.
        /// </summary>
        /// <param name="graphicsDevice">The graphics device.</param>
        /// <param name="adapter">The adapter.</param>
        /// <param name="adapterIndex">Index of the adapter.</param>
        internal XNAGraphicsAdapter(XFG.GraphicsDevice graphicsDevice, XFG.GraphicsAdapter adapter, int adapterIndex)
        {
            _graphicsDevice = graphicsDevice;
            _adapter        = adapter;
            _adapterIndex   = adapterIndex;

            List <DisplayMode> list = new List <DisplayMode>();

            foreach (XFG.DisplayMode mode in adapter.SupportedDisplayModes)
            {
                DisplayMode display = new DisplayMode(mode.Width, mode.Height, XNAHelper.FromXNASurfaceFormat(mode.Format));
                if (list.Contains(display))
                {
                    list.Add(display);
                }
            }
            _displayModes = new DisplayModeCollection(list);

            _supportedTextureFormats = new List <XFG.SurfaceFormat>(new XFG.SurfaceFormat[] {
                XFG.SurfaceFormat.Color, XFG.SurfaceFormat.Bgr565, XFG.SurfaceFormat.Bgra5551,
                XFG.SurfaceFormat.Bgra4444, XFG.SurfaceFormat.NormalizedByte2, XFG.SurfaceFormat.NormalizedByte4,
                XFG.SurfaceFormat.Dxt1, XFG.SurfaceFormat.Dxt3, XFG.SurfaceFormat.Dxt5
            });

            if (graphicsDevice.GraphicsProfile == XFG.GraphicsProfile.HiDef)
            {
                _supportedVertexTextureFormats = new List <XFG.SurfaceFormat>(new XFG.SurfaceFormat[] {
                    XFG.SurfaceFormat.Single, XFG.SurfaceFormat.Vector4, XFG.SurfaceFormat.Vector2,
                    XFG.SurfaceFormat.HalfVector2, XFG.SurfaceFormat.HalfVector4, XFG.SurfaceFormat.HalfSingle
                });

                _supportedTextureFormats.AddRange(new XFG.SurfaceFormat[] {
                    XFG.SurfaceFormat.Alpha8, XFG.SurfaceFormat.Rg32, XFG.SurfaceFormat.Rgba64,
                    XFG.SurfaceFormat.Rgba1010102, XFG.SurfaceFormat.Single, XFG.SurfaceFormat.Vector2,
                    XFG.SurfaceFormat.Vector4, XFG.SurfaceFormat.HalfSingle, XFG.SurfaceFormat.HalfVector2,
                    XFG.SurfaceFormat.HalfVector4
                });
            }
        }
Exemple #25
0
 /// <summary>
 /// Binds the implementation. This is called the first time an unbound state is set to the device or manually by the user in order to
 /// create the underlying state ahead of time (best practice). Once called the state properties are read-only.
 /// </summary>
 public override void BindDepthStencilState()
 {
     if (!base.IsBound)
     {
         _depthStencilState = new XFG.DepthStencilState();
         _depthStencilState.DepthBufferEnable                      = base.DepthEnable;
         _depthStencilState.DepthBufferWriteEnable                 = base.DepthWriteEnable;
         _depthStencilState.StencilEnable                          = base.StencilEnable;
         _depthStencilState.TwoSidedStencilMode                    = base.TwoSidedStencilEnable;
         _depthStencilState.StencilMask                            = base.StencilReadMask;
         _depthStencilState.StencilWriteMask                       = base.StencilWriteMask;
         _depthStencilState.ReferenceStencil                       = base.ReferenceStencil;
         _depthStencilState.CounterClockwiseStencilPass            = XNAHelper.ToXNAStencilOperation(base.CounterClockwiseStencilPass);
         _depthStencilState.CounterClockwiseStencilDepthBufferFail = XNAHelper.ToXNAStencilOperation(base.CounterClockwiseStencilDepthFail);
         _depthStencilState.CounterClockwiseStencilFail            = XNAHelper.ToXNAStencilOperation(base.CounterClockwiseStencilFail);
         _depthStencilState.CounterClockwiseStencilFunction        = XNAHelper.ToXNACompareFunction(base.CounterClockwiseStencilFunction);
         _depthStencilState.DepthBufferFunction                    = XNAHelper.ToXNACompareFunction(base.DepthFunction);
         _depthStencilState.StencilFunction                        = XNAHelper.ToXNACompareFunction(base.StencilFunction);
         _depthStencilState.StencilDepthBufferFail                 = XNAHelper.ToXNAStencilOperation(base.StencilDepthFail);
         _depthStencilState.StencilFail                            = XNAHelper.ToXNAStencilOperation(base.StencilFail);
         _depthStencilState.StencilPass                            = XNAHelper.ToXNAStencilOperation(base.StencilPass);
         base.IsBound = true;
     }
 }
Exemple #26
0
 /// <summary>
 /// Queries if the specified surface format is valid for texture resources.
 /// </summary>
 /// <param name="surfaceFormat">Surface format</param>
 /// <param name="surfaceFormat">Surface format</param>
 /// <returns>True if valid, false otherwise</returns>
 public bool QueryTextureFormat(SurfaceFormat surfaceFormat, TextureDimensions texType)
 {
     return(_supportedTextureFormats.Contains(XNAHelper.ToXNASurfaceFormat(surfaceFormat)));
 }
Exemple #27
0
        /// <summary>
        /// The update checks for successful ghost selection against the selection render. Successful ones are hidden, and a new one is displayed.
        /// New renders are made each time a new ghost appears on the screen.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        public override void Update(GameTime gameTime)
        {
            MouseState ms = Mouse.GetState();

            if (selectableList[0].selected && (Gesture == ManipMode.GRAB || Gesture == ManipMode.SELECTGRAB))
            {
                Ray ray = XNAHelper.CalculateCursorRay(CursorPos, camera.GetProjectionMatrix(), camera.GetViewMatrix(), game.GraphicsDevice);
                selectableList[0].position   = Vector3.Lerp(selectableList[0].position, ray.Position + (ray.Direction * ratio), (float)gameTime.ElapsedGameTime.TotalSeconds * 8);
                selectableList[0].position.Y = MathHelper.Clamp(selectableList[0].position.Y, ymin, ymax);
                selectableList[0].position.Z = MathHelper.Clamp(selectableList[0].position.Z, zmin, zmax);
                selectableList[0].position.X = xFixed;
            }

            if ((Gesture == ManipMode.SELECT || Gesture == ManipMode.SELECTGRAB) && LastGesture == ManipMode.NONE)
            {
                Rectangle source              = new Rectangle((int)(CursorPos.X - Game1.cursorArea / 2), (int)(CursorPos.Y - Game1.cursorArea / 2), (int)Game1.cursorArea, (int)Game1.cursorArea);
                Color[]   retrieved           = new Color[(int)(Game1.cursorArea * Game1.cursorArea)];
                bool      selectionSuccessful = false;

                try {
                    flatRender.GetData <Color>(0, source, retrieved, 0, (int)(Game1.cursorArea * Game1.cursorArea));
                    //We increment by 2 as an optimization measure, as those values are going to be pretty consistent.
                    for (int i = 0; i < retrieved.Length; i += 2)
                    {
                        if (retrieved[i] == this.selectionColor)
                        {
                            selectableList[0].selected = true;
                            selectionSuccessful        = true;
                            Ray ray = XNAHelper.CalculateCursorRay(new Vector2(ms.X, ms.Y), camera.GetProjectionMatrix(), camera.GetViewMatrix(), game.GraphicsDevice);
                            ratio = Vector3.Distance(ray.Position, selectableList[0].position)
                                    / Vector3.Distance(ray.Position, ray.Position + new Vector3(ray.Direction.X, 0, 0));
                            ((GEntity)selectableList[0]).waiting = true;
                        }
                    }
                    if (selectionSuccessful)
                    {
                        DataLogger.Environment = LoggingEnvironment.YESSELECT;
                    }
                    else
                    {
                        DataLogger.Environment = LoggingEnvironment.NOSELECT;
                    }
                } catch (ArgumentException) {
                    Console.Error.WriteLine("Mouse Click outside Bounds!");
                }
            }

            if (Gesture == ManipMode.NONE && LastGesture != ManipMode.NONE)
            {
                if (((Cage)draggableList[0]).Contains(selectableList[0].position))
                {
                    selectableList[0].selected = false;
                    sceneryList.Insert(0, selectableList[0]);
                    selectableList.RemoveAt(0);
                    ((Firefly)sceneryList[0]).standardColor = Color.Yellow;
                    ((Firefly)sceneryList[0]).RemoveGlow();
                    DataLogger.Environment = LoggingEnvironment.YESDROP;
                    if (selectableList.Count == 0)
                    {
                        complete = true;
                    }
                    else
                    {
                        ((Firefly)selectableList[0]).standardColor = Color.Orange;
                    }
                }
                else
                {
                    DataLogger.Environment = LoggingEnvironment.NODROP;
                }
                renderRequested = true;
            }

            base.Update(gameTime);
        }
Exemple #28
0
 public override void Draw(PrimitiveType primType, int vertexCount, int startVertex)
 {
     _device.DrawPrimitives(XNAHelper.ToXNAPrimitiveType(primType), startVertex, XNAHelper.GetPrimitiveCount(primType, vertexCount, false, 0));
 }
Exemple #29
0
        /// <summary>
        /// The update checks for successful ghost selection against the selection render. Successful ones are hidden, and a new one is displayed.
        /// New renders are made each time a new ghost appears on the screen.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        public override void Update(GameTime gameTime)
        {
            if (trialState == TrialState.PRE)
            {
                if (Keyboard.GetState().IsKeyDown(Keys.Enter))
                {
                    Game1.wandCursor.DisplayingWithoutGesture = false;
                    trialState      = TrialState.INT;
                    renderRequested = true;

                    selectableList.Clear();
                    Key key = new Key(game, new Vector3(leftp - 5, 25, 65), camera);
                    key.scale         = 2f;
                    key.xrotation     = -MathHelper.PiOver2;
                    key.selectedColor = Color.Yellow;
                    selectableList.Add(key);
                    ((GEntity)draggableList[0]).standardColor = Color.Red;
                }
                return;
            }

            MouseState ms = Mouse.GetState();

            if ((Gesture == ManipMode.SELECT || Gesture == ManipMode.SELECTGRAB) && LastGesture == ManipMode.NONE)
            {
                Rectangle source    = new Rectangle((int)(CursorPos.X - Game1.cursorArea / 2), (int)(CursorPos.Y - Game1.cursorArea / 2), (int)Game1.cursorArea, (int)Game1.cursorArea);
                Color[]   retrieved = new Color[(int)(Game1.cursorArea * Game1.cursorArea)];

                try
                {
                    flatRender.GetData <Color>(0, source, retrieved, 0, (int)(Game1.cursorArea * Game1.cursorArea));
                    bool selectSuccessful = false;
                    //We increment by 2 as an optimization measure, as those values are going to be pretty consistent.
                    for (int i = 0; i < retrieved.Length; i += 2)
                    {
                        if (retrieved[i] == this.selectionColor)
                        {
                            selectableList[0].selected = true;
                            Ray ray = XNAHelper.CalculateCursorRay(CursorPos, camera.GetProjectionMatrix(), camera.GetViewMatrix(), game.GraphicsDevice);
                            ratio = Vector3.Distance(ray.Position, selectableList[0].position)
                                    / Vector3.Distance(ray.Position, ray.Position + new Vector3(0, 0, ray.Direction.Z));
                            //((GEntity)selectableList[0]).invisibleNextRender = true;
                            renderRequested  = true;
                            selectSuccessful = true;
                            ((GEntity)selectableList[0]).waiting = true;
                        }
                    }
                    if (selectSuccessful)
                    {
                        DataLogger.Environment = LoggingEnvironment.YESSELECT;
                    }
                    else
                    {
                        DataLogger.Environment = LoggingEnvironment.NOSELECT;
                    }
                } catch (ArgumentException) {
                    Console.Error.WriteLine("Mouse Click outside Bounds!");
                }
            }

            if ((Gesture == ManipMode.GRAB || Gesture == ManipMode.SELECTGRAB) && selectableList[0].selected)
            {
                Ray   ray    = XNAHelper.CalculateCursorRay(CursorPos, camera.GetProjectionMatrix(), camera.GetViewMatrix(), game.GraphicsDevice);
                float zFixed = selectableList[0].position.Z;
                selectableList[0].position   = Vector3.Lerp(selectableList[0].position, ray.Position + (ray.Direction * ratio), (float)gameTime.ElapsedGameTime.TotalSeconds * 8);
                selectableList[0].position.Y = MathHelper.Clamp(selectableList[0].position.Y, 23, 80);
                selectableList[0].position.Z = zFixed;

                Ray camRay = new Ray(camera.Position, Vector3.Normalize(draggableList[0].position - camera.Position));

                if (((Key)selectableList[0]).Intersects(camRay))
                {
                    selectableList[0].selected  = false;
                    selectableList[0].position  = new Vector3(selectableList[0].position.X < midp ? Game1.random.Next(rightp, midp - 1) : Game1.random.Next(midp + 1, leftp), 25, 65);
                    selectableList[0].yrotation = 0;
                    ((GEntity)draggableList[0]).standardColor = null;
                    Entity e = draggableList[1];
                    draggableList.RemoveAt(1);
                    draggableList.Insert(0, e);
                    ((GEntity)draggableList[0]).standardColor = Color.Red;
                    DataLogger.Environment = LoggingEnvironment.YESDRAG;

                    keysLeft--;
                    if (keysLeft == 0)
                    {
                        complete = true;
                    }
                }
            }

            if (Gesture == ManipMode.NONE && (LastGesture == ManipMode.GRAB || LastGesture == ManipMode.SELECTGRAB))
            {
                renderRequested = true;
                if (selectableList[0].selected)
                {
                    DataLogger.Environment = LoggingEnvironment.NODROP;
                }
            }

            base.Update(gameTime);
        }
Exemple #30
0
        /// <summary>
        /// The update checks for successful ghost selection against the selection render. Successful ones are hidden, and a new one is displayed.
        /// New renders are made each time a new ghost appears on the screen.
        /// </summary>
        /// <param name="gameTime">The game time</param>
        public override void Update(GameTime gameTime)
        {
            MouseState ms = Mouse.GetState();

            if (selectableList[0].selected)
            {
                Ray ray = XNAHelper.CalculateCursorRay(new Vector2(ms.X, ms.Y), camera.GetProjectionMatrix(), camera.GetViewMatrix(), game.GraphicsDevice);
                selectableList[0].position   = Vector3.Lerp(selectableList[0].position, ray.Position + (ray.Direction * ratio), (float)gameTime.ElapsedGameTime.TotalSeconds * 8);
                selectableList[0].position.Y = MathHelper.Clamp(selectableList[0].position.Y, 220, 280);
                selectableList[0].position.X = MathHelper.Clamp(selectableList[0].position.X, 330, 370);
                selectableList[0].position.Z = 310;

                Ray camRay = new Ray(camera.Position, Vector3.Normalize(draggableList[0].position - camera.Position));

                /*
                 * if ((selectableList[0]).Intersects(camRay))
                 * {
                 *  selectableList[0].selected = false;
                 *  selectableList[0].position = new Vector3(selectableList[0].position.X < midp ? Game1.random.Next(rightp, midp - 1) : Game1.random.Next(midp + 1, leftp), 25, 65);
                 *  selectableList[0].yrotation = 0;
                 *  ((GEntityaggableList[0]).standardColor = null;
                 *  Entity e = draggableList[1];
                 *  draggableList.RemoveAt(1);
                 *  draggableList.Insert(0, e);
                 *  ((GEntity)draggableList[0]).standardColor = Color.Red;
                 * }*/
            }

            if (ms.LeftButton == ButtonState.Pressed && lms.LeftButton == ButtonState.Released)
            {
                Rectangle source    = new Rectangle(Mouse.GetState().X, Mouse.GetState().Y, 1, 1);
                Color[]   retrieved = new Color[1];
                try
                {
                    flatRender.GetData <Color>(0, source, retrieved, 0, 1);
                    Console.Out.WriteLine(retrieved[0].R + "," + retrieved[0].G + "," + retrieved[0].B);
                    if (retrieved[0] == this.selectionColor)
                    {
                        selectableList[0].selected = true;
                        Ray ray = XNAHelper.CalculateCursorRay(new Vector2(ms.X, ms.Y), camera.GetProjectionMatrix(), camera.GetViewMatrix(), game.GraphicsDevice);
                        ratio = Vector3.Distance(ray.Position, selectableList[0].position)
                                / Vector3.Distance(ray.Position, ray.Position + new Vector3(0, 0, ray.Direction.Z));
                        //((GEntity)selectableList[0]).invisibleNextRender = true;
                        renderRequested = true;
                        ((GEntity)selectableList[0]).waiting = true;
                    }
                }
                catch (ArgumentException)
                {
                    Console.Error.WriteLine("Mouse Click outside Bounds!");
                }
            }
            else if (ms.LeftButton == ButtonState.Released && lms.LeftButton == ButtonState.Pressed)
            {
                selectableList[0].selected = false;
                renderRequested            = true;
            }

            lms = ms;
            base.Update(gameTime);
        }