- Home /
Math question, angles and magnitude stuff
im using arctangent2 to find the angle between 2 vectors.
arctan2(magnitude(axis of rotation), dotProduct(start vector,end vector));
so rotating from vector1 direction to vector 2 direction along axis "axis" angle degrees where angle is that arctan function.
Problem is it requires square rooting. Can i arctangent with a square adn get the right answer still?
my frame rate is getting hammered. Basically this is running in update. and yea it's just smashing the shit out of the frame rate. And running outside of update doesnt seem viable. The algorithm based on appearances it gets more and more accurate every second.
I've not idea why but literally, this is rotating in update adn yet i can watch it slowly rotate around like it was lerping.
That is just trashing framerate to do so. I can live without it (it's just a CPU load not a GPU so it's honestly not a huge issue for a computer game, and its only ever going to run one at a time, it's an editor to snap 2 objects together).
So i can totally run it and live with it as is. It only slows framerate while it snaps stuff together (though that does take literally a second or two)
But if i dont have to i dont want to. It really is very very noticable the drag. $$anonymous$$y framerate in the stats viewer goes from 2600 frames a second.
O$$anonymous$$ CO$$anonymous$$PLETELY WRONG
It was a debug draw function that was running in update that trashed the framerate my bad. it was drawing debug lines with 5 second lifespans every update so hundreds stacked on eachother and THAT was trashing framerate.
So ignore all this.
Answer by Fattie · Mar 25, 2013 at 02:13 PM
just curious -- could it be something else causing the problem?
Like literally in say 1980 (thirty+ years ago) you'd hear people say "if possible avoid a square root!"
That's irrelevant today. Consider how many calculations Unity is doing all the time man ??! All the rotations and so on... every single frame... I mean .. my goodness .. it's not even a compiled language, you're using vast layers of interpreters, physics engines, and what not.
I use and I see used Atan2 constantly, in fairly high performance code (every sort of typical 3D game etc), eg...
__angleCCW = Mathf.Atan2(b.z,b.x) - Mathf.Atan2(a.z,a.x);
So ... just a thought man ! Maybe forget about it :)
Don't $$anonymous$$d, @Fattie - you deserved the up vote, and questions solved don't give us karma anyway. You're right about square roots: even mobile devices have a FPU to spit thousands of floating point operations per frame, including square roots.
that's weird dude ... no karma for Ticks huh ??? Only for thumbs .. is that correct? Seems hard to believe.
(Of course I don't really $$anonymous$$d - I was just kidding around.)
Despite the high rate of calculation of most devices nowadays, I still consider little details like avoiding sqr root, trig functions or other recursive function. Even if they tend to make code less readable...
And right answer (when ticked) do give $$anonymous$$arma if it is ticked by someone else. As if you still need some.
"And right answer (when ticked) do give $$anonymous$$arma" ... ah that makes sense. thanks for the info.
("when ticked by someone else" .. indeed)
"As if you still need some." I don't know how you can say that man! I need SO $$anonymous$$UCH $$anonymous$$OAR :)
I can't agree with you on sqrroot and trig man. You should use them very freely.
Regarding recursion, never use it, for sure.
Answer by sparkzbarca · Mar 25, 2013 at 03:01 PM
wasnt square root fucntion
was a debug.drawray running every update and creating rays that lasted 5 seconds.
My bad.
Question answered cause it doesnt need an answer.
we happened to answer at the same time, on my screen there wasnt even an answer when i went to reply :P You'll notice i got posted first.
you've been marked though :)