Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
prototypeVec4d.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: 14819 $ *
45 * $LastChangedBy: moebius $ *
46 * $Date: 2012-06-29 13:42:49 +0200 (Fr, 29 Jun 2012) $ *
47 * *
48 \*===========================================================================*/
49 
50 
51 
52 
53 //
54 // C++ Interface: prototypeVec4d
55 //
56 // Description:
57 //
58 //
59 // Author: Jan Möbius <moebius@cs.rwth-aachen.de>, (C) 2007
60 //
61 
62 #define PROTOTYPEVEC4D_C
63 
64 #include "prototypeVec4d.hh"
65 
66 prototypeVec4d::prototypeVec4d(QObject *parent ) :
67  QObject(parent)
68 {
69 
70 }
71 
72 QString prototypeVec4d::toString() const {
73  return "Vector : ( " +
74  thisObject().property("x").toString() + "," +
75  thisObject().property("y").toString() + "," +
76  thisObject().property("z").toString() + "," +
77  thisObject().property("w").toString() + " )";
78 }
79 
80 void prototypeVec4d::multiply(QScriptValue _scalar) {
81  thisObject().setProperty("x", QScriptValue(thisObject().property("x").toNumber() * _scalar.toNumber()));
82  thisObject().setProperty("y", QScriptValue(thisObject().property("y").toNumber() * _scalar.toNumber()));
83  thisObject().setProperty("z", QScriptValue(thisObject().property("z").toNumber() * _scalar.toNumber()));
84  thisObject().setProperty("w", QScriptValue(thisObject().property("w").toNumber() * _scalar.toNumber()));
85 }
86 
87 void prototypeVec4d::add(QScriptValue _vector) {
88  thisObject().setProperty("x", QScriptValue(_vector.property("x").toNumber() + thisObject().property("x").toNumber()));
89  thisObject().setProperty("y", QScriptValue(_vector.property("y").toNumber() + thisObject().property("y").toNumber()));
90  thisObject().setProperty("z", QScriptValue(_vector.property("z").toNumber() + thisObject().property("z").toNumber()));
91  thisObject().setProperty("w", QScriptValue(_vector.property("w").toNumber() + thisObject().property("w").toNumber()));
92 }
93 
94 
95 void prototypeVec4d::sub(QScriptValue _vector) {
96  thisObject().setProperty("x", QScriptValue(thisObject().property("x").toNumber() - _vector.property("x").toNumber()));
97  thisObject().setProperty("y", QScriptValue(thisObject().property("y").toNumber() - _vector.property("y").toNumber()));
98  thisObject().setProperty("z", QScriptValue(thisObject().property("z").toNumber() - _vector.property("z").toNumber()));
99  thisObject().setProperty("w", QScriptValue(thisObject().property("w").toNumber() - _vector.property("w").toNumber()));
100 }
101 
103  thisObject().setProperty("x", QScriptValue(0.0));
104  thisObject().setProperty("y", QScriptValue(0.0));
105  thisObject().setProperty("z", QScriptValue(0.0));
106  thisObject().setProperty("w", QScriptValue(0.0));
107 }
108 
109 QScriptValue prototypeVec4d::sprod(QScriptValue _vector) {
110  return QScriptValue( thisObject().property("x").toNumber() * _vector.property("x").toNumber() +
111  thisObject().property("y").toNumber() * _vector.property("y").toNumber() +
112  thisObject().property("z").toNumber() * _vector.property("z").toNumber() +
113  thisObject().property("w").toNumber() * _vector.property("w").toNumber() );
114 
115 }
116 
117 QScriptValue prototypeVec4d::norm() {
118  return QScriptValue( sqrt( thisObject().property("x").toNumber() * thisObject().property("x").toNumber() +
119  thisObject().property("y").toNumber() * thisObject().property("y").toNumber() +
120  thisObject().property("z").toNumber() * thisObject().property("z").toNumber() +
121  thisObject().property("w").toNumber() * thisObject().property("w").toNumber() ) );
122 }
123 
124 QScriptValue prototypeVec4d::sqrnorm() {
125  return QScriptValue( thisObject().property("x").toNumber() * thisObject().property("x").toNumber() +
126  thisObject().property("y").toNumber() * thisObject().property("y").toNumber() +
127  thisObject().property("z").toNumber() * thisObject().property("z").toNumber() +
128  thisObject().property("w").toNumber() * thisObject().property("w").toNumber() );
129 }
130 
132  double length = sqrt( thisObject().property("x").toNumber() * thisObject().property("x").toNumber() +
133  thisObject().property("y").toNumber() * thisObject().property("y").toNumber() +
134  thisObject().property("z").toNumber() * thisObject().property("z").toNumber() +
135  thisObject().property("w").toNumber() * thisObject().property("w").toNumber() );
136 
137  if ( length != 0.0 ) {
138  thisObject().setProperty("x", ( thisObject().property("x").toNumber() / length ) );
139  thisObject().setProperty("y", ( thisObject().property("y").toNumber() / length ) );
140  thisObject().setProperty("z", ( thisObject().property("z").toNumber() / length ) );
141  thisObject().setProperty("w", ( thisObject().property("w").toNumber() / length ) );
142  }
143 
144 
145 }
146 
void sub(QScriptValue _vector)
Subtracts another vector from this vector.
QScriptValue sprod(QScriptValue _vector)
Calculate scalar product.
QScriptValue sqrnorm()
Calculate the squared Euclidean norm of the vector.
void add(QScriptValue _vector)
Adds another vector to this vector.
void zero()
Resets all components of the vector to zero.
void normalize()
Normalize the vector.
void multiply(QScriptValue _scalar)
Multiplies the given vector with the scalar.
QScriptValue norm()
Calculate the Euclidean norm of the vector.