Commit 937046a6 authored by edo9300's avatar edo9300

More constants replacement

parent 5a9b97b1
...@@ -780,7 +780,7 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir ...@@ -780,7 +780,7 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
if (controler == 0) { if (controler == 0) {
if(deck_reversed == pcard->is_reversed) { if(deck_reversed == pcard->is_reversed) {
r->X = 0.0f; r->X = 0.0f;
r->Y = 3.1415926f; r->Y = PI;
r->Z = 0.0f; r->Z = 0.0f;
} else { } else {
r->X = 0.0f; r->X = 0.0f;
...@@ -790,12 +790,12 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir ...@@ -790,12 +790,12 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
} else { } else {
if(deck_reversed == pcard->is_reversed) { if(deck_reversed == pcard->is_reversed) {
r->X = 0.0f; r->X = 0.0f;
r->Y = 3.1415926f; r->Y = PI;
r->Z = 3.1415926f; r->Z = PI;
} else { } else {
r->X = 0.0f; r->X = 0.0f;
r->Y = 0.0f; r->Y = 0.0f;
r->Z = 3.1415926f; r->Z = PI;
} }
} }
break; break;
...@@ -819,12 +819,12 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir ...@@ -819,12 +819,12 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
t->Z = 0.5f + 0.001f * sequence; t->Z = 0.5f + 0.001f * sequence;
} }
if(pcard->code) { if(pcard->code) {
r->X = -0.798056f; r->X = -mainGame->board.atan;
r->Y = 0.0f; r->Y = 0.0f;
r->Z = 0.0f; r->Z = 0.0f;
} else { } else {
r->X = 0.798056f; r->X = mainGame->board.atan;
r->Y = 3.1415926f; r->Y = PI;
r->Z = 0; r->Z = 0;
} }
} else { } else {
...@@ -843,11 +843,11 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir ...@@ -843,11 +843,11 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
t->Z = 0.5f - 0.001f * sequence; t->Z = 0.5f - 0.001f * sequence;
} }
if (pcard->code == 0) { if (pcard->code == 0) {
r->X = 0.798056f; r->X = mainGame->board.atan;
r->Y = 3.1415926f; r->Y = PI;
r->Z = 0; r->Z = 0;
} else { } else {
r->X = -0.798056f; r->X = -mainGame->board.atan;
r->Y = 0; r->Y = 0;
r->Z = 0; r->Z = 0;
} }
...@@ -861,29 +861,29 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir ...@@ -861,29 +861,29 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
if (controler == 0) { if (controler == 0) {
if (pcard->position & POS_DEFENSE) { if (pcard->position & POS_DEFENSE) {
r->X = 0.0f; r->X = 0.0f;
r->Z = -3.1415926f / 2.0f; r->Z = -HALF_PI;
if (pcard->position & POS_FACEDOWN) if (pcard->position & POS_FACEDOWN)
r->Y = 3.1415926f + 0.001f; r->Y = PI + 0.001f;
else r->Y = 0.0f; else r->Y = 0.0f;
} else { } else {
r->X = 0.0f; r->X = 0.0f;
r->Z = 0.0f; r->Z = 0.0f;
if (pcard->position & POS_FACEDOWN) if (pcard->position & POS_FACEDOWN)
r->Y = 3.1415926f; r->Y = PI;
else r->Y = 0.0f; else r->Y = 0.0f;
} }
} else { } else {
if (pcard->position & POS_DEFENSE) { if (pcard->position & POS_DEFENSE) {
r->X = 0.0f; r->X = 0.0f;
r->Z = 3.1415926f / 2.0f; r->Z = HALF_PI;
if (pcard->position & POS_FACEDOWN) if (pcard->position & POS_FACEDOWN)
r->Y = 3.1415926f + 0.001f; r->Y = PI + 0.001f;
else r->Y = 0.0f; else r->Y = 0.0f;
} else { } else {
r->X = 0.0f; r->X = 0.0f;
r->Z = 3.1415926f; r->Z = PI;
if (pcard->position & POS_FACEDOWN) if (pcard->position & POS_FACEDOWN)
r->Y = 3.1415926f; r->Y = PI;
else r->Y = 0.0f; else r->Y = 0.0f;
} }
} }
...@@ -897,13 +897,13 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir ...@@ -897,13 +897,13 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
r->X = 0.0f; r->X = 0.0f;
r->Z = 0.0f; r->Z = 0.0f;
if (pcard->position & POS_FACEDOWN) if (pcard->position & POS_FACEDOWN)
r->Y = 3.1415926f; r->Y = PI;
else r->Y = 0.0f; else r->Y = 0.0f;
} else { } else {
r->X = 0.0f; r->X = 0.0f;
r->Z = 3.1415926f; r->Z = PI;
if (pcard->position & POS_FACEDOWN) if (pcard->position & POS_FACEDOWN)
r->Y = 3.1415926f; r->Y = PI;
else r->Y = 0.0f; else r->Y = 0.0f;
} }
break; break;
...@@ -919,7 +919,7 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir ...@@ -919,7 +919,7 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
} else { } else {
r->X = 0.0f; r->X = 0.0f;
r->Y = 0.0f; r->Y = 0.0f;
r->Z = 3.1415926f; r->Z = PI;
} }
break; break;
} }
...@@ -934,18 +934,18 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir ...@@ -934,18 +934,18 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
r->Z = 0.0f; r->Z = 0.0f;
} else { } else {
r->X = 0.0f; r->X = 0.0f;
r->Y = 3.1415926f; r->Y = PI;
r->Z = 0.0f; r->Z = 0.0f;
} }
} else { } else {
if(pcard->position & POS_FACEUP) { if(pcard->position & POS_FACEUP) {
r->X = 0.0f; r->X = 0.0f;
r->Y = 0.0f; r->Y = 0.0f;
r->Z = 3.1415926f; r->Z = PI;
} else { } else {
r->X = 0.0f; r->X = 0.0f;
r->Y = 3.1415926f; r->Y = PI;
r->Z = 3.1415926f; r->Z = PI;
} }
} }
break; break;
...@@ -958,14 +958,14 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir ...@@ -958,14 +958,14 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
r->X = 0.0f; r->X = 0.0f;
if(pcard->position & POS_FACEUP) if(pcard->position & POS_FACEUP)
r->Y = 0.0f; r->Y = 0.0f;
else r->Y = 3.1415926f; else r->Y = PI;
r->Z = 0.0f; r->Z = 0.0f;
} else { } else {
r->X = 0.0f; r->X = 0.0f;
if(pcard->position & POS_FACEUP) if(pcard->position & POS_FACEUP)
r->Y = 0.0f; r->Y = 0.0f;
else r->Y = 3.1415926f; else r->Y = PI;
r->Z = 3.1415926f; r->Z = PI;
} }
break; break;
} }
...@@ -989,7 +989,7 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir ...@@ -989,7 +989,7 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
t->Z = 0.005f + pcard->sequence * 0.0001f; t->Z = 0.005f + pcard->sequence * 0.0001f;
r->X = 0.0f; r->X = 0.0f;
r->Y = 0.0f; r->Y = 0.0f;
r->Z = 3.1415926f; r->Z = PI;
} }
} else { } else {
if (pcard->overlayTarget->controler == 0) { if (pcard->overlayTarget->controler == 0) {
...@@ -1006,7 +1006,7 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir ...@@ -1006,7 +1006,7 @@ void ClientField::GetCardLocation(ClientCard* pcard, irr::core::vector3df* t, ir
t->Z = 0.005f + pcard->sequence * 0.0001f; t->Z = 0.005f + pcard->sequence * 0.0001f;
r->X = 0.0f; r->X = 0.0f;
r->Y = 0.0f; r->Y = 0.0f;
r->Z = 3.1415926f; r->Z = PI;
} }
} }
break; break;
...@@ -1023,27 +1023,27 @@ void ClientField::MoveCard(ClientCard * pcard, int frame) { ...@@ -1023,27 +1023,27 @@ void ClientField::MoveCard(ClientCard * pcard, int frame) {
GetCardLocation(pcard, &trans, &rot); GetCardLocation(pcard, &trans, &rot);
pcard->dPos = (trans - pcard->curPos) / frame; pcard->dPos = (trans - pcard->curPos) / frame;
float diff = rot.X - pcard->curRot.X; float diff = rot.X - pcard->curRot.X;
while (diff < 0) diff += 3.1415926f * 2; while (diff < 0) diff += PI * 2;
while (diff > 3.1415926f * 2) while (diff > PI * 2)
diff -= 3.1415926f * 2; diff -= PI * 2;
if (diff < 3.1415926f) if (diff < PI)
pcard->dRot.X = diff / frame; pcard->dRot.X = diff / frame;
else else
pcard->dRot.X = -(3.1415926f * 2 - diff) / frame; pcard->dRot.X = -(PI * 2 - diff) / frame;
diff = rot.Y - pcard->curRot.Y; diff = rot.Y - pcard->curRot.Y;
while (diff < 0) diff += 3.1415926f * 2; while (diff < 0) diff += PI * 2;
while (diff > 3.1415926f * 2) diff -= 3.1415926f * 2; while (diff > PI * 2) diff -= PI * 2;
if (diff < 3.1415926f) if (diff < PI)
pcard->dRot.Y = diff / frame; pcard->dRot.Y = diff / frame;
else else
pcard->dRot.Y = -(3.1415926f * 2 - diff) / frame; pcard->dRot.Y = -(PI * 2 - diff) / frame;
diff = rot.Z - pcard->curRot.Z; diff = rot.Z - pcard->curRot.Z;
while (diff < 0) diff += 3.1415926f * 2; while (diff < 0) diff += PI * 2;
while (diff > 3.1415926f * 2) diff -= 3.1415926f * 2; while (diff > PI * 2) diff -= PI * 2;
if (diff < 3.1415926f) if (diff < PI)
pcard->dRot.Z = diff / frame; pcard->dRot.Z = diff / frame;
else else
pcard->dRot.Z = -(3.1415926f * 2 - diff) / frame; pcard->dRot.Z = -(PI * 2 - diff) / frame;
pcard->is_moving = true; pcard->is_moving = true;
pcard->aniFrame = frame; pcard->aniFrame = frame;
} }
......
...@@ -643,10 +643,10 @@ void Game::DrawStackIndicator(const wchar_t* text, S3DVertex* v, bool opponent) ...@@ -643,10 +643,10 @@ void Game::DrawStackIndicator(const wchar_t* text, S3DVertex* v, bool opponent)
/*Converts the coordinates from the 3d plane to the 2d plane (the window) /*Converts the coordinates from the 3d plane to the 2d plane (the window)
*/ */
void Game::ConvertCoords(float x, float y, int* x1, int* y1) { void Game::ConvertCoords(float x, float y, int* x1, int* y1) {
double angle = atan((y - 8.0) / -7.8); double angle = atan((y - mainGame->board.y) / -mainGame->board.z);
double screeny = tan(0.798056 - angle); //0.798056 = arctan(8.0/7.8), to avoid calculating it every time double screeny = tan(mainGame->board.atan - angle);
double vlen = sqrt(1.0 + screeny * screeny); double vlen = sqrt(1.0 + screeny * screeny);
double screenx = (x - 4.2) / (7.8 / vlen / cos(angle)); double screenx = (x - mainGame->board.x) / (mainGame->board.z / vlen / cos(angle));
*x1 = (screenx + 0.90) * 1024.0 / 1.35; *x1 = (screenx + 0.90) * 1024.0 / 1.35;
*y1 = (screeny + 0.42) * 640.0 / 0.84; *y1 = (screeny + 0.42) * 640.0 / 0.84;
} }
...@@ -798,7 +798,7 @@ void Game::DrawSpec() { ...@@ -798,7 +798,7 @@ void Game::DrawSpec() {
} }
case 7: { case 7: {
core::position2d<s32> corner[4]; core::position2d<s32> corner[4];
float y = sin(showcarddif * 3.1415926f / 180.0f) * CARD_IMG_HEIGHT * window_size.Height / 640; float y = sin(showcarddif * PI / 180.0f) * CARD_IMG_HEIGHT * window_size.Height / 640;
corner[0] = core::position2d<s32>(574 * window_size.Width / 1024 - (CARD_IMG_HEIGHT * window_size.Height / 640 - y) * 0.3f, 404 * window_size.Height / 640 - y); corner[0] = core::position2d<s32>(574 * window_size.Width / 1024 - (CARD_IMG_HEIGHT * window_size.Height / 640 - y) * 0.3f, 404 * window_size.Height / 640 - y);
corner[1] = core::position2d<s32>(751 * window_size.Width / 1024 + (CARD_IMG_HEIGHT * window_size.Height / 640 - y) * 0.3f, 404 * window_size.Height / 640 - y); corner[1] = core::position2d<s32>(751 * window_size.Width / 1024 + (CARD_IMG_HEIGHT * window_size.Height / 640 - y) * 0.3f, 404 * window_size.Height / 640 - y);
corner[2] = core::position2d<s32>(574 * window_size.Width / 1024, 404 * window_size.Height / 640); corner[2] = core::position2d<s32>(574 * window_size.Width / 1024, 404 * window_size.Height / 640);
......
...@@ -2244,7 +2244,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) { ...@@ -2244,7 +2244,7 @@ int DuelClient::ClientAnalyze(char * msg, unsigned int len) {
for (auto cit = mainGame->dField.hand[player].begin(); cit != mainGame->dField.hand[player].end(); ++cit) for (auto cit = mainGame->dField.hand[player].begin(); cit != mainGame->dField.hand[player].end(); ++cit)
if((*cit)->code) { if((*cit)->code) {
(*cit)->dPos = irr::core::vector3df(0, 0, 0); (*cit)->dPos = irr::core::vector3df(0, 0, 0);
(*cit)->dRot = irr::core::vector3df(1.322f / 5, 3.1415926f / 5, 0); (*cit)->dRot = irr::core::vector3df(1.322f / 5, PI / 5, 0);
(*cit)->is_moving = true; (*cit)->is_moving = true;
(*cit)->is_hovered = false; (*cit)->is_hovered = false;
(*cit)->aniFrame = 5; (*cit)->aniFrame = 5;
......
...@@ -2198,10 +2198,10 @@ void ClientField::GetHoverField(int x, int y) { ...@@ -2198,10 +2198,10 @@ void ClientField::GetHoverField(int x, int y) {
} else { } else {
double screenx = x / 1024.0 * 1.35 - 0.90; double screenx = x / 1024.0 * 1.35 - 0.90;
double screeny = y / 640.0 * 0.84 - 0.42; double screeny = y / 640.0 * 0.84 - 0.42;
double angle = 0.798056 - atan(screeny); //0.798056 = arctan(8.0/7.8) double angle = mainGame->board.atan - atan(screeny);
double vlen = sqrt(1.0 + screeny * screeny); double vlen = sqrt(1.0 + screeny * screeny);
double boardx = 4.2 + 7.8 * screenx / vlen / cos(angle); double boardx = mainGame->board.x + mainGame->board.z * screenx / vlen / cos(angle);
double boardy = 8.0 - 7.8 * tan(angle); double boardy = mainGame->board.y - mainGame->board.z * tan(angle);
hovered_location = 0; hovered_location = 0;
if(boardx >= matManager.vFieldExtra[0][speed][0].Pos.X && boardx <= matManager.vFieldExtra[0][speed][1].Pos.X) { if(boardx >= matManager.vFieldExtra[0][speed][0].Pos.X && boardx <= matManager.vFieldExtra[0][speed][1].Pos.X) {
if(boardy >= matManager.vFieldExtra[0][speed][0].Pos.Y && boardy <= matManager.vFieldExtra[0][speed][2].Pos.Y) { if(boardy >= matManager.vFieldExtra[0][speed][0].Pos.Y && boardy <= matManager.vFieldExtra[0][speed][2].Pos.Y) {
......
...@@ -693,6 +693,12 @@ bool Game::Initialize() { ...@@ -693,6 +693,12 @@ bool Game::Initialize() {
col.setAlpha(224); col.setAlpha(224);
env->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col); env->getSkin()->setColor((EGUI_DEFAULT_COLOR)i, col);
} }
board.x = FIELD_X;
board.y = FIELD_Y;
board.z = FIELD_Z;
board.atan = atan(FIELD_Y / FIELD_Z);
engineSound = irrklang::createIrrKlangDevice(); engineSound = irrklang::createIrrKlangDevice();
engineMusic = irrklang::createIrrKlangDevice(); engineMusic = irrklang::createIrrKlangDevice();
hideChat = false; hideChat = false;
...@@ -709,7 +715,7 @@ void Game::MainLoop() { ...@@ -709,7 +715,7 @@ void Game::MainLoop() {
BuildProjectionMatrix(mProjection, -0.90f, 0.45f, -0.42f, 0.42f, 1.0f, 100.0f); BuildProjectionMatrix(mProjection, -0.90f, 0.45f, -0.42f, 0.42f, 1.0f, 100.0f);
camera->setProjectionMatrix(mProjection); camera->setProjectionMatrix(mProjection);
mProjection.buildCameraLookAtMatrixLH(vector3df(4.2f, 8.0f, 7.8f), vector3df(4.2f, 0, 0), vector3df(0, 0, 1)); mProjection.buildCameraLookAtMatrixLH(vector3df(board.x, board.y, board.z), vector3df(board.x, 0, 0), vector3df(0, 0, 1));
camera->setViewMatrixAffector(mProjection); camera->setViewMatrixAffector(mProjection);
smgr->setAmbientLight(SColorf(1.0f, 1.0f, 1.0f)); smgr->setAmbientLight(SColorf(1.0f, 1.0f, 1.0f));
float atkframe = 0.1f; float atkframe = 0.1f;
......
...@@ -86,6 +86,10 @@ struct FadingUnit { ...@@ -86,6 +86,10 @@ struct FadingUnit {
irr::core::vector2di fadingDiff; irr::core::vector2di fadingDiff;
}; };
struct Fieldmatrix {
float x, y, z, atan;
};
class Game { class Game {
public: public:
...@@ -119,6 +123,7 @@ public: ...@@ -119,6 +123,7 @@ public:
void WaitFrameSignal(int frame); void WaitFrameSignal(int frame);
void DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, int>* lflist, bool drag = false); void DrawThumb(code_pointer cp, position2di pos, std::unordered_map<int, int>* lflist, bool drag = false);
void DrawDeckBd(); void DrawDeckBd();
bool LoadGui(irr::SIrrlichtCreationParameters params, bool reload = false);
void LoadConfig(); void LoadConfig();
void SaveConfig(); void SaveConfig();
void ShowCardInfo(int code, bool resize = false); void ShowCardInfo(int code, bool resize = false);
...@@ -148,6 +153,7 @@ public: ...@@ -148,6 +153,7 @@ public:
position2di Resize(s32 x, s32 y, bool reverse = false); position2di Resize(s32 x, s32 y, bool reverse = false);
recti ResizeElem(s32 x, s32 y, s32 x2, s32 y2); recti ResizeElem(s32 x, s32 y, s32 x2, s32 y2);
recti ResizeWin(s32 x, s32 y, s32 x2, s32 y2, bool chat = false); recti ResizeWin(s32 x, s32 y, s32 x2, s32 y2, bool chat = false);
void ValidateName(irr::gui::IGUIEditBox* box);
Mutex gMutex; Mutex gMutex;
Mutex gBuffer; Mutex gBuffer;
...@@ -486,12 +492,18 @@ public: ...@@ -486,12 +492,18 @@ public:
//cancel or finish //cancel or finish
irr::gui::IGUIButton* btnCancelOrFinish; irr::gui::IGUIButton* btnCancelOrFinish;
Fieldmatrix board;
}; };
extern Game* mainGame; extern Game* mainGame;
} }
#define FIELD_X 4.2f
#define FIELD_Y 8.0f
#define FIELD_Z 7.8f
#define CARD_IMG_WIDTH 177 #define CARD_IMG_WIDTH 177
#define CARD_IMG_HEIGHT 254 #define CARD_IMG_HEIGHT 254
#define CARD_THUMB_WIDTH 44 #define CARD_THUMB_WIDTH 44
...@@ -599,6 +611,7 @@ extern Game* mainGame; ...@@ -599,6 +611,7 @@ extern Game* mainGame;
#define BUTTON_DISPLAY_4 294 #define BUTTON_DISPLAY_4 294
#define SCROLL_CARD_DISPLAY 295 #define SCROLL_CARD_DISPLAY 295
#define BUTTON_CARD_DISP_OK 296 #define BUTTON_CARD_DISP_OK 296
#define EDITBOX_DECK_NAME 297
#define BUTTON_CATEGORY_OK 300 #define BUTTON_CATEGORY_OK 300
#define COMBOBOX_DBLFLIST 301 #define COMBOBOX_DBLFLIST 301
#define COMBOBOX_DBDECKS 302 #define COMBOBOX_DBDECKS 302
...@@ -624,6 +637,7 @@ extern Game* mainGame; ...@@ -624,6 +637,7 @@ extern Game* mainGame;
#define BUTTON_REPLAY_UNDO 323 #define BUTTON_REPLAY_UNDO 323
#define BUTTON_REPLAY_EXIT 324 #define BUTTON_REPLAY_EXIT 324
#define BUTTON_REPLAY_SWAP 325 #define BUTTON_REPLAY_SWAP 325
#define EDITBOX_REPLAY_NAME 326
#define BUTTON_REPLAY_SAVE 330 #define BUTTON_REPLAY_SAVE 330
#define BUTTON_REPLAY_CANCEL 331 #define BUTTON_REPLAY_CANCEL 331
#define LISTBOX_SINGLEPLAY_LIST 350 #define LISTBOX_SINGLEPLAY_LIST 350
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment