* doodads are now displayed on the map

* commented out a line in the M2 loader, it was causing a crash (?!)
* added NormalizeFilename() in tools.cpp, please use this when formatting filenames for linux
* TODO: remove doodads that are too far away or if the map is changed. currently its using A LOT of graphics power
This commit is contained in:
false_genesis 2008-04-06 21:00:19 +00:00
parent 79a7f0dfae
commit 4cef295bed
10 changed files with 76 additions and 9 deletions

View File

@ -77,7 +77,7 @@ for(u32 i =0;i<header.nViews;i++)
file->read(&tempM2MView,sizeof(ModelView));
M2MViews.push_back(tempM2MView);
}
std::cout << "Read "<<M2MViews.size()<<"/"<<header.nViews<<" Views\n";
//std::cout << "Read "<<M2MViews.size()<<"/"<<header.nViews<<" Views\n";
logger->log("Using View 0 for all further operations",ELL_INFORMATION);
std::cout<<"This View has "<<M2MViews[0].nSub<<" Submeshes\n";
@ -195,7 +195,8 @@ for(u32 i=0; i<M2MTextureDef.size(); i++)
{
tempTexFileName.reserve(M2MTextureDef[i].texFileLen + 1);
file->seek(M2MTextureDef[i].texFileOfs);
file->read(&tempTexFileName[0],M2MTextureDef[i].texFileLen);
file->read((void*)tempTexFileName.c_str(),M2MTextureDef[i].texFileLen);
std::cout << "texture: '" << tempTexFileName << "'\n";
M2MTextureFiles.push_back(tempTexFileName.c_str());
std::cout<<M2MTextureFiles.size()<<"-"<<M2MTextureFiles[i].c_str()<<"\n";
}

View File

@ -96,7 +96,7 @@ void DrawObject::Draw(void)
if(cube)
{
WorldPosition pos = ((WorldObject*)_obj)->GetPosition();
cube->setPosition(irr::core::vector3df(-pos.x,pos.z,-pos.y));
cube->setPosition(WPToIrr(pos));
rotation.Y = O_TO_IRR(pos.o);
float s = _obj->GetFloatValue(OBJECT_FIELD_SCALE_X);

View File

@ -82,7 +82,6 @@ private:
MapMgr *mapmgr;
IGUIStaticText *debugText;
bool debugmode;
gui::IGUIImage *icursor;
};

View File

@ -276,6 +276,7 @@ void SceneWorld::UpdateTerrain(void)
{
// apply map height data
for(uint32 chy = 0; chy < 16; chy++)
{
for(uint32 chx = 0; chx < 16; chx++)
{
MapChunk *chunk = maptile->GetChunk(chx, chy);
@ -291,6 +292,22 @@ void SceneWorld::UpdateTerrain(void)
}
}
}
// create doodads
for(uint32 i = 0; i < maptile->GetDoodadCount(); i++)
{
Doodad *d = maptile->GetDoodad(i);
scene::IAnimatedMesh *mesh = smgr->getMesh(d->model.c_str());
if(mesh)
{
scene::ISceneNode *doodad = smgr->addAnimatedMeshSceneNode(mesh);
if(doodad)
{
doodad->setPosition(core::vector3df(-d->x, d->z, -d->y));
doodad->setRotation(core::vector3df(d->ox + 270.0f, d->oy, d->oz)); // +270 solves M2 models lying on the side
}
}
}
}
else
{
logerror("SceneWorld: MapTile (%u, %u) not loaded, can't apply heightmap!", mapmgr->GetGridX()+tilex, mapmgr->GetGridY()+tiley);

View File

@ -142,7 +142,7 @@ bool ADTFile::LoadMem(ByteBuffer& buf)
}*/
else if(!strcmp((char*)fourcc,"MDDF"))
{
uint32 ndoodads = size / 36;
uint32 ndoodads = size / sizeof(MDDF_chunk);
//DEBUG(printf("ADT: Loading %u doodads.\n",ndoodads));
for(uint32 i = 0; i<ndoodads; i++)
{

View File

@ -51,12 +51,12 @@ struct MDDF_chunk
{
uint32 id; // position in the MMDX list
uint32 uniqueid; // unique instance id (?)
float x;
float x; // position (quaternion)
float y;
float z;
float oy;
float oz;
float ox;
float a; // rotatation
float b;
float c;
uint16 flags;
uint16 scale;
};

View File

@ -68,6 +68,30 @@ void MapTile::ImportFromADT(ADTFile *adt)
}
}
}
// copy over doodads and do some transformations
DEBUG(logdebug("%u doodads", adt->_doodadsp.size()));
for(uint32 i = 0; i < adt->_doodadsp.size(); i++)
{
Doodad d;
MDDF_chunk& mddf = adt->_doodadsp[i];
// and yet another coordinate system...
d.y = -(mddf.x - ZEROPOINT);
d.z = mddf.y;
d.x = -(mddf.z - ZEROPOINT);
d.ox = mddf.c;
d.oy = mddf.b - 90.0f; // wowdev states Y=B-90, but this doesnt really look as expected...
d.oz = -mddf.a;
d.flags = mddf.flags;
d.model = std::string("./data/model/") + NormalizeFilename(_PathToFileName(adt->_models[mddf.id]));
// this .mdx -> .m2 transformation is annoying >.< - replace "mdx" and end of string with "m2\0"
memcpy(&d.model[0] + d.model.size() - 3, "m2\0", 3);
d.scale = mddf.scale / 1024.0f;
if(d.scale < 0.00001f)
d.scale = 1;
_doodads.push_back(d);
}
_xbase = _chunks[0].basex;
_ybase = _chunks[0].basey;
_hbase = _chunks[0].baseheight;

View File

@ -25,6 +25,13 @@ public:
//... TODO: implement the rest of this
};
struct Doodad
{
float x,y,z,ox,oy,oz,scale;
uint16 flags;
std::string model;
};
// generic map tile class. stores the information previously stored in an ADT file
// in an easier to use form.
class MapTile
@ -39,12 +46,15 @@ public:
inline float GetBaseX(void) { return _xbase; }
inline float GetBaseY(void) { return _ybase; }
inline float GetBaseHeight(void) { return _hbase; }
inline uint32 GetDoodadCount(void) { return _doodads.size(); }
inline Doodad *GetDoodad(uint32 i) { return &_doodads[i]; }
private:
MapChunk _chunks[256]; // 16x16
std::vector<std::string> _textures;
std::vector<std::string> _wmos;
std::vector<std::string> _models;
std::vector<Doodad> _doodads;
float _xbase,_ybase,_hbase;

View File

@ -231,4 +231,19 @@ std::string _PathToFileName(std::string str)
return str;
}
std::string NormalizeFilename(std::string s)
{
uint32 p;
while( (p = s.find('\\')) != std::string::npos)//Replace \ by /
{
s.replace(p,1,"/");
}
while( (p = s.find(' ')) != std::string::npos)//Replace space by _
{
s.replace(p,1,"_");
}
std::transform(s.begin(), s.end(), s.begin(), tolower);
return s;
}

View File

@ -22,5 +22,6 @@ uint32 getMSTime(void);
uint32 GetFileSize(const char*);
void _FixFileName(std::string&);
std::string _PathToFileName(std::string);
std::string NormalizeFilename(std::string);
#endif