aboutsummaryrefslogtreecommitdiff
path: root/src/server/collision/Models
diff options
context:
space:
mode:
Diffstat (limited to 'src/server/collision/Models')
-rw-r--r--src/server/collision/Models/GameObjectModel.cpp173
-rw-r--r--src/server/collision/Models/GameObjectModel.h69
-rw-r--r--src/server/collision/Models/WorldModel.cpp4
-rwxr-xr-xsrc/server/collision/Models/WorldModel.h3
4 files changed, 248 insertions, 1 deletions
diff --git a/src/server/collision/Models/GameObjectModel.cpp b/src/server/collision/Models/GameObjectModel.cpp
new file mode 100644
index 00000000000..1abbc59a5b0
--- /dev/null
+++ b/src/server/collision/Models/GameObjectModel.cpp
@@ -0,0 +1,173 @@
+/*
+ * Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "VMapFactory.h"
+#include "VMapManager2.h"
+#include "VMapDefinitions.h"
+#include "WorldModel.h"
+
+#include "GameObjectModel.h"
+#include "Log.h"
+#include "GameObject.h"
+#include "Creature.h"
+#include "TemporarySummon.h"
+#include "Object.h"
+#include "DBCStores.h"
+
+using G3D::Vector3;
+using G3D::Ray;
+using G3D::AABox;
+
+struct GameobjectModelData
+{
+ GameobjectModelData(const std::string& name_, const AABox& box) :
+ bound(box), name(name_) {}
+
+ AABox bound;
+ std::string name;
+};
+
+typedef UNORDERED_MAP<uint32, GameobjectModelData> ModelList;
+ModelList model_list;
+
+void LoadGameObjectModelList()
+{
+ FILE* model_list_file = fopen((sWorld->GetDataPath() + "vmaps/" + VMAP::GAMEOBJECT_MODELS).c_str(), "rb");
+ if (!model_list_file)
+ return;
+
+ uint32 name_length, displayId;
+ char buff[500];
+ while (!feof(model_list_file))
+ {
+ Vector3 v1, v2;
+ if (fread(&displayId, sizeof(uint32), 1, model_list_file) != 1
+ || fread(&name_length, sizeof(uint32), 1, model_list_file) != 1
+ || name_length >= sizeof(buff)
+ || fread(&buff, sizeof(char), name_length, model_list_file) != name_length
+ || fread(&v1, sizeof(Vector3), 1, model_list_file) != 1
+ || fread(&v2, sizeof(Vector3), 1, model_list_file) != 1)
+ {
+ printf("\nFile '%s' seems to be corrupted", VMAP::GAMEOBJECT_MODELS);
+ break;
+ }
+
+ model_list.insert
+ (
+ ModelList::value_type( displayId, GameobjectModelData(std::string(buff,name_length),AABox(v1,v2)) )
+ );
+ }
+ fclose(model_list_file);
+}
+
+GameObjectModel::~GameObjectModel()
+{
+ if (iModel)
+ ((VMAP::VMapManager2*)VMAP::VMapFactory::createOrGetVMapManager())->releaseModelInstance(name);
+}
+
+bool GameObjectModel::initialize(const GameObject& go, const GameObjectDisplayInfoEntry& info)
+{
+ ModelList::const_iterator it = model_list.find(info.Displayid);
+ if (it == model_list.end())
+ return false;
+
+ G3D::AABox mdl_box(it->second.bound);
+ // ignore models with no bounds
+ if (mdl_box == G3D::AABox::zero())
+ {
+ std::cout << "Model " << it->second.name << " has zero bounds, loading skipped" << std::endl;
+ return false;
+ }
+
+ iModel = ((VMAP::VMapManager2*)VMAP::VMapFactory::createOrGetVMapManager())->acquireModelInstance(sWorld->GetDataPath() + "vmaps/", it->second.name);
+
+ if (!iModel)
+ return false;
+
+ name = it->second.name;
+ //flags = VMAP::MOD_M2;
+ //adtId = 0;
+ //ID = 0;
+ iPos = Vector3(go.GetPositionX(), go.GetPositionY(), go.GetPositionZ());
+ phasemask = go.GetPhaseMask();
+ iScale = go.GetFloatValue(OBJECT_FIELD_SCALE_X);
+ iInvScale = 1.f / iScale;
+
+ G3D::Matrix3 iRotation = G3D::Matrix3::fromEulerAnglesZYX(go.GetOrientation(), 0, 0);
+ iInvRot = iRotation.inverse();
+ // transform bounding box:
+ mdl_box = AABox(mdl_box.low() * iScale, mdl_box.high() * iScale);
+ AABox rotated_bounds;
+ for (int i = 0; i < 8; ++i)
+ rotated_bounds.merge(iRotation * mdl_box.corner(i));
+
+ this->iBound = rotated_bounds + iPos;
+#ifdef SPAWN_CORNERS
+ // test:
+ for (int i = 0; i < 8; ++i)
+ {
+ Vector3 pos(iBound.corner(i));
+ if (Creature* c = const_cast<GameObject&>(go).SummonCreature(24440, pos.x, pos.y, pos.z, 0, TEMPSUMMON_MANUAL_DESPAWN))
+ {
+ c->setFaction(35);
+ c->SetFloatValue(OBJECT_FIELD_SCALE_X, 0.1f);
+ }
+ }
+#endif
+
+ return true;
+}
+
+GameObjectModel* GameObjectModel::Create(const GameObject& go)
+{
+ const GameObjectDisplayInfoEntry* info = sGameObjectDisplayInfoStore.LookupEntry(go.GetGOInfo()->displayId);
+ if (!info)
+ return NULL;
+
+ GameObjectModel* mdl = new GameObjectModel();
+ if (!mdl->initialize(go, *info))
+ {
+ delete mdl;
+ return NULL;
+ }
+
+ return mdl;
+}
+
+bool GameObjectModel::intersectRay(const G3D::Ray& ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask) const
+{
+ if (!(phasemask & ph_mask))
+ return false;
+
+ float time = ray.intersectionTime(iBound);
+ if (time == G3D::inf())
+ return false;
+
+ // child bounds are defined in object space:
+ Vector3 p = iInvRot * (ray.origin() - iPos) * iInvScale;
+ Ray modRay(p, iInvRot * ray.direction());
+ float distance = MaxDist * iInvScale;
+ bool hit = iModel->IntersectRay(modRay, distance, StopAtFirstHit);
+ if(hit)
+ {
+ distance *= iScale;
+ MaxDist = distance;
+ }
+ return hit;
+}
diff --git a/src/server/collision/Models/GameObjectModel.h b/src/server/collision/Models/GameObjectModel.h
new file mode 100644
index 00000000000..0bb6c0f47bc
--- /dev/null
+++ b/src/server/collision/Models/GameObjectModel.h
@@ -0,0 +1,69 @@
+/*
+ * Copyright (C) 2008-2012 TrinityCore <http://www.trinitycore.org/>
+ * Copyright (C) 2005-2009 MaNGOS <http://getmangos.com/>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+ * more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _GAMEOBJECT_MODEL_H
+#define _GAMEOBJECT_MODEL_H
+
+#include <G3D/Matrix3.h>
+#include <G3D/Vector3.h>
+#include <G3D/AABox.h>
+#include <G3D/Ray.h>
+
+#include "Define.h"
+
+namespace VMAP
+{
+ class WorldModel;
+}
+
+class GameObject;
+struct GameObjectDisplayInfoEntry;
+
+class GameObjectModel /*, public Intersectable*/
+{
+ uint32 phasemask;
+ G3D::AABox iBound;
+ G3D::Matrix3 iInvRot;
+ G3D::Vector3 iPos;
+ //G3D::Vector3 iRot;
+ float iInvScale;
+ float iScale;
+ VMAP::WorldModel* iModel;
+
+ GameObjectModel() : phasemask(0), iModel(NULL) {}
+ bool initialize(const GameObject& go, const GameObjectDisplayInfoEntry& info);
+
+public:
+ std::string name;
+
+ const G3D::AABox& getBounds() const { return iBound; }
+
+ ~GameObjectModel();
+
+ const G3D::Vector3& getPosition() const { return iPos;}
+
+ /** Enables\disables collision. */
+ void disable() { phasemask = 0;}
+ void enable(uint32 ph_mask) { phasemask = ph_mask;}
+
+ bool intersectRay(const G3D::Ray& Ray, float& MaxDist, bool StopAtFirstHit, uint32 ph_mask) const;
+
+ static GameObjectModel* Create(const GameObject& go);
+};
+
+#endif // _GAMEOBJECT_MODEL_H \ No newline at end of file
diff --git a/src/server/collision/Models/WorldModel.cpp b/src/server/collision/Models/WorldModel.cpp
index a7de37d41e6..cda34510058 100644
--- a/src/server/collision/Models/WorldModel.cpp
+++ b/src/server/collision/Models/WorldModel.cpp
@@ -17,6 +17,7 @@
*/
#include "WorldModel.h"
+#include "ModelInstance.h"
#include "VMapDefinitions.h"
#include "MapTree.h"
@@ -420,6 +421,9 @@ namespace VMAP
bool WorldModel::IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const
{
+ // M2 models are not taken into account for LoS calculation
+ if (Flags & MOD_M2)
+ return false;
// small M2 workaround, maybe better make separate class with virtual intersection funcs
// in any case, there's no need to use a bound tree if we only have one submodel
if (groupModels.size() == 1)
diff --git a/src/server/collision/Models/WorldModel.h b/src/server/collision/Models/WorldModel.h
index 52ecf498700..dbaccb58573 100755
--- a/src/server/collision/Models/WorldModel.h
+++ b/src/server/collision/Models/WorldModel.h
@@ -80,7 +80,7 @@ namespace VMAP
//! pass mesh data to object and create BIH. Passed vectors get get swapped with old geometry!
void setMeshData(std::vector<Vector3> &vert, std::vector<MeshTriangle> &tri);
- void setLiquidData(WmoLiquid* liquid) { iLiquid = liquid; }
+ void setLiquidData(WmoLiquid*& liquid) { iLiquid = liquid; liquid = NULL; }
bool IntersectRay(const G3D::Ray &ray, float &distance, bool stopAtFirstHit) const;
bool IsInsideObject(const Vector3 &pos, const Vector3 &down, float &z_dist) const;
bool GetLiquidLevel(const Vector3 &pos, float &liqHeight) const;
@@ -113,6 +113,7 @@ namespace VMAP
bool GetLocationInfo(const G3D::Vector3 &p, const G3D::Vector3 &down, float &dist, LocationInfo &info) const;
bool writeFile(const std::string &filename);
bool readFile(const std::string &filename);
+ uint32 Flags;
protected:
uint32 RootWMOID;
std::vector<GroupModel> groupModels;