mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-03 18:14:01 +00:00
QuadGrid now working
This commit is contained in:
parent
fa35ee41bd
commit
e1f78aaca7
3 changed files with 38 additions and 26 deletions
|
@ -9632,7 +9632,11 @@ luaFunc(quadgrid_resetUV)
|
|||
{
|
||||
QuadGrid *q = getQuadGrid(L);
|
||||
if(q)
|
||||
q->resetUV();
|
||||
{
|
||||
const float xmul = luaL_optnumber(L, 2, 1);
|
||||
const float ymul = luaL_optnumber(L, 3, 1);
|
||||
q->resetUV(xmul, ymul);
|
||||
}
|
||||
luaReturnNil();
|
||||
}
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
#include "Core.h"
|
||||
|
||||
QuadGrid::QuadGrid(size_t w, size_t h)
|
||||
: pauseLevel(0), _w(w), _h(h)
|
||||
: pauseLevel(0), _w(w+1), _h(h+1)
|
||||
{
|
||||
addType(SCO_QUAD_GRID);
|
||||
_points.resize((w+1) * (h+1));
|
||||
|
@ -12,6 +12,8 @@ QuadGrid::QuadGrid(size_t w, size_t h)
|
|||
resetPos(1, 1);
|
||||
this->width = 2;
|
||||
this->height = 2;
|
||||
this->cull = false;
|
||||
this->repeatTexture = true;
|
||||
}
|
||||
|
||||
QuadGrid* QuadGrid::New(size_t w, size_t h)
|
||||
|
@ -25,39 +27,43 @@ QuadGrid::~QuadGrid()
|
|||
|
||||
void QuadGrid::resetUV(float xmul, float ymul)
|
||||
{
|
||||
const float incX = 1.0f / float(_w + 1);
|
||||
const float incY = 1.0f / float(_h + 1);
|
||||
const float incX = xmul / float(quadsX());
|
||||
const float incY = ymul / float(quadsY());
|
||||
const size_t NX = pointsX();
|
||||
|
||||
float u0 = 0, u1 = incX, v0 = 0, v1 = incY;
|
||||
float v = 0;
|
||||
|
||||
// go over points, so <= to compare boundaries
|
||||
for(size_t y = 0; y <= _h; ++y, v0 = v1, v1 += incY)
|
||||
// go over points
|
||||
for(size_t y = 0; y < _h; ++y)
|
||||
{
|
||||
Point *row = &_points[y * _w];
|
||||
for(size_t x = 0; x <= _w; ++x, u0 = u1, u1 += incX)
|
||||
Point *row = &_points[y * NX];
|
||||
float u = 0;
|
||||
for(size_t x = 0; x < NX; ++x)
|
||||
{
|
||||
row[x].u = u0;
|
||||
row[y].v = v0;
|
||||
row[x].u = u;
|
||||
row[x].v = v;
|
||||
u += incX;
|
||||
}
|
||||
v += incY;
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
const float dx = w / float(quadsX());
|
||||
const float dy = h / float(quadsY());
|
||||
const size_t NX = pointsX();
|
||||
|
||||
float yy = yoffs;
|
||||
// go over points, so <= to compare boundaries
|
||||
for(size_t y = 0; y <= _h; ++y, yy += dy)
|
||||
// go over points
|
||||
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;
|
||||
row[x].y = yy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -75,14 +81,16 @@ void QuadGrid::onRender()
|
|||
|
||||
const float ox = texOffset.x;
|
||||
const float oy = texOffset.y;
|
||||
const size_t NX = _w + 1;
|
||||
const size_t NX = pointsX();
|
||||
|
||||
// go over grids, so < to compare boundaries
|
||||
for(size_t y = 0; y < _h; ++y)
|
||||
// go over grids
|
||||
const size_t W = quadsX();
|
||||
const size_t H = quadsY();
|
||||
for(size_t y = 0; y < H; ++y)
|
||||
{
|
||||
Point * const row0 = &_points[y * NX];
|
||||
Point * const row1 = row0 + NX;
|
||||
for(size_t x = 0; x < _w; ++x)
|
||||
for(size_t x = 0; x < W; ++x)
|
||||
{
|
||||
glBegin(GL_QUADS);
|
||||
drawOnePoint(row0[x], ox, oy);
|
||||
|
|
|
@ -49,11 +49,11 @@ public:
|
|||
void resetUV(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; }
|
||||
inline size_t quadsX() const { return _w - 1; }
|
||||
inline size_t quadsY() const { return _h - 1; }
|
||||
|
||||
inline size_t pointsX() const { return _w + 1; }
|
||||
inline size_t pointsY() const { return _h + 1; }
|
||||
inline size_t pointsX() const { return _w; }
|
||||
inline size_t pointsY() const { return _h; }
|
||||
|
||||
|
||||
public:
|
||||
|
@ -63,7 +63,7 @@ public:
|
|||
|
||||
private:
|
||||
QuadGrid(size_t w, size_t h);
|
||||
const size_t _w, _h; // number of quads in each direction (2x3 quads => 3x4 grid points)
|
||||
const size_t _w, _h; // number of points in each direction (2x3 quads => 3x4 grid points)
|
||||
std::vector<Point> _points;
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue