Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include <GL/glut.h>
- #include "Vector3.h"
- class Spotlight
- {
- public:
- Spotlight(GLenum light);
- ~Spotlight();
- void update(GLfloat angle, Vector3 position, bool isEnabled);
- private:
- GLenum m_light;
- GLfloat cutoffAngle[1];
- GLfloat lightCharacterisitcs[4];
- };
- Spotlight::Spotlight(GLenum light)
- {
- m_light = light;
- cutoffAngle[0] = 45.0f;
- lightCharacterisitcs[0] = 1.0f;
- lightCharacterisitcs[1] = 1.0f;
- lightCharacterisitcs[2] = 1.0f;
- lightCharacterisitcs[3] = 1.0f;
- GLfloat lightAmb1[4] = { 0.0f, 0.0f, 0.0f, 1.0f };
- glLightfv(m_light, GL_AMBIENT, lightAmb1);
- glLightfv(m_light, GL_SPECULAR, lightCharacterisitcs);
- }
- Spotlight::~Spotlight()
- {
- }
- void Spotlight::update(GLfloat angle, Vector3 position, bool isEnabled)
- {
- if (!isEnabled)
- {
- glDisable(m_light);
- return;
- }
- cutoffAngle[0] = angle;
- GLfloat spotlight[4] = { 1.0f, 1.0f, 1.0f, 1.0f };
- GLfloat nosePos[4] = { position.X(), position.Y(), position.Z(), 1.0f };
- GLfloat spotDirection[3] = { -1, -1, 0 };
- glLightfv(m_light, GL_DIFFUSE, lightCharacterisitcs);
- glLightfv(m_light, GL_POSITION, nosePos);
- glLightfv(m_light, GL_SPOT_DIRECTION, spotDirection);
- glLightfv(m_light, GL_SPOT_CUTOFF, cutoffAngle);
- glEnable(m_light);
- }
- //Examples
- //cutOffAngle ++ or -- depending on keyboard input
- void renderScene()
- {
- [...]
- //glPushMatrix + Transformations for helicopter
- helicopter->drawHelicopter(mainRotorAngle, rearRotorAngle);
- spotlight->update(cutoffAngle, helicopter->getNoseMiddle(), showSpotlight);
- //glPopMatrix
- [...]
- }
- int main(int argc, char** argv)
- {
- [...]
- spotlight = new Spotlight(GL_LIGHT1);
- [...]
- glutIdleFunc(renderScene);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement