oh.. and be aware that if you decide to use opengl, the y axis is reversed.
That is, in the standard Canvas system, 0,0 is TOP left, whereas in OpenGL 0,0 is BOTTOM left (which makes much more sense to me) On Aug 29, 5:27 pm, Jason <[email protected]> wrote: > hmmm.. it seems to me that all the trig functions (sin/cos etc) are > unnecessary. > > The screen is just a 2D grid, so the difference in position between > one point and another is always just a difference of x/y values. > > If I were you, I would just determine the difference in x and y > between your start and end positions, then move through a portion of > each with every step based on your speed. > > For example: > > If your current position is 50,50, and you want to move to 100,200 in > 1 second, then you just work out the diff, and determine how much to > move each millisecond: > > diff is 50 on the x axis (100 - 50) and 150 on the y axis (200-50) > so each millisecond, move X by 50/1000 and Y by 150/1000. > > Then if your frame takes 16ms to render (hence the move step is 16ms), > then you would be moving X by (16 x 50/1000) and Y by (16 x 150/1000) > (using floats of course.. not ints). > > The advantage here is much simpler calcs (== better performance) and > you don't care about whether your left/right/up/down because the +ve/- > ve results from the simple arithmetic will handle it. > > This assumes you are only moving in 2D of course. > > On Aug 29, 9:12 am, Jeffrey <[email protected]> wrote: > > > > > Okay, figured it out. I had some remnants from an old system still in > > there and was referencing a variable that wasn't being updated > > correctly. > > > Thank you for you help :) > > > On Aug 28, 5:47 pm, Jeffrey <[email protected]> wrote: > > > > The problem is that it is only moving the image one direction along > > > the slope of the line. I've tried making a condition that checks to > > > see if the target area is to the left of the current position, and if > > > so then make the X/Y differences negative, but that works very > > > sporadically, and make the image move in crazy ways sometime. > > > > On Aug 28, 5:33 pm, Jeffrey <[email protected]> wrote: > > > > > This almost works, but when I click on a point that has a smaller X > > > > value than it's current position it reverses the Y Direction. > > > > > On Aug 27, 1:01 pm, Robert Green <[email protected]> wrote: > > > > > > Direction will be in the range -180 to 180 so don't use abs! Always > > > > > use sin/cos for y/x respectively when in y+ down 2D coordinate > > > > > systems, otherwise x/y respectively. > > > > > > Here is kind of what you want > > > > > > // tickDelta should be something like .016f to .033f - definitely > > > > > should total 1.0f per second :) > > > > > float tickDelta = (currentMs - lastMs) / 1000f; > > > > > // now mMoveSpeed can be expressed in units-per-second and it'll work > > > > > at any framerate if you multiply by tickdelta > > > > > > float touchDelta = (float)(TouchY - V.CurY) / (TouchX - V.CurX); > > > > > float dirRads = (float)Math.atan(touchDelta); > > > > > float amountX = (float)Math.cos(dirRads) * mMoveSpeed * tickDelta; > > > > > float amountY = (float)Math.sin(dirRads) * mMoveSpeed * tickDelta; > > > > > x += amountX; > > > > > y += amountY; > > > > > > // no additional checks needed. This is how you do 2D directional > > > > > movement. > > > > > // this assumes that either TouchX/TouchY or V is set only when the > > > > > touch is touched down initially so that a vector is made when the > > > > > touch moves and that value is not updated. > > > > > > On Aug 26, 8:40 pm, Jeffrey <[email protected]> wrote: > > > > > > > I know this is more of a general programming question, but my > > > > > > Android > > > > > > friends here have always been helpful. I am trying to make an image > > > > > > move from one part of the screen to a position the user touches, as > > > > > > a > > > > > > constant speed. I don't know the best way to go about doing this and > > > > > > the way I have been trying to get to work is taxing my brain too > > > > > > much. > > > > > > > I have been using geometry to calculate slope, then using Sin * > > > > > > movement speed to calculate the difference in X,Y coordinates. > > > > > > > This is the code I'm looking at: > > > > > > > TouchX = V.TX; (This is the touch event > > > > > > coordinates > > > > > > TouchY = > > > > > > V.TY; ) > > > > > > > Slope = (TouchY - V.CurY) / (TouchX - > > > > > > V.CurX); (this figures out > > > > > > the slope of the line to the touch point) > > > > > > DegreeSlopeY = Math.atan(Slope); > > > > > > DegreeSlopeY = Math.abs(DegreeSlopeY); > > > > > > (this is so > > > > > > that I can calculate the direction the image should travel along the > > > > > > slope) > > > > > > DegreeSlopeX = (90.0000000000000 - > > > > > > DegreeSlopeY); > > > > > > NewY = (mMoveSpeed * > > > > > > Math.sin(DegreeSlopeY)); (This calculates the > > > > > > shift in Y axis for the image) > > > > > > NewX = (mMoveSpeed * > > > > > > Math.sin(DegreeSlopeX)); (This calculates the > > > > > > shift in X axis for the image) > > > > > > if(TouchX < V.CenterX) NewX = -NewX; > > > > > > (This is to finish > > > > > > calculating the correct X axis direction to travel) > > > > > > if(TouchY < V.CenterY) NewY = -NewY; > > > > > > (This is to finish > > > > > > calculating the correct X axis direction to travel) > > > > > > > The problem that I'm having is the image is veering way of course > > > > > > when > > > > > > traveling in Y heavy paths. When traveling horizontally it works > > > > > > almost perfect. > > > > > > > I know there is probably an easier way though I don't know how to > > > > > > use > > > > > > a lot of things (like OpenGLES) so if your advice is to use a > > > > > > different method please link a tutorial for that method if you know > > > > > > of > > > > > > one. > > > > > > > Thanks in advance. -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/android-developers?hl=en

