Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ CreateConstrainedBillboard() [2/2]

static Matrix Microsoft.Xna.Framework.Matrix.CreateConstrainedBillboard ( Vector3 objectPosition,
Vector3 cameraPosition,
Vector3 rotateAxis,
Vector3? cameraForwardVector,
Vector3? objectForwardVector )
inlinestatic

Definition at line 304 of file Matrix.cs.

305 {
306 Vector3 value = default(Vector3);
307 value.X = objectPosition.X - cameraPosition.X;
308 value.Y = objectPosition.Y - cameraPosition.Y;
309 value.Z = objectPosition.Z - cameraPosition.Z;
310 float num = value.LengthSquared();
311 if (num < 0.0001f)
312 {
313 value = (cameraForwardVector.HasValue ? (-cameraForwardVector.Value) : Vector3.Forward);
314 }
315 else
316 {
317 Vector3.Multiply(ref value, 1f / (float)Math.Sqrt(num), out value);
318 }
319 Vector3 vector = rotateAxis;
320 Vector3.Dot(ref rotateAxis, ref value, out var result);
321 Vector3 result2;
322 Vector3 result3;
323 if (Math.Abs(result) > 0.99825466f)
324 {
325 if (objectForwardVector.HasValue)
326 {
327 result2 = objectForwardVector.Value;
328 Vector3.Dot(ref rotateAxis, ref result2, out result);
329 if (Math.Abs(result) > 0.99825466f)
330 {
331 result = rotateAxis.X * Vector3.Forward.X + rotateAxis.Y * Vector3.Forward.Y + rotateAxis.Z * Vector3.Forward.Z;
332 result2 = ((Math.Abs(result) > 0.99825466f) ? Vector3.Right : Vector3.Forward);
333 }
334 }
335 else
336 {
337 result = rotateAxis.X * Vector3.Forward.X + rotateAxis.Y * Vector3.Forward.Y + rotateAxis.Z * Vector3.Forward.Z;
338 result2 = ((Math.Abs(result) > 0.99825466f) ? Vector3.Right : Vector3.Forward);
339 }
340 Vector3.Cross(ref rotateAxis, ref result2, out result3);
341 result3.Normalize();
342 Vector3.Cross(ref result3, ref rotateAxis, out result2);
343 result2.Normalize();
344 }
345 else
346 {
347 Vector3.Cross(ref rotateAxis, ref value, out result3);
348 result3.Normalize();
349 Vector3.Cross(ref result3, ref vector, out result2);
350 result2.Normalize();
351 }
352 Matrix result4 = default(Matrix);
353 result4.M11 = result3.X;
354 result4.M12 = result3.Y;
355 result4.M13 = result3.Z;
356 result4.M14 = 0f;
357 result4.M21 = vector.X;
358 result4.M22 = vector.Y;
359 result4.M23 = vector.Z;
360 result4.M24 = 0f;
361 result4.M31 = result2.X;
362 result4.M32 = result2.Y;
363 result4.M33 = result2.Z;
364 result4.M34 = 0f;
365 result4.M41 = objectPosition.X;
366 result4.M42 = objectPosition.Y;
367 result4.M43 = objectPosition.Z;
368 result4.M44 = 1f;
369 return result4;
370 }
static double Sqrt(double d)
static double Abs(double value)
Matrix(float m11, float m12, float m13, float m14, float m21, float m22, float m23, float m24, float m31, float m32, float m33, float m34, float m41, float m42, float m43, float m44)
Definition Matrix.cs:210

References System.Math.Abs(), Microsoft.Xna.Framework.Vector3.Cross(), Microsoft.Xna.Framework.Vector3.Dot(), Microsoft.Xna.Framework.Vector3.Forward, Microsoft.Xna.Framework.Vector3.Multiply(), Microsoft.Xna.Framework.Vector3.Right, System.Math.Sqrt(), System.value, Microsoft.Xna.Framework.Vector3.X, Microsoft.Xna.Framework.Vector3.Y, and Microsoft.Xna.Framework.Vector3.Z.