2 ===========================================================================
3 Copyright (C) 1997-2006 Id Software, Inc.
5 This file is part of Quake 2 Tools source code.
7 Quake 2 Tools source code is free software; you can redistribute it
8 and/or modify it under the terms of the GNU General Public License as
9 published by the Free Software Foundation; either version 2 of the License,
10 or (at your option) any later version.
12 Quake 2 Tools source code is distributed in the hope that it will be
13 useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Quake 2 Tools source code; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 ===========================================================================
46 ============================================================================
50 ============================================================================
53 static int cursorx, cursory;
60 void Z_MouseDown (int x, int y, int buttons)
62 vec3_t org, dir, vup, vright;
65 Sys_GetCursorPos (&cursorx, &cursory);
67 vup[0] = 0; vup[1] = 0; vup[2] = 1/z.scale;
69 VectorCopy (z.origin, org);
70 org[2] += (y - (z.height/2))/z.scale;
73 b = selected_brushes.next;
74 if (b != &selected_brushes)
76 org[0] = (b->mins[0] + b->maxs[0])/2;
79 dir[0] = 0; dir[1] = 1; dir[2] = 0;
81 vright[0] = 0; vright[1] = 0; vright[2] = 0;
83 // LBUTTON = manipulate selection
84 // shift-LBUTTON = select
85 // middle button = grab texture
86 // ctrl-middle button = set entire brush to texture
87 // ctrl-shift-middle button = set single face to texture
88 if ( (buttons == MK_LBUTTON)
89 || (buttons == (MK_LBUTTON | MK_SHIFT))
90 || (buttons == MK_MBUTTON)
91 // || (buttons == (MK_MBUTTON|MK_CONTROL))
92 || (buttons == (MK_MBUTTON|MK_SHIFT|MK_CONTROL)) )
94 Drag_Begin (x, y, buttons,
100 // control mbutton = move camera
101 if ((buttons == (MK_CONTROL|MK_MBUTTON) ) || (buttons == (MK_CONTROL|MK_LBUTTON)))
103 camera.origin[2] = org[2] ;
104 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY|W_Z);
115 void Z_MouseUp (int x, int y, int buttons)
125 void Z_MouseMoved (int x, int y, int buttons)
129 if (buttons == MK_LBUTTON)
131 Drag_MouseMoved (x, y, buttons);
132 Sys_UpdateWindows (W_Z|W_CAMERA);
135 // rbutton = drag z origin
136 if (buttons == MK_RBUTTON)
138 Sys_GetCursorPos (&x, &y);
141 z.origin[2] += y-cursory;
142 Sys_SetCursorPos (cursorx, cursory);
143 Sys_UpdateWindows (W_Z);
147 // control mbutton = move camera
148 if ((buttons == (MK_CONTROL|MK_MBUTTON) ) || (buttons == (MK_CONTROL|MK_LBUTTON)))
150 camera.origin[2] = (y - (z.height/2))/z.scale;
151 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY|W_Z);
158 ============================================================================
162 ============================================================================
171 void Z_DrawGrid (void)
177 w = z.width/2 / z.scale;
178 h = z.height/2 / z.scale;
180 zb = z.origin[2] - h;
181 if (zb < region_mins[2])
183 zb = 64 * floor (zb/64);
185 ze = z.origin[2] + h;
186 if (ze > region_maxs[2])
188 ze = 64 * ceil (ze/64);
192 glColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMAJOR]);
199 for (zz=zb ; zz<ze ; zz+=64)
208 if (g_qeglobals.d_showgrid && g_qeglobals.d_gridsize*z.scale >= 4)
210 glColor3fv(g_qeglobals.d_savedinfo.colors[COLOR_GRIDMINOR]);
213 for (zz=zb ; zz<ze ; zz+=g_qeglobals.d_gridsize)
215 if ( ! ((int)zz & 63) )
223 // draw coordinate text if needed
225 glColor4f(0, 0, 0, 0);
227 for (zz=zb ; zz<ze ; zz+=64)
229 glRasterPos2f (-w+1, zz);
230 sprintf (text, "%i",(int)zz);
231 glCallLists (strlen(text), GL_UNSIGNED_BYTE, text);
235 #define CAM_HEIGHT 48 // height of main part
236 #define CAM_GIZMO 8 // height of the gizmo
238 void ZDrawCameraIcon (void)
241 int xCam = z.width/4;
244 y = camera.origin[2];
246 glColor3f (0.0, 0.0, 1.0);
247 glBegin(GL_LINE_STRIP);
248 glVertex3f (x-xCam,y,0);
249 glVertex3f (x,y+CAM_GIZMO,0);
250 glVertex3f (x+xCam,y,0);
251 glVertex3f (x,y-CAM_GIZMO,0);
252 glVertex3f (x-xCam,y,0);
253 glVertex3f (x+xCam,y,0);
254 glVertex3f (x+xCam,y-CAM_HEIGHT,0);
255 glVertex3f (x-xCam,y-CAM_HEIGHT,0);
256 glVertex3f (x-xCam,y,0);
261 GLbitfield glbitClear = GL_COLOR_BUFFER_BIT; //HACK
275 vec3_t org_top, org_bottom, dir_up, dir_down;
276 int xCam = z.width/3;
278 if (!active_brushes.next)
279 return; // not valid yet
282 start = Sys_DoubleTime ();
287 glViewport(0, 0, z.width, z.height);
290 g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][0],
291 g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][1],
292 g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][2],
296 /* When not using hw acceleration, gl will fault if we clear the depth
297 buffer bit on the first pass. The hack fix is to set the GL_DEPTH_BUFFER_BIT
298 only after Z_Draw() has been called once. Yeah, right. */
300 glbitClear |= GL_DEPTH_BUFFER_BIT;
302 glMatrixMode(GL_PROJECTION);
305 w = z.width/2 / z.scale;
306 h = z.height/2 / z.scale;
307 glOrtho (-w, w, z.origin[2]-h, z.origin[2]+h, -8, 8);
309 glDisable(GL_TEXTURE_2D);
310 glDisable(GL_TEXTURE_1D);
311 glDisable(GL_DEPTH_TEST);
324 glDisable(GL_CULL_FACE);
326 glShadeModel (GL_FLAT);
328 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
330 glDisable(GL_TEXTURE_2D);
332 glDisable(GL_DEPTH_TEST);
335 // draw filled interiors and edges
336 dir_up[0] = 0 ; dir_up[1] = 0; dir_up[2] = 1;
337 dir_down[0] = 0 ; dir_down[1] = 0; dir_down[2] = -1;
338 VectorCopy (z.origin, org_top);
340 VectorCopy (z.origin, org_bottom);
341 org_bottom[2] = -4096;
343 for (brush = active_brushes.next ; brush != &active_brushes ; brush=brush->next)
345 if (brush->mins[0] >= z.origin[0]
346 || brush->maxs[0] <= z.origin[0]
347 || brush->mins[1] >= z.origin[1]
348 || brush->maxs[1] <= z.origin[1])
351 if (!Brush_Ray (org_top, dir_down, brush, &top))
353 top = org_top[2] - top;
354 if (!Brush_Ray (org_bottom, dir_up, brush, &bottom))
356 bottom = org_bottom[2] + bottom;
358 q = Texture_ForName (brush->brush_faces->texdef.name);
359 glColor3f (q->color[0], q->color[1], q->color[2]);
361 glVertex2f (-xCam, bottom);
362 glVertex2f (xCam, bottom);
363 glVertex2f (xCam, top);
364 glVertex2f (-xCam, top);
368 glBegin (GL_LINE_LOOP);
369 glVertex2f (-xCam, bottom);
370 glVertex2f (xCam, bottom);
371 glVertex2f (xCam, top);
372 glVertex2f (-xCam, top);
377 // now draw selected brushes
379 for (brush = selected_brushes.next ; brush != &selected_brushes ; brush=brush->next)
381 if ( !(brush->mins[0] >= z.origin[0]
382 || brush->maxs[0] <= z.origin[0]
383 || brush->mins[1] >= z.origin[1]
384 || brush->maxs[1] <= z.origin[1]) )
386 if (Brush_Ray (org_top, dir_down, brush, &top))
388 top = org_top[2] - top;
389 if (Brush_Ray (org_bottom, dir_up, brush, &bottom))
391 bottom = org_bottom[2] + bottom;
393 q = Texture_ForName (brush->brush_faces->texdef.name);
394 glColor3f (q->color[0], q->color[1], q->color[2]);
396 glVertex2f (-xCam, bottom);
397 glVertex2f (xCam, bottom);
398 glVertex2f (xCam, top);
399 glVertex2f (-xCam, top);
406 glBegin (GL_LINE_LOOP);
407 glVertex2f (-xCam, brush->mins[2]);
408 glVertex2f (xCam, brush->mins[2]);
409 glVertex2f (xCam, brush->maxs[2]);
410 glVertex2f (-xCam, brush->maxs[2]);
418 QE_CheckOpenGLForErrors();
422 end = Sys_DoubleTime ();
423 Sys_Printf ("z: %i ms\n", (int)(1000*(end-start)));