]> Dogcows Code - chaz/yoink/blob - src/Moof/Tilemap.hh
improved new vorbisfile compatibility
[chaz/yoink] / src / Moof / Tilemap.hh
1
2 /*******************************************************************************
3
4 Copyright (c) 2009, Charles McGarvey
5 All rights reserved.
6
7 Redistribution and use in source and binary forms, with or without
8 modification, are permitted provided that the following conditions are met:
9
10 * Redistributions of source code must retain the above copyright notice,
11 this list of conditions and the following disclaimer.
12 * Redistributions in binary form must reproduce the above copyright notice,
13 this list of conditions and the following disclaimer in the documentation
14 and/or other materials provided with the distribution.
15
16 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17 AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
20 FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
23 CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
25 OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26
27 *******************************************************************************/
28
29 #ifndef _MOOF_TILEMAP_HH_
30 #define _MOOF_TILEMAP_HH_
31
32 /**
33 * @file Tilemap.hh
34 * Small subclass to give some basic tile-mapping functionality to textures.
35 */
36
37 #include <boost/shared_ptr.hpp>
38
39 #include <Moof/Math.hh>
40 #include <Moof/Texture.hh>
41
42
43 namespace Mf {
44
45
46 /**
47 * A tilemap is a texture which is meant to be divided into smaller sprites.
48 * This class provides all the functionality of a texture and adds some methods
49 * to get texture coordinates to individual tiles within the tilemap. For
50 * simplicity, this class assumes square tiles.
51 */
52
53 class Tilemap : public Texture
54 {
55 public:
56 /**
57 * Possible orientations for texture coordinates.
58 */
59
60 typedef unsigned Index;
61 static const Index NO_TILE = -1;
62
63 typedef enum
64 {
65 NORMAL = 0, ///< Normal orientation.
66 FLIP = 1, ///< Flip over a horizontal axis.
67 REVERSE = 2, ///< Flip over a vertical axis.
68 FLIP_AND_REVERSE = 3 ///< Flip over both.
69 } Orientation;
70
71
72 Tilemap(const std::string& name);
73
74 /**
75 * Calculate texture coordinates for a tile at a certain index. Tiles are
76 * indexed start with zero as the to-left tile and moving across, then down.
77 * @param index The tile index.
78 * @param coords An array of scalars where the texture coordinates will be
79 * stored after this call. The first coordinate (u,v) will be in the first
80 * two places and so on until all four coordinates are stored, therefore
81 * requiring enough room for an array of eight scalars. The winding of the
82 * coordinates is always counter-clockwise (the GL default).
83 * @return True if index is valid, false otherwise.
84 */
85
86 bool getTileCoords(Index index, Scalar coords[8]) const;
87
88
89 /**
90 * This version let's you specify an orientation that will be reflected in
91 * the texture coordinates. This allows you to easily map a texture
92 * backwards or upside-down.
93 * @param what The orientation; can be flip, reverse, or flip_and_reverse.
94 * @return True if index is valid, false otherwise.
95 */
96
97 bool getTileCoords(Index index, Scalar coords[8], Orientation what) const;
98
99
100 static std::string getPath(const std::string& name);
101
102 private:
103 class Impl;
104 boost::shared_ptr<Impl> impl_;
105 };
106
107
108 } // namespace Mf
109
110 #endif // _MOOF_TILEMAP_HH_
111
112 /** vim: set ts=4 sw=4 tw=80: *************************************************/
113
This page took 0.032049 seconds and 4 git commands to generate.