forked from GokuMK/TSRE5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoords.cpp
155 lines (138 loc) · 6.19 KB
/
Coords.cpp
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
/* This file is part of TSRE5.
*
* TSRE5 - train sim game engine and MSTS/OR Editors.
* Copyright (C) 2016 Piotr Gadecki <[email protected]>
*
* Licensed under GNU General Public License 3.0 or later.
*
* See LICENSE.md or https://www.gnu.org/licenses/gpl.html
*/
#include "Coords.h"
#include <QFile>
#include "GLMatrix.h"
#include <math.h>
#include "ParserX.h"
#include <QDebug>
#include <QOpenGLShaderProgram>
#include <cstdlib>
#include "TexLib.h"
#include "Vector2f.h"
#include "TerrainLib.h"
#include "TS.h"
#include "Game.h"
#include "FileFunctions.h"
#include "ReadFile.h"
#include "GeoCoordinates.h"
#include "OglObj.h"
#include "TextObj.h"
Coords::Coords() {
loaded = false;
}
Coords::Coords(QString path) {
qDebug() << "undefined coords file";
loaded = false;
}
Coords::~Coords() {
}
void Coords::render(GLUU* gluu, float * playerT, float* playerW, float playerRot) {
if (!loaded) return;
gluu->setMatrixUniforms();
if (simpleMarkerObjP == NULL) {
simpleMarkerObjP = new OglObj();
simpleMarkerObjL = new OglObj();
float *punkty = new float[3 * 2];
int ptr = 0;
int i = 0;
punkty[ptr++] = 0;
punkty[ptr++] = 0;
punkty[ptr++] = 0;
punkty[ptr++] = 0;
punkty[ptr++] = 30;
punkty[ptr++] = 0;
simpleMarkerObjP->setMaterial(1.0, 0.0, 1.0);
simpleMarkerObjP->init(punkty, ptr, simpleMarkerObjP->V, GL_LINES);
simpleMarkerObjL->setMaterial(0.0, 1.0, 0.0);
simpleMarkerObjL->init(punkty, ptr, simpleMarkerObjL->V, GL_LINES);
delete[] punkty;
}
TextObj* txt;
for (int i = 0; i < markerList.size(); i++ ) {
for(int j = 0; j < markerList[i].tileX.size(); j++ ){
if (fabs(markerList[i].tileX[j] - playerT[0]) + fabs(-markerList[i].tileZ[j] - playerT[1]) > 2) {
continue;
}
gluu->mvPushMatrix();
//if(pos == NULL) return;
float h = Game::terrainLib->getHeight(markerList[i].tileX[j], -markerList[i].tileZ[j], markerList[i].x[j], markerList[i].z[j]);
Mat4::translate(gluu->mvMatrix, gluu->mvMatrix, markerList[i].x[j] + 2048 * (markerList[i].tileX[j] - playerT[0]), h, markerList[i].z[j] + 2048 * (-markerList[i].tileZ[j] - playerT[1]));
//Mat4::translate(gluu->mvMatrix, gluu->mvMatrix, this->trItemRData[0] + 2048*(this->trItemRData[3] - playerT[0] ), this->trItemRData[1]+2, -this->trItemRData[2] + 2048*(-this->trItemRData[4] - playerT[1]));
//Mat4::translate(gluu->mvMatrix, gluu->mvMatrix, this->trItemRData[0] + 0, this->trItemRData[1]+0, -this->trItemRData[2] + 0);
gluu->currentShader->setUniformValue(gluu->currentShader->mvMatrixUniform, *reinterpret_cast<float(*)[4][4]> (gluu->mvMatrix));
if(j == 0)
simpleMarkerObjP->render();
else
simpleMarkerObjL->render();
Mat4::translate(gluu->mvMatrix, gluu->mvMatrix, 0, 30, 0);
gluu->currentShader->setUniformValue(gluu->currentShader->mvMatrixUniform, *reinterpret_cast<float(*)[4][4]> (gluu->mvMatrix));
txt = nameGl[markerList[i].name.toStdString()];
if(txt == NULL){
txt = new TextObj(markerList[i].name, 16, 1.0);
txt->setColor(0,0,0);
nameGl[markerList[i].name.toStdString()] = txt;
}
txt->render(playerRot);
gluu->mvPopMatrix();
}
/*if (markerList[i].tileX.size() == 1) continue;
if (markerList[i].oglObj == NULL){
markerList[i].oglObj = new OglObj();
float *punkty = new float[markerList[i].pointsX.size()*3*2];
int ptr = 0;
int j = 0;
for (j = 0; j < markerList[i].pointsX.size() - 1; j++) {
punkty[ptr++] = markerList[i].pointsX[j];
punkty[ptr++] = Game::terrainLib->getHeight(markerList[i].tileX, -markerList[i].tileZ, markerList[i].pointsX[j], markerList[i].pointsZ[j]);
punkty[ptr++] = markerList[i].pointsZ[j];
punkty[ptr++] = markerList[i].pointsX[j+1];
punkty[ptr++] = Game::terrainLib->getHeight(markerList[i].tileX, -markerList[i].tileZ, markerList[i].pointsX[j], markerList[i].pointsZ[j]);
punkty[ptr++] = markerList[i].pointsZ[j+1];
}
markerList[i].oglObj->setMaterial(1.0, 0.0, 1.0);
markerList[i].oglObj->init(punkty, ptr, markerList[i].oglObj->V, GL_LINES);
delete[] punkty;
}
gluu->mvPushMatrix();
Mat4::translate(gluu->mvMatrix, gluu->mvMatrix, 2048 * (markerList[i].tileX - playerT[0]), 0, 2048 * (-markerList[i].tileZ - playerT[1]));
gluu->m_program->setUniformValue(gluu->mvMatrixUniform, *reinterpret_cast<float(*)[4][4]> (gluu->mvMatrix));
markerList[i].oglObj->render();
gluu->mvPopMatrix();*/
}
};
void Coords::getTileList(QMap<int, QPair<int, int>*> &tileList, int radius, int step){
if (!loaded) return;
QMap<int, QPair<int, int>*> tileList2;
for (int i = 0; i < markerList.size(); i++ ) {
for(int j = 0; j < markerList[i].tileX.size(); j++ ){
if(tileList2[markerList[i].tileX[j]*10000 + markerList[i].tileZ[j]] == NULL)
tileList2[markerList[i].tileX[j]*10000 + markerList[i].tileZ[j]] = new QPair<int, int>(markerList[i].tileX[j], markerList[i].tileZ[j]);
}
}
QMapIterator<int, QPair<int, int>*> i(tileList2);
int x, z;
radius *= step;
qDebug() << "radius" << radius;
while (i.hasNext()) {
i.next();
if(i.value() == NULL)
continue;
x = i.value()->first;
z = i.value()->second;
for(int i = -radius; i <= radius; i+=step)
for(int j = -radius; j <= radius; j+=step){
if(tileList[(x+i)*10000+(z+j)] == NULL){
tileList[(x+i)*10000+(z+j)] = new QPair<int, int>(x+i, z+j);
//qDebug() << i.value()->first << i.value()->second;
}
}
}
}