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 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246
|
/*
* 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/ObjMoveManager.cpp $
* $Revision: 1.1.1.1 $
* $Date: 2003-08-26 03:57:38 $
* $Author: kevinb $
*
* Object Move Manager
*
* $Log: not supported by cvs2svn $
*
* 14 5/11/99 12:07a 3dsmax
* may have fixed problem with wireframe/object movement conflict.
*
* 13 6/17/98 12:30p Samir
* don't draw wireframe when moving an object.
*
* 12 4/16/98 8:22p Sean
* don't allow movement of doors
*
* 11 2/06/98 3:10p Samir
* modified rotate scale a bit.
*
* 10 2/06/98 3:08p Samir
* Simplified object movement code.
*
* 9 2/04/98 12:42a Matt
* Made objects turn a lot faster with the mouse
*
* 8 9/05/97 3:08p Dan
* fixed some more rotatation
*
* 7 9/05/97 2:51p Samir
* Yet another adjustment on banking objects.
*
* 6 9/05/97 2:45p Samir
* Increased resolution of PHB rotations.
*
* 5 9/03/97 8:00p Samir
* Implemented most of the fixes for the object moving system.
*
* 4 9/02/97 5:36p Matt
* Got rid of warnings
*
* 3 9/02/97 3:11p Samir
* Fixed small bug.
*
* 2 9/02/97 3:00p Samir
* more intuitive object moving for certain axis.
*
* 1 8/29/97 1:45p Samir
* Basic object movement working.
*
* $NoKeywords: $
*/
#include "stdafx.h"
#include "ObjMoveManager.h"
#include "TextureGrWnd.h"
#include "editor.h"
#include "d3edit.h"
#include "HObject.h"
#include "ddio.h"
ObjectMoveManager ObjMoveManager;
//////////////////////////////////////////////////////////////////////////////
// Object Moving Manager
ObjectMoveManager::ObjectMoveManager() {
m_DragState = 0;
m_MoveAxis = OBJMOVEAXIS_X;
}
// This should be called once we want to start moving an object
// (usually from a mouse down event)
#define CURSOR_BIND_RECT_W2 20
void ObjectMoveManager::Start(CWnd *wnd, int view_width, int view_height, vector *view_pos, matrix *view_mat, int x,
int y) {
if (Objects[Cur_object_index].type == OBJ_DOOR)
return; // Can't move doors
m_DragState = 1;
// set up window properties.
m_DragWnd = wnd;
m_WindowW2 = view_width / 2;
m_WindowH2 = view_height / 2;
m_DragWnd->GetWindowRect(&m_DragRect);
m_ObjNum = Cur_object_index;
if (m_ObjNum == -1)
m_DragState = 0; // stop now!
m_ViewPos = *view_pos;
m_ViewMat = *view_mat;
//@@ if (first_poll) {
//@@ //bind cursor to dragging rectangle
//@@ POINT pt = {0,0};
//@@ RECT bind_rect;
//@@ vector v;
//@@
//@@ GetXYAndPointOfObject(&pt, &v);
//@@ wnd->ClientToScreen(&pt);
//@@
//@@ SetRect(&bind_rect, pt.x - CURSOR_BIND_RECT_W2, pt.y - CURSOR_BIND_RECT_W2, pt.x + CURSOR_BIND_RECT_W2,
//@@ pt.y + CURSOR_BIND_RECT_W2);
//@@
//@@ ClipCursor(&bind_rect);
//@@
//@@ old_pt = pt;
//@@ first_poll = false;
//@@ }
//@@
//@@ hOldCursor = GetCursor();
//@@ SetCursor(LoadCursor(NULL, IDC_CROSS));
}
// ends current object movement
void ObjectMoveManager::End() {
//@@ SetCursor(hOldCursor);
//@@ ClipCursor(NULL);
m_DragState = 0;
Object_moved = 0;
World_changed = 1;
}
#define ROTATE_SCALE (256.0f * 20.0f / ((obj->size < 10.0f) ? 10.0f : obj->size))
// defers control to the move manager
void ObjectMoveManager::Defer() {
// this code will call the object movement routines based off of the current mouse state and
// the current movement axis.
static POINT cur_pt;
if (m_DragState == 1) {
int x, y, dsx, dsy;
float dx, dy;
Object_moved = 0;
if (ddio_MouseGetState(&x, &y, &dsx, &dsy) & MOUSE_LB) {
object *obj = &Objects[m_ObjNum];
if (!dsx && !dsy)
return;
GetObjectDeltas(&dx, &dy, obj, dsx, dsy);
switch (m_MoveAxis) {
case OBJMOVEAXIS_X:
HObjectMove(Cur_object_index, dx, 0, 0);
break;
case OBJMOVEAXIS_Y:
HObjectMove(Cur_object_index, 0, -dy, 0);
break;
case OBJMOVEAXIS_Z:
HObjectMove(Cur_object_index, 0, 0, dy);
break;
case OBJMOVEAXIS_XY:
HObjectMove(Cur_object_index, dx, -dy, 0);
break;
case OBJMOVEAXIS_P:
Object_move_rotation = fabs(-dy) * ROTATE_SCALE;
if (dy > 0)
HObjectIncreasePitch();
else if (dy < 0)
HObjectDecreasePitch();
break;
case OBJMOVEAXIS_H:
Object_move_rotation = fabs(dx) * ROTATE_SCALE;
if (dx > 0)
HObjectIncreaseHeading();
else if (dx < 0)
HObjectDecreaseheading();
break;
case OBJMOVEAXIS_B:
Object_move_rotation = fabs(dx) * ROTATE_SCALE;
if (dx > 0)
HObjectIncreaseBank();
else if (dx < 0)
HObjectDecreaseBank();
break;
case OBJMOVEAXIS_PH:
Object_move_rotation = fabs(-dy) * ROTATE_SCALE;
if (dy > 0)
HObjectIncreasePitch();
else if (dy < 0)
HObjectDecreasePitch();
Object_move_rotation = fabs(dx) * ROTATE_SCALE;
if (dx > 0)
HObjectIncreaseHeading();
else if (dx < 0)
HObjectDecreaseheading();
break;
}
} else {
// we are done otherwise, reset drag state to off
this->End();
}
} else {
Object_moved = 0;
}
}
// dx and dy are the return values projected from dsx and dsy, given the object's position
void ObjectMoveManager::GetObjectDeltas(float *dx, float *dy, object *obj, int dsx, int dsy) {
vector pos;
// rotate object to view position
pos = obj->pos - m_ViewPos;
pos = pos * m_ViewMat;
if (pos.z == 0.0)
return;
*dx = ((float)dsx * pos.z) / m_WindowW2;
*dy = ((float)dsy * pos.z) / m_WindowH2;
}
|