I have a pitch, roll, and yaw angles (in degrees). I want to find the angle to north.
My goal is to transform this info (pitch+roll+yaw) to a simple compass degrees.
Related
I am currently working on block-breaking in a Minecraft clone. In order to do so, I want use the camera's Euler angles to determine the direction vector of the camera's ray.
I have 2 angles: pitch and yaw.
Pitch rotates along the X axis and is positive when the player looks down, and negative when the player looks up. It cannot be greater than 90 degrees (looking straight down) and cannot be smaller than -90 degrees (looking straight up)
Yaw rotates along the Y axis. It can be a negative number and a positive number, depending on how many times the player turned and in which direction. For example, the player spawns in (yaw = 0) and instantly spins counter-clockwise 360 degrees. In such a case, yaw = -360.
As stated in the question, I am using OpenGL, so when yaw = 0, the player is looking down the negative Z-axis.
How can I generate a direction vector (must be a unit-vector) using only the Euler angles with the restrictions described above?
From your description of Pitch and Yaw, I am assuming that you are using a left-hand reference (pitch=0 and yaw=0 gives a camera vector (0.0, 0.0, 1.0).
The Pitch parameter moves the camera vector in the YZ plane :
Y = cos(pitchInRadians)
Z = sin(pitchInRadians)
The Yaw parameter moves the camera vector in the XZ plane :
X = sin(yawInRadians)
Z = cos(yawInRadians)
Combining the two would give you your final camera vector :
Cv = (sin(yaw), cos(pitch), sin(pitch)*cos(yaw))
As you should have noted, the angles are in radians. Since your post mentions angles in degrees, you will have to convert your degree angles to radians first :
radians = (degrees * PI) /180
Im working now with some mod for the game, exactly i need rotate my player to any object.
I have two vector3, its my pos and object pos.
As usually we can
Vector3 Dir = object - mypos to get direction and calculate yaw and pitch using atan2 function, write it to our player angle and we will done rotation.
Problem. I first time see pitch value between 180 (mouse up) and 360 (mouse down), yaw 0 - 360, roll 0 (doesn’t matter now). Its represents as Vector3 euler. Of course if im using atan2 way i getting incorrect values for this eluer vector cause i getting less small (Lower than 180) or negative values for pitch, yaw seems in range. How to calculate correct?
My calcs:
Vector3 DoorDir = DoorOrigin - PlayerOrigin;
DoorDir = NormalizeVec(DoorDir);
float yaw = Rad2Deg(atan2(DoorDir.x, DoorDir.z));//Game has XZY coords.
float pitch = Rad2Deg(-1.f * atan2(DoorDir.y, sqrtf(DoorDir.x * DoorDir.x + DoorDir.z * DoorDir.z)));
SetAngles(Vector2(yaw,pitch)//Sets angles (converted yaw and pitch back to DEG)
I am implementing a software that reads the raw data by an accelerometer (connected via USB port) and rotates a virtual object (for example a cube in unity3d environment).
From the raw data given by the accelerometer I calculate the accelerator components:
Xg = raw_data[0]*range/pow(2,resolution-1) //for x accelerator component
Yg = raw_data[1]*range/pow(2,resolution-1) //for y accelerator component
Zg = raw_data[2]*range/pow(2,resolution-1) //for z accelerator component
where range and resolution are provided by accelerometer datasheet.
Then I calculate the pitch and roll angles by means these formulas:
roll = arctg(-Xg/Zg)*180/PI
pitch = arctg(Yg/sqrt(pow(Xg,2)+pow(Zg,2)))-180/PI
Finally I get the yaw angle from gyroscope.
In order to rotate an object in my scene I set its euler angles to these value but the object has a full rotation in x and z axis (roll angle and yaw angle), but not in y axis (pitch angle) where the object rotates only 180 degrees.
The problem is that the pitch angle is in range [-90,90] degrees and the object
cannot have a 360degrees rotation.
Is there a formula for pitch angle to have a 360 degrees rotation also for the y axis? Thanks a lot.
If I have a camera's yaw, pitch, and up vector (always [0,1,0] in my case), what's the best way to calculate the corresponding roll?
When a camera's up vector is (0,1,0), the effect is to lock its yaw to 0 degrees.
How do I calculate the pitch, yaw, and roll angles for a point in 3D space?
I'm working on a game where the player character must face towards an object that's flying around.
For yaw, use the atan2() of the X and Y coordinates. For the pitch, use the X-Y magnitude and the Z coordinate. Points don't have a roll.