2011-08-03 20:05:33 +00:00
|
|
|
/*
|
|
|
|
Copyright (C) 2007, 2010 - Bit-Blot
|
|
|
|
|
|
|
|
This file is part of Aquaria.
|
|
|
|
|
|
|
|
Aquaria is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
|
|
|
|
|
|
See the GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#include "Quad.h"
|
|
|
|
#include "Core.h"
|
2016-07-09 02:18:40 +00:00
|
|
|
#include "RenderBase.h"
|
2011-08-03 20:05:33 +00:00
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
Quad::Quad(const std::string &tex, const Vector &pos)
|
|
|
|
: RenderObject()
|
|
|
|
{
|
2022-09-24 02:57:08 +00:00
|
|
|
renderBorderColor = Vector(1,1,1);
|
2011-08-03 20:05:33 +00:00
|
|
|
initQuad();
|
|
|
|
position = pos;
|
|
|
|
setTexture(tex);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void Quad::setSegs(int x, int y, float dgox, float dgoy, float dgmx, float dgmy, float dgtm, bool dgo)
|
|
|
|
{
|
|
|
|
deleteGrid();
|
|
|
|
if (x == 0 || y == 0)
|
|
|
|
{
|
|
|
|
doUpdateGrid = false;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-09-14 03:11:56 +00:00
|
|
|
doUpdateGrid = true;
|
2011-08-03 20:05:33 +00:00
|
|
|
this->drawGridOffsetX = dgox;
|
|
|
|
this->drawGridOffsetY = dgoy;
|
|
|
|
this->drawGridModX = dgmx;
|
|
|
|
this->drawGridModY = dgmy;
|
|
|
|
this->drawGridTimeMultiplier = dgtm;
|
|
|
|
drawGridOut = dgo;
|
|
|
|
createGrid(x, y);
|
|
|
|
}
|
2022-09-14 03:11:56 +00:00
|
|
|
|
|
|
|
gridTimer = 0;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::createGrid(int xd, int yd)
|
|
|
|
{
|
2022-09-14 03:11:56 +00:00
|
|
|
drawGrid.init(xd, yd);
|
2011-08-03 20:05:33 +00:00
|
|
|
resetGrid();
|
2022-09-14 03:11:56 +00:00
|
|
|
Vector *dg = drawGrid.data();
|
|
|
|
for(size_t i = 0; i < drawGrid.linearsize(); ++i)
|
|
|
|
dg[i].z = 1.0f;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2017-01-14 17:10:20 +00:00
|
|
|
void Quad::setDrawGridAlpha(size_t x, size_t y, float alpha)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-09-14 03:11:56 +00:00
|
|
|
if (x < drawGrid.width() && y < drawGrid.height())
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-09-14 03:11:56 +00:00
|
|
|
drawGrid(x, y).z = alpha;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-14 03:11:56 +00:00
|
|
|
void Quad::setStripPoints(bool vert, const Vector *points, size_t n)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-09-14 03:11:56 +00:00
|
|
|
if (drawGrid.empty()) return;
|
2011-08-03 20:05:33 +00:00
|
|
|
resetGrid();
|
2022-09-14 03:11:56 +00:00
|
|
|
|
|
|
|
const float mul = float(n);
|
|
|
|
|
|
|
|
if (!vert) // horz
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-09-14 03:11:56 +00:00
|
|
|
const size_t xmax = std::min(drawGrid.width(), n);
|
|
|
|
for (size_t y = 0; y < drawGrid.height(); y++)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-09-14 03:11:56 +00:00
|
|
|
Vector *row = drawGrid.row(y);
|
|
|
|
for (size_t x = 0; x < xmax; x++)
|
|
|
|
row[x] += points[x] * mul;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
2022-09-14 03:11:56 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
const size_t ymax = std::min(drawGrid.height(), n);
|
|
|
|
for (size_t x = 0; x < drawGrid.width(); x++)
|
|
|
|
for (size_t y = 0; y < ymax; y++)
|
|
|
|
drawGrid(x, y) += points[y] * mul;
|
|
|
|
}
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-09-23 16:10:44 +00:00
|
|
|
void Quad::ResetGrid(Vector* dst, size_t w, size_t h)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-09-23 16:10:44 +00:00
|
|
|
assert(w > 1 && h > 1);
|
|
|
|
const float xMulF = 1.0f / (float)(w-1);
|
|
|
|
const float yMulF = 1.0f / (float)(h-1);
|
2022-09-14 03:11:56 +00:00
|
|
|
|
2022-09-23 16:10:44 +00:00
|
|
|
for (size_t y = 0; y < h; y++)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-09-14 03:11:56 +00:00
|
|
|
const float yval = float(y)*yMulF-0.5f;
|
2022-09-23 16:10:44 +00:00
|
|
|
for (size_t x = 0; x < w; x++)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-09-23 16:10:44 +00:00
|
|
|
dst->x = float(x)*xMulF-0.5f;
|
|
|
|
dst->y = yval;
|
|
|
|
++dst;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-23 16:10:44 +00:00
|
|
|
void Quad::ResetGridAndAlpha(Vector* dst, size_t w, size_t h, float alpha)
|
|
|
|
{
|
|
|
|
assert(w > 1 && h > 1);
|
|
|
|
const float xMulF = 1.0f / (float)(w-1);
|
|
|
|
const float yMulF = 1.0f / (float)(h-1);
|
|
|
|
|
|
|
|
for (size_t y = 0; y < h; y++)
|
|
|
|
{
|
|
|
|
const float yval = float(y)*yMulF-0.5f;
|
|
|
|
for (size_t x = 0; x < w; x++)
|
|
|
|
{
|
|
|
|
dst->x = float(x)*xMulF-0.5f;
|
|
|
|
dst->y = yval;
|
|
|
|
dst->z = alpha;
|
|
|
|
++dst;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::resetGrid()
|
|
|
|
{
|
|
|
|
if (drawGrid.empty()) return;
|
|
|
|
|
|
|
|
ResetGrid(drawGrid.data(), drawGrid.width(), drawGrid.height());
|
|
|
|
}
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
void Quad::initQuad()
|
|
|
|
{
|
|
|
|
repeatToFillScale = Vector(1,1);
|
|
|
|
gridType = GRID_WAVY;
|
|
|
|
gridTimer = 0;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
doUpdateGrid = false;
|
|
|
|
|
|
|
|
autoWidth = autoHeight = 0;
|
|
|
|
|
|
|
|
renderBorder = false;
|
|
|
|
renderCenter = true;
|
|
|
|
width = 2; height = 2;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
upperLeftTextureCoordinates = Vector(0,0);
|
|
|
|
lowerRightTextureCoordinates = Vector(1,1);
|
|
|
|
renderQuad = true;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-09-24 02:57:08 +00:00
|
|
|
void Quad::_renderBorder(const RenderState& rs, Vector color, float borderalpha) const
|
|
|
|
{
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
|
|
|
|
if (rs.forceRenderCenter || renderCenter)
|
|
|
|
{
|
|
|
|
glColor4f(color.x, color.y, color.z, borderalpha*alpha.x*alphaMod);
|
|
|
|
glPointSize(16);
|
|
|
|
glBegin(GL_POINTS);
|
|
|
|
glVertex2f(0,0);
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
glColor4f(color.x, color.y, color.z, alpha.x*alphaMod);
|
|
|
|
glLineWidth(2);
|
|
|
|
const float _w2 = width*0.5f;
|
|
|
|
const float _h2 = height*0.5f;
|
|
|
|
glBegin(GL_LINES);
|
|
|
|
glVertex2f(-_w2, _h2);
|
|
|
|
glVertex2f(_w2, _h2);
|
|
|
|
glVertex2f(_w2, -_h2);
|
|
|
|
glVertex2f(_w2, _h2);
|
|
|
|
glVertex2f(-_w2, -_h2);
|
|
|
|
glVertex2f(-_w2, _h2);
|
|
|
|
glVertex2f(-_w2, -_h2);
|
|
|
|
glVertex2f(_w2, -_h2);
|
|
|
|
glEnd();
|
|
|
|
RenderObject::lastTextureApplied = 0;
|
|
|
|
}
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
Quad::Quad() : RenderObject()
|
|
|
|
{
|
Script interface improvements & extensions.
- Pointer typechecks are now enabled by default.
- enabled all script warnings for non-FULL or DEMO builds by default
- Added generic obj_* functions that operate on any type of RenderObject.
These give quite low-level control about the renderer, and are quite
dangerous too.
Subsequently, many functions sharing the same code (*_setPosition, for example)
could be removed, and simply call the generic functions after a type check.
- Added interface function deathNotify(). The original logic of death
notifiers was never used, so i thought i'd make use of it.
This is useful in scripts to safely drop dangling pointers.
- removed sendEntityMessage, entity_setCollideWithAvatar, entity_setTouchDamage,
which were essentially no-ops.
- Replaced all unnecessary luaReturnNum(0) and luaReturnInt(0),
now it does only push a return value on the stack if the function
is actually supposed to have a retun value.
- Allow variadic calling of entity_msg(). Now any parameters can be passed
to the function, and the target entity will receive all of them.
Any values returned from the entity's msg() callback will be returned
by entity_msg() to the original caller. This allows nice RPC-like
entity communication.
- fixed possible crash in debugLog, bone_update, entity_debugText
- added an override function for loadfile() that is case-insensitive like dofile()
- entity_createEntity returns the created entity now
- spawnParticleEffect returns the associated RenderObject
- Added some text rendering functions
- Added beam_setFirer()
- removed the underflow check in avatar_decrLeaches() I added earlier
- added a panic function for Lua.
- added the Lua debug library
- fixed a stupid typo in ScriptObject::isType() that made the type checks a lot less accurate
- misc stuff I forgot
2012-02-05 19:22:54 +00:00
|
|
|
addType(SCO_QUAD);
|
2011-08-03 20:05:33 +00:00
|
|
|
borderAlpha = 0.5;
|
2022-09-25 02:30:38 +00:00
|
|
|
drawOrder = GRID_DRAW_DEFAULT;
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
initQuad();
|
2016-05-05 17:40:28 +00:00
|
|
|
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::deleteGrid()
|
|
|
|
{
|
2022-09-14 03:11:56 +00:00
|
|
|
drawGrid.clear();
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::destroy()
|
|
|
|
{
|
|
|
|
deleteGrid();
|
|
|
|
RenderObject::destroy();
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
bool Quad::isCoordinateInside(Vector coord, int minSize) const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2012-01-31 18:25:13 +00:00
|
|
|
Vector realscale = getRealScale();
|
|
|
|
int hw = fabsf((width)*realscale.x)*0.5f;
|
|
|
|
int hh = fabsf((height)*realscale.y)*0.5f;
|
2011-08-03 20:05:33 +00:00
|
|
|
if (hw < minSize)
|
|
|
|
hw = minSize;
|
|
|
|
if (hh < minSize)
|
|
|
|
hh = minSize;
|
|
|
|
|
2012-01-31 18:25:13 +00:00
|
|
|
Vector pos = getRealPosition();
|
|
|
|
|
|
|
|
if (coord.x >= pos.x - hw && coord.x <= pos.x + hw)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2012-01-31 18:25:13 +00:00
|
|
|
if (coord.y >= pos.y - hh && coord.y <= pos.y + hh)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
bool Quad::isCoordinateInsideWorld(const Vector &coord, int minSize) const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
int hw = fabsf((width)*getRealScale().x)*0.5f;
|
|
|
|
int hh = fabsf((height)*getRealScale().y)*0.5f;
|
|
|
|
if (hw < minSize)
|
|
|
|
hw = minSize;
|
|
|
|
if (hh < minSize)
|
|
|
|
hh = minSize;
|
|
|
|
|
|
|
|
Vector pos = getWorldPosition();
|
|
|
|
if (coord.x >= pos.x + offset.x - hw && coord.x <= pos.x + offset.x + hw)
|
|
|
|
{
|
|
|
|
if (coord.y >= pos.y + offset.y - hh && coord.y <= pos.y + offset.y + hh)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2022-05-19 03:17:00 +00:00
|
|
|
bool Quad::isCoordinateInsideWorldRect(const Vector &coord, int w, int h) const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
int hw = w*0.5f;
|
|
|
|
int hh = h*0.5f;
|
|
|
|
|
|
|
|
Vector pos = getWorldPosition();
|
|
|
|
if (coord.x >= pos.x + offset.x - hw && coord.x <= pos.x + offset.x + hw)
|
|
|
|
{
|
|
|
|
if (coord.y >= pos.y + offset.y - hh && coord.y <= pos.y + offset.y + hh)
|
|
|
|
{
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::updateGrid(float dt)
|
|
|
|
{
|
|
|
|
if (!doUpdateGrid) return;
|
|
|
|
|
|
|
|
if (gridType == GRID_WAVY)
|
|
|
|
{
|
|
|
|
gridTimer += dt * drawGridTimeMultiplier;
|
|
|
|
resetGrid();
|
2022-09-14 03:11:56 +00:00
|
|
|
size_t hx = drawGrid.width()/2;
|
|
|
|
for (size_t x = 0; x < drawGrid.width(); x++)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
float yoffset = x * drawGridOffsetY;
|
|
|
|
float addY = 0;
|
|
|
|
if (drawGridModY != 0)
|
|
|
|
addY = cosf(gridTimer+yoffset)*drawGridModY;
|
2022-09-14 03:11:56 +00:00
|
|
|
for (size_t y = 0; y < drawGrid.height(); y++)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
float xoffset = y * drawGridOffsetX;
|
|
|
|
if (drawGridModX != 0)
|
|
|
|
{
|
|
|
|
float addX = (sinf(gridTimer+xoffset)*drawGridModX);
|
|
|
|
if (drawGridOut && x < hx)
|
2022-09-14 03:11:56 +00:00
|
|
|
drawGrid(x,y).x += addX;
|
2011-08-03 20:05:33 +00:00
|
|
|
else
|
2022-09-14 03:11:56 +00:00
|
|
|
drawGrid(x,y).x -= addX;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
2022-09-14 03:11:56 +00:00
|
|
|
drawGrid(x,y).y += addY;
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-21 14:31:10 +00:00
|
|
|
void Quad::renderGrid(const RenderState& rs) const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-09-14 03:11:56 +00:00
|
|
|
if (drawGrid.width() < 2 || drawGrid.height() < 2)
|
2011-08-03 20:05:33 +00:00
|
|
|
return;
|
|
|
|
|
2022-09-25 02:30:38 +00:00
|
|
|
switch(drawOrder)
|
|
|
|
{
|
|
|
|
case GRID_DRAW_LRTB:
|
|
|
|
renderGrid_LRTB(rs);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRID_DRAW_LRBT:
|
|
|
|
renderGrid_LRBT(rs);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case GRID_DRAW_WORLDMAP:
|
|
|
|
renderGridWithAlpha(rs);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// debug points
|
|
|
|
if (RenderObject::renderCollisionShape)
|
|
|
|
{
|
|
|
|
const size_t NX = drawGrid.width()-1;
|
|
|
|
const size_t NY = drawGrid.height()-1;
|
|
|
|
const float w = this->getWidth();
|
|
|
|
const float h = this->getHeight();
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
glPointSize(2);
|
|
|
|
glColor3f(1,0,0);
|
|
|
|
glBegin(GL_POINTS);
|
|
|
|
for (size_t y = 0; y < NY; y++)
|
|
|
|
{
|
|
|
|
for (size_t x = 0; x < NX; x++)
|
|
|
|
{
|
|
|
|
glVertex2f(w*drawGrid(x,y).x, h*drawGrid(x,y).y);
|
|
|
|
glVertex2f(w*drawGrid(x,y+1).x, h*drawGrid(x,y+1).y);
|
|
|
|
glVertex2f(w*drawGrid(x+1,y+1).x, h*drawGrid(x+1,y+1).y);
|
|
|
|
glVertex2f(w*drawGrid(x+1,y).x, h*drawGrid(x+1,y).y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
glEnd();
|
2023-05-30 22:55:16 +00:00
|
|
|
RenderObject::lastTextureApplied = 0;
|
2022-09-25 02:30:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::renderGrid_LRTB(const RenderState& rs) const
|
|
|
|
{
|
|
|
|
const float percentX = lowerRightTextureCoordinates.x - upperLeftTextureCoordinates.x;
|
|
|
|
const float percentY = lowerRightTextureCoordinates.y - upperLeftTextureCoordinates.y;
|
|
|
|
|
|
|
|
const float baseX = upperLeftTextureCoordinates.x;
|
|
|
|
const float baseY = upperLeftTextureCoordinates.y;
|
|
|
|
|
|
|
|
const size_t NX = drawGrid.width()-1;
|
|
|
|
const size_t NY = drawGrid.height()-1;
|
|
|
|
|
|
|
|
// NOTE: These are used to avoid repeated expensive divide operations,
|
|
|
|
// but they may cause rounding error of around 1 part per million,
|
|
|
|
// which could in theory cause minor graphical glitches with broken
|
|
|
|
// OpenGL implementations. --achurch
|
|
|
|
const float incX = percentX / float(NX);
|
|
|
|
const float incY = percentY / float(NY);
|
|
|
|
|
|
|
|
const float w = this->getWidth();
|
|
|
|
const float h = this->getHeight();
|
|
|
|
|
|
|
|
const float red = rs.color.x * this->color.x;
|
|
|
|
const float green = rs.color.y * this->color.y;
|
|
|
|
const float blue = rs.color.z * this->color.z;
|
|
|
|
const float alpha = rs.alpha * this->alpha.x * this->alphaMod;
|
|
|
|
|
|
|
|
glColor4f(red, green, blue, alpha);
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
float v0 = baseY;
|
|
|
|
float v1 = v0 + incY;
|
|
|
|
for (size_t y = 0; y < NY; y++, v0 = v1, v1 += incY)
|
|
|
|
{
|
|
|
|
float u0 = baseX;
|
|
|
|
float u1 = u0 + incX;
|
|
|
|
const Vector *row0 = drawGrid.row(y);
|
|
|
|
const Vector *row1 = drawGrid.row(y+1);
|
|
|
|
for (size_t x = 0; x < NX; x++, u0 = u1, u1 += incX)
|
|
|
|
{
|
|
|
|
const Vector dg00 = row0[x];
|
|
|
|
const Vector dg01 = row1[x];
|
|
|
|
const Vector dg10 = row0[x+1];
|
|
|
|
const Vector dg11 = row1[x+1];
|
|
|
|
|
|
|
|
glTexCoord2f(u0, v0);
|
|
|
|
glVertex2f(w*dg00.x, h*dg00.y);
|
|
|
|
|
|
|
|
glTexCoord2f(u0, v1);
|
|
|
|
glVertex2f(w*dg01.x, h*dg01.y);
|
|
|
|
|
|
|
|
glTexCoord2f(u1, v1);
|
|
|
|
glVertex2f(w*dg11.x, h*dg11.y);
|
|
|
|
|
|
|
|
glTexCoord2f(u1, v0);
|
|
|
|
glVertex2f(w*dg10.x, h*dg10.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::renderGrid_LRBT(const RenderState& rs) const
|
|
|
|
{
|
|
|
|
const float percentX = lowerRightTextureCoordinates.x - upperLeftTextureCoordinates.x;
|
|
|
|
const float percentY = upperLeftTextureCoordinates.y - lowerRightTextureCoordinates.y;
|
|
|
|
|
|
|
|
const float baseX = upperLeftTextureCoordinates.x;
|
|
|
|
const float baseY = lowerRightTextureCoordinates.y;
|
|
|
|
|
|
|
|
const size_t NX = drawGrid.width()-1;
|
|
|
|
const size_t NY = drawGrid.height()-1;
|
|
|
|
|
|
|
|
// NOTE: These are used to avoid repeated expensive divide operations,
|
|
|
|
// but they may cause rounding error of around 1 part per million,
|
|
|
|
// which could in theory cause minor graphical glitches with broken
|
|
|
|
// OpenGL implementations. --achurch
|
|
|
|
const float incX = percentX / float(NX);
|
|
|
|
const float incY = percentY / float(NY);
|
|
|
|
|
|
|
|
const float w = this->getWidth();
|
|
|
|
const float h = this->getHeight();
|
|
|
|
|
|
|
|
const float red = rs.color.x * this->color.x;
|
|
|
|
const float green = rs.color.y * this->color.y;
|
|
|
|
const float blue = rs.color.z * this->color.z;
|
|
|
|
const float alpha = rs.alpha * this->alpha.x * this->alphaMod;
|
|
|
|
|
|
|
|
glColor4f(red, green, blue, alpha);
|
|
|
|
|
|
|
|
glBegin(GL_QUADS);
|
|
|
|
float v0 = baseY;
|
|
|
|
float v1 = v0 + incY;
|
|
|
|
for (size_t y = NY; y --> 0; v0 = v1, v1 += incY)
|
|
|
|
{
|
|
|
|
float u0 = baseX;
|
|
|
|
float u1 = u0 + incX;
|
|
|
|
const Vector *row0 = drawGrid.row(y+1);
|
|
|
|
const Vector *row1 = drawGrid.row(y);
|
|
|
|
for (size_t x = 0; x < NX; x++, u0 = u1, u1 += incX)
|
|
|
|
{
|
|
|
|
const Vector dg00 = row0[x];
|
|
|
|
const Vector dg01 = row1[x];
|
|
|
|
const Vector dg10 = row0[x+1];
|
|
|
|
const Vector dg11 = row1[x+1];
|
|
|
|
|
|
|
|
glTexCoord2f(u0, v0);
|
|
|
|
glVertex2f(w*dg00.x, h*dg00.y);
|
|
|
|
|
|
|
|
glTexCoord2f(u0, v1);
|
|
|
|
glVertex2f(w*dg01.x, h*dg01.y);
|
|
|
|
|
|
|
|
glTexCoord2f(u1, v1);
|
|
|
|
glVertex2f(w*dg11.x, h*dg11.y);
|
|
|
|
|
|
|
|
glTexCoord2f(u1, v0);
|
|
|
|
glVertex2f(w*dg10.x, h*dg10.y);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::renderGridWithAlpha(const RenderState& rs) const
|
|
|
|
{
|
2011-08-03 20:05:33 +00:00
|
|
|
const float percentX = fabsf(this->lowerRightTextureCoordinates.x - this->upperLeftTextureCoordinates.x);
|
|
|
|
const float percentY = fabsf(this->upperLeftTextureCoordinates.y - this->lowerRightTextureCoordinates.y);
|
|
|
|
|
|
|
|
const float baseX =
|
|
|
|
(lowerRightTextureCoordinates.x < upperLeftTextureCoordinates.x)
|
|
|
|
? lowerRightTextureCoordinates.x : upperLeftTextureCoordinates.x;
|
|
|
|
const float baseY =
|
|
|
|
(lowerRightTextureCoordinates.y < upperLeftTextureCoordinates.y)
|
|
|
|
? lowerRightTextureCoordinates.y : upperLeftTextureCoordinates.y;
|
|
|
|
|
2022-09-14 03:11:56 +00:00
|
|
|
const size_t NX = drawGrid.width()-1;
|
|
|
|
const size_t NY = drawGrid.height()-1;
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
// NOTE: These are used to avoid repeated expensive divide operations,
|
|
|
|
// but they may cause rounding error of around 1 part per million,
|
|
|
|
// which could in theory cause minor graphical glitches with broken
|
|
|
|
// OpenGL implementations. --achurch
|
2022-09-14 03:11:56 +00:00
|
|
|
const float incX = percentX / float(NX);
|
|
|
|
const float incY = percentY / float(NY);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
const float w = this->getWidth();
|
|
|
|
const float h = this->getHeight();
|
|
|
|
|
2022-05-21 14:31:10 +00:00
|
|
|
const float red = rs.color.x * this->color.x;
|
|
|
|
const float green = rs.color.y * this->color.y;
|
|
|
|
const float blue = rs.color.z * this->color.z;
|
|
|
|
const float alpha = rs.alpha * this->alpha.x * this->alphaMod;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2012-02-19 03:57:04 +00:00
|
|
|
glBegin(GL_QUADS);
|
2022-09-14 03:36:46 +00:00
|
|
|
float v0 = 1 - percentY + baseY;
|
|
|
|
float v1 = v0 + incY;
|
|
|
|
for (size_t y = 0; y < NY; y++, v0 = v1, v1 += incY)
|
2012-02-19 03:57:04 +00:00
|
|
|
{
|
2022-09-14 03:36:46 +00:00
|
|
|
float u0 = baseX;
|
|
|
|
float u1 = u0 + incX;
|
|
|
|
const Vector *row0 = drawGrid.row(y);
|
|
|
|
const Vector *row1 = drawGrid.row(y+1);
|
|
|
|
for (size_t x = 0; x < NX; x++, u0 = u1, u1 += incX)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-09-14 03:36:46 +00:00
|
|
|
const Vector dg00 = row0[x];
|
|
|
|
const Vector dg01 = row1[x];
|
|
|
|
const Vector dg10 = row0[x+1];
|
|
|
|
const Vector dg11 = row1[x+1];
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-09-14 03:36:46 +00:00
|
|
|
if (dg00.z != 0 || dg01.z != 0 || dg10.z != 0 || dg11.z != 0)
|
|
|
|
{
|
|
|
|
glColor4f(red, green, blue, alpha*dg00.z);
|
2012-02-19 03:57:04 +00:00
|
|
|
glTexCoord2f(u0, v0);
|
2022-09-14 03:36:46 +00:00
|
|
|
glVertex2f(w*dg00.x, h*dg00.y);
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2022-09-14 03:36:46 +00:00
|
|
|
glColor4f(red, green, blue, alpha*dg01.z);
|
2012-02-19 03:57:04 +00:00
|
|
|
glTexCoord2f(u0, v1);
|
2022-09-14 03:36:46 +00:00
|
|
|
glVertex2f(w*dg01.x, h*dg01.y);
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2022-09-14 03:36:46 +00:00
|
|
|
glColor4f(red, green, blue, alpha*dg11.z);
|
2012-02-19 03:57:04 +00:00
|
|
|
glTexCoord2f(u1, v1);
|
2022-09-14 03:36:46 +00:00
|
|
|
glVertex2f(w*dg11.x, h*dg11.y);
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2022-09-14 03:36:46 +00:00
|
|
|
glColor4f(red, green, blue, alpha*dg10.z);
|
2012-02-19 03:57:04 +00:00
|
|
|
glTexCoord2f(u1, v0);
|
2022-09-14 03:36:46 +00:00
|
|
|
glVertex2f(w*dg10.x, h*dg10.y);
|
2012-02-19 03:57:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
glEnd();
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::repeatTextureToFill(bool on)
|
|
|
|
{
|
2012-02-19 03:57:04 +00:00
|
|
|
repeatTexture = on;
|
|
|
|
refreshRepeatTextureToFill();
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-19 23:04:19 +00:00
|
|
|
void Quad::onRender(const RenderState& rs) const
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
if (!renderQuad) return;
|
|
|
|
|
2022-05-21 15:31:50 +00:00
|
|
|
const float _w2 = width*0.5f;
|
|
|
|
const float _h2 = height*0.5f;
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-09-14 03:11:56 +00:00
|
|
|
if (drawGrid.empty())
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-21 15:31:50 +00:00
|
|
|
glBegin(GL_QUADS);
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2022-05-21 15:31:50 +00:00
|
|
|
glTexCoord2f(upperLeftTextureCoordinates.x, 1.0f-upperLeftTextureCoordinates.y);
|
|
|
|
glVertex2f(-_w2, +_h2);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-21 15:31:50 +00:00
|
|
|
glTexCoord2f(lowerRightTextureCoordinates.x, 1.0f-upperLeftTextureCoordinates.y);
|
|
|
|
glVertex2f(+_w2, +_h2);
|
2016-05-05 17:40:28 +00:00
|
|
|
|
2022-05-21 15:31:50 +00:00
|
|
|
glTexCoord2f(lowerRightTextureCoordinates.x, 1.0f-lowerRightTextureCoordinates.y);
|
|
|
|
glVertex2f(+_w2, -_h2);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
2022-05-21 15:31:50 +00:00
|
|
|
glTexCoord2f(upperLeftTextureCoordinates.x, 1.0f-lowerRightTextureCoordinates.y);
|
|
|
|
glVertex2f(-_w2, -_h2);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
glEnd();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2022-05-21 15:31:50 +00:00
|
|
|
renderGrid(rs);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-09-24 02:57:08 +00:00
|
|
|
if(renderBorder)
|
|
|
|
_renderBorder(rs, renderBorderColor, borderAlpha);
|
|
|
|
else if(rs.forceRenderBorder)
|
|
|
|
_renderBorder(rs, rs.renderBorderColor, rs.renderBorderAlpha);
|
2011-08-03 20:05:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void Quad::flipHorizontal()
|
|
|
|
{
|
|
|
|
RenderObject::flipHorizontal();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::flipVertical()
|
|
|
|
{
|
|
|
|
if (!_fv)
|
|
|
|
{
|
|
|
|
lowerRightTextureCoordinates.y = 0;
|
|
|
|
upperLeftTextureCoordinates.y = 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
lowerRightTextureCoordinates.y = 1;
|
|
|
|
upperLeftTextureCoordinates.y = 0;
|
|
|
|
}
|
|
|
|
RenderObject::flipVertical();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::refreshRepeatTextureToFill()
|
|
|
|
{
|
2022-05-20 02:05:54 +00:00
|
|
|
if (repeatTexture && texture)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
upperLeftTextureCoordinates.x = texOff.x;
|
|
|
|
upperLeftTextureCoordinates.y = texOff.y;
|
|
|
|
lowerRightTextureCoordinates.x = (width*scale.x*repeatToFillScale.x)/texture->width + texOff.x;
|
|
|
|
lowerRightTextureCoordinates.y = (height*scale.y*repeatToFillScale.y)/texture->height + texOff.y;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
if (fabsf(lowerRightTextureCoordinates.x) > 1 || fabsf(lowerRightTextureCoordinates.y)>1)
|
|
|
|
lowerRightTextureCoordinates = Vector(1,1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::reloadDevice()
|
|
|
|
{
|
|
|
|
RenderObject::reloadDevice();
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::onUpdate(float dt)
|
|
|
|
{
|
|
|
|
RenderObject::onUpdate(dt);
|
|
|
|
|
|
|
|
if (autoWidth == AUTO_VIRTUALWIDTH)
|
|
|
|
width = core->getVirtualWidth();
|
|
|
|
else if (autoWidth == AUTO_VIRTUALHEIGHT)
|
|
|
|
width = core->getVirtualHeight();
|
|
|
|
|
|
|
|
if (autoHeight == AUTO_VIRTUALWIDTH)
|
|
|
|
height = core->getVirtualWidth();
|
|
|
|
else if (autoHeight == AUTO_VIRTUALHEIGHT)
|
|
|
|
height = core->getVirtualHeight();
|
|
|
|
|
|
|
|
|
|
|
|
refreshRepeatTextureToFill();
|
|
|
|
|
|
|
|
lowerRightTextureCoordinates.update(dt);
|
|
|
|
upperLeftTextureCoordinates.update(dt);
|
|
|
|
|
2022-09-14 03:11:56 +00:00
|
|
|
if (!drawGrid.empty() && alpha.x > 0 && alphaMod > 0)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
updateGrid(dt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Script interface improvements & extensions.
- Pointer typechecks are now enabled by default.
- enabled all script warnings for non-FULL or DEMO builds by default
- Added generic obj_* functions that operate on any type of RenderObject.
These give quite low-level control about the renderer, and are quite
dangerous too.
Subsequently, many functions sharing the same code (*_setPosition, for example)
could be removed, and simply call the generic functions after a type check.
- Added interface function deathNotify(). The original logic of death
notifiers was never used, so i thought i'd make use of it.
This is useful in scripts to safely drop dangling pointers.
- removed sendEntityMessage, entity_setCollideWithAvatar, entity_setTouchDamage,
which were essentially no-ops.
- Replaced all unnecessary luaReturnNum(0) and luaReturnInt(0),
now it does only push a return value on the stack if the function
is actually supposed to have a retun value.
- Allow variadic calling of entity_msg(). Now any parameters can be passed
to the function, and the target entity will receive all of them.
Any values returned from the entity's msg() callback will be returned
by entity_msg() to the original caller. This allows nice RPC-like
entity communication.
- fixed possible crash in debugLog, bone_update, entity_debugText
- added an override function for loadfile() that is case-insensitive like dofile()
- entity_createEntity returns the created entity now
- spawnParticleEffect returns the associated RenderObject
- Added some text rendering functions
- Added beam_setFirer()
- removed the underflow check in avatar_decrLeaches() I added earlier
- added a panic function for Lua.
- added the Lua debug library
- fixed a stupid typo in ScriptObject::isType() that made the type checks a lot less accurate
- misc stuff I forgot
2012-02-05 19:22:54 +00:00
|
|
|
void Quad::setWidthHeight(float w, float h)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
if (h == -1)
|
|
|
|
height = w;
|
|
|
|
else
|
|
|
|
height = h;
|
|
|
|
width = w;
|
|
|
|
}
|
|
|
|
|
Script interface improvements & extensions.
- Pointer typechecks are now enabled by default.
- enabled all script warnings for non-FULL or DEMO builds by default
- Added generic obj_* functions that operate on any type of RenderObject.
These give quite low-level control about the renderer, and are quite
dangerous too.
Subsequently, many functions sharing the same code (*_setPosition, for example)
could be removed, and simply call the generic functions after a type check.
- Added interface function deathNotify(). The original logic of death
notifiers was never used, so i thought i'd make use of it.
This is useful in scripts to safely drop dangling pointers.
- removed sendEntityMessage, entity_setCollideWithAvatar, entity_setTouchDamage,
which were essentially no-ops.
- Replaced all unnecessary luaReturnNum(0) and luaReturnInt(0),
now it does only push a return value on the stack if the function
is actually supposed to have a retun value.
- Allow variadic calling of entity_msg(). Now any parameters can be passed
to the function, and the target entity will receive all of them.
Any values returned from the entity's msg() callback will be returned
by entity_msg() to the original caller. This allows nice RPC-like
entity communication.
- fixed possible crash in debugLog, bone_update, entity_debugText
- added an override function for loadfile() that is case-insensitive like dofile()
- entity_createEntity returns the created entity now
- spawnParticleEffect returns the associated RenderObject
- Added some text rendering functions
- Added beam_setFirer()
- removed the underflow check in avatar_decrLeaches() I added earlier
- added a panic function for Lua.
- added the Lua debug library
- fixed a stupid typo in ScriptObject::isType() that made the type checks a lot less accurate
- misc stuff I forgot
2012-02-05 19:22:54 +00:00
|
|
|
void Quad::setWidth(float w)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
width = w;
|
|
|
|
}
|
|
|
|
|
Script interface improvements & extensions.
- Pointer typechecks are now enabled by default.
- enabled all script warnings for non-FULL or DEMO builds by default
- Added generic obj_* functions that operate on any type of RenderObject.
These give quite low-level control about the renderer, and are quite
dangerous too.
Subsequently, many functions sharing the same code (*_setPosition, for example)
could be removed, and simply call the generic functions after a type check.
- Added interface function deathNotify(). The original logic of death
notifiers was never used, so i thought i'd make use of it.
This is useful in scripts to safely drop dangling pointers.
- removed sendEntityMessage, entity_setCollideWithAvatar, entity_setTouchDamage,
which were essentially no-ops.
- Replaced all unnecessary luaReturnNum(0) and luaReturnInt(0),
now it does only push a return value on the stack if the function
is actually supposed to have a retun value.
- Allow variadic calling of entity_msg(). Now any parameters can be passed
to the function, and the target entity will receive all of them.
Any values returned from the entity's msg() callback will be returned
by entity_msg() to the original caller. This allows nice RPC-like
entity communication.
- fixed possible crash in debugLog, bone_update, entity_debugText
- added an override function for loadfile() that is case-insensitive like dofile()
- entity_createEntity returns the created entity now
- spawnParticleEffect returns the associated RenderObject
- Added some text rendering functions
- Added beam_setFirer()
- removed the underflow check in avatar_decrLeaches() I added earlier
- added a panic function for Lua.
- added the Lua debug library
- fixed a stupid typo in ScriptObject::isType() that made the type checks a lot less accurate
- misc stuff I forgot
2012-02-05 19:22:54 +00:00
|
|
|
void Quad::setHeight(float h)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
|
|
|
height = h;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Quad::onSetTexture()
|
|
|
|
{
|
|
|
|
if (texture)
|
|
|
|
{
|
|
|
|
width = this->texture->width;
|
|
|
|
height = this->texture->height;
|
|
|
|
}
|
2015-03-23 23:06:51 +00:00
|
|
|
else
|
|
|
|
{
|
|
|
|
width = 64;
|
|
|
|
height = 64;
|
|
|
|
}
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 00:49:14 +00:00
|
|
|
PauseQuad::PauseQuad() : Quad(), pauseLevel(0), positionSnapTo(0)
|
2011-08-03 20:05:33 +00:00
|
|
|
{
|
2013-04-25 00:51:54 +00:00
|
|
|
addType(SCO_PAUSEQUAD);
|
2011-08-03 20:05:33 +00:00
|
|
|
}
|
|
|
|
|
2022-05-18 17:44:42 +00:00
|
|
|
PauseQuad::~PauseQuad()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
void PauseQuad::onUpdate(float dt)
|
|
|
|
{
|
2022-05-18 00:49:14 +00:00
|
|
|
if (positionSnapTo)
|
|
|
|
this->position = *positionSnapTo;
|
|
|
|
|
2011-08-03 20:05:33 +00:00
|
|
|
if (core->particlesPaused <= pauseLevel)
|
|
|
|
{
|
|
|
|
Quad::onUpdate(dt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-05-18 00:49:14 +00:00
|
|
|
void PauseQuad::setPositionSnapTo(InterpolatedVector *positionSnapTo)
|
|
|
|
{
|
|
|
|
this->positionSnapTo = positionSnapTo;
|
|
|
|
}
|
2022-05-18 17:44:42 +00:00
|
|
|
|
|
|
|
CollideQuad::CollideQuad()
|
|
|
|
: collideRadius(0)
|
|
|
|
{
|
|
|
|
addType(SCO_COLLIDE_QUAD);
|
|
|
|
}
|
|
|
|
|
|
|
|
CollideQuad::~CollideQuad()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2022-05-19 23:04:19 +00:00
|
|
|
void CollideQuad::renderCollision(const RenderState& rs) const
|
2022-05-18 17:44:42 +00:00
|
|
|
{
|
|
|
|
if (collideRadius > 0)
|
|
|
|
{
|
|
|
|
glPushMatrix();
|
|
|
|
glLoadIdentity();
|
|
|
|
core->setupRenderPositionAndScale();
|
|
|
|
glBindTexture(GL_TEXTURE_2D, 0);
|
|
|
|
glTranslatef(position.x+offset.x, position.y+offset.y, 0);
|
|
|
|
|
|
|
|
glTranslatef(internalOffset.x, internalOffset.y, 0);
|
|
|
|
glEnable(GL_BLEND);
|
|
|
|
|
|
|
|
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
|
|
|
glColor4f(1,0,0,0.5);
|
|
|
|
drawCircle(collideRadius, 8);
|
|
|
|
glDisable(GL_BLEND);
|
|
|
|
glTranslatef(offset.x, offset.y,0);
|
|
|
|
glPopMatrix();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|