mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-29 03:33:48 +00:00
some work on quadgrid, still untested
This commit is contained in:
parent
ad36f6cf99
commit
fa35ee41bd
3 changed files with 54 additions and 4 deletions
|
@ -9636,6 +9636,20 @@ luaFunc(quadgrid_resetUV)
|
|||
luaReturnNil();
|
||||
}
|
||||
|
||||
luaFunc(quadgrid_resetPos)
|
||||
{
|
||||
QuadGrid *q = getQuadGrid(L);
|
||||
if(q)
|
||||
{
|
||||
const float w = luaL_optnumber(L, 2, 1);
|
||||
const float h = luaL_optnumber(L, 3, 1);
|
||||
const float xoffs = luaL_optnumber(L, 4, 0);
|
||||
const float yoffs = luaL_optnumber(L, 5, 0);
|
||||
q->resetPos(w, h, xoffs, yoffs);
|
||||
}
|
||||
luaReturnNil();
|
||||
}
|
||||
|
||||
// ---------- Minimap related ------------------
|
||||
|
||||
luaFunc(getMinimapRender)
|
||||
|
@ -10888,6 +10902,7 @@ static const struct {
|
|||
luaRegister(quadgrid_setPauseLevel),
|
||||
luaRegister(quadgrid_getPauseLevel),
|
||||
luaRegister(quadgrid_resetUV),
|
||||
luaRegister(quadgrid_resetPos),
|
||||
|
||||
#undef MK_FUNC
|
||||
#undef MK_ALIAS
|
||||
|
|
|
@ -9,6 +9,9 @@ QuadGrid::QuadGrid(size_t w, size_t h)
|
|||
addType(SCO_QUAD_GRID);
|
||||
_points.resize((w+1) * (h+1));
|
||||
resetUV();
|
||||
resetPos(1, 1);
|
||||
this->width = 2;
|
||||
this->height = 2;
|
||||
}
|
||||
|
||||
QuadGrid* QuadGrid::New(size_t w, size_t h)
|
||||
|
@ -39,6 +42,26 @@ void QuadGrid::resetUV(float xmul, float ymul)
|
|||
}
|
||||
}
|
||||
|
||||
void QuadGrid::resetPos(float w, float h, float xoffs, float yoffs)
|
||||
{
|
||||
const float dx = 1.0f / w;
|
||||
const float dy = 1.0f / h;
|
||||
const size_t NX = _w + 1;
|
||||
|
||||
float yy = yoffs;
|
||||
// go over points, so <= to compare boundaries
|
||||
for(size_t y = 0; y <= _h; ++y, yy += dy)
|
||||
{
|
||||
Point * const row = &_points[y * NX];
|
||||
float xx = xoffs;
|
||||
for(size_t x = 0; x < NX; ++x, xx += dx)
|
||||
{
|
||||
row[x].x = xx;
|
||||
row[y].y = yy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static inline void drawOnePoint(const QuadGrid::Point& p, float ox, float oy)
|
||||
{
|
||||
glTexCoord2f(p.u + ox, p.v + oy);
|
||||
|
@ -48,12 +71,10 @@ static inline void drawOnePoint(const QuadGrid::Point& p, float ox, float oy)
|
|||
|
||||
void QuadGrid::onRender()
|
||||
{
|
||||
glBindTexture(GL_TEXTURE_2D, texture->textures[0]);
|
||||
glColor4f(color.x, color.y, color.z, alpha.x * alphaMod);
|
||||
|
||||
const float ox = texOffset.x;
|
||||
const float oy = texOffset.y;
|
||||
|
||||
const size_t NX = _w + 1;
|
||||
|
||||
// go over grids, so < to compare boundaries
|
||||
|
@ -83,3 +104,16 @@ void QuadGrid::onUpdate(float dt)
|
|||
RenderObject::onUpdate(dt);
|
||||
}
|
||||
|
||||
void QuadGrid::onSetTexture() // same as Quad::setTexture()
|
||||
{
|
||||
if (texture)
|
||||
{
|
||||
width = this->texture->width;
|
||||
height = this->texture->height;
|
||||
}
|
||||
else
|
||||
{
|
||||
width = 64;
|
||||
height = 64;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,9 +44,10 @@ public:
|
|||
|
||||
virtual void onRender();
|
||||
virtual void onUpdate(float dt);
|
||||
virtual void onSetTexture();
|
||||
|
||||
void resetUV(float xmul = 1, float ymul = 1);
|
||||
void resetPos(float xmul = 1, float ymul = 1);
|
||||
void resetPos(float w, float h, float xoffs = 0, float yoffs = 0);
|
||||
|
||||
inline size_t quadsX() const { return _w; }
|
||||
inline size_t quadsY() const { return _h; }
|
||||
|
@ -62,7 +63,7 @@ public:
|
|||
|
||||
private:
|
||||
QuadGrid(size_t w, size_t h);
|
||||
const size_t _w, _h;
|
||||
const size_t _w, _h; // number of quads in each direction (2x3 quads => 3x4 grid points)
|
||||
std::vector<Point> _points;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue