Exemplo n.º 1
0
trace_t Test_Ray (vec3_t origin, vec3_t dir, int flags)
{
	brush_t	*brush;
	face_t	*face;
	float	dist;
	trace_t	t;

	memset (&t, 0, sizeof(t));
	t.dist = DIST_START;

	if (! (flags & SF_SELECTED_ONLY) )
		for (brush = active_brushes.next ; brush != &active_brushes ; brush=brush->next)
		{
			if ( (flags & SF_ENTITIES_FIRST) && brush->owner == world_entity)
				continue;
			if (FilterBrush (brush))
				continue;
			face = Brush_Ray (origin, dir, brush, &dist);
			if (dist > 0 && dist < t.dist)
			{
				t.dist		= dist;
				t.brush		= brush;
				t.face		= face;
				t.selected	= FALSE;
			}
		}

	for (brush = selected_brushes.next ; brush != &selected_brushes ; brush=brush->next)
	{
		if ( (flags & SF_ENTITIES_FIRST) && brush->owner == world_entity)
			continue;
		if (FilterBrush (brush))
			continue;
		face = Brush_Ray (origin, dir, brush, &dist);
		if (dist > 0 && dist < t.dist)
		{
			t.dist		= dist;
			t.brush		= brush;
			t.face		= face;
			t.selected	= TRUE;
		}
	}

	// if entites first, but didn't find any, check regular

	if ( (flags & SF_ENTITIES_FIRST) && t.brush == NULL)
		return Test_Ray (origin, dir, flags - SF_ENTITIES_FIRST);

	return t;
}
Exemplo n.º 2
0
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 ( b->pTerrain && !Terrain_Ray( start, dir, b, &d ) )
			continue;
		if ( !b->pTerrain && !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);
}
Exemplo n.º 3
0
/*
   ==============
   Z_Draw
   ==============
 */
void Z_Draw( void ){
#ifdef DBG_WINDOWPOS
	CheckWatchit( "Z_Draw" );
#endif
	brush_t   *brush;
	float w, h;
	double start, end;
	qtexture_t  *q;
	float top, bottom;
	vec3_t org_top, org_bottom, dir_up, dir_down;
	int xCam = z.width / 3;

	if ( !active_brushes.next ) {
		return; // not valid yet

	}
	if ( z.timing ) {
		start = Sys_DoubleTime();
	}

	//
	// clear
	//
	glViewport( 0, 0, z.width, z.height );

	glClearColor(
		g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][0],
		g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][1],
		g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][2],
		0 );

	/* GL Bug */
	/* When not using hw acceleration, gl will fault if we clear the depth
	   buffer bit on the first pass. The hack fix is to set the GL_DEPTH_BUFFER_BIT
	   only after Z_Draw() has been called once. Yeah, right. */
	glClear( glbitClear );
	glbitClear |= GL_DEPTH_BUFFER_BIT;
	glMatrixMode( GL_PROJECTION );

	glLoadIdentity();
	w = z.width / 2 / z.scale;
	h = z.height / 2 / z.scale;
	glOrtho( -w, w, z.origin[2] - h, z.origin[2] + h, -8, 8 );

	glDisable( GL_TEXTURE_2D );
	glDisable( GL_TEXTURE_1D );
	glDisable( GL_DEPTH_TEST );
	glDisable( GL_BLEND );


	//
	// now draw the grid
	//
	Z_DrawGrid();

	//
	// draw stuff
	//

	glDisable( GL_CULL_FACE );

	glShadeModel( GL_FLAT );

	glPolygonMode( GL_FRONT_AND_BACK, GL_FILL );

	glDisable( GL_TEXTURE_2D );
	glDisable( GL_BLEND );
	glDisable( GL_DEPTH_TEST );


	// draw filled interiors and edges
	dir_up[0] = 0 ; dir_up[1] = 0; dir_up[2] = 1;
	dir_down[0] = 0 ; dir_down[1] = 0; dir_down[2] = -1;
	VectorCopy( z.origin, org_top );
	org_top[2] = g_MaxWorldCoord;
	VectorCopy( z.origin, org_bottom );
	org_bottom[2] = g_MinWorldCoord;

	for ( brush = active_brushes.next ; brush != &active_brushes ; brush = brush->next )
	{
		if ( brush->bFiltered ) {
			continue;
		}

		if ( brush->mins[0] >= z.origin[0]
			 || brush->maxs[0] <= z.origin[0]
			 || brush->mins[1] >= z.origin[1]
			 || brush->maxs[1] <= z.origin[1] ) {
			continue;
		}

		if ( !Brush_Ray( org_top, dir_down, brush, &top ) ) {
			continue;
		}
		top = org_top[2] - top;
		if ( !Brush_Ray( org_bottom, dir_up, brush, &bottom ) ) {
			continue;
		}
		bottom = org_bottom[2] + bottom;

		q = brush->brush_faces->pShader->getTexture();
		glColor3f( q->color[0], q->color[1], q->color[2] );
		glBegin( GL_QUADS );
		glVertex2f( -xCam, bottom );
		glVertex2f( xCam, bottom );
		glVertex2f( xCam, top );
		glVertex2f( -xCam, top );
		glEnd();

		glColor3f( 1,1,1 );
		glBegin( GL_LINE_LOOP );
		glVertex2f( -xCam, bottom );
		glVertex2f( xCam, bottom );
		glVertex2f( xCam, top );
		glVertex2f( -xCam, top );
		glEnd();
	}

	//
	// now draw selected brushes
	//
	for ( brush = selected_brushes.next ; brush != &selected_brushes ; brush = brush->next )
	{
		if ( !( brush->mins[0] >= z.origin[0]
				|| brush->maxs[0] <= z.origin[0]
				|| brush->mins[1] >= z.origin[1]
				|| brush->maxs[1] <= z.origin[1] ) ) {
			if ( Brush_Ray( org_top, dir_down, brush, &top ) ) {
				top = org_top[2] - top;
				if ( Brush_Ray( org_bottom, dir_up, brush, &bottom ) ) {
					bottom = org_bottom[2] + bottom;

					q = brush->brush_faces->pShader->getTexture();
					glColor3f( q->color[0], q->color[1], q->color[2] );
					glBegin( GL_QUADS );
					glVertex2f( -xCam, bottom );
					glVertex2f( xCam, bottom );
					glVertex2f( xCam, top );
					glVertex2f( -xCam, top );
					glEnd();
				}
			}
		}

		glColor3fv( g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES] );
		glBegin( GL_LINE_LOOP );
		glVertex2f( -xCam, brush->mins[2] );
		glVertex2f( xCam, brush->mins[2] );
		glVertex2f( xCam, brush->maxs[2] );
		glVertex2f( -xCam, brush->maxs[2] );
		glEnd();
	}


	ZDrawCameraIcon();

	glFinish();
	QE_CheckOpenGLForErrors();

	if ( z.timing ) {
		end = Sys_DoubleTime();
		Sys_Printf( "z: %i ms\n", (int)( 1000 * ( end - start ) ) );
	}
}
Exemplo n.º 4
0
/*
 =======================================================================================================================
    Z_Draw
 =======================================================================================================================
 */
void Z_Draw(void) {
	brush_t		*brush;	
	float		top, bottom;
	idVec3		org_top, org_bottom, dir_up, dir_down;
	int			xCam = z.width / 3;

	if (!active_brushes.next) {
		return; // not valid yet
	}

	// clear
	glViewport(0, 0, z.width, z.height);
	glScissor(0, 0, z.width, z.height);

	glClearColor
	(
		g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][0],
		g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][1],
		g_qeglobals.d_savedinfo.colors[COLOR_GRIDBACK][2],
		0
	);

	/*
	 * GL Bug £
	 * When not using hw acceleration, gl will fault if we clear the depth buffer bit
	 * on the first pass. The hack fix is to set the GL_DEPTH_BUFFER_BIT only after
	 * Z_Draw() has been called once. Yeah, right. £
	 * glClear(glbitClear);
	 */
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

	//
	// glbitClear |= GL_DEPTH_BUFFER_BIT;
	// glClear(GL_DEPTH_BUFFER_BIT);
	//
	const float w = z.width / 2 / z.scale;
	const float h = z.height / 2 / z.scale;

  GL_ProjectionMatrix.LoadIdentity();
  GL_ProjectionMatrix.Ortho(-w, w, z.origin[2] - h, z.origin[2] + h, -8, 8);

	globalImages->BindNull();
	glDisable(GL_DEPTH_TEST);
	glDisable(GL_BLEND);

	// now draw the grid
	Z_DrawGrid();

	// draw stuff
	glDisable(GL_CULL_FACE);

	glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
  glLineWidth(1.0f);

	globalImages->BindNull();

	// draw filled interiors and edges
	dir_up[0] = 0;
	dir_up[1] = 0;
	dir_up[2] = 1;
	dir_down[0] = 0;
	dir_down[1] = 0;
	dir_down[2] = -1;
	VectorCopy(z.origin, org_top);
	org_top[2] = 4096;
	VectorCopy(z.origin, org_bottom);
	org_bottom[2] = -4096;

	for (brush = active_brushes.next; brush != &active_brushes; brush = brush->next) {
		if
		(
			brush->mins[0] >= z.origin[0] ||
			brush->maxs[0] <= z.origin[0] ||
			brush->mins[1] >= z.origin[1] ||
			brush->maxs[1] <= z.origin[1]
		) {
			continue;
		}

		if (!Brush_Ray(org_top, dir_down, brush, &top)) {
			continue;
		}

		top = org_top[2] - top;
		if (!Brush_Ray(org_bottom, dir_up, brush, &bottom)) {
			continue;
		}

		bottom = org_bottom[2] + bottom;

		//q = declManager->FindMaterial(brush->brush_faces->texdef.name);
    fhImmediateMode im;
		im.Color3f(brush->owner->eclass->color.x, brush->owner->eclass->color.y, brush->owner->eclass->color.z);
		im.Begin(GL_QUADS);
		im.Vertex2f(-xCam, bottom);
		im.Vertex2f(xCam, bottom);
		im.Vertex2f(xCam, top);
		im.Vertex2f(-xCam, top);
		im.End();
    
		im.Color3f(1, 1, 1);
		im.Begin(GL_LINE_LOOP);
		im.Vertex2f(-xCam, bottom);
		im.Vertex2f(xCam, bottom);
		im.Vertex2f(xCam, top);
		im.Vertex2f(-xCam, top);
		im.End();
	}

	// now draw selected brushes
  fhImmediateMode im;
	for (brush = selected_brushes.next; brush != &selected_brushes; brush = brush->next) {
		if
		(
			!(
				brush->mins[0] >= z.origin[0] ||
				brush->maxs[0] <= z.origin[0] ||
				brush->mins[1] >= z.origin[1] ||
				brush->maxs[1] <= z.origin[1]
			)
		) {
			if (Brush_Ray(org_top, dir_down, brush, &top)) {
				top = org_top[2] - top;
				if (Brush_Ray(org_bottom, dir_up, brush, &bottom)) {
					bottom = org_bottom[2] + bottom;

					//q = declManager->FindMaterial(brush->brush_faces->texdef.name);
					im.Color3f(brush->owner->eclass->color.x, brush->owner->eclass->color.y, brush->owner->eclass->color.z);
					im.Begin(GL_QUADS);
					im.Vertex2f(-xCam, bottom);
					im.Vertex2f(xCam, bottom);
					im.Vertex2f(xCam, top);
					im.Vertex2f(-xCam, top);
					im.End();
				}
			}
		}

		im.Color3fv(g_qeglobals.d_savedinfo.colors[COLOR_SELBRUSHES].ToFloatPtr());
		im.Begin(GL_LINE_LOOP);
		im.Vertex2f(-xCam, brush->mins[2]);
		im.Vertex2f(xCam, brush->mins[2]);
		im.Vertex2f(xCam, brush->maxs[2]);
		im.Vertex2f(-xCam, brush->maxs[2]);
		im.End();
	}

	ZDrawCameraIcon();
	ZDrawZClip();

	glFinish();
	QE_CheckOpenGLForErrors();
}
Exemplo n.º 5
0
trace_t Test_Ray( vec3_t origin, vec3_t dir, int flags )
{
	brush_s*    brush;
	face_s* face;
	float   dist;
	trace_t t;
	
	memset( &t, 0, sizeof( t ) );
	t.dist = DIST_START;
	
	if ( flags & SF_CYCLE )
	{
		CPtrArray array;
		brush_s* pToSelect = ( selected_brushes.next != &selected_brushes ) ? selected_brushes.next : NULL;
		Select_Deselect();
		
		// go through active brushes and accumulate all "hit" brushes
		for ( brush = active_brushes.next ; brush != &active_brushes ; brush = brush->next )
		{
			//if ( (flags & SF_ENTITIES_FIRST) && brush->owner == world_entity)
			//  continue;
			
			if ( FilterBrush( brush ) )
				continue;
				
			if ( !g_PrefsDlg.m_bSelectCurves && brush->patchBrush )
				continue;
				
			if ( !g_PrefsDlg.m_bSelectTerrain && brush->terrainBrush )
				continue;
				
			//if (!g_bShowPatchBounds && brush->patchBrush)
			//  continue;
			
			face = Brush_Ray( origin, dir, brush, &dist );
			
			if ( face )
			{
				array.Add( brush );
			}
		}
		
		int nSize = array.GetSize();
		if ( nSize > 0 )
		{
			bool bFound = false;
			for ( int i = 0; i < nSize; i++ )
			{
				brush_s* b = reinterpret_cast<brush_s*>( array.GetAt( i ) );
				// did we hit the last one selected yet ?
				if ( b == pToSelect )
				{
					// yes we want to select the next one in the list
					int n = ( i > 0 ) ? i - 1 : nSize - 1;
					pToSelect = reinterpret_cast<brush_s*>( array.GetAt( n ) );
					bFound = true;
					break;
				}
			}
			if ( !bFound )
				pToSelect = reinterpret_cast<brush_s*>( array.GetAt( 0 ) );
		}
		if ( pToSelect )
		{
			face = Brush_Ray( origin, dir, pToSelect, &dist );
			
			t.dist = dist;
			t.brush = pToSelect;
			t.face = face;
			t.selected = false;
			return t;
		}
	}
	
	if ( !( flags & SF_SELECTED_ONLY ) )
	{
		for ( brush = active_brushes.next ; brush != &active_brushes ; brush = brush->next )
		{
			if ( ( flags & SF_ENTITIES_FIRST ) && brush->owner == world_entity )
				continue;
				
			if ( FilterBrush( brush ) )
				continue;
				
			if ( !g_PrefsDlg.m_bSelectCurves && brush->patchBrush )
				continue;
				
			if ( !g_PrefsDlg.m_bSelectTerrain && brush->terrainBrush )
				continue;
				
			//if (!g_bShowPatchBounds && brush->patchBrush)
			//  continue;
			
			face = Brush_Ray( origin, dir, brush, &dist );
			if ( dist > 0 && dist < t.dist )
			{
				t.dist = dist;
				t.brush = brush;
				t.face = face;
				t.selected = false;
			}
		}
	}
	
	
	for ( brush = selected_brushes.next ; brush != 0 && brush != &selected_brushes ; brush = brush->next )
	{
		if ( ( flags & SF_ENTITIES_FIRST ) && brush->owner == world_entity )
			continue;
			
		if ( FilterBrush( brush ) )
			continue;
			
		if ( !g_PrefsDlg.m_bSelectCurves && brush->patchBrush )
			continue;
			
		if ( !g_PrefsDlg.m_bSelectTerrain && brush->terrainBrush )
			continue;
			
		face = Brush_Ray( origin, dir, brush, &dist );
		if ( dist > 0 && dist < t.dist )
		{
			t.dist = dist;
			t.brush = brush;
			t.face = face;
			t.selected = true;
		}
	}
	
	// if entites first, but didn't find any, check regular
	
	if ( ( flags & SF_ENTITIES_FIRST ) && t.brush == NULL )
		return Test_Ray( origin, dir, flags - SF_ENTITIES_FIRST );
		
	return t;
	
}