camwnd.cpp
字号:
// CamWnd.cpp : implementation file
//
#include "stdafx.h"
#include "Radiant.h"
#include "XYWnd.h"
#include "CamWnd.h"
#include "qe3.h"
#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif
extern void DrawPathLines();
int g_nAngleSpeed = 300;
int g_nMoveSpeed = 400;
/////////////////////////////////////////////////////////////////////////////
// CCamWnd
IMPLEMENT_DYNCREATE(CCamWnd, CWnd);
CCamWnd::CCamWnd()
{
m_pXYFriend = NULL;
m_nNumTransBrushes = 0;
memset(&m_Camera, 0, sizeof(camera_t));
m_pSide_select = NULL;
m_bClipMode = false;
Cam_Init();
}
CCamWnd::~CCamWnd()
{
}
BEGIN_MESSAGE_MAP(CCamWnd, CWnd)
//{{AFX_MSG_MAP(CCamWnd)
ON_WM_KEYDOWN()
ON_WM_PAINT()
ON_WM_DESTROY()
ON_WM_CLOSE()
ON_WM_MOUSEMOVE()
ON_WM_LBUTTONDOWN()
ON_WM_LBUTTONUP()
ON_WM_MBUTTONDOWN()
ON_WM_MBUTTONUP()
ON_WM_RBUTTONDOWN()
ON_WM_RBUTTONUP()
ON_WM_CREATE()
ON_WM_SIZE()
ON_WM_NCCALCSIZE()
ON_WM_KILLFOCUS()
ON_WM_SETFOCUS()
ON_WM_KEYUP()
//}}AFX_MSG_MAP
END_MESSAGE_MAP()
LONG WINAPI CamWndProc (
HWND hWnd,
UINT uMsg,
WPARAM wParam,
LPARAM lParam)
{
RECT rect;
GetClientRect(hWnd, &rect);
switch (uMsg)
{
case WM_KILLFOCUS:
case WM_SETFOCUS:
SendMessage( hWnd, WM_NCACTIVATE, uMsg == WM_SETFOCUS, 0 );
return 0;
case WM_NCCALCSIZE:// don't let windows copy pixels
DefWindowProc (hWnd, uMsg, wParam, lParam);
return WVR_REDRAW;
}
return DefWindowProc( hWnd, uMsg, wParam, lParam );
}
/////////////////////////////////////////////////////////////////////////////
// CCamWnd message handlers
BOOL CCamWnd::PreCreateWindow(CREATESTRUCT& cs)
{
WNDCLASS wc;
HINSTANCE hInstance = AfxGetInstanceHandle();
if (::GetClassInfo(hInstance, CAMERA_WINDOW_CLASS, &wc) == FALSE)
{
// Register a new class
memset (&wc, 0, sizeof(wc));
wc.style = CS_NOCLOSE | CS_OWNDC;
wc.lpszClassName = CAMERA_WINDOW_CLASS;
wc.hCursor = LoadCursor (NULL,IDC_ARROW);
wc.lpfnWndProc = CamWndProc;
if (AfxRegisterClass(&wc) == FALSE)
Error ("CCamWnd RegisterClass: failed");
}
cs.lpszClass = CAMERA_WINDOW_CLASS;
cs.lpszName = "CAM";
if (cs.style != QE3_CHILDSTYLE)
cs.style = QE3_SPLITTER_STYLE;
BOOL bResult = CWnd::PreCreateWindow(cs);
// See if the class already exists and if not then we need
// to register our new window class.
return bResult;
}
void CCamWnd::OnKeyDown(UINT nChar, UINT nRepCnt, UINT nFlags)
{
g_pParentWnd->HandleKey(nChar, nRepCnt, nFlags);
}
brush_t* g_pSplitList = NULL;
void CCamWnd::OnPaint()
{
CPaintDC dc(this); // device context for painting
bool bPaint = true;
if (!qwglMakeCurrent( dc.m_hDC, g_qeglobals.d_hglrcBase ))
{
Sys_Printf("ERROR: wglMakeCurrent failed..\n ");
Sys_Printf("Please restart Q3Radiant if the camera view is not working\n");
}
else
{
QE_CheckOpenGLForErrors();
g_pSplitList = NULL;
if (g_bClipMode)
{
if (g_Clip1.Set() && g_Clip2.Set())
{
g_pSplitList = ( (g_pParentWnd->ActiveXY()->GetViewType() == XZ) ? !g_bSwitch : g_bSwitch) ? &g_brBackSplits : &g_brFrontSplits;
}
}
Cam_Draw ();
QE_CheckOpenGLForErrors();
qwglSwapBuffers(dc.m_hDC);
}
}
void CCamWnd::SetXYFriend(CXYWnd * pWnd)
{
m_pXYFriend = pWnd;
}
void CCamWnd::OnDestroy()
{
QEW_StopGL(GetSafeHwnd(), g_qeglobals.d_hglrcBase, g_qeglobals.d_hdcBase );
CWnd::OnDestroy();
}
void CCamWnd::OnClose()
{
CWnd::OnClose();
}
extern void Select_ShiftTexture(int x, int y);
extern void Select_RotateTexture(int amt);
extern void Select_ScaleTexture(int x, int y);
void CCamWnd::OnMouseMove(UINT nFlags, CPoint point)
{
CRect r;
GetClientRect(r);
if (GetCapture() == this && (GetKeyState(VK_MENU) & 0x8000) && !((GetKeyState(VK_SHIFT) & 0x8000) || (GetKeyState(VK_CONTROL) & 0x8000)))
{
if (GetKeyState(VK_CONTROL) & 0x8000)
Select_RotateTexture(point.y - m_ptLastCursor.y);
else
if (GetKeyState(VK_SHIFT) & 0x8000)
Select_ScaleTexture(point.x - m_ptLastCursor.x, m_ptLastCursor.y - point.y);
else
Select_ShiftTexture(point.x - m_ptLastCursor.x, m_ptLastCursor.y - point.y);
}
else
{
Cam_MouseMoved(point.x, r.bottom - 1 - point.y, nFlags);
}
m_ptLastCursor = point;
}
void CCamWnd::OnLButtonDown(UINT nFlags, CPoint point)
{
m_ptLastCursor = point;
OriginalMouseDown(nFlags, point);
}
void CCamWnd::OnLButtonUp(UINT nFlags, CPoint point)
{
OriginalMouseUp(nFlags, point);
}
void CCamWnd::OnMButtonDown(UINT nFlags, CPoint point)
{
OriginalMouseDown(nFlags, point);
}
void CCamWnd::OnMButtonUp(UINT nFlags, CPoint point)
{
OriginalMouseUp(nFlags, point);
}
void CCamWnd::OnRButtonDown(UINT nFlags, CPoint point)
{
OriginalMouseDown(nFlags, point);
}
void CCamWnd::OnRButtonUp(UINT nFlags, CPoint point)
{
OriginalMouseUp(nFlags, point);
}
int CCamWnd::OnCreate(LPCREATESTRUCT lpCreateStruct)
{
if (CWnd::OnCreate(lpCreateStruct) == -1)
return -1;
g_qeglobals.d_hdcBase = GetDC()->m_hDC;
QEW_SetupPixelFormat(g_qeglobals.d_hdcBase, true);
if ((g_qeglobals.d_hglrcBase = qwglCreateContext(g_qeglobals.d_hdcBase)) == 0)
Error("wglCreateContext failed");
if (!qwglMakeCurrent(g_qeglobals.d_hdcBase, g_qeglobals.d_hglrcBase))
Error ("wglMakeCurrent failed");
//
// create GL font
//
HFONT hfont = ::CreateFont(
12, // logical height of font
6, // logical average character width
0, // angle of escapement
0, // base-line orientation angle
0, // font weight
0, // italic attribute flag
0, // underline attribute flag
0, // strikeout attribute flag
0, // character set identifier
0, // output precision
0, // clipping precision
0, // output quality
0, // pitch and family
"system font" // pointer to typeface name string
);
if (!hfont)
Error( "couldn't create font" );
::SelectObject(g_qeglobals.d_hdcBase, hfont);
if ((g_qeglobals.d_font_list = qglGenLists (256)) == 0)
Error( "couldn't create font dlists" );
// create the bitmap display lists
// we're making images of glyphs 0 thru 255
if (g_PrefsDlg.m_bBuggyICD)
{
if ( !qwglUseFontBitmaps (g_qeglobals.d_hdcBase, 1, 255, g_qeglobals.d_font_list-1) )
Error( "wglUseFontBitmaps faileD" );
}
else
{
if ( !qwglUseFontBitmaps (g_qeglobals.d_hdcBase, 1, 255, g_qeglobals.d_font_list) )
Error( "wglUseFontBitmaps faileD" );
}
// indicate start of glyph display lists
qglListBase (g_qeglobals.d_font_list);
// report OpenGL information
Sys_Printf ("GL_VENDOR: %s\n", qglGetString (GL_VENDOR));
Sys_Printf ("GL_RENDERER: %s\n", qglGetString (GL_RENDERER));
Sys_Printf ("GL_VERSION: %s\n", qglGetString (GL_VERSION));
Sys_Printf ("GL_EXTENSIONS: %s\n", qglGetString (GL_EXTENSIONS));
g_qeglobals.d_hwndCamera = GetSafeHwnd();
return 0;
}
void CCamWnd::OriginalMouseUp(UINT nFlags, CPoint point)
{
CRect r;
GetClientRect(r);
Cam_MouseUp(point.x, r.bottom - 1 - point.y, nFlags);
if (!(nFlags & (MK_LBUTTON|MK_RBUTTON|MK_MBUTTON)))
ReleaseCapture ();
}
void CCamWnd::OriginalMouseDown(UINT nFlags, CPoint point)
{
//if (GetTopWindow()->GetSafeHwnd() != GetSafeHwnd())
// BringWindowToTop();
CRect r;
GetClientRect(r);
SetFocus();
SetCapture();
//if (!(GetKeyState(VK_MENU) & 0x8000))
Cam_MouseDown (point.x, r.bottom - 1 - point.y, nFlags);
}
void CCamWnd::Cam_Init()
{
//m_Camera.draw_mode = cd_texture;
m_Camera.timing = false;
m_Camera.origin[0] = 0;
m_Camera.origin[1] = 20;
m_Camera.origin[2] = 46;
m_Camera.color[0] = 0.3;
m_Camera.color[1] = 0.3;
m_Camera.color[2] = 0.3;
}
void CCamWnd::Cam_BuildMatrix()
{
float xa, ya;
float matrix[4][4];
int i;
xa = m_Camera.angles[0]/180*Q_PI;
ya = m_Camera.angles[1]/180*Q_PI;
// the movement matrix is kept 2d
m_Camera.forward[0] = cos(ya);
m_Camera.forward[1] = sin(ya);
m_Camera.right[0] = m_Camera.forward[1];
m_Camera.right[1] = -m_Camera.forward[0];
qglGetFloatv (GL_PROJECTION_MATRIX, &matrix[0][0]);
for (i=0 ; i<3 ; i++)
{
m_Camera.vright[i] = matrix[i][0];
m_Camera.vup[i] = matrix[i][1];
m_Camera.vpn[i] = matrix[i][2];
}
VectorNormalize (m_Camera.vright);
VectorNormalize (m_Camera.vup);
VectorNormalize (m_Camera.vpn);
}
void CCamWnd::Cam_ChangeFloor (qboolean up)
{
brush_t *b;
float d, bestd, current;
vec3_t start, dir;
start[0] = m_Camera.origin[0];
start[1] = m_Camera.origin[1];
start[2] = 8192;
dir[0] = dir[1] = 0;
dir[2] = -1;
current = 8192 - (m_Camera.origin[2] - 48);
if (up)
bestd = 0;
else
bestd = 16384;
for (b=active_brushes.next ; b != &active_brushes ; b=b->next)
{
if (!Brush_Ray (start, dir, b, &d))
continue;
if (up && d < current && d > bestd)
bestd = d;
if (!up && d > current && d < bestd)
bestd = d;
}
if (bestd == 0 || bestd == 16384)
return;
m_Camera.origin[2] += current - bestd;
Sys_UpdateWindows (W_CAMERA|W_Z_OVERLAY);
}
void CCamWnd::Cam_PositionDrag()
{
int x, y;
Sys_GetCursorPos (&x, &y);
if (x != m_ptCursor.x || y != m_ptCursor.y)
{
x -= m_ptCursor.x;
VectorMA (m_Camera.origin, x, m_Camera.vright, m_Camera.origin);
y -= m_ptCursor.y;
m_Camera.origin[2] -= y;
SetCursorPos(m_ptCursor.x, m_ptCursor.y);
Sys_UpdateWindows (W_CAMERA | W_XY_OVERLAY);
}
}
void CCamWnd::Cam_MouseControl (float dtime)
{
int xl, xh;
int yl, yh;
float xf, yf;
if (g_PrefsDlg.m_nMouseButtons == 2)
{
if (m_nCambuttonstate != (MK_RBUTTON | MK_SHIFT))
return;
}
else
{
if (m_nCambuttonstate != MK_RBUTTON)
return;
}
xf = (float)(m_ptButton.x - m_Camera.width/2) / (m_Camera.width/2);
yf = (float)(m_ptButton.y - m_Camera.height/2) / (m_Camera.height/2);
xl = m_Camera.width/3;
xh = xl*2;
yl = m_Camera.height/3;
yh = yl*2;
//Sys_Printf("xf-%f yf-%f xl-%i xh-i% yl-i% yh-i%\n",xf,yf,xl,xh,yl,yh);
#if 0
// strafe
if (buttony < yl && (buttonx < xl || buttonx > xh))
VectorMA (camera.origin, xf*dtime*g_nMoveSpeed, camera.right, camera.origin);
else
#endif
{
xf *= 1.0 - fabs(yf);
if (xf < 0)
{
xf += 0.1;
if (xf > 0)
xf = 0;
}
else
{
xf -= 0.1;
if (xf < 0)
xf = 0;
}
VectorMA (m_Camera.origin, yf*dtime*g_nMoveSpeed, m_Camera.forward, m_Camera.origin);
m_Camera.angles[YAW] += xf*-dtime*g_nAngleSpeed;
}
#if 0
if (g_PrefsDlg.m_bQE4Painting)
{
MSG msg;
if (::PeekMessage( &msg, NULL, 0, 0, PM_REMOVE ))
{
TranslateMessage(&msg);
DispatchMessage(&msg);
}
}
#endif
int nUpdate = (g_PrefsDlg.m_bCamXYUpdate) ? (W_CAMERA | W_XY) : (W_CAMERA);
Sys_UpdateWindows (nUpdate);
g_pParentWnd->PostMessage(WM_TIMER, 0, 0);
}
void CCamWnd::Cam_MouseDown(int x, int y, int buttons)
{
vec3_t dir;
float f, r, u;
int i;
//
// calc ray direction
//
u = (float)(y - m_Camera.height/2) / (m_Camera.width/2);
r = (float)(x - m_Camera.width/2) / (m_Camera.width/2);
f = 1;
for (i=0 ; i<3 ; i++)
dir[i] = m_Camera.vpn[i] * f + m_Camera.vright[i] * r + m_Camera.vup[i] * u;
VectorNormalize (dir);
GetCursorPos(&m_ptCursor);
m_nCambuttonstate = buttons;
m_ptButton.x = x;
m_ptButton.y = y;
// LBUTTON = manipulate selection
// shift-LBUTTON = select
// middle button = grab texture
// ctrl-middle button = set entire brush to texture
// ctrl-shift-middle button = set single face to texture
int nMouseButton = g_PrefsDlg.m_nMouseButtons == 2 ? MK_RBUTTON : MK_MBUTTON;
if ((buttons == MK_LBUTTON)
|| (buttons == (MK_LBUTTON | MK_SHIFT))
|| (buttons == (MK_LBUTTON | MK_CONTROL))
|| (buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT))
|| (buttons == nMouseButton)
|| (buttons == (nMouseButton|MK_SHIFT))
|| (buttons == (nMouseButton|MK_CONTROL))
|| (buttons == (nMouseButton|MK_SHIFT|MK_CONTROL)))
{
if (g_PrefsDlg.m_nMouseButtons == 2 && (buttons == (MK_RBUTTON | MK_SHIFT)))
Cam_MouseControl (0.1);
else
{
// something global needs to track which window is responsible for stuff
Patch_SetView(W_CAMERA);
Drag_Begin (x, y, buttons, m_Camera.vright, m_Camera.vup, m_Camera.origin, dir);
}
return;
}
if (buttons == MK_RBUTTON)
{
Cam_MouseControl (0.1);
return;
}
}
void CCamWnd::Cam_MouseUp (int x, int y, int buttons)
{
m_nCambuttonstate = 0;
Drag_MouseUp (buttons);
}
void CCamWnd::Cam_MouseMoved (int x, int y, int buttons)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -