Krita Source Code Documentation
Loading...
Searching...
No Matches
KisTangentTiltOption.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2015 Wolthera van Hövell tot Westerflier <griffinvalley@gmail.com>
3 *
4 * SPDX-License-Identifier: LGPL-2.0-or-later
5 */
7
10
11
16
18 : m_redChannel(data.redChannel)
19 , m_greenChannel(data.greenChannel)
20 , m_blueChannel(data.blueChannel)
21 , m_directionType(data.directionType)
22 , m_elevationSensitivity(data.elevationSensitivity)
23 , m_mixValue(data.mixValue)
24{
25}
26
27void KisTangentTiltOption::swizzleAssign(qreal const horizontal, qreal const vertical, qreal const depth, qreal *component, int index, qreal maxvalue)
28{
29 switch(index) {
30 case 0: *component = horizontal; break;
31 case 1: *component = maxvalue-horizontal; break;
32 case 2: *component = vertical; break;
33 case 3: *component = maxvalue-vertical; break;
34 case 4: *component = depth; break;
35 case 5: *component = maxvalue-depth; break;
36 }
37}
38
39void KisTangentTiltOption::apply(const KisPaintInformation& info,qreal *r,qreal *g,qreal *b)
40{
41 //formula based on https://www.cerebralmeltdown.com/programming_projects/Altitude%20and%20Azimuth%20to%20Vector/index.html
42
43 /* It doesn't make sense of have higher than 8bit color depth.
44 * Instead we make sure in the paintAt function of kis_tangent_normal_paintop to pick an 8bit space of the current
45 * color space if the space is an RGB space. If not, it'll pick sRGB 8bit.
46 */
47 qreal halfvalue = 0.5;
48 qreal maxvalue = 1.0;
49
50 //have the azimuth and altitude in degrees.
51 qreal direction = KisPaintInformation::tiltDirection(info, true)*360.0;
52 qreal elevation= (info.tiltElevation(info, 60.0, 60.0, true)*90.0);
53
55 direction = KisPaintInformation::tiltDirection(info, true)*360.0;
56 elevation= (info.tiltElevation(info, 60.0, 60.0, true)*90.0);
58 direction = (0.75 + info.drawingAngle() / (2.0 * M_PI))*360.0;
59 elevation= 0;//turns out that tablets that don't support tilt just return 90 degrees for elevation.
61 direction = info.rotation();
62 elevation= (info.tiltElevation(info, 60.0, 60.0, true)*90.0);//artpens have tilt-recognition, so this should work.
63 } else if (m_directionType == TangentTiltDirectionType::Mix) {//mix of tilt+direction
64 qreal mixamount = m_mixValue/100.0;
65 direction = (KisPaintInformation::tiltDirection(info, true)*360.0*(1.0-mixamount))+((0.75 + info.drawingAngle() / (2.0 * M_PI))*360.0*(mixamount));
66 elevation= (info.tiltElevation(info, 60.0, 60.0, true)*90.0);
67 }
68
69 //subtract/add the rotation of the canvas.
71 direction = normalizeAngleDegrees(direction - info.canvasRotation());
72 }
73
74 //limit the direction/elevation
75
76 //qreal elevationMax = (m_elevationSensitivity*90.0)/100.0;
77 qreal elevationT = elevation*(m_elevationSensitivity/100.0)+(90-(m_elevationSensitivity*90.0)/100.0);
78 elevation = static_cast<int>(elevationT);
79
80 //convert to radians.
81 // Convert this to kis_global's radian function.
82 direction = kisDegreesToRadians(direction);
83 elevation = kisDegreesToRadians(elevation);
84
85 //make variables for axes for easy switching later on.
86 qreal horizontal, vertical, depth;
87
88 //spherical coordinates always center themselves around the origin, leading to values. We need to work around those...
89
90 horizontal = cos(elevation)*sin(direction);
91 if (horizontal>0.0) {
92 horizontal= halfvalue+(fabs(horizontal)*halfvalue);
93 }
94 else {
95 horizontal= halfvalue-(fabs(horizontal)*halfvalue);
96 }
97 vertical = cos(elevation)*cos(direction);
98 if (vertical>0.0) {
99 vertical = halfvalue+(fabs(vertical)*halfvalue);
100 }
101 else {
102 vertical = halfvalue-(fabs(vertical)*halfvalue);
103 }
104
105 if (info.canvasMirroredH()) {horizontal = maxvalue - horizontal;}
106 if (info.canvasMirroredV()) {vertical = maxvalue - vertical;}
107
108 depth = sin(elevation)*maxvalue;
109
110 //assign right components to correct axes.
111 swizzleAssign(horizontal, vertical, depth, r, m_redChannel, maxvalue);
112 swizzleAssign(horizontal, vertical, depth, g, m_greenChannel, maxvalue);
113 swizzleAssign(horizontal, vertical, depth, b, m_blueChannel, maxvalue);
114}
static qreal tiltDirection(const KisPaintInformation &info, bool normalize=true)
static qreal tiltElevation(const KisPaintInformation &info, qreal maxTiltX=60.0, qreal maxTiltY=60.0, bool normalize=true)
qreal rotation() const
rotation as given by the tablet event
qreal drawingAngle(bool considerLockedAngle=false) const
void swizzleAssign(qreal const horizontal, qreal const vertical, qreal const depth, qreal *component, int index, qreal maxvalue)
KisTangentTiltOption(const KisPropertiesConfiguration *setting)
TangentTiltDirectionType m_directionType
void apply(const KisPaintInformation &info, qreal *r, qreal *g, qreal *b)
std::enable_if< std::is_floating_point< T >::value, T >::type normalizeAngleDegrees(T a)
Definition kis_global.h:132
T kisDegreesToRadians(T degrees)
Definition kis_global.h:176
#define M_PI
Definition kis_global.h:111