Blender V2.61 - r43446

btQuantization.h

Go to the documentation of this file.
00001 #ifndef BT_QUANTIZATION_H_INCLUDED
00002 #define BT_QUANTIZATION_H_INCLUDED
00003 
00008 /*
00009 This source file is part of GIMPACT Library.
00010 
00011 For the latest info, see http://gimpact.sourceforge.net/
00012 
00013 Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
00014 email: projectileman@yahoo.com
00015 
00016 
00017 This software is provided 'as-is', without any express or implied warranty.
00018 In no event will the authors be held liable for any damages arising from the use of this software.
00019 Permission is granted to anyone to use this software for any purpose,
00020 including commercial applications, and to alter it and redistribute it freely,
00021 subject to the following restrictions:
00022 
00023 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.
00024 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
00025 3. This notice may not be removed or altered from any source distribution.
00026 */
00027 
00028 #include "LinearMath/btTransform.h"
00029 
00030 
00031 
00032 
00033 
00034 
00035 SIMD_FORCE_INLINE void bt_calc_quantization_parameters(
00036     btVector3 & outMinBound,
00037     btVector3 & outMaxBound,
00038     btVector3 & bvhQuantization,
00039     const btVector3& srcMinBound,const btVector3& srcMaxBound,
00040     btScalar quantizationMargin)
00041 {
00042     //enlarge the AABB to avoid division by zero when initializing the quantization values
00043     btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin);
00044     outMinBound = srcMinBound - clampValue;
00045     outMaxBound = srcMaxBound + clampValue;
00046     btVector3 aabbSize = outMaxBound - outMinBound;
00047     bvhQuantization = btVector3(btScalar(65535.0),
00048                                 btScalar(65535.0),
00049                                 btScalar(65535.0)) / aabbSize;
00050 }
00051 
00052 
00053 SIMD_FORCE_INLINE void bt_quantize_clamp(
00054     unsigned short* out,
00055     const btVector3& point,
00056     const btVector3 & min_bound,
00057     const btVector3 & max_bound,
00058     const btVector3 & bvhQuantization)
00059 {
00060 
00061     btVector3 clampedPoint(point);
00062     clampedPoint.setMax(min_bound);
00063     clampedPoint.setMin(max_bound);
00064 
00065     btVector3 v = (clampedPoint - min_bound) * bvhQuantization;
00066     out[0] = (unsigned short)(v.getX()+0.5f);
00067     out[1] = (unsigned short)(v.getY()+0.5f);
00068     out[2] = (unsigned short)(v.getZ()+0.5f);
00069 }
00070 
00071 
00072 SIMD_FORCE_INLINE btVector3 bt_unquantize(
00073     const unsigned short* vecIn,
00074     const btVector3 & offset,
00075     const btVector3 & bvhQuantization)
00076 {
00077     btVector3   vecOut;
00078     vecOut.setValue(
00079         (btScalar)(vecIn[0]) / (bvhQuantization.getX()),
00080         (btScalar)(vecIn[1]) / (bvhQuantization.getY()),
00081         (btScalar)(vecIn[2]) / (bvhQuantization.getZ()));
00082     vecOut += offset;
00083     return vecOut;
00084 }
00085 
00086 
00087 
00088 #endif // GIM_VECTOR_H_INCLUDED