Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Mathematics - Rotation problem

Author
Message
Dragon Knight
19
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 20th Mar 2010 19:19 Edited at: 20th Mar 2010 19:21
I've had a late night drinking.. and a major headache, my problem solving has went out the window today.. and I'm requesting the help of my fellow TGC community , Thanks in advance

The problem I have a ship that rotates towards an angle.

for example
DestAngle = 45
SourceAngle = 0

SourceAngle will +1 until it reaches 45

The problem occurs when the Source angle is at say 4 degrees, and the destAngle is at 356 degrees, currently my if statements are very simple just adding and decreasing depending on if it's lower / higher.

Any thought on how to fix this, i'm guessing having another claus saying if SourceAngle<180 and DesAngle>180 then decrease until less than 0 and bang flip it to 360, and the same vise versa.

What do you guys think?

C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 20th Mar 2010 19:29
I'm sure you could try something with wrapvalue.

As for the original part, don't use if statements, use:

As this calls no functions and is just pure mathematics.
(Where DEST is the destination value and CURR is the current value)
(A more logical form uses abs() at the end:
Link102
21
Years of Service
User Offline
Joined: 1st Dec 2004
Location: On your head, weeeeee!
Posted: 20th Mar 2010 19:33 Edited at: 20th Mar 2010 19:35
356 degrees = -4 degrees

wait. think about it...
...
...
...
ok, go.

edit:
I can't resist.

speudo code:

if wrapvalue(destangle) = < 360 and > 180 then destangle = destangle - 360

Dragon Knight
19
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 20th Mar 2010 19:48 Edited at: 20th Mar 2010 19:49
Link that approach doesn't work, just tried it.

C0wbox, I've tried both and messed around with them for a while and didn't get the results I wanted .

e.g.
Source = 5
Destination = 355

It will still increment the source upwards, instead of taking it away until less than 0 switching it to 360

so instead of incrementing 350 times upwards i'd like to:
Decrease the 5 by 10 decrements and get 360 in 10 moves... instead of the 350 increments i'd have to do, going upwards.

Dragon Knight
19
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 20th Mar 2010 20:06
Got it solved... but in a very bad hacker way...

I had the rotation being got from a atan2 from an on screen joystick.
Angles Vary between -3.14 and 3.14 ish.. it's done in radians
Anyway got the code to work by doing the following


Robert The Robot
19
Years of Service
User Offline
Joined: 8th Jan 2007
Location: Fireball XL5
Posted: 20th Mar 2010 20:07
Source= 5, Destination = 355
DirectionOne: Destination - Source = 355 - 5 = 350.
DirectionTwo = Wrapvalue(Source - Destination) = Wrap(5 - 355) = Wrap(-350) = 10
DirectionTwo<Directionone so move negative 10 degrees.


To confirm it works:
Source= 0, Destination = 45
DirectionOne: Destination - Source = 45 - 0 = 45.
DirectionTwo = Wrapvalue(0 - 45) = Wrap(-45) = 315.
Directionone<DirectionTwo so move +45 degrees
Hope this hhelps!

"I wish I was a spaceman, the fastest guy alive. I'd fly you round the universe, in Fireball XL5..."
Jimpo
21
Years of Service
User Offline
Joined: 9th Apr 2005
Location:
Posted: 20th Mar 2010 20:15
Here's a solution that is a little cleaner:



The function is what you want, the rest is just to test.

Dragon Knight
19
Years of Service
User Offline
Joined: 10th Jan 2007
Location: Newcastle
Posted: 20th Mar 2010 20:38 Edited at: 20th Mar 2010 20:40
Jimpo, perfect Substituting it in now
C0wbox, I guess that's what you were hinting at but the use of changing DEST in your formulas confused me a bit, as to what you were doing.

Everyone, thanks for your help it's much appreciated.

C0wbox
20
Years of Service
User Offline
Joined: 6th Jun 2006
Location: 0,50,-150
Posted: 21st Mar 2010 02:18
My formula was just to move the current value to the destination value. - It wasn't going to solve your problem.

Login to post a reply

Server time is: 2026-07-26 21:11:39
Your offset time is: 2026-07-26 21:11:39