File: object.hpp

package info (click to toggle)
openmw 0.50.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 37,076 kB
  • sloc: cpp: 380,958; xml: 2,192; sh: 1,449; python: 911; makefile: 26; javascript: 5
file content (197 lines) | stat: -rw-r--r-- 5,152 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
#ifndef OPENCS_VIEW_OBJECT_H
#define OPENCS_VIEW_OBJECT_H

#include <memory>
#include <string>

#include <osg/Vec3f>
#include <osg/Vec4f>
#include <osg/ref_ptr>

#include <components/esm/position.hpp>
#include <components/esm/refid.hpp>

#include "tagbase.hpp"

class QModelIndex;

namespace osg
{
    class PositionAttitudeTransform;
    class Geometry;
    class Group;
    class Node;
}

namespace osgFX
{
    class Scribe;
}

namespace Resource
{
    class ResourceSystem;
}

namespace CSMWorld
{
    class Data;
    struct CellRef;
    class CommandMacro;
}

namespace CSVRender
{
    class Actor;
    class Object;
    struct WorldspaceHitResult;

    // An object to attach as user data to the osg::Node, allows us to get an Object back from a Node when we are doing
    // a ray query
    class ObjectTag : public TagBase
    {
    public:
        ObjectTag(Object* object);

        Object* mObject;

        QString getToolTip(bool hideBasics, const WorldspaceHitResult& hit) const override;
    };

    class Object
    {
    public:
        enum OverrideFlags
        {
            Override_Position = 1,
            Override_Rotation = 2,
            Override_Scale = 4
        };

        enum SubMode
        {
            Mode_Move,
            Mode_Rotate,
            Mode_Scale,
            Mode_None,
        };

        enum Axis
        {
            Axis_X,
            Axis_Y,
            Axis_Z
        };

    private:
        CSMWorld::Data& mData;
        ESM::RefId mReferenceId;
        ESM::RefId mReferenceableId;
        osg::ref_ptr<osg::PositionAttitudeTransform> mRootNode;
        osg::ref_ptr<osg::PositionAttitudeTransform> mBaseNode;
        osg::ref_ptr<osgFX::Scribe> mOutline;
        bool mSelected;
        bool mSnapTarget;
        osg::Group* mParentNode;
        Resource::ResourceSystem* mResourceSystem;
        bool mForceBaseToZero;
        ESM::Position mPositionOverride;
        float mScaleOverride;
        int mOverrideFlags;
        std::unique_ptr<Actor> mActor;

        /// Not implemented
        Object(const Object&);

        /// Not implemented
        Object& operator=(const Object&);

        /// Remove object from node (includes deleting)
        void clear();

        /// Update model
        /// @note Make sure adjustTransform() was called first so world space particles get positioned correctly
        void update();

        /// Adjust position, orientation and scale
        void adjustTransform();

        /// Throws an exception if *this was constructed with referenceable
        const CSMWorld::CellRef& getReference() const;

    public:
        Object(CSMWorld::Data& data, osg::Group* cellNode, const std::string& id, bool referenceable,
            bool forceBaseToZero = false);
        /// \param forceBaseToZero If this is a reference ignore the coordinates and place
        /// it at 0, 0, 0 instead.

        ~Object();

        /// Mark the object as selected, selected objects show an outline effect
        void setSelected(bool selected, const osg::Vec4f& color = osg::Vec4f(1, 1, 1, 1));

        bool getSelected() const;

        /// Mark Object as "snap target"
        void setSnapTarget(bool isSnapTarget);

        bool getSnapTarget() const;

        /// Get object node with GUI graphics
        osg::ref_ptr<osg::Group> getRootNode();

        /// Get object node without GUI graphics
        osg::ref_ptr<osg::Group> getBaseNode();

        /// \return Did this call result in a modification of the visual representation of
        /// this object?
        bool referenceableDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);

        /// \return Did this call result in a modification of the visual representation of
        /// this object?
        bool referenceableAboutToBeRemoved(const QModelIndex& parent, int start, int end);

        /// \return Did this call result in a modification of the visual representation of
        /// this object?
        bool referenceDataChanged(const QModelIndex& topLeft, const QModelIndex& bottomRight);

        /// Reloads the underlying asset
        void reloadAssets();

        /// Returns an empty string if this is a refereceable-type object.
        std::string getReferenceId() const;

        std::string getReferenceableId() const;

        osg::ref_ptr<TagBase> getTag() const;

        /// Is there currently an editing operation running on this object?
        bool isEdited() const;

        void setEdited(int flags);

        ESM::Position getPosition() const;

        float getScale() const;

        /// Set override position.
        void setPosition(const float position[3]);

        /// Set override rotation
        void setRotation(const float rotation[3]);

        /// Set override scale
        void setScale(float scale);

        void setMarkerTransparency(float value);

        /// Apply override changes via command and end edit mode
        void apply(CSMWorld::CommandMacro& commands);

        /// Erase all overrides and restore the visual representation of the object to its
        /// true state.
        void reset();
    };
}

#endif