locked
Switch graphical element?

    Question

  • Only had about a year of DirectX programming so still pretty new to all this but really putting the effort in. One thing that I do not quite get just now is if render inherits from another render method where the graphical elements are created what would be the best way to update the graphical elements?

    Would it be where the graphics elements are created with 

    void Graphics::CreateGraphicsElements(Microsoft::WRL::ComPtr<ID3D11Device1>& dev, Microsoft::WRL::ComPtr<ID3D11DeviceContext1>& devCon)

    Where the graphics elements are rendered with

    void Graphics::Render(Microsoft::WRL::ComPtr<ID3D11DeviceContext1>& devCon, Microsoft::WRL::ComPtr<ID3D11Buffer>& constBuff)

    Or would it be in the update method of the main file? Been racking my brain over this and think I'm starting to go around in circles now. Have tried applying different states in the game logic to update the graphics but even though the states change the graphics do not render. Even tried using booleans but that just ended up with the same results. 

    Does anyone know how I could switch the graphical elements of the switch statement given certain conditions in the game?

    Do I need to make another render call after I have switched the value of the graphical element?

    Tuesday, February 05, 2013 9:24 PM

Answers

  • If you want to modify a CMazeElement, you will need to make changes to the CRenderableObject class so that you can modify it. If you wanted to change the texture , for instance, you would need to create a member function in CRenderableObject that would let you change the texture. Same goes for position, rotation, and scale.

    Then you would want to modify CMaze so that you could access individual CMazeElement objects by adding a member function to CMaze that would do that.

    Then in CGame::Update you would want to test to see if the end was reached (you may need to add more functions to CMaze to do this) and if so you would then want to access the particular CMazeElement you want to change and then use the member functions you created in order to change it. That way when CMazeElement::Render (which is inherited from CRenderableObject) runs, it will draw the object with the modifications.

    The sample has merit as a teaching tool but its dense OO structure makes it difficult to modify it. Just to do something as minor as changing a texture on one maze block, we would need to make significant changes to three different classes, none of which is the actual maze element class. If I wrote this sample, I would make CRenderableObject a pure virtual class (such that it would act like an interface) with just a Render abstract member function. That way anything that inherited from it would need to specify its own rendering code so that if you needed to change how something renders, you wouldn't need to worry about breaking other things.


    XNA/DirectX MVP | Website | Blog | @mikebmcl

    Friday, February 08, 2013 6:17 PM
  • ... One thing that I do not quite get just now is if render inherits from another render method where the graphical elements are created what would be the best way to update the graphical elements?

    Would it be where the graphics elements are created[?]

    Where the graphics elements are rendered[?]

    Or would it be in the update method of the main file?

    Been racking my brain over this and think I'm starting to go around in circles now. Have tried applying different states in the game logic to update the graphics but even though the states change the graphics do not render. Even tried using booleans but that just ended up with the same results. 

    Does anyone know how I could switch the graphical elements of the switch statement given certain conditions in the game?

    Do I need to make another render call after I have switched the value of the graphical element?

    Several issues. First, you include some code (a Graphics class) that does not exist in the sample you say you are working from. So you've obviously modified quite a bit, which makes it a guessing game as to what you might mean.

    Beyond that, generally you update game state in an Update member function. But you aren't clear about what sort of updating you mean. If you're talking about updating a cbuffer, then that should probably go in a Render method since it's a manipulation of a GPU object. You would update the relevant cbuffer and then you would draw the object.

    You further say that you tried applying different states but that then "the graphics do not render". Do you mean that they literally disappear? If so it's likely a data error with the values you are updating. If you mean that the changes do not reflect the state changes you made, then it's a problem with state that affects the object's appearance, position, etc., not getting updated (or not properly getting updated).

    You should never need to render something twice to make it appear (excluding certain deferred rendering techniques which this does not seem to involve); all you'd be doing is drawing the same thing twice thus making the GPU do pointless work.

    What exactly are you trying to update? A cbuffer? A vertex buffer? An index buffer? Something else?

    How are you trying to update it? Are you making changes to CPU-side data structures? Perhaps you aren't making the corresponding changes to the GPU-side data (typically a cbuffer) that would actually cause the object's appearance/position/whatever to change.

    We need more detail about what you are trying to do and what you are trying to do it to in order to hopefully provide a good answer.


    XNA/DirectX MVP | Website | Blog | @mikebmcl

    Thursday, February 07, 2013 9:41 PM

All replies

  • What piece of code are you starting from?

    Tuesday, February 05, 2013 11:37 PM
  • It is the Writing a 3D DirectX Maze that's navigable  with speech commands that I started from. It is from the Nokia Developer site and can be found here 3D DirectX Maze. The game has been modified so that it runs on my Windows 8 PC and Surface RT. It doesn't use speech commands now either and uses the pointer for input. The problem I face it seems is that when the graphical elements have been rendered I can not seem to change them.  Kind of hit a brick wall with this and was just hoping for some guidance on it. 
    Wednesday, February 06, 2013 1:07 AM
  • So that's a pretty complex sample. Have you started with something a bit more simple first? Your question is specific to the design of that sample, not a general question about DirectX
    Wednesday, February 06, 2013 7:16 PM
  • Hi again, sorry if it seems foolish of me to tackle this. The samples I started with before this were DirectX Tool Kit Simple Sample, DirectX Touch Input Sample, Visual Studio 3D Starter Kit, Direct 3D Post Processing Example, the DXGI offer and reclaim sample, also I worked through all the tutorials on DirectXTutorial.com. Checked out the Marble Maze game for some tips as well.

    Would I use something like the DXGI offer and reclaim sample for this but instead of when the program resumes have another condition change the graphical element? Went through numerous other samples but these were the ones I was most thorough with. Would you recommend one of these other samples which could be used to create a simple test bed game instead where it would be possible to manipulate the position, scale and appearance of the models; preferably with textures?  



    • Edited by GABsturr Thursday, February 07, 2013 3:43 PM grammar correction
    Thursday, February 07, 2013 3:40 PM
  • ... One thing that I do not quite get just now is if render inherits from another render method where the graphical elements are created what would be the best way to update the graphical elements?

    Would it be where the graphics elements are created[?]

    Where the graphics elements are rendered[?]

    Or would it be in the update method of the main file?

    Been racking my brain over this and think I'm starting to go around in circles now. Have tried applying different states in the game logic to update the graphics but even though the states change the graphics do not render. Even tried using booleans but that just ended up with the same results. 

    Does anyone know how I could switch the graphical elements of the switch statement given certain conditions in the game?

    Do I need to make another render call after I have switched the value of the graphical element?

    Several issues. First, you include some code (a Graphics class) that does not exist in the sample you say you are working from. So you've obviously modified quite a bit, which makes it a guessing game as to what you might mean.

    Beyond that, generally you update game state in an Update member function. But you aren't clear about what sort of updating you mean. If you're talking about updating a cbuffer, then that should probably go in a Render method since it's a manipulation of a GPU object. You would update the relevant cbuffer and then you would draw the object.

    You further say that you tried applying different states but that then "the graphics do not render". Do you mean that they literally disappear? If so it's likely a data error with the values you are updating. If you mean that the changes do not reflect the state changes you made, then it's a problem with state that affects the object's appearance, position, etc., not getting updated (or not properly getting updated).

    You should never need to render something twice to make it appear (excluding certain deferred rendering techniques which this does not seem to involve); all you'd be doing is drawing the same thing twice thus making the GPU do pointless work.

    What exactly are you trying to update? A cbuffer? A vertex buffer? An index buffer? Something else?

    How are you trying to update it? Are you making changes to CPU-side data structures? Perhaps you aren't making the corresponding changes to the GPU-side data (typically a cbuffer) that would actually cause the object's appearance/position/whatever to change.

    We need more detail about what you are trying to do and what you are trying to do it to in order to hopefully provide a good answer.


    XNA/DirectX MVP | Website | Blog | @mikebmcl

    Thursday, February 07, 2013 9:41 PM
  • It is the cBuffer I believe I have to update as that is what is related to the final render call of the maze inheriting from CMazeElements. Can the cBuffer be updated multiple times if required or just once?

    What I meant by the graphics do not render is that they do not change to reflect the state changes I made. I have tried using the state changes in the createMaze, Render and Update functions of CMaze. Would any of these the right place to make theses state changes for a change to the graphical elements of the maze? 

    In the original code of the example there is a CMaze class. There is a createMaze and Render function in this class. The CMaze::Render is called in the CGame::Render. Would there be a way as so the switch statement values representative of graphical elements in the createMaze function could be switched in real time?

    In the example the playerAvatar can move from start to finish and when it reaches the end it is reset to the beginning. Instead of having the playerAvatar reset how would I go about changing the graphical elements of say one cell within the array? 

    Friday, February 08, 2013 2:17 PM
  • If you want to modify a CMazeElement, you will need to make changes to the CRenderableObject class so that you can modify it. If you wanted to change the texture , for instance, you would need to create a member function in CRenderableObject that would let you change the texture. Same goes for position, rotation, and scale.

    Then you would want to modify CMaze so that you could access individual CMazeElement objects by adding a member function to CMaze that would do that.

    Then in CGame::Update you would want to test to see if the end was reached (you may need to add more functions to CMaze to do this) and if so you would then want to access the particular CMazeElement you want to change and then use the member functions you created in order to change it. That way when CMazeElement::Render (which is inherited from CRenderableObject) runs, it will draw the object with the modifications.

    The sample has merit as a teaching tool but its dense OO structure makes it difficult to modify it. Just to do something as minor as changing a texture on one maze block, we would need to make significant changes to three different classes, none of which is the actual maze element class. If I wrote this sample, I would make CRenderableObject a pure virtual class (such that it would act like an interface) with just a Render abstract member function. That way anything that inherited from it would need to specify its own rendering code so that if you needed to change how something renders, you wouldn't need to worry about breaking other things.


    XNA/DirectX MVP | Website | Blog | @mikebmcl

    Friday, February 08, 2013 6:17 PM
  • If you want to modify a CMazeElement, you will need to make changes to the CRenderableObject class so that you can modify it. If you wanted to change the texture , for instance, you would need to create a member function in CRenderableObject that would let you change the texture. Same goes for position, rotation, and scale.

    Then you would want to modify CMaze so that you could access individual CMazeElement objects by adding a member function to CMaze that would do that.

    Then in CGame::Update you would want to test to see if the end was reached (you may need to add more functions to CMaze to do this) and if so you would then want to access the particular CMazeElement you want to change and then use the member functions you created in order to change it. That way when CMazeElement::Render (which is inherited from CRenderableObject) runs, it will draw the object with the modifications.

    The sample has merit as a teaching tool but its dense OO structure makes it difficult to modify it. Just to do something as minor as changing a texture on one maze block, we would need to make significant changes to three different classes, none of which is the actual maze element class. If I wrote this sample, I would make CRenderableObject a pure virtual class (such that it would act like an interface) with just a Render abstract member function. That way anything that inherited from it would need to specify its own rendering code so that if you needed to change how something renders, you wouldn't need to worry about breaking other things.


    XNA/DirectX MVP | Website | Blog | @mikebmcl

    That was a comprehensive answer to my question thank you. Not too sure if I am allowed to ask another question now that the thread has been marked answered so hope it is all right to ask about how to access one object of CMazeElement. To begin with I have started with scale so in CRenderableObject I added the member functions:

    float CRenderableObject::GetScaleY()
    {
    	return m_ScaleY;
    }
    
    void CRenderableObject::SetScaleY(float height)
    {
    	m_ScaleY = height;
    }

    The constructor now looks like so:

    CRenderableObject::CRenderableObject(Microsoft::WRL::ComPtr<ID3D11ShaderResourceView> inTexture)
    {
    	SetScaleY(4.0f);
    
    	m_Position = Vector3D(0,0,0);
    	m_Scale = Vector3D(1, m_ScaleY, 1);
    	m_Rotation = Vector3D(0,0,0);
    
    	m_Texture = inTexture;
    }

    Not entirely sure how I will update this in real time yet but believe it is less of problem than accessing an individual CMazeElement object. The member functions I added to the CMaze class were:

    int CMaze::GetCell()
    {
    	return m_MazeArray[4][4];
    }
    
    void CMaze::SetCell(int cellModified[4][4])
    {
    	m_MazeArray[4][4] = cellModified[4][4];
    }

    By using m_MazeArray I believe I am accessing an individual cell of CMazeElement however I am uncertain how to change the element within CGame::Update. I am unsure how to set the value of the array before changing scale and texture.

    mp_Maze->SetCell();
    What would be the right way to access an individual CMazeElement object?
    Thursday, February 14, 2013 11:40 PM