Browse Source

Add support for rotated views and stretched tiles.

legacy
Sam Hocevar sam 14 years ago
parent
commit
5ebe9f9c85
7 changed files with 20 additions and 15 deletions
  1. +3
    -1
      src/map.cpp
  2. +4
    -2
      src/scene.cpp
  3. +1
    -1
      src/scene.h
  4. +2
    -2
      src/tiler.cpp
  5. +1
    -1
      src/tiler.h
  6. +8
    -7
      src/tileset.cpp
  7. +1
    -1
      src/tileset.h

+ 3
- 1
src/map.cpp View File

@@ -15,6 +15,7 @@
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctype.h>

#include "core.h"
@@ -126,7 +127,8 @@ Map::Map(char const *path)
else if (sscanf(tmp, " <image source=\"%[^\"]\"", str) == 1)
{
/* This is a tileset image file. Associate it with firstgid. */
data->tilers[data->ntilers] = Tiler::Register(str, 32, 32);
data->tilers[data->ntilers] = Tiler::Register(str, 32, 32,
sqrtf(2));
data->ntilers++;
//fprintf(stderr, "new tiler %s\n", str);
}


+ 4
- 2
src/scene.cpp View File

@@ -53,17 +53,19 @@ private:

Tile *tiles;
int ntiles;
float angle;
};

/*
* Public Scene class
*/

Scene::Scene()
Scene::Scene(float angle)
{
data = new SceneData();
data->tiles = 0;
data->ntiles = 0;
data->angle = angle;
}

Scene::~Scene()
@@ -104,7 +106,7 @@ void Scene::Render() // XXX: rename to Blit()
static float f = 0.0f;
f += 0.05f;
glTranslatef(320.0f, 240.0f, 0.0f);
glRotatef(-45.0f, 1.0f, 0.0f, 0.0f);
glRotatef(-data->angle, 1.0f, 0.0f, 0.0f);
#if 0
glRotatef(3.0f * sinf(f), 1.0f, 0.0f, 0.0f);
glRotatef(8.0f * cosf(f), 0.0f, 0.0f, 1.0f);


+ 1
- 1
src/scene.h View File

@@ -23,7 +23,7 @@ class SceneData;
class Scene
{
public:
Scene();
Scene(float angle);
~Scene();

void AddTile(uint32_t code, int x, int y, int z, int o);


+ 2
- 2
src/tiler.cpp View File

@@ -33,13 +33,13 @@ static TilerData * const data = &tilerdata;
* Public Tiler class
*/

int Tiler::Register(char const *path, int w, int h)
int Tiler::Register(char const *path, int w, int h, float dilate)
{
int id = data->tilesets.MakeSlot(path);

if (!data->tilesets.GetEntity(id))
{
TileSet *tileset = new TileSet(path, w, h);
TileSet *tileset = new TileSet(path, w, h, dilate);
data->tilesets.SetEntity(id, tileset);
}



+ 1
- 1
src/tiler.h View File

@@ -22,7 +22,7 @@
class Tiler
{
public:
static int Register(char const *path, int w, int h);
static int Register(char const *path, int w, int h, float dilate);
static void Deregister(int id);

static void BlitTile(uint32_t code, int x, int y, int z, int o);


+ 8
- 7
src/tileset.cpp View File

@@ -43,7 +43,7 @@ private:
char *name;
int *tiles;
int w, h, nw, nh, ntiles;
float tx, ty;
float dilate, tx, ty;

SDL_Surface *img;
GLuint texture;
@@ -53,7 +53,7 @@ private:
* Public TileSet class
*/

TileSet::TileSet(char const *path, int w, int h)
TileSet::TileSet(char const *path, int w, int h, float dilate)
{
data = new TileSetData();
data->name = strdup(path);
@@ -78,6 +78,7 @@ TileSet::TileSet(char const *path, int w, int h)

data->w = w;
data->h = h;
data->dilate = dilate;
/* FIXME: check for non-zero here */
data->nw = data->img->w / w;
data->nh = data->img->h / h;
@@ -134,8 +135,8 @@ void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o)
{
float tx = data->tx * ((id & 0xffff) % data->nw);
float ty = data->ty * ((id & 0xffff) / data->nw);
float dilate = data->dilate;

float sqrt2 = sqrtf(2.0f);
int off = o ? data->h : 0;
int dx = data->w;
int dy = data->h * 38 / 32; /* Magic... fix this one day */
@@ -146,13 +147,13 @@ void TileSet::BlitTile(uint32_t id, int x, int y, int z, int o)
glBindTexture(GL_TEXTURE_2D, data->texture);
glBegin(GL_QUADS);
glTexCoord2f(tx, ty);
glVertex3f(x, sqrt2 * (y - dy - off), sqrt2 * (z + off));
glVertex3f(x, dilate * (y - dy - off), dilate * (z + off));
glTexCoord2f(tx + data->tx, ty);
glVertex3f(x + dx, sqrt2 * (y - dy - off), sqrt2 * (z + off));
glVertex3f(x + dx, dilate * (y - dy - off), dilate * (z + off));
glTexCoord2f(tx + data->tx, ty + data->ty);
glVertex3f(x + dx, sqrt2 * (y - dy2), sqrt2 * z);
glVertex3f(x + dx, dilate * (y - dy2), dilate * z);
glTexCoord2f(tx, ty + data->ty);
glVertex3f(x, sqrt2 * (y - dy2), sqrt2 * z);
glVertex3f(x, dilate * (y - dy2), dilate * z);
glEnd();
}
}


+ 1
- 1
src/tileset.h View File

@@ -28,7 +28,7 @@ class TileSetData;
class TileSet : public Entity
{
public:
TileSet(char const *path, int w, int h);
TileSet(char const *path, int w, int h, float dilate);
virtual ~TileSet();

protected:


Loading…
Cancel
Save