[3255] | 1 | // Light.cpp: implementation of the Light class.
|
---|
| 2 | //
|
---|
| 3 | //////////////////////////////////////////////////////////////////////
|
---|
| 4 |
|
---|
| 5 | #include "Light.h"
|
---|
| 6 |
|
---|
| 7 | //////////////////////////////////////////////////////////////////////
|
---|
| 8 | // Construction/Destruction
|
---|
| 9 | //////////////////////////////////////////////////////////////////////
|
---|
| 10 |
|
---|
| 11 | Light::Light()
|
---|
| 12 | {
|
---|
| 13 |
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | Light::~Light()
|
---|
| 17 | {
|
---|
| 18 |
|
---|
| 19 | }
|
---|
| 20 |
|
---|
| 21 | void Light::SetLight(GLenum light)
|
---|
| 22 | {
|
---|
| 23 | //glLightfv(light,GL_AMBIENT,m_Ambient_Color.GetArrayf());
|
---|
| 24 | glLightfv(light,GL_DIFFUSE,m_Diffuse_Color.GetArrayf());
|
---|
| 25 | //glLightfv(light,GL_AMBIENT,m_Diffuse_Color.GetArrayf());
|
---|
| 26 | glLightfv(light,GL_SPECULAR,m_Specular_Color.GetArrayf());
|
---|
| 27 |
|
---|
| 28 | if(this->m_type==LIGHT_TYPE_DIRECTIONAL)
|
---|
| 29 | {
|
---|
| 30 | m_Position.z=0;
|
---|
| 31 | m_Position.x=-1*m_Spot_Direction.x;
|
---|
| 32 | m_Position.y=-1*m_Spot_Direction.y;
|
---|
| 33 | m_Position.z=-1*m_Spot_Direction.z;
|
---|
| 34 | }
|
---|
| 35 | glLightfv(light,GL_POSITION,m_Position.GetArrayf());
|
---|
| 36 |
|
---|
| 37 | if(m_type==LIGHT_TYPE_SPOT)
|
---|
| 38 | {
|
---|
| 39 | glLightfv(light,GL_SPOT_DIRECTION,m_Spot_Direction.GetArrayf());
|
---|
| 40 | glLightf(light,GL_SPOT_EXPONENT,m_Exponent);
|
---|
| 41 | glLightf(light,GL_SPOT_CUTOFF,m_Cutoff);
|
---|
| 42 | }
|
---|
| 43 |
|
---|
| 44 | if(this->m_type==LIGHT_TYPE_POINT)
|
---|
| 45 | {
|
---|
| 46 | m_Cutoff=180;
|
---|
| 47 | glLightf(light,GL_SPOT_CUTOFF,m_Cutoff);
|
---|
| 48 | }
|
---|
| 49 |
|
---|
| 50 | glEnable(light);
|
---|
| 51 | }
|
---|
| 52 |
|
---|
| 53 | void Light::Load(ifstream *file)
|
---|
| 54 | {
|
---|
| 55 | fprintf(stderr, "Loading Light...\n");
|
---|
| 56 |
|
---|
| 57 | char* tempchar=new char[500];
|
---|
| 58 | file->getline(tempchar,500,' ');
|
---|
| 59 | file->getline(tempchar,500,'\n');
|
---|
| 60 | //pointlight
|
---|
| 61 | if(tempchar[0]=='p')
|
---|
| 62 | {
|
---|
| 63 | m_type=0;
|
---|
| 64 | }
|
---|
| 65 | //directionallight
|
---|
| 66 | if(tempchar[0]=='d')
|
---|
| 67 | {
|
---|
| 68 | m_type=1;
|
---|
| 69 | }
|
---|
| 70 | //spotlight
|
---|
| 71 | if(tempchar[0]=='s')
|
---|
| 72 | {
|
---|
| 73 | m_type=2;
|
---|
| 74 | }
|
---|
| 75 |
|
---|
| 76 | file->getline(tempchar,500,'\n');
|
---|
| 77 | sscanf(tempchar,"color %f %f %f",&m_Diffuse_Color.x,&m_Diffuse_Color.y,&m_Diffuse_Color.z);
|
---|
| 78 | m_Specular_Color=m_Diffuse_Color;
|
---|
| 79 |
|
---|
| 80 | switch(m_type)
|
---|
| 81 | {
|
---|
| 82 | case 0:
|
---|
| 83 | file->getline(tempchar,500,'\n');
|
---|
| 84 | sscanf(tempchar,"position %f %f %f",&m_Position.x,&m_Position.y,&m_Position.z);
|
---|
| 85 | m_Position.w=1;
|
---|
| 86 | file->getline(tempchar,500,'\n');
|
---|
| 87 | break;
|
---|
| 88 | case 1:
|
---|
| 89 | file->getline(tempchar,500,'\n');
|
---|
| 90 | sscanf(tempchar,"position %f %f %f",&m_Position.x,&m_Position.y,&m_Position.z);
|
---|
| 91 | m_Position.w=0;
|
---|
| 92 | sscanf(tempchar,"direction %f %f %f",&m_Position.x,&m_Position.y,&m_Position.z);
|
---|
| 93 | break;
|
---|
| 94 | case 2:
|
---|
| 95 | file->getline(tempchar,500,'\n');
|
---|
| 96 | sscanf(tempchar,"position %f %f %f",&m_Position.x,&m_Position.y,&m_Position.z);
|
---|
| 97 | m_Position.w=1;
|
---|
| 98 | sscanf(tempchar,"direction %f %f %f",&m_Spot_Direction.x,&m_Spot_Direction.y,&m_Spot_Direction.z);
|
---|
| 99 | break;
|
---|
| 100 | }
|
---|
| 101 | }
|
---|