Jump to content
  • Advertisement
Sign in to follow this  

Ray Vs OBB problem!

This topic is 2959 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I wrote a custom content pipeline that will set a molde.tag value with List<List<Triangle>> (inner list will keep all triangles of each mesh of model and outer list will keep all meshes triangles list) triangles coordinate are in absolute form without any scales or rotations or translates .when I load a model its will set model.tag properties and create an OBB for each mesh by its triangles this is my OBB class:

public OBB(Triangle[] Triangles, Matrix AbsoluteBoneTransform)
Abs = AbsoluteBoneTransform;
IncludingTriangles = Triangles;
List<Vector3> Vertices = new List<Vector3>(0);
for (int i = 0; i < Triangles.Length; i++)
if (!Vertices.Contains(IncludingTriangles.FirstVertex))
if (!Vertices.Contains(IncludingTriangles.SecondVertex))
if (!Vertices.Contains(IncludingTriangles.ThirdVertex))
float MaxX = float.MinValue;
float MaxY = float.MinValue;
float MaxZ = float.MinValue;
float MinX = float.MaxValue;
float MinY = float.MaxValue;
float MinZ = float.MaxValue;
this.Corners = Vertices.ToArray();
foreach (Vector3 v in this.Corners)
if (v.X < MinX)
MinX = v.X;
if (v.Y < MinY)
MinY = v.Y;
if (v.Z < MinZ)
MinZ = v.Z;
if (v.X > MaxX)
MaxX = v.X;
if (v.Y > MaxY)
MaxY = v.Y;
if (v.Z > MaxZ)
MaxZ = v.Z;
this.Max = new Vector3(MaxX, MaxY, MaxZ);
this.Min = new Vector3(MinX, MinY, MinZ);
this.Center = (Min + Max) * 0.5f;
this.Extents = (Max - Min) * 0.5f;
public void GetLoacalCoordinates(Matrix Abs)
Vector3 Translation;
Quaternion Rotation;
Vector3 Scale;
Abs.Decompose(out Scale, out Rotation, out Translation);
LocalXAxis = Vector3.Transform(Vector3.Right, Rotation);
LocalZAxis = Vector3.Transform(Vector3.Forward, Rotation);
LocalYAxis = Vector3.Transform(Vector3.Up, Rotation);
U = new Vector3[] { LocalXAxis, LocalYAxis, LocalZAxis };
E = new float[] { this.Extents.X, this.Extents.Y, this.Extents.Z };

So in this class I have three values Center , Extends and U[0..2] and corners for drawing purposes so I’m trying to write Ray Vs OBB test.

Class OBB
Vector3 U[3]; // Local x-, y-, and z-axes
Vector3 E; // Positive halfwidth extents of OBB along each axis
Vector3 Center; ] // OBB center point
Vector3 Corners[8]; //will store all 8 corners of OBB

This is my problem how can I do that?I think I must use Inverse of U vectors for orientation of Ray.Direction but I don’t know how can I test this new ray with my obb!!!
I m using XNA 3.1 and C#.
any codes or idea.
Thanks a lot.

Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!