A little Vector Type Math

Problems with Canvas, OpenGL, etc...

A little Vector Type Math

Postby multiplydivide » Tue Jan 04, 2011 11:15 pm

Heres the lowdown:

I want an arrow to point from where the user touches down on the screen to where they lift off and I want it to update as they move there finger across the screen

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.                 m = new Matrix();
  3.                 float postScaleY = (float)(targetArrowSize/arrowHeight);
  4.                 //arrowHeight is the height of the image targetArrow size is the wanted size
  6.                 m.postScale(1,postScaleY);
  8.                 // fromLocation is the touch down and targetArrowLocation is the up or move point
  9.                 double x = (targetArrowLocation.x - fromLocation.x);
  10.                 double y = (targetArrowLocation.y - fromLocation.y);
  12.                 double theta = Math.acos( y /Math.sqrt( Math.pow(x, 2) +Math.pow(y, 2) ) );
  14.                 m.postRotate( (float) Math.toDegrees(theta) );
  16.                 m.postTranslate(fromLocation.x - offsetX, fromLocation.y - offsetY);
  18.                 invalidate();
Parsed in 0.011 seconds, using GeSHi

This works if the fromLocation.x is to the right of the targetArrowLocation but if this isnt the case it draws the arrow pointing to the corresponding point on the opposite side of the screen... so the arrow always points left..
I think that if I could do a reflection across the y-axis it would work, so if anyone can tell me how to do that I can try it... but there must be a way to get the math right... Any Ideas?

without any matrix being applied the arrow points down into the positive Y
Posts: 34
Joined: Wed Apr 28, 2010 2:09 am


Return to Android 2D/3D Graphics - OpenGL Problems

Who is online

Users browsing this forum: No registered users and 1 guest