Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.

obi-wan shinobi

basic directx question (primitives and movements)

This topic is 5571 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

In the experimenting I''ve done with basic direct3d8 stuff, I''ve managed to load and use textures, and have one primitive rotating around one axis while another primitive rotates around a different axis. My question now is how can I have a primitive "move around" like go in one direction for a few seconds and move in the opposite direction for another few seconds while in the rendering loop? I tried to use the Translation matrix in d3d and setting it in the loop, but that just shifts it''s position from the way the vertex buffer defines it. Also, how can I have a rotating object rotating around an axis without sort of orbiting it and staying at the same coordinates? I can only achieve the desired effect when the object is placed at the origin. The (partial) code: VOID direct3d::initMatrices() { D3DXMATRIX matWorld; D3DXMatrixIdentity(&matWorld); gpd3ddevice->SetTransform(D3DTS_WORLD, &matWorld); D3DXMATRIX matView; D3DXMatrixLookAtLH(&matView, &D3DXVECTOR3(0.0f, 0.0f, -10.0f), &D3DXVECTOR3(0.0f, 0.0f, 0.0f), &D3DXVECTOR3(0.0f, 1.0f, 0.0f)); gpd3ddevice->SetTransform(D3DTS_VIEW, &matView); D3DXMATRIX matProj; D3DXMatrixPerspectiveFovLH(&matProj, D3DX_PI/4, 1.0f, 1.0f, 100.0f); gpd3ddevice->SetTransform(D3DTS_PROJECTION, &matProj); } VOID direct3d::texrender() { if(NULL==gpd3ddevice) return; ZeroMemory(&pd3dtex, sizeof(pd3dtex)); D3DXCreateTextureFromFileEx(gpd3ddevice, "tex1.bmp", D3DX_DEFAULT, D3DX_DEFAULT, D3DX_DEFAULT, 0, D3DFMT_A8R8G8B8, D3DPOOL_MANAGED, D3DX_FILTER_TRIANGLE, D3DX_FILTER_TRIANGLE, D3DCOLOR_RGBA(255,255,255,255), NULL, NULL, &pd3dtex); gpd3ddevice->SetRenderState(D3DRS_ALPHATESTENABLE, TRUE); gpd3ddevice->SetRenderState(D3DRS_ALPHAREF, 0xff); gpd3ddevice->SetRenderState(D3DRS_ALPHAFUNC, D3DCMP_LESSEQUAL); gpd3ddevice->Clear(0, NULL, D3DCLEAR_TARGET|D3DCLEAR_ZBUFFER, D3DCOLOR_XRGB(128,128,128), 1.0f, 0); gpd3ddevice->BeginScene(); initMatrices(); gpd3ddevice->SetStreamSource(0, gpvb, sizeof(vertices)); gpd3ddevice->SetVertexShader(texture); gpd3ddevice->SetTexture(0, pd3dtex); D3DXMatrixRotationY(&matWorld, timeGetTime()/250.0f); gpd3ddevice->SetTransform(D3DTS_WORLD, &matWorld); gpd3ddevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 0, 2); gpd3ddevice->EndScene(); gpd3ddevice->BeginScene(); D3DXMatrixRotationZ(&matWorld, timeGetTime()/500.0f); gpd3ddevice->SetTransform(D3DTS_WORLD, &matWorld); gpd3ddevice->DrawPrimitive(D3DPT_TRIANGLEFAN, 4, 2); gpd3ddevice->EndScene(); gpd3ddevice->SetTexture(0, NULL); gpd3ddevice->SetRenderState(D3DRS_ALPHATESTENABLE, FALSE); gpd3ddevice->Present(NULL, NULL, NULL, NULL); }

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

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

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!