Developer Documentation

prototypeMatrix4x4.cc
1 /*===========================================================================*\
2 * *
3 * OpenFlipper *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openflipper.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenFlipper. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 \*===========================================================================*/
41
42
43 #define PROTOTYPEMATRIX4X4_C
44
45 #include "prototypeMatrix4x4.hh"
46
47 prototypeMatrix4x4::prototypeMatrix4x4(QObject *parent ) :
48 QObject(parent)
49 {
50
51 }
52
53 QString prototypeMatrix4x4::toString() const {
54
55 QString result = "Matrix4x4 : \n";
56
57 for ( uint i = 0 ; i < 4 ; ++i ) {
58 for ( uint j = 0 ; j < 4 ; ++j ) {
59 result = result + thisObject().property(QString::number(i) + QString::number(j)).toString() + " ";
60 }
61
62 // Don't add a newline at the end of the Matrix
63 if ( i != 3 )
64 result += "\n";
65 }
66
67 return result;
68 }
69
70 QScriptValue prototypeMatrix4x4::transform_vector(QScriptValue _vector )
71 {
72
73 // Convert from this objects properties to the matrix representation
74 Matrix4x4 matrix;
75 for ( uint i = 0 ; i < 4 ; ++i )
76 for ( uint j = 0 ; j < 4 ; ++j )
77 matrix(i,j) = thisObject().property(QString::number(i) + QString::number(j)).toNumber();
78
79 // Convert the vector from scripting representation to C++
80 ACG::Vec3d vector(_vector.property("x").toNumber(),_vector.property("y").toNumber(),_vector.property("z").toNumber());
81
82 // Calculate result vector
83 ACG::Vec3d result = matrix.transform_vector(vector);
84
85 // Transform back to scriptable vector
86 return QScriptValue( engine()->toScriptValue(result) );
87
88 }
89
90 QScriptValue prototypeMatrix4x4::transform_point(QScriptValue _vector )
91 {
92
93 // Convert from this objects properties to the matrix representation
94 Matrix4x4 matrix;
95 for ( uint i = 0 ; i < 4 ; ++i )
96 for ( uint j = 0 ; j < 4 ; ++j )
97 matrix(i,j) = thisObject().property(QString::number(i) + QString::number(j)).toNumber();
98
99 // Convert the vector from scripting representation to C++
100 ACG::Vec3d vector(_vector.property("x").toNumber(),_vector.property("y").toNumber(),_vector.property("z").toNumber());
101
102 // Calculate result vector
103 const ACG::Vec3d result = matrix.transform_point(vector);
104
105 // Transform back to scriptable vector
106 return QScriptValue( engine()->toScriptValue(result) );
107
108 }
109
prototypeMatrix4x4::transform_point
QScriptValue transform_point(QScriptValue _vector)
Matrix vector product.
Definition: prototypeMatrix4x4.cc:90
ACG::Matrix4x4T::transform_point
VectorT< T, 3 > transform_point(const VectorT< T, 3 > &_v) const
transform point (x&#39;,y&#39;,z&#39;,1) = M * (x,y,z,1)
Definition: Matrix4x4T_impl.hh:196
prototypeMatrix4x4::transform_vector
QScriptValue transform_vector(QScriptValue _vector)
Matrix vector product.
Definition: prototypeMatrix4x4.cc:70
ACG::Matrix4x4T< double >
OpenMesh::VectorT
Definition: Vector11T.hh:83
ACG::Matrix4x4T::transform_vector
VectorT< T, 3 > transform_vector(const VectorT< T, 3 > &_v) const
transform vector (x&#39;,y&#39;,z&#39;,0) = A * (x,y,z,0)
Definition: Matrix4x4T_impl.hh:219