Ticket #2033: prop_alignment.diff

File prop_alignment.diff, 10.8 KB (added by sanderd17, 11 years ago)
  • binaries/data/mods/public/art/actors/structures/persians/stables.xml

     
    77      <props>
    88        <prop actor="props/structures/decals/dirt_4x4.xml" attachpoint="root"/>
    99        <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"/>
    1313      </props>
    1414      <textures><texture file="structural/pers_struct.dds" name="baseTex"/></textures>
    1515    </variant>
  • source/graphics/Model.cpp

     
    3636#include "ps/Profile.h"
    3737#include "ps/CLogger.h"
    3838#include "renderer/Renderer.h"
     39#include "simulation2/Simulation2.h"
     40#include "simulation2/components/ICmpTerrain.h"
    3941
     42
    4043/////////////////////////////////////////////////////////////////////////////////////////////////////////////
    4144// Constructor
    42 CModel::CModel(CSkeletonAnimManager& skeletonAnimManager)
    43     : m_Flags(0), m_Anim(NULL), m_AnimTime(0),
     45CModel::CModel(CSkeletonAnimManager& skeletonAnimManager, CSimulation2& simulation)
     46    : m_Flags(0), m_Anim(NULL), m_AnimTime(0), m_Simulation(simulation),
    4447    m_BoneMatrices(NULL),
    4548    m_AmmoPropPoint(NULL), m_AmmoLoadedProp(0),
    4649    m_SkeletonAnimManager(skeletonAnimManager)
     
    380383    {
    381384        const Prop& prop=m_Props[j];
    382385
    383         CMatrix3D proptransform = prop.m_Point->m_Transform;;
     386        CMatrix3D proptransform = prop.m_Point->m_Transform;
     387
     388       
    384389        if (prop.m_Point->m_BoneIndex != 0xff)
    385390        {
    386391            CMatrix3D boneMatrix = m_BoneMatrices[prop.m_Point->m_BoneIndex];
     
    393398            // not relative to any bone; just apply world-space transformation (i.e. relative to object-space origin)
    394399            proptransform.Concatenate(m_Transform);
    395400        }
     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        }
    396421       
    397422        prop.m_Model->SetTransform(proptransform);
    398423        prop.m_Model->ValidatePosition();
     
    484509
    485510/////////////////////////////////////////////////////////////////////////////////////////////////////////////
    486511// AddProp: add a prop to the model on the given point
    487 void CModel::AddProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry)
     512void CModel::AddProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry, float minHeight, float maxHeight)
    488513{
    489514    // position model according to prop point position
    490515
     
    496521    prop.m_Point = point;
    497522    prop.m_Model = model;
    498523    prop.m_ObjectEntry = objectentry;
     524    prop.m_minHeight = minHeight;
     525    prop.m_maxHeight = maxHeight;
    499526    m_Props.push_back(prop);
    500527}
    501528
    502529void CModel::AddAmmoProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry)
    503530{
    504     AddProp(point, model, objectentry);
     531    AddProp(point, model, objectentry, 0.f, 0.f);
    505532    m_AmmoPropPoint = point;
    506533    m_AmmoLoadedProp = m_Props.size() - 1;
    507534    m_Props[m_AmmoLoadedProp].m_Hidden = true;
     
    564591// Clone: return a clone of this model
    565592CModelAbstract* CModel::Clone() const
    566593{
    567     CModel* clone = new CModel(m_SkeletonAnimManager);
     594    CModel* clone = new CModel(m_SkeletonAnimManager,m_Simulation);
    568595    clone->m_ObjectBounds = m_ObjectBounds;
    569596    clone->InitModel(m_pModelDef);
    570597    clone->SetMaterial(m_Material);
     
    577604        if (m_AmmoPropPoint && i == m_AmmoLoadedProp)
    578605            clone->AddAmmoProp(m_Props[i].m_Point, m_Props[i].m_Model->Clone(), m_Props[i].m_ObjectEntry);
    579606        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);
    581608    }
    582609
    583610    return clone;
  • source/graphics/Model.h

     
    3535class CSkeletonAnim;
    3636class CSkeletonAnimDef;
    3737class CSkeletonAnimManager;
     38class CSimulation2;
    3839
    3940#define MODELFLAG_CASTSHADOWS       (1<<0)
    4041#define MODELFLAG_NOLOOPANIMATION   (1<<1)
     
    5556    {
    5657        Prop() : m_Point(0), m_Model(0), m_ObjectEntry(0), m_Hidden(false) {}
    5758
     59        float m_minHeight;
     60        float m_maxHeight;
     61
    5862        /**
    5963         * Location of the prop point within its parent model, relative to either a bone in the parent model or to the
    6064         * parent model's origin. See the documentation for @ref SPropPoint for more details.
     
    7579
    7680public:
    7781    // constructor
    78     CModel(CSkeletonAnimManager& skeletonAnimManager);
     82    CModel(CSkeletonAnimManager& skeletonAnimManager, CSimulation2& simulation);
    7983    // destructor
    8084    ~CModel();
    8185
     86
    8287    /// Dynamic cast
    8388    virtual CModel* ToCModel()
    8489    {
     
    205210    /**
    206211     * Add a prop to the model on the given point.
    207212     */
    208     void AddProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry);
     213    void AddProp(const SPropPoint* point, CModelAbstract* model, CObjectEntry* objectentry, float minHeight, float maxHeight);
    209214
    210215    /**
    211216     * Add a prop to the model on the given point, and treat it as the ammo prop.
     
    250255private:
    251256    // delete anything allocated by the model
    252257    void ReleaseData();
     258   
     259    CSimulation2& m_Simulation;
    253260
    254261    // object flags
    255262    int m_Flags;
  • source/graphics/ObjectBase.cpp

     
    8080    AT(angle);
    8181    AT(offsetx);
    8282    AT(offsetz);
     83    AT(minheight);
     84    AT(maxheight);
    8385    #undef AT
    8486    #undef EL
    8587
     
    246248                                    prop.m_PropPointName = pe.Value;
    247249                                else if (pe.Name == at_actor)
    248250                                    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();
    249255                            }
    250256                            currentVariant->m_Props.push_back(prop);
    251257                        }
  • source/graphics/ObjectBase.h

     
    5959        CStr m_PropPointName;
    6060        // name of the model file - art/actors/props/sword.xml or whatever
    6161        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;
    6265    };
    6366   
    6467    struct Samp
  • source/graphics/ObjectEntry.cpp

     
    3535#include "ps/Game.h"
    3636#include "ps/World.h"
    3737#include "renderer/Renderer.h"
     38#include "simulation2/Simulation2.h"
    3839
    3940#include <sstream>
    4041
    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)
     42CObjectEntry::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)
    4344{
    4445}
    4546
     
    123124    }
    124125
    125126    // delete old model, create new
    126     CModel* model = new CModel(objectManager.GetSkeletonAnimManager());
     127    CModel* model = new CModel(objectManager.GetSkeletonAnimManager(), m_Simulation);
    127128    delete m_Model;
    128129    m_Model = model;
    129130    model->SetMaterial(g_Renderer.GetMaterialManager().LoadMaterial(m_Base->m_Material));
     
    234235            if (isAmmo)
    235236                model->AddAmmoProp(proppoint, propmodel, oe);
    236237            else
    237                 model->AddProp(proppoint, propmodel, oe);
     238                model->AddProp(proppoint, propmodel, oe, prop.m_minHeight, prop.m_maxHeight);
    238239            if (propmodel->ToCModel())
    239240                propmodel->ToCModel()->SetAnimation(oe->GetRandomAnimation("idle"));
    240241        }
  • source/graphics/ObjectEntry.h

     
    2222class CSkeletonAnim;
    2323class CObjectBase;
    2424class CObjectManager;
     25class CSimulation2;
    2526struct SPropPoint;
    2627
    2728#include <map>
     
    3738class CObjectEntry
    3839{
    3940public:
    40     CObjectEntry(CObjectBase* base);
     41    CObjectEntry(CObjectBase* base, CSimulation2& simulation);
    4142    ~CObjectEntry();
    4243
    4344    // Construct this actor, using the specified variation selections
     
    7576    bool m_Outdated;
    7677
    7778private:
     79    CSimulation2& m_Simulation;
     80
    7881    typedef std::multimap<CStr, CSkeletonAnim*> SkeletonAnimMap;
    7982    SkeletonAnimMap m_Animations;
    8083        // TODO: something more memory-efficient than storing loads of similar strings for each unit?
  • source/graphics/ObjectManager.cpp

     
    139139    // makes more sense (e.g. use shared_ptr); for now I'll just leak, to avoid making the logic
    140140    // more complex than it is already is, since this only matters for the rare case of hotloading.
    141141
    142     CObjectEntry* obj = new CObjectEntry(base); // TODO: type ?
     142    CObjectEntry* obj = new CObjectEntry(base, m_Simulation); // TODO: type ?
    143143
    144144    // TODO (for some efficiency): use the pre-calculated choices for this object,
    145145    // which has already worked out what to do for props, instead of passing the