Archived

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

drawing vertexes with delta?

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

duh... i'm doing my own mesh lib, and using the following:
  
void CMeshLib::Render(float dx, float dy, float dz)
{
	Vert *vtxQuad;
	vbsrc->Lock(0,0, (BYTE **)&vtxQuad, NULL);
	for(int i=0; i<NumVectors; i++) {
		vtxQuad[i].x+=dx;
		vtxQuad[i].y+=dy;
		vtxQuad[i].z+=dz;
	};
	vbsrc->Unlock();

	g_pd3dDevice->SetVertexShader(D3DFVF_DIFFUSE|D3DFVF_XYZ|D3DFVF_NORMAL);
	g_pd3dDevice->SetStreamSource(0, vbsrc, sizeof(Vert));
	g_pd3dDevice->ProcessVertices(0,0,NumVectors,vbdest,0);

	g_pd3dDevice->SetVertexShader(D3DFVF_DIFFUSE|D3DFVF_XYZRHW);
	g_pd3dDevice->SetStreamSource(0, vbdest, sizeof(DVert));
	g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, NumVectors/3);
	vbsrc->Lock(0,0, (BYTE **)&vtxQuad, NULL);
	for(i=0; i<NumVectors; i++) {
		vtxQuad[i].x-=dx;
		vtxQuad[i].y-=dy;
		vtxQuad[i].z-=dz;
	};
	vbsrc->Unlock();
}
  
is there any better way than changing the vertexes each time? [edited by - gilzu on August 15, 2002 5:49:22 PM]

Share this post


Link to post
Share on other sites
You''ll need to get rid of the lock/unlock calls that orient the mesh in world space. Use a world transformation matrix instead. Look up in the DX SDK (8.x) under DirectX Graphics > Programmers Guide > Getting Started with Direct3D > DirectX Graphics C/C++ Tutorials > Tutorial 3: Using Matrices.

Also, there is no reason to call ProcessVertices, the pipeline will take care of that for you.

Try this instead:


  
void CMyMeshLib::Render(float dx, float dy, float dz)
{
D3DXMATRIX matWorld;
D3DXMatrixTranslation(&matWorld, dx, dy, dz);
g_pd3dDevice->SetTransform(D3DTS_WORLD, &matWorld);

g_pd3dDevice->SetVertexShader(D3DFVF_DIFFUSE|D3DFVF_XYZ|D3DFVF_NORMAL);
g_pd3dDevice->SetStreamSource(0, vbsrc, sizeof(Vert));

// Turn off textures unless you''re not using them or they are already off


g_pd3dDevice->DrawPrimitive(D3DPT_TRIANGLELIST, 0, NumVectors/3);
}

Share this post


Link to post
Share on other sites