Newer
Older
cg / sources / light.cpp
@glproj03 glproj03 on 28 Jan 2006 1 KB kei plan was geendert isch
#include "light.h"

#include <GL/gl.h>
#include <GL/glu.h>

Light::Light(Vec* _pos, Vec* _dir, GLenum _lightnum) {
  pos = _pos;
  dir = _dir;
  lightnum = _lightnum;
  enabled=true;
  set();
}

Light::Light() {
  Vec _dir = new Vec(0.0f, 0.0f, 0.0f);
  Vec _pos = new Vec(20.0f, 20.0f, 20.0f);
  printf("fuckoff");
}

void Light::trace() {
	glBegin (GL_LINES);
	glVertex3fv(pos->getCoords());
	glVertex3fv(dir->getCoords());
	glEnd();
}

void Light::draw() {
	float p [4] = {pos->x(), pos->y(), pos->z(), 1.0f};
	float d [4] = {dir->x(), dir->y(), dir->z(), 1.0f};
	glLightf(lightnum, GL_SPOT_CUTOFF, 180.0f);
	glLightfv(lightnum, GL_POSITION, p);
	glLightfv(lightnum, GL_SPOT_DIRECTION, d);
}

void Light::set() {
  if (enabled) {
	glEnable(lightnum);
	printf("%d on\n", lightnum);
  } else {
	glDisable(lightnum);
	printf("%d off\n", lightnum);
  }
}

void Light::flip() {
  if (enabled)
	enabled = false;
  else
	enabled = true;
  set();
}

DiffuseLight::DiffuseLight(Vec* _pos, Color* _color, GLenum _lightnum) {  
  pos = _pos;
  col = _color;
  lightnum = _lightnum;
  set();
}

void DiffuseLight::draw() {
	float p [4] = {pos->x(), pos->y(), pos->z(), 1.0f};
	float c [4] = {col->r, col->g, col->b, 1.0f};
	glLightfv(lightnum, GL_DIFFUSE, c);
	glLightfv(lightnum, GL_POSITION, p);
}

void DiffuseLight::trace() {
  glBegin(GL_POINTS);
  glVertex3fv(pos->getCoords());
  glEnd();
}