I have been googling up and down translation in DirectX. I've seen plenty of tutorials on how to accomplish translation using matrices and I have accomplished the task before in OpenGL. However, I started using DirectX and I am using a vertex buffer and pushing it to a vertex shader for processing.
I'm trying to figure out, where in the process, and what objects come into play, when dynamically translating -specific- sets of vertices.
For instance, if I have two squares, and I push my vertices for my squares into my vertex buffer, after this is accomplished, where do I apply my offsets? Is it in the shader? If so, how to pass my offsets to the shader so that it knows which vertices to apply which offset?
Or, do I recreate my vertex buffer every time translation occurs (could be many times in a frame from user input or whatnot, this doesn't seem right to me).
Does anyone have some good material on simple 2d/3d translation during runtime with vertex buffers, or some quick tips on how you might accomplish such a thing.
So, I set up my renderable objects:
Game::Game(HWND hWnd)
{
Renderable_Object * square1 = new Renderable_Object(-50, -50, 0, 0);
Renderable_Object * square2 = new Renderable_Object(-0, -0, 50, 50);
Game_Objects.push_back(square1);
Game_Objects.push_back(square2);
renderer = new Renderer(hWnd, Game_Objects);
}
In my renderer, I set up my vertex buffer, along with my other directx junk:
void Renderer::InitGraphics(std::vector<Renderable_Object*> Game_Objects)
{
for (int i = 0; i < Game_Objects.size(); i++)
{
for (int j = 0; j < Game_Objects[i]->getVertices().size(); j++)
{
OurVertices.push_back(Game_Objects[i]->getVertices()[j]);
}
}
createVertexBuffer();
createConstantBuffer();
}
Then, after all is said and done, I draw the stuff, see below for my commented question:
void Renderer::Update()
{
// clear the back buffer to a deep blue
devcon->ClearRenderTargetView(backbuffer, D3DXCOLOR(0.0f, 0.2f, 0.4f, 1.0f));
// Here is where I imagine I will have to do alterations and translation on my vertices based on input
// my problem is not how to do this, like, the math part, applying an offset and junk like that...
// my problem is what do I change right here, in order to make my squares move?
// should I rebind my vertex buffer after applying some kind of offset?
// like, another createVertexBuffer();?
// or, is there some way to tell the shader to apply the offset for a specific group of vertices?
// help please!
// select which vertex buffer to display
UINT stride = sizeof(Vertex);
UINT offset = 0;
devcon->IASetVertexBuffers(0, 1, &pVBuffer, &stride, &offset);
// select which primtive type we are using
devcon->IASetPrimitiveTopology(D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
// draw the vertex buffer to the back buffer
devcon->Draw(12, 0);
// switch the back buffer and the front buffer
swapchain->Present(0, 0);
}
// Here is where I imagine I will have to do alterations and translation on my vertices based on input
// my problem is not how to do this, like, the math part, applying an offset and junk like that...
// my problem is what do I change right here, in order to make my squares move?
// should I rebind my vertex buffer after applying some kind of offset?
// like, another createVertexBuffer();?
// or, is there some way to tell the shader to apply the offset for a specific group of vertices?
// help please!
Thanks for your help in advance!