The world matrix is what your put the objects transformations in, so the translation, rotation and scale is put into the world matrix for that object. Remember again the order that you multiply matters. Each transformation you do is relative to the axis (0, 0, 0), So if your objects are not centered around 0, 0, 0, and you try to scale the object, it will appear to be stretched, so you should try to center your objects around the point (0,0,0) in the modeling program. The same goes for rotation. the rotation is done around the point (0,0,0), so if your object is not centered, it will be rotating around the point 0,0,0, and not the objects own center. You can fix this by first translating the object to be centered around the point (0,0,0). First you will have to find your objects true center. So if you want to have the object rotate around it's own center, it would look something like this:
D3DXVECTOR3 objectsTrueCenter;
D3DXMATRIX TranslationTrueCenter;
D3DXMatrixTranslation(&TranslationTrueCenter, -objectsTrueCenter.x, -objectsTrueCenter.y, -objectsTrueCenter.z); // Subtract the objects true center from it's position, so it is centered around 0,0,0
D3DXMATRIX Rotation; // Now create your rotation matrix
D3DXMATRIX Scale; // If you have one, you need to make sure the object is centered around 0,0,0 before you use it, or it will become stretched. since objects are usually centered around 0,0,0 by default, you will want to do a scale before you translate it to another position
D3DXMATRIX worldTranslation; // Now translate the object to the place you want in the world. If your object was already in the place you wanted it (before the translation to 0,0,0), then you can just use the objectsTrueCenter again to put it back in it's place
D3DXMATRIX worldMatrix = TranslationTrueCenter * Scale * Rotation * worldTranslation;
You need to create a world matrix for every object like i already said. About the lighting, it's maybe because you are not rotating your normals correctly
Try multiplying the normal the same way you multiply the vertex position, with all three world view and projection matrices
Show differencesHistory of post edits
#2iedoc
Posted 11 February 2012 - 12:01 AM
The world matrix is what your put the objects transformations in, so the translation, rotation and scale is put into the world matrix for that object. Remember again the order that you multiply matters. Each transformation you do is relative to the axis (0, 0, 0), So if your objects are not centered around 0, 0, 0, and you try to scale the object, it will appear to be stretched, so you should try to center your objects around the point (0,0,0) in the modeling program. The same goes for rotation. the rotation is done around the point (0,0,0), so if your object is not centered, it will be rotating around the point 0,0,0, and not the objects own center. You can fix this by first translating the object to be centered around the point (0,0,0). First you will have to find your objects true center. So if you want to have the object rotate around it's own center, it would look something like this:
D3DXVECTOR3 objectsTrueCenter;
D3DXMATRIX TranslationTrueCenter;
D3DXMatrixTranslation(&TranslationTrueCenter, -objectsTrueCenter.x, -objectsTrueCenter.y, -objectsTrueCenter.z); // Subtract the objects true center from it's position, so it is centered around 0,0,0
D3DXMATRIX Rotation; // Now create your rotation matrix
D3DXMATRIX Scale; // If you have one, you need to make sure the object is centered around 0,0,0 before you use it, or it will become stretched. since objects are usually centered around 0,0,0 by default, you will want to do a scale before you translate it to another position
D3DXMATRIX worldTranslation; // Now translate the object to the place you want in the world. If your object was already in the place you wanted it (before the translation to 0,0,0), then you can just use the objectsTrueCenter again to put it back in it's place
D3DXMATRIX worldMatrix = TranslationTrueCenter * Scale * Rotation * worldTranslation;
You need to create a world matrix for every object like i already said. About the lighting, it's maybe because you are not rotating your normals correctly
D3DXVECTOR3 objectsTrueCenter;
D3DXMATRIX TranslationTrueCenter;
D3DXMatrixTranslation(&TranslationTrueCenter, -objectsTrueCenter.x, -objectsTrueCenter.y, -objectsTrueCenter.z); // Subtract the objects true center from it's position, so it is centered around 0,0,0
D3DXMATRIX Rotation; // Now create your rotation matrix
D3DXMATRIX Scale; // If you have one, you need to make sure the object is centered around 0,0,0 before you use it, or it will become stretched. since objects are usually centered around 0,0,0 by default, you will want to do a scale before you translate it to another position
D3DXMATRIX worldTranslation; // Now translate the object to the place you want in the world. If your object was already in the place you wanted it (before the translation to 0,0,0), then you can just use the objectsTrueCenter again to put it back in it's place
D3DXMATRIX worldMatrix = TranslationTrueCenter * Scale * Rotation * worldTranslation;
You need to create a world matrix for every object like i already said. About the lighting, it's maybe because you are not rotating your normals correctly
#1iedoc
Posted 11 February 2012 - 12:00 AM
Each object has a single "world" matrix. the matrix you are calling local is actually called a world matrix, because it explains the position, size, and rotation of the object in world space. Each object has it's own matrix, but all objects use the same view and projection matrix. So when you draw your geometry, you create a WorldViewProjection matrix to send to the vertex shader by multiplying the three matrices in that order (remember that in matrix multiplication order matters), World*View*Projection. Then in the vertex shader, you multiply the each vertex by the WorldViewProjection matrix.
The world matrix is what your put the objects transformations in, so the translation, rotation and scale is put into the world matrix for that object. Remember again the order that you multiply matters. Each transformation you do is relative to the axis (0, 0, 0), So if your objects are not centered around 0, 0, 0, and you try to scale the object, it will appear to be stretched, so you should try to center your objects around the point (0,0,0) in the modeling program. The same goes for rotation. the rotation is done around the point (0,0,0), so if your object is not centered, it will be rotating around the point 0,0,0, and not the objects own center. You can fix this by first translating the object to be centered around the point (0,0,0). First you will have to find your objects true center. So if you want to have the object rotate around it's own center, it would look something like this:
D3DXVECTOR3 objectsTrueCenter;
D3DXMATRIX TranslationTrueCenter;
D3DXMatrixTranslation(&TranslationTrueCenter, -objectsTrueCenter.x, -objectsTrueCenter.y, -objectsTrueCenter.z); // Subtract the objects true center from it's position, so it is centered around 0,0,0
D3DXMATRIX Rotation; // Now create your rotation matrix
D3DXMATRIX Scale; // If you have one, you need to make sure the object is centered around 0,0,0 before you use it, or it will become stretched. since objects are usually centered around 0,0,0 by default, you will want to do a scale before you translate it to another position
D3DXMATRIX worldTranslation; // Now translate the object to the place you want in the world. If your object was already in the place you wanted it (before the translation to 0,0,0), then you can just use the objectsTrueCenter again to put it back in it's place
D3DXMATRIX worldMatrix = TranslationTrueCenter * Scale * Rotation * worldTranslation;
You need to create a world matrix for every object like i already said. About the lighting, it's maybe because you are not rotating your normals correctly
The world matrix is what your put the objects transformations in, so the translation, rotation and scale is put into the world matrix for that object. Remember again the order that you multiply matters. Each transformation you do is relative to the axis (0, 0, 0), So if your objects are not centered around 0, 0, 0, and you try to scale the object, it will appear to be stretched, so you should try to center your objects around the point (0,0,0) in the modeling program. The same goes for rotation. the rotation is done around the point (0,0,0), so if your object is not centered, it will be rotating around the point 0,0,0, and not the objects own center. You can fix this by first translating the object to be centered around the point (0,0,0). First you will have to find your objects true center. So if you want to have the object rotate around it's own center, it would look something like this:
D3DXVECTOR3 objectsTrueCenter;
D3DXMATRIX TranslationTrueCenter;
D3DXMatrixTranslation(&TranslationTrueCenter, -objectsTrueCenter.x, -objectsTrueCenter.y, -objectsTrueCenter.z); // Subtract the objects true center from it's position, so it is centered around 0,0,0
D3DXMATRIX Rotation; // Now create your rotation matrix
D3DXMATRIX Scale; // If you have one, you need to make sure the object is centered around 0,0,0 before you use it, or it will become stretched. since objects are usually centered around 0,0,0 by default, you will want to do a scale before you translate it to another position
D3DXMATRIX worldTranslation; // Now translate the object to the place you want in the world. If your object was already in the place you wanted it (before the translation to 0,0,0), then you can just use the objectsTrueCenter again to put it back in it's place
D3DXMATRIX worldMatrix = TranslationTrueCenter * Scale * Rotation * worldTranslation;
You need to create a world matrix for every object like i already said. About the lighting, it's maybe because you are not rotating your normals correctly