diff options
Diffstat (limited to 'src/gui/math3d/qmath3dutil.cpp')
-rw-r--r-- | src/gui/math3d/qmath3dutil.cpp | 164 |
1 files changed, 164 insertions, 0 deletions
diff --git a/src/gui/math3d/qmath3dutil.cpp b/src/gui/math3d/qmath3dutil.cpp new file mode 100644 index 0000000..91d4b15 --- /dev/null +++ b/src/gui/math3d/qmath3dutil.cpp @@ -0,0 +1,164 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Contact: Qt Software Information (qt-info@nokia.com) +** +** This file is part of the $MODULE$ of the Qt Toolkit. +** +** $TROLLTECH_DUAL_LICENSE$ +** +****************************************************************************/ + +#include "qmath3dutil_p.h" + +QT_BEGIN_NAMESPACE + +#ifdef QT_GL_FIXED_PREFERRED + +// The table that follows was automatically generated by the following code: +// +//#include <math.h> +//#include <stdio.h> +// +//int main() +//{ +// double angle; +// int count = 0; +// for (angle = 0.0; angle < 360.0; angle += 1.0) { +// if ((count % 4) == 0) +// printf(" "); +// printf(" qf2vt(%f)", sin(angle * M_PI / 180.0)); +// ++count; +// if (count != 360) +// printf(","); +// if ((count % 4) == 0) +// printf("\n"); +// } +// return 0; +//} + +#define qf2vt(x) (int((x) * 65536.0)) + +static int const sinTable[360] = { + qf2vt(0.000000), qf2vt(0.017452), qf2vt(0.034899), qf2vt(0.052336), + qf2vt(0.069756), qf2vt(0.087156), qf2vt(0.104528), qf2vt(0.121869), + qf2vt(0.139173), qf2vt(0.156434), qf2vt(0.173648), qf2vt(0.190809), + qf2vt(0.207912), qf2vt(0.224951), qf2vt(0.241922), qf2vt(0.258819), + qf2vt(0.275637), qf2vt(0.292372), qf2vt(0.309017), qf2vt(0.325568), + qf2vt(0.342020), qf2vt(0.358368), qf2vt(0.374607), qf2vt(0.390731), + qf2vt(0.406737), qf2vt(0.422618), qf2vt(0.438371), qf2vt(0.453990), + qf2vt(0.469472), qf2vt(0.484810), qf2vt(0.500000), qf2vt(0.515038), + qf2vt(0.529919), qf2vt(0.544639), qf2vt(0.559193), qf2vt(0.573576), + qf2vt(0.587785), qf2vt(0.601815), qf2vt(0.615661), qf2vt(0.629320), + qf2vt(0.642788), qf2vt(0.656059), qf2vt(0.669131), qf2vt(0.681998), + qf2vt(0.694658), qf2vt(0.707107), qf2vt(0.719340), qf2vt(0.731354), + qf2vt(0.743145), qf2vt(0.754710), qf2vt(0.766044), qf2vt(0.777146), + qf2vt(0.788011), qf2vt(0.798636), qf2vt(0.809017), qf2vt(0.819152), + qf2vt(0.829038), qf2vt(0.838671), qf2vt(0.848048), qf2vt(0.857167), + qf2vt(0.866025), qf2vt(0.874620), qf2vt(0.882948), qf2vt(0.891007), + qf2vt(0.898794), qf2vt(0.906308), qf2vt(0.913545), qf2vt(0.920505), + qf2vt(0.927184), qf2vt(0.933580), qf2vt(0.939693), qf2vt(0.945519), + qf2vt(0.951057), qf2vt(0.956305), qf2vt(0.961262), qf2vt(0.965926), + qf2vt(0.970296), qf2vt(0.974370), qf2vt(0.978148), qf2vt(0.981627), + qf2vt(0.984808), qf2vt(0.987688), qf2vt(0.990268), qf2vt(0.992546), + qf2vt(0.994522), qf2vt(0.996195), qf2vt(0.997564), qf2vt(0.998630), + qf2vt(0.999391), qf2vt(0.999848), qf2vt(1.000000), qf2vt(0.999848), + qf2vt(0.999391), qf2vt(0.998630), qf2vt(0.997564), qf2vt(0.996195), + qf2vt(0.994522), qf2vt(0.992546), qf2vt(0.990268), qf2vt(0.987688), + qf2vt(0.984808), qf2vt(0.981627), qf2vt(0.978148), qf2vt(0.974370), + qf2vt(0.970296), qf2vt(0.965926), qf2vt(0.961262), qf2vt(0.956305), + qf2vt(0.951057), qf2vt(0.945519), qf2vt(0.939693), qf2vt(0.933580), + qf2vt(0.927184), qf2vt(0.920505), qf2vt(0.913545), qf2vt(0.906308), + qf2vt(0.898794), qf2vt(0.891007), qf2vt(0.882948), qf2vt(0.874620), + qf2vt(0.866025), qf2vt(0.857167), qf2vt(0.848048), qf2vt(0.838671), + qf2vt(0.829038), qf2vt(0.819152), qf2vt(0.809017), qf2vt(0.798636), + qf2vt(0.788011), qf2vt(0.777146), qf2vt(0.766044), qf2vt(0.754710), + qf2vt(0.743145), qf2vt(0.731354), qf2vt(0.719340), qf2vt(0.707107), + qf2vt(0.694658), qf2vt(0.681998), qf2vt(0.669131), qf2vt(0.656059), + qf2vt(0.642788), qf2vt(0.629320), qf2vt(0.615661), qf2vt(0.601815), + qf2vt(0.587785), qf2vt(0.573576), qf2vt(0.559193), qf2vt(0.544639), + qf2vt(0.529919), qf2vt(0.515038), qf2vt(0.500000), qf2vt(0.484810), + qf2vt(0.469472), qf2vt(0.453990), qf2vt(0.438371), qf2vt(0.422618), + qf2vt(0.406737), qf2vt(0.390731), qf2vt(0.374607), qf2vt(0.358368), + qf2vt(0.342020), qf2vt(0.325568), qf2vt(0.309017), qf2vt(0.292372), + qf2vt(0.275637), qf2vt(0.258819), qf2vt(0.241922), qf2vt(0.224951), + qf2vt(0.207912), qf2vt(0.190809), qf2vt(0.173648), qf2vt(0.156434), + qf2vt(0.139173), qf2vt(0.121869), qf2vt(0.104528), qf2vt(0.087156), + qf2vt(0.069756), qf2vt(0.052336), qf2vt(0.034899), qf2vt(0.017452), + qf2vt(0.000000), qf2vt(-0.017452), qf2vt(-0.034899), qf2vt(-0.052336), + qf2vt(-0.069756), qf2vt(-0.087156), qf2vt(-0.104528), qf2vt(-0.121869), + qf2vt(-0.139173), qf2vt(-0.156434), qf2vt(-0.173648), qf2vt(-0.190809), + qf2vt(-0.207912), qf2vt(-0.224951), qf2vt(-0.241922), qf2vt(-0.258819), + qf2vt(-0.275637), qf2vt(-0.292372), qf2vt(-0.309017), qf2vt(-0.325568), + qf2vt(-0.342020), qf2vt(-0.358368), qf2vt(-0.374607), qf2vt(-0.390731), + qf2vt(-0.406737), qf2vt(-0.422618), qf2vt(-0.438371), qf2vt(-0.453990), + qf2vt(-0.469472), qf2vt(-0.484810), qf2vt(-0.500000), qf2vt(-0.515038), + qf2vt(-0.529919), qf2vt(-0.544639), qf2vt(-0.559193), qf2vt(-0.573576), + qf2vt(-0.587785), qf2vt(-0.601815), qf2vt(-0.615661), qf2vt(-0.629320), + qf2vt(-0.642788), qf2vt(-0.656059), qf2vt(-0.669131), qf2vt(-0.681998), + qf2vt(-0.694658), qf2vt(-0.707107), qf2vt(-0.719340), qf2vt(-0.731354), + qf2vt(-0.743145), qf2vt(-0.754710), qf2vt(-0.766044), qf2vt(-0.777146), + qf2vt(-0.788011), qf2vt(-0.798636), qf2vt(-0.809017), qf2vt(-0.819152), + qf2vt(-0.829038), qf2vt(-0.838671), qf2vt(-0.848048), qf2vt(-0.857167), + qf2vt(-0.866025), qf2vt(-0.874620), qf2vt(-0.882948), qf2vt(-0.891007), + qf2vt(-0.898794), qf2vt(-0.906308), qf2vt(-0.913545), qf2vt(-0.920505), + qf2vt(-0.927184), qf2vt(-0.933580), qf2vt(-0.939693), qf2vt(-0.945519), + qf2vt(-0.951057), qf2vt(-0.956305), qf2vt(-0.961262), qf2vt(-0.965926), + qf2vt(-0.970296), qf2vt(-0.974370), qf2vt(-0.978148), qf2vt(-0.981627), + qf2vt(-0.984808), qf2vt(-0.987688), qf2vt(-0.990268), qf2vt(-0.992546), + qf2vt(-0.994522), qf2vt(-0.996195), qf2vt(-0.997564), qf2vt(-0.998630), + qf2vt(-0.999391), qf2vt(-0.999848), qf2vt(-1.000000), qf2vt(-0.999848), + qf2vt(-0.999391), qf2vt(-0.998630), qf2vt(-0.997564), qf2vt(-0.996195), + qf2vt(-0.994522), qf2vt(-0.992546), qf2vt(-0.990268), qf2vt(-0.987688), + qf2vt(-0.984808), qf2vt(-0.981627), qf2vt(-0.978148), qf2vt(-0.974370), + qf2vt(-0.970296), qf2vt(-0.965926), qf2vt(-0.961262), qf2vt(-0.956305), + qf2vt(-0.951057), qf2vt(-0.945519), qf2vt(-0.939693), qf2vt(-0.933580), + qf2vt(-0.927184), qf2vt(-0.920505), qf2vt(-0.913545), qf2vt(-0.906308), + qf2vt(-0.898794), qf2vt(-0.891007), qf2vt(-0.882948), qf2vt(-0.874620), + qf2vt(-0.866025), qf2vt(-0.857167), qf2vt(-0.848048), qf2vt(-0.838671), + qf2vt(-0.829038), qf2vt(-0.819152), qf2vt(-0.809017), qf2vt(-0.798636), + qf2vt(-0.788011), qf2vt(-0.777146), qf2vt(-0.766044), qf2vt(-0.754710), + qf2vt(-0.743145), qf2vt(-0.731354), qf2vt(-0.719340), qf2vt(-0.707107), + qf2vt(-0.694658), qf2vt(-0.681998), qf2vt(-0.669131), qf2vt(-0.656059), + qf2vt(-0.642788), qf2vt(-0.629320), qf2vt(-0.615661), qf2vt(-0.601815), + qf2vt(-0.587785), qf2vt(-0.573576), qf2vt(-0.559193), qf2vt(-0.544639), + qf2vt(-0.529919), qf2vt(-0.515038), qf2vt(-0.500000), qf2vt(-0.484810), + qf2vt(-0.469472), qf2vt(-0.453990), qf2vt(-0.438371), qf2vt(-0.422618), + qf2vt(-0.406737), qf2vt(-0.390731), qf2vt(-0.374607), qf2vt(-0.358368), + qf2vt(-0.342020), qf2vt(-0.325568), qf2vt(-0.309017), qf2vt(-0.292372), + qf2vt(-0.275637), qf2vt(-0.258819), qf2vt(-0.241922), qf2vt(-0.224951), + qf2vt(-0.207912), qf2vt(-0.190809), qf2vt(-0.173648), qf2vt(-0.156434), + qf2vt(-0.139173), qf2vt(-0.121869), qf2vt(-0.104528), qf2vt(-0.087156), + qf2vt(-0.069756), qf2vt(-0.052336), qf2vt(-0.034899), qf2vt(-0.017452) +}; + +void qt_math3d_sincos(qreal angle, qrealinner *s, qrealinner *c) +{ + if (angle == qFloor(angle)) { + // The angle is an integer number of degrees, so look up the results. + int a = (int)angle; + if (a >= 0) + a = (a % 360); + else + a = 360 - (-a % 360); + s->setBits(sinTable[a]); + c->setBits(sinTable[(a + 90) % 360]); + } else { + qreal a = angle * M_PI / 180.0f; + *s = qSin(a); + *c = qCos(a); + } +} + +#else + +void qt_math3d_sincos(qreal angle, qrealinner *s, qrealinner *c) +{ + qreal a = angle * M_PI / 180.0f; + *s = qSin(a); + *c = qCos(a); +} + +#endif + +QT_END_NAMESPACE |