Advertisement
Guest User

Untitled

a guest
Oct 31st, 2014
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.69 KB | None | 0 0
  1. #pragma once
  2. #include <GL/glut.h>
  3. #include "Vector3.h"
  4.  
  5. class Spotlight
  6. {
  7. public:
  8. Spotlight(GLenum light);
  9. ~Spotlight();
  10. void update(GLfloat angle, Vector3 position, bool isEnabled);
  11.  
  12.  
  13. private:
  14. GLenum m_light;
  15. GLfloat cutoffAngle[1];
  16. GLfloat lightCharacterisitcs[4];
  17. };
  18.  
  19. Spotlight::Spotlight(GLenum light)
  20. {
  21. m_light = light;
  22.  
  23. cutoffAngle[0] = 45.0f;
  24. lightCharacterisitcs[0] = 1.0f;
  25. lightCharacterisitcs[1] = 1.0f;
  26. lightCharacterisitcs[2] = 1.0f;
  27. lightCharacterisitcs[3] = 1.0f;
  28.  
  29. GLfloat lightAmb1[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
  30.  
  31. glLightfv(m_light, GL_AMBIENT, lightAmb1);
  32. glLightfv(m_light, GL_SPECULAR, lightCharacterisitcs);
  33. }
  34.  
  35.  
  36. Spotlight::~Spotlight()
  37. {
  38. }
  39.  
  40.  
  41. void Spotlight::update(GLfloat angle, Vector3 position, bool isEnabled)
  42. {
  43. if (!isEnabled)
  44. {
  45. glDisable(m_light);
  46. return;
  47. }
  48.  
  49. cutoffAngle[0] = angle;
  50. GLfloat spotlight[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
  51. GLfloat nosePos[4] = { position.X(), position.Y(), position.Z(), 1.0f };
  52. GLfloat spotDirection[3] = { -1, -1, 0 };
  53.  
  54. glLightfv(m_light, GL_DIFFUSE, lightCharacterisitcs);
  55. glLightfv(m_light, GL_POSITION, nosePos);
  56. glLightfv(m_light, GL_SPOT_DIRECTION, spotDirection);
  57. glLightfv(m_light, GL_SPOT_CUTOFF, cutoffAngle);
  58.  
  59. glEnable(m_light);
  60. }
  61.  
  62. //Examples
  63.  
  64. //cutOffAngle ++ or -- depending on keyboard input
  65.  
  66. void renderScene()
  67. {
  68. [...]
  69. //glPushMatrix + Transformations for helicopter
  70. helicopter->drawHelicopter(mainRotorAngle, rearRotorAngle);
  71. spotlight->update(cutoffAngle, helicopter->getNoseMiddle(), showSpotlight);
  72. //glPopMatrix
  73. [...]
  74.  
  75. }
  76.  
  77. int main(int argc, char** argv)
  78. {
  79. [...]
  80. spotlight = new Spotlight(GL_LIGHT1);
  81. [...]
  82. glutIdleFunc(renderScene);
  83. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement