more optimized uses of EntityItem::getDimensions()

This commit is contained in:
Andrew Meadows 2016-04-27 11:04:22 -07:00
parent c686418be0
commit b5ad989811
5 changed files with 15 additions and 12 deletions

View file

@ -339,15 +339,16 @@ void RenderableModelEntityItem::updateModelBounds() {
return;
}
bool movingOrAnimating = isMovingRelativeToParent() || isAnimatingSomething();
glm::vec3 dimensions = getDimensions();
if ((movingOrAnimating ||
_needsInitialSimulation ||
_needsJointSimulation ||
_model->getTranslation() != getPosition() ||
_model->getScaleToFitDimensions() != getDimensions() ||
_model->getScaleToFitDimensions() != dimensions ||
_model->getRotation() != getRotation() ||
_model->getRegistrationPoint() != getRegistrationPoint())
&& _model->isActive() && _dimensionsInitialized) {
_model->setScaleToFit(true, getDimensions());
_model->setScaleToFit(true, dimensions);
_model->setSnapModelToRegistrationPoint(true, getRegistrationPoint());
_model->setRotation(getRotation());
_model->setTranslation(getPosition());

View file

@ -206,13 +206,14 @@ glm::mat4 RenderablePolyVoxEntityItem::voxelToLocalMatrix() const {
voxelVolumeSize = _voxelVolumeSize;
});
glm::vec3 scale = getDimensions() / voxelVolumeSize; // meters / voxel-units
glm::vec3 dimensions = getDimensions();
glm::vec3 scale = dimensions / voxelVolumeSize; // meters / voxel-units
bool success; // TODO -- Does this actually have to happen in world space?
glm::vec3 center = getCenterPosition(success); // this handles registrationPoint changes
glm::vec3 position = getPosition(success);
glm::vec3 positionToCenter = center - position;
positionToCenter -= getDimensions() * Vectors::HALF - getSurfacePositionAdjustment();
positionToCenter -= dimensions * Vectors::HALF - getSurfacePositionAdjustment();
glm::mat4 centerToCorner = glm::translate(glm::mat4(), positionToCenter);
glm::mat4 scaled = glm::scale(centerToCorner, scale);
return scaled;
@ -445,7 +446,8 @@ bool RenderablePolyVoxEntityItem::findDetailedRayIntersection(const glm::vec3& o
// the PolyVox ray intersection code requires a near and far point.
// set ray cast length to long enough to cover all of the voxel space
float distanceToEntity = glm::distance(origin, getPosition());
float largestDimension = glm::max(getDimensions().x, getDimensions().y, getDimensions().z) * 2.0f;
glm::vec3 dimensions = getDimensions();
float largestDimension = glm::max(dimensions.x, dimensions.y, dimensions.z) * 2.0f;
glm::vec3 farPoint = origin + normDirection * (distanceToEntity + largestDimension);
glm::vec4 originInVoxel = wtvMatrix * glm::vec4(origin, 1.0f);

View file

@ -119,12 +119,13 @@ bool RenderableWebEntityItem::buildWebSurface(EntityTreeRenderer* renderer) {
// Map the intersection point to an actual offscreen pixel
glm::vec3 point = intersection.intersection;
glm::vec3 dimensions = getDimensions();
point -= getPosition();
point = glm::inverse(getRotation()) * point;
point /= getDimensions();
point /= dimensions;
point += 0.5f;
point.y = 1.0f - point.y;
point *= getDimensions() * METERS_TO_INCHES * DPI;
point *= dimensions * (METERS_TO_INCHES * DPI);
if (event->button() == Qt::MouseButton::LeftButton) {
if (event->type() == QEvent::MouseButtonPress) {

View file

@ -76,12 +76,13 @@ void LightEntityItem::setIsSpotlight(bool value) {
if (value != _isSpotlight) {
_isSpotlight = value;
glm::vec3 dimensions = getDimensions();
if (_isSpotlight) {
const float length = getDimensions().z;
const float length = dimensions.z;
const float width = length * glm::sin(glm::radians(_cutoff));
setDimensions(glm::vec3(width, width, length));
} else {
float maxDimension = glm::max(getDimensions().x, getDimensions().y, getDimensions().z);
float maxDimension = glm::max(dimensions.x, dimensions.y, dimensions.z);
setDimensions(glm::vec3(maxDimension, maxDimension, maxDimension));
}
}

View file

@ -101,15 +101,13 @@ bool LineEntityItem::setLinePoints(const QVector<glm::vec3>& points) {
if (points.size() > MAX_POINTS_PER_LINE) {
return false;
}
glm::vec3 halfBox = getDimensions() * 0.5f;
for (int i = 0; i < points.size(); i++) {
glm::vec3 point = points.at(i);
// glm::vec3 pos = getPosition();
glm::vec3 halfBox = getDimensions() * 0.5f;
if ( (point.x < - halfBox.x || point.x > halfBox.x) || (point.y < -halfBox.y || point.y > halfBox.y) || (point.z < - halfBox.z || point.z > halfBox.z) ) {
qDebug() << "Point is outside entity's bounding box";
return false;
}
}
_points = points;
_pointsChanged = true;