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.

AppGameKit Studio Chat / Normalize a vector

Author
Message
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 9th Apr 2020 22:23
Anyone have a code snippet for this?
hendron
8
Years of Service
User Offline
Joined: 20th Dec 2015
Location:
Posted: 9th Apr 2020 23:04
Divide each component by the vector's magnitude:

Raven
19
Years of Service
User Offline
Joined: 23rd Mar 2005
Location: Hertfordshire, England
Posted: 9th Apr 2020 23:33
You don't want to do it as separate Functions., as it slows the code down (see: Array Performance Thread)
But yeah...

Type Vector
X As Float
Y As Float
Z As Float
EndTyp

Function VectorNormalise( Vec Ref As Vector )
Local Length As Float
Length = Sqrt( Vec.x * Vec.x + Vec.y * Vec.y + Vec.z * Vec.z )
Vec.x = Vex.x / Length
Vec.y = Vec.y / Length
Vec.z = Vec.z / Length
EndFunction

Weirdly GetVector3Normalize( ) isn't one of the Math Functions., mind it seems like an after thought Command Library anyway.
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 9th Apr 2020 23:52
Thanks guys! I really appreciate it. Works a treat

Login to post a reply

Server time is: 2024-04-16 22:54:17
Your offset time is: 2024-04-16 22:54:17