diff --git a/indra/newview/fsfloaterposer.h b/indra/newview/fsfloaterposer.h index c3ab3d6f99..3d21953b05 100644 --- a/indra/newview/fsfloaterposer.h +++ b/indra/newview/fsfloaterposer.h @@ -1,5 +1,5 @@ /** - * @file fsfloaterposer.cpp + * @file fsfloaterposer.h * @brief View Model for posing your (and other) avatar(s). * * $LicenseInfo:firstyear=2024&license=viewerlgpl$ diff --git a/indra/newview/fsmaniprotatejoint.cpp b/indra/newview/fsmaniprotatejoint.cpp index f1e177912c..8e5c4466da 100644 --- a/indra/newview/fsmaniprotatejoint.cpp +++ b/indra/newview/fsmaniprotatejoint.cpp @@ -43,18 +43,17 @@ #include "lljoint.h" #include "llagent.h" // for gAgent, etc. #include "llagentcamera.h" +#include "llappviewer.h" #include "llcontrol.h" +#include "llfloaterreg.h" #include "llresmgr.h" // for LLLocale #include "llviewerwindow.h" #include "llviewercamera.h" +#include "llviewercontrol.h" #include "llviewershadermgr.h" -#include "llfloaterreg.h" #include "fsfloaterposer.h" // ------------------------------------- -extern U64MicrosecondsImplicit gFrameTime; -extern LLControlGroup gSavedSettings; - /** * @brief Renders a pulsing sphere at a specified joint position in the world. @@ -69,7 +68,7 @@ extern LLControlGroup gSavedSettings; * @return void * */ -void renderPulsingSphere(const LLVector3& joint_world_position, const LLColor4& color=LLColor4(1.f, 1.f, 1.f, 1.f)) +static void renderPulsingSphere(const LLVector3& joint_world_position, const LLColor4& color = LLColor4(1.f, 1.f, 1.f, 1.f)) { constexpr float MAX_SPHERE_RADIUS = 0.05f; // Base radius in agent-space units. constexpr float PULSE_AMPLITUDE = 0.01f; // Additional radius variation. @@ -79,7 +78,7 @@ void renderPulsingSphere(const LLVector3& joint_world_position, const LLColor4& // Get the current time (in seconds) from the global timer. const U64 timeMicrosec = gFrameTime; // Convert microseconds to seconds - const F64 timeSec = std::fmod( static_cast(timeMicrosec) / 1000000.0, PULSE_TIME_DOMAIN ); + const F64 timeSec = std::fmod(static_cast(timeMicrosec) / 1000000.0, PULSE_TIME_DOMAIN); // Compute the pulse factor using a sine wave. This value oscillates between 0 and 1. float pulseFactor = 0.75f + 0.25f * std::sin(PULSE_FREQUENCY * 2.f * F_PI * static_cast(timeSec)); @@ -131,7 +130,7 @@ void renderPulsingSphere(const LLVector3& joint_world_position, const LLColor4& } -bool isMouseOverJoint(S32 mouseX, S32 mouseY, const LLVector3& jointWorldPos, F32 jointRadius, F32& outDistanceFromCamera) +static bool isMouseOverJoint(S32 mouseX, S32 mouseY, const LLVector3& jointWorldPos, F32 jointRadius, F32& outDistanceFromCamera) { LLViewerCamera* camera = LLViewerCamera::getInstance(); @@ -201,7 +200,7 @@ const std::unordered_mapgetJoint(std::string(entry)); - if (!joint) continue; + if (!joint) + continue; // Update the joint's world matrix to ensure its position is current. joint->updateWorldMatrixParent(); @@ -386,7 +386,7 @@ bool FSManipRotateJoint::updateVisiblity() const auto * viewer_camera = LLViewerCamera::getInstance(); visible = viewer_camera->projectPosAgentToScreen(agent_space_center, mCenterScreen ); - if( visible ) + if (visible) { mCenterToCam = gAgentCamera.getCameraPositionAgent() - agent_space_center; mCenterToCamNorm = mCenterToCam; @@ -415,7 +415,7 @@ bool FSManipRotateJoint::updateVisiblity() mCamEdgeOn = false; F32 axis_onto_cam = mManipPart >= LL_ROT_X ? llabs( getConstraintAxis() * mCenterToCamNorm ) : 0.f; - if( axis_onto_cam < AXIS_ONTO_CAM_TOLERANCE ) + if (axis_onto_cam < AXIS_ONTO_CAM_TOLERANCE) { mCamEdgeOn = true; } @@ -500,12 +500,12 @@ void FSManipRotateJoint::renderManipulatorRings(const LLVector3& agent_space_cen LLMatrix4 rot_mat(rotation); gGL.multMatrix((GLfloat*)rot_mat.mMatrix); - for ( int pass = 0; pass < 2; ++pass) + for (int pass = 0; pass < 2; ++pass) { if( mManipPart == LL_NO_PART || mManipPart == LL_ROT_ROLL || mHighlightedPart == LL_ROT_ROLL) { renderCenterSphere( mRadiusMeters); - for (auto & ring_params : sRingParams) + for (auto& ring_params : sRingParams) { const auto part = ring_params.first; const auto& params = ring_params.second; @@ -545,14 +545,14 @@ void FSManipRotateJoint::renderManipulatorRings(const LLVector3& agent_space_cen gUIProgram.bind(); } -void FSManipRotateJoint::renderCenterCircle(const F32 radius, const LLColor4 normal_color, const LLColor4 highlight_color) +void FSManipRotateJoint::renderCenterCircle(const F32 radius, const LLColor4& normal_color, const LLColor4& highlight_color) { gGL.pushMatrix(); { LLGLEnable cull_face(GL_CULL_FACE); LLGLDepthTest gls_depth(GL_FALSE); - const int segments = 64; + constexpr int segments = 64; glLineWidth(6.0f); // Set the desired line thickness // Compute a scale factor that already factors in the radius. @@ -573,7 +573,7 @@ void FSManipRotateJoint::renderCenterCircle(const F32 radius, const LLColor4 nor if (rotationAxis.magVec() > 0.001f) { - gGL.rotatef(angle, rotationAxis.mV[0], rotationAxis.mV[1], rotationAxis.mV[2]); + gGL.rotatef(angle, rotationAxis.mV[VX], rotationAxis.mV[VY], rotationAxis.mV[VZ]); } // Draw a unit circle in the XY plane (which is now rotated correctly). @@ -592,14 +592,14 @@ void FSManipRotateJoint::renderCenterCircle(const F32 radius, const LLColor4 nor gGL.popMatrix(); } -void FSManipRotateJoint::renderCenterSphere(const F32 radius, const LLColor4 normal_color, const LLColor4 highlight_color) +void FSManipRotateJoint::renderCenterSphere(const F32 radius, const LLColor4& normal_color, const LLColor4& highlight_color) { gGL.pushMatrix(); { LLGLEnable cull_face(GL_CULL_FACE); LLGLDepthTest gls_depth(GL_FALSE); - float scale = radius*0.8f; + float scale = radius * 0.8f; if (mManipPart == LL_ROT_GENERAL || mHighlightedPart == LL_ROT_GENERAL) { @@ -690,8 +690,6 @@ void FSManipRotateJoint::render() const LLVector3 agent_space_center = gAgent.getPosAgentFromGlobal(mRotationCenter); - - LLCachedControl use_natural_direction(gSavedSettings, "FSManipRotateJointUseNaturalDirection", true); LLQuaternion active_rotation = use_natural_direction? final_world_alignment : joint_world_rotation; // Render the manipulator rings in a separate function. @@ -808,7 +806,7 @@ std::string FSManipRotateJoint::getManipPartString(EManipPart part) */ void FSManipRotateJoint::renderNameXYZ(const LLVector3 &vec) { - const S32 PAD = 10; + constexpr S32 PAD = 10; S32 window_center_x = gViewerWindow->getWorldViewRectScaled().getWidth() / 2; S32 window_center_y = gViewerWindow->getWorldViewRectScaled().getHeight() / 2; S32 vertical_offset = window_center_y - VERTICAL_OFFSET; @@ -962,9 +960,9 @@ bool FSManipRotateJoint::handleMouseDownOnPart(S32 x, S32 y, MASK mask) { // Constrained rotation. LLVector3 axis = setConstraintAxis(); // set the axis based on the manipulator part - F32 axis_onto_cam = llabs( axis * mCenterToCamNorm ); - const F32 AXIS_ONTO_CAM_TOL = cos( 85.f * DEG_TO_RAD ); - if( axis_onto_cam < AXIS_ONTO_CAM_TOL ) + F32 axis_onto_cam = llabs(axis * mCenterToCamNorm); + const F32 AXIS_ONTO_CAM_TOL = cos(85.f * DEG_TO_RAD); + if (axis_onto_cam < AXIS_ONTO_CAM_TOL) { LLVector3 up_from_axis = mCenterToCamNorm % axis; up_from_axis.normalize(); @@ -1037,7 +1035,6 @@ bool FSManipRotateJoint::handleMouseUp(S32 x, S32 y, MASK mask) } - /** * @brief Does all the hard work of working out what inworld control we are interacting with * @@ -1314,6 +1311,7 @@ LLQuaternion FSManipRotateJoint::dragConstrained(S32 x, S32 y) mLastAngle = angle; return LLQuaternion(angle, constraint_axis); } + void FSManipRotateJoint::drag(S32 x, S32 y) { if (!updateVisiblity() || !mJoint) return; @@ -1363,7 +1361,7 @@ LLVector3 FSManipRotateJoint::setConstraintAxis() if (use_natural_direction) { // Get the joint's current local rotation. - LLQuaternion currentLocalRot = mJoint->getRotation(); + LLQuaternion currentLocalRot = mJoint->getRotation(); const LLQuaternion parentWorldRot = (mJoint->getParent()) ? mJoint->getParent()->getWorldRotation() : LLQuaternion::DEFAULT; LLQuaternion rotatedNaturalAlignment = mNaturalAlignmentQuat * currentLocalRot; rotatedNaturalAlignment.normalize(); diff --git a/indra/newview/fsmaniprotatejoint.h b/indra/newview/fsmaniprotatejoint.h index 5914d1fb11..4feb5e2600 100644 --- a/indra/newview/fsmaniprotatejoint.h +++ b/indra/newview/fsmaniprotatejoint.h @@ -1,11 +1,39 @@ -// File: fsmaniprotatejoint.h +/** + * @file fsmaniproatejoint.h + * @brief custom manipulator for rotating joints + * + * $LicenseInfo:firstyear=2024&license=viewerlgpl$ + * Phoenix Firestorm Viewer Source Code + * Copyright (c) 2025 Beq Janus @ Second Life + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; + * version 2.1 of the License only. + * + * This library 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * The Phoenix Firestorm Project, Inc., 1831 Oakwood Drive, Fairmont, Minnesota 56031-3225 USA + * http://www.firestormviewer.org + * $/LicenseInfo$ + */ #ifndef FS_MANIP_ROTATE_JOINT_H #define FS_MANIP_ROTATE_JOINT_H + #include "llselectmgr.h" #include "llmaniprotate.h" + class LLJoint; class LLVOAvatar; // or LLVOAvatarSelf, etc. + namespace { const F32 AXIS_ONTO_CAM_TOLERANCE = cos( 80.f * DEG_TO_RAD ); // cos() is not constexpr til c++26 constexpr F32 RADIUS_PIXELS = 100.f; // size in screen space @@ -25,8 +53,8 @@ namespace { constexpr F32 SELECTED_MANIPULATOR_SCALE = 1.05f; constexpr F32 MANIPULATOR_SCALE_HALF_LIFE = 0.07f; constexpr S32 VERTICAL_OFFSET = 100; - } + class FSManipRotateJoint : public LLManipRotate { // Used for overriding the natural "up" direction of a joint. @@ -41,6 +69,7 @@ class FSManipRotateJoint : public LLManipRotate }; LLQuaternion computeAlignmentQuat( const BoneAxes& boneAxes ) const; BoneAxes computeBoneAxes() const; + public: FSManipRotateJoint(LLToolComposite* composite); virtual ~FSManipRotateJoint() {} @@ -59,20 +88,17 @@ public: bool handleMouseUp(S32 x, S32 y, MASK mask) override; bool handleHover(S32 x, S32 y, MASK mask) override; void drag(S32 x, S32 y) override; - bool isAlwaysRendered() override { return true; } - void highlightManipulators(S32 x, S32 y) override; + bool isAlwaysRendered() override { return true; } + void highlightManipulators(S32 x, S32 y) override; bool handleMouseDownOnPart(S32 x, S32 y, MASK mask) override; void highlightHoverSpheres(S32 mouseX, S32 mouseY); + protected: // void renderNameXYZ(const std::string name, const LLVector3 &vec); LLQuaternion dragUnconstrained( S32 x, S32 y ); LLQuaternion dragConstrained( S32 x, S32 y ); LLVector3 getConstraintAxis() const { return mConstraintAxis; }; LLVector3 setConstraintAxis(); - bool computeMouseIntersectionOnSphere(S32 x, S32 y, - const LLVector3d& sphere_center_global, - F32 sphere_radius, - LLVector3& outIntersection); // Instead of selecting an LLViewerObject, we have a single joint LLJoint* mJoint = nullptr; @@ -85,6 +111,7 @@ protected: F32 mHighlightedPartDistance = 0.f; LLVector3 mInitialIntersection; // The initial point on the manipulator’s sphere (in agent space) const std::vector getSelectableJoints(){ return sSelectableJoints; }; + private: static const std::vector sSelectableJoints; @@ -105,15 +132,13 @@ private: void renderActiveRing( F32 radius, F32 width, const LLColor4& front_color, const LLColor4& back_color); void renderManipulatorRings(const LLVector3& center, const LLQuaternion& finalAlignment); - void renderCenterCircle(const F32 radius, const LLColor4 normal_color=LLColor4(0.7f,0.7,0.7f,0.2), const LLColor4 highlight_color=LLColor4(0.8f,0.8f,0.8f,0.3)); - void renderCenterSphere(const F32 radius, const LLColor4 normal_color=LLColor4(0.7f,0.7,0.7f,0.2), const LLColor4 highlight_color=LLColor4(0.8f,0.8f,0.8f,0.3)); - void renderDetailedRings(float width_meters); + void renderCenterCircle(const F32 radius, const LLColor4& normal_color = LLColor4(0.7f,0.7,0.7f,0.2), const LLColor4& highlight_color = LLColor4(0.8f,0.8f,0.8f,0.3)); + void renderCenterSphere(const F32 radius, const LLColor4& normal_color = LLColor4(0.7f,0.7,0.7f,0.2), const LLColor4& highlight_color = LLColor4(0.8f,0.8f,0.8f,0.3)); void renderRingPass(const RingRenderParams& params, float radius, float width, int pass); void renderAxes(const LLVector3& center, F32 size, const LLQuaternion& rotation); float mLastAngle = 0.f; LLVector3 mConstraintAxis; - }; #endif // FS_MANIP_ROTATE_JOINT_H