1// tLight.cpp 
2// 
3// This file implements scene lights. It supports point, spot, directional, and ambient lights. 
4// 
5// Copyright (c) 2006, 2017 Tristan Grimmer. 
6// Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby 
7// granted, provided that the above copyright notice and this permission notice appear in all copies. 
8// 
9// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL 
10// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, 
11// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN 
12// AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 
13// PERFORMANCE OF THIS SOFTWARE. 
14 
15#include "Scene/tLight.h" 
16namespace tScene 
17{ 
18 
19 
20void tLight::Clear() 
21{ 
22 tObject::Clear(); 
23 Type = tType::Point; 
24 AttenNearStart = 0.0f; 
25 AttenNearEnd = 0.0f; 
26 AttenFarStart = 0.0f; 
27 AttenFarEnd = 0.0f; 
28} 
29 
30 
31void tLight::Save(tChunkWriter& chunk) const 
32{ 
33 chunk.Begin(tChunkID::Scene_Light); 
34 { 
35 tObject::Save(chunk); 
36 
37 chunk.Begin(tChunkID::Scene_LightType); 
38 { 
39 chunk.Write(Type); 
40 } 
41 chunk.End(); 
42 
43 chunk.Begin(tChunkID::Scene_LightParameters); 
44 { 
45 chunk.Write(AttenNearStart); 
46 chunk.Write(AttenNearEnd); 
47 chunk.Write(AttenFarStart); 
48 chunk.Write(AttenFarEnd); 
49 } 
50 chunk.End(); 
51 } 
52 chunk.End(); 
53} 
54 
55 
56void tLight::Load(const tChunk& lightChunk) 
57{ 
58 tAssert(lightChunk.ID() == tChunkID::Scene_Light); 
59 Clear(); 
60 
61 for (tChunk chunk = lightChunk.First(); chunk.Valid(); chunk = chunk.Next()) 
62 { 
63 switch (chunk.ID()) 
64 { 
65 case tChunkID::Scene_Object: 
66 tObject::Load(chunk); 
67 break; 
68 
69 case tChunkID::Scene_LightType: 
70 chunk.GetItem(Type); 
71 break; 
72 
73 case tChunkID::Scene_LightParameters: 
74 chunk.GetItem(AttenNearStart); 
75 chunk.GetItem(AttenNearEnd); 
76 chunk.GetItem(AttenFarStart); 
77 chunk.GetItem(AttenFarEnd); 
78 break; 
79 } 
80 } 
81} 
82 
83 
84} 
85