Rules FAQ Members List Search Register Login

 Raised This Month: \$204 Target: \$400 51%

Author Message
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
 07-27-2010 , 23:21   Difference between 2 angle vectors? #1 I don't fully understand vectors :S Basically, I have one angle vector which I got from the client's eye angles. Code: `GetClientEyeAngles` Then I have another angle vector which is the correct angle for the client's eyes to be looking at another point. Code: ```MakeVectorFromPoints(ClientEyes, OtherPoint, VectorConnecting); GetVectorAngles(VectorConnecting, VectorAngles);``` What I want to be able to do now, is to figure out if the different between both angle vectors is less than 75 degrees in all directions, but for the life of me I can't figure out how. Any help? __________________
Monkeys
Veteran Member
Join Date: Jan 2010
07-27-2010 , 23:51   Re: Difference between 2 angle vectors?
#2

Quote:
 Originally Posted by almcaeobtac I don't fully understand vectors :S Basically, I have one angle vector which I got from the client's eye angles. Code: `GetClientEyeAngles` Then I have another angle vector which is the correct angle for the client's eyes to be looking at another point. Code: ```MakeVectorFromPoints(ClientEyes, OtherPoint, VectorConnecting); GetVectorAngles(VectorConnecting, VectorAngles);``` What I want to be able to do now, is to figure out if the different between both angle vectors is less than 75 degrees in all directions, but for the life of me I can't figure out how. Any help?
I'm not all to sure what you want.
If you want to see if the Vector Angles of the second one (VectorAngles) versus the ones from GetClientEyeAngle are within 75° of eachother on each plane, can't you just substract absolutes and see if it's below 75?

Side note: I'm guessing GetVectorAngles gets the angles of the line connecting (0,0,0) with the given vector, right? Because I have no idea how you'd get the angles of a single point any other way x)
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
 07-28-2010 , 01:35   Re: Difference between 2 angle vectors? #3 No I'm getting the angle from one point to another. IE the Client's eyes to another point. VS. the client's eyes in their current angle, but I'll try your method. How do you subtract absolutes, is it just | |? __________________
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
 07-28-2010 , 01:40   Re: Difference between 2 angle vectors? #4 Also...360 degrees and 1 degree wouldn't register as being within 75 degrees of each other, even though they are in actuality. How would I work around that too? __________________
Monkeys
Veteran Member
Join Date: Jan 2010
07-28-2010 , 02:00   Re: Difference between 2 angle vectors?
#5

Quote:
 Originally Posted by almcaeobtac Also...360 degrees and 1 degree wouldn't register as being within 75 degrees of each other, even though they are in actuality. How would I work around that too?
Seeing how you're working with floats, use the FloatAbs() function to get absolutes.
To get around the 360-1 problem, use an || with a 360 increase on values (both, or you'd have to check which one is highest first, which is a lot more work)
It would look something like this:
PHP Code:
``` if( FloatAbs( (Angles1[0] - Angles2[0]) ) < 75.0 || FloatAbs( (Angles1[0] - (Angles2[0] + 360.0) ) ) < 75.0 || FloatAbs( ( (Angles1[0] + 360.0) - Angles2[0]) ) < 75.0 )  ```
And do it for each angle you need.

You could probably use a few other mathematical formulas which are a lot easier to use, but hard to understand.

EDIT: Incase you're not too awake when reading this, and doubt if this is true, here's the empirical proof (which I wrote down for my brother, who doubted this ;p)

Code:
```Testcases: 5 & 75 (true), 5 & 86 (false), 5 & 352 (true), 5 & 250 (false), 352 & 2 (true), 355 & 75 (false). These have been chosen by my brother as each possible case. (First two are communitive due to the Absolute).

5 & 75:
| 5 - 75 | < 75
= | - 70 | < 75
= 70 < 75
= true

5 & 86:
| 5 - 86 | < 75 = 81 < 75 = false
OR
| 5 - 341 | < 75 = false
OR
|365 - 81| < 75 = false

5 & 352:
| 5 - 352 | < 75 = false
OR
| 5 - 712 | < 75 = false
OR
|365 - 352| < 75 = true

5 & 250:
| 5 - 250 | < 75 = false
OR
| 5 - 580 | < 75 = false
OR
|365 - 250| < 75 = false

352 & 2:
| 352 - 2 | < 75 = false
OR
| 352 - 362 | < 75 = true

355 & 75:
| 355 - 75 | < 75 = false
OR
| 355 - 435 | < 75 = false
OR
| 715 - 75 | < 75 = false```
__________________
Get a lid on that zombie,
he's never gonna be alri-i-ight.
Oooh get a lid on that zombie,
or he's gonna feed all night.

Last edited by Monkeys; 07-28-2010 at 02:17. Reason: Forgot the tagmismatches of 75(.0)
Damizean
SourceMod Donor
Join Date: Mar 2009
 07-28-2010 , 14:58   Re: Difference between 2 angle vectors? #6 You could do it with a simple dot product of the forward vectors of the angles. This is because the dot product of two normalized vectors is the cosine of the angle between them: Code: `cos a = v1 · v2` The snippet would be something like this. PHP Code: ``` Float:GetDifferenceBetweenAngles(Float:fA[3], Float:fB[3]){    decl Float:fFwdA[3]; GetAngleVectors(fA, fFwdA, NULL_VECTOR, NULL_VECTOR);    decl Float:fFwdB[3]; GetAngleVectors(fB, fFwdB, NULL_VECTOR, NULL_VECTOR);    return RadToDeg(ArcCosine(fFwdA[0] * fFwdB[0] + fFwdA[1] * fFwdB[1] + fFwdA[2] * fFwdB[2]));}// Exampleif (GetDifferenceBetweenAngles(Angles1, Angles2) > 70.0){    // Do stuff    ...}  ``` __________________ Dat annoying guy
almcaeobtac
Senior Member
Join Date: Nov 2008
Location: Florida
 07-28-2010 , 20:21   Re: Difference between 2 angle vectors? #7 Wow, thank you both so much. I tried to do something like this before you replied, and failed horribly. You've saved my plugin! +respect __________________

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is Off Forum Rules
 Forum Jump User Control Panel Private Messages Subscriptions Who's Online Search Forums Forums Home Server Discussion     Source Servers (SRCDS)     HL1 Servers (HLDS) AMX Mod X     News     Bug Reports     General     Off-Topic     Plugins         Suggestions / Requests         Approved Plugins         New Plugin Submissions         Unapproved/Old Plugins         Translation Request         High-Traffic Plugins             GunGame             UAIO (Ultimate All-In-One Plugin)             xREDIRECT             CSDM             AMX Super             RuneMod             Zombie Plague Mod             SuperHero Mod                 News                 Tech Support                 Scripting Help                 Off-Topic / General Chat                 Heroes                     Suggestions / Requests                     Approved Heroes                     New Submissions                     Unapproved/Old Heroes                         Module Heroes                     SuperHero Mod Stats - By 123                 (OLD) Bug Reports     Scripting         Scripting Help         Code Snippets/Tutorials         Module Coding     Donor Access SourceMod     News     General     Plugins         Plugins         Unapproved Plugins         Plugin/Gameplay Ideas and Requests         High-Traffic Plugins             SourceMod Anti-Cheat             Zombie:Reloaded             SourceBans / SourceBans++             VSH / Freak Fortress             Store             SM_Hosties             HLstatsX:CE     Scripting     Extensions     Snippets and Tutorials     Donor Access     Metamod: Source         Metamod:Source Plugins         Metamod:Source Questions         Coding MM:S Plugins & SM Extensions Hosted Stuff     Asherkin's Plugins         TF2Items         TFDodgeball         SteamTools     Bail's Plugins         CSDM         CS:S DM Off-Topic & Trash     Off-Topic     Trash

All times are GMT -4. The time now is 22:50.

 DMCA - Archive - Top