void C_QUA_Strider::DrawHudElements( )
{
	CHudTexture *pIcon;
	//int iIconX, iIconY;


		// draw crosshairs for vehicle gun
		pIcon = gHUD.GetIcon( "gunhair" );

		if ( pIcon != NULL )
		{
			float x, y;
			Vector screen;

			x = ScreenWidth()/2;
			y = ScreenHeight()/2;

		
			ScreenTransform( m_vecGunCrosshair, screen );
			x += 0.5 * screen[0] * ScreenWidth() + 0.5;
			y -= 0.5 * screen[1] * ScreenHeight() + 0.5;

			x -= pIcon->Width() / 2; 
			y -= pIcon->Height() / 2; 
			bool unable;
			unable=false;
			Color	clr = ( unable ) ? gHUD.m_clrCaution : gHUD.m_clrNormal;
			pIcon->DrawSelf( x, y, clr );
		}

	// Aqui pondremos el crosshair
}
Beispiel #2
0
//-----------------------------------------------------------------------------
// Purpose: Get the x & y positions of a world position in screenspace
//			Returns true if it's onscreen
//-----------------------------------------------------------------------------
bool GetVectorInScreenSpace( Vector pos, int& iX, int& iY, Vector *vecOffset )
{
	Vector screen;

	// Apply the offset, if one was specified
	if ( vecOffset != NULL )
		pos += *vecOffset;

	// Transform to screen space
	int iFacing = ScreenTransform( pos, screen );
	iX =  0.5 * screen[0] * ScreenWidth();
	iY = -0.5 * screen[1] * ScreenHeight();
	iX += 0.5 * ScreenWidth();
	iY += 0.5 * ScreenHeight();

	// Make sure the player's facing it
	if ( iFacing )
	{
		// We're actually facing away from the Target. Stomp the screen position.
		iX = -640;
		iY = -640;
		return false;
	}

	return true;
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pMaterial - 
//			source - 
//			color - 
//-----------------------------------------------------------------------------
void DrawHaloOriented( const Vector& source, float scale, float const *color, float roll )
{
	Vector point, screen;
	
	CMatRenderContextPtr pRenderContext( materials );
	IMesh* pMesh = pRenderContext->GetDynamicMesh();

	CMeshBuilder meshBuilder;
	meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );

	// Transform source into screen space
	ScreenTransform( source, screen );

	Vector right, up;
	float sr, cr;

	SinCos( roll, &sr, &cr );

	for ( int i = 0; i < 3; i++ )
	{
		right[i] = CurrentViewRight()[i] * cr + CurrentViewUp()[i] * sr;
		up[i] = CurrentViewRight()[i] * -sr + CurrentViewUp()[i] * cr;
	}

	meshBuilder.Color3fv (color);
	meshBuilder.TexCoord2f (0, 0, 1);
	VectorMA (source, -scale, up, point);
	VectorMA (point, -scale, right, point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv (color);
	meshBuilder.TexCoord2f (0, 0, 0);
	VectorMA (source, scale, up, point);
	VectorMA (point, -scale, right, point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv (color);
	meshBuilder.TexCoord2f (0, 1, 0);
	VectorMA (source, scale, up, point);
	VectorMA (point, scale, right, point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv (color);
	meshBuilder.TexCoord2f (0, 1, 1);
	VectorMA (source, -scale, up, point);
	VectorMA (point, scale, right, point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();
	
	meshBuilder.End();
	pMesh->Draw();
}
Beispiel #4
0
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pMaterial - 
//			source - 
//			color - 
//-----------------------------------------------------------------------------
void DrawHalo(IMaterial* pMaterial, const Vector& source, float scale, float const* color, float flHDRColorScale )
{
	static unsigned int nHDRColorScaleCache = 0;
	Vector		point, screen;
	
	if( pMaterial )
	{
		IMaterialVar *pHDRColorScaleVar = pMaterial->FindVarFast( "$hdrcolorscale", &nHDRColorScaleCache );
		if( pHDRColorScaleVar )
		{
			pHDRColorScaleVar->SetFloatValue( flHDRColorScale );
		}
	}

	CMatRenderContextPtr pRenderContext( materials );
	IMesh* pMesh = pRenderContext->GetDynamicMesh( );

	CMeshBuilder meshBuilder;
	meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );

	// Transform source into screen space
	ScreenTransform( source, screen );

	meshBuilder.Color3fv (color);
	meshBuilder.TexCoord2f (0, 0, 1);
	VectorMA (source, -scale, CurrentViewUp(), point);
	VectorMA (point, -scale, CurrentViewRight(), point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv (color);
	meshBuilder.TexCoord2f (0, 0, 0);
	VectorMA (source, scale, CurrentViewUp(), point);
	VectorMA (point, -scale, CurrentViewRight(), point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv (color);
	meshBuilder.TexCoord2f (0, 1, 0);
	VectorMA (source, scale, CurrentViewUp(), point);
	VectorMA (point, scale, CurrentViewRight(), point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv (color);
	meshBuilder.TexCoord2f (0, 1, 1);
	VectorMA (source, -scale, CurrentViewUp(), point);
	VectorMA (point, scale, CurrentViewRight(), point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();
	
	meshBuilder.End();
	pMesh->Draw();
}
Beispiel #5
0
bool CNeeded::WorldToScreen( const Vector &vOrigin, Vector &vScreen )
 {
	if( ScreenTransform(vOrigin , vScreen) == false ){
		int iScreenWidth, iScreenHeight;
		g_pEngine->GetScreenSize( iScreenWidth, iScreenHeight );
		float x = iScreenWidth / 2;
		float y = iScreenHeight / 2;
		x += 0.5 * vScreen.x * iScreenWidth + 0.5;
		y -= 0.5 * vScreen.y * iScreenHeight + 0.5;
		vScreen.x = x;
		vScreen.y = y;
		return true;
	}
	return false;
} 
Beispiel #6
0
bool CNeeded::TransformVector( Vector v, Vector &s )
{
	if( ScreenTransform( v, s ) == false ){
		int sw, sh;
		g_pEngine->GetScreenSize( sw, sh );
		float x = sw / 2;
		float y = sh / 2;
		x += 0.5 * s.x * sw + 0.5;
		y -= 0.5 * s.y * sh + 0.5;
		s.x = x;
		s.y = y;
		return true;
	}
	return false;
}
void vParticleOperator_GravityWorld::Simulate( vParticle *parent )
{
	float dot_z = DotProduct( MainViewForward(), Vector( 0, 0, -1 ) );
	float rotation_dir = Sign( dot_z );

	int vx, vy, w, t;
	vgui::surface()->GetFullscreenViewport( vx, vy, w, t );

	Vector screen;
	if ( ScreenTransform( MainViewOrigin() + Vector( 0, 0, 100 ), screen ) )
		ScreenTransform( MainViewOrigin() - Vector( 0, 0, 100 ), screen );

	screen *= Vector( 0.5f, -0.5f, 0 );
	screen += Vector( 0.5f, 0.5f, 0 );

	Vector2D gravity_center( w * screen.x, t * screen.y );
	Vector2D delta = parent->vecPos - gravity_center;

	float screenLength = delta.NormalizeInPlace();
	delta *= rotation_dir * -1.0f;

	Vector2D accel = delta * vParticle::GetRelativeScale() * GetImpulse( parent ) * amt;

	float speedMult = 1.0f;

	if ( rotation_dir > 0 )
	{
		float drag = RemapValClamped( rotation_dir, 0.5f, 1, 1, 0.00001f );
		ScaleByFrametime( drag );

		speedMult = RemapValClamped( (screenLength/vParticle::GetRelativeScale()), 0, 1000, 0, 1 ) * (1.0f - drag) + drag;
	}

	parent->vecVelocity += accel;
	parent->vecVelocity *= speedMult;
}
Beispiel #8
0
		SDK::Vector WorldToScreen( const SDK::Vector &origin ) {
			SDK::Vector screen;
			if(!ScreenTransform( origin, screen )) {
				int iScreenWidth, iScreenHeight;
				SDK::Interfaces::g_pEngine->GetScreenSize( iScreenWidth, iScreenHeight );

				float fScreenX = iScreenWidth / 2.0f;
				float fScreenY = iScreenHeight / 2.0f;

				fScreenX += 0.5f * screen.x * iScreenWidth + 0.5f;
				fScreenY -= 0.5f * screen.y * iScreenHeight + 0.5f;

				screen.x = fScreenX;
				screen.y = fScreenY;
			}
			return screen;
		}
bool CGodRaysEffect::SetMaterialParms( const Vector& vLightPos )
{
	int nSunX, nSunY;
	bool bOnScreen = GetVectorInHudSpace( vLightPos, nSunX, nSunY );

	if( bOnScreen )
	{
		// Set the material parameters.
		m_pGrDecayVar->SetFloatValue( gfx_gr_decay.GetFloat() );
		m_pGrDensityVar->SetFloatValue( gfx_gr_density.GetFloat() );
		m_pGrExposureVar->SetFloatValue( gfx_gr_exposure.GetFloat() );
		m_pGrWeightVar->SetFloatValue( gfx_gr_weight.GetFloat() );

		// Set the sun position.
		float flSunX = float( nSunX ) / float( ScreenWidth() );
		float flSunY = float( nSunY ) / float( ScreenHeight() );
		m_pGrSunPosVar->SetVecValue(flSunX, flSunY);
	}

	return bOnScreen;
#if 0
	// Convert from 3d to 2d.
	Vector vLightPos2d;
	int behind = ScreenTransform( vLightPos, vLightPos2d );

	if( behind == 0 )
	{
		m_pGrDecayVar->SetFloatValue( gfx_gr_decay.GetFloat() );
		m_pGrDensityVar->SetFloatValue( gfx_gr_density.GetFloat() );
		m_pGrExposureVar->SetFloatValue( gfx_gr_exposure.GetFloat() );
		m_pGrWeightVar->SetFloatValue( gfx_gr_weight.GetFloat() );
		
		int sunX, sunY;
		GetVectorInScreenSpace( vLightPos, sunX, sunY );
		m_pGrSunPosVar->SetVecValue( sunX / ScreenWidth(), sunY / ScreenHeight() );

		return true;
	}

	return false;
#endif
}
Beispiel #10
0
bool WorldToScreen(const Vector &origin, Vector &screen)
{
	bool ret = false;

	if (!ScreenTransform(origin, screen))
	{
		int width, height;
		structs.engine->GetScreenSize(&width, &height);

		fScreenX = int(width / 2);
		fScreenY = int(height / 2);

		fScreenX += 0.5f * screen.x * width + 0.5f;
		fScreenY -= 0.5f * screen.y * height + 0.5f;

		screen.x = fScreenX;
		screen.y = fScreenY;

		ret = true;
	}

	return ret;
}
Beispiel #11
0
void
PointerMotionAction(Graph *graph, XPointerMovedEvent *motionevent)
{
    int     sx2, sy2;
    int     sx1, sy1;
    int     button;
    float   x1, y1;
    float   x2, y2;
    float   x, y;


    /*
     * get the location of the cursor
     */

    sx2 = motionevent->x;
    sy2 = motionevent->y;

    /*
     * get the button pressed
     */

    button = (motionevent->state & 0xFF00) >> 8;

    switch (ButtonMode())
    {
    case PINCHMODE:
        /*
         * pinch at the cursor location
         */

        WorldTransform(graph, sx2, sy2, &x2, &y2);
        NBShowCoords((BasicWindow *)graph->frame->text,
                     0, graph->fontheight, x2, y2);
        break;

    case TEXTMODE:
        /*
         * if its in text mode then read out the cursor location
         */

        ShowCursorCoords((BasicWindow *)graph->frame->text,
                         0, graph->fontheight, sx2, sy2);
        break;

    case DRAWMODE:
        /*
         * If it's in screen coord mode then read out the cursor location.
         */

        switch (button)
        {
        case 1:     /* draw line */
            if (graph->dragx1 != -1)
            {
                if (graph->dragx2 != -1)
                {
                    /*
                     * erase the old drag line from the starting drag
                     * coordinates drag->x1, y1 to the previous end
                     * coordinates drag->x2, y2.
                     */

                    EraseSuperLine((BasicWindow *)graph,
                                   graph->dragx1, graph->dragy1,
                                   graph->dragx2, graph->dragy2);
                }

                /*
                 * get the world coordinates of the initial drag point
                 */

                x1 = graph->dragwx1;
                y1 = graph->dragwy1;

                /*
                 * get the world coordinates of the current cursor
                 * location
                 */

                WorldTransform(graph, sx2, sy2, &x2, &y2);

                /*
                 * update the drag coordinates to the current location
                 */

                graph->dragx2 = sx2;
                graph->dragy2 = sy2;

                /*
                 * display data about the line between the points in the
                 * text window
                 */

                ShowSlopeCoords((BasicWindow *)graph->frame->text,
                                0, graph->fontheight, x1,
                                y1, x2, y2);

                /*
                 * draw the new drag line
                 */

                DrawSuperLine((BasicWindow *)graph,
                              graph->dragx1, graph->dragy1, graph->dragx2,
                              graph->dragy2);
            }

            break;
        }

        break;

    case DATAMODE:
        switch (button)
        {
        case 1:     /* zoom box */
            if (graph->dragx1 != -1)
            {
                if (graph->dragx2 != -1)
                {
                    /*
                     * erase the old drag rectangle
                     */

                    EraseSuperBox((BasicWindow *)graph,
                                  graph->dragx1, graph->dragy1,
                                  graph->dragx2, graph->dragy2);
                }

                graph->dragx2 = sx2;
                graph->dragy2 = sy2;

                /*
                 * draw the new drag rectangle
                 */

                DrawSuperBox((BasicWindow *)graph,
                             graph->dragx1, graph->dragy1,
                             graph->dragx2, graph->dragy2);
            }

            break;

        case 2:     /* ruler line */
            if (graph->dragx1 != -1)
            {
                if (graph->dragx2 != -1)
                {
                    /*
                     * erase the old drag line from the starting drag
                     * coordinates drag->x1, y1 to the previous end
                     * coordinates drag->x2, y2.
                     */

                    EraseSuperLine((BasicWindow *)graph,
                                   graph->dragx1, graph->dragy1,
                                   graph->dragx2, graph->dragy2);
                }

                /*
                 * get the world coordinates of the initial drag point
                 */

                x1 = graph->dragwx1;
                y1 = graph->dragwy1;

                if (snapmode)
                {
                    /*
                     * get the data coordinates closest to the current cursor
                     * location
                     */

                    Snap(graph, sx2, sy2, &x2, &y2);

                    /*
                     * compute the screen coordinate of the data point
                     */

                    ScreenTransform(graph, x2, y2, &sx1, &sy1);

                    /*
                     * update the drag coordinates to the current location
                     */

                    graph->dragx2 = sx1;
                    graph->dragy2 = sy1;
                }
                else
                {
                    /*
                     * get the world coordinates of the current cursor
                     * location
                     */

                    WorldTransform(graph, sx2, sy2, &x2, &y2);

                    /*
                     * update the drag coordinates to the current location
                     */

                    graph->dragx2 = sx2;
                    graph->dragy2 = sy2;
                }

                /*
                 * display data about the line between the points in the
                 * text window
                 */

                ShowSlopeCoords((BasicWindow *)graph->frame->text,
                                0, graph->fontheight, x1,
                                y1, x2, y2);
                /*
                 * draw the new drag line
                 */

                DrawSuperLine((BasicWindow *)graph,
                              graph->dragx1, graph->dragy1, graph->dragx2,
                              graph->dragy2);
            }

            break;

        case 4:
            /*
             * get the data point whose screen x coordinate is closest to the
             * current cursor location
             */

            Snap(graph, sx2, sy2, &x, &y);

            /*
             * compute the screen coordinate of the data point
             */

            ScreenTransform(graph, x, y, &sx1, &sy1);

            /*
             * erase the previous line
             */

            EraseSuperLine((BasicWindow *)graph,
                           graph->dragx2, graph->dragy2, graph->dragx2,
                           graph->dragy1);

            /*
             * and draw a new line using the x coordinate of the data point
             * and the y coordinates of the cursor and the data point
             */

            graph->dragx1 = sx2;
            graph->dragy1 = sy2;
            graph->dragx2 = sx1;
            graph->dragy2 = sy1;
            DrawSuperLine((BasicWindow *)graph, sx1, sy1, sx1, sy2);

            /*
             * display the data coordinates in the text window
             */

            NBShowCoords((BasicWindow *)graph->frame->text,
                         0, graph->fontheight, x, y);
            break;
        }

        break;
    }
}
Beispiel #12
0
void
ButtonReleaseAction(Graph *graph, XButtonReleasedEvent *buttonevent)
{
    int     button;
    int     sx2, sy2;
    int     sx1, sy1;
    float   x1, y1, x2, y2;

    button = buttonevent->button;
    sx2 = buttonevent->x;
    sy2 = buttonevent->y;
    switch (ButtonMode())
    {
    case DATAMODE:
        switch (button)
        {
        case 1:     /* zoom box */
            /*
             * mark the end of the drag and zoom
             */

            graph->dragx2 = sx2;
            graph->dragy2 = sy2;
            WorldTransform(graph, graph->dragx1, graph->dragy1, &x1, &y1);
            WorldTransform(graph, graph->dragx2, graph->dragy2, &x2, &y2);

            /*
             * Don't perform a zero scale action.
             */

            if (x2 == x1 || y2 == y1)
                return;

            if (x2 > x1)
            {
                graph->wxmin = x1;
                graph->wxmax = x2;
            }
            else
            {
                graph->wxmin = x2;
                graph->wxmax = x1;
            }

            if (y2 > y1)
            {
                graph->wymin = y1;
                graph->wymax = y2;
            }
            else
            {
                graph->wymin = y2;
                graph->wymax = y1;
            }

            ScaleAndRefreshGraph(graph);
            /*
             * set the drag coords back to the invalid state
             */
            graph->dragx1 = -1;
            graph->dragx2 = -1;
            break;

        case 2:     /* ruler line */
            /*
             * get the world coordinates of the starting point
             */

            x1 = graph->dragwx1;
            y1 = graph->dragwy1;

            if (sx2 != graph->dragx1 || sy2 != graph->dragy1)
            {
                if (snapmode)
                {
                    /*
                     * display the final coords
                     */

                    Snap(graph, sx2, sy2, &x2, &y2);

                    /*
                     * compute the screen coordinate of the data point
                     */

                    ScreenTransform(graph, x2, y2, &sx1, &sy1);
                    ShowCoords((BasicWindow *)graph, sx1, sy1, x2, y2);
                }
                else
                {
                    /*
                     * display the final coords
                     */

                    WorldTransform(graph, sx2, sy2, &x2, &y2);
                    ShowCoords((BasicWindow *)graph, sx2, sy2, x2, y2);
                }

                ClearWindow((BasicWindow *)graph->frame->text);
                ShowSlope((BasicWindow *)graph->frame->text,
                          0, graph->fontheight,
                          x1, y1, x2, y2);
                AddLabelLine((BasicWindow *)graph, 0, 0, 0, 0,
                             x1, y1, x2, y2, WORLD_LBL, TEMPORARY_LBL);
            }

            /*
             * set the drag coords back to the invalid state
             */

            graph->dragx1 = -1;
            graph->dragx2 = -1;
            break;

        case 3:     /* drag line */
            /*
             * erase the old line
             */

            EraseSuperLine((BasicWindow *)graph, graph->dragx2,
                           graph->dragy1, graph->dragx2, graph->dragy2);

            /*
             * get the coords
             */

            Snap(graph, sx2, sy2, &x2, &y2);
            ShowCoords((BasicWindow *)graph,
                       graph->dragx2, graph->dragy2, x2, y2);
            graph->dragx1 = -1;
            graph->dragx2 = -1;
            break;
        }

        break;

    case DRAWMODE:
        switch (button)
        {
        case 1:     /* draw line */
            /*
             * mark the end of the drag and zoom
             */

            graph->dragx2 = sx2;
            graph->dragy2 = sy2;
            WorldTransform(graph, graph->dragx1, graph->dragy1, &x1, &y1);
            WorldTransform(graph, graph->dragx2, graph->dragy2, &x2, &y2);

            /*
             * draw a line between the points
             */

            AddLabelLine((BasicWindow *)graph,
                         0, 0, 0, 0,
                         x1, y1, x2, y2, WORLD_LBL, TEMPORARY_LBL);

            /*
             * set the drag coords back to the invalid state
             */

            graph->dragx1 = -1;
            graph->dragx2 = -1;
            break;
        }

        break;
    }
}
Beispiel #13
0
void
ButtonPressAction(Graph *graph, XButtonPressedEvent *buttonevent)
{
    float   x, y;
    int     sx1, sy1;
    int     sx2, sy2;
    int     button;

    sx1 = buttonevent->x;
    sy1 = buttonevent->y;
    button = buttonevent->button;

    switch (ButtonMode())
    {
    case DATAMODE:
        switch (button)
        {
        case 1:
            /*
             * mark the start of the drag location
             */
            graph->dragx1 = sx1;
            graph->dragy1 = sy1;
            break;

        case 2:
            ClearWindow((BasicWindow *)graph->frame->text);

            if (snapmode)
            {
                /*
                 * world coord xy readout of data
                 */

                Snap(graph, sx1, sy1, &x, &y);

                /*
                 * get the screen coords of the data point
                 */

                ScreenTransform(graph, x, y, &sx2, &sy2);
                ShowCoords((BasicWindow *)graph, sx2, sy2, x, y);

                /*
                 * mark the start of the drag location
                 */

                graph->dragx1 = sx2;
                graph->dragy1 = sy2;
            }
            else
            {
                /*
                 * world coord xy readout of cursor location
                 */

                WorldTransform(graph, sx1, sy1, &x, &y);
                ShowCoords((BasicWindow *)graph, sx1, sy1, x, y);

                /*
                 * mark the start of the drag location
                 */

                graph->dragx1 = sx1;
                graph->dragy1 = sy1;
            }

            graph->dragwx1 = x;
            graph->dragwy1 = y;
            break;

        case 3:
            /*
             * world coord xy readout closest above point
             */

            Snap(graph, sx1, sy1, &x, &y);

            /*
             * draw a line to the point on the plot (sx2, sy2)
             */

            ScreenTransform(graph, x, y, &sx2, &sy2);

            /* avoid writing on the last pixel */

            if (sy2 > sy1)
            {
                sy2 -= 1;
            }
            else
            {
                sy2 += 1;
            }

            graph->dragx1 = sx1;
            graph->dragy1 = sy1;
            graph->dragx2 = sx2;
            graph->dragy2 = sy2;
            DrawSuperLine((BasicWindow *)graph, sx2, sy1, sx2, sy2);
            ClearWindow((BasicWindow *)graph->frame->text);
            NBShowCoords((BasicWindow *)graph->frame->text,
                         0, graph->fontheight, x, y);
        }

        break;

    case DRAWMODE:
        switch (button)
        {
        case 1:
            /*
             * mark the start of the line
             */

            graph->dragx1 = sx1;
            graph->dragy1 = sy1;
            WorldTransform(graph, sx1, sy1, &x, &y);
            graph->dragwx1 = x;
            graph->dragwy1 = y;
            break;
        }

        break;

    case ZAPMODE:
        switch (button)
        {
        case 1:
            /*
             * delete the label
             */

            ZapLabel(graph, (XKeyEvent *)buttonevent);
            break;
        }

        break;

    case PINCHMODE:
        switch (button)
        {
        case 1:
            /*
             * offset the plots
             */

            OffsetPlotGraphically(graph, buttonevent->x, buttonevent->y, 0);
            break;
        }

        break;
    }
}
Beispiel #14
0
void
DrawXTicks(Graph *graph)
{
    int   sx1, sy1;
    int   sx2, sy2;
    int   i;
    float yint;
    float val;
    float scale;
    int   tmp;
    int   axisx;
    int   j;


    if (graph->xaxis_desired_nticks == 0)
    {
        graph->xaxis_nticks = 1;
        return;
    }

    /*
     * Get the screen coordinates of the axis.
     */

    SetColor(graph->foreground);
    yint = graph->xaxis_yintcpt;
    ScreenTransform(graph, graph->wxmin, yint, &sx1, &sy1);
    ScreenTransform(graph, graph->wxmax, yint, &sx2, &sy2);

    scale = 1.0 / pow((double) 10.0, (double) graph->xaxis_exponent);
    ScreenTransform(graph, graph->yaxis_xintcpt, 0.0, &axisx, &tmp);

    for (i = 0; i < graph->xaxis_nticks; i++)
    {
        for (j = 0; j < graph->xaxis_nsubticks + 1; j++)
        {
            val = i * graph->xaxis_tickinc + graph->xaxis_tickstart +
                j * graph->xaxis_tickinc / (graph->xaxis_nsubticks + 1);
            ScreenTransform(graph, val, graph->xaxis_yintcpt, &sx1, &sy1);

            /*
             * Either draw a grid or just tick marks at the tick intervals.
             */

            if (graph->show_xgrid)
            {
                SetColor(graph->gridcolor);
                SetLinestyle((BasicWindow *)graph, 1);
                DrawLine(sx1, 0, sx1, graph->wheight);
                SetLinestyle((BasicWindow *)graph, 0);
                SetColor(graph->foreground);
            }

            if (!(graph->quadrants & 0x1) && !(graph->quadrants & 0x4))
                continue;

            /*
             * Check for quadrants I.
             */

            if (!(graph->quadrants & 0x1) && sx1 > axisx)
                continue;

            /*
             * Check for quadrants III.
             */

            if (!(graph->quadrants & 0x4) && sx1 < axisx)
                continue;

            if (j == 0)
            {
                DrawLine(sx1, sy1 - graph->ticksize, sx1,
                         sy2 + graph->ticksize);

                /*
                 * label the ticks
                 */

                if (graph->show_xlabels)
                {
                    DrawXTickLabel(graph, sx1, sy1,
                                   val, scale,
                                   graph->xaxis_leftdp, graph->xaxis_rightdp);
                }
            }
            else
            {
                DrawLine(sx1, sy1 - (int) (0.5 * graph->ticksize), sx1,
                         sy2 + (int) (0.5 * graph->ticksize));
            }
        }
    }
}
Beispiel #15
0
void
DrawYTicks(Graph *graph)
{
    int   sx1, sy1;
    int   sx2, sy2;
    int   i;
    float xint;
    float val;
    float scale;
    int   tmp;
    int   axisy;
    int   j;

    if (graph->yaxis_desired_nticks == 0)
    {
        graph->yaxis_nticks = 1;
        return;
    }

    /*
     * Get the screen coordinates of the axis.
     */

    SetColor(graph->foreground);
    xint = graph->yaxis_xintcpt;
    ScreenTransform(graph, xint, graph->wymin, &sx1, &sy1);
    ScreenTransform(graph, xint, graph->wymax, &sx2, &sy2);

    /*
     * Get the axis exponent.
     */

    scale = 1.0 / pow((double) 10.0, (double) graph->yaxis_exponent);
    ScreenTransform(graph, 0.0, graph->xaxis_yintcpt, &tmp, &axisy);

    /*
     * Loop over all the tick marks.
     */

    for (i = 0; i < graph->yaxis_nticks; i++)
    {
        for (j = 0; j < graph->yaxis_nsubticks + 1; j++)
        {
            /*
             * Get the actual value of the tick.
             */

            val = i * graph->yaxis_tickinc +
                graph->yaxis_tickstart +
                j * graph->yaxis_tickinc / (graph->yaxis_nsubticks + 1);

            /*
             * Locate its screen position in the window.
             */

            ScreenTransform(graph, graph->yaxis_xintcpt, val, &sx1, &sy1);

            /*
             * Either draw a grid or just tick marks at the tick intervals.
             */

            if (graph->show_ygrid)
            {
                SetColor(graph->gridcolor);
                SetLinestyle((BasicWindow *)graph, 1);
                DrawLine(0, sy1, graph->wwidth, sy1);
                SetLinestyle((BasicWindow *)graph, 0);
                SetColor(graph->foreground);
            }

            if (!(graph->quadrants & 0x2) && !(graph->quadrants & 0x8))
                continue;

            /*
             * Check for quadrants II.
             */

            if (!(graph->quadrants & 0x2) && sy1 < axisy)
                continue;

            /*
             * Check for quadrants IV.
             */

            if (!(graph->quadrants & 0x8) && sy1 > axisy)
                continue;

            if (j == 0)
            {
                DrawLine(sx1 - graph->ticksize, sy1,
                         sx2 + graph->ticksize, sy1);

                /*
                 * Label the ticks.
                 */

                if (graph->show_ylabels)
                {
                    DrawYTickLabel(graph, sx1, sy1,
                                   val, scale,
                                   graph->yaxis_leftdp, graph->yaxis_rightdp);
                }
            }
            else
            {
                DrawLine(sx1 - (int) (0.5 * graph->ticksize), sy1,
                         sx2 + (int) (0.5 * graph->ticksize), sy1);
            }
        }
    }
}
float PixelVisibility_DrawProxy( IMatRenderContext *pRenderContext, OcclusionQueryObjectHandle_t queryHandle, Vector origin, float scale, float proxyAspect, IMaterial *pMaterial, bool screenspace )
{
	Vector point;

	// don't expand this with distance to fit pixels or the sprite will poke through
	// only expand the parts perpendicular to the view
	float forwardScale = scale;
	// draw a pyramid of points touching a sphere of radius "scale" at origin
	float pixelsPerUnit = pRenderContext->ComputePixelDiameterOfSphere( origin, 1.0f );
	pixelsPerUnit = MAX( pixelsPerUnit, 1e-4f );
	if ( screenspace )
	{
		// Force this to be the size of a sphere of diameter "scale" at some reference distance (1.0 unit)
		float pixelsPerUnit2 = pRenderContext->ComputePixelDiameterOfSphere( CurrentViewOrigin() + CurrentViewForward()*1.0f, scale*0.5f );
		// force drawing of "scale" pixels
		scale = pixelsPerUnit2 / pixelsPerUnit;
	}
	else
	{
		float pixels = scale * pixelsPerUnit;
		
		// make the radius larger to ensure a minimum screen space size of the proxy geometry
		if ( pixels < MIN_PROXY_PIXELS )
		{
			scale = MIN_PROXY_PIXELS / pixelsPerUnit;
		}
	}

	// collapses the pyramid to a plane - so this could be a quad instead
	Vector dir = origin - CurrentViewOrigin();
	VectorNormalize(dir);
	origin -= dir * forwardScale;
	forwardScale = 0.0f;
	// 

	Vector verts[5];
	const float sqrt2 = 0.707106781f; // sqrt(2) - keeps all vectors the same length from origin
	scale *= sqrt2;
	float scale45x = scale;
	float scale45y = scale / proxyAspect;
	verts[0] = origin - CurrentViewForward() * forwardScale;					  // the apex of the pyramid
	verts[1] = origin + CurrentViewUp() * scale45y - CurrentViewRight() * scale45x; // these four form the base
	verts[2] = origin + CurrentViewUp() * scale45y + CurrentViewRight() * scale45x; // the pyramid is a sprite with a point that
	verts[3] = origin - CurrentViewUp() * scale45y + CurrentViewRight() * scale45x; // pokes back toward the camera through any nearby 
	verts[4] = origin - CurrentViewUp() * scale45y - CurrentViewRight() * scale45x; // geometry

	// get screen coords of edges
	Vector screen[4];
	for ( int i = 0; i < 4; i++ )
	{
		extern int ScreenTransform( const Vector& point, Vector& screen );
		if ( ScreenTransform( verts[i+1], screen[i] ) )
			return -1;
	}

	// compute area and screen-clipped area
	float w = screen[1].x - screen[0].x;
	float h = screen[0].y - screen[3].y;
	float ws = MIN(1.0f, screen[1].x) - MAX(-1.0f, screen[0].x);
	float hs = MIN(1.0f, screen[0].y) - MAX(-1.0f, screen[3].y);
	float area = w*h; // area can be zero when we ALT-TAB
	float areaClipped = ws*hs;
	float ratio = 0.0f;
	if ( area != 0 )
	{
		// compute the ratio of the area not clipped by the frustum to total area
		ratio = areaClipped / area;
		ratio = clamp(ratio, 0.0f, 1.0f);
	}

	pRenderContext->BeginOcclusionQueryDrawing( queryHandle );
	CMeshBuilder meshBuilder;
	IMesh* pMesh = pRenderContext->GetDynamicMesh( false, NULL, NULL, pMaterial );
	meshBuilder.Begin( pMesh, MATERIAL_TRIANGLES, 4 );
	// draw a pyramid
	for ( int i = 0; i < 4; i++ )
	{
		int a = i+1;
		int b = (a%4)+1;
		meshBuilder.Position3fv( verts[0].Base() );
		meshBuilder.AdvanceVertex();
		meshBuilder.Position3fv( verts[a].Base() );
		meshBuilder.AdvanceVertex();
		meshBuilder.Position3fv( verts[b].Base() );
		meshBuilder.AdvanceVertex();
	}
	meshBuilder.End();
	pMesh->Draw();

	// sprite/quad proxy
#if 0
	meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );

	VectorMA (origin, -scale, CurrentViewUp(), point);
	VectorMA (point, -scale, CurrentViewRight(), point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();

	VectorMA (origin, scale, CurrentViewUp(), point);
	VectorMA (point, -scale, CurrentViewRight(), point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();

	VectorMA (origin, scale, CurrentViewUp(), point);
	VectorMA (point, scale, CurrentViewRight(), point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();

	VectorMA (origin, -scale, CurrentViewUp(), point);
	VectorMA (point, scale, CurrentViewRight(), point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();
	
	meshBuilder.End();
	pMesh->Draw();
#endif
	pRenderContext->EndOcclusionQueryDrawing( queryHandle );

	// fraction clipped by frustum
	return ratio;
}
void C_PropVehicleDriveable::DrawHudElements( )
{
	CHudTexture *pIcon;
	int iIconX, iIconY;

	if (m_bHasGun)
	{
		// draw crosshairs for vehicle gun
		pIcon = gHUD.GetIcon( "gunhair" );

		if ( pIcon != NULL )
		{
			float x, y;

			if( UseVR() )
			{
				C_BasePlayer *pPlayer = (C_BasePlayer *)GetPassenger( VEHICLE_ROLE_DRIVER );
				Vector vecStart, vecDirection;
				pPlayer->EyePositionAndVectors( &vecStart, &vecDirection, NULL, NULL );
				Vector vecEnd = vecStart + vecDirection * MAX_TRACE_LENGTH;

				trace_t tr;
				UTIL_TraceLine( vecStart, vecEnd, MASK_SHOT, this, COLLISION_GROUP_NONE, &tr );

				Vector screen;
				screen.Init();
				ScreenTransform(tr.endpos, screen);

				int vx, vy, vw, vh;
				vgui::surface()->GetFullscreenViewport( vx, vy, vw, vh );

				float screenWidth = vw;
				float screenHeight = vh;

				x = 0.5f * ( 1.0f + screen[0] ) * screenWidth + 0.5f;
				y = 0.5f * ( 1.0f - screen[1] ) * screenHeight + 0.5f;
			}
			else
			{
				Vector screen;

				x = ScreenWidth()/2;
				y = ScreenHeight()/2;

#if TRIANGULATED_CROSSHAIR
				ScreenTransform( m_vecGunCrosshair, screen );
				x += 0.5 * screen[0] * ScreenWidth() + 0.5;
				y -= 0.5 * screen[1] * ScreenHeight() + 0.5;
#endif
			}


			x -= pIcon->Width() / 2; 
			y -= pIcon->Height() / 2; 
			
			Color	clr = ( m_bUnableToFire ) ? gHUD.m_clrCaution : gHUD.m_clrNormal;
			pIcon->DrawSelf( x, y, clr );
		}

		if ( m_nScannerDisabledWeapons )
		{
			// Draw icons for scanners "weps disabled"  
			pIcon = gHUD.GetIcon( "dmg_bio" );
			if ( pIcon )
			{
				iIconY = 467 - pIcon->Height() / 2;
				iIconX = 385;
				if ( !m_bScannerWepIcon )
				{
					pIcon->DrawSelf( XRES(iIconX), YRES(iIconY), Color( 0, 0, 255, 255 ) );
					m_bScannerWepIcon = true;
					m_iScannerWepFlashTimer = 0;
					m_bScannerWepDim = true;
				}
				else
				{
					pIcon->DrawSelf( XRES(iIconX), YRES(iIconY), Color( 0, 0, GetFlashColorIntensity(55, 255, m_bScannerWepDim, 10, m_iScannerWepFlashTimer), 255 ) );
					m_iScannerWepFlashTimer++;
					m_iScannerWepFlashTimer %= 20;
					if(!m_iScannerWepFlashTimer)
						m_bScannerWepDim ^= 1;
				}
			}
		}
	}

	if ( m_nScannerDisabledVehicle )
	{
		// Draw icons for scanners "vehicle disabled"  
		pIcon = gHUD.GetIcon( "dmg_bio" );
		if ( pIcon )
		{
			iIconY = 467 - pIcon->Height() / 2;
			iIconX = 410;
			if ( !m_bScannerVehicleIcon )
			{
				pIcon->DrawSelf( XRES(iIconX), YRES(iIconY), Color( 0, 0, 255, 255 ) );
				m_bScannerVehicleIcon = true;
				m_iScannerVehicleFlashTimer = 0;
				m_bScannerVehicleDim = true;
			}
			else
			{
				pIcon->DrawSelf( XRES(iIconX), YRES(iIconY), Color( 0, 0, GetFlashColorIntensity(55, 255, m_bScannerVehicleDim, 10, m_iScannerVehicleFlashTimer), 255 ) );
				m_iScannerVehicleFlashTimer++;
				m_iScannerVehicleFlashTimer %= 20;
				if(!m_iScannerVehicleFlashTimer)
					m_bScannerVehicleDim ^= 1;
			}
		}
	}
}