예제 #1
0
        /// <summary>
        /// Generar OBB a partir de AABB
        /// </summary>
        /// <param name="aabb">BoundingBox</param>
        /// <returns>OBB generado</returns>
        public static TgcObb.OBBStruct computeFromAABB(TgcBoundingBox.AABBStruct aabb)
        {
            OBBStruct obb = new OBBStruct();

            obb.extents = (aabb.max - aabb.min) * 0.5f;
            obb.center  = aabb.min + obb.extents;

            obb.orientation = new Vector3[] { new Vector3(1, 0, 0), new Vector3(0, 1, 0), new Vector3(0, 0, 1) };
            return(obb);
        }
예제 #2
0
        /// <summary>
        /// Indica si un BoundingSphere colisiona con un BoundingBox.
        /// </summary>
        /// <param name="sphere">BoundingSphere</param>
        /// <param name="aabb">BoundingBox</param>
        /// <returns>True si hay colisión</returns>
        public static bool testSphereOBB(TgcBoundingSphere.SphereStruct sphere, TgcObb.OBBStruct obb)
        {
            //Transformar esfera a OBB-Space
            TgcBoundingSphere.SphereStruct sphere2 = new TgcBoundingSphere.SphereStruct();
            sphere2.center = obb.toObbSpace(sphere.center);
            sphere2.radius = sphere.radius;

            //Crear AABB que representa al OBB
            Vector3 min = -obb.extents;
            Vector3 max = obb.extents;
            TgcBoundingBox.AABBStruct aabb = new TgcBoundingBox.AABBStruct();
            aabb.min = min;
            aabb.max = max;

            return TgcCollisionUtils.testSphereAABB(sphere2, aabb);
        }
예제 #3
0
        /// <summary>
        /// Interseccion Ray-OBB.
        /// Devuelve true y el punto q de colision si hay interseccion.
        /// </summary>
        public static bool intersectRayObb(TgcRay ray, TgcObb obb, out Vector3 q)
        {
            //Transformar Ray a OBB-space
            Vector3 a = ray.Origin;
            Vector3 b = ray.Origin + ray.Direction;
            a = obb.toObbSpace(a);
            b = obb.toObbSpace(b);
            TgcRay.RayStruct ray2 = new TgcRay.RayStruct();
            ray2.origin = a;
            ray2.direction = Vector3.Normalize(b - a);

            //Crear AABB que representa al OBB
            Vector3 min = -obb.Extents;
            Vector3 max = obb.Extents;
            TgcBoundingBox.AABBStruct aabb = new TgcBoundingBox.AABBStruct();
            aabb.min = min;
            aabb.max = max;

            //Hacer interseccion Ray-AABB
            if (TgcCollisionUtils.intersectRayAABB(ray2, aabb, out q))
            {
                //Pasar q a World-Space
                q = obb.toWorldSpace(q);
                return true;
            }

            return false;
        }