private void CreateDevice(IntPtr windowHandle, int width, int height)
        {
            try
            {
                parameters = new PresentationParameters();

                parameters.BackBufferWidth = Math.Max(width, 1);
                parameters.BackBufferHeight = Math.Max(height, 1);
                parameters.BackBufferFormat = SurfaceFormat.Color;
                parameters.DepthStencilFormat = DepthFormat.Depth24;
                parameters.DeviceWindowHandle = windowHandle;
                parameters.PresentationInterval = PresentInterval.Immediate;
                parameters.IsFullScreen = false;

                graphicsDevice = new GraphicsDevice(
                    GraphicsAdapter.DefaultAdapter,
                    GraphicsProfile.Reach,
                    parameters);

                if (DeviceCreated != null)
                    DeviceCreated(this, EventArgs.Empty);

            }
            catch (Exception ex)
            {
                throw new ApplicationException("Failed to initialize GraphicsDeviceService. See inner exception for details.", ex);
            }
        }
        /// <summary>
        /// InitializePlot the multicopter entity simulation environment
        /// </summary>
        /// <param name="device">A reference to the graphics device</param>
        /// <param name="physicsEngine">A reference to the created instance of the physics engine</param>
        public override void Initialize(xnagrfx.GraphicsDevice device, PhysicsEngine physicsEngine)
        {
            try
            {
                InitError = string.Empty;

                // Build the model
                ProgrammaticallyBuildModel(device, physicsEngine);

                // Reset values, position, rotation of the multicopter entity
                Reset();

                // Insert propellers dynamically based on multicopter type
                InsertPropellers(device, physicsEngine);

                base.Initialize(device, physicsEngine);
            }

            catch (Exception ex)
            {
                // In case of exception delete physics entity and manage the errors
                if (PhysicsEntity != null)
                {
                    PhysicsEngine.DeleteEntity(PhysicsEntity);
                }

                HasBeenInitialized = false;
                InitError          = ex.ToString();
            }
        }
        public XNATexture2DImplementation(XFG.GraphicsDevice device, int width, int height, bool genMipMaps, SurfaceFormat format)
            : base(width, height, format)
        {
            _graphicsDevice = device;

            _texture2D = new XFG.Texture2D(device, width, height, genMipMaps, XNAHelper.ToXNASurfaceFormat(format));
        }
Ejemplo n.º 4
0
        public override void Draw(Microsoft.Xna.Framework.Graphics.GraphicsDevice device)
        {
            if (Mesh == null)
            {
                return;
            }

            var effect = new BasicEffect(device, null);

            effect.World      = World;
            effect.View       = View;
            effect.Projection = Projection;
            effect.Begin();
            if (Texture != null)
            {
                effect.TextureEnabled = true;
                effect.Texture        = Texture;
            }

            foreach (var pass in effect.CurrentTechnique.Passes)
            {
                pass.Begin();
                Mesh.Draw(device);
                pass.End();
            }
            effect.End();
        }
 public static Texture2D ResourceToTexture2D(string resource, GraphicsDevice gd)
 {
     using (Stream stream = Assembly.GetCallingAssembly().GetManifestResourceStream(resource))
     {
         return Texture2D.FromStream(gd, stream);
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// Constructor is private, because this is a singleton class:
        /// client controls should use the public AddRef method instead.
        /// </summary>
        GraphicsDeviceService(IntPtr windowHandle, int width, int height)
        {
            parameters = new PresentationParameters();

            // Basic settings.
            parameters.BackBufferWidth = Math.Max(width, 1);
            parameters.BackBufferHeight = Math.Max(height, 1);
            parameters.BackBufferFormat = SurfaceFormat.Color;
            parameters.DepthStencilFormat = DepthFormat.Depth24;
            parameters.DeviceWindowHandle = windowHandle;
            parameters.PresentationInterval = PresentInterval.Immediate;
            parameters.IsFullScreen = false;

            // High-quality settings.
            parameters.MultiSampleCount = 4;

            // Try for high-quality graphics, otherwise drop down to basic settings.
            try
            {
                graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter,
                                                    GraphicsProfile.HiDef,
                                                    parameters);
            }
            catch
            {
                parameters.MultiSampleCount = 0;
                graphicsDevice = new GraphicsDevice(GraphicsAdapter.DefaultAdapter,
                                                       GraphicsProfile.Reach,
                                                       parameters);
            }

        }
Ejemplo n.º 7
0
 public void Draw(Microsoft.Xna.Framework.Graphics.GraphicsDevice device)
 {
     foreach (var scene in Scenes)
     {
         scene.Draw(device);
     }
 }
Ejemplo n.º 8
0
 public TextTest(IKernel kernel, GraphicsDevice device, ContentManager content)
     : base("Text Test", kernel)
 {
     _kernel = kernel;
     _device = device;
     _content = content;
 }
Ejemplo n.º 9
0
        protected void LoadContent()
        {
            GrDev        = base.GraphicsDevice;
            spriteBatch  = new SpriteBatch(base.GraphicsDevice);
            spriteBatch1 = new SpriteBatch(base.GraphicsDevice);
            this.camera  = new Camera2D(new Viewport(0, 0, (int)Assets.screenWidth, (int)Assets.screenHeight));
            if (this.acel != null)
            {
                acel.ReportInterval  = acel.MinimumReportInterval;
                acel.ReadingChanged += Aceloro;
            }

            if (this.orientationSensor != null)
            {
                Settings.orientation = this.orientationSensor.GetCurrentOrientation();
                switch (Settings.orientation)
                {
                case SimpleOrientation.NotRotated: Settings.or = 1; break;

                case SimpleOrientation.Faceup: Settings.or = 1; break;

                case SimpleOrientation.Rotated180DegreesCounterclockwise: Settings.or = 2; break;

                case SimpleOrientation.Rotated270DegreesCounterclockwise: Settings.or = 3; break;

                case SimpleOrientation.Rotated90DegreesCounterclockwise: Settings.or = 4; break;
                }
                this.orientationSensor.OrientationChanged += OrientationChange;
            }
        }
Ejemplo n.º 10
0
        public TextureContext(GraphicsDevice graphicsDevice, Stream stream, bool premultiplyAlpha)
        {
            _texture = Texture2D.FromStream(graphicsDevice, stream);

            if (premultiplyAlpha)
                PremultiplyTexture(_texture);
        }
Ejemplo n.º 11
0
 public SpriteTest(IKernel kernel, ContentManager content, GraphicsDevice device)
     : base("Sprite Test", kernel)
 {
     _kernel = kernel;
     _content = content;
     _device = device;
 }
Ejemplo n.º 12
0
 public override void Draw(GraphicsDevice device)
 {
     for (int i = 0; i < m_Elements.Count; i++)
     {
         m_Elements[i].Draw(device);
     }
 }
Ejemplo n.º 13
0
 public Snowplow(GraphicsDevice device, Model model, VFXEffect effect)
     : base(device,model,effect)
 {
     _isDoubleSided["Circle"] = true;
     _isDoubleSided["Circle.004"] = true;
     _isDoubleSided["Circle.003"] = true;
 }
Ejemplo n.º 14
0
 public void DrawBefore2D(GraphicsDevice gd, WorldState state)
 {
     foreach (var avatar in Blueprint.Avatars)
     {
         avatar.Draw(gd, state);
     }
 }
Ejemplo n.º 15
0
        public ModelLoader(ContentManager contentManager, GraphicsDevice graphicsDevice)
        {
            content = contentManager;
            graphics = graphicsDevice;

            modelEffect = contentManager.Load<Effect>("EffectFiles/model");
        }
Ejemplo n.º 16
0
 public ParticlesTest(IKernel kernel, ContentManager content, GraphicsDevice device)
     : base("Particles", kernel)
 {
     _kernel = kernel;
     _content = content;
     _device = device;
 }
Ejemplo n.º 17
0
        internal void SetConstantBuffers(GraphicsDevice device, int shaderProgram)
#endif
        {
            // If there are no constant buffers then skip it.
            if (_valid == 0)
                return;

            var valid = _valid;

            for (var i = 0; i < _buffers.Length; i++)
            {
                var buffer = _buffers[i];
                if (buffer != null)
                {
#if DIRECTX
                    buffer.Apply(device, _stage, i);
#elif OPENGL || PSM
                    buffer.Apply(device, shaderProgram);
#endif
                }

                // Early out if this is the last one.
                valid &= ~(1 << i);
                if (valid == 0)
                    return;
            }
        }
 public ContentManager GetContentManager(GraphicsDevice graphicsDevice)
 {
     return new ContentManager(new XnaServiceProvider(graphicsDevice))
         {
             RootDirectory = "Content"
         };
 }
Ejemplo n.º 19
0
        /// <summary>
        /// Creates a new instance of Content.
        /// </summary>
        /// <param name="basePath">Path to client directory.</param>
        /// <param name="device">A GraphicsDevice instance.</param>
        private Content(string basePath, GraphicsDevice device)
        {
            this.BasePath = basePath;
            this.Device = device;

            Changes = new ChangeManager();

            UIGraphics = new UIGraphicsProvider(this);
            AvatarMeshes = new AvatarMeshProvider(this, Device);
            AvatarBindings = new AvatarBindingProvider(this);
            AvatarTextures = new AvatarTextureProvider(this, Device);
            AvatarSkeletons = new AvatarSkeletonProvider(this);
            AvatarAppearances = new AvatarAppearanceProvider(this);
            AvatarOutfits = new AvatarOutfitProvider(this);
            AvatarAnimations = new AvatarAnimationProvider(this);
            AvatarPurchasables = new AvatarPurchasables(this);
            AvatarHandgroups = new HandgroupProvider(this, Device);
            AvatarCollections = new AvatarCollectionsProvider(this);
            AvatarThumbnails = new AvatarThumbnailProvider(this, Device);

            WorldObjects = new WorldObjectProvider(this);
            WorldFloors = new WorldFloorProvider(this);
            WorldWalls = new WorldWallProvider(this);
            WorldObjectGlobals = new WorldGlobalProvider(this);
            WorldCatalog = new WorldObjectCatalog();

            Audio = new Audio(this);
            GlobalTuning = new Tuning(Path.Combine(basePath, "tuning.dat"));

            Init();
        }
 /// <summary>
 /// Creates a new RenderTargetImageSource.
 /// </summary>
 /// <param name="graphics">The GraphicsDevice to use.</param>
 /// <param name="width">The width of the image source.</param>
 /// <param name="height">The height of the image source.</param>
 public RenderTargetImageSource(GraphicsDevice graphics, int width, int height)
 {
     // create the render target and buffer to hold the data
     renderTarget = new RenderTarget2D(graphics, width, height, false, SurfaceFormat.Color, DepthFormat.Depth24Stencil8);
     buffer = new byte[width * height * 4];
     writeableBitmap = new WriteableBitmap(width, height, 96, 96, PixelFormats.Bgra32, null);
 }
Ejemplo n.º 21
0
        internal void ClearTargets(GraphicsDevice device, RenderTargetBinding[] targets)
        {
            // NOTE: We make the assumption here that the caller has
            // locked the d3dContext for us to use.
            var pixelShaderStage = device._d3dContext.PixelShader;

            // We assume 4 targets to avoid a loop within a loop below.
            var target0 = targets[0].RenderTarget;
            var target1 = targets[1].RenderTarget;
            var target2 = targets[2].RenderTarget;
            var target3 = targets[3].RenderTarget;

            // Make one pass across all the texture slots.
            for (var i = 0; i < _textures.Length; i++)
            {
                if (_textures[i] != target0 &&
                    _textures[i] != target1 &&
                    _textures[i] != target2 &&
                    _textures[i] != target3)
                    continue;

                // Immediately clear the texture from the device.
                _dirty &= ~(1 << i);
                _textures[i] = null;
                pixelShaderStage.SetShaderResource(i, null);
            }
        }
Ejemplo n.º 22
0
 internal Effect(GraphicsDevice device)
 {
     graphicsDevice = device;
     Parameters = new EffectParameterCollection();
     Techniques = new EffectTechniqueCollection();
     CurrentTechnique = new EffectTechnique(this);
 }
        Texture2D Circle(GraphicsDevice graphics, int radius)
        {
            int aDiameter = radius * 2;
            Vector2 aCenter = new Vector2(radius, radius);

            Texture2D aCircle = new Texture2D(graphics, aDiameter, aDiameter, false, SurfaceFormat.Color);
            Color[] aColors = new Color[aDiameter * aDiameter];

            for (int i = 0; i < aColors.Length; i++)
            {
                int x = (i + 1) % aDiameter;
                int y = (i + 1) / aDiameter;

                Vector2 aDistance = new Vector2(Math.Abs(aCenter.X - x), Math.Abs(aCenter.Y - y));


                if (Math.Sqrt((aDistance.X * aDistance.X) + (aDistance.Y * aDistance.Y)) > radius)
                {
                    aColors[i] = Color.Transparent;
                }
                else
                {
                    aColors[i] = Color.White;
                }
            }

            aCircle.SetData<Color>(aColors);

            return aCircle;
        }
Ejemplo n.º 24
0
        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);
        }
Ejemplo n.º 25
0
		public XnaTextureManager( XFG.GraphicsDevice device )
            : base()
		{
			this._device = device;

			Is32Bit = true;
		}
Ejemplo n.º 26
0
 public Renderer(GraphicsDevice device, RenderState renderState)
 {
     RenderState  = renderState;
     Device = device;
     _effect = new BasicEffect(Device);
     _bufferedInstructions = new List<IEnumerable<RenderInstruction>>();
 }
        internal void PlatformSetSamplers(GraphicsDevice device)
        {
            for (var i = 0; i < _actualSamplers.Length; i++)
            {
                var sampler = _actualSamplers[i];
                var texture = device.Textures[i];

                if (sampler != null && texture != null && sampler != texture.glLastSamplerState)
                {
                    // TODO: Avoid doing this redundantly (see TextureCollection.SetTextures())
                    // However, I suspect that rendering from the same texture with different sampling modes
                    // is a relatively rare occurrence...
                    GL.ActiveTexture(TextureUnit.Texture0 + i);
                    GraphicsExtensions.CheckGLError();

                    // NOTE: We don't have to bind the texture here because it is already bound in
                    // TextureCollection.SetTextures(). This, of course, assumes that SetTextures() is called
                    // before this method is called. If that ever changes this code will misbehave.
                    // GL.BindTexture(texture.glTarget, texture.glTexture);
                    // GraphicsExtensions.CheckGLError();

                    sampler.Activate(device, texture.glTarget, texture.LevelCount > 1);
                    texture.glLastSamplerState = sampler;
                }
            }
        }
Ejemplo n.º 28
0
        internal Effect(GraphicsDevice graphicsDevice)
		{
			if (graphicsDevice == null)
				throw new ArgumentNullException ("Graphics Device Cannot Be Null");

			this.GraphicsDevice = graphicsDevice;
		}
Ejemplo n.º 29
0
 public void DrawAfter2D(GraphicsDevice gd, WorldState state)
 {
     gd.RenderState.CullMode = CullMode.CullCounterClockwiseFace;
     foreach (var avatar in Blueprint.Avatars){
         avatar.Draw(gd, state);
     }
 }
Ejemplo n.º 30
0
 public static unsafe void Reset(GraphicsDevice graphicsDevice, PresentationParameters parameters)
 {
     var fi = typeof(GraphicsDevice).GetField("pComPtr", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
     var ptr = fi.GetValue(graphicsDevice);
     var pComPtr = new IntPtr(System.Reflection.Pointer.Unbox(ptr));
     if (g_mdxAssembly == null) throw new ApplicationException("GraphicsDevice.Reset failed. Please install Managed DirectX from the Assault Wing web site.");
     var mdxDeviceType = g_mdxAssembly.GetType("Microsoft.DirectX.Direct3D.Device");
     var mdxPresentParametersType = g_mdxAssembly.GetType("Microsoft.DirectX.Direct3D.PresentParameters");
     var dev = Activator.CreateInstance(mdxDeviceType, pComPtr);
     dynamic dxParameters = new MDXPresentParameters(Activator.CreateInstance(mdxPresentParametersType));
     dxParameters.AutoDepthStencilFormat = parameters.DepthStencilFormat.ToD3D();
     dxParameters.BackBufferCount = 1;
     dxParameters.BackBufferFormat = parameters.BackBufferFormat.ToD3D();
     dxParameters.BackBufferHeight = parameters.BackBufferHeight;
     dxParameters.BackBufferWidth = parameters.BackBufferWidth;
     dxParameters.DeviceWindow = null;
     dxParameters.DeviceWindowHandle = parameters.DeviceWindowHandle;
     dxParameters.EnableAutoDepthStencil = false; // ???
     dxParameters.ForceNoMultiThreadedFlag = false; // ???
     dxParameters.FullScreenRefreshRateInHz = 0; // ??? should be 0 for windowed mode; in fullscreen mode take value from DisplayModeCollection
     dxParameters.MultiSample = GetMDXEnumValue("MultiSampleType", "None");
     dxParameters.MultiSampleQuality = 0;
     dxParameters.PresentationInterval = parameters.PresentationInterval.ToD3D();
     dxParameters.PresentFlag = GetMDXEnumValue("PresentFlag", "None"); // ???
     dxParameters.SwapEffect = GetMDXEnumValue("SwapEffect", "Flip"); // ??? see _parameters.RenderTargetUsage
     dxParameters.Windowed = !parameters.IsFullScreen;
     var resetMethod = mdxDeviceType.GetMethod("Reset");
     var mdxPresentParametersArray = Array.CreateInstance(mdxPresentParametersType, 1);
     mdxPresentParametersArray.SetValue(((MDXPresentParameters)dxParameters).WrappedValue, 0);
     resetMethod.Invoke(dev, new[] { mdxPresentParametersArray });
 }
Ejemplo n.º 31
0
 public GraphicsManger(GraphicsDevice graphicsDevice, SpriteBatch spriteBatch, ContentManager content)
 {
     Console.WriteLine("graphics manager initialized");
     GraphicsDevice = graphicsDevice;
     SpriteBatch = spriteBatch;
     Content = content;
 }
Ejemplo n.º 32
0
        public XEngineGraphics(XEngineGame game)
        {
            this.mGame = game;

            this.mDevice = null;
            this.mSpriteBatch = null;
        }
Ejemplo n.º 33
0
 public void draw(SpriteBatchWrapper sprites, GraphicsDevice device)
 {
     if (this.wantsToExit()) {
         return;
     }
     this.activeScene.draw(sprites, device);
 }
Ejemplo n.º 34
0
        public override void Initialize()
        {
            base.Initialize();

            graphics = Game1.Instance.Graphics.GraphicsDevice;
            spriteBatch = new SpriteBatch(graphics);
        }
Ejemplo n.º 35
0
 internal void ApplyState(GraphicsDevice device)
 {
   bool flag = device.GetRenderTargets().Length > 0;
   if (this.CullMode == CullMode.None)
   {
     GL.Disable(EnableCap.CullFace);
   }
   else
   {
     GL.Enable(EnableCap.CullFace);
     GL.CullFace(CullFaceMode.Back);
     if (this.CullMode == CullMode.CullClockwiseFace)
     {
       if (flag)
         GL.FrontFace(FrontFaceDirection.Cw);
       else
         GL.FrontFace(FrontFaceDirection.Ccw);
     }
     else if (flag)
       GL.FrontFace(FrontFaceDirection.Ccw);
     else
       GL.FrontFace(FrontFaceDirection.Cw);
   }
   if (this.FillMode == FillMode.Solid)
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill);
   else
     GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line);
   if (this.ScissorTestEnable)
     GL.Enable(EnableCap.ScissorTest);
   else
     GL.Disable(EnableCap.ScissorTest);
   GL.Enable(EnableCap.PolygonOffsetFill);
   GL.PolygonOffset(this.SlopeScaleDepthBias, this.DepthBias * 1E+07f);
 }
Ejemplo n.º 36
0
        public RenderTarget2D(GraphicsDevice graphicsDevice, int width, int height, bool mipMap, 
			SurfaceFormat preferredFormat, DepthFormat preferredDepthFormat, int preferredMultiSampleCount, RenderTargetUsage usage)
            : base(graphicsDevice, width, height, mipMap, preferredFormat)
        {
            RenderTargetUsage = usage;
            DepthStencilFormat = preferredDepthFormat;
        }
Ejemplo n.º 37
0
        public Microsoft.Xna.Framework.Graphics.Texture2D GetPreviewTexture(Microsoft.Xna.Framework.Graphics.GraphicsDevice GraphicsDevice)
        {
            var MapPreview = new Texture2D(GraphicsDevice, PreviewSize.Width, PreviewSize.Height, false, SurfaceFormat.Color);

            MapPreview.SetData(Preview);

            return(MapPreview);
        }
Ejemplo n.º 38
0
        public override void draw(Microsoft.Xna.Framework.Graphics.GraphicsDevice _GraphicsDevice, Microsoft.Xna.Framework.Graphics.SpriteBatch _SpriteBatch)
        {
            float     percentageLife = Configuration.Configuration.networkManager.client.PlayerObject.HealthPoints / Configuration.Configuration.networkManager.client.PlayerObject.MaxHealthPoints;
            Rectangle source         = new Rectangle(0, (int)((1 - percentageLife) * this.Bounds.Height), this.Bounds.Width, (int)(this.Bounds.Height * percentageLife));
            Rectangle destination    = new Rectangle(this.Bounds.X, (int)(this.Bounds.Y + (1 - percentageLife) * this.Bounds.Height), this.Bounds.Width, (int)(this.Bounds.Height * percentageLife));

            _SpriteBatch.Draw(Ressourcen.RessourcenManager.ressourcenManager.Texture[this.BackgroundGraphicPath], destination, source, this.ComponentColor);
        }
Ejemplo n.º 39
0
        /*public void setAnimation(Animation.AnimatedObjectAnimation _Animation)
         * {
         *  this.animation = _Animation;
         *  if(this.equipment!=null)
         *  {
         *      this.equipment.A
         * }*/

        private void drawEquipment(Microsoft.Xna.Framework.Graphics.GraphicsDevice _GraphicsDevice, Microsoft.Xna.Framework.Graphics.SpriteBatch _SpriteBatch, Vector2 _BodyCenter)
        {
            if (this.equipment != null)
            {
                this.equipment.Position = new Vector3(_BodyCenter, 0);
                this.equipment.drawWearingEquipment(_GraphicsDevice, _SpriteBatch, this.color, this.animation);
            }
        }
Ejemplo n.º 40
0
        public void CreateBuffer(Microsoft.Xna.Framework.Graphics.GraphicsDevice gd)
        {
            VertexBuffer = new VertexBuffer(gd, TerrainVertex.SizeInBytes * Vertices.Length, BufferUsage.WriteOnly);
            VertexBuffer.SetData(Vertices);

            IndexBuffer = new IndexBuffer(gd, typeof(int), Indexes.Length, BufferUsage.WriteOnly);
            IndexBuffer.SetData(Indexes);
        }
Ejemplo n.º 41
0
        public override void Draw(Microsoft.Xna.Framework.Graphics.GraphicsDevice device, Camera cam)
        {
            if (ApplicationSettings.ShowDebugLines)
            {
                Debug.DrawLines(device, cam);
            }
            if (ApplicationSettings.ShowDebugPhysics)
            {
                Matrix proj = cam.projectionMatrix;
                Matrix view = cam.view;
                if (rayCastPlane.HasValue)
                {
                    if (rayCastPlane.Value.normal == Vector3.up)
                    {
                        view = Matrix.CreateRotationX(MathHelper.ToRadians(90)) * view;
                    }
                }

                physicsDebugView.RenderDebugData(ref proj, ref view, b => dontDrawColliders.Contains(b.UserData));

                // NOTE: This only works for XY plane stuff
                PressPlay.FFWD.Vector3 inPos = Input.mousePosition;
                inPos.z = cam.nearClipPlane;
                PressPlay.FFWD.Vector2 castPos = cam.ScreenToWorldPoint(inPos);
                if (rayCastPlane.HasValue)
                {
                    float dist;
                    Ray   ray = Camera.main.ScreenPointToRay(inPos);
                    if (rayCastPlane.Value.Raycast(ray, out dist))
                    {
                        Vector3 pt = ray.GetPoint(dist);
                        castPos = new Vector2(pt.x, pt.z);
                    }
                    else
                    {
                        castPos = Vector2.zero;
                    }
                }
                Debug.Display("Mouse / Physics", inPos + " / " + castPos);

                RaycastHit[] hits = Physics.PointcastAll(castPos, cam.cullingMask);
                if (hits.Length > 0)
                {
                    Debug.Display("Over", String.Join("\n", hits.Select(h => h.collider.ToString()).OrderBy(s => s).ToArray()));
                }
                else
                {
                    Debug.Display("Over", "");
                }
            }

            if (ApplicationSettings.ShowDebugPhysicsCustom)
            {
                Physics.DrawDebug();
            }
        }
Ejemplo n.º 42
0
 /// <summary>
 /// Construct
 /// </summary>
 /// <param name="Content"></param>
 /// <param name="GraphicsDevice"></param>
 /// <param name="newSpace"></param>
 public RainParticle(Microsoft.Xna.Framework.Content.ContentManager Content, Microsoft.Xna.Framework.Graphics.GraphicsDevice GraphicsDevice, int newSpace)
 {
     // TODO: Complete member initialization
     rainView            = new List <RainView>();
     this.m_rainTexture  = Content.Load <Texture2D>("rain");
     this.GraphicsDevice = GraphicsDevice;
     this.space          = newSpace;
     random1             = new Random();
     random2             = new Random();
 }
Ejemplo n.º 43
0
 public void PreDraw(Microsoft.Xna.Framework.Graphics.GraphicsDevice device)
 {
     foreach (var scene in Scenes)
     {
         if (scene.Visible)
         {
             scene.PreDraw(device);
         }
     }
 }
Ejemplo n.º 44
0
        /// <summary>
        /// Draws the meshes making up this Avatar instance.
        /// </summary>
        /// <param name="device">A GraphicsDevice instance.</param>
        public override void Draw(Microsoft.Xna.Framework.Graphics.GraphicsDevice device)
        {
            Effect.CurrentTechnique = Effect.Techniques[DefaultTechnique];
            Effect.Parameters["View"].SetValue(View);
            Effect.Parameters["Projection"].SetValue(Projection);
            Effect.Parameters["World"].SetValue(World);
            Effect.Parameters["AmbientLight"].SetValue(AmbientLight);

            DrawGeometry(device, Effect);
        }
Ejemplo n.º 45
0
 public static bool TryCreateTexture(SpanBitmap src, XNA.GraphicsDevice device, out XNA.Texture2D tex)
 {
     try
     {
         tex = null;
         Copy(src, ref tex, false, device, null, null);
         return(true);
     }
     catch (ArgumentException) { tex = null; return(false); }
 }
Ejemplo n.º 46
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="pDevice"></param>
        public void LoadGraphicsContent(XNA.Graphics.GraphicsDevice pDevice)
        {
            mSpriteBatch    = new SpriteBatch(pDevice);
            mPrimitiveBatch = new PrimitivesSample.PrimitiveBatch(pDevice);

            if (this.mLogoTexture == null)
            {
                this.mLogoTexture = Texture2D.FromFile(pDevice, @"Content\Logo.png");
            }
        }
Ejemplo n.º 47
0
 /// <summary>
 /// Creates a new instance of <see cref="XNAEffectImplementation"/>.
 /// </summary>
 /// <param name="renderer">The XNA renderer.</param>
 /// <param name="byteCode">The compiled byte code.</param>
 internal XNAEffectImplementation(XNARenderer renderer, byte[] byteCode)
 {
     _renderer       = renderer;
     _graphicsDevice = renderer.GraphicsDevice;
     _cachedByteCode = byteCode;
     _effect         = new XFG.Effect(_graphicsDevice, byteCode);
     base.SetParameters(new XNAEffectParameterCollection(_effect.Parameters));
     base.SetTechniques(new XNAEffectTechniqueCollection(_effect.Techniques));
     _currentTechnique = (XNAEffectTechnique)base.Techniques[0];
 }
Ejemplo n.º 48
0
 public virtual void drawWearingEquipment(Microsoft.Xna.Framework.Graphics.GraphicsDevice _GraphicsDevice, Microsoft.Xna.Framework.Graphics.SpriteBatch _SpriteBatch, Microsoft.Xna.Framework.Color _Color, Animation.AnimatedObjectAnimation _Animation)
 {
     try
     {
         _SpriteBatch.Draw(Ressourcen.RessourcenManager.ressourcenManager.Texture[this.Body.MainBody.TexturePath], new Microsoft.Xna.Framework.Vector2(this.Position.X, this.Position.Y), _Animation.sourceRectangle(), _Animation.drawColor(), 0f, Microsoft.Xna.Framework.Vector2.Zero, new Microsoft.Xna.Framework.Vector2(this.Scale, this.Scale), Microsoft.Xna.Framework.Graphics.SpriteEffects.None, 1.0f);
     }
     catch (Exception e)
     {
     }
 }
Ejemplo n.º 49
0
        public void draw(Microsoft.Xna.Framework.Graphics.GraphicsDevice _GraphicsDevice, Microsoft.Xna.Framework.Graphics.SpriteBatch _SpriteBatch, Vector2 _BodyCenter)
        {
            Vector2 var_Position  = new Vector2(this.position.X + _BodyCenter.X, this.position.Y + _BodyCenter.Y);
            Color   var_DrawColor = this.color;

            if (!this.animation.graphicPath().Equals(""))
            {
                _SpriteBatch.Draw(Ressourcen.RessourcenManager.ressourcenManager.Texture[this.animation.graphicPath()], var_Position, this.animation.sourceRectangle(), var_DrawColor, 0f, Vector2.Zero, new Vector2(this.scale, this.scale), SpriteEffects.None, 1.0f);
            }
            this.drawEquipment(_GraphicsDevice, _SpriteBatch, _BodyCenter);
        }
Ejemplo n.º 50
0
 public XNARenderSystemProvider()
 {
     _game      = new XNAGame();
     _gdManager = new XNA.GraphicsDeviceManager(_game);
     _gdManager.GraphicsProfile = XFG.GraphicsProfile.HiDef;
     _gdManager.ApplyChanges();
     _renderer = new XNARenderer(_gdManager.GraphicsDevice);
     _device   = _renderer.GraphicsDevice;
     _content  = new ContentManager(new EmbeddedResourceLocator(Tesla.Xna.DefaultContent.ResourceManager));
     _content.UseDefaultContent = false;
 }
Ejemplo n.º 51
0
        /// <summary>
        /// Initialization
        /// </summary>
        /// <param name="device"></param>
        /// <param name="physicsEngine"></param>
        public override void Initialize(xnagrfx.GraphicsDevice device, PhysicsEngine physicsEngine)
        {
            try
            {
                InitError = string.Empty;
                // set flag so rendering engine renders us last
                Flags |= VisualEntityProperties.UsesAlphaBlending;

                // creates effect, loads meshes, etc
                base.Initialize(device, physicsEngine);

                HeightFieldShapeProperties hf = new HeightFieldShapeProperties("height field", 2, 0.02f, 2, 0.02f, 0, 0, 1, 1);
                hf.HeightSamples = new HeightFieldSample[hf.RowCount * hf.ColumnCount];
                for (int i = 0; i < hf.HeightSamples.Length; i++)
                {
                    hf.HeightSamples[i] = new HeightFieldSample();
                }

                _particlePlane            = new Shape(hf);
                _particlePlane.State.Name = "sonar impact plane";

                VisualEntityMesh sonarMesh = null;

                // we render on our own only the laser impact points. The laser Box is rendered as part of the parent.
                int index = Meshes.Count;
                Meshes.Add(SimulationEngine.ResourceCache.CreateMesh(device, _particlePlane.State));
                Meshes[0].Textures[0] = SimulationEngine.ResourceCache.CreateTextureFromFile(device, "particle.bmp");

                // we have a custom effect, with an additional global parameter. Get handle to it here
                if (Effect != null)
                {
                    _timeAttenuationHandle = Effect.GetParameter("timeAttenuation");
                }

                World = xna.Matrix.Identity;
                if (Meshes.Count > 1)
                {
                    sonarMesh = Meshes[0];
                }

                if (Parent == null)
                {
                    throw new Exception("This entity must be a child of another entity.");
                }

                Parent.AddShapeToPhysicsEntity(_sonarBox, sonarMesh);
            }
            catch (Exception ex)
            {
                HasBeenInitialized = false;
                InitError          = ex.ToString();
            }
        }
Ejemplo n.º 52
0
        /// <summary>
        /// Draws the meshes making up this Avatar instance.
        /// </summary>
        /// <param name="device">A GraphicsDevice instance.</param>
        public override void Draw(Microsoft.Xna.Framework.Graphics.GraphicsDevice device)
        {
            Effect.CurrentTechnique = Effect.Techniques[DefaultTechnique];
            Effect.Parameters["View"].SetValue(View);
            Effect.Parameters["Projection"].SetValue(Projection);
            Effect.Parameters["World"].SetValue(World);
            Effect.Parameters["AmbientLight"].SetValue(new Vector4(1, 1, 1, 1));

            var test = Vector4.Transform(new Vector4(0, 5.2f, 0, 1), World * View * Projection);

            DrawGeometry(device, Effect);
        }
Ejemplo n.º 53
0
 public void Initialize(Microsoft.Xna.Framework.Graphics.GraphicsDevice device)
 {
     this.Device = device;
     foreach (var scene in Scenes)
     {
         scene.Initialize(this);
     }
     foreach (var scene in External)
     {
         scene.Initialize(this);
     }
 }
Ejemplo n.º 54
0
 internal XNASwapChainImplementation(XNA.GraphicsDeviceManager gdManager, IntPtr windowHandle, PresentationParameters presentParams)
 {
     _gdManager             = gdManager;
     _graphicsDevice        = gdManager.GraphicsDevice;
     _windowHandle          = windowHandle;
     _presentParams         = presentParams;
     _pp                    = new XFG.PresentationParameters();
     _pp.DeviceWindowHandle = windowHandle;
     _pp.IsFullScreen       = false;
     _pp.DisplayOrientation = XNA.DisplayOrientation.Default;
     SetXNAPresentationParameters(presentParams);
     _graphicsDevice.Reset(_pp);
 }
Ejemplo n.º 55
0
 public static void Initialize(GDM gdm, GD gd, CM cm, SB sb)
 {
     G.gdm = gdm;
     G.gd  = gd;
     G.cm  = cm;
     G.sb  = sb;
     w     = gdm.PreferredBackBufferWidth = 1024;
     h     = gdm.PreferredBackBufferHeight = 768;
     gdm.ApplyChanges();
     leftVp   = new Viewport(0, 0, G.w / 2, G.h);
     rightVp  = new Viewport(G.w / 2, 0, G.w / 2, G.h);
     screenVp = new Viewport(0, 0, G.w, G.h);
 }
Ejemplo n.º 56
0
 internal XNARenderer(XFG.GraphicsProfile profile)
 {
     _dummyForm = new System.Windows.Forms.Form();
     XFG.PresentationParameters pp = new XFG.PresentationParameters();
     pp.BackBufferFormat     = XFG.SurfaceFormat.Color;
     pp.BackBufferHeight     = 1;
     pp.BackBufferWidth      = 1;
     pp.DepthStencilFormat   = XFG.DepthFormat.None;
     pp.DeviceWindowHandle   = _dummyForm.Handle;
     pp.PresentationInterval = XFG.PresentInterval.Immediate;
     pp.IsFullScreen         = false;
     _device = new XFG.GraphicsDevice(XFG.GraphicsAdapter.DefaultAdapter, profile, pp);
 }
        /// <summary>
        /// Insert propellers dynamically based on multicopter type
        /// </summary>
        private void InsertPropellers(xnagrfx.GraphicsDevice device, PhysicsEngine physicsEngine)
        {
            // InitializePlot propeller list
            propellerEntities = new List <PropellerEntity>();

            // Calculate angleChange between arms by dividing 360° by the number of propellers
            float angleBetweenArms             = (2 * xna.MathHelper.Pi) / Globals.Instance.multicopterPropellerCount[multicopterType];
            float propellerInclinationAngleRad = xna.MathHelper.ToRadians(propellerInclinationAngle);

            // Define the position of the first propeller (the other positions are calculated by rotating this vector)
            Vector3 positionFirstPropeller = new Vector3(0.11f, CHASSIS_DIMENSIONS_HEIGHT - 0.005f, 0.0f);

            // Define the orientation axis of the first propeller (the other orientation axis are calculated by rotating this vector)
            Vector3 orientationAxisFirstPropeller = new Vector3(0, 0, 1);

            // Calculate the force direction of the first propeller (the other force directions are calculated by rotating this vector)
            Vector3 forceDirectionFirstPropeller = MathHelper.RotateAroundAxis_Z(
                new Vector3(0, 1, 0),        // The normal force direction at zero inclination is straight upwards
                new Vector3(),               // The forces are local, we rotate around (0, 0, 0)
                propellerInclinationAngleRad // Get inclination angleChange in rad
                );

            // InitializePlot every propeller for every arm
            for (byte i = 0; i < Globals.Instance.multicopterPropellerCount[multicopterType]; i++)
            {
                // Construct the name by the current number
                string namePropeller = State.Name + " Propeller " + (i + 1);

                // Calculate the angleChange between this arm and the first arm
                float currentAngle = angleBetweenArms * i;

                // Calculate the position of the propeller by rotating the first position around the y-axis
                Vector3 positionPropeller = MathHelper.RotateAroundAxis_Y(positionFirstPropeller, new Vector3(), currentAngle);

                // Calculate the position of the orientation axis by rotating the first orientation axis around the y-axis
                Vector3 orientationAxisPropeller = MathHelper.RotateAroundAxis_Y(orientationAxisFirstPropeller, new Vector3(), currentAngle);
                //Quaternion orientationPropeller = Quaternion.FromAxisAngle(orientationAxisPropeller.X, 0, orientationAxisPropeller.Z, propellerInclinationAngleRad);
                Quaternion orientationPropeller = Quaternion.FromAxisAngle(new AxisAngle(orientationAxisPropeller, propellerInclinationAngleRad));

                // Calculate the force direction of the propeller by rotating the first force direction around the y-axis
                Vector3 forceDirectionPropeller = MathHelper.RotateAroundAxis_Y(forceDirectionFirstPropeller, new Vector3(), currentAngle);

                // Create the new propeller entity
                PropellerEntity newPropellerEntity = new PropellerEntity(namePropeller, positionPropeller, orientationPropeller, forceDirectionPropeller);
                newPropellerEntity.Parent = this;
                newPropellerEntity.Initialize(device, physicsEngine);

                // Add the new propeller entity
                propellerEntities.Add(newPropellerEntity);
            }
        }
Ejemplo n.º 58
0
        /// <summary>
        /// Updates the scene.
        /// </summary>
        private void Form1_OnFrameMove(Microsoft.Xna.Framework.Graphics.GraphicsDevice pDevice)
        {
            mWorldMat = Matrix.Identity * Matrix.CreateScale(m_Scale) * Matrix.CreateRotationX(m_RotationX) * Matrix.CreateRotationY(m_RotationY) * Matrix.CreateRotationZ(m_RotationZ);

            if (m_RenderSim.GetBodyMesh() != null && m_RenderSim.GetHeadMesh() != null)
            {
                if (m_IsAnimating)
                {
                    m_RenderSim.GetBodyMesh().AdvanceFrame(ref m_RenderSim.SimSkeleton, m_CurrentAnim,
                                                           ref m_CurrentFrame, .02f);
                    m_RenderSim.SimSkeleton.ComputeBonePositions(m_RenderSim.SimSkeleton.RootBone, mWorldMat);
                }
            }
        }
Ejemplo n.º 59
0
        //protected Rectangle rectangle;


        public StaticGraphic(Device graphicDevice, string source, Vector2 position,
                             float rotate, float scale, Color color, byte alpha, byte parameter)
        {
            Texturearray      = new[] { Texture2D.FromFile(graphicDevice, source) };
            Origin            = new Vector2(0, 0);
            Position          = position;
            Rotate            = rotate;
            Scale             = new Vector2(scale, scale);
            Layer             = 0;
            Color             = color;
            Alpha             = alpha;
            Parameter         = parameter;
            CurrentFrameIndex = 0;
        }
Ejemplo n.º 60
0
        /// <summary>
        /// Constructor is private, because this is a singleton class:
        /// client controls should use the public AddRef method instead.
        /// </summary>
        GraphicsDeviceService(IntPtr windowHandle, int width, int height)
        {
            parameters = new PresentationParameters();

            parameters.BackBufferWidth      = Math.Max(width, 1);
            parameters.BackBufferHeight     = Math.Max(height, 1);
            parameters.BackBufferFormat     = SurfaceFormat.Color;
            parameters.DepthStencilFormat   = DepthFormat.Depth24;
            parameters.DeviceWindowHandle   = windowHandle;
            parameters.PresentationInterval = PresentInterval.Immediate;
            parameters.IsFullScreen         = false;

            graphicsDevice = new Microsoft.Xna.Framework.Graphics.GraphicsDevice(GraphicsAdapter.DefaultAdapter, GraphicsProfile.HiDef, parameters);
        }