K Kamac Active Member Licensed User Longtime User Sep 8, 2011 #1 Hi. So i am having troubles with rotating by bitmap at, i am using atand. Code: rot3 = ATanD((posx - pos2x)/(posy - pos2y)*-1) Everything works fine when posy is bigger than pos2y, but when it is otherwise, AtanD won't return me a value in degrees, that would rotate my sprite down. It sounds kinda weird, but it returns values only that can rotate in up. So it can be rotated: _\|/_ in all these directions, but not opposite
Hi. So i am having troubles with rotating by bitmap at, i am using atand. Code: rot3 = ATanD((posx - pos2x)/(posy - pos2y)*-1) Everything works fine when posy is bigger than pos2y, but when it is otherwise, AtanD won't return me a value in degrees, that would rotate my sprite down. It sounds kinda weird, but it returns values only that can rotate in up. So it can be rotated: _\|/_ in all these directions, but not opposite
thedesolatesoul Expert Licensed User Longtime User Sep 8, 2011 #2 Firstly, I think it is (y/x) not (x/y) as in your code. i.e. Code: rot3 = ATanD((posy - pos2y)/(posx - pos2x)*-1) And yes sometimes it does that...i saw a workaround in klaus' code somewhere. when posy-pos2y = 0, AtanD will return zero. Instead of either 0 or 180. So, Code: if posy-pos2y = 0 then if posx-pos2x < 0 then rot3 = 180 else rot3 = 0 end if else rot3 = ATanD((posy - pos2y)/(posx - pos2x)*-1) end if I hope this works...havent tried it. Last edited: Sep 8, 2011 Upvote 0
Firstly, I think it is (y/x) not (x/y) as in your code. i.e. Code: rot3 = ATanD((posy - pos2y)/(posx - pos2x)*-1) And yes sometimes it does that...i saw a workaround in klaus' code somewhere. when posy-pos2y = 0, AtanD will return zero. Instead of either 0 or 180. So, Code: if posy-pos2y = 0 then if posx-pos2x < 0 then rot3 = 180 else rot3 = 0 end if else rot3 = ATanD((posy - pos2y)/(posx - pos2x)*-1) end if I hope this works...havent tried it.
K Kamac Active Member Licensed User Longtime User Sep 8, 2011 #3 I've switched X with Y so it is (y)/(x) now, but now it can rotate only left or right :BangHead:. Your code doesn't works . EDIT@ I've added: Code: rot3 = rot3 + 180 So now it's rotated properly, but if i would have dynamic objects, it would be harder :| Last edited: Sep 8, 2011 Upvote 0
I've switched X with Y so it is (y)/(x) now, but now it can rotate only left or right :BangHead:. Your code doesn't works . EDIT@ I've added: Code: rot3 = rot3 + 180 So now it's rotated properly, but if i would have dynamic objects, it would be harder :|
thedesolatesoul Expert Licensed User Longtime User Sep 8, 2011 #4 This was Klaus's function: Code: Sub CalcAngle(x As Float, y As Float) As Float Dim a As Float If x - x0 = 0 Then a = 90 Else a = ATanD((y - y0)/(x - x0)) End If If x - x0 < 0 Then a = a + 180 End If Return a End Sub I remember is worked beautifully. Upvote 0
This was Klaus's function: Code: Sub CalcAngle(x As Float, y As Float) As Float Dim a As Float If x - x0 = 0 Then a = 90 Else a = ATanD((y - y0)/(x - x0)) End If If x - x0 < 0 Then a = a + 180 End If Return a End Sub I remember is worked beautifully.
K Kamac Active Member Licensed User Longtime User Sep 8, 2011 #5 Hmph. Could you provide some example of use Klaus's function in rotation? :sign0104: Upvote 0
thedesolatesoul Expert Licensed User Longtime User Sep 8, 2011 #6 Why dont you have a look at: http://www.b4x.com/forum/basic4android-updates-questions/11186-rotation-moving-2.html#post62578 Upvote 0
Why dont you have a look at: http://www.b4x.com/forum/basic4android-updates-questions/11186-rotation-moving-2.html#post62578
K Kamac Active Member Licensed User Longtime User Sep 8, 2011 #7 :signOops: Didn't notice that one :BangHead: Upvote 0