-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_cSpaceBackground.cpp
252 lines (208 loc) · 8.39 KB
/
04_cSpaceBackground.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
///////////////////////////////////////////////////////
//*-------------------------------------------------*//
//| Part of Project One (https://www.maus-games.at) |//
//*-------------------------------------------------*//
//| Copyright (c) 2010 Martin Mauersics |//
//| Released under the zlib License |//
//*-------------------------------------------------*//
///////////////////////////////////////////////////////
#include "main.h"
// ****************************************************************
// constructor
cSpaceBackground::cSpaceBackground()noexcept
: cBackground (false)
, m_vCoverDir (coreVector2(0.0f,1.0f))
, m_fCoverScale (1.0f)
, m_fMeteorSpeed (1.0f)
, m_iCopyLower (0u)
, m_iCopyUpper (0u)
, m_vNebulaMove (coreVector2(0.0f,0.0f))
{
coreBatchList* pList1;
//
this->__InitOwn();
//
m_pOutdoor = new cOutdoor();
m_pOutdoor->SetEnabled(CORE_OBJECT_ENABLE_NOTHING);
// allocate meteor list
pList1 = new coreBatchList(SPACE_METEOR_RESERVE);
pList1->DefineProgram("object_ground_inst_program");
{
coreBool bBlack = false;
// load object resources
coreObject3D oBase;
oBase.DefineModel ("environment_stone_01.md3");
oBase.DefineTexture(0u, "environment_stone_diff.png");
oBase.DefineTexture(1u, "environment_stone_norm.png");
oBase.DefineProgram("object_ground_program");
for(coreUintW i = 0u; i < SPACE_METEOR_NUM; ++i)
{
// calculate position and height
const coreVector2 vPosition = __BACKGROUND_SCANLINE(Core::Rand->Float(-0.45f, 0.45f), i, SPACE_METEOR_NUM);
const coreFloat fHeight = Core::Rand->Float(-30.0f, -5.0f); // # shadow issues below -30.0f
if(!cBackground::_CheckIntersectionQuick3(pList1, coreVector3(vPosition, fHeight), POW2(11.5f)))
{
// create object
coreObject3D* pObject = POOLED_NEW(s_MemoryPool, coreObject3D, oBase);
// set object properties
pObject->SetPosition (coreVector3(vPosition, fHeight));
pObject->SetSize (coreVector3::Rand(0.85f,1.3f, 0.85f,1.3f, 0.85f,1.3f) * Core::Rand->Float(2.0f, 2.6f) * 2.1f);
pObject->SetDirection (coreVector3::Rand());
pObject->SetOrientation(coreVector3::Rand());
pObject->SetColor3 (coreVector3(1.0f,1.0f,1.0f) * Core::Rand->Float(0.85f, 1.0f) * (bBlack ? 0.5f : 1.0f));
// add object to the list
pList1->BindObject(pObject);
//
bBlack = !bBlack;
}
}
//
m_iCopyUpper = pList1->GetSize();
// post-process list and add to the ground
cBackground::_FillInfinite(pList1, SPACE_METEOR_RESERVE);
m_apGroundObjectList.push_back(pList1);
//
m_iCopyLower = pList1->GetSize() - m_iCopyUpper;
//
m_pOutdoor->GetShadowMap()->BindList(pList1);
}
//
m_Cover.DefineTexture(0u, "environment_space_inside.png");
m_Cover.DefineProgram("menu_grey_vignette_program");
m_Cover.SetPosition (coreVector2(0.0f,0.0f));
m_Cover.SetColor3 (LERP(COLOR_MENU_MAGENTA, coreVector3(1.0f,1.0f,1.0f), 0.35f) * 1.3f);
//
m_Cover2.DefineTexture(0u, "environment_space_outside.png");
m_Cover2.DefineProgram("menu_single_program");
m_Cover2.SetPosition (coreVector2(0.0f,0.0f));
m_Cover2.SetColor3 (LERP(COLOR_MENU_MAGENTA, coreVector3(1.0f,1.0f,1.0f), 0.15f) * 1.3f);
m_Cover2.SetAlpha (0.7f);
m_Cover2.SetTexSize (coreVector2(1.0f,1.0f) * 4.2f);
//
m_Nebula.DefineTexture(0u, "environment_clouds_low.png");
m_Nebula.DefineProgram("effect_weather_nebula_program");
m_Nebula.SetPosition (coreVector2(0.0f,0.0f));
m_Nebula.SetAlpha (0.2f);
}
// ****************************************************************
// destructor
cSpaceBackground::~cSpaceBackground()
{
//
this->__ExitOwn();
}
// ****************************************************************
//
void cSpaceBackground::__InitOwn()
{
// load base sound-effect
m_pBaseSound = Core::Manager::Resource->Get<coreSound>("environment_space.wav");
m_pBaseSound.OnUsableOnce([this, pResource = m_pBaseSound]()
{
pResource->PlayRelative(this, 0.0f, 1.0f, true, SOUND_AMBIENT);
});
}
// ****************************************************************
//
void cSpaceBackground::__ExitOwn()
{
// stop base sound-effect
m_pBaseSound.OnUsableOnce([this, pResource = m_pBaseSound]()
{
if(pResource->EnableRef(this))
pResource->Stop();
});
}
// ****************************************************************
//
void cSpaceBackground::__RenderOwnBefore()
{
glDepthMask(false);
{
glDisable(GL_BLEND);
{
//
m_Cover.Render();
}
glEnable(GL_BLEND);
//
m_Cover2.Render();
}
glDepthMask(true);
}
// ****************************************************************
//
void cSpaceBackground::__RenderOwnAfter()
{
// enable the shader-program
if(!m_Nebula.GetProgram().IsUsable()) return;
if(!m_Nebula.GetProgram()->Enable()) return;
coreRand oRand(1u);
//
coreProgram* pLocal = m_Nebula.GetProgram().GetResource();
for(coreUintW i = 0u; i < SPACE_NEBULA_NUM; ++i)
{
const coreVector2 vNewTexOffset = m_Nebula.GetTexOffset() + coreVector2::Rand(0.0f,1.0f, 0.0f,1.0f, &oRand);
const coreFloat fNewScale = 0.3f - 0.045f * I_TO_F(i);
pLocal->SendUniform(s_asOverlayTransform[i], coreVector3(vNewTexOffset.Processed(FRACT), fNewScale));
}
glDisable(GL_DEPTH_TEST);
{
//
m_Nebula.Render();
}
glEnable(GL_DEPTH_TEST);
}
// ****************************************************************
//
void cSpaceBackground::__MoveOwn()
{
//
const coreMatrix3 amRota[] = {coreMatrix4::RotationY(TIME * -0.7f * m_fMeteorSpeed).m123(),
coreMatrix4::RotationY(TIME * -0.6f * m_fMeteorSpeed).m123(),
coreMatrix4::RotationY(TIME * -0.5f * m_fMeteorSpeed).m123()};
//
coreBatchList* pList = m_apGroundObjectList[0];
for(coreUintW i = 0u, ie = LOOP_NONZERO(pList->GetSize()); i < ie; ++i)
{
coreObject3D* pMeteor = (*pList->List())[i];
if((i >= m_iCopyLower) && (i < m_iCopyUpper) && !pMeteor->IsEnabled(CORE_OBJECT_ENABLE_ALL)) continue; // # all
//
const coreMatrix3& mRota = amRota[(i % m_iCopyUpper) % ARRAY_SIZE(amRota)];
//
pMeteor->SetDirection ((pMeteor->GetDirection () * mRota).Normalized());
pMeteor->SetOrientation((pMeteor->GetOrientation() * mRota).Normalized());
}
pList->MoveNormal();
//
const coreVector2 vEnvMove = coreVector2(0.0f,1.0f) * (-0.35f * g_pEnvironment->GetSpeed());
const coreVector2 vSize = coreVector2(1.0f,1.0f) * SQRT2 * ENVIRONMENT_SCALE_FACTOR * m_fCoverScale;
const coreVector2 vTexOffset = m_Cover .GetTexOffset() + (coreVector2(0.0f,0.0f) + vEnvMove) * (0.05f * TIME);
const coreVector2 vTexOffset2 = m_Cover2.GetTexOffset() + (coreVector2(0.0f,0.0f) + vEnvMove) * (0.28f * TIME);
//
m_Cover.SetSize (vSize);
m_Cover.SetDirection(MapToAxis(g_pEnvironment->GetDirection().InvertedX(), m_vCoverDir));
m_Cover.SetTexOffset(vTexOffset.Processed(FRACT));
m_Cover.Move();
//
m_Cover2.SetSize (vSize);
m_Cover2.SetDirection(m_Cover.GetDirection());
m_Cover2.SetTexOffset(vTexOffset2.Processed(FRACT));
m_Cover2.Move();
//
const coreVector2 vEnvMove2 = coreVector2(0.0f,1.0f) * (-0.15f * g_pEnvironment->GetSpeed());
const coreVector2 vTexSize = coreVector2(1.0f,1.0f) * 5.4f;
const coreVector2 vTexOffset3 = m_Nebula.GetTexOffset() + (m_vNebulaMove.InvertedX() + vEnvMove2) * (0.5f * TIME);
//
m_Nebula.SetSize (vSize);
m_Nebula.SetDirection(MapToAxis(g_pEnvironment->GetDirection().InvertedX(), m_vCoverDir));
m_Nebula.SetColor3 (m_Cover.GetColor3().LowRatio());
m_Nebula.SetTexSize (vTexSize);
m_Nebula.SetTexOffset(vTexOffset3.Processed(FRACT));
m_Nebula.Move();
// adjust volume of the base sound-effect
if(m_pBaseSound.IsUsable() && m_pBaseSound->EnableRef(this))
{
m_pBaseSound->SetVolume(g_pEnvironment->RetrieveTransitionBlend(this));
}
}