forked from GokuMK/TSRE5
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCameraConsist.cpp
167 lines (122 loc) · 4.21 KB
/
CameraConsist.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
156
157
158
159
160
161
162
163
164
165
166
167
/* 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 "CameraConsist.h"
#include <math.h>
#include "GLMatrix.h"
#include "Game.h"
#include "GeoCoordinates.h"
CameraConsist::CameraConsist(float* pt) {
if(pt != NULL)
pozT = pt;
else{
pozT = new float[2];
pozT[0] = 0;
pozT[1] = 1;
}
up[0] = 0;
up[1] = 1;
up[2] = 0;
playerRot[0] = 0.0;
playerRot[1] = 0.0;
playerPos[0] = 0;
playerPos[1] = 10;
playerPos[2] = 0;
relativeRot[0] = 0;
relativeRot[1] = 0;
relativePos[0] = 0;
relativePos[1] = 0;
relativePos[2] = 0;
moveF = moveR = moveB = moveL = false;
fov = 49;
}
CameraConsist::CameraConsist(const CameraConsist& orig) {
}
CameraConsist::~CameraConsist() {
}
PreciseTileCoordinate* CameraConsist::getCurrentPos(){
if(this->currentPos == NULL)
this->currentPos = new PreciseTileCoordinate();
this->currentPos->TileX = this->pozT[0];
this->currentPos->TileZ = -this->pozT[1];
float* p = this->getPos();
this->currentPos->setWxyz(p[0], p[1], -p[2]);
return this->currentPos;
}
float* CameraConsist::getMatrix() {
Mat4::lookAt(lookAt, playerPos, getTarget(), up);
return lookAt;
};
float* CameraConsist::getTarget() {
// + trasa.ruch1.pozW.x
//return new Vector3f(obx+ trasa.ruch1.pozW.x + (float) Math.sin(kato) * 35 , oby + trasa.ruch1.pozW.y + (float) Math.sin(katov) * 20 , obz - trasa.ruch1.pozW.z + (float) Math.cos(kato) * 35 );
//return new Vector3f(playerPos.x + relativePos.x + (float) Math.sin(playerRot.x + relativeRot.x) * 1 , playerPos.y + relativePos.y + (float) Math.sin(playerRot.y + relativeRot.y) * 1 , playerPos.z + relativePos.z + (float) Math.cos(playerRot.x + relativeRot.x) * 1 );
//return new float[3]{getPos().x + (float) sin(playerRot[0] + relativeRot[0]) * 1, playerPos.y + relativePos.y + (float) sin(playerRot.y + relativeRot.y) * 1, getPos().z + (float) cos(playerRot.x + relativeRot.x) * 1};
target[0] = playerPos[0] + (float) sin(playerRot[0] + relativeRot[0]) * cos(playerRot[1] + relativeRot[1]);
target[1] = playerPos[1] + (float) sin(playerRot[1] + relativeRot[1]) * 1;
target[2] = playerPos[2] + (float) cos(playerRot[0] + relativeRot[0]) * cos(playerRot[1] + relativeRot[1]);
return target;
//return new float[3]{playerPos[0], playerPos[1],playerPos[2]+1};
}
void CameraConsist::setPos(float* pos){
playerPos[0] = pos[0];
playerPos[1] = pos[1];
playerPos[2] = pos[2];
}
void CameraConsist::setPos(float x, float y, float z){
playerPos[0] = x;
playerPos[1] = y;
playerPos[2] = z;
}
void CameraConsist::setPozT(int x, int y){
pozT[0] = x;
pozT[1] = y;
}
float* CameraConsist::getPos() {
pos[0] = relativePos[0] + (playerPos[0] * (float) cos(-relativeRot[0]) - playerPos[2] * (float) sin(-relativeRot[0]));
pos[1] = relativePos[1] + playerPos[1];
pos[2] = relativePos[2] + (playerPos[0] * (float) sin(-relativeRot[0]) + playerPos[2] * (float) cos(-relativeRot[0]));
return pos;
}
float CameraConsist::getRotX() {
return playerRot[0] + relativeRot[0];
}
float CameraConsist::getRotY() {
return playerRot[1] + relativeRot[1];
}
void CameraConsist::update(float fps) {
}
void CameraConsist::moveForward(float fps) {
}
void CameraConsist::moveBackward(float fps) {
}
void CameraConsist::moveLeft(float fps) {
}
void CameraConsist::moveRight(float fps) {
}
void CameraConsist::moveUp() {
}
void CameraConsist::moveDown() {
}
void CameraConsist::patrzX(float f) {
}
void CameraConsist::patrzY(float f) {
}
void CameraConsist::check_coords() {
}
void CameraConsist::MouseMove(QMouseEvent* e) {
}
void CameraConsist::MouseDown(QMouseEvent* e) {
}
void CameraConsist::MouseUp(QMouseEvent* e) {
}
void CameraConsist::keyUp(QKeyEvent * e) {
}
void CameraConsist::keyDown(QKeyEvent * e) {
};