boxBoxDistance.h

Go to the documentation of this file.
00001 /*
00002    Copyright (C) 2006, 2008 Sony Computer Entertainment Inc.
00003    All rights reserved.
00004 
00005 This software is provided 'as-is', without any express or implied warranty.
00006 In no event will the authors be held liable for any damages arising from the use of this software.
00007 Permission is granted to anyone to use this software for any purpose, 
00008 including commercial applications, and to alter it and redistribute it freely, 
00009 subject to the following restrictions:
00010 
00011 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
00012 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00013 3. This notice may not be removed or altered from any source distribution.
00014 
00015 */
00016 
00017 
00018 #ifndef __BOXBOXDISTANCE_H__
00019 #define __BOXBOXDISTANCE_H__
00020 
00021 
00022 #include "Box.h"
00023 
00024 
00025 //---------------------------------------------------------------------------
00026 // boxBoxDistance:
00027 //
00028 // description:
00029 //    this computes info that can be used for the collision response of two boxes.  when the boxes
00030 //    do not overlap, the points are set to the closest points of the boxes, and a positive
00031 //    distance between them is returned.  if the boxes do overlap, a negative distance is returned
00032 //    and the points are set to two points that would touch after the boxes are translated apart.
00033 //    the contact normal gives the direction to repel or separate the boxes when they touch or
00034 //    overlap (it's being approximated here as one of the 15 "separating axis" directions).
00035 //
00036 // returns:
00037 //    positive or negative distance between two boxes.
00038 //
00039 // args:
00040 //    vmVector3& normal: set to a unit contact normal pointing from box A to box B.
00041 //
00042 //    BoxPoint& boxPointA, BoxPoint& boxPointB:
00043 //       set to a closest point or point of penetration on each box.
00044 //
00045 //    Box boxA, Box boxB:
00046 //       boxes, represented as 3 half-widths
00047 //
00048 //    const vmTransform3& transformA, const vmTransform3& transformB:
00049 //       box transformations, in world coordinates
00050 //
00051 //    float distanceThreshold:
00052 //       the algorithm will exit early if it finds that the boxes are more distant than this
00053 //       threshold, and not compute a contact normal or points.  if this distance returned
00054 //       exceeds the threshold, all the other output data may not have been computed.  by
00055 //       default, this is set to MAX_FLOAT so it will have no effect.
00056 //
00057 //---------------------------------------------------------------------------
00058 
00059 float
00060 boxBoxDistance(vmVector3& normal, BoxPoint& boxPointA, BoxPoint& boxPointB,
00061                            PE_REF(Box) boxA, const vmTransform3 & transformA, PE_REF(Box) boxB,
00062                            const vmTransform3 & transformB,
00063                            float distanceThreshold = FLT_MAX );
00064 
00065 #endif /* __BOXBOXDISTANCE_H__ */