1 /* ResidualVM - A 3D game interpreter
2  *
3  * ResidualVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the AUTHORS
5  * file distributed with this source distribution.
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20  *
21  */
22 
23 #ifndef STARK_GFX_RENDER_ENTRY_H
24 #define STARK_GFX_RENDER_ENTRY_H
25 
26 #include "common/array.h"
27 #include "common/rect.h"
28 #include "common/str.h"
29 
30 #include "math/ray.h"
31 #include "math/vector3d.h"
32 
33 namespace Stark {
34 
35 class Visual;
36 class VisualImageXMG;
37 
38 namespace Resources {
39 class ItemVisual;
40 }
41 
42 namespace Gfx {
43 
44 struct LightEntry {
45 	enum Type {
46 		kAmbient     = 0,
47 		kPoint       = 1,
48 		kDirectional = 2,
49 		kSpot        = 4
50 	};
51 
52 	Type type;
53 	Math::Vector3d color;
54 	Math::Vector3d position;
55 	Math::Vector3d direction;
56 	Math::Angle innerConeAngle;
57 	Math::Angle outerConeAngle;
58 	float falloffNear;
59 	float falloffFar;
60 };
61 
62 typedef Common::Array<LightEntry *> LightEntryArray;
63 
64 class RenderEntry {
65 public:
66 	RenderEntry(Resources::ItemVisual *owner, const Common::String &name);
~RenderEntry()67 	virtual ~RenderEntry() {}
68 
69 	void render(const LightEntryArray &lights);
70 
71 	void setVisual(Visual *visual);
72 	void setPosition(const Common::Point &position);
73 	void setPosition3D(const Math::Vector3d &position, float direction);
74 	void setSortKey(float sortKey);
75 	void setClickable(bool clickable);
76 
77 	/** Gets the owner-object */
getOwner()78 	Resources::ItemVisual *getOwner() const { return _owner; }
79 
80 	/** Obtain the underlying image visual, if any */
81 	VisualImageXMG *getImage() const;
82 
83 	/**
84 	 * Mouse picking test for 2D items
85 	 *
86 	 * @param position game window coordinates to test
87 	 * @param relativePosition successful hit item relative coordinates
88 	 * @return successful hit
89 	 */
90 	bool containsPoint(const Common::Point &position, Common::Point &relativePosition) const;
91 
92 	/** Mouse picking test for 3D items */
93 	bool intersectRay(const Math::Ray &ray) const;
94 
95 	/** Compare two render entries by their sort keys */
96 	static bool compare(const RenderEntry *x, const RenderEntry *y);
97 
98 protected:
99 	Common::String _name;
100 	Resources::ItemVisual *_owner;
101 
102 	Visual *_visual;
103 	Common::Point _position;
104 	Math::Vector3d _position3D;
105 	float _direction3D;
106 	float _sortKey;
107 	bool _clickable;
108 };
109 
110 typedef Common::Array<RenderEntry *> RenderEntryArray;
111 
112 } // End of namespace Gfx
113 } // End of namespace Stark
114 
115 #endif // STARK_GFX_RENDER_ENTRY_H
116