Results 1 to 1 of 1
  1. #1
    Dwar
    Dwar is offline
    Veteran Dwar's Avatar
    Join Date
    2010 Mar
    Posts
    2,222
    Thanks Thanks Given 
    211
    Thanks Thanks Received 
    2,230
    Thanked in
    292 Posts
    Rep Power
    10

    D3D Crosshairs example

    Variant 1:
    /*This down here create the function with the name "DrawXHair", so for use you'll  write: DrawXHair(pDevice, D3DCOLOR_XRGB(0, 0, 0); //for example. The  color can be as in the example but also hex (0xFFFFFFFF), and in ARGB.*/

    void DrawXHair(LPDIRECT3DDEVICE9 pDevice, D3DCOLOR color)
    {
    D3DVIEWPORT9 viewP; //this create a D3DVIEWPORT9 variable
    pDevice->GetViewport( &viewP ); //put the values of screen resolution, viewport coords, in viewP
    DWORD ScreenCenterX = viewP.Width / 2; //Create a DWORD that represent the screen center X // STUDY CARTESIAN AXES AND ALGEBRA
    DWORD ScreenCenterY = viewP.Height / 2; // Same as up there, but for Y

    D3DRECT rect1 = {ScreenCenterX-25, ScreenCenterY, ScreenCenterX+ 25, ScreenCenterY+1}; //Create a D3DRECT variable that contains the coord of where we are going to draw a line
    D3DRECT rect2 = {ScreenCenterX, ScreenCenterY-25, ScreenCenterX+ 1, ScreenCenterY+25}; //Same as up there

    pDevice->Clear( 1, &rect1, D3DCLEAR_TARGET, color, 0, 0 ); //This function draw a line on determinated coords
    pDevice->Clear( 1, &rect2, D3DCLEAR_TARGET, color, 0, 0 ); //Same as up there
    }


    here another way to draw a crosshair:
    void CrossHair(LPDIRECT3DDEVICE9 pDevice, int size, int strong,  D3DCOLOR xcolor){
    int iCenterX = GetSystemMetrics( 0 ) / 2;
    int iCenterY = GetSystemMetrics( 1 ) / 2;
    if( iCenterX < 20 && iCenterY < 20 )
    {
    iCenterX = ( GetSystemMetrics( 0 ) / 2 );
    iCenterY = ( GetSystemMetrics( 1 ) / 2 );
    }
    D3DRECT rec2 = { iCenterX- size, iCenterY, iCenterX+ size, iCenterY+ strong};
    D3DRECT rec3 = { iCenterX, iCenterY- size, iCenterX+ strong,iCenterY+ size};
    pDevice->Clear(1, &rec2, D3DCLEAR_TARGET, xcolor, 1000, 0);
    pDevice->Clear(1, &rec3, D3DCLEAR_TARGET, xcolor, 100, 0);
    }
    Please, post your questions on forum, not by PM or mail

    I spend my time, so please pay a little bit of your time to keep world in equilibrium

  2. The Following User Says Thank You to Dwar For This Useful Post:


Similar Threads

  1. [Snippet] D3D Crosshairs
    By Dwar in forum D3D Programming
    Replies: 6
    Last Post: 2012-07-19, 08:18 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •