Go to the documentation of this file.00001 #ifndef BT_GIMPACT_QUANTIZATION_H_INCLUDED
00002 #define BT_GIMPACT_QUANTIZATION_H_INCLUDED
00003
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
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
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 // BT_GIMPACT_QUANTIZATION_H_INCLUDED