Next: , Previous: , Up: Graphics setup   [Contents][Index]


5.2.2 Lighting

There are several functions for setup lighting. The general function is light which switch on/off the lighting for overall plot. It influence only for graphics which created after light call (with one exception, OpenGL). Generally MathGL support up to 10 independent light sources. But in OpenGL mode only 8 of light sources is used due to OpenGL limitations. The position, color, brightness of each light source can be set separately. By default only one light source is active. It is source number 0 with white color, located at top of the plot. See Lighting sample, for sample code and picture.

MGL command: light [val=on]
Method on mglGraph: bool Light (bool enable)
C function: void mgl_set_light (HMGL gr, int enable)

Sets the using of light on/off for overall plot. Function returns previous value of lighting. Default value is lightning off.

MGL command: light num val
Method on mglGraph: void Light (int n, bool enable)
C function: void mgl_set_light_n (HMGL gr, int n, int enable)

Switch on/off n-th light source separately.

MGL command: light num xdir ydir zdir ['col'='w' br=0.5]
MGL command: light num xdir ydir zdir xpos ypos zpos ['col'='w' br=0.5 ap=0]
Method on mglGraph: void AddLight (int n, mglPoint d, char c='w', mreal bright=0.5, mreal ap=0)
Method on mglGraph: void AddLight (int n, mglPoint r, mglPoint d, char c='w', mreal bright=0.5, mreal ap=0)
C function: void mgl_add_light (HMGL gr, int n, mreal dx, mreal dy, mreal dz)
C function: void mgl_add_light_ext (HMGL gr, int n, mreal dx, mreal dy, mreal dz, char c, mreal bright, mreal ap)
C function: void mgl_add_light_loc (HMGL gr, int n, mreal rx, mreal ry, mreal rz, mreal dx, mreal dy, mreal dz, char c, mreal bright, mreal ap)

The function adds a light source with identification n in direction d with color c and with brightness bright (which must be in range [0,1]). If position r is specified and isn’t NAN then light source is supposed to be local otherwise light source is supposed to be placed at infinity.

MGL command: diffuse val
Method on mglGraph: void SetDiffuse (mreal bright)
C function: void mgl_set_difbr (HMGL gr, mreal bright)

Set brightness of diffusive light (only for local light sources).

MGL command: ambient val
Method on mglGraph: void SetAmbient (mreal bright=0.5)
C function: void mgl_set_ambbr (HMGL gr, mreal bright)

Sets the brightness of ambient light. The value should be in range [0,1].

MGL command: attachlight val
Method on mglGraph: void AttachLight (bool val)
C function: void mgl_set_attach_light (HMGL gr, int val)

Set to attach light settings to inplot/subplot. Note, OpenGL and some output formats don’t support this feature.


Next: , Previous: , Up: Graphics setup   [Contents][Index]