Bullet Collision Detection & Physics Library
btQuantization.h
Go to the documentation of this file.
1 #ifndef BT_GIMPACT_QUANTIZATION_H_INCLUDED
2 #define BT_GIMPACT_QUANTIZATION_H_INCLUDED
3 
8 /*
9 This source file is part of GIMPACT Library.
10 
11 For the latest info, see http://gimpact.sourceforge.net/
12 
13 Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
14 email: projectileman@yahoo.com
15 
16 
17 This software is provided 'as-is', without any express or implied warranty.
18 In no event will the authors be held liable for any damages arising from the use of this software.
19 Permission is granted to anyone to use this software for any purpose,
20 including commercial applications, and to alter it and redistribute it freely,
21 subject to the following restrictions:
22 
23 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.
24 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
25 3. This notice may not be removed or altered from any source distribution.
26 */
27 
28 #include "LinearMath/btTransform.h"
29 
30 
31 
32 
33 
34 
36  btVector3 & outMinBound,
37  btVector3 & outMaxBound,
38  btVector3 & bvhQuantization,
39  const btVector3& srcMinBound,const btVector3& srcMaxBound,
40  btScalar quantizationMargin)
41 {
42  //enlarge the AABB to avoid division by zero when initializing the quantization values
43  btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin);
44  outMinBound = srcMinBound - clampValue;
45  outMaxBound = srcMaxBound + clampValue;
46  btVector3 aabbSize = outMaxBound - outMinBound;
47  bvhQuantization = btVector3(btScalar(65535.0),
48  btScalar(65535.0),
49  btScalar(65535.0)) / aabbSize;
50 }
51 
52 
54  unsigned short* out,
55  const btVector3& point,
56  const btVector3 & min_bound,
57  const btVector3 & max_bound,
58  const btVector3 & bvhQuantization)
59 {
60 
61  btVector3 clampedPoint(point);
62  clampedPoint.setMax(min_bound);
63  clampedPoint.setMin(max_bound);
64 
65  btVector3 v = (clampedPoint - min_bound) * bvhQuantization;
66  out[0] = (unsigned short)(v.getX()+0.5f);
67  out[1] = (unsigned short)(v.getY()+0.5f);
68  out[2] = (unsigned short)(v.getZ()+0.5f);
69 }
70 
71 
73  const unsigned short* vecIn,
74  const btVector3 & offset,
75  const btVector3 & bvhQuantization)
76 {
77  btVector3 vecOut;
78  vecOut.setValue(
79  (btScalar)(vecIn[0]) / (bvhQuantization.getX()),
80  (btScalar)(vecIn[1]) / (bvhQuantization.getY()),
81  (btScalar)(vecIn[2]) / (bvhQuantization.getZ()));
82  vecOut += offset;
83  return vecOut;
84 }
85 
86 
87 
88 #endif // BT_GIMPACT_QUANTIZATION_H_INCLUDED
void setValue(const btScalar &_x, const btScalar &_y, const btScalar &_z)
Definition: btVector3.h:640
#define SIMD_FORCE_INLINE
Definition: btScalar.h:58
btVector3 bt_unquantize(const unsigned short *vecIn, const btVector3 &offset, const btVector3 &bvhQuantization)
const btScalar & getZ() const
Return the z value.
Definition: btVector3.h:565
void bt_quantize_clamp(unsigned short *out, const btVector3 &point, const btVector3 &min_bound, const btVector3 &max_bound, const btVector3 &bvhQuantization)
const btScalar & getY() const
Return the y value.
Definition: btVector3.h:563
const btScalar & getX() const
Return the x value.
Definition: btVector3.h:561
btVector3 can be used to represent 3D points and vectors.
Definition: btVector3.h:83
void bt_calc_quantization_parameters(btVector3 &outMinBound, btVector3 &outMaxBound, btVector3 &bvhQuantization, const btVector3 &srcMinBound, const btVector3 &srcMaxBound, btScalar quantizationMargin)
void setMax(const btVector3 &other)
Set each element to the max of the current values and the values of another btVector3.
Definition: btVector3.h:609
void setMin(const btVector3 &other)
Set each element to the min of the current values and the values of another btVector3.
Definition: btVector3.h:626
float btScalar
The btScalar type abstracts floating point numbers, to easily switch between double and single floati...
Definition: btScalar.h:266