Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: code/branches/buildsystem3/src/bullet/BulletCollision/Gimpact/btQuantization.h @ 2703

Last change on this file since 2703 was 2662, checked in by rgrieder, 16 years ago

Merged presentation branch back to trunk.

  • Property svn:eol-style set to native
File size: 2.6 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
33
34
35SIMD_FORCE_INLINE void bt_calc_quantization_parameters(
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
53SIMD_FORCE_INLINE void bt_quantize_clamp(
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
72SIMD_FORCE_INLINE btVector3 bt_unquantize(
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 // GIM_VECTOR_H_INCLUDED
Note: See TracBrowser for help on using the repository browser.