1
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */
10
#include "3DOParser.h"
11
#include "S3OParser.h"
12
#include "Rendering/FarTextureHandler.h"
13
#include "Rendering/GL/myGL.h"
14
#include "Sim/Misc/CollisionVolume.h"
15
#include "System/Exceptions.h"
16
#include "System/Util.h"
17
#include "System/LogOutput.h"
20
//////////////////////////////////////////////////////////////////////
24
void S3DModelPiece::DrawStatic() const
27
glTranslatef(offset.x, offset.y, offset.z);
29
for (std::vector<S3DModelPiece*>::const_iterator ci = childs.begin(); ci != childs.end(); ci++) {
36
S3DModelPiece::~S3DModelPiece()
38
glDeleteLists(displist, 1);
43
/******************************************************************************/
44
/******************************************************************************/
49
LocalModel::~LocalModel()
51
// delete the local piece copies
52
for (std::vector<LocalModelPiece*>::iterator pi = pieces.begin(); pi != pieces.end(); pi++) {
60
void LocalModel::SetLODCount(unsigned int count)
63
pieces[0]->SetLODCount(count);
67
void LocalModel::ApplyRawPieceTransform(int piecenum) const
69
pieces[piecenum]->ApplyTransform();
73
float3 LocalModel::GetRawPiecePos(int piecenum) const
75
return pieces[piecenum]->GetPos();
79
CMatrix44f LocalModel::GetRawPieceMatrix(int piecenum) const
81
return pieces[piecenum]->GetMatrix();
87
void LocalModel::GetRawEmitDirPos(int piecenum, float3 &pos, float3 &dir) const
89
pieces[piecenum]->GetEmitDirPos(pos, dir);
93
//Only useful for special pieces used for emit-sfx
94
float3 LocalModel::GetRawPieceDirection(int piecenum) const
96
return pieces[piecenum]->GetDirection();
100
/******************************************************************************/
101
/******************************************************************************/
106
static const float RADTOANG = 180 / PI;
108
void LocalModelPiece::Draw() const
110
if (!visible && childs.size()==0)
115
if (pos.x || pos.y || pos.z) { glTranslatef(pos.x, pos.y, pos.z); }
116
if (rot[1]) { glRotatef(rot[1] * RADTOANG, 0.0f, 1.0f, 0.0f); }
117
if (rot[0]) { glRotatef(rot[0] * RADTOANG, 1.0f, 0.0f, 0.0f); }
118
if (rot[2]) { glRotatef(rot[2] * RADTOANG, 0.0f, 0.0f, 1.0f); }
121
glCallList(displist);
123
for (unsigned int i = 0; i < childs.size(); i++) {
131
void LocalModelPiece::DrawLOD(unsigned int lod) const
133
if (!visible && childs.size()==0)
138
if (pos.x || pos.y || pos.z) { glTranslatef(pos.x, pos.y, pos.z); }
139
if (rot[1]) { glRotatef(rot[1] * RADTOANG, 0.0f, 1.0f, 0.0f); }
140
if (rot[0]) { glRotatef(rot[0] * RADTOANG, 1.0f, 0.0f, 0.0f); }
141
if (rot[2]) { glRotatef(rot[2] * RADTOANG, 0.0f, 0.0f, 1.0f); }
144
glCallList(lodDispLists[lod]);
146
for (unsigned int i = 0; i < childs.size(); i++) {
147
childs[i]->DrawLOD(lod);
154
void LocalModelPiece::ApplyTransform() const
157
parent->ApplyTransform();
160
if (pos.x || pos.y || pos.z) { glTranslatef(pos.x, pos.y, pos.z); }
161
if (rot[1]) { glRotatef(rot[1] * RADTOANG, 0.0f, 1.0f, 0.0f); }
162
if (rot[0]) { glRotatef(rot[0] * RADTOANG, 1.0f, 0.0f, 0.0f); }
163
if (rot[2]) { glRotatef(rot[2] * RADTOANG, 0.0f, 0.0f, 1.0f); }
167
void LocalModelPiece::GetPiecePosIter(CMatrix44f* mat) const
170
parent->GetPiecePosIter(mat);
173
if (pos.x || pos.y || pos.z) { mat->Translate(pos.x, pos.y, pos.z); }
174
if (rot[1]) { mat->RotateY(-rot[1]); }
175
if (rot[0]) { mat->RotateX(-rot[0]); }
176
if (rot[2]) { mat->RotateZ(-rot[2]); }
180
void LocalModelPiece::SetLODCount(unsigned int count)
182
const unsigned int oldCount = lodDispLists.size();
184
lodDispLists.resize(count);
185
for (unsigned int i = oldCount; i < count; i++) {
189
for (unsigned int i = 0; i < childs.size(); i++) {
190
childs[i]->SetLODCount(count);
195
#if defined(USE_GML) && defined(__GNUC__) && (__GNUC__ == 4)
196
// This is supposed to fix some GCC crashbug related to threading
197
// The MOVAPS SSE instruction is otherwise getting misaligned data
198
__attribute__ ((force_align_arg_pointer))
200
float3 LocalModelPiece::GetPos() const
203
GetPiecePosIter(&mat);
205
if (type == MODELTYPE_3DO) {
207
const S3DOPiece* p3 = static_cast<S3DOPiece*>(original);
208
if (p3 && (p3->vertices.size() == 2)) {
209
const std::vector<S3DOVertex>& pv = p3->vertices;
210
if (pv[0].pos.y > pv[1].pos.y) {
211
mat.Translate(pv[0].pos.x, pv[0].pos.y, -pv[0].pos.z);
213
mat.Translate(pv[1].pos.x, pv[1].pos.y, -pv[1].pos.z);
218
// we use a 'right' vector, and the positive x axis points to the left
219
float3 pos = mat.GetPos();
225
CMatrix44f LocalModelPiece::GetMatrix() const
228
GetPiecePosIter(&mat);
234
float3 LocalModelPiece::GetDirection() const
236
const S3DModelPiece* piece = original;
237
const unsigned int count = piece->GetVertexCount();
239
return float3(1.0f, 1.0f, 1.0f);
241
return (piece->GetVertexPos(0) - piece->GetVertexPos(1));
245
bool LocalModelPiece::GetEmitDirPos(float3 &pos, float3 &dir) const
248
GetPiecePosIter(&mat);
250
const S3DModelPiece* piece = original;
255
const unsigned int count = piece->GetVertexCount();
259
dir = mat.Mul(float3(0.0f, 0.0f, 1.0f)) - pos;
260
} else if (count == 1) {
262
dir = mat.Mul(piece->GetVertexPos(0)) - pos;
263
} else if (count >= 2) {
264
float3 p1 = mat.Mul(piece->GetVertexPos(0));
265
float3 p2 = mat.Mul(piece->GetVertexPos(1));
273
// we use a 'right' vector, and the positive x axis points to the left
280
/******************************************************************************/
281
/******************************************************************************/