cherrymount
Programmer
Hello,
I've got a problem when scaling a mesh: I don't know how to scale the normals. So when I resize my mesh - the lighting doesnt work!
Here's the code:
LPD3DXMESH ScaleMesh(LPD3DXMESH pMesh, double xscale, double yscale, double zscale){
struct Vertex {
D3DXVECTOR3 pos;
float tu;
float tv;
enum {
VertexFVF = D3DFVF_XYZ | D3DFVF_TEX1
};
};
LPD3DXMESH meshCopy;
Vertex *pVertex;
DWORD NUM_VERTICES = pMesh->GetNumVertices();
DWORD i;
pMesh->CloneMeshFVF(0, Vertex::VertexFVF, gD3DDevice, shCopy);
meshCopy->LockVertexBuffer(0,(VOID**)&pVertex);
for ( i=0;i<NUM_VERTICES;i++) {
// Scale
pVertex.pos.x *= xscale;
pVertex.pos.y *= yscale;
pVertex.pos.z *= zscale;
}
meshCopy->UnlockVertexBuffer();
pMesh->Release();
return meshCopy;
}
What do I need to do to scale the normals? Any ideas?
I've got a problem when scaling a mesh: I don't know how to scale the normals. So when I resize my mesh - the lighting doesnt work!
Here's the code:
LPD3DXMESH ScaleMesh(LPD3DXMESH pMesh, double xscale, double yscale, double zscale){
struct Vertex {
D3DXVECTOR3 pos;
float tu;
float tv;
enum {
VertexFVF = D3DFVF_XYZ | D3DFVF_TEX1
};
};
LPD3DXMESH meshCopy;
Vertex *pVertex;
DWORD NUM_VERTICES = pMesh->GetNumVertices();
DWORD i;
pMesh->CloneMeshFVF(0, Vertex::VertexFVF, gD3DDevice, shCopy);
meshCopy->LockVertexBuffer(0,(VOID**)&pVertex);
for ( i=0;i<NUM_VERTICES;i++) {
// Scale
pVertex.pos.x *= xscale;
pVertex.pos.y *= yscale;
pVertex.pos.z *= zscale;
}
meshCopy->UnlockVertexBuffer();
pMesh->Release();
return meshCopy;
}
What do I need to do to scale the normals? Any ideas?