File: moveworld.cpp

package info (click to toggle)
descent3 1.5.0%2Bds-2
  • links: PTS, VCS
  • area: contrib
  • in suites: forky, sid
  • size: 35,256 kB
  • sloc: cpp: 416,147; ansic: 3,233; sh: 10; makefile: 8
file content (186 lines) | stat: -rw-r--r-- 5,179 bytes parent folder | download | duplicates (2)
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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/*
* Descent 3
* Copyright (C) 2024 Parallax Software
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program.  If not, see <http://www.gnu.org/licenses/>.

--- HISTORICAL COMMENTS FOLLOW ---

 * $Logfile: /DescentIII/Main/editor/moveworld.cpp $
 * $Revision: 1.1.1.1 $
 * $Date: 2003-08-26 03:57:38 $
 * $Author: kevinb $
 *
 * Code to use the mouse to rotate and move the world in the editor
 *
 * $Log: not supported by cvs2svn $
 *
 * 6     10/04/98 1:25p Matt
 *
 * 5     1/20/98 1:36p Matt
 * Moved mine origin to the center of the terrain
 *
 * 4     10/03/97 3:39p Matt
 * Added seperate sets of wireframe view variables for mine & room views
 *
 * 3     7/22/97 7:08p Matt
 * Cleaned up D3EditState, moving some vars in and some out, and renaming
 * and changing a few others
 *
 * 8     6/13/97 4:24p Matt
 * Added functions to change wireframe view target
 *
 * 7     5/22/97 5:16p Jason
 * added "drawing" on the topo map
 *
 * 6     3/31/97 5:58p Matt
 * Revamped mine update flags
 *
 * 5     2/10/97 5:39p Matt
 * Added func to reset view
 *
 * 4     2/07/97 5:47p Matt
 * Renamed vector.h to vecmat.h to fix DevStudio problem
 *
 * $NoKeywords: $
 */

#include "Moveworld.h"

#include "ddio.h"
#include "vecmat.h"
#include "d3edit.h"
#include "mono.h"

#define dist_2d(x, y) sqrt((x) * (x) + (y) * (y))

void GetMouseRotation(int idx, int idy, matrix *RotMat) {
  float dr, cos_theta, sin_theta, denom, cos_theta1;
  float Radius = 100.0;
  float dx, dy;
  float dxdr, dydr;

  idy *= -1;

  dx = idx;
  dy = idy;

  dr = dist_2d(dx, dy);

  denom = dist_2d(Radius, dr);

  cos_theta = Radius / denom;
  sin_theta = dr / denom;

  cos_theta1 = 1.0 - cos_theta;

  dxdr = dx / dr;
  dydr = dy / dr;

  RotMat->rvec.x = cos_theta + ((dydr * dydr) * cos_theta1);
  RotMat->uvec.x = -((dxdr * dydr) * cos_theta1);
  RotMat->fvec.x = (dxdr * sin_theta);

  RotMat->rvec.y = RotMat->uvec.x;
  RotMat->uvec.y = cos_theta + ((dxdr * dxdr) * cos_theta1);
  RotMat->fvec.y = (dydr * sin_theta);

  RotMat->rvec.z = -RotMat->fvec.x;
  RotMat->uvec.z = -RotMat->fvec.y;
  RotMat->fvec.z = cos_theta;
}

// Variables for current view position and orientation
#define DEFAULT_VIEW_DIST 500
#define DEFAULT_VIEW_RAD 5000

// Wireframe views for the mine & room views
wireframe_view Wireframe_view_mine = {IDENTITY_MATRIX, {0, 0, 0}, DEFAULT_VIEW_DIST, DEFAULT_VIEW_RAD};
wireframe_view Wireframe_view_room = {IDENTITY_MATRIX, {0, 0, 0}, DEFAULT_VIEW_DIST, DEFAULT_VIEW_RAD};

// The current wireframe view
wireframe_view *Wireframe_view = &Wireframe_view_mine;

#define MOVE_SCALE 3.0
#define ZOOM_SCALE 10.0
#define RAD_SCALE 10.0

// Read the mouse and move the wireframe view
void MoveWorld() {
  int x, y, dx, dy;
  ddio_MouseGetState(&x, &y, &dx, &dy);

  if ((dx != 0) || (dy != 0)) {

    if (Editor_view_mode == VM_TERRAIN) {
      return;
    }

    if ((KEY_STATE(KEY_LCTRL) || KEY_STATE(KEY_RCTRL)) && !(KEY_STATE(KEY_LSHIFT) || KEY_STATE(KEY_RSHIFT))) {
      matrix rotmat, tempm;
      GetMouseRotation(dx, dy, &rotmat);
      tempm = Wireframe_view->orient * rotmat;
      Wireframe_view->orient = tempm;
      Edview_changed = 1;
    }

    if ((KEY_STATE(KEY_LCTRL) || KEY_STATE(KEY_RCTRL)) && (KEY_STATE(KEY_LSHIFT) || KEY_STATE(KEY_RSHIFT))) {
      Wireframe_view->target += Wireframe_view->orient.rvec * -dx * MOVE_SCALE;
      Wireframe_view->target += Wireframe_view->orient.uvec * dy * MOVE_SCALE;
      Edview_changed = 1;
    }

    if (KEY_STATE(KEY_Z) && !(KEY_STATE(KEY_LSHIFT) || KEY_STATE(KEY_RSHIFT))) {
      Wireframe_view->dist += dy * ZOOM_SCALE;
      if (Wireframe_view->dist < 0)
        Wireframe_view->dist = 0;
      Edview_changed = 1;
    }

    if (KEY_STATE(KEY_Z) && (KEY_STATE(KEY_LSHIFT) || KEY_STATE(KEY_RSHIFT))) {
      Wireframe_view->rad += dy * RAD_SCALE;
      if (Wireframe_view->rad < 0)
        Wireframe_view->rad = 0;
      EditorStatus("View radius = %.0f", Wireframe_view->rad);
      Edview_changed = 1;
    }
  }
}

extern vector Mine_origin;

// Reset the orienation, position, & distance of the wireframe view
void ResetWireframeView() {
  Wireframe_view->dist = DEFAULT_VIEW_DIST;
  Wireframe_view->rad = DEFAULT_VIEW_RAD;
  vm_MakeIdentity(&Wireframe_view->orient);

  Wireframe_view->target = Mine_origin;

  Edview_changed = 1;
}

// Reset the view radius of the wireframe view
void ResetWireframeViewRad() {
  Wireframe_view->rad = DEFAULT_VIEW_RAD;
  Edview_changed = 1;
}

// Set the wireframe view target to a specific location
// Does not reset the distance or orientation
void SetWireframeView(vector *pos) {
  Wireframe_view->target = *pos;

  Edview_changed = 1;
}