mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-02-04 02:24:00 +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);
|
QuadGrid *q = getQuadGrid(L);
|
||||||
if(q)
|
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();
|
luaReturnNil();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
#include "Core.h"
|
#include "Core.h"
|
||||||
|
|
||||||
QuadGrid::QuadGrid(size_t w, size_t 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);
|
addType(SCO_QUAD_GRID);
|
||||||
_points.resize((w+1) * (h+1));
|
_points.resize((w+1) * (h+1));
|
||||||
|
@ -12,6 +12,8 @@ QuadGrid::QuadGrid(size_t w, size_t h)
|
||||||
resetPos(1, 1);
|
resetPos(1, 1);
|
||||||
this->width = 2;
|
this->width = 2;
|
||||||
this->height = 2;
|
this->height = 2;
|
||||||
|
this->cull = false;
|
||||||
|
this->repeatTexture = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
QuadGrid* QuadGrid::New(size_t w, size_t h)
|
QuadGrid* QuadGrid::New(size_t w, size_t h)
|
||||||
|
@ -25,39 +27,43 @@ QuadGrid::~QuadGrid()
|
||||||
|
|
||||||
void QuadGrid::resetUV(float xmul, float ymul)
|
void QuadGrid::resetUV(float xmul, float ymul)
|
||||||
{
|
{
|
||||||
const float incX = 1.0f / float(_w + 1);
|
const float incX = xmul / float(quadsX());
|
||||||
const float incY = 1.0f / float(_h + 1);
|
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
|
// go over points
|
||||||
for(size_t y = 0; y <= _h; ++y, v0 = v1, v1 += incY)
|
for(size_t y = 0; y < _h; ++y)
|
||||||
{
|
{
|
||||||
Point *row = &_points[y * _w];
|
Point *row = &_points[y * NX];
|
||||||
for(size_t x = 0; x <= _w; ++x, u0 = u1, u1 += incX)
|
float u = 0;
|
||||||
|
for(size_t x = 0; x < NX; ++x)
|
||||||
{
|
{
|
||||||
row[x].u = u0;
|
row[x].u = u;
|
||||||
row[y].v = v0;
|
row[x].v = v;
|
||||||
|
u += incX;
|
||||||
}
|
}
|
||||||
|
v += incY;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void QuadGrid::resetPos(float w, float h, float xoffs, float yoffs)
|
void QuadGrid::resetPos(float w, float h, float xoffs, float yoffs)
|
||||||
{
|
{
|
||||||
const float dx = 1.0f / w;
|
const float dx = w / float(quadsX());
|
||||||
const float dy = 1.0f / h;
|
const float dy = h / float(quadsY());
|
||||||
const size_t NX = _w + 1;
|
const size_t NX = pointsX();
|
||||||
|
|
||||||
float yy = yoffs;
|
float yy = yoffs;
|
||||||
// go over points, so <= to compare boundaries
|
// go over points
|
||||||
for(size_t y = 0; y <= _h; ++y, yy += dy)
|
for(size_t y = 0; y < _h; ++y, yy += dy)
|
||||||
{
|
{
|
||||||
Point * const row = &_points[y * NX];
|
Point * const row = &_points[y * NX];
|
||||||
float xx = xoffs;
|
float xx = xoffs;
|
||||||
for(size_t x = 0; x < NX; ++x, xx += dx)
|
for(size_t x = 0; x < NX; ++x, xx += dx)
|
||||||
{
|
{
|
||||||
row[x].x = xx;
|
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 ox = texOffset.x;
|
||||||
const float oy = texOffset.y;
|
const float oy = texOffset.y;
|
||||||
const size_t NX = _w + 1;
|
const size_t NX = pointsX();
|
||||||
|
|
||||||
// go over grids, so < to compare boundaries
|
// go over grids
|
||||||
for(size_t y = 0; y < _h; ++y)
|
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 row0 = &_points[y * NX];
|
||||||
Point * const row1 = row0 + 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);
|
glBegin(GL_QUADS);
|
||||||
drawOnePoint(row0[x], ox, oy);
|
drawOnePoint(row0[x], ox, oy);
|
||||||
|
|
|
@ -49,11 +49,11 @@ public:
|
||||||
void resetUV(float xmul = 1, float ymul = 1);
|
void resetUV(float xmul = 1, float ymul = 1);
|
||||||
void resetPos(float w, float h, float xoffs = 0, float yoffs = 0);
|
void resetPos(float w, float h, float xoffs = 0, float yoffs = 0);
|
||||||
|
|
||||||
inline size_t quadsX() const { return _w; }
|
inline size_t quadsX() const { return _w - 1; }
|
||||||
inline size_t quadsY() const { return _h; }
|
inline size_t quadsY() const { return _h - 1; }
|
||||||
|
|
||||||
inline size_t pointsX() const { return _w + 1; }
|
inline size_t pointsX() const { return _w; }
|
||||||
inline size_t pointsY() const { return _h + 1; }
|
inline size_t pointsY() const { return _h; }
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -63,7 +63,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QuadGrid(size_t w, size_t h);
|
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;
|
std::vector<Point> _points;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue