Great work ^^
M2 are rotated with quaternion only in wmo meshes ...
I have z for height.
For rotation in adt i use
Code:
for (int i = 0; i < adt.mddf.GetSize(); i++)
{
/* Get the M2 file name */
std::string m2_filepath = adt.mmdx.GetOffset(adt.mmid[adt.mddf[i].nameId]);
if (m2_filepath.find(".mdx") != std::string::npos)
FindAndReplace(m2_filepath, ".mdx", ".m2");
else if (m2_filepath.find(".MDX") != std::string::npos)
FindAndReplace(m2_filepath, ".MDX", ".m2");
else if (m2_filepath.find(".MDL") != std::string::npos)
FindAndReplace(m2_filepath, ".MDL", ".m2");
/* Set Translation, Rotation and scale */
Vertex translation;
translation.x = (17066.666666666656f - adt.mddf[i].pos[2]);
translation.y = adt.mddf[i].pos[1];
translation.z = -(17066.666666666656f - adt.mddf[i].pos[0]);
RotationMatrixf rotation_matrix;
//THIS !
rotation_matrix = rotation_matrix.FromEulerAnglesXZY((-adt.mddf[i].rot[2])*rad,(adt.mddf[i].rot[0]) * rad,(-adt.mddf[i].rot[1] + 180) * rad);
ScaleValue scale;
scale.n = 1024.0f / (adt.mddf[i].scale);
METransformStrategyPtr m2_transformation = MatrixTrans::Create(
rotation_matrix, translation, scale);
/* add this M2 */
MapLodObject* m2_map_object = MapLodObject::Create(m2_filepath,
mMapResource["M2Resource"], m2_transformation,
adt.mddf[i].uniqueId);
/* Add element to Doodas_set */
ret_map_node->AddMapElement(m2_map_object);
}
and in wmo :
Code:
for (int j = wmo_root.mods[doodadSetIndex].firstinstanceindex; j < wmo_root.mods[doodadSetIndex].firstinstanceindex + wmo_root.mods[doodadSetIndex].numDoodads; j++)
{
/* Get the file name */
std::string m2_filepath = wmo_root.modn.GetOffset(wmo_root.modd[j].nameOffs);
if (m2_filepath.find(".mdx") != std::string::npos)
FindAndReplace(m2_filepath, ".mdx", ".m2");
else if (m2_filepath.find(".MDX") != std::string::npos)
FindAndReplace(m2_filepath, ".MDX", ".m2");
else if (m2_filepath.find(".MDL") != std::string::npos)
FindAndReplace(m2_filepath, ".MDL", ".m2");
/* TODO : Binary search
if(!GetMpqConteining(m2_filepath.c_str()))
throw std::runtime_error("WowMapTileBuilder::BuildAdt() : Can't find \"" + m2_filepath + "\".");
*/
/* Set Translation, Rotation and scale */
Vertex traslation;
traslation.x = wmo_root.modd[j].pos[0];
traslation.y = wmo_root.modd[j].pos[2];
traslation.z = -wmo_root.modd[j].pos[1];
//THIS !
Quaternionf rotation_quaternion = Quaternionf(wmo_root.modd[j].rot[3],wmo_root.modd[j].rot[0], wmo_root.modd[j].rot[2], -wmo_root.modd[j].rot[1]);
ScaleValue scale;
scale.n = 1.0f / wmo_root.modd[j].scale;
METransformStrategyPtr m2_transformation = QuaternionTrans::Create(rotation_quaternion,traslation,scale);
/* Create the M2 Element */
MapLodObject* ob = MapLodObject::Create(m2_filepath,mMapResource["M2Resource"],m2_transformation);
/* add this element to the doodads set*/
doodads_set->AddMapElement(ob);
}
where QuaternionTrans and MatrixTrans are only a function that applies the transformation
Hope this can help
PS: Bounding mesh is different from view mesh ... in boat I think that there is a mismatch of bounding box and mesh