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 * *
44 * $Revision$ *
45 * $LastChangedBy$ *
46 * $Date$ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //
54 // C++ Interface: prototypeVec3d
55 //
56 // Description:
57 //
58 //
59 // Author: Jan Möbius <moebius@cs.rwth-aachen.de>, (C) 2007
60 //
61 
62 #define PROTOTYPEMATRIX4X4_C
63 
64 #include "prototypeMatrix4x4.hh"
65 
66 prototypeMatrix4x4::prototypeMatrix4x4(QObject *parent ) :
67  QObject(parent)
68 {
69 
70 }
71 
72 QString prototypeMatrix4x4::toString() const {
73 
74  QString result = "Matrix4x4 : \n";
75 
76  for ( uint i = 0 ; i < 4 ; ++i ) {
77  for ( uint j = 0 ; j < 4 ; ++j ) {
78  result = result + thisObject().property(QString::number(i) + QString::number(j)).toString() + " ";
79  }
80 
81  // Don't add a newline at the end of the Matrix
82  if ( i != 3 )
83  result += "\n";
84  }
85 
86  return result;
87 }
88 
89 QScriptValue prototypeMatrix4x4::transform_vector(QScriptValue _vector )
90 {
91 
92  // Convert from this objects properties to the matrix representation
93  Matrix4x4 matrix;
94  for ( uint i = 0 ; i < 4 ; ++i )
95  for ( uint j = 0 ; j < 4 ; ++j )
96  matrix(i,j) = thisObject().property(QString::number(i) + QString::number(j)).toNumber();
97 
98  // Convert the vector from scripting representation to C++
99  ACG::Vec3d vector(_vector.property("x").toNumber(),_vector.property("y").toNumber(),_vector.property("z").toNumber());
100 
101  // Calculate result vector
102  ACG::Vec3d result = matrix.transform_vector(vector);
103 
104  // Transform back to scriptable vector
105  return QScriptValue( engine()->toScriptValue(result) );
106 
107 }
108 
109 QScriptValue prototypeMatrix4x4::transform_point(QScriptValue _vector )
110 {
111 
112  // Convert from this objects properties to the matrix representation
113  Matrix4x4 matrix;
114  for ( uint i = 0 ; i < 4 ; ++i )
115  for ( uint j = 0 ; j < 4 ; ++j )
116  matrix(i,j) = thisObject().property(QString::number(i) + QString::number(j)).toNumber();
117 
118  // Convert the vector from scripting representation to C++
119  ACG::Vec3d vector(_vector.property("x").toNumber(),_vector.property("y").toNumber(),_vector.property("z").toNumber());
120 
121  // Calculate result vector
122  const ACG::Vec3d result = matrix.transform_point(vector);
123 
124  // Transform back to scriptable vector
125  return QScriptValue( engine()->toScriptValue(result) );
126 
127 }
128 
QScriptValue transform_vector(QScriptValue _vector)
Matrix vector product.
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.cc:202
QScriptValue transform_point(QScriptValue _vector)
Matrix vector product.
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.cc:225