Huhu,
ich versuche, wie der Titel schon sagt, die zurueckgelegte Strecke der Maus zu errechnen.
Das mache ich folgendermasen:
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27:
| Die Variablen private Cursor meinCursor; private int xPosDeltaAktuell; private int yPosDeltaAktuell; private int xPosDeltaAlt; private int yPosDeltaAlt; private double km_ergebnis; private double dpi = 96.0; private double cm = 2.54; |
Konstructor
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9:
| public Form1() { InitializeComponent();
this.meinCursor = Cursors.Cross; Cursor.Show(); xPosDeltaAlt = Cursor.Position.X; yPosDeltaAlt = Cursor.Position.Y; } |
Timer:
C#-Quelltext
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18:
| private void timIntervall_Tick(object sender, EventArgs e) { this.xPosDeltaAktuell = Cursor.Position.X; this.yPosDeltaAktuell = Cursor.Position.Y;
int xPosDelta = Math.Abs(xPosDeltaAktuell - xPosDeltaAlt); int yPosDelta = Math.Abs(yPosDeltaAktuell - yPosDeltaAlt);
km_ergebnis += (xPosDelta + yPosDelta); km_ergebnis /= dpi; km_ergebnis *= cm;
this.xPosDeltaAlt = this.xPosDeltaAktuell; this.yPosDeltaAlt = this.yPosDeltaAktuell;
} |
Der erste Wert ist korrekt und liefert die Pixel aus.
km_ergebnis += (xPosDelta + yPosDelta);
Der 2te und 3te Wert allerdings stimmt dann i-wie nicht ....aber warum?
Theoretisch muesste die Rechnung so stimmen.
Oder lieg ich da falsch?
Als Ergebnis bekomme ich eine 0,0000231238120938 Zahl raus, anstatt (bei 14000 Pixeln) ~ 360,....cm..
Bitte um Hilfe/Rat...danke.
EDIT: geloest: es lag daran, das ich im timer weiter gerechnet hatte,...
C#-Quelltext
1: 2:
| km_ergebnis /= dpi; km_ergebnis *= cm; |
Das darf sich nicht im timer befinden.