3143
Example of How to Add Lighting to a Surface Object
This is a continuation of the article ‘Add Axis to a Surface Object Example' . This is to show how to use lighting with a surface object. This code will also demonstrate how to change a gridded surface into a filled surface. A filled surface will add to the lighting effect.
Below is an example of how to continue extending a basic surface object. We are going to add lighting to our surface and change it to a filled surface.
As you can see, in addition to our surface object with axis you just need to change STYLE=1, to STYLE=2 to get your filled surface:
oSurface = obj_new('IDLgrSurface', data, STYLE=2, $
SHADING=1, COLOR = [0, 0, 255], $
XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs)
To get positional lighting into your object, you just need to add this segment of code:
; add positional (TYPE=1) lighting to our surface
oLightModel = OBJ_NEW('IDLgrModel')
oLight = OBJ_NEW('IDLgrLight', TYPE=1, LOCATION=[-1,0.5,0.5])
oLightModel->Add, oLight
oView->Add, oLightModel
Example:
PRO mySurface3
; create data
data = dist(100)
; create your model, your view, and your surface
; make surface, a filled surface
oModel = obj_new('IDLgrModel')
oView = obj_new('IDLgrView')
oSurface = obj_new('IDLgrSurface', data, STYLE=2, $
SHADING=1, COLOR = [0, 0, 255])
; add axis to your surface
oSurface->GetProperty, XRANGE=xr, YRANGE=yr, ZRANGE=zr
; Calculating normalized conversion factors and shifting
; -.5 in every direction
; Keep in mind that your view default coordinate system
; is [-1,-1], [1, 1]
xs = NORM_COORD(xr)
xs[0] = xs[0] - 0.5
ys = NORM_COORD(yr)
ys[0] = ys[0] - 0.5
zs = NORM_COORD(zr)
zs[0] = zs[0] - 0.5
oSurface->SetProperty,XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs
oXaxis = OBJ_NEW('IDLgrAxis', 0, RANGE=xr, $
XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs, $
LOCATION=[0, 0, 0])
oYaxis = OBJ_NEW('IDLgrAxis', 1, RANGE=yr, $
XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs, $
LOCATION=[0, 0, 0])
oZaxis = OBJ_NEW('IDLgrAxis', 2, RANGE=zr, $
XCOORD_CONV=xs, YCOORD_CONV=ys, ZCOORD_CONV=zs, $
LOCATION=[0, yr[1], 0])
; add (TYPE=1) lighting to our surface
oLightModel = OBJ_NEW('IDLgrModel')
oLight = OBJ_NEW('IDLgrLight', TYPE=1, LOCATION=[-1,0.5,0.5])
oLightModel->Add, oLight
oView->Add, oLightModel
; add the surface to the model, and the model to the view
oModel->add, oSurface
oModel->Add, oXaxis
oModel->Add, oYaxis
oModel->Add, oZaxis
oView->Add, oModel
; rotate for better view of your surface
oModel->rotate, [1, 0, 0], -90
oModel->rotate, [0, 1, 0], 30
oModel->rotate, [1, 0, 0], 30
; create a window and draw the view of your Surface object
oWindow = obj_new('IDLgrWindow')
oWindow->Draw, oView
end