mirror of
https://thingvellir.net/git/overte
synced 2025-03-27 23:52:03 +01:00
Added aspect fields to cuboids.
This commit is contained in:
parent
d3761cd753
commit
bce0147776
3 changed files with 42 additions and 8 deletions
|
@ -2357,6 +2357,7 @@ void CuboidRenderer::renderUnclipped(const glm::vec4& color, Mode mode) {
|
|||
glm::quat rotation = cuboid->getRotation();
|
||||
glm::vec3 axis = glm::axis(rotation);
|
||||
glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z);
|
||||
glScalef(1.0f, cuboid->getAspectY(), cuboid->getAspectZ());
|
||||
|
||||
glutSolidCube(cuboid->getScale() * 2.0f);
|
||||
|
||||
|
|
|
@ -2246,13 +2246,30 @@ AttributeValue Sphere::getNormal(MetavoxelInfo& info, int alpha) const {
|
|||
return AttributeValue(getAttributes().at(1), encodeInline<QRgb>(color));
|
||||
}
|
||||
|
||||
Cuboid::Cuboid() {
|
||||
Cuboid::Cuboid() :
|
||||
_aspectY(1.0f),
|
||||
_aspectZ(1.0f) {
|
||||
|
||||
connect(this, &Cuboid::translationChanged, this, &Cuboid::updateBoundsAndPlanes);
|
||||
connect(this, &Cuboid::rotationChanged, this, &Cuboid::updateBoundsAndPlanes);
|
||||
connect(this, &Cuboid::scaleChanged, this, &Cuboid::updateBoundsAndPlanes);
|
||||
connect(this, &Cuboid::aspectYChanged, this, &Cuboid::updateBoundsAndPlanes);
|
||||
connect(this, &Cuboid::aspectZChanged, this, &Cuboid::updateBoundsAndPlanes);
|
||||
updateBoundsAndPlanes();
|
||||
}
|
||||
|
||||
void Cuboid::setAspectY(float aspectY) {
|
||||
if (_aspectY != aspectY) {
|
||||
emit aspectYChanged(_aspectY = aspectY);
|
||||
}
|
||||
}
|
||||
|
||||
void Cuboid::setAspectZ(float aspectZ) {
|
||||
if (_aspectZ != aspectZ) {
|
||||
emit aspectZChanged(_aspectZ = aspectZ);
|
||||
}
|
||||
}
|
||||
|
||||
bool Cuboid::contains(const glm::vec3& point) {
|
||||
glm::vec4 point4(point, 1.0f);
|
||||
for (int i = 0; i < PLANE_COUNT; i++) {
|
||||
|
@ -2299,17 +2316,17 @@ QByteArray Cuboid::getRendererClassName() const {
|
|||
}
|
||||
|
||||
void Cuboid::updateBoundsAndPlanes() {
|
||||
glm::vec3 extent(getScale(), getScale(), getScale());
|
||||
glm::vec3 extent(getScale(), getScale() * _aspectY, getScale() * _aspectZ);
|
||||
glm::mat4 rotationMatrix = glm::mat4_cast(getRotation());
|
||||
setBounds(glm::translate(getTranslation()) * rotationMatrix * Box(-extent, extent));
|
||||
|
||||
glm::vec4 translation4 = glm::vec4(getTranslation(), 1.0f);
|
||||
_planes[0] = glm::vec4(glm::vec3(rotationMatrix[0]), -glm::dot(rotationMatrix[0], translation4) - getScale());
|
||||
_planes[1] = glm::vec4(glm::vec3(-rotationMatrix[0]), glm::dot(rotationMatrix[0], translation4) - getScale());
|
||||
_planes[2] = glm::vec4(glm::vec3(rotationMatrix[1]), -glm::dot(rotationMatrix[1], translation4) - getScale());
|
||||
_planes[3] = glm::vec4(glm::vec3(-rotationMatrix[1]), glm::dot(rotationMatrix[1], translation4) - getScale());
|
||||
_planes[4] = glm::vec4(glm::vec3(rotationMatrix[2]), -glm::dot(rotationMatrix[2], translation4) - getScale());
|
||||
_planes[5] = glm::vec4(glm::vec3(-rotationMatrix[2]), glm::dot(rotationMatrix[2], translation4) - getScale());
|
||||
_planes[2] = glm::vec4(glm::vec3(rotationMatrix[1]), -glm::dot(rotationMatrix[1], translation4) - getScale() * _aspectY);
|
||||
_planes[3] = glm::vec4(glm::vec3(-rotationMatrix[1]), glm::dot(rotationMatrix[1], translation4) - getScale() * _aspectY);
|
||||
_planes[4] = glm::vec4(glm::vec3(rotationMatrix[2]), -glm::dot(rotationMatrix[2], translation4) - getScale() * _aspectZ);
|
||||
_planes[5] = glm::vec4(glm::vec3(-rotationMatrix[2]), glm::dot(rotationMatrix[2], translation4) - getScale() * _aspectZ);
|
||||
}
|
||||
|
||||
StaticModel::StaticModel() {
|
||||
|
|
|
@ -777,14 +777,27 @@ private:
|
|||
/// A cuboid.
|
||||
class Cuboid : public ColorTransformable {
|
||||
Q_OBJECT
|
||||
|
||||
Q_PROPERTY(float aspectY MEMBER _aspectY WRITE setAspectY NOTIFY aspectYChanged)
|
||||
Q_PROPERTY(float aspectZ MEMBER _aspectZ WRITE setAspectZ NOTIFY aspectZChanged)
|
||||
|
||||
public:
|
||||
|
||||
Q_INVOKABLE Cuboid();
|
||||
|
||||
void setAspectY(float aspectY);
|
||||
float getAspectY() const { return _aspectY; }
|
||||
|
||||
void setAspectZ(float aspectZ);
|
||||
float getAspectZ() const { return _aspectZ; }
|
||||
|
||||
virtual bool contains(const glm::vec3& point);
|
||||
virtual bool intersects(const glm::vec3& start, const glm::vec3& end, float& distance, glm::vec3& normal);
|
||||
|
||||
|
||||
signals:
|
||||
|
||||
void aspectYChanged(float aspectY);
|
||||
void aspectZChanged(float aspectZ);
|
||||
|
||||
protected:
|
||||
|
||||
virtual QByteArray getRendererClassName() const;
|
||||
|
@ -794,6 +807,9 @@ private slots:
|
|||
void updateBoundsAndPlanes();
|
||||
|
||||
private:
|
||||
|
||||
float _aspectY;
|
||||
float _aspectZ;
|
||||
|
||||
static const int PLANE_COUNT = 6;
|
||||
glm::vec4 _planes[PLANE_COUNT];
|
||||
|
|
Loading…
Reference in a new issue