Developer Documentation
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
prototypeVec3d.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 PROTOTYPEVEC3D_C
63 
64 #include "prototypeVec3d.hh"
65 
66 prototypeVec3d::prototypeVec3d(QObject *parent ) :
67  QObject(parent)
68 {
69 
70 }
71 
72 QString prototypeVec3d::toString() const {
73  return "Vector : ( " +
74  thisObject().property("x").toString() + "," +
75  thisObject().property("y").toString() + "," +
76  thisObject().property("z").toString() + " )";
77 }
78 
79 void prototypeVec3d::multiply(QScriptValue _scalar) {
80  thisObject().setProperty("x", QScriptValue(thisObject().property("x").toNumber() * _scalar.toNumber()));
81  thisObject().setProperty("y", QScriptValue(thisObject().property("y").toNumber() * _scalar.toNumber()));
82  thisObject().setProperty("z", QScriptValue(thisObject().property("z").toNumber() * _scalar.toNumber()));
83 }
84 
85 void prototypeVec3d::add(QScriptValue _vector) {
86  thisObject().setProperty("x", QScriptValue(_vector.property("x").toNumber() + thisObject().property("x").toNumber()));
87  thisObject().setProperty("y", QScriptValue(_vector.property("y").toNumber() + thisObject().property("y").toNumber()));
88  thisObject().setProperty("z", QScriptValue(_vector.property("z").toNumber() + thisObject().property("z").toNumber()));
89 }
90 
91 
92 void prototypeVec3d::sub(QScriptValue _vector) {
93  thisObject().setProperty("x", QScriptValue(thisObject().property("x").toNumber() - _vector.property("x").toNumber()));
94  thisObject().setProperty("y", QScriptValue(thisObject().property("y").toNumber() - _vector.property("y").toNumber()));
95  thisObject().setProperty("z", QScriptValue(thisObject().property("z").toNumber() - _vector.property("z").toNumber()));
96 }
97 
99  thisObject().setProperty("x", QScriptValue(0.0));
100  thisObject().setProperty("y", QScriptValue(0.0));
101  thisObject().setProperty("z", QScriptValue(0.0));
102 }
103 
104 QScriptValue prototypeVec3d::sprod(QScriptValue _vector) {
105  return QScriptValue( thisObject().property("x").toNumber() * _vector.property("x").toNumber() +
106  thisObject().property("y").toNumber() * _vector.property("y").toNumber() +
107  thisObject().property("z").toNumber() * _vector.property("z").toNumber() );
108 
109 }
110 
111 QScriptValue prototypeVec3d::norm() {
112  return QScriptValue( 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 }
116 
117 QScriptValue prototypeVec3d::sqrnorm() {
118  return QScriptValue( 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 }
122 
124  double length = sqrt( thisObject().property("x").toNumber() * thisObject().property("x").toNumber() +
125  thisObject().property("y").toNumber() * thisObject().property("y").toNumber() +
126  thisObject().property("z").toNumber() * thisObject().property("z").toNumber() );
127 
128  if ( length != 0.0 ) {
129  thisObject().setProperty("x", ( thisObject().property("x").toNumber() / length ) );
130  thisObject().setProperty("y", ( thisObject().property("y").toNumber() / length ) );
131  thisObject().setProperty("z", ( thisObject().property("z").toNumber() / length ) );
132  }
133 
134 
135 }
136 
void zero()
Resets all components of the vector to zero.
QScriptValue norm()
Calculate the Euclidean norm of the vector.
void normalize()
Normalize the vector.
QScriptValue sqrnorm()
Calculate the squared Euclidean norm of the vector.
void add(QScriptValue _vector)
Adds another vector to this vector.
QScriptValue sprod(QScriptValue _vector)
Calculate scalar product.
void sub(QScriptValue _vector)
Subtracts another vector from this vector.
void multiply(QScriptValue _scalar)
Multiplies the given vector with the scalar.