Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/physics/src/bullet/BulletCollision/GIMPACT/btQuantization.h @ 2041

Last change on this file since 2041 was 1963, checked in by rgrieder, 16 years ago

Added Bullet physics engine.

  • Property svn:eol-style set to native
File size: 2.7 KB
Line 
1#ifndef BT_QUANTIZATION_H_INCLUDED
2#define BT_QUANTIZATION_H_INCLUDED
3
4/*! \file btQuantization.h
5*\author Francisco Len Nßjera
6
7*/
8/*
9This source file is part of GIMPACT Library.
10
11For the latest info, see http://gimpact.sourceforge.net/
12
13Copyright (c) 2007 Francisco Leon Najera. C.C. 80087371.
14email: projectileman@yahoo.com
15
16
17This software is provided 'as-is', without any express or implied warranty.
18In no event will the authors be held liable for any damages arising from the use of this software.
19Permission is granted to anyone to use this software for any purpose,
20including commercial applications, and to alter it and redistribute it freely,
21subject to the following restrictions:
22
231. 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.
242. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
253. This notice may not be removed or altered from any source distribution.
26*/
27
28#include "LinearMath/btTransform.h"
29
30
31
32/*! \defgroup GEOMETRIC_OPERATIONS
33*/
34//! @{
35
36
37
38SIMD_FORCE_INLINE void bt_calc_quantization_parameters(
39        btVector3 & outMinBound,
40        btVector3 & outMaxBound,
41        btVector3 & bvhQuantization,
42        const btVector3& srcMinBound,const btVector3& srcMaxBound,
43        btScalar quantizationMargin)
44{
45        //enlarge the AABB to avoid division by zero when initializing the quantization values
46        btVector3 clampValue(quantizationMargin,quantizationMargin,quantizationMargin);
47        outMinBound = srcMinBound - clampValue;
48        outMaxBound = srcMaxBound + clampValue;
49        btVector3 aabbSize = outMaxBound - outMinBound;
50        bvhQuantization = btVector3(btScalar(65535.0),
51                                                                btScalar(65535.0),
52                                                                btScalar(65535.0)) / aabbSize;
53}
54
55
56SIMD_FORCE_INLINE void bt_quantize_clamp(
57        unsigned short* out,
58        const btVector3& point,
59        const btVector3 & min_bound,
60        const btVector3 & max_bound,
61        const btVector3 & bvhQuantization)
62{
63
64        btVector3 clampedPoint(point);
65        clampedPoint.setMax(min_bound);
66        clampedPoint.setMin(max_bound);
67
68        btVector3 v = (clampedPoint - min_bound) * bvhQuantization;
69        out[0] = (unsigned short)(v.getX()+0.5f);
70        out[1] = (unsigned short)(v.getY()+0.5f);
71        out[2] = (unsigned short)(v.getZ()+0.5f);
72}
73
74
75SIMD_FORCE_INLINE btVector3 bt_unquantize(
76        const unsigned short* vecIn,
77        const btVector3 & offset,
78        const btVector3 & bvhQuantization)
79{
80        btVector3       vecOut;
81        vecOut.setValue(
82                (btScalar)(vecIn[0]) / (bvhQuantization.getX()),
83                (btScalar)(vecIn[1]) / (bvhQuantization.getY()),
84                (btScalar)(vecIn[2]) / (bvhQuantization.getZ()));
85        vecOut += offset;
86        return vecOut;
87}
88
89//! @}
90
91
92#endif // GIM_VECTOR_H_INCLUDED
Note: See TracBrowser for help on using the repository browser.