Bug 250978 - Stylus X/Y Tilt sensors are broken
Summary: Stylus X/Y Tilt sensors are broken
Status: RESOLVED FIXED
Alias: None
Product: krita
Classification: Applications
Component: Brush engines (show other bugs)
Version: git master (please specify the git hash!)
Platform: Compiled Sources Linux
: NOR normal
Target Milestone: ---
Assignee: LukasT
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2010-09-12 15:10 UTC by animtim
Modified: 2011-01-08 16:22 UTC (History)
0 users

See Also:
Latest Commit:
Version Fixed In:


Attachments
Rotation with Xtilt (92.82 KB, image/png)
2010-10-18 12:29 UTC, animtim
Details
rotation with Y tilt (92.95 KB, image/png)
2010-10-18 12:30 UTC, animtim
Details
rotation how it should be (95.69 KB, image/png)
2010-10-18 12:30 UTC, animtim
Details

Note You need to log in before you can comment on or make changes to this bug.
Description animtim 2010-09-12 15:10:15 UTC
Version:           svn trunk (using KDE 4.4.2) 
OS:                Linux

Try to set the Rotation setting on with rotation sensor : it doesn't work anymore.
(while using another sensor like drawing angle works).

Reproducible: Always
Comment 1 LukasT 2010-10-18 10:42:56 UTC
Rotation comes from the special pen like Art pen. Do you have it?
I tested it and it worked for me fine.
Comment 2 animtim 2010-10-18 12:29:02 UTC
True I don't have an Art pen, Sorry, what I'm talking about here is the "rotation" parameter in Intuos3 stylus with the "Tilt" parameters (not available in Graphire/Bamboo series) It is available in Mypaint (git version) as "Ascension" parameter, and in Gimp 2.6 in the Ink tool the "inclinaison" parameter.

These parameters let rotate the tip shape depending on the stylus angle.

So I've tried to use the "Tilt X" and "Tilt Y" sensors on Rotation parameter but they doesn't work as they should.

Here is some screenshot of how it works now and how it should work:
Comment 3 animtim 2010-10-18 12:29:44 UTC
Created attachment 52644 [details]
Rotation with Xtilt
Comment 4 animtim 2010-10-18 12:30:13 UTC
Created attachment 52645 [details]
rotation with Y tilt
Comment 5 animtim 2010-10-18 12:30:52 UTC
Created attachment 52646 [details]
rotation how it should be
Comment 6 LukasT 2010-10-18 12:39:09 UTC
Cool attachments, now I understand.
Comment 7 LukasT 2011-01-08 16:22:07 UTC
commit 7fafc0e50ee8f82be2e66d05d595c081a592bbef
branch master
Author: Lukáš Tvrdý <lukast.dev@gmail.com>
Date:   Sat Jan 8 16:17:54 2011 +0100

    Add new sensors: ascension and declination
    
    Better tilt support. Ascension is very usable with rotation of the brush.
    Declination is very nice with connection to the size of the brush.
    
    BUG:250978

diff --git a/krita/plugins/paintops/libpaintop/kis_dynamic_sensor.cc b/krita/plugins/paintops/libpaintop/kis_dynamic_sensor.cc
index 0a7da23..51c1d22 100644
--- a/krita/plugins/paintops/libpaintop/kis_dynamic_sensor.cc
+++ b/krita/plugins/paintops/libpaintop/kis_dynamic_sensor.cc
@@ -1,6 +1,7 @@
 /*
  *  Copyright (c) 2007 Cyrille Berger <cberger@cberger.net>
- *
+ *  Copyright (c) 2011 Lukáš Tvrdý <lukast.dev@gmail.com>
+ * 
  *  This program 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 of the License.
@@ -49,6 +50,10 @@ KisDynamicSensor* KisDynamicSensor::id2Sensor(const KoID& id)
         return new KisDynamicSensorXTilt();
     } else if (id.id() == YTiltId.id()) {
         return new KisDynamicSensorYTilt();
+    } else if (id.id() == AscensionId.id()) {
+        return new KisDynamicSensorAscension();
+    } else if (id.id() == DeclinationId.id()) {
+        return new KisDynamicSensorDeclination();
     } else if (id.id() == SpeedId.id()) {
         return new KisDynamicSensorSpeed();
     } else if (id.id() == DrawingAngleId.id()) {
@@ -93,7 +98,7 @@ KisDynamicSensor* KisDynamicSensor::createFromXML(const QDomElement& e)
 QList<KoID> KisDynamicSensor::sensorsIds()
 {
     QList<KoID> ids;
-    ids << PressureId << XTiltId << YTiltId << SpeedId << DrawingAngleId << RotationId << DistanceId << TimeId << FuzzyId << FadeId << PerspectiveId;
+    ids << PressureId << XTiltId << YTiltId << AscensionId << DeclinationId << SpeedId << DrawingAngleId << RotationId << DistanceId << TimeId << FuzzyId << FadeId << PerspectiveId;
     return ids;
 }
 
diff --git a/krita/plugins/paintops/libpaintop/kis_dynamic_sensor.h b/krita/plugins/paintops/libpaintop/kis_dynamic_sensor.h
index e55b6e1..4938db3 100644
--- a/krita/plugins/paintops/libpaintop/kis_dynamic_sensor.h
+++ b/krita/plugins/paintops/libpaintop/kis_dynamic_sensor.h
@@ -1,6 +1,7 @@
 /*
  *  Copyright (c) 2006 Cyrille Berger <cberger@cberger.net>
- *
+ *  Copyright (c) 2011 Lukáš Tvrdý <lukast.dev@gmail.com>
+ * 
  *  This program 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 of the License.
@@ -43,6 +44,8 @@ const KoID RotationId("rotation", ki18n("Rotation")); ///< rotation coming from
 const KoID PressureId("pressure", ki18n("Pressure")); ///< number depending on the pressure
 const KoID XTiltId("xtilt", ki18n("X-Tilt")); ///< number depending on X-tilt
 const KoID YTiltId("ytilt", ki18n("Y-Tilt")); ///< number depending on Y-tilt
+const KoID AscensionId("ascension", ki18n("Ascension")); /// < number depending on the X and Y tilt, ascension is 0 when stylus nib points to you and changes clockwise from -180 to +180.
+const KoID DeclinationId("declination", ki18n("Declination")); /// < declination is 90 when stylus is perpendicular to tablet and 0 when it's parallel to tablet
 const KoID PerspectiveId("perspective", ki18n("Perspective")); ///< number depending on the distance on the perspective grid
 
 /**
diff --git a/krita/plugins/paintops/libpaintop/sensors/kis_dynamic_sensors.cc b/krita/plugins/paintops/libpaintop/sensors/kis_dynamic_sensors.cc
index 857c903..980fb17 100644
--- a/krita/plugins/paintops/libpaintop/sensors/kis_dynamic_sensors.cc
+++ b/krita/plugins/paintops/libpaintop/sensors/kis_dynamic_sensors.cc
@@ -1,5 +1,6 @@
 /*
  *  Copyright (c) 2007,2010 Cyrille Berger <cberger@cberger.net>
+ *  Copyright (c) 2011 Lukáš Tvrdý <lukast.dev@gmail.com>
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU Lesser General Public License as published by
@@ -72,6 +73,19 @@ KisDynamicSensorYTilt::KisDynamicSensorYTilt() : KisDynamicSensor(YTiltId)
     setMaximumLabel(i18n("30°"));
 }
 
+KisDynamicSensorAscension::KisDynamicSensorAscension() : KisDynamicSensor(AscensionId)
+{
+    setMinimumLabel(i18n("0°"));
+    setMaximumLabel(i18n("360°"));
+}
+
+KisDynamicSensorDeclination::KisDynamicSensorDeclination() : KisDynamicSensor(DeclinationId)
+{
+    setMinimumLabel(i18n("90°"));
+    setMaximumLabel(i18n("0°"));
+}
+
+
 KisDynamicSensorPerspective::KisDynamicSensorPerspective() : KisDynamicSensor(PerspectiveId)
 {
     setMinimumLabel(i18n("Far"));
diff --git a/krita/plugins/paintops/libpaintop/sensors/kis_dynamic_sensors.h b/krita/plugins/paintops/libpaintop/sensors/kis_dynamic_sensors.h
index 5eba10c..66fce1e 100644
--- a/krita/plugins/paintops/libpaintop/sensors/kis_dynamic_sensors.h
+++ b/krita/plugins/paintops/libpaintop/sensors/kis_dynamic_sensors.h
@@ -1,6 +1,7 @@
 /*
  *  Copyright (c) 2006-2007,2010 Cyrille Berger <cberger@cberger.net>
- *
+ *  Copyright (c) 2011 Lukáš Tvrdý <lukast.dev@gmail.com>
+ * 
  *  This program 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 of the License.
@@ -100,6 +101,45 @@ public:
     }
 };
 
+class KisDynamicSensorAscension : public KisDynamicSensor
+{
+public:
+    KisDynamicSensorAscension();
+    virtual ~KisDynamicSensorAscension() {}
+    virtual qreal parameter(const KisPaintInformation& info){
+        qreal xTilt = info.xTilt();
+        qreal yTilt = info.yTilt();
+        // radians -PI, PI
+        qreal ascension = atan2(-xTilt, yTilt);
+        // map to 0.0..1.0
+        ascension = ascension / (2 * M_PI) + 0.5;
+        return ascension;
+    }
+};
+
+class KisDynamicSensorDeclination : public KisDynamicSensor
+{
+public:
+    KisDynamicSensorDeclination();
+    virtual ~KisDynamicSensorDeclination() {}
+    virtual qreal parameter(const KisPaintInformation& info){
+        qreal xTilt = qBound(-1.0, info.xTilt() / 60.0 , 1.0);
+        qreal yTilt = qBound(-1.0, info.yTilt() / 60.0 , 1.0);
+
+        qreal e;
+        if (fabs(xTilt) > fabs(yTilt)) {
+            e = sqrt(1.0 + yTilt*yTilt);
+        } else {
+            e = sqrt(1.0 + xTilt*xTilt);
+        }
+      
+        qreal cosAlpha = sqrt(xTilt*xTilt + yTilt*yTilt)/e;
+        // in radians in [0, 0.5 * PI] .. mapping to 0.0..1.0
+        qreal declination = acos (cosAlpha) / (M_PI * 0.5);
+        return declination;
+    }
+};
+
 class KisDynamicSensorPerspective : public KisDynamicSensor
 {
 public: