Ticket #2033: prop_alignment.diff
File prop_alignment.diff, 10.8 KB (added by , 11 years ago) |
---|
-
binaries/data/mods/public/art/actors/structures/persians/stables.xml
7 7 <props> 8 8 <prop actor="props/structures/decals/dirt_4x4.xml" attachpoint="root"/> 9 9 <prop actor="props/structures/decals/celt_sb1_mud.xml" attachpoint="root"/> 10 <prop actor="props/structures/persians/stable_horse_a.xml" attachpoint="horsea" />11 <prop actor="props/structures/persians/stable_horse_b.xml" attachpoint="horseb" />12 <prop actor="props/structures/persians/stable_horse_c.xml" attachpoint="horsec" />10 <prop actor="props/structures/persians/stable_horse_a.xml" attachpoint="horsea" minheight="-20" maxheight="1.7"/> 11 <prop actor="props/structures/persians/stable_horse_b.xml" attachpoint="horseb" minheight="-20" maxheight="1.7"/> 12 <prop actor="props/structures/persians/stable_horse_c.xml" attachpoint="horsec" minheight="-20" maxheight="1.7"/> 13 13 </props> 14 14 <textures><texture file="structural/pers_struct.dds" name="baseTex"/></textures> 15 15 </variant> -
source/graphics/Model.cpp
36 36 #include "ps/Profile.h" 37 37 #include "ps/CLogger.h" 38 38 #include "renderer/Renderer.h" 39 #include "simulation2/Simulation2.h" 40 #include "simulation2/components/ICmpTerrain.h" 39 41 42 40 43 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// 41 44 // Constructor 42 CModel::CModel(CSkeletonAnimManager& skeletonAnimManager )43 : m_Flags(0), m_Anim(NULL), m_AnimTime(0), 45 CModel::CModel(CSkeletonAnimManager& skeletonAnimManager, CSimulation2& simulation) 46 : m_Flags(0), m_Anim(NULL), m_AnimTime(0), m_Simulation(simulation), 44 47 m_BoneMatrices(NULL), 45 48 m_AmmoPropPoint(NULL), m_AmmoLoadedProp(0), 46 49 m_SkeletonAnimManager(skeletonAnimManager) … … 380 383 { 381 384 const Prop& prop=m_Props[j]; 382 385 383 CMatrix3D proptransform = prop.m_Point->m_Transform;; 386 CMatrix3D proptransform = prop.m_Point->m_Transform; 387 388 384 389 if (prop.m_Point->m_BoneIndex != 0xff) 385 390 { 386 391 CMatrix3D boneMatrix = m_BoneMatrices[prop.m_Point->m_BoneIndex]; … … 393 398 // not relative to any bone; just apply world-space transformation (i.e. relative to object-space origin) 394 399 proptransform.Concatenate(m_Transform); 395 400 } 401 402 // Adjust prop height to terrain level when needed 403 if (prop.m_maxHeight != 0.f || prop.m_minHeight != 0.f) 404 { 405 CVector3D propTranslation = proptransform.GetTranslation(); 406 CVector3D objTranslation = m_Transform.GetTranslation(); 407 408 CmpPtr<ICmpTerrain> cmpTerrain(m_Simulation, SYSTEM_ENTITY); 409 if (cmpTerrain) 410 { 411 float objTerrain = cmpTerrain->GetExactGroundLevel(objTranslation.X, objTranslation.Z); 412 float propTerrain = cmpTerrain->GetExactGroundLevel(propTranslation.X, propTranslation.Z); 413 float translateHeight = propTerrain - objTerrain; 414 translateHeight = fmax(translateHeight, prop.m_minHeight); 415 translateHeight = fmin(translateHeight, prop.m_maxHeight); 416 CMatrix3D translate = CMatrix3D(); 417 translate.SetTranslation(0.f,translateHeight,0.f); 418 proptransform.Concatenate(translate); 419 } 420 } 396 421 397 422 prop.m_Model->SetTransform(proptransform); 398 423 prop.m_Model->ValidatePosition(); … … 484 509 485 510 ///////////////////////////////////////////////////////////////////////////////////////////////////////////// 486 511 // AddProp: add a prop to the model on the given point 487 void CModel::AddProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry )512 void CModel::AddProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry, float minHeight, float maxHeight) 488 513 { 489 514 // position model according to prop point position 490 515 … … 496 521 prop.m_Point = point; 497 522 prop.m_Model = model; 498 523 prop.m_ObjectEntry = objectentry; 524 prop.m_minHeight = minHeight; 525 prop.m_maxHeight = maxHeight; 499 526 m_Props.push_back(prop); 500 527 } 501 528 502 529 void CModel::AddAmmoProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry) 503 530 { 504 AddProp(point, model, objectentry );531 AddProp(point, model, objectentry, 0.f, 0.f); 505 532 m_AmmoPropPoint = point; 506 533 m_AmmoLoadedProp = m_Props.size() - 1; 507 534 m_Props[m_AmmoLoadedProp].m_Hidden = true; … … 564 591 // Clone: return a clone of this model 565 592 CModelAbstract* CModel::Clone() const 566 593 { 567 CModel* clone = new CModel(m_SkeletonAnimManager );594 CModel* clone = new CModel(m_SkeletonAnimManager,m_Simulation); 568 595 clone->m_ObjectBounds = m_ObjectBounds; 569 596 clone->InitModel(m_pModelDef); 570 597 clone->SetMaterial(m_Material); … … 577 604 if (m_AmmoPropPoint && i == m_AmmoLoadedProp) 578 605 clone->AddAmmoProp(m_Props[i].m_Point, m_Props[i].m_Model->Clone(), m_Props[i].m_ObjectEntry); 579 606 else 580 clone->AddProp(m_Props[i].m_Point, m_Props[i].m_Model->Clone(), m_Props[i].m_ObjectEntry );607 clone->AddProp(m_Props[i].m_Point, m_Props[i].m_Model->Clone(), m_Props[i].m_ObjectEntry, m_Props[i].m_minHeight, m_Props[i].m_maxHeight); 581 608 } 582 609 583 610 return clone; -
source/graphics/Model.h
35 35 class CSkeletonAnim; 36 36 class CSkeletonAnimDef; 37 37 class CSkeletonAnimManager; 38 class CSimulation2; 38 39 39 40 #define MODELFLAG_CASTSHADOWS (1<<0) 40 41 #define MODELFLAG_NOLOOPANIMATION (1<<1) … … 55 56 { 56 57 Prop() : m_Point(0), m_Model(0), m_ObjectEntry(0), m_Hidden(false) {} 57 58 59 float m_minHeight; 60 float m_maxHeight; 61 58 62 /** 59 63 * Location of the prop point within its parent model, relative to either a bone in the parent model or to the 60 64 * parent model's origin. See the documentation for @ref SPropPoint for more details. … … 75 79 76 80 public: 77 81 // constructor 78 CModel(CSkeletonAnimManager& skeletonAnimManager );82 CModel(CSkeletonAnimManager& skeletonAnimManager, CSimulation2& simulation); 79 83 // destructor 80 84 ~CModel(); 81 85 86 82 87 /// Dynamic cast 83 88 virtual CModel* ToCModel() 84 89 { … … 205 210 /** 206 211 * Add a prop to the model on the given point. 207 212 */ 208 void AddProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry );213 void AddProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry, float minHeight, float maxHeight); 209 214 210 215 /** 211 216 * Add a prop to the model on the given point, and treat it as the ammo prop. … … 250 255 private: 251 256 // delete anything allocated by the model 252 257 void ReleaseData(); 258 259 CSimulation2& m_Simulation; 253 260 254 261 // object flags 255 262 int m_Flags; -
source/graphics/ObjectBase.cpp
80 80 AT(angle); 81 81 AT(offsetx); 82 82 AT(offsetz); 83 AT(minheight); 84 AT(maxheight); 83 85 #undef AT 84 86 #undef EL 85 87 … … 246 248 prop.m_PropPointName = pe.Value; 247 249 else if (pe.Name == at_actor) 248 250 prop.m_ModelName = pe.Value.FromUTF8(); 251 else if (pe.Name == at_minheight) 252 prop.m_minHeight = pe.Value.ToFloat(); 253 else if (pe.Name == at_maxheight) 254 prop.m_maxHeight = pe.Value.ToFloat(); 249 255 } 250 256 currentVariant->m_Props.push_back(prop); 251 257 } -
source/graphics/ObjectBase.h
59 59 CStr m_PropPointName; 60 60 // name of the model file - art/actors/props/sword.xml or whatever 61 61 CStrW m_ModelName; 62 // allow the prop to ajust the height from minHeight to maxHeight relative to the main model 63 float m_minHeight; 64 float m_maxHeight; 62 65 }; 63 66 64 67 struct Samp -
source/graphics/ObjectEntry.cpp
35 35 #include "ps/Game.h" 36 36 #include "ps/World.h" 37 37 #include "renderer/Renderer.h" 38 #include "simulation2/Simulation2.h" 38 39 39 40 #include <sstream> 40 41 41 CObjectEntry::CObjectEntry(CObjectBase* base ) :42 m_Base(base), m_Color(1.0f, 1.0f, 1.0f, 1.0f), m_Model(NULL), m_Outdated(false) 42 CObjectEntry::CObjectEntry(CObjectBase* base, CSimulation2& simulation) : 43 m_Base(base), m_Color(1.0f, 1.0f, 1.0f, 1.0f), m_Model(NULL), m_Outdated(false), m_Simulation(simulation) 43 44 { 44 45 } 45 46 … … 123 124 } 124 125 125 126 // delete old model, create new 126 CModel* model = new CModel(objectManager.GetSkeletonAnimManager() );127 CModel* model = new CModel(objectManager.GetSkeletonAnimManager(), m_Simulation); 127 128 delete m_Model; 128 129 m_Model = model; 129 130 model->SetMaterial(g_Renderer.GetMaterialManager().LoadMaterial(m_Base->m_Material)); … … 234 235 if (isAmmo) 235 236 model->AddAmmoProp(proppoint, propmodel, oe); 236 237 else 237 model->AddProp(proppoint, propmodel, oe );238 model->AddProp(proppoint, propmodel, oe, prop.m_minHeight, prop.m_maxHeight); 238 239 if (propmodel->ToCModel()) 239 240 propmodel->ToCModel()->SetAnimation(oe->GetRandomAnimation("idle")); 240 241 } -
source/graphics/ObjectEntry.h
22 22 class CSkeletonAnim; 23 23 class CObjectBase; 24 24 class CObjectManager; 25 class CSimulation2; 25 26 struct SPropPoint; 26 27 27 28 #include <map> … … 37 38 class CObjectEntry 38 39 { 39 40 public: 40 CObjectEntry(CObjectBase* base );41 CObjectEntry(CObjectBase* base, CSimulation2& simulation); 41 42 ~CObjectEntry(); 42 43 43 44 // Construct this actor, using the specified variation selections … … 75 76 bool m_Outdated; 76 77 77 78 private: 79 CSimulation2& m_Simulation; 80 78 81 typedef std::multimap<CStr, CSkeletonAnim*> SkeletonAnimMap; 79 82 SkeletonAnimMap m_Animations; 80 83 // TODO: something more memory-efficient than storing loads of similar strings for each unit? -
source/graphics/ObjectManager.cpp
139 139 // makes more sense (e.g. use shared_ptr); for now I'll just leak, to avoid making the logic 140 140 // more complex than it is already is, since this only matters for the rare case of hotloading. 141 141 142 CObjectEntry* obj = new CObjectEntry(base ); // TODO: type ?142 CObjectEntry* obj = new CObjectEntry(base, m_Simulation); // TODO: type ? 143 143 144 144 // TODO (for some efficiency): use the pre-calculated choices for this object, 145 145 // which has already worked out what to do for props, instead of passing the