1 /**
2  * @file
3  */
4 
5 /*
6 Copyright (C) 2002-2013 UFO: Alien Invasion.
7 
8 This program is free software; you can redistribute it and/or
9 modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation; either version 2
11 of the License, or (at your option) any later version.
12 
13 This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16 
17 See the GNU General Public License for more details.
18 
19 You should have received a copy of the GNU General Public License
20 along with this program; if not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
22 
23 */
24 
25 #pragma once
26 
27 #include "../ui_nodes.h"
28 #include "ui_node_abstractnode.h"
29 #include "../../cl_shared.h"
30 
31 class uiGeoscapeNode : public uiLocatedNode {
32 protected:
33 	void smoothTranslate (uiNode_t* node);
34 	void smoothRotate (uiNode_t* node);
35 	void screenTo3DMap (const uiNode_t* node, int x, int y, vec2_t pos);
36 	void screenToMap (const uiNode_t* node, int x, int y, vec2_t pos);
37 	void calcAndUploadDayAndNightTexture (uiNode_t* node, float q);
38 public:
39 	void draw(uiNode_t* node) override;
40 	void onMouseUp(uiNode_t* node, int x, int y, int button) override;
41 	void onCapturedMouseMove(uiNode_t* node, int x, int y) override;
42 	void onCapturedMouseLost(uiNode_t* node) override;
43 	void onLoading(uiNode_t* node) override;
44 	bool onScroll(uiNode_t* node, int deltaX, int deltaY) override;
45 	void onLeftClick(uiNode_t* node, int x, int y) override;
46 	bool onStartDragging(uiNode_t* node, int startX, int startY, int currentX, int currentY, int button) override;
47 	void zoom(uiNode_t* node, bool out);
48 	void startMouseShifting(uiNode_t* node, int x, int y);
49 };
50 
51 #define UI_MAPEXTRADATA_TYPE mapExtraData_t
52 #define UI_MAPEXTRADATA(node) UI_EXTRADATA(node, UI_MAPEXTRADATA_TYPE)
53 #define UI_MAPEXTRADATACONST(node) UI_EXTRADATACONST(node, UI_MAPEXTRADATA_TYPE)
54 
55 #define DAN_WIDTH		2048
56 #define DAN_HEIGHT		1024
57 
58 /**
59  * @brief Typical zoom to use on the 3D geoscape to use same zoom values for both 2D and 3D geoscape
60  * @note Used to convert openGL coordinates of the sphere into screen coordinates
61  * @sa GLOBE_RADIUS */
62 #define STANDARD_3D_ZOOM 40.0f
63 
64 #define EARTH_RADIUS 8192.0f
65 #define MOON_RADIUS 1024.0f
66 #define SUN_RADIUS 1024.0f
67 
68 /** @brief radius of the globe in screen coordinates */
69 #define GLOBE_RADIUS EARTH_RADIUS * (UI_MAPEXTRADATACONST(node).zoom / STANDARD_3D_ZOOM)
70 
71 typedef struct mapExtraData_s {
72 	/* Smoothing variables */
73 	bool smoothRotation; /**< @c true if the rotation of 3D geoscape must me smooth */
74 	vec3_t smoothFinalGlobeAngle; /**< value of final angles for a smooth change of angle (see MAP_CenterOnPoint)*/
75 	vec2_t smoothFinal2DGeoscapeCenter; /**< value of center for a smooth change of position (see MAP_CenterOnPoint) */
76 	float smoothDeltaLength; /**< angle/position difference that we need to change when smoothing */
77 	float smoothFinalZoom; /**< value of final zoom for a smooth change of angle (see MAP_CenterOnPoint)*/
78 	float smoothDeltaZoom; /**< zoom difference that we need to change when smoothing */
79 	float curZoomSpeed; /**< The current zooming speed. Used for smooth zooming. */
80 	float curRotationSpeed; /**< The current rotation speed. Used for smooth rotating.*/
81 
82 	vec2_t mapSize;
83 	vec2_t mapPos;
84 	vec3_t angles; /**< 3d geoscape rotation */
85 	vec2_t center; /**< latitude and longitude of the point we're looking at on earth */
86 	float zoom; /**< zoom used when looking at earth */
87 	bool flatgeoscape;
88 	float ambientLightFactor;
89 	float mapzoommin;
90 	float mapzoommax;
91 	float paddingRight;
92 	int32_t overlayMask;
93 	geoscapeData_t* geoscapeData;
94 	byte* r_dayandnightAlpha;
95 } mapExtraData_t;
96 
97 void UI_RegisterGeoscapeNode(uiBehaviour_t* behaviour);
98