File: FlyingPiece.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 (98 lines) | stat: -rwxr-xr-x 2,308 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
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#include "FlyingPiece.h"
#include "Game/GlobalUnsynced.h"
#include "Rendering/GlobalRendering.h"
#include "Rendering/GlobalRendering.h"
#include "Rendering/UnitDrawer.h"
#include "Rendering/GL/VertexArray.h"
#include "Rendering/Textures/3DOTextureHandler.h"
#include "Rendering/Textures/S3OTextureHandler.h"
#include "Rendering/Models/3DOParser.h"
#include "Rendering/Models/S3OParser.h"
#include "System/Matrix44f.h"

FlyingPiece::~FlyingPiece() {
	delete[] verts;
}

void FlyingPiece::Init(int _team, const float3& _pos, const float3& _speed)
{
	prim   = NULL;
	object = NULL;
	verts  = NULL;

	pos   = _pos;
	speed = _speed;

	texture = 0;
	team    = _team;

	rotAxis  = gu->usRandVector().ANormalize();
	rotSpeed = gu->usRandFloat() * 0.1f;
	rot = 0;
}

void FlyingPiece::Draw(int modelType, size_t* lastTeam, size_t* lastTex, CVertexArray* va) {

	if (team != *lastTeam) {
		*lastTeam = team;

		va->DrawArrayTN(GL_QUADS); //switch to GL_TRIANGLES?
		va->Initialize();
		unitDrawer->SetTeamColour(team);
	}

	CMatrix44f m;
	m.Rotate(rot, rotAxis);
	float3 tp, tn;

	const float3 interPos = pos + speed * globalRendering->timeOffset;

	switch (modelType) {
		case MODELTYPE_3DO: {
			const C3DOTextureHandler::UnitTexture* tex = prim->texture;

			const std::vector<S3DOVertex>& vertices    = object->vertices;
			const std::vector<int>&        verticesIdx = prim->vertices;

			const float uvCoords[8] = {
				tex->xstart, tex->ystart,
				tex->xend,   tex->ystart,
				tex->xend,   tex->yend,
				tex->xstart, tex->yend
			};

			for (int i = 0; i < 4; i++) {
				const S3DOVertex& v = vertices[verticesIdx[i]];
				tp = m.Mul(v.pos) + interPos;
				tn = m.Mul(v.normal);
				va->AddVertexQTN(tp, uvCoords[i << 1], uvCoords[(i << 1) + 1], tn);
			}
		} break;

		case MODELTYPE_S3O: {
			if (texture != *lastTex) {
				*lastTex = texture;

				if (*lastTex == 0) {
					return;
				}

				va->DrawArrayTN(GL_QUADS);
				va->Initialize();
				texturehandlerS3O->SetS3oTexture(texture);
			}

			for (int i = 0; i < 4; i++) {
				const SS3OVertex& v = verts[i];
				tp = m.Mul(v.pos) + interPos;
				tn = m.Mul(v.normal);
				va->AddVertexQTN(tp, v.textureX, v.textureY, tn);
			}
		} break;

		default: {
		} break;
	}
}