Advertisement

How to inverse atan2(sin(Pitch), 1.0 - sin(Pitch)) ?

Started by June 04, 2015 06:52 PM
6 comments, last by scragglypoo 9 years, 8 months ago

Hello, I have a game that transforms the player pitch like this.

pitch = 1.0
Equation used in matrix calculation is: 1.0 - sin(pitch))
But the normal way is: cos(pitch).

So for example the pitch is more sensitive when closer to 0.0:

atan2(sin(pitch), 1.0 - sin(pitch)) = 1.38458
So the value scales now, which is used for game controllers; and I cannot changed it, as it's locked to older versions of the game, which play online.

Another way of looking at it: How to extract pitch from x when x is 1.0 - sin(Pitch) ?

Now Is it possible to get 1.0 back from 1.38458? Because I'd like newer versions to abandon the scaling, but still support old versions online in servers.

Something like this:

If ( Player.IsOldVersion ) {

Player.Pitch = UnscalePitch( Player.Pitch );
}

And on sending packets:

PlayerPacket.Pitch = ScalePitch( Player.Pitch )

Edit: Rewrote.

There are lots of `1.0' in your expression, and it's not entirely clear to me which of them are variable and which of them are constant. Can you rewrite the formula using `x' instead?
Advertisement
Your post makes me worried that you're trying to solve a problem that you shouldn't be solving in the first place...

(Instead of the normal atan2(sin(1.0), cos(1.0)) excluding the yaw...)


Excluding what yaw? One rotation about one axis needs at least a sin/cos pair (or more if you're constructing a matrix). It's not a single "sin for pitch" and "cos for yaw".

Perhaps first we should ask: Why are you using that equation in the first place? What are you trying to do with it? Are you in 2D or 3D?

Edit: Updated main post.

Nypyren: It's 3d. The equation is for game controllers and makes the pitch more sensitive the closer to 0.0 it is. But I want to be able to convert values so I can handle old version users on new online servers. The equation for the pitch scaling is: 1.0-sin(pitch) instead of. normal: cos( pitch )

Ok, I read your updated post.

It seems like the simplest solution is to force players to update to the latest version of the game, or at least make sure that client/server versions must match.

I don't know how to solve that equation. Alvaro's probably your best bet.

If it were me, I'd probably end up making a half-assed nearest-value mapping array that approximates the mapping between the two sides of the equation and use it to convert back and forth.
Advertisement

Im not really sure if I understand what you are trying to do..

But assuming that your equation is correct and you just want to get the variable pitch from the atan (lets call it V):

V = atan2(sin(pitch), 1.0f - sin(pitch)) = atan(sin(pitch) / (1.0f - sin(pitch)))

tan(V) = sin(pitch) / (1.0f - sin(pitch))

tan(V) * (1.0f - sin(pitch)) = sin(pitch)

tan(V) - tan(V) * sin(pitch) = sin(pitch)

tan(V) = sin(pitch) + tan(V) * sin(pitch)

tan(V) = sin(pitch) * (1 + tan(V))

tan(V) / (1 + tan(V)) = sin(pitch)

Therefore:

pitch = asin(tan(V) / (1.0f + tan(V)))

In your case:

asin(tan(1.38458f) / (1.0f + tan(1.38458f))) = 1.0f

thanks

This topic is closed to new replies.

Advertisement