; VertexNormal Example ; -------------------- ; A vertex normal is the direction a vertex 'faces' for lighting. ; VertexNormal sets it by hand. The panel below never moves - only ; its normals swing - yet the changing brightness makes it look as ; if it were tilting into and out of the light. Graphics3D 640,480 SetBuffer BackBuffer() camera=CreateCamera() PositionEntity camera,0,0,-4 ; Directional light shining into the scene (along +z) light=CreateLight() panel=CreateMesh() surf=CreateSurface(panel) ; A simple quad facing the camera v0=AddVertex(surf,-1.5,1.5,0) v1=AddVertex(surf,1.5,1.5,0) v2=AddVertex(surf,1.5,-1.5,0) v3=AddVertex(surf,-1.5,-1.5,0) AddTriangle surf,v0,v1,v2 AddTriangle surf,v0,v2,v3 EntityColor panel,190,190,255 angle#=0 While Not KeyDown(1) ; [ and ] swing the normals left and right If KeyDown(26) And angle>-80 Then angle=angle-2 If KeyDown(27) And angle<80 Then angle=angle+2 ; Point every vertex normal the same way - the documented command. ; Straight at the camera (0,0,-1) is brightest; swung away is dark. nx#=Sin(angle) nz#=-Cos(angle) VertexNormal surf,v0,nx,0,nz VertexNormal surf,v1,nx,0,nz VertexNormal surf,v2,nx,0,nz VertexNormal surf,v3,nx,0,nz ; Arrow keys move the camera If KeyDown(200) Then MoveEntity camera,0,0,0.1 If KeyDown(208) Then MoveEntity camera,0,0,-0.1 If KeyDown(203) Then TurnEntity camera,0,1,0 If KeyDown(205) Then TurnEntity camera,0,-1,0 RenderWorld Text 0,0,"[ / ] : swing the normals Arrow keys: move camera Esc: exit" Text 0,20,"VertexNormal surf,v,"+nx+",0,"+nz Text 0,40,"The quad never moves - only its lighting changes" Flip Wend End