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 ===========================================================================
27 void DrawPathLines (void);
38 // camera.draw_mode = cd_texture;
39 // camera.draw_mode = cd_solid;
40 // camera.draw_mode = cd_wire;
42 camera.timing = false;
45 camera.origin[1] = 20;
46 camera.origin[2] = 46;
48 camera.color[0] = 0.3;
49 camera.color[1] = 0.3;
50 camera.color[2] = 0.3;
54 //============================================================================
56 void Cam_BuildMatrix (void)
62 xa = camera.angles[0]/180*Q_PI;
63 ya = camera.angles[1]/180*Q_PI;
65 // the movement matrix is kept 2d
67 camera.forward[0] = cos(ya);
68 camera.forward[1] = sin(ya);
69 camera.right[0] = camera.forward[1];
70 camera.right[1] = -camera.forward[0];
72 glGetFloatv (GL_PROJECTION_MATRIX, &matrix[0][0]);
76 camera.vright[i] = matrix[i][0];
77 camera.vup[i] = matrix[i][1];
78 camera.vpn[i] = matrix[i][2];
81 VectorNormalize (camera.vright);
82 VectorNormalize (camera.vup);
83 VectorNormalize (camera.vpn);
86 //===============================================
93 void Cam_ChangeFloor (qboolean up)
96 float d, bestd, current;
99 start[0] = camera.origin[0];
100 start[1] = camera.origin[1];
105 current = 8192 - (camera.origin[2] - 48);
111 for (b=active_brushes.next ; b != &active_brushes ; b=b->next)
113 if (!Brush_Ray (start, dir, b, &d))
115 if (up && d < current && d > bestd)
117 if (!up && d > current && d < bestd)
121 if (bestd == 0 || bestd == 16384)
124 camera.origin[2] += current - bestd;
125 Sys_UpdateWindows (W_CAMERA|W_Z_OVERLAY);
129 //===============================================
132 static int buttonx, buttony;
133 static int cursorx, cursory;
137 #define ANGLE_SPEED 300
138 #define MOVE_SPEED 400
145 void Cam_PositionDrag (void)
149 Sys_GetCursorPos (&x, &y);
150 if (x != cursorx || y != cursory)
153 VectorMA (camera.origin, x, camera.vright, camera.origin);
155 camera.origin[2] -= y;
157 Sys_SetCursorPos (cursorx, cursory);
158 Sys_UpdateWindows (W_CAMERA | W_XY_OVERLAY);
167 void Cam_MouseControl (float dtime)
173 if (cambuttonstate != MK_RBUTTON)
176 xf = (float)(buttonx - camera.width/2) / (camera.width/2);
177 yf = (float)(buttony - camera.height/2) / (camera.height/2);
181 yl = camera.height/3;
186 if (buttony < yl && (buttonx < xl || buttonx > xh))
187 VectorMA (camera.origin, xf*dtime*MOVE_SPEED, camera.right, camera.origin);
191 xf *= 1.0 - fabs(yf);
205 VectorMA (camera.origin, yf*dtime*MOVE_SPEED, camera.forward, camera.origin);
206 camera.angles[YAW] += xf*-dtime*ANGLE_SPEED;
208 Sys_UpdateWindows (W_CAMERA|W_XY_OVERLAY);
219 void Cam_MouseDown (int x, int y, int buttons)
226 // calc ray direction
228 u = (float)(y - camera.height/2) / (camera.width/2);
229 r = (float)(x - camera.width/2) / (camera.width/2);
232 for (i=0 ; i<3 ; i++)
233 dir[i] = camera.vpn[i] * f + camera.vright[i] * r + camera.vup[i] * u;
234 VectorNormalize (dir);
236 Sys_GetCursorPos (&cursorx, &cursory);
238 cambuttonstate = buttons;
242 // LBUTTON = manipulate selection
243 // shift-LBUTTON = select
244 // middle button = grab texture
245 // ctrl-middle button = set entire brush to texture
246 // ctrl-shift-middle button = set single face to texture
247 if ( (buttons == MK_LBUTTON)
248 || (buttons == (MK_LBUTTON | MK_SHIFT))
249 || (buttons == (MK_LBUTTON | MK_CONTROL))
250 || (buttons == (MK_LBUTTON | MK_CONTROL | MK_SHIFT))
251 || (buttons == MK_MBUTTON)
252 || (buttons == (MK_MBUTTON|MK_CONTROL))
253 || (buttons == (MK_MBUTTON|MK_SHIFT|MK_CONTROL)) )
255 Drag_Begin (x, y, buttons,
256 camera.vright, camera.vup,
261 if (buttons == MK_RBUTTON)
263 Cam_MouseControl (0.1);
273 void Cam_MouseUp (int x, int y, int buttons)
285 void Cam_MouseMoved (int x, int y, int buttons)
287 cambuttonstate = buttons;
293 if (buttons == (MK_RBUTTON|MK_CONTROL) )
296 Sys_UpdateWindows (W_XY|W_CAMERA|W_Z);
300 Sys_GetCursorPos (&cursorx, &cursory);
302 if (buttons & (MK_LBUTTON | MK_MBUTTON) )
304 Drag_MouseMoved (x, y, buttons);
305 Sys_UpdateWindows (W_XY|W_CAMERA|W_Z);
311 int cullv1[3], cullv2[3];
317 VectorSubtract (camera.vpn, camera.vright, cull1);
318 VectorAdd (camera.vpn, camera.vright, cull2);
320 for (i=0 ; i<3 ; i++)
333 qboolean CullBrush (brush_t *b)
339 for (i=0 ; i<3 ; i++)
340 point[i] = b->mins[cullv1[i]] - camera.origin[i];
342 d = DotProduct (point, cull1);
346 for (i=0 ; i<3 ; i++)
347 point[i] = b->mins[cullv2[i]] - camera.origin[i];
349 d = DotProduct (point, cull2);
371 if (!active_brushes.next)
372 return; // not valid yet
375 start = Sys_DoubleTime ();
380 QE_CheckOpenGLForErrors();
382 glViewport(0, 0, camera.width, camera.height);
383 glScissor(0, 0, camera.width, camera.height);
385 g_qeglobals.d_savedinfo.colors[COLOR_CAMERABACK][0],
386 g_qeglobals.d_savedinfo.colors[COLOR_CAMERABACK][1],
387 g_qeglobals.d_savedinfo.colors[COLOR_CAMERABACK][2],
389 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
394 glMatrixMode(GL_PROJECTION);
397 screenaspect = (float)camera.width/camera.height;
398 yfov = 2*atan((float)camera.height/camera.width)*180/Q_PI;
399 gluPerspective (yfov, screenaspect, 2, 8192);
401 glRotatef (-90, 1, 0, 0); // put Z going up
402 glRotatef (90, 0, 0, 1); // put Z going up
403 glRotatef (camera.angles[0], 0, 1, 0);
404 glRotatef (-camera.angles[1], 0, 0, 1);
405 glTranslatef (-camera.origin[0], -camera.origin[1], -camera.origin[2]);
415 switch (camera.draw_mode)
418 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
419 glDisable(GL_TEXTURE_2D);
420 glDisable(GL_TEXTURE_1D);
422 glDisable(GL_DEPTH_TEST);
423 glColor3f(1.0, 1.0, 1.0);
424 // glEnable (GL_LINE_SMOOTH);
428 glCullFace(GL_FRONT);
429 glEnable(GL_CULL_FACE);
430 glShadeModel (GL_FLAT);
432 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
433 glDisable(GL_TEXTURE_2D);
436 glEnable(GL_DEPTH_TEST);
437 glDepthFunc (GL_LEQUAL);
441 glCullFace(GL_FRONT);
442 glEnable(GL_CULL_FACE);
444 glShadeModel (GL_FLAT);
446 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
447 glEnable(GL_TEXTURE_2D);
449 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
450 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
451 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
453 glEnable(GL_DEPTH_TEST);
454 glDepthFunc (GL_LEQUAL);
459 GLfloat fogColor[4] = {0.0, 1.0, 0.0, 0.25};
461 glFogi (GL_FOG_MODE, GL_LINEAR);
462 glHint (GL_FOG_HINT, GL_NICEST); /* per pixel */
463 glFogf (GL_FOG_START, -8192);
464 glFogf (GL_FOG_END, 65536);
465 glFogfv (GL_FOG_COLOR, fogColor);
473 glCullFace(GL_FRONT);
474 glEnable(GL_CULL_FACE);
476 glShadeModel (GL_FLAT);
478 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
479 glEnable(GL_TEXTURE_2D);
481 glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
482 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
483 glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
484 glDisable(GL_DEPTH_TEST);
486 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
490 glMatrixMode(GL_TEXTURE);
491 for (brush = active_brushes.next ; brush != &active_brushes ; brush=brush->next)
493 if (CullBrush (brush))
495 if (FilterBrush (brush))
500 glMatrixMode(GL_PROJECTION);
503 // now draw selected brushes
506 glTranslatef (g_qeglobals.d_select_translate[0], g_qeglobals.d_select_translate[1], g_qeglobals.d_select_translate[2]);
507 glMatrixMode(GL_TEXTURE);
510 for (brush = selected_brushes.next ; brush != &selected_brushes ; brush=brush->next)
516 glMatrixMode(GL_PROJECTION);
518 glColor4f(1.0, 0.0, 0.0, 0.3);
520 glPolygonMode (GL_FRONT_AND_BACK, GL_FILL);
521 glBlendFunc (GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
522 glDisable (GL_TEXTURE_2D);
523 for (brush = selected_brushes.next ; brush != &selected_brushes ; brush=brush->next)
524 for (face=brush->brush_faces ; face ; face=face->next)
527 Face_Draw(selected_face);
529 // non-zbuffered outline
531 glDisable (GL_BLEND);
532 glDisable (GL_DEPTH_TEST);
533 glPolygonMode (GL_FRONT_AND_BACK, GL_LINE);
535 for (brush = selected_brushes.next ; brush != &selected_brushes ; brush=brush->next)
536 for (face=brush->brush_faces ; face ; face=face->next)
539 // edge / vertex flags
541 if (g_qeglobals.d_select_mode == sel_vertex)
546 for (i=0 ; i<g_qeglobals.d_numpoints ; i++)
547 glVertex3fv (g_qeglobals.d_points[i]);
551 else if (g_qeglobals.d_select_mode == sel_edge)
558 for (i=0 ; i<g_qeglobals.d_numedges ; i++)
560 v1 = g_qeglobals.d_points[g_qeglobals.d_edges[i].p1];
561 v2 = g_qeglobals.d_points[g_qeglobals.d_edges[i].p2];
562 glVertex3f ( (v1[0]+v2[0])*0.5,(v1[1]+v2[1])*0.5,(v1[2]+v2[2])*0.5);
571 glEnable(GL_DEPTH_TEST);
575 if (g_qeglobals.d_pointfile_display_list)
578 // glCallList (g_qeglobals.d_pointfile_display_list);
581 // bind back to the default texture so that we don't have problems
582 // elsewhere using/modifying texture maps between contexts
583 glBindTexture( GL_TEXTURE_2D, 0 );
586 QE_CheckOpenGLForErrors();
590 end = Sys_DoubleTime ();
591 Sys_Printf ("Camera: %i ms\n", (int)(1000*(end-start)));