Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de
1 | -- NightGlower class |
2 | -- |
3 | -- Copyright (C) GIANTS Software GmbH, Confidential, All Rights Reserved. |
4 | |
5 | NightGlower = {} |
6 | |
7 | local NightGlower_mt = Class(NightGlower); |
8 | |
9 | function NightGlower:onCreate(id) |
10 | g_currentMission:addUpdateable(NightGlower:new(id)); |
11 | end; |
12 | |
13 | function NightGlower:new(id) |
14 | local self = {}; |
15 | setmetatable(self, NightGlower_mt); |
16 | self.id = id; |
17 | self.isSunOn = true; |
18 | self.maxGlow = {1, 6, 3}; |
19 | self.minGlow = {1, 3, 1}; |
20 | self.timer = 0; |
21 | |
22 | setShaderParameter(self.id, "colorTint", 1, 1, 1, 1, false); |
23 | |
24 | g_currentMission.environment:addWeatherChangeListener(self); |
25 | |
26 | return self; |
27 | end; |
28 | |
29 | function NightGlower:delete() |
30 | if g_currentMission.environment ~= nil then |
31 | g_currentMission.environment:removeWeatherChangeListener(self); |
32 | end; |
33 | end; |
34 | |
35 | function NightGlower:update(dt) |
36 | if not self.isSunOn then |
37 | self.timer = (self.timer + dt * 0.001) % (2*math.pi); |
38 | local glowValue = (math.sin(self.timer) + 1) / 2; -- value from 0 to 1 |
39 | local currentGlow = {0, 0, 0}; |
40 | currentGlow[1] = glowValue * self.maxGlow[1] + (1 - glowValue) * self.minGlow[1]; |
41 | currentGlow[2] = glowValue * self.maxGlow[2] + (1 - glowValue) * self.minGlow[2]; |
42 | currentGlow[3] = glowValue * self.maxGlow[3] + (1 - glowValue) * self.minGlow[3]; |
43 | setShaderParameter(self.id, "colorTint", currentGlow[1], currentGlow[2], currentGlow[3], 1, false); |
44 | end; |
45 | end; |
46 | |
47 | function NightGlower:weatherChanged() |
48 | self.isSunOn = g_currentMission.environment.isSunOn; |
49 | if self.isSunOn then |
50 | setShaderParameter(self.id, "colorTint", 1, 1, 1, 1, false); |
51 | end; |
52 | end;
|
Copyright (c) 2008-2015 GIANTS Software GmbH, Confidential, All Rights Reserved.
This document is to be published solely by ls-mods.de