Changeset 222 for trunk/src


Ignore:
Timestamp:
Jan 18, 2011, 2:04:03 AM (11 years ago)
Author:
sam
Message:

Add support for rotated views and stretched tiles.

Location:
trunk/src
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/map.cpp

    r221 r222  
    1616#include <cstring>
    1717#include <cstdlib>
     18#include <cmath>
    1819#include <ctype.h>
    1920
     
    127128        {
    128129            /* This is a tileset image file. Associate it with firstgid. */
    129             data->tilers[data->ntilers] = Tiler::Register(str, 32, 32);
     130            data->tilers[data->ntilers] = Tiler::Register(str, 32, 32,
     131                                                          sqrtf(2));
    130132            data->ntilers++;
    131133            //fprintf(stderr, "new tiler %s\n", str);
  • trunk/src/scene.cpp

    r221 r222  
    5454    Tile *tiles;
    5555    int ntiles;
     56    float angle;
    5657};
    5758
     
    6061 */
    6162
    62 Scene::Scene()
     63Scene::Scene(float angle)
    6364{
    6465    data = new SceneData();
    6566    data->tiles = 0;
    6667    data->ntiles = 0;
     68    data->angle = angle;
    6769}
    6870
     
    105107    f += 0.05f;
    106108    glTranslatef(320.0f, 240.0f, 0.0f);
    107     glRotatef(-45.0f, 1.0f, 0.0f, 0.0f);
     109    glRotatef(-data->angle, 1.0f, 0.0f, 0.0f);
    108110#if 0
    109111    glRotatef(3.0f * sinf(f), 1.0f, 0.0f, 0.0f);
  • trunk/src/scene.h

    r221 r222  
    2424{
    2525public:
    26     Scene();
     26    Scene(float angle);
    2727    ~Scene();
    2828
  • trunk/src/tiler.cpp

    r221 r222  
    3434 */
    3535
    36 int Tiler::Register(char const *path, int w, int h)
     36int Tiler::Register(char const *path, int w, int h, float dilate)
    3737{
    3838    int id = data->tilesets.MakeSlot(path);
     
    4040    if (!data->tilesets.GetEntity(id))
    4141    {
    42         TileSet *tileset = new TileSet(path, w, h);
     42        TileSet *tileset = new TileSet(path, w, h, dilate);
    4343        data->tilesets.SetEntity(id, tileset);
    4444    }
  • trunk/src/tiler.h

    r221 r222  
    2323{
    2424public:
    25     static int Register(char const *path, int w, int h);
     25    static int Register(char const *path, int w, int h, float dilate);
    2626    static void Deregister(int id);
    2727
  • trunk/src/tileset.cpp

    r221 r222  
    4444    int *tiles;
    4545    int w, h, nw, nh, ntiles;
    46     float tx, ty;
     46    float dilate, tx, ty;
    4747
    4848    SDL_Surface *img;
     
    5454 */
    5555
    56 TileSet::TileSet(char const *path, int w, int h)
     56TileSet::TileSet(char const *path, int w, int h, float dilate)
    5757{
    5858    data = new TileSetData();
     
    7979    data->w = w;
    8080    data->h = h;
     81    data->dilate = dilate;
    8182    /* FIXME: check for non-zero here */
    8283    data->nw = data->img->w / w;
     
    135136    float tx = data->tx * ((id & 0xffff) % data->nw);
    136137    float ty = data->ty * ((id & 0xffff) / data->nw);
     138    float dilate = data->dilate;
    137139
    138     float sqrt2 = sqrtf(2.0f);
    139140    int off = o ? data->h : 0;
    140141    int dx = data->w;
     
    147148        glBegin(GL_QUADS);
    148149            glTexCoord2f(tx, ty);
    149             glVertex3f(x, sqrt2 * (y - dy - off), sqrt2 * (z + off));
     150            glVertex3f(x, dilate * (y - dy - off), dilate * (z + off));
    150151            glTexCoord2f(tx + data->tx, ty);
    151             glVertex3f(x + dx, sqrt2 * (y - dy - off), sqrt2 * (z + off));
     152            glVertex3f(x + dx, dilate * (y - dy - off), dilate * (z + off));
    152153            glTexCoord2f(tx + data->tx, ty + data->ty);
    153             glVertex3f(x + dx, sqrt2 * (y - dy2), sqrt2 * z);
     154            glVertex3f(x + dx, dilate * (y - dy2), dilate * z);
    154155            glTexCoord2f(tx, ty + data->ty);
    155             glVertex3f(x, sqrt2 * (y - dy2), sqrt2 * z);
     156            glVertex3f(x, dilate * (y - dy2), dilate * z);
    156157        glEnd();
    157158    }
  • trunk/src/tileset.h

    r221 r222  
    2929{
    3030public:
    31     TileSet(char const *path, int w, int h);
     31    TileSet(char const *path, int w, int h, float dilate);
    3232    virtual ~TileSet();
    3333
Note: See TracChangeset for help on using the changeset viewer.