Developer Documentation

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 #define PROTOTYPEVEC4D_C
43
44 #include "prototypeVec4d.hh"
45
46 prototypeVec4d::prototypeVec4d(QObject *parent ) :
47 QObject(parent)
48 {
49
50 }
51
52 QString prototypeVec4d::toString() const {
53 return "Vector : ( " +
54 thisObject().property("x").toString() + "," +
55 thisObject().property("y").toString() + "," +
56 thisObject().property("z").toString() + "," +
57 thisObject().property("w").toString() + " )";
58 }
59
60 void prototypeVec4d::multiply(QScriptValue _scalar) {
61 thisObject().setProperty("x", QScriptValue(thisObject().property("x").toNumber() * _scalar.toNumber()));
62 thisObject().setProperty("y", QScriptValue(thisObject().property("y").toNumber() * _scalar.toNumber()));
63 thisObject().setProperty("z", QScriptValue(thisObject().property("z").toNumber() * _scalar.toNumber()));
64 thisObject().setProperty("w", QScriptValue(thisObject().property("w").toNumber() * _scalar.toNumber()));
65 }
66
67 void prototypeVec4d::add(QScriptValue _vector) {
68 thisObject().setProperty("x", QScriptValue(_vector.property("x").toNumber() + thisObject().property("x").toNumber()));
69 thisObject().setProperty("y", QScriptValue(_vector.property("y").toNumber() + thisObject().property("y").toNumber()));
70 thisObject().setProperty("z", QScriptValue(_vector.property("z").toNumber() + thisObject().property("z").toNumber()));
71 thisObject().setProperty("w", QScriptValue(_vector.property("w").toNumber() + thisObject().property("w").toNumber()));
72 }
73
74
75 void prototypeVec4d::sub(QScriptValue _vector) {
76 thisObject().setProperty("x", QScriptValue(thisObject().property("x").toNumber() - _vector.property("x").toNumber()));
77 thisObject().setProperty("y", QScriptValue(thisObject().property("y").toNumber() - _vector.property("y").toNumber()));
78 thisObject().setProperty("z", QScriptValue(thisObject().property("z").toNumber() - _vector.property("z").toNumber()));
79 thisObject().setProperty("w", QScriptValue(thisObject().property("w").toNumber() - _vector.property("w").toNumber()));
80 }
81
82 void prototypeVec4d::zero() {
83 thisObject().setProperty("x", QScriptValue(0.0));
84 thisObject().setProperty("y", QScriptValue(0.0));
85 thisObject().setProperty("z", QScriptValue(0.0));
86 thisObject().setProperty("w", QScriptValue(0.0));
87 }
88
89 QScriptValue prototypeVec4d::sprod(QScriptValue _vector) {
90 return QScriptValue( thisObject().property("x").toNumber() * _vector.property("x").toNumber() +
91 thisObject().property("y").toNumber() * _vector.property("y").toNumber() +
92 thisObject().property("z").toNumber() * _vector.property("z").toNumber() +
93 thisObject().property("w").toNumber() * _vector.property("w").toNumber() );
94
95 }
96
97 QScriptValue prototypeVec4d::norm() {
98 return QScriptValue( sqrt( thisObject().property("x").toNumber() * thisObject().property("x").toNumber() +
99 thisObject().property("y").toNumber() * thisObject().property("y").toNumber() +
100 thisObject().property("z").toNumber() * thisObject().property("z").toNumber() +
101 thisObject().property("w").toNumber() * thisObject().property("w").toNumber() ) );
102 }
103
104 QScriptValue prototypeVec4d::sqrnorm() {
105 return QScriptValue( thisObject().property("x").toNumber() * thisObject().property("x").toNumber() +
106 thisObject().property("y").toNumber() * thisObject().property("y").toNumber() +
107 thisObject().property("z").toNumber() * thisObject().property("z").toNumber() +
108 thisObject().property("w").toNumber() * thisObject().property("w").toNumber() );
109 }
110
111 void prototypeVec4d::normalize() {
112 double length = sqrt( thisObject().property("x").toNumber() * thisObject().property("x").toNumber() +
113 thisObject().property("y").toNumber() * thisObject().property("y").toNumber() +
114 thisObject().property("z").toNumber() * thisObject().property("z").toNumber() +
115 thisObject().property("w").toNumber() * thisObject().property("w").toNumber() );
116
117 if ( length != 0.0 ) {
118 thisObject().setProperty("x", ( thisObject().property("x").toNumber() / length ) );
119 thisObject().setProperty("y", ( thisObject().property("y").toNumber() / length ) );
120 thisObject().setProperty("z", ( thisObject().property("z").toNumber() / length ) );
121 thisObject().setProperty("w", ( thisObject().property("w").toNumber() / length ) );
122 }
123
124
125 }
126
prototypeVec4d::normalize
void normalize()
Normalize the vector.
Definition: prototypeVec4d.cc:111
prototypeVec4d::norm
QScriptValue norm()
Calculate the Euclidean norm of the vector.
Definition: prototypeVec4d.cc:97
prototypeVec4d::multiply
void multiply(QScriptValue _scalar)
Multiplies the given vector with the scalar.
Definition: prototypeVec4d.cc:60
prototypeVec4d::zero
void zero()
Resets all components of the vector to zero.
Definition: prototypeVec4d.cc:82
prototypeVec4d::add
void add(QScriptValue _vector)
Adds another vector to this vector.
Definition: prototypeVec4d.cc:67
prototypeVec4d::sqrnorm
QScriptValue sqrnorm()
Calculate the squared Euclidean norm of the vector.
Definition: prototypeVec4d.cc:104
prototypeVec4d::sub
void sub(QScriptValue _vector)
Subtracts another vector from this vector.
Definition: prototypeVec4d.cc:75
prototypeVec4d::sprod
QScriptValue sprod(QScriptValue _vector)
Calculate scalar product.
Definition: prototypeVec4d.cc:89