// Project: XnaShooter, File: Vector3Helper.cs
// Namespace: XnaShooter.Helpers, Class: Vector3Helper
// Path: C:\code\XnaShooter\Helpers, Author: Abi
// Code lines: 62, Size of file: 2,14 KB
// Creation date: 13.10.2006 23:14
// Last modified: 20.10.2006 08:29
// Generated with Commenter by abi.exDream.com
#region Using directives
using Microsoft.Xna.Framework;
using System;
using System.Collections.Generic;
using System.Text;
#endregion
namespace XnaShooter.Helpers
{
///
/// Vector 3 helper
///
class Vector3Helper
{
#region Get angle between vectors
///
/// Return angle between two vectors. Used for visbility testing and
/// for checking angles between vectors for the road sign generation.
///
/// Vector 1
/// Vector 2
/// Float
public static float GetAngleBetweenVectors(Vector3 vec1, Vector3 vec2)
{
// See http://en.wikipedia.org/wiki/Vector_(spatial)
// for help and check out the Dot Product section ^^
// Both vectors are normalized so we can save deviding through the
// lengths.
return (float)Math.Acos(Vector3.Dot(vec1, vec2));
} // GetAngleBetweenVectors(vec1, vec2)
#endregion
#region Distance to line
///
/// Distance from our point to the line described by linePos1 and linePos2.
///
/// Point
/// Line position 1
/// Line position 2
/// Float
public static float DistanceToLine(Vector3 point,
Vector3 linePos1, Vector3 linePos2)
{
// For help check out this article:
// http://mathworld.wolfram.com/Point-LineDistance3-Dimensional.html
Vector3 lineVec = linePos2-linePos1;
Vector3 pointVec = linePos1-point;
return Vector3.Cross(lineVec, pointVec).Length() / lineVec.Length();
} // DistanceToLine(point, linePos1, linePos2)
#endregion
#region Signed distance to plane
///
/// Signed distance to plane
///
/// Point
/// Plane position
/// Plane normal
/// Float
public static float SignedDistanceToPlane(Vector3 point,
Vector3 planePosition, Vector3 planeNormal)
{
Vector3 pointVec = planePosition - point;
return Vector3.Dot(planeNormal, pointVec);
} // SignedDistanceToPlane(point, planePosition, planeNormal)
#endregion
} // class Vector3Helper
} // namespace XnaShooter.Helpers