]> Dogcows Code - chaz/yoink/blob - src/Tilemap.hh
163b45af434aa78289412064904c95ba6ec55f20
[chaz/yoink] / src / 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 _TILEMAP_HH_
30 #define _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 /**
44 * A tilemap is a texture which is meant to be divided into smaller sprites.
45 * This class provides all the functionality of a texture and adds some methods
46 * to get texture coordinates to individual tiles within the tilemap. For
47 * simplicity, this class assumes square tiles.
48 */
49
50 class Tilemap : public Mf::Texture
51 {
52 public:
53 /**
54 * Possible orientations for texture coordinates.
55 */
56
57 typedef unsigned Index;
58 static const Index NO_TILE = -1;
59
60 typedef enum
61 {
62 NORMAL = 0, ///< Normal orientation.
63 FLIP = 1, ///< Flip over a horizontal axis.
64 REVERSE = 2, ///< Flip over a vertical axis.
65 FLIP_AND_REVERSE = 3 ///< Flip over both.
66 } Orientation;
67
68
69 Tilemap(const std::string& name);
70
71 /**
72 * Calculate texture coordinates for a tile at a certain index. Tiles are
73 * indexed start with zero as the to-left tile and moving across, then down.
74 * @param index The tile index.
75 * @param coords An array of scalars where the texture coordinates will be
76 * stored after this call. The first coordinate (u,v) will be in the first
77 * two places and so on until all four coordinates are stored, therefore
78 * requiring enough room for an array of eight scalars. The winding of the
79 * coordinates is always counter-clockwise (the GL default).
80 * @return True if index is valid, false otherwise.
81 */
82
83 bool getTileCoords(Index index, Mf::Scalar coords[8]) const;
84
85
86 /**
87 * This version let's you specify an orientation that will be reflected in
88 * the texture coordinates. This allows you to easily map a texture
89 * backwards or upside-down.
90 * @param what The orientation; can be flip, reverse, or flip_and_reverse.
91 * @return True if index is valid, false otherwise.
92 */
93
94 bool getTileCoords(Index index, Mf::Scalar coords[8], Orientation what) const;
95
96
97 static std::string getPath(const std::string& name);
98
99 private:
100 class Impl;
101 boost::shared_ptr<Impl> impl_;
102 };
103
104
105 #endif // _TILEMAP_HH_
106
107 /** vim: set ts=4 sw=4 tw=80: *************************************************/
108
This page took 0.035032 seconds and 3 git commands to generate.