Xceed Chart for WinForms v4.4 Documentation
Texture Mapping

Welcome to Xceed Chart for WinForms v4.4 > User Guide > Fill Effects > Texture Mapping

Internally, Xceed Chart for WinForms converts gradients, patterns, advanced gradients, and images to textures. By default you won't have to modify the properties related to texture mapping because the control will automatically assign the values best for the current type of fill effect. In certain cases, however, you can achieve a much better appearance if you're familiar with this chart feature. 

Texture mapping is controlled by mapping types and layout types. 

There are three mapping types (see the MapMode Enumeration page for details):

  • Relative to view (MapMode.RelativeToViewer): With this mapping type, texture coordinates are computed relative to the viewer. This is why the texture appears to move inside the object when you rotate or scale it.
  • Relative to object (MapMode.RelativeToObject): With this mapping type, texture coordinates are calculated relative to the object position. This is why the texture mapping does not change when you rotate or move your objects. This is the most common mapping type.
  • Sphere map (MapMode.Sphere): This mapping type can be used if you want to employ special visual effects such as mirror or reflection. However, using it properly requires an appropriate texture. This is why sphere mapping is not described in this tutorial: if you want to use this feature, you must have an in-depth understanding of OpenGL.

In addition, when the mapping type is MapMode.RelativeToObject, a layout strategy can be chosen from MapLayout Enumeration.

  • Stretched: This mapping layout stretches the texture along the X and Y axes until it fits the object. It does not preserve the original ratio of the texture dimensions (aspect).
  • Fitted: Stretches the texture until it fits along X or Y, by choosing the smaller stretch. This layout mode preserves the ratio of the texture dimensions (aspect).
  • Centered: Similar to Fitted. When used on the background object, it also preserves the original texture dimensions.
  • Tiled: Repeats the texture along the X and Y axes. This layout mode preserves the ratio of the texture dimensions (aspect).
  • StretchedToWidth: Stretches the texture's width until it fits. This layout mode preserves the ratio of the texture dimensions ratio.
  • StretchedToHeight: The same as "Stretched to Width" except that it stretches along the Y axis. This layout mode preserves the ratio of the texture dimensions (aspect).
  • CropFitted: Stretches the texture until it fits along X or Y by choosing the greater stretch. This layout mode preserves the ratio of the texture dimensions (aspect).

The properties related to texture mapping are controlled by objects of type FillEffectMapping. You can assign such an object to a fill effect with the help of the Mapping property:

VB.NET  

Dim mapping As FillEffectMapping = New FillEffectMapping()
mapping.MapLayout = MapLayout.Tiled
fillEffect.Mapping = mapping
C#  

FillEffectMapping mapping = new FillEffectMapping();
mapping.MapLayout = MapLayout.Tiled;
fillEffect.Mapping = mapping;

You can also take advantage of the HorizontalScale and VerticalScale properties of the fill effect mapping object, which allow you to scale the image along the X and Y directions. The following code applies a pattern to the background and scales it 4 times:

VB.NET  

fillEffect.SetPattern(HatchStyle.Divot, Color.White, Color.Blue)

Dim mapping As FillEffectMapping = New FillEffectMapping()

mapping.MapMode = MapMode.RelativeToViewer
mapping.MapLayout = MapLayout.Tiled
mapping.HorizontalScale = 4.0F
mapping.VerticalScale = 4.0F
C#  

fillEffect.SetPattern(HatchStyle.Divot, Color.White, Color.Blue);

FillEffectMapping mapping = new FillEffectMapping();

mapping.MapMode = MapMode.RelativeToViewer;
mapping.MapLayout = MapLayout.Tiled;
mapping.HorizontalScale = 4.0f;
mapping.VerticalScale = 4.0f;

Related Examples

Windows Forms: Fill Effects\General

See Also

FillEffect | Xceed 3D Lighting Model | Working with Lights