Thread: First person question

  1. #1
    Registered User
    Join Date
    Sep 2004

    First person question

    Hi Folks;

    I'm attempting my hand at some first person game programming and the nature of the game requires a reticule in the middle of the screen. To change my view of the world I do some rotations but I can't seem to keep my reticule in the screen. Can anyone offer some advice on this?

  2. #2
    Registered User Draco's Avatar
    Join Date
    Apr 2002
    The easiest way to do it would be to put your reticle at a certain pixel coordinate after the 3d calculations are done-in essence you already have your picture of the 3d view, and then you paste the reticule over it. I haven't done it but the setup of opengl should make this easy to do. If you're using directx I have no idea what it would take.

  3. #3
    Super Moderator VirtualAce's Avatar
    Join Date
    Aug 2001
    Here is what it takes in DirectX:

    #ifndef C2DOVERLAY
    #define C2DOVERLAY
    #include <string>
    #include <d3d9.h>
    struct TLVertex
      D3DXVECTOR3  m_Position;
      float                  m_fRhw;
      float                  m_fTu,m_fTv;
      static const DWORD m_dwFVF;
      TLVertex(D3DXVECTOR3 pos,float u,float v):m_Position(pos),m_fRhw(1.0f),m_fTu(u),m_fTv(v) {}
    class C2DOverlay
       TLVertex      m_pVerts[4];
       IDirect3DTexture9      *m_pTexture;
       IDirect3DDevice9        *m_pDevice;
       float m_fSize;
          C2DOverlay(void):m_pTexture(NULL),m_pDevice(NULL),m_fSize(0.0f) {}
            //If we sucessfully allocated an object from COM, hand it back now
            if (Texture) Texture->Release();
         void Create(IDirect3DDevice9 *_device,float _size);
         void Render(float _timeDelta);
    #include "C2DOverlay.h"
    void C2DOverlay::Create(IDirect3DDevice9 *_device,float _size,std::string _TextureFile)
        float size2=m_fSize*.5f;
        if (FAILED(D3DXCreateTextureFromFile(m_pDevice,_TextureFile.c_str(),&m_pTexture)))
           MessageBox(0,0,"C2DOverlay::Create() - Failed to load texture");
    void C2DOverlay::Render(float _timeDelta)
       //Insert code to translate overlay here
       //Render overlay
       m_pDevice->DrawPrimitiveUP(D3DPT_TRIANGLESTRIP, 2 ,m_pVerts,sizeof(TLVertex));
    That should do the trick. Render your vertices as XYZRHW. This tells Direct3D NOT to send the vertices down the rendering pipeline. In essence you are saying 'I've already transformed these vertexes to screen space....don't touch them.' What this translates to is that the x and y components of your vertices are rendered as is - in screen space - just like in a normal 2D game. So it's fairly straightforward how to move the object around in screen space so I omitted that code.

    You can also use irregular shaped textures by using the correct alpha blending states.

    m_pDevice->SetRenderState(D3DRS_SRCBLEND,D3DBLEND_SRCALPHA );

    You probably don't want to do this in each object's render function as it would be too slow. Turn alpha blending on, render all objects that use that type of alpha blending and then turn it off if need be or simply change the blending states to do different types of alpha blending.

    Hope this helps.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. another do while question
    By kbpsu in forum C++ Programming
    Replies: 3
    Last Post: 03-23-2009, 12:14 PM
  2. can someone help me with these errors please code included
    By geekrockergal in forum C Programming
    Replies: 7
    Last Post: 02-10-2009, 02:20 PM
  3. ordered linked list
    By redmondtab in forum C Programming
    Replies: 48
    Last Post: 10-22-2006, 06:09 AM
  4. Very simple question, problem in my Code.
    By Vber in forum C Programming
    Replies: 7
    Last Post: 11-16-2002, 03:57 PM
  5. Another Quick Question....I'm a really curious Person
    By kermi3 in forum A Brief History of
    Replies: 0
    Last Post: 01-02-2002, 05:10 PM