absence_thelab

diff src/3deng/lights.cpp @ 0:1cffe3409164

initial commit
author John Tsiombikas <nuclear@member.fsf.org>
date Thu, 23 Oct 2014 01:46:07 +0300
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/3deng/lights.cpp	Thu Oct 23 01:46:07 2014 +0300
     1.3 @@ -0,0 +1,586 @@
     1.4 +#include "lights.h"
     1.5 +#include <cmath>
     1.6 +
     1.7 +Light::Light() {
     1.8 +	intensity = 1.0f;
     1.9 +	ambient_color = 0.0f;
    1.10 +	diffuse_color = specular_color = 1.0f;
    1.11 +	CastShadows = false;
    1.12 +}
    1.13 +
    1.14 +void Light::SetIntensity(float intensity) {
    1.15 +	this->intensity = intensity;
    1.16 +}
    1.17 +
    1.18 +float Light::GetIntensity() const {
    1.19 +	return intensity;
    1.20 +}
    1.21 +
    1.22 +void Light::SetColor(const Color &color, PhongComponent comp) {
    1.23 +	if(comp == (PhongComponent)-1) {
    1.24 +        diffuse_color = specular_color = color;
    1.25 +	} else {
    1.26 +		switch(comp) {
    1.27 +		case Ambient:
    1.28 +			ambient_color = color;
    1.29 +			break;
    1.30 +		case Diffuse:
    1.31 +			diffuse_color = color;
    1.32 +			break;
    1.33 +		case Specular:
    1.34 +			specular_color = color;
    1.35 +			break;
    1.36 +		}
    1.37 +	}
    1.38 +}
    1.39 +
    1.40 +const Color &Light::GetColor(PhongComponent comp) const {
    1.41 +	switch(comp) {
    1.42 +	case Ambient:
    1.43 +		return ambient_color;
    1.44 +	case Diffuse:
    1.45 +		return diffuse_color;
    1.46 +	case Specular:
    1.47 +		return specular_color;
    1.48 +	}
    1.49 +}
    1.50 +
    1.51 +void Light::SetShadowCasting(bool enable) {
    1.52 +	CastShadows = enable;
    1.53 +}
    1.54 +
    1.55 +bool Light::GetShadowCasting() const {
    1.56 +	return CastShadows;
    1.57 +}
    1.58 +
    1.59 +////////// Directional Light ///////////
    1.60 +
    1.61 +// Non-Applicable functions for this type of light
    1.62 +void DirLight::SetPosition(const Vector3 &pos) {}
    1.63 +void DirLight::SetRange(float range) {}
    1.64 +void DirLight::SetAttenuation(float att0, float att1, float att2) {}
    1.65 +Vector3 DirLight::GetPosition() const {return Direction;}
    1.66 +float DirLight::GetRange() const {return 0.0f;}
    1.67 +float DirLight::GetAttenuation(int degree) const {return 0.0f;}
    1.68 +void DirLight::ResetTransform() {}
    1.69 +void DirLight::ResetTranslation() {}
    1.70 +void DirLight::ResetRotation() {}
    1.71 +void DirLight::Transform(const Matrix4x4 &matrix) {}
    1.72 +void DirLight::Translate(float x, float y, float z) {}
    1.73 +void DirLight::Rotate(float x, float y, float z) {}
    1.74 +void DirLight::Rotate(const Vector3 &axis, float angle) {}
    1.75 +void DirLight::SetCone(float InnerCone, float OuterCone) {}
    1.76 +float DirLight::GetInnerCone() const {return 0.0f;}
    1.77 +float DirLight::GetOuterCone() const {return 0.0f;}
    1.78 +void DirLight::SetFalloff(float falloff) {}
    1.79 +float DirLight::GetFalloff() const {return 0.0f;}
    1.80 +void DirLight::ResetTargetTransform() {}
    1.81 +void DirLight::ResetTargetTranslation() {}
    1.82 +void DirLight::ResetTargetRotation() {}
    1.83 +void DirLight::TargetTransform(const Matrix4x4 &matrix) {}
    1.84 +void DirLight::TargetTranslate(float x, float y, float z) {}
    1.85 +void DirLight::TargetRotate(float x, float y, float z) {}
    1.86 +void DirLight::TargetRotate(const Vector3 &axis, float angle) {}
    1.87 +
    1.88 +
    1.89 +
    1.90 +DirLight::DirLight() {
    1.91 +	Direction = Vector3(0, -1, 0);
    1.92 +}
    1.93 +
    1.94 +DirLight::DirLight(const Vector3 &dir) {
    1.95 +	Direction = dir;
    1.96 +}
    1.97 +
    1.98 +
    1.99 +void DirLight::SetDirection(const Vector3 &dir) {
   1.100 +	Direction = dir;
   1.101 +}
   1.102 +
   1.103 +Vector3 DirLight::GetDirection() const {
   1.104 +	Vector3 dir = Direction;
   1.105 +	dir.Transform(DirRot);
   1.106 +	return dir;
   1.107 +}
   1.108 +
   1.109 +LightType DirLight::GetType() const {
   1.110 +	return LTDir;
   1.111 +}
   1.112 +
   1.113 +// direction transformations
   1.114 +void DirLight::ResetDirTransform() {
   1.115 +	DirRot.ResetIdentity();
   1.116 +}
   1.117 +
   1.118 +void DirLight::ResetDirRotation() {
   1.119 +	DirRot.ResetIdentity();
   1.120 +}
   1.121 +
   1.122 +void DirLight::TransformDir(const Matrix4x4 &matrix) {
   1.123 +	DirRot *= matrix;
   1.124 +}
   1.125 +
   1.126 +void DirLight::RotateDir(float x, float y, float z) {
   1.127 +	DirRot.Rotate(x, y, z);
   1.128 +}
   1.129 +
   1.130 +void DirLight::RotateDir(const Vector3 &axis, float angle) {
   1.131 +	DirRot.Rotate(axis, angle);
   1.132 +}
   1.133 +
   1.134 +
   1.135 +void DirLight::SetLight(dword index, GraphicsContext *gc) const {
   1.136 +
   1.137 +	Vector3 dir = Direction;
   1.138 +	dir.Transform(DirRot);
   1.139 +
   1.140 +	D3DLIGHT8 light;
   1.141 +	memset(&light, 0, sizeof(D3DLIGHT8));
   1.142 +	light.Ambient.r = ambient_color.r * intensity;
   1.143 +	light.Diffuse.r = diffuse_color.r * intensity;
   1.144 +	light.Specular.r = specular_color.r * intensity;
   1.145 +	light.Ambient.g = ambient_color.g * intensity;
   1.146 +	light.Diffuse.g = diffuse_color.g * intensity;
   1.147 +	light.Specular.g = specular_color.g * intensity;
   1.148 +	light.Ambient.b = ambient_color.b * intensity;
   1.149 +	light.Diffuse.b = diffuse_color.b * intensity;
   1.150 +	light.Specular.b = specular_color.b * intensity;
   1.151 +	light.Direction = dir;
   1.152 +	light.Type = (D3DLIGHTTYPE)LTDir;
   1.153 +	
   1.154 +	gc->D3DDevice->SetLight(index, &light);
   1.155 +	gc->D3DDevice->LightEnable(index, true);
   1.156 +}
   1.157 +
   1.158 +Vertex DirLightVisVertices[] = {
   1.159 +	Vertex(Vector3(0.0f, 0.0f, 0.1f), 0.0f, 0.0f, 0x00ff0000),
   1.160 +	Vertex(Vector3(0.03f, 0.03f, 0.0f), 0.0f, 0.0f, 0x000000ff),
   1.161 +	Vertex(Vector3(-0.03f, 0.03f, 0.0f), 0.0f, 0.0f, 0x000000ff),
   1.162 +	Vertex(Vector3(0.0f, -0.03f, 0.0f), 0.0f, 0.0f, 0x000000ff)
   1.163 +};
   1.164 +
   1.165 +Index DirLightVisIndices[] = {
   1.166 +	0, 1, 2,
   1.167 +	0, 2, 3,
   1.168 +	0, 3, 1,
   1.169 +	1, 3, 2
   1.170 +};
   1.171 +
   1.172 +
   1.173 +void DirLight::Draw(GraphicsContext *gc, float size) {
   1.174 +	
   1.175 +	Material mat(0.9f, 0.8f, 0.3f);
   1.176 +	gc->SetMaterial(mat);
   1.177 +	gc->SetTexture(0, 0);
   1.178 +	gc->SetColorVertex(true);
   1.179 +	gc->SetLighting(false);
   1.180 +	gc->SetZBuffering(false);
   1.181 +
   1.182 +	Matrix4x4 WorldMat = (Matrix4x4)Base(Direction).CreateRotationMatrix() * DirRot;
   1.183 +	gc->SetWorldMatrix(WorldMat);
   1.184 +
   1.185 +	Matrix4x4 ViewMat = gc->GetViewMatrix();
   1.186 +	Matrix4x4 AugViewMat;
   1.187 +
   1.188 +	for(int i=0; i<4; i++) {
   1.189 +        AugViewMat.SetRowVector(ViewMat.GetRowVector(i).Normalized(), i);
   1.190 +	}
   1.191 +
   1.192 +	gc->SetViewMatrix(AugViewMat);
   1.193 +
   1.194 +	gc->Draw(DirLightVisVertices, DirLightVisIndices, 4, 12);
   1.195 +
   1.196 +	gc->SetViewMatrix(ViewMat);
   1.197 +
   1.198 +	gc->SetZBuffering(true);
   1.199 +	gc->SetLighting(true);
   1.200 +	gc->SetColorVertex(false);
   1.201 +
   1.202 +}
   1.203 +
   1.204 +/////////// Point Light //////////////
   1.205 +
   1.206 +// Non-Applicable member functions
   1.207 +void PointLight::SetDirection(const Vector3 &dir) {}
   1.208 +Vector3 PointLight::GetDirection() const {return Position;}
   1.209 +void PointLight::ResetDirTransform() {}
   1.210 +void PointLight::ResetDirRotation() {}
   1.211 +void PointLight::TransformDir(const Matrix4x4 &matrix) {}
   1.212 +void PointLight::RotateDir(float x, float y, float z) {}
   1.213 +void PointLight::RotateDir(const Vector3 &axis, float angle) {}
   1.214 +void PointLight::SetCone(float InnerCone, float OuterCone) {}
   1.215 +float PointLight::GetInnerCone() const {return 0.0f;}
   1.216 +float PointLight::GetOuterCone() const {return 0.0f;}
   1.217 +void PointLight::SetFalloff(float falloff) {}
   1.218 +float PointLight::GetFalloff() const {return 0.0f;}
   1.219 +void PointLight::ResetTargetTransform() {}
   1.220 +void PointLight::ResetTargetTranslation() {}
   1.221 +void PointLight::ResetTargetRotation() {}
   1.222 +void PointLight::TargetTransform(const Matrix4x4 &matrix) {}
   1.223 +void PointLight::TargetTranslate(float x, float y, float z) {}
   1.224 +void PointLight::TargetRotate(float x, float y, float z) {}
   1.225 +void PointLight::TargetRotate(const Vector3 &axis, float angle) {}
   1.226 +
   1.227 +
   1.228 +
   1.229 +PointLight::PointLight() {
   1.230 +	Position = Vector3(0, 100, 0);
   1.231 +	Range = 300.0f;
   1.232 +	Attenuation[0] = 1.0f;
   1.233 +	Attenuation[1] = 0.0f;
   1.234 +	Attenuation[2] = 0.0f;
   1.235 +}
   1.236 +
   1.237 +PointLight::PointLight(const Vector3 &pos, float range, float att0, float att1, float att2) {
   1.238 +	Position = pos;
   1.239 +	Range = range;
   1.240 +	Attenuation[0] = att0;
   1.241 +	Attenuation[1] = att1;
   1.242 +	Attenuation[2] = att2;
   1.243 +}
   1.244 +
   1.245 +Matrix4x4 PointLight::GetTransform() const {
   1.246 +	return PosXForm * PosRot * PosTrans;
   1.247 +}
   1.248 +
   1.249 +void PointLight::SetPosition(const Vector3 &pos) {
   1.250 +	Position = pos;
   1.251 +}
   1.252 +
   1.253 +void PointLight::SetRange(float range) {
   1.254 +	Range = range;
   1.255 +}
   1.256 +
   1.257 +void PointLight::SetAttenuation(float att0, float att1, float att2) {
   1.258 +	Attenuation[0] = att0;
   1.259 +	Attenuation[1] = att1;
   1.260 +	Attenuation[2] = att2;
   1.261 +}
   1.262 +
   1.263 +Vector3 PointLight::GetPosition() const {
   1.264 +	Vector3 pos = Position;
   1.265 +	pos.Transform(GetTransform());
   1.266 +	return pos;
   1.267 +}
   1.268 +
   1.269 +float PointLight::GetRange() const {
   1.270 +	return Range;
   1.271 +}
   1.272 +
   1.273 +float PointLight::GetAttenuation(int degree) const {
   1.274 +	return Attenuation[degree];
   1.275 +}
   1.276 +
   1.277 +LightType PointLight::GetType() const {
   1.278 +	return LTPoint;
   1.279 +}
   1.280 +
   1.281 +// position transformations
   1.282 +void PointLight::ResetTransform() {
   1.283 +	PosRot.ResetIdentity();
   1.284 +	PosTrans.ResetIdentity();
   1.285 +	PosXForm.ResetIdentity();
   1.286 +}
   1.287 +
   1.288 +void PointLight::ResetTranslation() {
   1.289 +	PosTrans.ResetIdentity();
   1.290 +}
   1.291 +
   1.292 +void PointLight::ResetRotation() {
   1.293 +	PosRot.ResetIdentity();
   1.294 +}
   1.295 +
   1.296 +void PointLight::Transform(const Matrix4x4 &matrix) {
   1.297 +	PosXForm *= matrix;
   1.298 +}
   1.299 +
   1.300 +void PointLight::Translate(float x, float y, float z) {
   1.301 +	PosTrans.Translate(x, y, z);
   1.302 +}
   1.303 +
   1.304 +void PointLight::Rotate(float x, float y, float z) {
   1.305 +	PosRot.Rotate(x, y, z);
   1.306 +}
   1.307 +
   1.308 +void PointLight::Rotate(const Vector3 &axis, float angle) {
   1.309 +	PosRot.Rotate(axis, angle);
   1.310 +}
   1.311 +
   1.312 +
   1.313 +void PointLight::SetLight(dword index, GraphicsContext *gc) const {
   1.314 +
   1.315 +	Vector3 pos = Position;
   1.316 +	pos.Transform(GetTransform());
   1.317 +
   1.318 +	D3DLIGHT8 light;
   1.319 +	memset(&light, 0, sizeof(D3DLIGHT8));
   1.320 +	light.Ambient.r = ambient_color.r * intensity;
   1.321 +	light.Diffuse.r = diffuse_color.r * intensity;
   1.322 +	light.Specular.r = specular_color.r * intensity;
   1.323 +	light.Ambient.g = ambient_color.g * intensity;
   1.324 +	light.Diffuse.g = diffuse_color.g * intensity;
   1.325 +	light.Specular.g = specular_color.g * intensity;
   1.326 +	light.Ambient.b = ambient_color.b * intensity;
   1.327 +	light.Diffuse.b = diffuse_color.b * intensity;
   1.328 +	light.Specular.b = specular_color.b * intensity;
   1.329 +	light.Position = pos;
   1.330 +	light.Range = Range;
   1.331 +	light.Attenuation0 = Attenuation[0];
   1.332 +	light.Attenuation1 = Attenuation[1];
   1.333 +	light.Attenuation2 = Attenuation[2];
   1.334 +	light.Type = (D3DLIGHTTYPE)LTPoint;
   1.335 +
   1.336 +	gc->D3DDevice->SetLight(index, &light);
   1.337 +	gc->D3DDevice->LightEnable(index, true);
   1.338 +}
   1.339 +
   1.340 +
   1.341 +
   1.342 +Index PointLightVisIndices[] = {0, 2, 1, 0, 3, 2};
   1.343 +
   1.344 +void PointLight::Draw(GraphicsContext *gc, float size) {
   1.345 +
   1.346 +	dword color = (diffuse_color * intensity).GetPacked32();
   1.347 +
   1.348 +	float PtHalfSz = size / 2.0f;
   1.349 +	Vertex PointLightVisVertices[] = {
   1.350 +		Vertex(Vector3(-PtHalfSz, PtHalfSz, 0.0f), 0.0f, 0.0f, color),
   1.351 +		Vertex(Vector3(PtHalfSz, PtHalfSz, 0.0f), 1.0f, 0.0f, color),
   1.352 +		Vertex(Vector3(PtHalfSz, -PtHalfSz, 0.0f), 1.0f, 1.0f, color),
   1.353 +		Vertex(Vector3(-PtHalfSz, -PtHalfSz, 0.0f), 0.0f, 1.0f, color)
   1.354 +	};
   1.355 +
   1.356 +	Texture *tex = gc->texman->LoadTexture("STOCKTEX_BLOB");
   1.357 +	gc->SetTexture(0, tex);
   1.358 +	gc->SetTextureStageColor(0, TexBlendModulate, TexArgTexture, TexArgCurrent);
   1.359 +	gc->SetTexture(1, 0);
   1.360 +	
   1.361 +	gc->SetAlphaBlending(true);
   1.362 +	gc->SetBlendFunc(BLEND_ONE, BLEND_ONE);
   1.363 +	
   1.364 +	gc->SetColorVertex(true);
   1.365 +	gc->SetLighting(false);
   1.366 +
   1.367 +	Matrix4x4 InvPos;
   1.368 +	InvPos.Translate(Position.x, Position.y, Position.z);
   1.369 +	gc->SetWorldMatrix(InvPos * GetTransform());
   1.370 +
   1.371 +	gc->SetZWrite(false);
   1.372 +	gc->SetBillboarding(true);
   1.373 +	gc->Draw(PointLightVisVertices, PointLightVisIndices, 4, 6);
   1.374 +	gc->SetBillboarding(false);
   1.375 +	gc->SetZWrite(true);
   1.376 +
   1.377 +	gc->SetAlphaBlending(false);	
   1.378 +	gc->SetLighting(true);
   1.379 +	gc->SetColorVertex(false);
   1.380 +	gc->SetTexture(0, 0);
   1.381 +}
   1.382 +
   1.383 +
   1.384 +////////////// Spot Light ////////////////
   1.385 +void SpotLight::ResetTargetTransform() {}
   1.386 +void SpotLight::ResetTargetTranslation() {}
   1.387 +void SpotLight::ResetTargetRotation() {}
   1.388 +void SpotLight::TargetTransform(const Matrix4x4 &matrix) {}
   1.389 +void SpotLight::TargetTranslate(float x, float y, float z) {}
   1.390 +void SpotLight::TargetRotate(float x, float y, float z) {}
   1.391 +void SpotLight::TargetRotate(const Vector3 &axis, float angle) {}
   1.392 +
   1.393 +SpotLight::SpotLight() {
   1.394 +	Position = Vector3(0, 100, 0);
   1.395 +	Direction = Vector3(0, -1, 0);
   1.396 +	Falloff = 1.0f;
   1.397 +	Phi = QuarterPi;
   1.398 +	Theta = Phi - (Phi / 9.0f);
   1.399 +}
   1.400 +
   1.401 +SpotLight::SpotLight(const Vector3 &pos, const Vector3 &dir, float InnerCone, float OuterCone, float range, float att0, float att1, float att2) {
   1.402 +	Position = pos;
   1.403 +	Direction = dir;
   1.404 +	SetCone(InnerCone, OuterCone);
   1.405 +	Range = range;
   1.406 +	Attenuation[0] = att0;
   1.407 +	Attenuation[1] = att1;
   1.408 +	Attenuation[2] = att2;
   1.409 +	Falloff = 1.0f;
   1.410 +}
   1.411 +
   1.412 +void SpotLight::SetDirection(const Vector3 &dir) {
   1.413 +	Direction = dir;
   1.414 +}
   1.415 +
   1.416 +Vector3 SpotLight::GetDirection() const {
   1.417 +	Vector3 dir = Direction;
   1.418 +	dir.Transform(DirRot);
   1.419 +	return dir;
   1.420 +}
   1.421 +
   1.422 +// direction transformations
   1.423 +void SpotLight::ResetDirTransform() {
   1.424 +	DirRot.ResetIdentity();
   1.425 +}
   1.426 +
   1.427 +void SpotLight::ResetDirRotation() {
   1.428 +	DirRot.ResetIdentity();
   1.429 +}
   1.430 +
   1.431 +void SpotLight::TransformDir(const Matrix4x4 &matrix) {
   1.432 +	DirRot *= matrix;
   1.433 +}
   1.434 +
   1.435 +void SpotLight::RotateDir(float x, float y, float z) {
   1.436 +	DirRot.Rotate(x, y, z);
   1.437 +}
   1.438 +
   1.439 +void SpotLight::RotateDir(const Vector3 &axis, float angle) {
   1.440 +	DirRot.Rotate(axis, angle);
   1.441 +}
   1.442 +
   1.443 +
   1.444 +LightType SpotLight::GetType() const {
   1.445 +	return LTSpot;
   1.446 +}
   1.447 +
   1.448 +void SpotLight::SetCone(float InnerCone, float OuterCone) {
   1.449 +	Theta = InnerCone;
   1.450 +	Phi = OuterCone;
   1.451 +}
   1.452 +
   1.453 +float SpotLight::GetInnerCone() const {
   1.454 +	return Theta;
   1.455 +}
   1.456 +
   1.457 +float SpotLight::GetOuterCone() const {
   1.458 +	return Phi;
   1.459 +}
   1.460 +
   1.461 +void SpotLight::SetFalloff(float falloff) {
   1.462 +	Falloff = falloff;
   1.463 +}
   1.464 +
   1.465 +float SpotLight::GetFalloff() const {
   1.466 +	return Falloff;
   1.467 +}
   1.468 +
   1.469 +
   1.470 +void SpotLight::SetLight(dword index, GraphicsContext *gc) const {
   1.471 +	
   1.472 +	Vector3 pos = Position;
   1.473 +	pos.Transform(GetTransform());
   1.474 +
   1.475 +	Vector3 dir = Direction;
   1.476 +	dir.Transform(DirRot);
   1.477 +
   1.478 +	D3DLIGHT8 light;
   1.479 +	memset(&light, 0, sizeof(D3DLIGHT8));
   1.480 +	light.Ambient.r = ambient_color.r * intensity;
   1.481 +	light.Diffuse.r = diffuse_color.r * intensity;
   1.482 +	light.Specular.r = specular_color.r * intensity;
   1.483 +	light.Ambient.g = ambient_color.g * intensity;
   1.484 +	light.Diffuse.g = diffuse_color.g * intensity;
   1.485 +	light.Specular.g = specular_color.g * intensity;
   1.486 +	light.Ambient.b = ambient_color.b * intensity;
   1.487 +	light.Diffuse.b = diffuse_color.b * intensity;
   1.488 +	light.Specular.b = specular_color.b * intensity;
   1.489 +	light.Position = pos;
   1.490 +	light.Direction = dir;
   1.491 +	light.Range = Range;
   1.492 +	light.Attenuation0 = Attenuation[0];
   1.493 +	light.Attenuation1 = Attenuation[1];
   1.494 +	light.Attenuation2 = Attenuation[2];
   1.495 +	light.Falloff = Falloff;
   1.496 +	light.Theta = Theta;
   1.497 +	light.Phi = Phi;
   1.498 +	light.Type = (D3DLIGHTTYPE)LTSpot;
   1.499 +
   1.500 +	gc->D3DDevice->SetLight(index, &light);
   1.501 +	gc->D3DDevice->LightEnable(index, true);
   1.502 +}
   1.503 +
   1.504 +void SpotLight::Draw(GraphicsContext *gc, float size) {
   1.505 +	PointLight::Draw(gc, size);
   1.506 +}
   1.507 +
   1.508 +//////////////// Target Spot Light ////////////////////
   1.509 +void TargetSpotLight::SetDirection(const Vector3 &dir) {}
   1.510 +Vector3 TargetSpotLight::GetDirection() const {return Vector3();}
   1.511 +void TargetSpotLight::ResetDirTransform() {}
   1.512 +void TargetSpotLight::ResetDirRotation() {}
   1.513 +void TargetSpotLight::TransformDir(const Matrix4x4 &matrix) {}
   1.514 +void TargetSpotLight::RotateDir(float x, float y, float z) {}
   1.515 +void TargetSpotLight::RotateDir(const Vector3 &axis, float angle) {}
   1.516 +
   1.517 +TargetSpotLight::TargetSpotLight() {
   1.518 +	Target = Vector3(0.0f, 0.0f, 0.0f);
   1.519 +}
   1.520 +
   1.521 +TargetSpotLight::TargetSpotLight(const Vector3 &pos, const Vector3 &target, float InnerCone, float OuterCone, float range, float att0, float att1, float att2) {
   1.522 +	Position = pos;
   1.523 +	Target = target;
   1.524 +	SetCone(InnerCone, OuterCone);
   1.525 +	Range = range;
   1.526 +	Attenuation[0] = att0;
   1.527 +	Attenuation[1] = att1;
   1.528 +	Attenuation[2] = att2;
   1.529 +	Falloff = 1.0f;
   1.530 +}
   1.531 +
   1.532 +Matrix4x4 TargetSpotLight::GetTargetTransform() const {
   1.533 +	return TargXForm * TargRot * TargTrans;
   1.534 +}
   1.535 +
   1.536 +void TargetSpotLight::ResetTargetTransform() {
   1.537 +	TargRot.ResetIdentity();
   1.538 +	TargTrans.ResetIdentity();
   1.539 +	TargXForm.ResetIdentity();
   1.540 +}
   1.541 +
   1.542 +void TargetSpotLight::ResetTargetTranslation() {
   1.543 +	TargTrans.ResetIdentity();
   1.544 +}
   1.545 +
   1.546 +void TargetSpotLight::ResetTargetRotation() {
   1.547 +	TargRot.ResetIdentity();
   1.548 +}
   1.549 +
   1.550 +void TargetSpotLight::TargetTransform(const Matrix4x4 &matrix) {
   1.551 +	TargXForm *= matrix;
   1.552 +}
   1.553 +
   1.554 +void TargetSpotLight::TargetTranslate(float x, float y, float z) {
   1.555 +	TargTrans.Translate(x, y, z);
   1.556 +}
   1.557 +
   1.558 +void TargetSpotLight::TargetRotate(float x, float y, float z) {
   1.559 +	TargRot.Rotate(x, y, z);
   1.560 +}
   1.561 +
   1.562 +void TargetSpotLight::TargetRotate(const Vector3 &axis, float angle) {
   1.563 +	TargRot.Rotate(axis, angle);
   1.564 +}
   1.565 +
   1.566 +
   1.567 +void TargetSpotLight::SetLight(dword index, GraphicsContext *gc) const {
   1.568 +	Vector3 targ = Target;
   1.569 +	targ.Transform(GetTargetTransform());
   1.570 +
   1.571 +	Vector3 pos = Position;
   1.572 +	pos.Transform(GetTransform());
   1.573 +
   1.574 +	Vector3 *dir = const_cast<Vector3*>(&Direction);
   1.575 +	*dir = (targ - pos).Normalized();
   1.576 +
   1.577 +	SpotLight::SetLight(index, gc);
   1.578 +}
   1.579 +
   1.580 +void TargetSpotLight::Draw(GraphicsContext *gc, float size) {
   1.581 +	Vector3 targ = Target;
   1.582 +	targ.Transform(GetTargetTransform());
   1.583 +
   1.584 +	Vector3 pos = Position;
   1.585 +	pos.Transform(GetTransform());
   1.586 +
   1.587 +	Direction = (targ - pos).Normalized();
   1.588 +	SpotLight::Draw(gc, size);
   1.589 +}
   1.590 \ No newline at end of file