]> Dogcows Code - chaz/yoink/blob - src/Moof/Tilemap.hh
scene drawing correctly implemented; new classes
[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
62 typedef enum
63 {
64 NORMAL = 0, ///< Normal orientation.
65 FLIP = 1, ///< Flip over a horizontal axis.
66 REVERSE = 2, ///< Flip over a vertical axis.
67 FLIP_AND_REVERSE = 3 ///< Flip over both.
68 } Orientation;
69
70
71 Tilemap(const std::string& name);
72
73 /**
74 * Calculate texture coordinates for a tile at a certain index. Tiles are
75 * indexed start with zero as the to-left tile and moving across, then down.
76 * @param index The tile index.
77 * @param coords An array of scalars where the texture coordinates will be
78 * stored after this call. The first coordinate (u,v) will be in the first
79 * two places and so on until all four coordinates are stored, therefore
80 * requiring enough room for an array of eight scalars. The winding of the
81 * coordinates is always counter-clockwise (the GL default).
82 * @return True if index is valid, false otherwise.
83 */
84
85 bool getTileCoords(Index index, Scalar coords[8]) const;
86
87
88 /**
89 * This version let's you specify an orientation that will be reflected in
90 * the texture coordinates. This allows you to easily map a texture
91 * backwards or upside-down.
92 * @param what The orientation; can be flip, reverse, or flip_and_reverse.
93 * @return True if index is valid, false otherwise.
94 */
95
96 bool getTileCoords(Index index, Scalar coords[8], Orientation what) const;
97
98
99 static std::string getPathToResource(const std::string& name);
100
101 private:
102 class TilemapImpl;
103 boost::shared_ptr<TilemapImpl> impl_;
104 };
105
106
107 } // namespace Mf
108
109 #endif // _MOOF_TILEMAP_HH_
110
111 /** vim: set ts=4 sw=4 tw=80: *************************************************/
112
This page took 0.033021 seconds and 4 git commands to generate.