Clean up align tool (mostly datatype fixes)

master
Ansariel 2015-11-02 15:59:46 +01:00
parent 3ea7ebc09a
commit 85ec6fc510
2 changed files with 55 additions and 84 deletions

View File

@ -9,7 +9,6 @@
#include "qtoolalign.h"
// Library includes
#include "llbbox.h"
#include "v3math.h"
// Viewer includes
@ -23,13 +22,11 @@
#include "llviewerobject.h"
#include "llviewerwindow.h"
#include "lleventtimer.h"
#include "fscommon.h"
const F32 MANIPULATOR_SIZE = 5.0f;
const F32 MANIPULATOR_SELECT_SIZE = 20.0f;
const F32 FUDGE = 0.001f; // because of SL precision/rounding
AlignThread* AlignThread::sInstance = NULL;
@ -38,13 +35,10 @@ QToolAlign::QToolAlign()
{
}
QToolAlign::~QToolAlign()
{
}
BOOL QToolAlign::handleMouseDown(S32 x, S32 y, MASK mask)
{
if (mHighlightedAxis != -1)
@ -59,8 +53,6 @@ BOOL QToolAlign::handleMouseDown(S32 x, S32 y, MASK mask)
return TRUE;
}
void QToolAlign::pickCallback(const LLPickInfo& pick_info)
{
LLViewerObject* object = pick_info.getObject();
@ -102,8 +94,6 @@ void QToolAlign::pickCallback(const LLPickInfo& pick_info)
LLSelectMgr::getInstance()->promoteSelectionToRoot();
}
void QToolAlign::handleSelect()
{
// no parts, please
@ -112,12 +102,10 @@ void QToolAlign::handleSelect()
LLSelectMgr::getInstance()->promoteSelectionToRoot();
}
void QToolAlign::handleDeselect()
{
}
BOOL QToolAlign::findSelectedManipulator(S32 x, S32 y)
{
mHighlightedAxis = -1;
@ -160,12 +148,12 @@ BOOL QToolAlign::findSelectedManipulator(S32 x, S32 y)
for (S32 axis = VX; axis <= VZ; axis++)
{
for (F32 direction = -1.0; direction <= 1.0; direction += 2.0)
for (F32 direction = -1.0f; direction <= 1.0f; direction += 2.0f)
{
LLVector3 axis_vector = LLVector3(0,0,0);
axis_vector.mV[axis] = direction * bbox_scale.mV[axis] / 2.0;
LLVector3 axis_vector = LLVector3(0.f, 0.f, 0.f);
axis_vector.mV[axis] = direction * bbox_scale.mV[axis] / 2.0f;
LLVector4 manipulator_center = LLVector4(axis_vector);
LLVector4 manipulator_center = LLVector4(axis_vector);
LLVector4 screen_center = manipulator_center * transform;
screen_center /= screen_center.mV[VW];
@ -180,14 +168,12 @@ BOOL QToolAlign::findSelectedManipulator(S32 x, S32 y)
mHighlightedDirection = direction;
return TRUE;
}
}
}
return FALSE;
}
BOOL QToolAlign::handleHover(S32 x, S32 y, MASK mask)
{
if(!AlignThread::sInstance)
@ -206,8 +192,6 @@ BOOL QToolAlign::handleHover(S32 x, S32 y, MASK mask)
return findSelectedManipulator(x, y);
}
void setup_transforms_bbox(LLBBox bbox)
{
// translate to center
@ -219,14 +203,13 @@ void setup_transforms_bbox(LLBBox bbox)
F32 angle_radians, x, y, z;
rotation.getAngleAxis(&angle_radians, &x, &y, &z);
gGL.flush();
gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
gGL.rotatef(angle_radians * RAD_TO_DEG, x, y, z);
// scale
LLVector3 scale = bbox.getMaxLocal() - bbox.getMinLocal();
gGL.scalef(scale.mV[VX], scale.mV[VY], scale.mV[VZ]);
}
void render_bbox(LLBBox bbox)
{
gGL.matrixMode(LLRender::MM_MODELVIEW);
@ -253,8 +236,6 @@ void render_cone_bbox(LLBBox bbox)
gGL.popMatrix();
}
// the selection bbox isn't axis aligned, so we must construct one
// should this be cached in the selection manager? yes.
LLBBox get_selection_axis_aligned_bbox()
@ -285,8 +266,6 @@ LLBBox get_selection_axis_aligned_bbox()
return axis_aligned_bbox;
}
void QToolAlign::computeManipulatorSize()
{
if (LLSelectMgr::getInstance()->getSelection()->getSelectType() == SELECT_TYPE_HUD)
@ -298,7 +277,7 @@ void QToolAlign::computeManipulatorSize()
{
F32 distance = dist_vec(gAgentCamera.getCameraPositionAgent(), mBBox.getCenterAgent());
if (distance > 0.001f)
if (distance > FUDGE)
{
// range != zero
F32 fraction_of_fov = MANIPULATOR_SIZE /LLViewerCamera::getInstance()->getViewHeightInPixels();
@ -326,15 +305,16 @@ void QToolAlign::renderManipulators()
LLVector3 bbox_scale = mBBox.getMaxLocal() - mBBox.getMinLocal();
for (S32 axis = VX; axis <= VZ; axis++)
for (F32 direction = -1.0; direction <= 1.0; direction += 2.0)
{
for (F32 direction = -1.0f; direction <= 1.0f; direction += 2.0f)
{
F32 size = mManipulatorSize;
LLColor4 color = manipulator_color[axis];
if ((axis == mHighlightedAxis) && (direction == mHighlightedDirection))
{
size *= 1.25;
color *= 1.5;
size *= 1.25f;
color *= 1.5f;
}
S32 arrows = 1;
@ -345,26 +325,27 @@ void QToolAlign::renderManipulators()
for (S32 i = 0; i < arrows; i++)
{
LLVector3 axis_vector = LLVector3(0,0,0);
axis_vector.mV[axis] = direction * (bbox_scale.mV[axis] / 2.0 + i * (size/3.0));
LLVector3 manipulator_center = bbox_center + axis_vector;
LLVector3 axis_vector = LLVector3(0.f, 0.f, 0.f);
axis_vector.mV[axis] = direction * (bbox_scale.mV[axis] / 2.0f + i * (size / 3.0f));
LLVector3 manipulator_center = bbox_center + axis_vector;
LLQuaternion manipulator_rotation;
manipulator_rotation.shortestArc(LLVector3(0,0,1), -1.0 * axis_vector);
LLBBox manipulator_bbox = LLBBox(manipulator_center, manipulator_rotation,
LLVector3(), LLVector3());
manipulator_rotation.shortestArc(LLVector3(0.f, 0.f, 1.f), -1.0f * axis_vector);
LLBBox manipulator_bbox = LLBBox(manipulator_center, manipulator_rotation,
LLVector3(), LLVector3());
manipulator_bbox.addPointLocal(LLVector3(-1.f, -1.f, -0.75f) * size * 0.5f);
manipulator_bbox.addPointLocal(LLVector3(1.f, 1.f, 0.75f) * size * 0.5f);
manipulator_bbox.addPointLocal(LLVector3(-1, -1, -0.75) * size * 0.5);
manipulator_bbox.addPointLocal(LLVector3(1, 1, 0.75) * size * 0.5);
gGL.color4fv(color.mV);
gGL.color4fv(color.mV);
render_cone_bbox(manipulator_bbox);
}
}
}
}
BOOL QToolAlign::canAffectSelection()
@ -411,19 +392,15 @@ void QToolAlign::render()
// only works for our specialized (AABB, position centered) bboxes
BOOL bbox_overlap(LLBBox bbox1, LLBBox bbox2)
{
const F32 FUDGE = 0.001f; // because of SL precision/rounding
LLVector3 delta = bbox1.getCenterAgent() - bbox2.getCenterAgent();
LLVector3 half_extent = (bbox1.getExtentLocal() + bbox2.getExtentLocal()) / 2.0;
LLVector3 half_extent = (bbox1.getExtentLocal() + bbox2.getExtentLocal()) / 2.0f;
return ((fabs(delta.mV[VX]) < half_extent.mV[VX] - FUDGE) &&
(fabs(delta.mV[VY]) < half_extent.mV[VY] - FUDGE) &&
(fabs(delta.mV[VZ]) < half_extent.mV[VZ] - FUDGE));
}
// used to sort bboxes before packing
class BBoxCompare
{
@ -434,10 +411,10 @@ public:
BOOL operator() (LLViewerObject* object1, LLViewerObject* object2)
{
LLVector3 corner1 = mBBoxes[object1].getCenterAgent() -
mDirection * mBBoxes[object1].getExtentLocal()/2.0;
mDirection * mBBoxes[object1].getExtentLocal() / 2.0f;
LLVector3 corner2 = mBBoxes[object2].getCenterAgent() -
mDirection * mBBoxes[object2].getExtentLocal()/2.0;
mDirection * mBBoxes[object2].getExtentLocal() / 2.0f;
return mDirection * corner1.mV[mAxis] < mDirection * corner2.mV[mAxis];
@ -448,7 +425,6 @@ public:
std::map<LLPointer<LLViewerObject>, LLBBox >& mBBoxes;
};
void QToolAlign::align()
{
if(AlignThread::sInstance)
@ -494,12 +470,10 @@ void QToolAlign::aligndone()
AlignThread::AlignThread() : LLThread("Align tool thread")
{
}
AlignThread::~AlignThread()
{
}
void AlignThread::run()
@ -510,7 +484,7 @@ void AlignThread::run()
std::vector<LLPointer<LLViewerObject> > objects;
std::map<LLPointer<LLViewerObject>, LLBBox > original_bboxes;
// cycle over the nodes in selection and collect them into an array
// cycle over the nodes in selection and collect them into an array
for (LLObjectSelection::root_iterator selection_iter = LLSelectMgr::getInstance()->getSelection()->root_begin();
selection_iter != LLSelectMgr::getInstance()->getSelection()->root_end();
++selection_iter)
@ -530,11 +504,11 @@ void AlignThread::run()
bbox.addBBoxAgent(object->getBoundingBoxAgent());
LLViewerObject::const_child_list_t& children = object->getChildren();
for (LLViewerObject::const_child_list_t::const_iterator i = children.begin();
i != children.end(); i++)
for (LLViewerObject::const_child_list_t::const_iterator it = children.begin();
it != children.end(); it++)
{
// add the child's bbox
LLViewerObject* child = *i;
LLViewerObject* child = *it;
bbox.addBBoxAgent(child->getBoundingBoxAgent());
}
@ -555,35 +529,35 @@ void AlignThread::run()
std::map<LLPointer<LLViewerObject>, LLBBox > new_bboxes = original_bboxes;
// find new positions
for (U32 i = 0; i < objects.size(); i++)
for (size_t i = 0; i < objects.size(); i++)
{
LLBBox target_bbox = QToolAlign::getInstance()->mBBox;
LLVector3 target_corner = target_bbox.getCenterAgent() -
direction * target_bbox.getExtentLocal() / 2.0;
direction * target_bbox.getExtentLocal() / 2.0f;
LLViewerObject* object = objects[i];
LLBBox this_bbox = original_bboxes[object];
LLVector3 this_corner = this_bbox.getCenterAgent() -
direction * this_bbox.getExtentLocal() / 2.0;
direction * this_bbox.getExtentLocal() / 2.0f;
// for packing, we cycle over several possible positions, taking the smallest that does not overlap
F32 smallest = direction * 9999999; // 999999 guarenteed not to be the smallest
for (U32 j = 0; j <= i; j++)
F32 smallest = direction * 9999999.f; // 999999 guarenteed not to be the smallest
for (size_t j = 0; j <= i; j++)
{
// how far must it move?
LLVector3 delta = target_corner - this_corner;
// new position moves only on one axis, please
LLVector3 delta_one_axis = LLVector3(0,0,0);
LLVector3 delta_one_axis = LLVector3(0.f, 0.f, 0.f);
delta_one_axis.mV[axis] = delta.mV[axis];
LLVector3 new_position = this_bbox.getCenterAgent() + delta_one_axis;
// construct the new bbox
LLBBox new_bbox = LLBBox(new_position, LLQuaternion(), LLVector3(), LLVector3());
new_bbox.addPointLocal(this_bbox.getExtentLocal() / 2.0);
new_bbox.addPointLocal(-1.0 * this_bbox.getExtentLocal() / 2.0);
new_bbox.addPointLocal(this_bbox.getExtentLocal() / 2.0f);
new_bbox.addPointLocal(-1.0f * this_bbox.getExtentLocal() / 2.0f);
// check to see if it overlaps the previously placed objects
BOOL overlap = FALSE;
@ -595,7 +569,7 @@ void AlignThread::run()
if (!QToolAlign::getInstance()->mForce) // well, don't check if in force mode
{
for (U32 k = 0; k < i; k++)
for (size_t k = 0; k < i; k++)
{
LLViewerObject* other_object = objects[k];
LLBBox other_bbox = new_bboxes[other_object];
@ -615,7 +589,7 @@ void AlignThread::run()
if (!overlap)
{
F32 this_value = (new_bbox.getCenterAgent() -
direction * new_bbox.getExtentLocal() / 2.0).mV[axis];
direction * new_bbox.getExtentLocal() / 2.0f).mV[axis];
if (direction * this_value < direction * smallest)
{
@ -630,14 +604,13 @@ void AlignThread::run()
{
LLBBox next_bbox = new_bboxes[objects[j]];
target_corner = next_bbox.getCenterAgent() +
direction * next_bbox.getExtentLocal() / 2.0;
direction * next_bbox.getExtentLocal() / 2.0f;
}
}
}
// now move them
for (U32 i = 0; i < objects.size(); i++)
for (size_t i = 0; i < objects.size(); i++)
{
LLViewerObject* object = objects[i];
@ -652,7 +625,6 @@ void AlignThread::run()
object->setPosition(new_position);
}
QToolAlign::getInstance()->aligndone();
}

View File

@ -7,9 +7,8 @@
#define Q_QTOOLALIGN_H
#include "lltool.h"
#include "llbbox.h"
#include "llthread.h"
#include "llbbox.h"
class LLViewerObject;
class LLPickInfo;
@ -34,24 +33,24 @@ public:
virtual void handleSelect();
virtual void handleDeselect();
virtual BOOL handleMouseDown(S32 x, S32 y, MASK mask);
virtual BOOL handleHover(S32 x, S32 y, MASK mask);
virtual BOOL handleHover(S32 x, S32 y, MASK mask);
virtual void render();
virtual BOOL canAffectSelection();
static void pickCallback(const LLPickInfo& pick_info);
static void aligndone();
static void pickCallback(const LLPickInfo& pick_info);
static void aligndone();
LLBBox mBBox;
F32 mManipulatorSize;
S32 mHighlightedAxis;
F32 mHighlightedDirection;
BOOL mForce;
LLBBox mBBox;
F32 mManipulatorSize;
S32 mHighlightedAxis;
F32 mHighlightedDirection;
BOOL mForce;
private:
void align();
void computeManipulatorSize();
void renderManipulators();
BOOL findSelectedManipulator(S32 x, S32 y);
void align();
void computeManipulatorSize();
void renderManipulators();
BOOL findSelectedManipulator(S32 x, S32 y);
};
#endif // Q_QTOOLALIGN_H