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
|
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
#include "FlyingPiece.h"
#include "Game/GlobalUnsynced.h"
#include "Map/Ground.h"
#include "Map/MapInfo.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"
SS3OFlyingPiece::~SS3OFlyingPiece() {
delete[] chunk;
}
bool FlyingPiece::Update() {
pos += speed;
speed *= 0.996f;
speed.y += mapInfo->map.gravity; // fp's are not projectiles
rotAngle += rotSpeed;
transMat.LoadIdentity();
transMat.Rotate(rotAngle, rotAxis);
return (pos.y >= CGround::GetApproximateHeight(pos.x, pos.z - 10.0f, false));
}
void FlyingPiece::InitCommon(const float3& _pos, const float3& _speed, int _team)
{
pos = _pos;
speed = _speed;
texture = 0;
team = _team;
rotAxis = gu->RandVector().ANormalize();
rotSpeed = gu->RandFloat() * 0.1f;
rotAngle = 0.0f;
}
void FlyingPiece::DrawCommon(size_t* lastTeam, CVertexArray* va) {
if (team != *lastTeam) {
*lastTeam = team;
va->DrawArrayTN(GL_QUADS); //switch to GL_TRIANGLES?
va = GetVertexArray();
va->Initialize();
unitDrawer->SetTeamColour(team);
}
}
void S3DOFlyingPiece::Draw(size_t* lastTeam, size_t* lastTex, CVertexArray* va) {
DrawCommon(lastTeam, va);
const float3& interPos = pos + speed * globalRendering->timeOffset;
const C3DOTextureHandler::UnitTexture* tex = chunk->texture;
const std::vector<S3DOVertex>& vertices = piece->vertices;
const std::vector<int>& indices = chunk->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[indices[i]];
const float3 tp = transMat.Mul(v.pos) + interPos;
const float3 tn = transMat.Mul(v.normal);
va->AddVertexQTN(tp, uvCoords[i << 1], uvCoords[(i << 1) + 1], tn);
}
}
void SS3OFlyingPiece::Draw(size_t* lastTeam, size_t* lastTex, CVertexArray* va) {
DrawCommon(lastTeam, va);
const float3& interPos = pos + speed * globalRendering->timeOffset;
if (texture != *lastTex) {
*lastTex = texture;
if (*lastTex == 0) {
return;
}
va->DrawArrayTN(GL_QUADS);
va = GetVertexArray();
va->Initialize();
texturehandlerS3O->SetS3oTexture(texture);
}
for (int i = 0; i < 4; i++) {
const SS3OVertex& v = chunk[i];
const float3 tp = transMat.Mul(v.pos) + interPos;
const float3 tn = transMat.Mul(v.normal);
va->AddVertexQTN(tp, v.texCoord.x, v.texCoord.y, tn);
}
}
|