public T2DPolygon()
        {
            // by default, we'll have physics and collision
            CreateWithCollision = true;
            CreateWithPhysics = true;

            GarageGames.Torque.Materials.SimpleMaterial seffect = new GarageGames.Torque.Materials.SimpleMaterial();
            _material = seffect;
        }
 /// <summary>
 /// This is called by the associated RenderMaterial when it's unloaded.
 /// </summary>
 public virtual void Destroy()
 {
     _material = null;
 }
        public override void Init(RenderMaterial material)
        {
            base.Init(material);

            // make sure our list isn't null
            if (_regionList == null)
                _regionList = new List<RectangleF>();
        }
        public override void Init(RenderMaterial material)
        {
            base.Init(material);

            // call calculate cells now
            // (there is a chance that it wasn't able to load earlier due to the texture
            // dimensions not being available yet)
            _CalculateCells();
        }
        /// <summary>
        /// Add the specified material to the manager with the specified name. If the material is already in the 
        /// manager, it is remapped to the specified name.
        /// </summary>
        /// <param name="name">Mapped name for material</param>
        /// <param name="material">The material</param>
        /// <returns>The material</returns>
        public static RenderMaterial Add(String name, RenderMaterial material)
        {
            Assert.Fatal(material != null, "Cannot add mapping to null material");

            if (!string.IsNullOrEmpty(name))
            {
                name = _MapName(name);
                RenderMaterial tempMat;
                if (_mappedMaterials.TryGetValue(name, out tempMat))
                    return null;
                _mappedMaterials[name] = material;
            }

            // the material might already have been added to the material list
            // don't re-add it
            if (!_materials.Contains(material))
                _materials.Add(material);

            return material;
        }
 public virtual void Dispose()
 {
     _material = null;
 }
예제 #7
0
 ///<summary>
 ///Draws an unstretched bitmap.
 ///</summary>
 ///<param name="material">
 ///The material used when rendering. 
 ///The material must implement <see cref="ITextureMaterial"/>.
 ///</param>
 ///<param name="position">
 ///Where to draw the texture in 2d coordinates.
 ///</param>
 ///<param name="flipMode">
 ///Any flipping to be done of the source texture.
 ///</param>
 public static void Bitmap(
   RenderMaterial material,
   Vector2 position,
   BitmapFlip flipMode)
 {
     DrawUtil.Bitmap(
         material,
         position + Instance._defaultOffset,
         flipMode);
 }
 /// <summary>
 /// Copies a render instance's fields into this render instance.
 /// </summary>
 /// <param name="src">The render instance to copy.</param>
 public void Copy(RenderInstance src)
 {
     VertexBuffer = src.VertexBuffer;
     IndexBuffer = src.IndexBuffer;
     VertexDeclaration = src.VertexDeclaration;
     Material = src.Material;
     ObjectTransform = src.ObjectTransform;
     WorldBox = src.WorldBox;
     UTextureAddressMode = src.UTextureAddressMode;
     VTextureAddressMode = src.VTextureAddressMode;
     VertexSize = src.VertexSize;
     PrimitiveType = src.PrimitiveType;
     BaseVertex = src.BaseVertex;
     VertexCount = src.VertexCount;
     StartIndex = src.StartIndex;
     PrimitiveCount = src.PrimitiveCount;
     Type = src.Type;
     SortPoint = src.SortPoint;
     IsSortPointSet = src.IsSortPointSet;
     Opacity = src.Opacity;
 }
예제 #9
0
        /// <summary>
        /// Draws a stretched sub-region of a texture.
        /// </summary>
        /// <param name="material">The material used when rendering. The material must implement ITextureMaterial.</param>
        /// <param name="dstRect">Rectangle where the texture object will be drawn.</param>
        /// <param name="srcRect">Sub-region of the texture that will be applied over the <paramref name="dstRect"/>.</param>
        /// <param name="flipMode">Any flipping to be done of the source texture.</param>
        public static void BitmapStretchSR(RenderMaterial material, RectangleF dstRect, RectangleF srcRect, BitmapFlip flipMode)
        {
            // setup render state
            GUICanvas.Instance.RenderState.World.LoadIdentity();
            GUICanvas.Instance.RenderState.View = Matrix.Identity;
            GUICanvas.Instance.RenderState.Projection = _clipMatrix;

            // setup the material
            material.SetupEffect(GUICanvas.Instance.RenderState, null);

            _texLeft = srcRect.X / ((Texture2D)((ITextureMaterial)material).Texture.Instance).Width;
            _texRight = (srcRect.X + srcRect.Width) / ((Texture2D)((ITextureMaterial)material).Texture.Instance).Width;
            _texTop = srcRect.Y / ((Texture2D)((ITextureMaterial)material).Texture.Instance).Height;
            _texBottom = (srcRect.Y + srcRect.Height) / ((Texture2D)((ITextureMaterial)material).Texture.Instance).Height;

            _screenLeft = dstRect.X;
            _screenRight = dstRect.X + dstRect.Width;
            _screenTop = dstRect.Y;
            _screenBottom = dstRect.Y + dstRect.Height;

            // flip x
            if ((flipMode & BitmapFlip.FlipX) != 0)
            {
                float temp = _texLeft;
                _texLeft = _texRight;
                _texRight = temp;
            }

            // flip y
            if ((flipMode & BitmapFlip.FlipY) != 0)
            {
                float temp = _texTop;
                _texTop = _texBottom;
                _texBottom = temp;
            }

            color = _bitmapModulation;

            _vertexSet4[0].Position = new Vector3(_screenLeft - 0.5f, _screenTop - 0.5f, 0.0f);
            _vertexSet4[0].TextureCoordinate = new Vector2(_texLeft, _texTop);
            _vertexSet4[0].Color = color;

            _vertexSet4[1].Position = new Vector3(_screenRight - 0.5f, _screenTop - 0.5f, 0.0f);
            _vertexSet4[1].TextureCoordinate = new Vector2(_texRight, _texTop);
            _vertexSet4[1].Color = color;

            _vertexSet4[2].Position = new Vector3(_screenLeft - 0.5f, _screenBottom - 0.5f, 0.0f);
            _vertexSet4[2].TextureCoordinate = new Vector2(_texLeft, _texBottom);
            _vertexSet4[2].Color = color;

            _vertexSet4[3].Position = new Vector3(_screenRight - 0.5f, _screenBottom - 0.5f, 0.0f);
            _vertexSet4[3].TextureCoordinate = new Vector2(_texRight, _texBottom);
            _vertexSet4[3].Color = color;

            // adltodo: hacks
            _workingRenderInstance = SceneRenderer.RenderManager.AllocateInstance();
            _workingRenderInstance.ObjectTransform = Matrix.Identity;

            GUICanvas.Instance.RenderState.Gfx.Device.VertexDeclaration = GFXVertexFormat.GetVertexDeclaration(GUICanvas.Instance.RenderState.Gfx.Device);

            // draw the vertices
            while (material.SetupPass())
            {
                material.SetupObject(_workingRenderInstance, GUICanvas.Instance.RenderState);

                GUICanvas.Instance.RenderState.Gfx.Device.DrawUserPrimitives<GFXVertexFormat.PCTTBN>(PrimitiveType.TriangleStrip, _vertexSet4, 0, 2);
            }

            // cleanup the material
            material.CleanupEffect();
            SceneRenderer.RenderManager.FreeInstance(_workingRenderInstance);
        }
예제 #10
0
 ///<summary>
 ///Draws a stretched sub-region of a texture.
 ///</summary>
 ///<param name="material">
 ///The material used when rendering. 
 ///The material must implement <see cref="ITextureMaterial"/>.
 ///</param>
 ///<param name="dstRect">
 ///Rectangle where the texture object will be drawn.
 ///</param>
 ///<param name="srcRect">
 ///Sub-region of the texture that will be applied over the
 ///<paramref name="dstRect"/>.
 ///</param>
 ///<param name="flipMode">
 ///Any flipping to be done of the source texture.
 ///</param>
 public static void BitmapStretchSR(
   RenderMaterial material,
   RectangleF dstRect,
   RectangleF srcRect,
   BitmapFlip flipMode)
 {
     dstRect.Point += Instance._defaultOffset;
     DrawUtil.BitmapStretchSR(material, dstRect, srcRect, flipMode);
 }
예제 #11
0
        /// <summary>
        /// Draws a stretched bitmap.
        /// </summary>
        /// <param name="material">The material used when rendering. The material must implement ITextureMaterial.</param>
        /// <param name="dstRect">Rectangle where the texture object will be drawn.</param>
        /// <param name="flipMode">Any flipping to be done of the source texture.</param>
        public static void BitmapStretch(RenderMaterial material, RectangleF dstRect, BitmapFlip flipMode)
        {
            Assert.Fatal(material != null, "No material specified for DrawUtil::BitmapStretch");

            if (((ITextureMaterial)material).Texture.IsNull)
            {
                Texture2D texture = ((Texture2D)ResourceManager.Instance.LoadTexture((material as ITextureMaterial).TextureFilename).Instance);
                subRegion = new RectangleF(0.0f, 0.0f, texture.Width, texture.Height);
            }
            else
            {
                subRegion = new RectangleF(0.0f, 0.0f, ((Texture2D)((ITextureMaterial)material).Texture.Instance).Width, ((Texture2D)((ITextureMaterial)material).Texture.Instance).Height);
            }

            DrawUtil.BitmapStretchSR(material, dstRect, subRegion, flipMode);
        }
예제 #12
0
        /// <summary>
        /// Draws an unstretched sub-region of a texture.
        /// </summary>
        /// <param name="material">The material used when rendering. The material must implement ITextureMaterial.</param>
        /// <param name="position">Where to draw the texture in 2d coordinates.</param>
        /// <param name="srcRect">Sub-region of the texture to be drawn.</param>
        /// <param name="flipMode">Any flipping to be done of the source texture.</param>
        public static void BitmapSR(RenderMaterial material, Vector2 position, RectangleF srcRect, BitmapFlip flipMode)
        {
            Assert.Fatal(material != null, "No texture specified for DrawUtil::BitmapSR");

            RectangleF stretch = new RectangleF(position.X, position.Y, srcRect.Width, srcRect.Height);
            DrawUtil.BitmapStretchSR(material, stretch, srcRect, flipMode);
        }
        /// <summary>
        /// Remove the specified material from the render manager.  Also removes any mappings to that material.
        /// </summary>
        /// <param name="material">The material to remove.</param>
        public static void Remove(RenderMaterial material)
        {
            Assert.Fatal(material != null, "Null material passed to Remove");
            if (material == null)
                return;

            _materials.Remove(material);
            string keyToRemove = null;
            foreach (KeyValuePair<string, RenderMaterial> pair in _mappedMaterials)
            {
                if (pair.Value == material)
                {
                    keyToRemove = pair.Key;
                    break;
                }
            }

            if (keyToRemove != null)
                _mappedMaterials.Remove(keyToRemove);
        }
 /// <summary>
 /// This is called by the associated RenderMaterial once it's been loaded.
 /// </summary>
 public virtual void Init(RenderMaterial material)
 {
     // keep a reference to the render material for later use
     _material = material;
 }
        protected override void _RenderGroup(List<RenderInstance> renderInstances, RenderMaterial material, MaterialInstanceData materialData, SceneRenderState srs, GraphicsDevice d3d)
        {
            // If the first instance is a 3D shape then make sure the
            // state is set for rendering them.
            if (renderInstances[0].Type == RenderInstance.RenderInstanceType.Mesh3D)
            {
                if (!_rendering3D)
                    _Setup3DState(srs, d3d);
            }
            else
            {
                // Restore the 2D rendering state.
                if (_rendering3D)
                    _Cleanup3DState(srs, d3d);
            }

            // Render as normal.
            base._RenderGroup(renderInstances, material, materialData, srs, d3d);
        }
 protected override void _RenderGroup(List<RenderInstance> renderInstances, RenderMaterial material, MaterialInstanceData materialData, SceneRenderState srs, GraphicsDevice d3d)
 {
     (material as IRefractionMaterial).SetTexture(_refractionTexture);
     base._RenderGroup(renderInstances, material, materialData, srs, d3d);
 }
 public override void Dispose()
 {
     _IsDisposed = true;
     _material = null;
     _animationFrames = null;
     if (_animationFramesList != null)
         _animationFramesList.Clear();
     _animationFramesList = null;
     base.Dispose();
 }
 /// <summary>
 /// Resets the render instance's fields to defaults.
 /// </summary>
 public virtual void Reset()
 {
     VertexBuffer = null;
     IndexBuffer = null;
     VertexDeclaration = null;
     Material = null;
     MaterialInstanceData = null;
     Opacity = 1.0f;
     UTextureAddressMode = TextureAddressMode.Clamp;
     VTextureAddressMode = TextureAddressMode.Clamp;
     ObjectTransform = Matrix.Identity;
     SortPoint = Vector3.Zero;
     IsSortPointSet = false;
     VertexSize = 0;
     PrimitiveType = PrimitiveType.TriangleStrip;
     BaseVertex = 0;
     VertexCount = 0;
     StartIndex = 0;
     PrimitiveCount = 0;
     Type = RenderInstanceType.UndefinedType;
     MaterialSortKey = 0;
     GeometrySortKey = 0;
     IsReset = true;
 }
 /// <summary>
 /// Adds the specified material to the material manager without a name. The material can be remapped
 /// with a name later.
 /// </summary>
 /// <param name="material"></param>
 /// <returns></returns>
 public static RenderMaterial Add(RenderMaterial material)
 {
     return Add(string.Empty, material);
 }