Skip to main content
gamedev.net
🔒 Locked

lighting

Started by vadim85 Jan 10, 2007 at 2:31 PM 0 replies 350+ views
Original Post
vadim85
vadim85
Hi, I want to render elliptical cylinder with proper lighting. Cylinder is drawn but the light doesn't work properly. I think that the problem with the normals, but I can't find the problem. glShadeModel GL_SMOOTH ' Draw Top Ellipse as a triangle fan glBegin GL_TRIANGLE_FAN glNormal3f 0#, 1#, 0# glVertex3f 0#, fHeight, 0# For I = 0 To l_vslice fAngle = I * (-6.2831853) / l_vslice '360 degree = 6.2831853 radian glVertex3f Cos(fAngle) * hr, fHeight, Sin(fAngle) * vr Next I glEnd ' Draw Bottom Ellipse as a triangle fan glBegin GL_TRIANGLE_FAN glNormal3f 0#, -1#, 0# glVertex3f 0#, 0, 0# For I = 0 To l_vslice fAngle = I * (6.2831853) / l_vslice '360 degree = 6.2831853 radian glVertex3f Cos(fAngle) * hr, 0, Sin(fAngle) * vr Next I glEnd ' Draw a number of sections that will make up the sides as quad strips Dim fCurrMin As Single, fCurrMax As Single Dim ca As Single, sa As Single For I = 0 To l_hslice - 1 fCurrMin = fHeightInc * I fCurrMax = fCurrMin + fHeightInc glBegin GL_QUAD_STRIP For j = 0 To l_vslice fAngle = j * (6.2831853) / l_vslice ca = hr * Cos(fAngle) sa = vr * Sin(fAngle) glNormal3f ca, fHalfHeight, sa glVertex3f ca, fCurrMin, sa glVertex3f ca, fCurrMax, sa Next j glEnd Next I glPopMatrix
Kalidor
Kalidor
Quote:
Original post by vadim85
glNormal3f ca, fHalfHeight, sa
The normals of the sides of the cylinder should be perpendicular to the cylinder's axis. In your case the cylinder is on the y-axis, so you want the y-component of the normal to be 0. You should also normalize them (or enable GL_NORMALIZE).

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.