/* -*- Objc -*- */ /* * $Id: Light.m,v 1.1 2003/09/12 20:39:43 ano Exp $ * * Copyright (C) 2003 Free Software Foundation, Inc. * * This file is part of GNU Hégémonie. * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * as published by the Free Software Foundation; either version 2 * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ #include "Light.h" #include "ColorAlpha.h" @implementation Light - (void) dealloc { [super dealloc]; } - (id) init { self = [super init]; _type = DIRECTIONNEL; _ambientColor = white; _specularColor = white; _diffusColor = white; _position = MakeCoord(0.0,180.0,0.0); _direction = MakeCoord(0.0,-1.0,0.0); _exponent = 0; _cutOff = 1; _constantAttenuation = 1.0; _linearAttenuation = 0.0; _quadraticAttenuation = 0.0; _shininess = 0.0; return self; } - (id) initWithPosition: (coord_t)pos { self = [super init]; _type = DIRECTIONNEL; _ambientColor = white; _specularColor = white; _diffusColor = white; _position = pos; _direction = MakeCoord(0.0,-1.0,0.0); _exponent = 0; _cutOff = 180; _constantAttenuation = 1.0; _linearAttenuation = 0.0; _quadraticAttenuation = 0.0; _shininess = 0.0; return self; } - (id) initWithLight: (id)light { NSParameterAssert(light); self = [super init]; _type = [light typeLight]; _ambientColor = [light colorForComposante: AMBIENT]; _specularColor = [light colorForComposante: SPECULAR]; _diffusColor = [light colorForComposante: DIFFUS]; _position = [light position]; _direction = [light direction]; _exponent = [light exponent]; _cutOff = [light cutOff]; _constantAttenuation = [light attenuationForType: CONSTANTE]; _linearAttenuation = [light attenuationForType: LINEAR]; _quadraticAttenuation = [light attenuationForType: QUADRATIC]; _shininess = [light shininess]; return self; } - (void) setTypeLight: (int)type { if (type == DIRECTIONNEL || type == PONCTUEL) _type = type; } - (void) setColor: (color_alpha_t)color forComposante: (int)composante { switch(composante) { case AMBIENT: _ambientColor = color; break; case SPECULAR: _specularColor = color; break; case DIFFUS: _diffusColor = color; break; default: printf("pas une composante\n"); break; } } - (void) setExponent: (double)exponent { if (exponent >= 0 && exponent <= 128) _exponent = exponent; } - (void) setCutOff: (double)cutOff { if ((cutOff >= 0 && cutOff <= 90) || (cutOff == 180)) _cutOff = cutOff; } - (void) setShininess: (double) shininess { _shininess = shininess; } - (void) setAttenuation: (double) attenuation forType: (int)type { switch(type) { case CONSTANTE: _constantAttenuation = attenuation; break; case LINEAR: _linearAttenuation = attenuation; break; case QUADRATIC: _quadraticAttenuation = attenuation; break; default: printf("pas une attenuation valide\n"); break; } } - (int) typeLight { return _type; } - (color_alpha_t) colorForComposante: (int)composante { switch(composante) { case AMBIENT: return _ambientColor; break; case SPECULAR: return _specularColor; break; case DIFFUS: return _diffusColor; break; } return black; } - (coord_t) position { return _position; } - (coord_t) direction { return _direction; } - (double) exponent { return _exponent; } - (double) cutOff { return _cutOff; } - (double) shininess { return _shininess; } - (double) attenuationForType: (int)type { switch(type) { case CONSTANTE: return _constantAttenuation; break; case LINEAR: return _linearAttenuation; break; case QUADRATIC: return _quadraticAttenuation; break; } return -1.0; } - (void) moveTo: (coord_t)position { _position = position; } - (void) move: (coord_t)step { _position = AddCoord(_position,step); } - (void) setDirection: (coord_t)dir { _direction = dir; } @end /*Light*/