| 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/ObjMoveManager.cpp $ |
| 21 | * $Revision: 1.1.1.1 $ |
| 22 | * $Date: 2003-08-26 03:57:38 $ |
| 23 | * $Author: kevinb $ |
| 24 | * |
| 25 | * Object Move Manager |
| 26 | * |
| 27 | * $Log: not supported by cvs2svn $ |
| 28 | * |
| 29 | * 14 5/11/99 12:07a 3dsmax |
| 30 | * may have fixed problem with wireframe/object movement conflict. |
| 31 | * |
| 32 | * 13 6/17/98 12:30p Samir |
| 33 | * don't draw wireframe when moving an object. |
| 34 | * |
| 35 | * 12 4/16/98 8:22p Sean |
| 36 | * don't allow movement of doors |
| 37 | * |
| 38 | * 11 2/06/98 3:10p Samir |
| 39 | * modified rotate scale a bit. |
| 40 | * |
| 41 | * 10 2/06/98 3:08p Samir |
| 42 | * Simplified object movement code. |
| 43 | * |
| 44 | * 9 2/04/98 12:42a Matt |
| 45 | * Made objects turn a lot faster with the mouse |
| 46 | * |
| 47 | * 8 9/05/97 3:08p Dan |
| 48 | * fixed some more rotatation |
| 49 | * |
| 50 | * 7 9/05/97 2:51p Samir |
| 51 | * Yet another adjustment on banking objects. |
| 52 | * |
| 53 | * 6 9/05/97 2:45p Samir |
| 54 | * Increased resolution of PHB rotations. |
| 55 | * |
| 56 | * 5 9/03/97 8:00p Samir |
| 57 | * Implemented most of the fixes for the object moving system. |
| 58 | * |
| 59 | * 4 9/02/97 5:36p Matt |
| 60 | * Got rid of warnings |
| 61 | * |
| 62 | * 3 9/02/97 3:11p Samir |
| 63 | * Fixed small bug. |
| 64 | * |
| 65 | * 2 9/02/97 3:00p Samir |
| 66 | * more intuitive object moving for certain axis. |
| 67 | * |
| 68 | * 1 8/29/97 1:45p Samir |
| 69 | * Basic object movement working. |
| 70 | * |
| 71 | * $NoKeywords: $ |
| 72 | */ |
| 73 | |
| 74 | #include "stdafx.h" |
| 75 | #include "ObjMoveManager.h" |
| 76 | #include "TextureGrWnd.h" |
| 77 | #include "editor.h" |
| 78 | #include "d3edit.h" |
| 79 | #include "HObject.h" |
| 80 | |
| 81 | #include "ddio.h" |
| 82 | |
| 83 | ObjectMoveManager ObjMoveManager; |
| 84 | |
| 85 | ////////////////////////////////////////////////////////////////////////////// |
| 86 | // Object Moving Manager |
| 87 | |
| 88 | ObjectMoveManager::ObjectMoveManager() { |
| 89 | m_DragState = 0; |
| 90 | m_MoveAxis = OBJMOVEAXIS_X; |
| 91 | } |
| 92 | |
| 93 | // This should be called once we want to start moving an object |
| 94 | // (usually from a mouse down event) |
| 95 | #define CURSOR_BIND_RECT_W2 20 |
| 96 | |
| 97 | void ObjectMoveManager::Start(CWnd *wnd, int view_width, int view_height, vector *view_pos, matrix *view_mat, int x, |
| 98 | int y) { |
| 99 | if (Objects[Cur_object_index].type == OBJ_DOOR) |
| 100 | return; // Can't move doors |
| 101 | |
| 102 | m_DragState = 1; |
| 103 | |
| 104 | // set up window properties. |
| 105 | m_DragWnd = wnd; |
| 106 | m_WindowW2 = view_width / 2; |
| 107 | m_WindowH2 = view_height / 2; |
| 108 | m_DragWnd->GetWindowRect(&m_DragRect); |
| 109 | m_ObjNum = Cur_object_index; |
| 110 | |
| 111 | if (m_ObjNum == -1) |
| 112 | m_DragState = 0; // stop now! |
| 113 | |
| 114 | m_ViewPos = *view_pos; |
| 115 | m_ViewMat = *view_mat; |
| 116 | |
| 117 | //@@ if (first_poll) { |
| 118 | //@@ //bind cursor to dragging rectangle |
| 119 | //@@ POINT pt = {0,0}; |
| 120 | //@@ RECT bind_rect; |
| 121 | //@@ vector v; |
| 122 | //@@ |
| 123 | //@@ GetXYAndPointOfObject(&pt, &v); |
| 124 | //@@ wnd->ClientToScreen(&pt); |
| 125 | //@@ |
| 126 | //@@ SetRect(&bind_rect, pt.x - CURSOR_BIND_RECT_W2, pt.y - CURSOR_BIND_RECT_W2, pt.x + CURSOR_BIND_RECT_W2, |
| 127 | //@@ pt.y + CURSOR_BIND_RECT_W2); |
| 128 | //@@ |
| 129 | //@@ ClipCursor(&bind_rect); |
| 130 | //@@ |
| 131 | //@@ old_pt = pt; |
| 132 | //@@ first_poll = false; |
| 133 | //@@ } |
| 134 | //@@ |
| 135 | //@@ hOldCursor = GetCursor(); |
| 136 | //@@ SetCursor(LoadCursor(NULL, IDC_CROSS)); |
| 137 | } |
| 138 | |
| 139 | // ends current object movement |
| 140 | void ObjectMoveManager::End() { |
| 141 | //@@ SetCursor(hOldCursor); |
| 142 | //@@ ClipCursor(NULL); |
| 143 | m_DragState = 0; |
| 144 | Object_moved = 0; |
| 145 | World_changed = 1; |
| 146 | } |
| 147 | |
| 148 | #define ROTATE_SCALE (256.0f * 20.0f / ((obj->size < 10.0f) ? 10.0f : obj->size)) |
| 149 | |
| 150 | // defers control to the move manager |
| 151 | void ObjectMoveManager::Defer() { |
| 152 | // this code will call the object movement routines based off of the current mouse state and |
| 153 | // the current movement axis. |
| 154 | static POINT cur_pt; |
| 155 | |
| 156 | if (m_DragState == 1) { |
| 157 | int x, y, dsx, dsy; |
| 158 | float dx, dy; |
| 159 | |
| 160 | Object_moved = 0; |
| 161 | |
| 162 | if (ddio_MouseGetState(&x, &y, &dsx, &dsy) & MOUSE_LB) { |
| 163 | object *obj = &Objects[m_ObjNum]; |
| 164 | |
| 165 | if (!dsx && !dsy) |
| 166 | return; |
| 167 | |
| 168 | GetObjectDeltas(&dx, &dy, obj, dsx, dsy); |
| 169 | |
| 170 | switch (m_MoveAxis) { |
| 171 | case OBJMOVEAXIS_X: |
| 172 | HObjectMove(Cur_object_index, dx, 0, 0); |
| 173 | break; |
| 174 | |
| 175 | case OBJMOVEAXIS_Y: |
| 176 | HObjectMove(Cur_object_index, 0, -dy, 0); |
| 177 | break; |
| 178 | |
| 179 | case OBJMOVEAXIS_Z: |
| 180 | HObjectMove(Cur_object_index, 0, 0, dy); |
| 181 | break; |
| 182 | |
| 183 | case OBJMOVEAXIS_XY: |
| 184 | HObjectMove(Cur_object_index, dx, -dy, 0); |
| 185 | break; |
| 186 | |
| 187 | case OBJMOVEAXIS_P: |
| 188 | Object_move_rotation = fabs(-dy) * ROTATE_SCALE; |
| 189 | if (dy > 0) |
| 190 | HObjectIncreasePitch(); |
| 191 | else if (dy < 0) |
| 192 | HObjectDecreasePitch(); |
| 193 | break; |
| 194 | |
| 195 | case OBJMOVEAXIS_H: |
| 196 | Object_move_rotation = fabs(dx) * ROTATE_SCALE; |
| 197 | if (dx > 0) |
| 198 | HObjectIncreaseHeading(); |
| 199 | else if (dx < 0) |
| 200 | HObjectDecreaseheading(); |
| 201 | break; |
| 202 | |
| 203 | case OBJMOVEAXIS_B: |
| 204 | Object_move_rotation = fabs(dx) * ROTATE_SCALE; |
| 205 | if (dx > 0) |
| 206 | HObjectIncreaseBank(); |
| 207 | else if (dx < 0) |
| 208 | HObjectDecreaseBank(); |
| 209 | break; |
| 210 | |
| 211 | case OBJMOVEAXIS_PH: |
| 212 | Object_move_rotation = fabs(-dy) * ROTATE_SCALE; |
| 213 | if (dy > 0) |
| 214 | HObjectIncreasePitch(); |
| 215 | else if (dy < 0) |
| 216 | HObjectDecreasePitch(); |
| 217 | Object_move_rotation = fabs(dx) * ROTATE_SCALE; |
| 218 | if (dx > 0) |
| 219 | HObjectIncreaseHeading(); |
| 220 | else if (dx < 0) |
| 221 | HObjectDecreaseheading(); |
| 222 | break; |
| 223 | } |
| 224 | } else { |
| 225 | // we are done otherwise, reset drag state to off |
| 226 | this->End(); |
| 227 | } |
| 228 | } else { |
| 229 | Object_moved = 0; |
| 230 | } |
| 231 | } |
| 232 | |
| 233 | // dx and dy are the return values projected from dsx and dsy, given the object's position |
| 234 | void ObjectMoveManager::GetObjectDeltas(float *dx, float *dy, object *obj, int dsx, int dsy) { |
| 235 | vector pos; |
| 236 | |
| 237 | // rotate object to view position |
| 238 | pos = obj->pos - m_ViewPos; |
| 239 | pos = pos * m_ViewMat; |
| 240 | |
| 241 | if (pos.z == 0.0) |
| 242 | return; |
| 243 | |
| 244 | *dx = ((float)dsx * pos.z) / m_WindowW2; |
| 245 | *dy = ((float)dsy * pos.z) / m_WindowH2; |
| 246 | } |