diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:29:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 16:29:01 +0000 |
commit | 35a96bde514a8897f6f0fcc41c5833bf63df2e2a (patch) | |
tree | 657d15a03cc46bd099fc2c6546a7a4ad43815d9f /src/display/nr-3dutils.cpp | |
parent | Initial commit. (diff) | |
download | inkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.tar.xz inkscape-35a96bde514a8897f6f0fcc41c5833bf63df2e2a.zip |
Adding upstream version 1.0.2.upstream/1.0.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/display/nr-3dutils.cpp')
-rw-r--r-- | src/display/nr-3dutils.cpp | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/src/display/nr-3dutils.cpp b/src/display/nr-3dutils.cpp new file mode 100644 index 0000000..3c0eb5e --- /dev/null +++ b/src/display/nr-3dutils.cpp @@ -0,0 +1,66 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * 3D utils. + * + * Authors: + * Jean-Rene Reinhard <jr@komite.net> + * + * Copyright (C) 2007 authors + * + * Released under GNU GPL v2+, read the file 'COPYING' for more information. + */ + +#include <glib.h> + +#include "display/nr-3dutils.h" +#include <cmath> +#include <2geom/point.h> +#include <2geom/affine.h> + +namespace NR { + +void convert_coord(gdouble &x, gdouble &y, gdouble &z, Geom::Affine const &trans) { + Geom::Point p = Geom::Point(x, y); + p *= trans; + x = p[Geom::X]; + y = p[Geom::Y]; + z *= trans[0]; +} + +gdouble norm(const Fvector &v) { + return sqrt(v[X_3D]*v[X_3D] + v[Y_3D]*v[Y_3D] + v[Z_3D]*v[Z_3D]); +} + +void normalize_vector(Fvector &v) { + gdouble nv = norm(v); + //TODO test nv == 0 + for (int j = 0; j < 3; j++) { + v[j] /= nv; + } +} + +gdouble scalar_product(const Fvector &a, const Fvector &b) { + return a[X_3D] * b[X_3D] + + a[Y_3D] * b[Y_3D] + + a[Z_3D] * b[Z_3D]; +} + +void normalized_sum(Fvector &r, const Fvector &a, const Fvector &b) { + r[X_3D] = a[X_3D] + b[X_3D]; + r[Y_3D] = a[Y_3D] + b[Y_3D]; + r[Z_3D] = a[Z_3D] + b[Z_3D]; + normalize_vector(r); +} + +}/* namespace NR */ + +/* + Local Variables: + mode:c++ + c-file-style:"stroustrup" + c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +)) + indent-tabs-mode:nil + fill-column:99 + End: +*/ +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 : |