Jump to content
  • Advertisement
Sign in to follow this  
Knight52

[D3D9] Vertex Translation problem

This topic is 2619 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm not sure if I should post this in beginner's forum, but I'm doing it here.

I'm trying to move this square to the right, but it just doesn't move and I have no idea where I went wrong.

Here's the code I think it's relevant:
#include <Windows.h>
#include <WindowsX.h>
#include <d3d9.h>
#include <d3dx9.h>

#pragma comment(lib, "d3d9.lib")
#pragma comment(lib, "d3dx9.lib")

#define SCREEN_HEIGHT 768
#define SCREEN_WIDTH 1024
#define CUSTOMFVF (D3DFVF_XYZRHW | D3DFVF_DIFFUSE)

LPDIRECT3D9 d3d;
LPDIRECT3DDEVICE9 d3dDevice;
LPDIRECT3DVERTEXBUFFER9 vBuffer;

DWORD Color_A = 0xff00ff00,
Color_B = D3DCOLOR_ARGB(136, 255, 0, 204);

void loadContent();
void initializeD3D(HWND hwnd);
void initializeGraphic(void);
void initializeLight();
void draw(void);
void update();
void flushD3D(void);
LRESULT CALLBACK WindowProc(HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam);

struct CustomVertex
{
float x, y, z, rhw;
DWORD alpha;
} theVertex[] = {
{ 100.0f, 100.0f, 0.5, 1, D3DCOLOR_ARGB(255, 0, 0, 255) },
{ 500.0f, 100.0f, 0.5, 1, D3DCOLOR_ARGB(255, 0, 255, 0) },
{ 500.0f, 500.0f, 0.5, 1, D3DCOLOR_ARGB(255, 255, 0, 0), },
{ 100.0f, 500.0f, 0.5, 1, D3DCOLOR_ARGB(255, 0, 255, 255)},
};
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
{.....
}
LRESULT CALLBACK WindowProc(HWND hwnd, unsigned int message, WPARAM wParam, LPARAM lParam)
{.....
}
void loadContent()
{ }
void initializeD3D(HWND hwnd)
{
d3d = Direct3DCreate9(D3D_SDK_VERSION);
D3DPRESENT_PARAMETERS param;
ZeroMemory(&param, sizeof(D3DPRESENT_PARAMETERS));
param.Windowed = true;
param.SwapEffect = D3DSWAPEFFECT_DISCARD;
param.hDeviceWindow = hwnd;
param.BackBufferFormat = D3DFMT_X8R8G8B8;
param.BackBufferWidth = SCREEN_WIDTH;
param.BackBufferHeight = SCREEN_HEIGHT;
d3d->CreateDevice(D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hwnd, D3DCREATE_SOFTWARE_VERTEXPROCESSING, &param, &d3dDevice);
initializeGraphic();
d3dDevice->SetRenderState(D3DRS_LIGHTING, false);
}
void initializeGraphic(void)
{
d3dDevice->CreateVertexBuffer(4*sizeof(CustomVertex), 0, CUSTOMFVF, D3DPOOL_MANAGED, &vBuffer, NULL);
void* pVoid;
vBuffer->Lock(0, 0, (void**)&pVoid, 0);
memcpy(pVoid, theVertex, sizeof(theVertex));
vBuffer->Unlock();
}
void draw(void)
{
d3dDevice->Clear(0, NULL, D3DCLEAR_TARGET, 0xffffffff, 1, 0);
d3dDevice->BeginScene();

d3dDevice->SetFVF(CUSTOMFVF);
static float index = 0; index += 1;// ------------ where I started
d3dDevice->SetStreamSource(0, vBuffer, 0, sizeof(CustomVertex));
D3DXMATRIX matTran;
D3DXMatrixTranslation(&matTran, index, 0, 0);/// ------------------ where I finished
d3dDevice->SetTransform(D3DTS_WORLD, &matTran);
d3dDevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2);

d3dDevice->EndScene();
d3dDevice->Present(NULL, NULL, NULL, NULL);
}
void flushD3D(void)
{
vBuffer->Release();
d3dDevice->Release();
d3d->Release();
}

Share this post


Link to post
Share on other sites
Advertisement
This happens because the format of your vertex's position is xyzfhw, therefore the coordinates are already transformed to screenspace. Try using D3DFVF_XYZ or translating the vertices manually instead.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!