public void UpdateTransform()
        {
            if (parent != null)
            {
                globalTransform = parent.globalTransform * localTransform;
            }
            else
            {
                globalTransform = localTransform;
            }

            foreach (SceneObject child in children)
            {
                child.UpdateTransform();
            }
        }
Example #2
0
        public void SetToTransformedBox(AABB box, Calculations.Matrix3 m)
        {
            // If we're empty, then exit (an empty box defined as having the min/max
            // set to infinity)
            if (box.IsEmpty())
            {
                Empty();
                return;
            }
            // Examine each of the nine matrix elements
            // and compute the new AABB
            Vector3 min = new Vector3();
            Vector3 max = new Vector3();

            if (m.x1 > 0.0f) // x1 = x11 in the formula above
            {
                min.x += m.x1 * box.min.x; max.x += m.x1 * box.max.x;
            }
            else
            {
                min.x += m.x1 * box.max.x; max.x += m.x1 * box.min.x;
            }
            if (m.x2 > 0.0f) // y1 = x12 in the formula above
            {
                min.y += m.x2 * box.min.x; max.y += m.x2 * box.max.x;
            }
            else
            {
                min.y += m.x2 * box.max.x; max.y += m.x2 * box.min.x;
            }
            if (m.x3 > 0.0f) // z1 = x13 in the formula above
            {
                min.z += m.x3 * box.min.x; max.z += m.x3 * box.max.x;
            }
            else
            {
                min.z += m.x3 * box.max.x; max.z += m.x3 * box.min.x;
            }
            //---------------------------------------------------------------------------
            if (m.y1 > 0.0f) // x2 = y11 in the formula above
            {
                min.x += m.y1 * box.min.y; max.x += m.y1 * box.max.y;
            }
            else
            {
                min.x += m.y1 * box.max.y; max.x += m.y1 * box.min.y;
            }
            if (m.y2 > 0.0f) // y2 = y12 in the formula above
            {
                min.y += m.y2 * box.min.y; max.y += m.y2 * box.max.y;
            }
            else
            {
                min.y += m.y2 * box.max.y; max.y += m.y2 * box.min.y;
            }
            if (m.y3 > 0.0f) // z2 = y13 in the formula above
            {
                min.z += m.y3 * box.min.y; max.z += m.y3 * box.max.y;
            }
            else
            {
                min.z += m.y3 * box.max.y; max.z += m.y3 * box.min.y;
            }
//---------------------------------------------------------------------------
            if (m.z1 > 0.0f) // x3 = z11 in the formula above
            {
                min.x += m.z1 * box.min.z; max.x += m.z1 * box.max.z;
            }
            else
            {
                min.x += m.z1 * box.max.z; max.x += m.z1 * box.min.z;
            }
            if (m.z2 > 0.0f) // y2 = z12 in the formula above
            {
                min.y += m.z2 * box.min.z; max.y += m.z2 * box.max.z;
            }
            else
            {
                min.y += m.z2 * box.max.z; max.y += m.z2 * box.min.z;
            }
            if (m.z3 > 0.0f) // z1 = z13 in the formula above
            {
                min.z += m.z3 * box.min.z; max.z += m.z3 * box.max.z;
            }
            else
            {
                min.z += m.z3 * box.max.z; max.z += m.z3 * box.min.z;
            }

            box.min = min;
            box.max = max;

            // Continue like this for the remaining 6 matrix values
        }
 /// <summary>
 /// Sets a Matrix3 to the variables of another Matrix3
 /// </summary>
 /// <param name="m"></param>
 public Matrix3(Matrix3 m)
 {
     x1 = m.x1; x2 = m.x2; x3 = m.x3;
     y1 = m.y1; y2 = m.y2; y3 = m.y3;
     z1 = m.z1; z2 = m.z2; z3 = m.z3;
 }