1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
2
3
4 #include "WakeProjectile.h"
5 #include "Game/Camera.h"
6 #include "Game/GlobalUnsynced.h"
7 #include "Rendering/GlobalRendering.h"
8 #include "Rendering/ProjectileDrawer.h"
9 #include "Rendering/Env/IWater.h"
10 #include "Rendering/GL/VertexArray.h"
11 #include "Rendering/Textures/TextureAtlas.h"
12
13 CR_BIND_DERIVED(CWakeProjectile, CProjectile, (NULL, ZeroVector, ZeroVector, 0.0f, 0.0f, 0.0f, 0.0f, 0.0f))
14
15 CR_REG_METADATA(CWakeProjectile,(
16 CR_MEMBER(alpha),
17 CR_MEMBER(alphaFalloff),
18 CR_MEMBER(alphaAdd),
19 CR_MEMBER(alphaAddTime),
20 CR_MEMBER(size),
21 CR_MEMBER(sizeExpansion),
22 CR_MEMBER(rotation),
23 CR_MEMBER(rotSpeed),
24 CR_RESERVED(8)
25 ))
26
27 //////////////////////////////////////////////////////////////////////
28 // Construction/Destruction
29 //////////////////////////////////////////////////////////////////////
30
CWakeProjectile(CUnit * owner,const float3 & pos,const float3 & speed,float startSize,float sizeExpansion,float alpha,float alphaFalloff,float fadeupTime)31 CWakeProjectile::CWakeProjectile(
32 CUnit* owner,
33 const float3& pos,
34 const float3& speed,
35 float startSize,
36 float sizeExpansion,
37 float alpha,
38 float alphaFalloff,
39 float fadeupTime
40 )
41 : CProjectile(pos, speed, owner, false, false, false)
42 , alpha(0.0f)
43 , alphaFalloff(alphaFalloff)
44 , alphaAdd(alpha / fadeupTime)
45 , alphaAddTime((int)fadeupTime)
46 , size(startSize)
47 , sizeExpansion(sizeExpansion)
48 {
49 this->pos.y = 0.0f;
50 this->speed.y = 0.0f;
51 rotation = gu->RandFloat() * PI*2;
52 rotSpeed = (gu->RandFloat() - 0.5f) * PI*2*0.01f;
53 checkCol = false;
54 if (water->BlockWakeProjectiles()) {
55 this->alpha = 0;
56 alphaAddTime = 0;
57 size = 0;
58 }
59 }
60
Update()61 void CWakeProjectile::Update()
62 {
63 pos += speed;
64 rotation += rotSpeed;
65 alpha -= alphaFalloff;
66 size += sizeExpansion;
67 drawRadius = size;
68
69 if (alphaAddTime != 0) {
70 alpha += alphaAdd;
71 --alphaAddTime;
72 } else if (alpha < 0) {
73 alpha = 0;
74 deleteMe = true;
75 }
76 }
77
Draw()78 void CWakeProjectile::Draw()
79 {
80 inArray = true;
81 unsigned char col[4];
82 col[0] = (unsigned char) (255 * alpha);
83 col[1] = (unsigned char) (255 * alpha);
84 col[2] = (unsigned char) (255 * alpha);
85 col[3] = (unsigned char) (255 * alpha)/*-alphaFalloff*globalRendering->timeOffset*/;
86
87 float interSize = size + sizeExpansion * globalRendering->timeOffset;
88 float interRot = rotation + rotSpeed * globalRendering->timeOffset;
89
90 const float3 dir1 = float3(math::cos(interRot), 0, math::sin(interRot)) * interSize;
91 const float3 dir2 = dir1.cross(UpVector);
92
93 #define wt projectileDrawer->waketex
94 va->AddVertexTC(drawPos + dir1 + dir2, wt->xstart, wt->ystart, col);
95 va->AddVertexTC(drawPos + dir1 - dir2, wt->xstart, wt->yend, col);
96 va->AddVertexTC(drawPos - dir1 - dir2, wt->xend, wt->yend, col);
97 va->AddVertexTC(drawPos - dir1 + dir2, wt->xend, wt->ystart, col);
98 #undef wt
99 }
100