mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 16:36:54 +02:00
Added subimage to Billboards overlays
This commit is contained in:
parent
2347bd7eed
commit
bd7b17a787
2 changed files with 47 additions and 9 deletions
|
@ -14,7 +14,8 @@
|
||||||
#include "BillboardOverlay.h"
|
#include "BillboardOverlay.h"
|
||||||
|
|
||||||
BillboardOverlay::BillboardOverlay()
|
BillboardOverlay::BillboardOverlay()
|
||||||
: _scale(1.0f),
|
: _fromImage(-1,-1,-1,-1),
|
||||||
|
_scale(1.0f),
|
||||||
_isFacingAvatar(true) {
|
_isFacingAvatar(true) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,6 +29,9 @@ void BillboardOverlay::render() {
|
||||||
image = image.convertToFormat(QImage::Format_ARGB32);
|
image = image.convertToFormat(QImage::Format_ARGB32);
|
||||||
}
|
}
|
||||||
_size = image.size();
|
_size = image.size();
|
||||||
|
if (_fromImage.x() == -1) {
|
||||||
|
_fromImage.setRect(0, 0, _size.width(), _size.height());
|
||||||
|
}
|
||||||
_billboardTexture.reset(new Texture());
|
_billboardTexture.reset(new Texture());
|
||||||
glBindTexture(GL_TEXTURE_2D, _billboardTexture->getID());
|
glBindTexture(GL_TEXTURE_2D, _billboardTexture->getID());
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _size.width(), _size.height(), 0,
|
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, _size.width(), _size.height(), 0,
|
||||||
|
@ -58,19 +62,23 @@ void BillboardOverlay::render() {
|
||||||
}
|
}
|
||||||
glScalef(_scale, _scale, _scale);
|
glScalef(_scale, _scale, _scale);
|
||||||
|
|
||||||
float maxSize = glm::max(_size.width(), _size.height());
|
float maxSize = glm::max(_fromImage.width(), _fromImage.height());
|
||||||
float x = _size.width() / (2.0f * maxSize);
|
float x = _fromImage.width() / (2.0f * maxSize);
|
||||||
float y = -_size.height() / (2.0f * maxSize);
|
float y = -_fromImage.height() / (2.0f * maxSize);
|
||||||
|
|
||||||
glColor3f(1.0f, 1.0f, 1.0f);
|
glColor3f(1.0f, 1.0f, 1.0f);
|
||||||
glBegin(GL_QUADS); {
|
glBegin(GL_QUADS); {
|
||||||
glTexCoord2f(0.0f, 0.0f);
|
glTexCoord2f((float)_fromImage.x() / (float)_size.width(),
|
||||||
|
(float)_fromImage.y() / (float)_size.height());
|
||||||
glVertex2f(-x, -y);
|
glVertex2f(-x, -y);
|
||||||
glTexCoord2f(1.0f, 0.0f);
|
glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
|
||||||
|
(float)_fromImage.y() / (float)_size.height());
|
||||||
glVertex2f(x, -y);
|
glVertex2f(x, -y);
|
||||||
glTexCoord2f(1.0f, 1.0f);
|
glTexCoord2f(((float)_fromImage.x() + (float)_fromImage.width()) / (float)_size.width(),
|
||||||
|
((float)_fromImage.y() + (float)_fromImage.height()) / _size.height());
|
||||||
glVertex2f(x, y);
|
glVertex2f(x, y);
|
||||||
glTexCoord2f(0.0f, 1.0f);
|
glTexCoord2f((float)_fromImage.x() / (float)_size.width(),
|
||||||
|
((float)_fromImage.y() + (float)_fromImage.height()) / (float)_size.height());
|
||||||
glVertex2f(-x, y);
|
glVertex2f(-x, y);
|
||||||
} glEnd();
|
} glEnd();
|
||||||
|
|
||||||
|
@ -93,6 +101,33 @@ void BillboardOverlay::setProperties(const QScriptValue &properties) {
|
||||||
setBillboardURL(_url);
|
setBillboardURL(_url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QScriptValue subImageBounds = properties.property("subImage");
|
||||||
|
if (subImageBounds.isValid()) {
|
||||||
|
QRect oldSubImageRect = _fromImage;
|
||||||
|
QRect subImageRect = _fromImage;
|
||||||
|
if (subImageBounds.property("x").isValid()) {
|
||||||
|
subImageRect.setX(subImageBounds.property("x").toVariant().toInt());
|
||||||
|
} else {
|
||||||
|
subImageRect.setX(oldSubImageRect.x());
|
||||||
|
}
|
||||||
|
if (subImageBounds.property("y").isValid()) {
|
||||||
|
subImageRect.setY(subImageBounds.property("y").toVariant().toInt());
|
||||||
|
} else {
|
||||||
|
subImageRect.setY(oldSubImageRect.y());
|
||||||
|
}
|
||||||
|
if (subImageBounds.property("width").isValid()) {
|
||||||
|
subImageRect.setWidth(subImageBounds.property("width").toVariant().toInt());
|
||||||
|
} else {
|
||||||
|
subImageRect.setWidth(oldSubImageRect.width());
|
||||||
|
}
|
||||||
|
if (subImageBounds.property("height").isValid()) {
|
||||||
|
subImageRect.setHeight(subImageBounds.property("height").toVariant().toInt());
|
||||||
|
} else {
|
||||||
|
subImageRect.setHeight(oldSubImageRect.height());
|
||||||
|
}
|
||||||
|
setClipFromSource(subImageRect);
|
||||||
|
}
|
||||||
|
|
||||||
QScriptValue scaleValue = properties.property("scale");
|
QScriptValue scaleValue = properties.property("scale");
|
||||||
if (scaleValue.isValid()) {
|
if (scaleValue.isValid()) {
|
||||||
_scale = scaleValue.toVariant().toFloat();
|
_scale = scaleValue.toVariant().toFloat();
|
||||||
|
|
|
@ -25,7 +25,8 @@ public:
|
||||||
|
|
||||||
virtual void render();
|
virtual void render();
|
||||||
virtual void setProperties(const QScriptValue& properties);
|
virtual void setProperties(const QScriptValue& properties);
|
||||||
|
void setClipFromSource(const QRect& bounds) { _fromImage = bounds; }
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void replyFinished();
|
void replyFinished();
|
||||||
|
|
||||||
|
@ -37,6 +38,8 @@ private:
|
||||||
QSize _size;
|
QSize _size;
|
||||||
QScopedPointer<Texture> _billboardTexture;
|
QScopedPointer<Texture> _billboardTexture;
|
||||||
|
|
||||||
|
QRect _fromImage; // where from in the image to sample
|
||||||
|
|
||||||
glm::quat _rotation;
|
glm::quat _rotation;
|
||||||
float _scale;
|
float _scale;
|
||||||
bool _isFacingAvatar;
|
bool _isFacingAvatar;
|
||||||
|
|
Loading…
Reference in a new issue