xywnd.cpp
来自「quake3工具源码。包括生成bsp文件」· C++ 代码 · 共 2,569 行 · 第 1/5 页
CPP
2,569 行
//point[1] = m_vOrigin[0] + (fx - fw / 2) / m_fScale;
//point[2] = m_vOrigin[1] + (fy - fh / 2 ) / m_fScale;
point[1] = m_vOrigin[1] + (fx - fw / 2) / m_fScale;
point[2] = m_vOrigin[2] + (fy - fh / 2 ) / m_fScale;
}
else
{
//point[0] = m_vOrigin[0] + (fx - fw / 2) / m_fScale;
////point[1] = 0;
//point[2] = m_vOrigin[1] + (fy - fh / 2) / m_fScale;
point[0] = m_vOrigin[0] + (fx - fw / 2) / m_fScale;
//point[1] = 0;
point[2] = m_vOrigin[2] + (fy - fh / 2) / m_fScale;
}
}
void CXYWnd::XY_ToGridPoint (int x, int y, vec3_t point)
{
if (m_nViewType == XY)
{
point[0] = m_vOrigin[0] + (x - m_nWidth / 2) / m_fScale;
point[1] = m_vOrigin[1] + (y - m_nHeight / 2) / m_fScale;
//point[2] = 0;
point[0] = floor(point[0] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
point[1] = floor(point[1] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
}
else if (m_nViewType == YZ)
{
//point[0] = 0;
//point[1] = m_vOrigin[0] + (x - m_nWidth / 2) / m_fScale;
//point[2] = m_vOrigin[1] + (y - m_nHeight / 2) / m_fScale;
point[1] = m_vOrigin[1] + (x - m_nWidth / 2) / m_fScale;
point[2] = m_vOrigin[2] + (y - m_nHeight / 2) / m_fScale;
point[1] = floor(point[1] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
point[2] = floor(point[2] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
}
else
{
//point[1] = 0;
//point[0] = m_vOrigin[0] + (x - m_nWidth / 2) / m_fScale;
//point[2] = m_vOrigin[1] + (y - m_nHeight / 2) / m_fScale;
point[0] = m_vOrigin[0] + (x - m_nWidth / 2) / m_fScale;
point[2] = m_vOrigin[2] + (y - m_nHeight / 2) / m_fScale;
point[0] = floor(point[0] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
point[2] = floor(point[2] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
}
}
void CXYWnd::XY_MouseDown (int x, int y, int buttons)
{
vec3_t point;
vec3_t origin, dir, right, up;
m_nButtonstate = buttons;
m_nPressx = x;
m_nPressy = y;
VectorCopy (vec3_origin, m_vPressdelta);
XY_ToPoint (x, y, point);
VectorCopy (point, origin);
dir[0] = 0; dir[1] = 0; dir[2] = 0;
if (m_nViewType == XY)
{
origin[2] = 8192;
dir[2] = -1;
right[0] = 1 / m_fScale;
right[1] = 0;
right[2] = 0;
up[0] = 0;
up[1] = 1 / m_fScale;
up[2] = 0;
}
else if (m_nViewType == YZ)
{
origin[0] = 8192;
dir[0] = -1;
right[1] = 1 / m_fScale;
right[2] = 0;
right[0] = 0;
up[0] = 0;
up[2] = 1 / m_fScale;
up[1] = 0;
}
else
{
origin[1] = 8192;
dir[1] = -1;
right[0] = 1 / m_fScale;
right[2] = 0;
right[1] = 0;
up[0] = 0;
up[2] = 1 / m_fScale;
up[1] = 0;
}
m_bPress_selection = (selected_brushes.next != &selected_brushes);
GetCursorPos(&m_ptCursor);
//Sys_GetCursorPos (&m_ptCursor.x, &m_ptCursor.y);
// lbutton = manipulate selection
// shift-LBUTTON = select
if ( (buttons == MK_LBUTTON)
|| (buttons == (MK_LBUTTON | MK_SHIFT))
|| (buttons == (MK_LBUTTON | MK_CONTROL))
|| (buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT)) )
{
Patch_SetView( (m_nViewType == XY) ? W_XY : (m_nViewType == YZ) ? W_YZ : W_XZ);
Drag_Begin (x, y, buttons, right, up, origin, dir);
return;
}
int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
// control mbutton = move camera
if (m_nButtonstate == (MK_CONTROL|nMouseButton) )
{
VectorCopyXY(point, g_pParentWnd->GetCamera()->Camera().origin);
Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
}
// mbutton = angle camera
if ((g_PrefsDlg.m_nMouseButtons == 3 && m_nButtonstate == MK_MBUTTON) ||
(g_PrefsDlg.m_nMouseButtons == 2 && m_nButtonstate == (MK_SHIFT|MK_CONTROL|MK_RBUTTON)))
{
VectorSubtract (point, g_pParentWnd->GetCamera()->Camera().origin, point);
int n1 = (m_nViewType == XY) ? 1 : 2;
int n2 = (m_nViewType == YZ) ? 1 : 0;
int nAngle = (m_nViewType == XY) ? YAW : PITCH;
if (point[n1] || point[n2])
{
g_pParentWnd->GetCamera()->Camera().angles[nAngle] = 180/Q_PI*atan2 (point[n1], point[n2]);
Sys_UpdateWindows (W_CAMERA_IFON|W_XY_OVERLAY);
}
}
// shift mbutton = move z checker
if (m_nButtonstate == (MK_SHIFT | nMouseButton))
{
if (RotateMode() || g_bPatchBendMode)
{
SnapToPoint (x, y, point);
VectorCopyXY(point, g_vRotateOrigin);
if (g_bPatchBendMode)
{
VectorCopy(point, g_vBendOrigin);
}
Sys_UpdateWindows (W_XY);
return;
}
else
{
SnapToPoint (x, y, point);
if (m_nViewType == XY)
{
z.origin[0] = point[0];
z.origin[1] = point[1];
}
else if (m_nViewType == YZ)
{
z.origin[0] = point[1];
z.origin[1] = point[2];
}
else
{
z.origin[0] = point[0];
z.origin[1] = point[2];
}
Sys_UpdateWindows (W_XY_OVERLAY|W_Z);
return;
}
}
}
void CXYWnd::XY_MouseUp(int x, int y, int buttons)
{
Drag_MouseUp (buttons);
if (!m_bPress_selection)
Sys_UpdateWindows (W_ALL);
m_nButtonstate = 0;
while (::ShowCursor(TRUE) < 0)
;
}
qboolean CXYWnd::DragDelta (int x, int y, vec3_t move)
{
vec3_t xvec, yvec, delta;
int i;
xvec[0] = 1 / m_fScale;
xvec[1] = xvec[2] = 0;
yvec[1] = 1 / m_fScale;
yvec[0] = yvec[2] = 0;
for (i=0 ; i<3 ; i++)
{
delta[i] = xvec[i] * (x - m_nPressx) + yvec[i] * (y - m_nPressy);
if (!g_PrefsDlg.m_bNoClamp)
{
delta[i] = floor(delta[i] / g_qeglobals.d_gridsize + 0.5) * g_qeglobals.d_gridsize;
}
}
VectorSubtract (delta, m_vPressdelta, move);
VectorCopy (delta, m_vPressdelta);
if (move[0] || move[1] || move[2])
return true;
return false;
}
/*
==============
NewBrushDrag
==============
*/
void CXYWnd::NewBrushDrag (int x, int y)
{
vec3_t mins, maxs, junk;
int i;
float temp;
brush_t *n;
if (!DragDelta (x,y, junk))
return;
// delete the current selection
if (selected_brushes.next != &selected_brushes)
Brush_Free (selected_brushes.next);
SnapToPoint (m_nPressx, m_nPressy, mins);
int nDim = (m_nViewType == XY) ? 2 : (m_nViewType == YZ) ? 0 : 1;
mins[nDim] = g_qeglobals.d_gridsize * ((int)(g_qeglobals.d_new_brush_bottom_z / g_qeglobals.d_gridsize));
SnapToPoint (x, y, maxs);
maxs[nDim] = g_qeglobals.d_gridsize * ((int)(g_qeglobals.d_new_brush_top_z / g_qeglobals.d_gridsize));
if (maxs[nDim] <= mins[nDim])
maxs[nDim] = mins[nDim] + g_qeglobals.d_gridsize;
for (i=0 ; i<3 ; i++)
{
if (mins[i] == maxs[i])
return; // don't create a degenerate brush
if (mins[i] > maxs[i])
{
temp = mins[i];
mins[i] = maxs[i];
maxs[i] = temp;
}
}
n = Brush_Create (mins, maxs, &g_qeglobals.d_texturewin.texdef);
if (!n)
return;
vec3_t vSize;
VectorSubtract(maxs, mins, vSize);
g_strStatus.Format("Size X:: %.1f Y:: %.1f Z:: %.1f", vSize[0], vSize[1], vSize[2]);
g_pParentWnd->SetStatusText(2, g_strStatus);
Brush_AddToList (n, &selected_brushes);
Entity_LinkBrush (world_entity, n);
Brush_Build( n );
// Sys_UpdateWindows (W_ALL);
Sys_UpdateWindows (W_XY| W_CAMERA);
}
/*
==============
XY_MouseMoved
==============
*/
void CXYWnd::XY_MouseMoved (int x, int y, int buttons)
{
vec3_t point;
if (!m_nButtonstate)
{
if (g_bCrossHairs)
{
::ShowCursor(FALSE);
Sys_UpdateWindows (W_XY | W_XY_OVERLAY);
::ShowCursor(TRUE);
}
return;
}
// lbutton without selection = drag new brush
if (m_nButtonstate == MK_LBUTTON && !m_bPress_selection && g_qeglobals.d_select_mode != sel_curvepoint)
{
NewBrushDrag (x, y);
return;
}
// lbutton (possibly with control and or shift)
// with selection = drag selection
if (m_nButtonstate & MK_LBUTTON)
{
Drag_MouseMoved (x, y, buttons);
Sys_UpdateWindows (W_XY_OVERLAY | W_CAMERA_IFON | W_Z);
return;
}
int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
// control mbutton = move camera
if (m_nButtonstate == (MK_CONTROL|nMouseButton) )
{
SnapToPoint (x, y, point);
VectorCopyXY(point, g_pParentWnd->GetCamera()->Camera().origin);
Sys_UpdateWindows (W_XY_OVERLAY | W_CAMERA);
return;
}
// shift mbutton = move z checker
if (m_nButtonstate == (MK_SHIFT|nMouseButton) )
{
if (RotateMode() || g_bPatchBendMode)
{
SnapToPoint (x, y, point);
VectorCopyXY(point, g_vRotateOrigin);
if (g_bPatchBendMode)
{
VectorCopy(point, g_vBendOrigin);
}
Sys_UpdateWindows (W_XY);
return;
}
else
{
SnapToPoint (x, y, point);
if (m_nViewType == XY)
{
z.origin[0] = point[0];
z.origin[1] = point[1];
}
else if (m_nViewType == YZ)
{
z.origin[0] = point[1];
z.origin[1] = point[2];
}
else
{
z.origin[0] = point[0];
z.origin[1] = point[2];
}
}
Sys_UpdateWindows (W_XY_OVERLAY|W_Z);
return;
}
// mbutton = angle camera
if ((g_PrefsDlg.m_nMouseButtons == 3 && m_nButtonstate == MK_MBUTTON) ||
(g_PrefsDlg.m_nMouseButtons == 2 && m_nButtonstate == (MK_SHIFT|MK_CONTROL|MK_RBUTTON)))
{
SnapToPoint (x, y, point);
VectorSubtract (point, g_pParentWnd->GetCamera()->Camera().origin, point);
int n1 = (m_nViewType == XY) ? 1 : 2;
int n2 = (m_nViewType == YZ) ? 1 : 0;
int nAngle = (m_nViewType == XY) ? YAW : PITCH;
if (point[n1] || point[n2])
{
g_pParentWnd->GetCamera()->Camera().angles[nAngle] = 180/Q_PI*atan2 (point[n1], point[n2]);
Sys_UpdateWindows (W_CAMERA_IFON|W_XY_OVERLAY);
}
return;
}
// rbutton = drag xy origin
if (m_nButtonstate == MK_RBUTTON)
{
Sys_GetCursorPos (&x, &y);
if (x != m_ptCursor.x || y != m_ptCursor.y)
{
int nDim1 = (m_nViewType == YZ) ? 1 : 0;
int nDim2 = (m_nViewType == XY) ? 1 : 2;
m_vOrigin[nDim1] -= (x - m_ptCursor.x) / m_fScale;
m_vOrigin[nDim2] += (y - m_ptCursor.y) / m_fScale;
SetCursorPos (m_ptCursor.x, m_ptCursor.y);
::ShowCursor(FALSE);
//XY_Draw();
//RedrawWindow(NULL, NULL, RDW_INVALIDATE | RDW_UPDATENOW);
Sys_UpdateWindows (W_XY | W_XY_OVERLAY);
//::ShowCursor(TRUE);
}
return;
}
}
/*
============================================================================
DRAWING
============================================================================
*/
/*
==============
XY_DrawGrid
==============
*/
void CXYWnd::XY_DrawGrid()
{
float x, y, xb, xe, yb, ye;
int w, h;
char text[32];
qglDisable(GL_TEXTURE_2D);
qglDisable(GL_TEXTURE_1D);
qglDisable(GL_DEPTH_TEST);
qglDisable(GL_BLEND);
w = m_nWidth / 2 / m_fScale;
h = m_nHeight / 2 / m_fScale;
int nDim1 = (m_nViewType == YZ) ? 1 : 0;
int nDim2 = (m_nViewType == XY) ? 1 : 2;
//int nDim1 = 0;
//int nDim2 = 1;
xb = m_vOrigin[nDim1] - w;
if (xb < region_mins[nDim1])
xb = region_mins[nDim1];
xb = 64 * floor (xb/64);
xe = m_vOrigin[nDim1] + w;
if (xe > region_maxs[nDim1])
xe = region_maxs[nDim1];
xe = 64 * ceil (xe/64);
yb = m_vOrigin[nDim2] - h;
if (yb < region_mins[nDim2])
yb = region_mins[nDim2];
yb = 64 * floor (yb/64);
ye = m_vOrigin[nDim2] + h;
if (ye > region_maxs[nDim2])
ye = region_maxs[nDim2];
ye = 64 * ceil (ye/64);
// draw major blocks
qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMAJOR]);
int stepSize = 64 * 0.1 / m_fScale;
if (stepSize < 64) {
stepSize = 64;
} else {
int i;
for (i = 1; i < stepSize; i <<= 1) {
}
stepSize = i;
}
if ( g_qeglobals.d_showgrid )
{
qglBegin (GL_LINES);
for (x=xb ; x<=xe ; x+=stepSize)
{
qglVertex2f (x, yb);
qglVertex2f (x, ye);
}
for (y=yb ; y<=ye ; y+=stepSize)
{
qglVertex2f (xb, y);
qglVertex2f (xe, y);
}
qglEnd ();
}
// draw minor blocks
if ( m_fScale > .1 && g_qeglobals.d_showgrid && g_qeglobals.d_gridsize * m_fScale >= 4 &&
g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR] != g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK])
{
qglColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR]);
qglBegin (GL_LINES);
for (x=xb ; x<xe ; x += g_qeglobals.d_gridsize)
{
if ( ! ((int)x & 63) )
continue;
qglVertex2f (x, yb);
qglVertex2f (x, ye);
}
for (y=yb ; y<ye ; y+=g_qeglobals.d_gridsize)
{
if ( ! ((int)y & 63) )
continue;
qglVertex2f (xb, y);
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?