Chapter 8
������� ���������� ��������

8.2  ���������� �������

     ��� ���������� ������� ��� ����������� ���������� �������-����������� �������: �����, ����, �����, ������. ����� ��� ����� ��� ��, ��� � � ���������� ������, �� ����������� ����, ��� ��������� ���������� ����� ������� ������� � �������� �����������, ��� � ����������. ����� � � �������� ����������� �������� ��������� �������: ���� - ���� ���������� ������� �� � ��������� XZ, ����� - ���� ����� �������� �� � ���������� XZ � ������ �������� ������ - ����� �������.

     ������� �����, ������ ����� ��������� ����� ����, � ������� �����, ���� - ����� �����. ��������������, ����� ����� ������������ �� �����. ������ �� �������� �� �����. ��� ��������� ��������� ����� ��� ����������� ��������� ��������� ��������:

  • �������� �������� ���������� �����
  • ������������� �� � ��������
  • � �������� ����������� �������� �������������� ����
  • ������������� ���������� �� �������� � ����������
  • ���������� ����� ��������� �����

     �� ������ �� ������� ��������� � ����� ����������� �����, ������������� �� ����� �� ����� "���������". �������� ����� ������ � ���������� � ���� ���� lamps.c. �������� �������-����������� � �������������� �������������� ������� ������� main.

    auxKeyFunc(AUX_LEFT, Key_LEFT);
    auxKeyFunc(AUX_RIGHT, Key_RIGHT);
    auxKeyFunc(AUX_UP, Key_UP);
    auxKeyFunc(AUX_DOWN, Key_DOWN);
��� ������� Key_LEFT ����� ���������:
void CALLBACK Key_LEFT(void)
{
float nor[4];
float pol[3];

  // �������� ������� ���������� �����
  glGetLightfv(GL_LIGHT3, GL_POSITION, nor);
  // ������������ �� � ��������
  Normal2Polar(nor[0], nor[1], nor[2], pol);
  // ��������� ���� ���� �� �������� ������
  pol[1] -= delta;
  // ������������ ������� � ���������� ����������
  Polar2Normal(pol[0], pol[1], pol[2], nor);
  // ������������� ����� ��������� �����
  glLightfv(GL_LIGHT3, GL_POSITION, nor);
}
����� ��������� ������������ ������ �������� ��� ���������:
#define M_PI        3.14159265358979323846

float delta=0.1;
������� �������� �� ����� ������� ��������� � ������:
void Polar2Normal(float a, float b, float r, float nor[3])
{
nor[0] = r*cos(a)*cos(b);
nor[1] = r*sin(a);
nor[2] = -r*cos(a)*sin(b);
}

void Normal2Polar(float x, float y, float z, float pol[3]) 
{
pol[2] = sqrt(x*x+y*y+z*z);
pol[0] = asin(y/pol[2]);
pol[1] = acos(x/sqrt(x*x+z*z));
if(z>0)
 pol[1] = 2*M_PI - pol[1];
}