Certainly can ike. I've attached the important bits of the OBB class so you know what each parameter is.
public class CD_OrientedBoundingBox
{
Vector3 Centre; // OBB centre point
Quaternion Orientation = Quaternion.Identity; // Orientation of OBB (Rotation matrix is derived from this)
Matrix Rotation; // Local space rotation matrix (What angle the box is at)
Vector3 Extents; // Positive halfwidth extents of the OBB along each axis
// To save memory you can store two Vector3 of the rotation axes
// Compute the 3rd using Vector3.Cross at collision test time (A 3x3 matrix can then be created from these 3 Vector3's)
public CD_OrientedBoundingBox(Vector3 centre, float width, float height, float depth, float yaw, float pitch, float roll)
{
Quaternion additionalRot = Quaternion.CreateFromYawPitchRoll(yaw, pitch, roll);
Orientation *= additionalRot;
Rotation = Matrix.CreateFromQuaternion(Orientation);
Centre = centre;
Extents = new Vector3(width * 0.5f, height * 0.5f, depth * 0.5f);
}
public CD_OrientedBoundingBox(Vector3 centre, float width, float height, float depth, Matrix rotation)
{
Quaternion additionalRot = Quaternion.CreateFromRotationMatrix(rotation);
Orientation *= additionalRot;
Rotation = Matrix.CreateFromQuaternion(additionalRot);
Centre = centre;
Extents = new Vector3(width * 0.5f, height * 0.5f, depth * 0.5f);
}
// Extents (Local Space - For drawing correctly with rotation)
public Vector3 Extents_HalfWidth
{
get { return Extents; }
}
/// <summary>
/// AABB min point contained within AABB (World Space) [Transformed Extents to World Space via World Transform/Transform_World]
/// </summary>
public Vector3 MinPoint
{
get { return Vector3.Transform(-Extents, Transform_World); }
}
/// <summary>
/// AABB max point contained within AABB (World Space) [Transformed Extents to World Space via World Transform/Transform_World]
/// </summary>
public Vector3 MaxPoint
{
get { return Vector3.Transform(Extents, Transform_World); }
}
public Vector3 Position
{
get { return Centre; }
set { Centre = value; }
}
public Matrix Rotation_Matrix
{
get { return Rotation; }
}
public Vector3 Axis_X // X axis rotation
{
get { return new Vector3(Rotation.M11, Rotation.M12, Rotation.M13); }
}
public Vector3 Axis_Y // Y axis rotation
{
get { return new Vector3(Rotation.M21, Rotation.M22, Rotation.M23); }
}
public Vector3 Axis_Z // Z axis rotation
{
get { return new Vector3(Rotation.M31, Rotation.M32, Rotation.M33); }
}
/// <summary>
/// Used for converting body (OBB) space into world space (and vice versa) [Derived from rotation, centre]
/// </summary>
public Matrix Transform_World
{
get
{
Matrix matrix_World = Rotation;
matrix_World.Translation = Centre;
return matrix_World;
}
}
1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63: 64: 65: 66: 67: 68: 69: 70: 71: 72: 73: 74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90:





by: ikeworkPosted on 2009-11-01 at 04:44:59ID: 25713531
Hi Dr_Spankenstein,
You have to transform the ray with the inverse transformation matrix of the obb, in order to trasform the ray into obb-space. Can you show the declaration of your Obb?
ike