Community
Message Board

Chat room - users
Game Over
( 394431 downloads)
Work In Progress
( 523201 downloads)
Links

Code Exchange
Downloads
Tutorials
Add to Favourites

Submit news

DIV ARENA FORUMS
Not logged in [Login - Register]
Go To Bottom

Printable Version  
Author: Subject: A fix for DIVs angle issue!
BreadCaster
Loyalty Card Holder
******


Avatar


Posts: 321
Registered: 2-3-2016
Member Is Offline


[*] posted on 8-12-2016 at 04:04 PM
A fix for DIVs angle issue!


EDIT: My original function doesn't seem to work as well as I thought it does. However, there is this one from Ecko that I managed to dig up, and that's what I've been using instead to solve the jump in angles between 0 and 360000:

Code:
function closest_angle(angle1, int angle2) private result; begin result=(angle2-angle1)%360000; if (result>180000) result-=360000; else if (result<-180000); result+=360000; end end if (result<0); result=abs(result); end return (result); end


Please credit him if using :) Thanks!

---

Hi there all!!

Disabling my VPN for a second so I can come back on here for a bit and give away this quick code snippet I've whipped up.

Now as we all know, one of the bugbears of using angles in DIV is that when the angle reads under 0, angle is turned to 360000 - it's a problem I remember a lot of people facing and it makes it hard to tell what's in a specific span of degrees of a given angle.

Well - not any more :) I've coded a quick function which I'll soon be using in my mode 8 capabilities demonstration which gives you a more accurate readout without the "jump" in angles and no other issues (as far as I can tell - please let me know if something is amiss!!)

Simply give the angle you want to calculate the "correct" angle for to the angle_readout function and assign the returned value to a variable.

Code:
Function angle_readout(angle); Private calc_angle; return_angle; Begin calc_angle=-angle+180000; if (calc_angle<0); return_angle=abs(calc_angle); else return_angle=calc_angle; end return (return_angle); End


Hope this helps!


/Breadytits


[Edited on 10-12-2016 by BreadCaster]

[Edited on 12-12-2016 by BreadCaster]




~*~ Princess of Pies and Pastries ~*~
View user's profile View All Posts By User
BreadCaster
Loyalty Card Holder
******


Avatar


Posts: 321
Registered: 2-3-2016
Member Is Offline


[*] posted on 10-12-2016 at 01:12 AM


Update - Whoops, this doesn't seem to work as well as I thought it does. While there's no gaps between the angles, it's now the case that the program can't know exactly which direction you're looking in, so it's no good. -_- Apologies for jumping the gun there folks. I'll see if I can get it working soon and post an updated version.



~*~ Princess of Pies and Pastries ~*~
View user's profile View All Posts By User
dom cook
Div Pro
******




Posts: 372
Registered: 4-3-2016
Member Is Offline


[*] posted on 10-12-2016 at 04:53 AM


I use this solution.

angle=(angle+360000) mod 360000;
View user's profile View All Posts By User
BreadCaster
Loyalty Card Holder
******


Avatar


Posts: 321
Registered: 2-3-2016
Member Is Offline


[*] posted on 10-12-2016 at 01:05 PM


Okay, I'll give that a shot instead. Thanks Dom :) btw I just shot you a message about mode 8



~*~ Princess of Pies and Pastries ~*~
View user's profile View All Posts By User
BreadCaster
Loyalty Card Holder
******


Avatar


Posts: 321
Registered: 2-3-2016
Member Is Offline


[*] posted on 10-12-2016 at 01:24 PM


What results does that bring usually, dom? It doesn't seem to act differently than how angles otherwise work... I just get the skipping back to 0/360000 gap.



~*~ Princess of Pies and Pastries ~*~
View user's profile View All Posts By User
BreadCaster
Loyalty Card Holder
******


Avatar


Posts: 321
Registered: 2-3-2016
Member Is Offline


[*] posted on 10-12-2016 at 07:40 PM


Okay, I've been using this instead, with success. Code by Master Ecko, salvaged from an old project:

Code:
function closest_angle(angle1, int angle2) private result; begin result=(angle2-angle1)%360000; if (result>180000) result-=360000; else if (result<-180000); result+=360000; end end if (result<0); result=abs(result); end return (result); end




~*~ Princess of Pies and Pastries ~*~
View user's profile View All Posts By User
MikeDX
DIV Nerd
*********


Avatar


Posts: 8388607
Registered: 25-2-2016
Member Is Offline


[*] posted on 10-12-2016 at 10:04 PM


You do realise there is a DIV function called near_angle, right?
View user's profile View All Posts By User
dom cook
Div Pro
******




Posts: 372
Registered: 4-3-2016
Member Is Offline


[*] posted on 11-12-2016 at 05:42 AM


Quote: Originally posted by BreadCaster  
What results does that bring usually, dom? It doesn't seem to act differently than how angles otherwise work... I just get the skipping back to 0/360000 gap.


Well, it's supposed to stop the angles going up to crazy numbers which unless you're making a snowboarding game can be pretty undesirable. (Imagine if you want an object to turn towards another -using near_angle() for example- and it does a few spins in the process) Depending on what range you wanted you could then offset it, for example by taking away 180000 to keep the angles in the range -180000 to 180000.

However, Looking at the code you're using now, I can see it's not what you were after. Out if interest, am I right in thinking that you were looking to return an angle between two angles?
View user's profile View All Posts By User
BreadCaster
Loyalty Card Holder
******


Avatar


Posts: 321
Registered: 2-3-2016
Member Is Offline


[*] posted on 11-12-2016 at 07:50 PM


I was essentially looking to be able to detect if a processes angle is within an angle "range" of another angle. The issue I had is what if you wanted to know what was within 10000 degrees of 0? You can only detect it in one direction because in the other direction the angle skips back over to 360000.

and yeah Mike, I've used near_angle in the past but in this case it doesn't yield much success. Fortunately the old code of Eckos I've dug up has sufficed :)




~*~ Princess of Pies and Pastries ~*~
View user's profile View All Posts By User
dom cook
Div Pro
******




Posts: 372
Registered: 4-3-2016
Member Is Offline


[*] posted on 12-12-2016 at 08:07 AM


Good Stuff. As you were.
View user's profile View All Posts By User

  Go To Top

Powered by XMB
XMB Forum Software © 2001-2012 The XMB Group
[Queries: 18]