Debian Codegraph @

editor/moveworld.cpp

raw
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17
18 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/Main/editor/moveworld.cpp $
21 * $Revision: 1.1.1.1 $
22 * $Date: 2003-08-26 03:57:38 $
23 * $Author: kevinb $
24 *
25 * Code to use the mouse to rotate and move the world in the editor
26 *
27 * $Log: not supported by cvs2svn $
28 *
29 * 6 10/04/98 1:25p Matt
30 *
31 * 5 1/20/98 1:36p Matt
32 * Moved mine origin to the center of the terrain
33 *
34 * 4 10/03/97 3:39p Matt
35 * Added seperate sets of wireframe view variables for mine & room views
36 *
37 * 3 7/22/97 7:08p Matt
38 * Cleaned up D3EditState, moving some vars in and some out, and renaming
39 * and changing a few others
40 *
41 * 8 6/13/97 4:24p Matt
42 * Added functions to change wireframe view target
43 *
44 * 7 5/22/97 5:16p Jason
45 * added "drawing" on the topo map
46 *
47 * 6 3/31/97 5:58p Matt
48 * Revamped mine update flags
49 *
50 * 5 2/10/97 5:39p Matt
51 * Added func to reset view
52 *
53 * 4 2/07/97 5:47p Matt
54 * Renamed vector.h to vecmat.h to fix DevStudio problem
55 *
56 * $NoKeywords: $
57 */
58
59 #include "Moveworld.h"
60
61 #include "ddio.h"
62 #include "vecmat.h"
63 #include "d3edit.h"
64 #include "mono.h"
65
66 #define dist_2d(x, y) sqrt((x) * (x) + (y) * (y))
67
68 void GetMouseRotation(int idx, int idy, matrix *RotMat) {
69 float dr, cos_theta, sin_theta, denom, cos_theta1;
70 float Radius = 100.0;
71 float dx, dy;
72 float dxdr, dydr;
73
74 idy *= -1;
75
76 dx = idx;
77 dy = idy;
78
79 dr = dist_2d(dx, dy);
80
81 denom = dist_2d(Radius, dr);
82
83 cos_theta = Radius / denom;
84 sin_theta = dr / denom;
85
86 cos_theta1 = 1.0 - cos_theta;
87
88 dxdr = dx / dr;
89 dydr = dy / dr;
90
91 RotMat->rvec.x = cos_theta + ((dydr * dydr) * cos_theta1);
92 RotMat->uvec.x = -((dxdr * dydr) * cos_theta1);
93 RotMat->fvec.x = (dxdr * sin_theta);
94
95 RotMat->rvec.y = RotMat->uvec.x;
96 RotMat->uvec.y = cos_theta + ((dxdr * dxdr) * cos_theta1);
97 RotMat->fvec.y = (dydr * sin_theta);
98
99 RotMat->rvec.z = -RotMat->fvec.x;
100 RotMat->uvec.z = -RotMat->fvec.y;
101 RotMat->fvec.z = cos_theta;
102 }
103
104 // Variables for current view position and orientation
105 #define DEFAULT_VIEW_DIST 500
106 #define DEFAULT_VIEW_RAD 5000
107
108 // Wireframe views for the mine & room views
109 wireframe_view Wireframe_view_mine = {IDENTITY_MATRIX, {0, 0, 0}, DEFAULT_VIEW_DIST, DEFAULT_VIEW_RAD};
110 wireframe_view Wireframe_view_room = {IDENTITY_MATRIX, {0, 0, 0}, DEFAULT_VIEW_DIST, DEFAULT_VIEW_RAD};
111
112 // The current wireframe view
113 wireframe_view *Wireframe_view = &Wireframe_view_mine;
114
115 #define MOVE_SCALE 3.0
116 #define ZOOM_SCALE 10.0
117 #define RAD_SCALE 10.0
118
119 // Read the mouse and move the wireframe view
120 void MoveWorld() {
121 int x, y, dx, dy;
122 ddio_MouseGetState(&x, &y, &dx, &dy);
123
124 if ((dx != 0) || (dy != 0)) {
125
126 if (Editor_view_mode == VM_TERRAIN) {
127 return;
128 }
129
130 if ((KEY_STATE(KEY_LCTRL) || KEY_STATE(KEY_RCTRL)) && !(KEY_STATE(KEY_LSHIFT) || KEY_STATE(KEY_RSHIFT))) {
131 matrix rotmat, tempm;
132 GetMouseRotation(dx, dy, &rotmat);
133 tempm = Wireframe_view->orient * rotmat;
134 Wireframe_view->orient = tempm;
135 Edview_changed = 1;
136 }
137
138 if ((KEY_STATE(KEY_LCTRL) || KEY_STATE(KEY_RCTRL)) && (KEY_STATE(KEY_LSHIFT) || KEY_STATE(KEY_RSHIFT))) {
139 Wireframe_view->target += Wireframe_view->orient.rvec * -dx * MOVE_SCALE;
140 Wireframe_view->target += Wireframe_view->orient.uvec * dy * MOVE_SCALE;
141 Edview_changed = 1;
142 }
143
144 if (KEY_STATE(KEY_Z) && !(KEY_STATE(KEY_LSHIFT) || KEY_STATE(KEY_RSHIFT))) {
145 Wireframe_view->dist += dy * ZOOM_SCALE;
146 if (Wireframe_view->dist < 0)
147 Wireframe_view->dist = 0;
148 Edview_changed = 1;
149 }
150
151 if (KEY_STATE(KEY_Z) && (KEY_STATE(KEY_LSHIFT) || KEY_STATE(KEY_RSHIFT))) {
152 Wireframe_view->rad += dy * RAD_SCALE;
153 if (Wireframe_view->rad < 0)
154 Wireframe_view->rad = 0;
155 EditorStatus("View radius = %.0f", Wireframe_view->rad);
156 Edview_changed = 1;
157 }
158 }
159 }
160
161 extern vector Mine_origin;
162
163 // Reset the orienation, position, & distance of the wireframe view
164 void ResetWireframeView() {
165 Wireframe_view->dist = DEFAULT_VIEW_DIST;
166 Wireframe_view->rad = DEFAULT_VIEW_RAD;
167 vm_MakeIdentity(&Wireframe_view->orient);
168
169 Wireframe_view->target = Mine_origin;
170
171 Edview_changed = 1;
172 }
173
174 // Reset the view radius of the wireframe view
175 void ResetWireframeViewRad() {
176 Wireframe_view->rad = DEFAULT_VIEW_RAD;
177 Edview_changed = 1;
178 }
179
180 // Set the wireframe view target to a specific location
181 // Does not reset the distance or orientation
182 void SetWireframeView(vector *pos) {
183 Wireframe_view->target = *pos;
184
185 Edview_changed = 1;
186 }