Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Vector3 DirToRot(Vector3 Dir)
- {
- try
- {
- /*
- This is rotation to direction:
- rotx = 0.2
- retx = 0.2 * 0.0174532924 = 0.00349065848 //radians to degrees
- Cos(0.2 * 0.0174532924) = 0.9999939076578741
- absx = Abs(Cos(0.2 * 0.0174532924)) = 0.9999939076578741
- rotz = 0.3
- retz = 0.3 * 0.0174532924 = 0.00523598772 //radians to degrees
- dirx = -Sin(retz) * absx = -0.005235963795437085 * 0.9999939076578741 = -0.0052359318961542843713968514009985 //-0.0052359318961542846 if rounded
- diry = Cos(retz) * absx = 0.9999862922476151 * 0.9999939076578741 = 0.999980199989
- dirz = Sin(retx) = 0.0052359637954370846088922220789420743196847079456760
- now this is direction to rotation:
- dirz = Sin(retx) = 0.0052359637954370846088922220789420743196847079456760
- num1 = retx = Asin(dirz)
- rotx = num1 / 0.0174532924
- num2 = absx = Abs(Cos(num1)
- num3 = diry / num2 = Cos(retz)
- num4 = retz = Acos(num3)
- rotz = num4 / 0.0174532924
- roty?
- */
- float dirz = Dir.Z;
- float num1 = (float)Math.Asin(dirz);
- float rotx = num1 / 0.0174532924f;
- float dirx = Dir.X;
- float num2 = (float)Math.Cos(num1);
- float num3 = dirx / num2;
- float num4 = (float)Math.Asin(-num3);
- float rotz1 = num4 / 0.0174532924f;
- float diry = Dir.Y;
- float num5 = (float)Math.Cos(num1);
- float num6 = diry / num5;
- float num7 = (float)Math.Acos(num6);
- float rotz2 = num7 / 0.0174532924f;
- if (rotz1 > 0)
- {
- if (rotz2 < 90)
- {
- trueRotZ = rotz1; //trueRotZ is a global float variable.
- }
- else
- {
- trueRotZ = rotz2;
- }
- }
- else
- {
- if (rotz2 < 90)
- {
- trueRotZ = rotz1;
- }
- else
- {
- trueRotZ = -rotz2;
- }
- }
- return new Vector3(rotx, 0, trueRotZ);
- }
- catch
- {
- return Vector3.Zero;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement