File: DirtProjectile.cpp

package info (click to toggle)
spring 88.0%2Bdfsg1-1.1
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 41,524 kB
  • sloc: cpp: 343,114; ansic: 38,414; python: 12,257; java: 12,203; awk: 5,748; sh: 1,204; xml: 997; perl: 405; objc: 192; makefile: 181; php: 134; sed: 2
file content (101 lines) | stat: -rwxr-xr-x 2,963 bytes parent folder | download
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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#include "System/mmgr.h"

#include "DirtProjectile.h"
#include "Game/Camera.h"
#include "Game/GlobalUnsynced.h"
#include "Map/Ground.h"
#include "Rendering/GlobalRendering.h"
#include "Rendering/ProjectileDrawer.h"
#include "Rendering/GL/VertexArray.h"
#include "Rendering/Textures/TextureAtlas.h"

CR_BIND_DERIVED(CDirtProjectile, CProjectile, );

CR_REG_METADATA(CDirtProjectile,
(
	CR_MEMBER_BEGINFLAG(CM_Config),
		CR_MEMBER(alpha),
		CR_MEMBER(alphaFalloff),
		CR_MEMBER(size),
		CR_MEMBER(sizeExpansion),
		CR_MEMBER(slowdown),
		CR_MEMBER(color),
		CR_MEMBER(texture),
	CR_MEMBER_ENDFLAG(CM_Config),
	CR_RESERVED(8)
));

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CDirtProjectile::CDirtProjectile(const float3& pos, const float3& speed, const float ttl, const float size, const float expansion, float slowdown, CUnit* owner, const float3& color):
	CProjectile(pos, speed, owner, false, false, false),
	alpha(255),
	size(size),
	sizeExpansion(expansion),
	slowdown(slowdown),
	color(color)
{
	checkCol = false;
	alphaFalloff = 255 / ttl;
	texture = projectileDrawer->randdotstex;
}

CDirtProjectile::CDirtProjectile() :
	CProjectile(),
	alpha(255.0f),
	alphaFalloff(10.0f),
	size(10.0f),
	sizeExpansion(0.0f),
	slowdown(1.0f)
{
	checkCol = false;
	texture = projectileDrawer->randdotstex;
}

CDirtProjectile::~CDirtProjectile()
{}

void CDirtProjectile::Update()
{
	speed *= slowdown;
	speed.y += mygravity;
	pos += speed;
	alpha -= alphaFalloff;
	size += sizeExpansion;

	if (ground->GetApproximateHeight(pos.x, pos.z, false) - 40 > pos.y) {
		deleteMe = true;
	}
	if (alpha <= 0) {
		deleteMe = true;
		alpha = 0;
	}
}

void CDirtProjectile::Draw()
{
	float partAbove = (pos.y / (size * camera->up.y));
	if (partAbove < -1) {
		return;
	} else if (partAbove > 1) {
		partAbove = 1;
	}
	inArray = true;
	unsigned char col[4];
	col[0] = (unsigned char) (color.x * alpha);
	col[1] = (unsigned char) (color.y * alpha);
	col[2] = (unsigned char) (color.z * alpha);
	col[3] = (unsigned char) (alpha)/*- (globalRendering->timeOffset * alphaFalloff)*/;

	const float interSize = size + globalRendering->timeOffset * sizeExpansion;
	const float texx = texture->xstart + (texture->xend - texture->xstart) * ((1.0f - partAbove) * 0.5f);

	va->AddVertexTC(drawPos - camera->right * interSize - camera->up * interSize * partAbove, texx,          texture->ystart, col);
	va->AddVertexTC(drawPos + camera->right * interSize - camera->up * interSize * partAbove, texx,          texture->yend,   col);
	va->AddVertexTC(drawPos + camera->right * interSize + camera->up * interSize,             texture->xend, texture->yend,   col);
	va->AddVertexTC(drawPos - camera->right * interSize + camera->up * interSize,             texture->xend, texture->ystart, col);
}