File: GeoSquareProjectile.cpp

package info (click to toggle)
spring 106.0%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 55,316 kB
  • sloc: cpp: 543,954; ansic: 44,800; python: 12,575; java: 12,201; awk: 5,889; sh: 1,796; asm: 1,546; xml: 655; perl: 405; php: 211; objc: 194; makefile: 76; sed: 2
file content (84 lines) | stat: -rw-r--r-- 2,448 bytes parent folder | download | duplicates (3)
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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */


#include "Game/Camera.h"
#include "GeoSquareProjectile.h"
#include "Rendering/Env/Particles/ProjectileDrawer.h"
#include "Rendering/GL/RenderDataBuffer.hpp"
#include "Rendering/Textures/TextureAtlas.h"


CR_BIND_DERIVED(CGeoSquareProjectile, CProjectile, )

CR_REG_METADATA(CGeoSquareProjectile,(
	CR_MEMBER(p1),
	CR_MEMBER(p2),
	CR_MEMBER(v1),
	CR_MEMBER(v2),
	CR_MEMBER(xsize),
	CR_MEMBER(ysize),
	CR_MEMBER(r),
	CR_MEMBER(g),
	CR_MEMBER(b),
	CR_MEMBER(a)
))


CGeoSquareProjectile::CGeoSquareProjectile(const float3& p1, const float3& p2, const float3& v1, const float3& v2, float xsize, float ysize)
	: CProjectile((p1 + p2) * 0.5f, ZeroVector, nullptr, false, false, false),
	p1(p1),
	p2(p2),
	v1(v1),
	v2(v2),
	xsize(xsize),
	ysize(ysize),
	r(0.5f),
	g(1.0f),
	b(0.5f),
	a(0.5f)
{
	checkCol = false;
	alwaysVisible = true;

	SetRadiusAndHeight(p1.distance(p2) * 0.55f, 0.0f);
}


void CGeoSquareProjectile::Draw(GL::RenderDataBufferTC* va) const
{
	unsigned char col[4];
	col[0] = (unsigned char) (r * a * 255);
	col[1] = (unsigned char) (g * a * 255);
	col[2] = (unsigned char) (b * a * 255);
	col[3] = (unsigned char) (    a * 255);

	float3 dif  = (p1 - camera->GetPos()).ANormalize();
	float3 dif2 = (p2 - camera->GetPos()).ANormalize();

	const float3 xdir = (dif.cross(v1)).ANormalize();
	const float3 ydir = (dif2.cross(v2)).ANormalize();


	const float u   = (projectileDrawer->geosquaretex->xstart + projectileDrawer->geosquaretex->xend) * 0.5f;
	const float v0s = projectileDrawer->geosquaretex->ystart;
	const float v0e = projectileDrawer->geosquaretex->yend;

	if (ysize != 0) {
		va->SafeAppend({p1 - xdir * xsize, u, v0e, col});
		va->SafeAppend({p1 + xdir * xsize, u, v0s, col});
		va->SafeAppend({p2 + ydir * ysize, u, v0s, col});

		va->SafeAppend({p2 + ydir * ysize, u, v0s, col});
		va->SafeAppend({p2 - ydir * ysize, u, v0e, col});
		va->SafeAppend({p1 - xdir * xsize, u, v0e, col});
	} else {
		va->SafeAppend({p1 - xdir * xsize, u, v0e,                      col});
		va->SafeAppend({p1 + xdir * xsize, u, v0s,                      col});
		va->SafeAppend({p2,                u, v0s + (v0e - v0s) * 0.5f, col});

		va->SafeAppend({p2,                u, v0s + (v0e - v0s) * 0.5f, col});
		va->SafeAppend({p2,                u, v0s + (v0e - v0s) * 1.5f, col});
		va->SafeAppend({p1 - xdir * xsize, u, v0e,                      col});
	}
}