Lighting is one of the most impressive features of Xceed Chart for WinForms: components that do not use a 3D technology such as OpenGL or DirectX to display charts cannot fully reproduce this effect.
Configuring lighting, however, is sometimes tricky because it requires an understanding of lighting. This is why Xceed has created a set of predefined light schemes that help you configure lighting with ease. It takes only one function call and is very convenient, especially when you're short on time and would like to deliver your project faster. The following code illustrates this:
VB.NET | |
---|---|
|
C# | |
---|---|
|
The above code will enable lighting and modify the global ambient light to RGB(64, 64, 64). It will also create a light source positioned at (3.0f, 9.0f, 20.0f) with ambient, diffuse, and specular colors set to RGB(64, 64, 64), RGB(255, 255, 255), and RGB(64, 64, 64), respectively. The following example achieves the same effect:
VB.NET | |
---|---|
|
C# | |
---|---|
|
This approach is not recommended unless of course you are trying to produce a lighting configuration that differs from the standard ones because it results in bulky code. We'll continue our discussion with a line-by-line explanation of this code.
1. When you plan to use lighting, the first thing to do is to inform the component. Since lighting is configured on a per-chart basis and Xceed Chart supports an unlimited number of charts, the following code assumes that there is only one chart in the control's chart collection:
VB.NET | |
---|---|
|
C# | |
---|---|
|
2. Sometimes the scene rendered with lighting looks dark. This is why it is recommended to have an ambient global light that makes the objects appear brighter:
VB.NET | |
---|---|
lightModel.GlobalAmbientLight = Color.FromArgb(64, 64, 64) |
C# | |
---|---|
lightModel.GlobalAmbientLight = Color.FromArgb(64, 64, 64); |
Another consideration to keep in mind when you apply ambient light is that it is applied to all scene elements. This is why it is best to apply a color with equal red, green, and blue components.
3. After you configure the global ambient properties, you can modify the light sources of the scene. This is done by adding LightSource objects to the LightSources collection of the LightModel object.
VB.NET | |
---|---|
|
C# | |
---|---|
|
4. To modify the light source light and position, you must touch the Ambient, Diffuse, Specular, and Position properties of the LightSource object:
VB.NET | |
---|---|
|
C# | |
---|---|
|
Note that the Position property is represented as a Vector object.
Related Examples
Windows Forms: Lights\General
See Also
LightSource | LightModel | FillEffect | Vector | Xceed 3D Lighting Model