I want to know how to set the property of light object, such as direction and location. and I wrote the routine below:
BUT the spotlight(type 3) didn't work,and the other lights's effects are also confused to me,because I find when i rotate the volume, the surface did'n't always be lightted the same direction.
you run the routine below,it has been compiled!
PRO Chapter08SurfaceTrack_EVENT, sEvent
WIDGET_CONTROL, sEvent.id, GET_UVALUE=uval
IF TAG_NAMES(sEvent,/STRUCTURE_NAME) EQ $
'WIDGET_KILL_REQUEST' THEN BEGIN
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState
OBJ_DESTROY, sState.oView & OBJ_DESTROY, sState.oTrack
WIDGET_CONTROL, sEvent.top, /DESTROY
RETURN
ENDIF
CASE uval OF
'DRAW': BEGIN
WIDGET_CONTROL, sEvent.top, GET_UVALUE=sState, /NO_COPY
IF (sEvent.type EQ 4) THEN BEGIN
;d_objworld2SceneAntiAlias,sstate.owindow,sstate.oview,3
sState.oWindow->Draw, sState.oView
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
RETURN
ENDIF
bHaveTransform = sState.oTrack->Update(sEvent, TRANSFORM=qmat)
IF (bHaveTransform NE 0) THEN BEGIN
sState.oGroup->GetProperty, TRANSFORM=t
sState.oGroup->SetProperty, TRANSFORM=t#qmat
;d_objworld2SceneAntiAlias,sstate.owindow,sstate.oview,8
sState.oWindow->Draw, sState.oView
ENDIF
IF (sEvent.type EQ 0) THEN BEGIN
;d_objworld2SceneAntiAlias,sstate.owindow,sstate.oview,8
WIDGET_CONTROL, sState.wDraw, /DRAW_MOTION
ENDIF
IF (sEvent.type EQ 1) THEN BEGIN
;d_objworld2SceneAntiAlias,sstate.owindow,sstate.oview,8
WIDGET_CONTROL, sState.wDraw, DRAW_MOTION=0
ENDIF
WIDGET_CONTROL, sEvent.top, SET_UVALUE=sState, /NO_COPY
END
ENDCASE
END
PRO Chapter08SurfaceTrack
xdim = 800 & ydim = 800
file=filepath('mucai.jpg',subdirectory=['examples','data'])
image=read_image(file)
oimage=obj_new('idlgrimage',image,interleave=0)
wBase = WIDGET_BASE(/COLUMN, XPAD=0, YPAD=0, $
TITLE="Surface Trackball Example", /TLB_KILL_REQUEST_EVENTS)
wDraw = WIDGET_DRAW(wBase, XSIZE=xdim, YSIZE=ydim, UVALUE='DRAW', $ RETAIN=0, /EXPOSE_EVENTS, /BUTTON_EVENTS, GRAPHICS_LEVEL=2)
wGuiBase1 = WIDGET_BASE(wBase, /COLUMN)
tLabel = WIDGET_LABEL(wGuiBase1, /FRAME, XSIZE=790, /ALIGN_CENTER, $
VALUE="Left Mouse: Trackball" )
WIDGET_CONTROL, wBase, /REALIZE
WIDGET_CONTROL, wDraw, GET_VALUE=oWindow
oView = OBJ_NEW('IDLgrView', PROJECTION=2, EYE=5, ZCLIP=[2,-2],$
VIEWPLANE_RECT=[-3,-3,6,6], COLOR=[40,40,40])
oTop = OBJ_NEW('IDLgrModel')
oGroup = OBJ_NEW('IDLgrModel')
oTop->Add, oGroup
verts=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1]]
texture=verts[0:1,*]
;normalized
texture[0,*]=0.5+0.5*texture[0,*]
texture[1,*]=0.5+0.5*texture[1,*]
obottompoly=obj_new('idlgrpolygon',verts,color=[255,255,255],style=2)
obottompoly->setproperty,texture_coord=texture,texture_map=oimage,alpha_channel=1
verts=[[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]]
texture=verts[0:1,*]
;normalized
texture[0,*]=0.5+0.5*texture[0,*]
texture[1,*]=0.5+0.5*texture[1,*]
ouppoly=obj_new('idlgrpolygon',verts,color=[255,255,255],style=2)
ouppoly->SetProperty,texture_coord=texture,texture_map=oimage,alpha_channel=1,hidden_lines=1
verts=[[-1,-1,-1],[1,-1,-1],[1,1,-1],[-1,1,-1],[-1,-1,1],[1,-1,1],[1,1,1],[-1,1,1]]
connect =[4,0,1,5,4, $
4,1,2,6,5, $
4,2,3,7,6, $
4,3,0,4,7 ]
texture=[[0,0], [1,0], [0,0], [1,0],[0,1], [1,1], [0,1], [1,1]]
osurroundpoly=obj_new('idlgrpolygon',verts,poly=connect,color=[255,255,255],style=2)
osurroundpoly->SetProperty,texture_coord=texture,texture_map=oimage,alpha_channel=1
oGroup->Add,osurroundpoly
oGroup->Add,obottompoly
oGroup->Add,ouppoly
olight1=obj_new('idlgrlight',type=1,intensity=1,location=[1,1,1],hide=0)
otop->Add,olight1
oLight2 = OBJ_NEW('IDLgrLight', TYPE=0, INTENSITY=0.0,color=[255,255,255],hide=0)
oTop->Add, oLight2
olight3=obj_new('idlgrlight',type=2,intensity=1,location=[0,0,200],hide=1)
otop->Add,olight3
olight4=obj_new('idlgrlight',type=3,coneangle=1,intensity=1,direction=[-1,-1,1])
otop->Add,olight4
oView->Add, oTop
oGroup->Rotate, [1,0,0], -90
oGroup->Rotate, [0,1,0], 30
oGroup->Rotate, [1,0,0], 30
oTrack = OBJ_NEW('Trackball', [xdim/2, ydim/2.], xdim/2.)
sState = {btndown: 0b, oTrack:oTrack, wDraw: wDraw, oWindow: oWindow,$
oView: oView, oGroup: oGroup }
WIDGET_CONTROL, wBase, SET_UVALUE=sState, /NO_COPY
XMANAGER, 'Chapter08SurfaceTrack', wBase, /NO_BLOCK
END
|