2 Mesh Questions

Started by
3 comments, last by phatslug 21 years, 9 months ago
1. How do I make the vertex shading of a Mesh work?? This: device->SetVertexShader( mesh->GetFVF() ); doesn''t seem to work. 2. I use this code to Render a mesh to a certain location D3DXMATRIX transMX; D3DXMatrixTranslation(&transMX,x,y,z); device->SetTransform(D3DTS_WORLD,&worldMX); Now... how do I make that mesh rotate? All the code I''ve tried seems pretty good at making the whole world rotate, but I actually want just that mesh, and to have it stay in place. thanks
Advertisement
probably it would be better if you would clone the mesh after loading it, this way, you could specify the fvf,

remember the rule in d3d8, when you set something on the device, that state would remain until you change it again, so maybe this is the reason why everything rotates, you forgot to reset/set the matrix for the other objects/models,

http://www.dualforcesolutions.comProfessional website designs and development, customized business systems, etc.,
quote:1. How do I make the vertex shading of a Mesh work?? This: device->SetVertexShader( mesh->GetFVF() );
doesn''t seem to work.


Assuming you meant using a vertex shader, you need to assemble and create one first. Then you pass the handle recieved from creating it to SetVertexShader, not the fvf of your mesh. When your done, you destroy the shader. You cannot render our mesh using the default DrawSubset. You need to gain access to the vertex and index buffer and render manually.

quote:2. I use this code to Render a mesh to a certain location
D3DXMATRIX transMX;
D3DXMatrixTranslation(&transMX,x,y,z);
device->SetTransform(D3DTS_WORLD,&worldMX);
Now... how do I make that mesh rotate? All the code I''ve tried seems pretty good at making the whole world rotate, but I actually want just that mesh, and to have it stay in place.

thanks


When setting transforms, whatever you set is used for all objects drawn after it. In order to stop using a transform, create an identity matrix and set it as the transform. Then objects drawn after you set the identity matrix will not be transformed.

---
My Site
Come join us on IRC in #directxdev @ irc.afternet.org
hmm... Perhaps Ill hold off on vertex shading for a while if I need to add a bunch more code to render meshes...

but about the rotation, heres the code I use before rendering every mesh

  void CMesh::Render(float x, float y, float z,				   float rx, float ry, float rz){	HRESULT hr;	D3DXMATRIX transMX, rotMX, worldMX;	D3DXMatrixRotationYawPitchRoll(&rotMX,rx,ry,rz);	D3DXMatrixTranslation(&transMX,x,y,z);	D3DXMatrixMultiply(&worldMX,&transMX,&rotMX);		hr = d3dDevice->SetTransform(D3DTS_WORLD,&worldMX);  


The effect that I get is that say when I input a number for say rx, the mesh will rotate so many degrees around the X-Axis. What I want is for it to stay in place and rotate around on its own.
I believe it has to do something with the center of the mesh being in the origin of its local coordinate system. But i had the same problem often enough.

Im Anfang war die Tat...
Faust
Im Anfang war die Tat...Faust

This topic is closed to new replies.

Advertisement