Ejemplo n.º 1
0
        public static void updateObbFromSegment(TgcObb obb, Vector3 a, Vector3 b, float thickness)
        {
            Vector3 lineDiff   = b - a;
            float   lineLength = lineDiff.Length();
            Vector3 lineVec    = Vector3.Normalize(lineDiff);

            //Obtener angulo y vector de rotacion
            Vector3 upVec        = new Vector3(0, 1, 0);
            float   angle        = FastMath.Acos(Vector3.Dot(upVec, lineVec));
            Vector3 axisRotation = Vector3.Cross(upVec, lineVec);

            axisRotation.Normalize();

            //Obtener matriz de rotacion para este eje y angulo
            Matrix rotM = Matrix.RotationAxis(axisRotation, angle);

            //Actualizar orientacion de OBB en base a matriz de rotacion
            obb.Orientation[0] = new Vector3(rotM.M11, rotM.M12, rotM.M13);
            obb.Orientation[1] = new Vector3(rotM.M21, rotM.M22, rotM.M23);
            obb.Orientation[2] = new Vector3(rotM.M31, rotM.M32, rotM.M33);

            //Actualizar extent de OBB segun el thickness del segmento
            obb.Extents = new Vector3(thickness, lineLength / 2, thickness);

            //Actualizar centro del OBB segun centro del segmento
            obb.Center = a + Vector3.Scale(lineDiff, 0.5f);

            //Regenerar OBB
            obb.updateValues();
        }