3535#include " ExtraShapes.h"
3636#include < iostream>
3737
38+ /* !
39+ * \brief Pipecylinder::Pipecylinder
40+ * creates a pipe or pipecylinder geometry
41+ */
3842Pipecylinder::Pipecylinder (float rI, float rO, float l) :
3943 osg::Geometry()
4044{
@@ -131,11 +135,25 @@ Pipecylinder::Pipecylinder(float rI, float rO, float l) :
131135 }
132136}
133137
138+ /* !
139+ * \brief Spring::normalize
140+ * \param the input vector
141+ * normalizes a vector
142+ * \return the normalized vector
143+ *
144+ */
134145osg::Vec3f Spring::normalize (osg::Vec3f vec) {
135146 float abs = absoluteVector (vec);
136147 return osg::Vec3f (vec[0 ]/abs, vec[1 ] / abs, vec[2 ] / abs);
137148}
138149
150+ /* !
151+ * \brief Spring::getNormal
152+ * \param the input vector
153+ * \param the length of the out vector
154+ * gets an arbitrary normal to the input vector
155+ * \return the normal
156+ */
139157osg::Vec3f Spring::getNormal (osg::Vec3f vec, float length) {
140158 osg::Vec3f vecN = normalize (vec);
141159 osg::Vec3f vecN_Abs = osg::Vec3f (std::abs (vecN[0 ]), std::abs (vecN[1 ]), std::abs (vecN[2 ]));
@@ -169,49 +187,91 @@ osg::Vec3f Spring::getNormal(osg::Vec3f vec, float length) {
169187 return n;
170188}
171189
190+ /* !
191+ * \brief Spring::absoluteVector
192+ * \param the input vector
193+ * gets the length of a vector
194+ * \return the length
195+ */
172196float Spring::absoluteVector (osg::Vec3f vec)
173197{
174198 return std::sqrt (std::pow (vec[0 ], 2 ) + std::pow (vec[1 ], 2 ) + std::pow (vec[2 ], 2 ));
175199}
176200
201+ /* !
202+ * \brief Spring::angleBetweenVectors
203+ * \param vector1
204+ * \param vector2
205+ * gets the angle between 2 vectors
206+ * \return the angle
207+ */
177208float Spring::angleBetweenVectors (osg::Vec3f vec1, osg::Vec3f vec2)
178209{
179210 float scalarProduct = vec1[0 ] * vec2[0 ] + vec1[1 ] * vec2[1 ] + vec1[2 ] * vec2[2 ];
180211 return (std::acos (scalarProduct/(absoluteVector (vec1)*absoluteVector (vec2)))/* / M_PI * 180*/ );
181212}
182213
214+ /* !
215+ * \brief Spring::rotateX
216+ * \param vector1
217+ * \param angle
218+ * rotates the vector around the cartesian x axis with angle phi
219+ * \return the rotated vector
220+ */
183221osg::Vec3f Spring::rotateX (osg::Vec3f vec, float phi)
184222{
185223 return osg::Vec3f ( vec[0 ],
186224 vec[1 ] * std::cos (phi) - vec[2 ] * std::sin (phi),
187225 vec[1 ] * std::sin (phi) + vec[2 ] * std::cos (phi));
188226}
189227
228+ /* !
229+ * \brief Spring::rotateY
230+ * \param vector1
231+ * \param angle
232+ * rotates the vector around the cartesian y axis with angle phi
233+ * \return the rotated vector
234+ */
190235osg::Vec3f Spring::rotateY (osg::Vec3f vec, float phi)
191236{
192237 return osg::Vec3f ( vec[2 ] * std::sin (phi) + vec[0 ] * std::cos (phi),
193238 vec[1 ],
194239 vec[2 ] * std::cos (phi) - vec[0 ] * std::sin (phi));
195240}
196241
242+ /* !
243+ * \brief Spring::rotateZ
244+ * \param vector1
245+ * \param angle
246+ * rotates the vector around the cartesian z axis with angle phi
247+ * \return the rotated vector
248+ */
197249osg::Vec3f Spring::rotateZ (osg::Vec3f vec, float phi)
198250{
199251 return osg::Vec3f ( vec[0 ] * std::cos (phi) - vec[1 ] * std::sin (phi),
200252 vec[0 ] * std::sin (phi) + vec[1 ] * std::cos (phi),
201253 vec[2 ]);
202254}
203255
204- osg::Vec3f Spring::rotateArbitraryAxes_expensive (osg::Vec3f vec, osg::Vec3f axes, float phi)
256+ /* !
257+ * \brief Spring::rotateArbitraryAxis_expensive
258+ * \param vector1
259+ * \param rotation axis
260+ * \param angle
261+ * rotates the vector around the given axis with angle phi, this is a bit odd, use rotateArbitraryAxis
262+ * \return the rotated vector
263+ */
264+ osg::Vec3f Spring::rotateArbitraryAxis_expensive (osg::Vec3f vec, osg::Vec3f axis, float phi)
205265{
206- // this is how I would do it by hand. Check out rotateArbitraryAxes , thats the shortest formula.
266+ // this is how I would do it by hand. Check out rotateArbitraryAxis , thats the shortest formula.
207267 // There is also still something wrong in here
208- osg::Vec3f axesN = normalize (axes );
268+ osg::Vec3f axisN = normalize (axis );
209269 osg::Vec3f aux = vec;
210270 // angle between vec and x, rotate in xz-plane
211- float phiX = angleBetweenVectors (axesN , osg::Vec3f (1 , 0 , 0 ));
271+ float phiX = angleBetweenVectors (axisN , osg::Vec3f (1 , 0 , 0 ));
212272 aux = rotateX (aux, phiX);
213- // angle between vec and x, rotate in z axes
214- float phiY = angleBetweenVectors (axesN , osg::Vec3f (0 , 1 , 0 ));
273+ // angle between vec and x, rotate in z axis
274+ float phiY = angleBetweenVectors (axisN , osg::Vec3f (0 , 1 , 0 ));
215275 aux = rotateY (aux, phiY);
216276 // rotate around z
217277 aux = rotateZ (aux, phi);
@@ -221,30 +281,44 @@ osg::Vec3f Spring::rotateArbitraryAxes_expensive(osg::Vec3f vec, osg::Vec3f axes
221281 return aux;
222282}
223283
224- osg::Vec3f Spring::rotateArbitraryAxes (osg::Vec3f vec, osg::Vec3f axes, float phi)
284+ /* !
285+ * \brief Spring::rotateArbitraryAxis
286+ * \param vector1
287+ * \param rotation axis
288+ * \param angle
289+ * rotates the vector around the given axis with angle phi
290+ * \return the rotated vector
291+ */
292+ osg::Vec3f Spring::rotateArbitraryAxis (osg::Vec3f vec, osg::Vec3f axis, float phi)
225293{
226- osg::Vec3f axesN = normalize (axes );
227- float M1_1 = (1 - std::cos (phi)) * axesN [0 ] * axesN [0 ] + std::cos (phi) * 1 + std::sin (phi) * 0 ;
228- float M1_2 = (1 - std::cos (phi)) * axesN [0 ] * axesN [1 ] + std::cos (phi) * 0 + std::sin (phi) * (-axesN [2 ]);
229- float M1_3 = (1 - std::cos (phi)) * axesN [0 ] * axesN [2 ] + std::cos (phi) * 0 + std::sin (phi) * (axesN [1 ]);
230- float M2_1 = (1 - std::cos (phi)) * axesN [0 ] * axesN [1 ] + std::cos (phi) * 0 + std::sin (phi) * (axesN [2 ]);
231- float M2_2 = (1 - std::cos (phi)) * axesN [1 ] * axesN [1 ] + std::cos (phi) * 1 + std::sin (phi) * 0 ;
232- float M2_3 = (1 - std::cos (phi)) * axesN [1 ] * axesN [2 ] + std::cos (phi) * 0 + std::sin (phi) * (-axesN [0 ]);
233- float M3_1 = (1 - std::cos (phi)) * axesN [0 ] * axesN [2 ] + std::cos (phi) * 0 + std::sin (phi) * (-axesN [1 ]);
234- float M3_2 = (1 - std::cos (phi)) * axesN [1 ] * axesN [2 ] + std::cos (phi) * 0 + std::sin (phi) * (axesN [0 ]);
235- float M3_3 = (1 - std::cos (phi)) * axesN [2 ] * axesN [2 ] + std::cos (phi) * 1 + std::sin (phi) * 0 ;
294+ osg::Vec3f axisN = normalize (axis );
295+ float M1_1 = (1 - std::cos (phi)) * axisN [0 ] * axisN [0 ] + std::cos (phi) * 1 + std::sin (phi) * 0 ;
296+ float M1_2 = (1 - std::cos (phi)) * axisN [0 ] * axisN [1 ] + std::cos (phi) * 0 + std::sin (phi) * (-axisN [2 ]);
297+ float M1_3 = (1 - std::cos (phi)) * axisN [0 ] * axisN [2 ] + std::cos (phi) * 0 + std::sin (phi) * (axisN [1 ]);
298+ float M2_1 = (1 - std::cos (phi)) * axisN [0 ] * axisN [1 ] + std::cos (phi) * 0 + std::sin (phi) * (axisN [2 ]);
299+ float M2_2 = (1 - std::cos (phi)) * axisN [1 ] * axisN [1 ] + std::cos (phi) * 1 + std::sin (phi) * 0 ;
300+ float M2_3 = (1 - std::cos (phi)) * axisN [1 ] * axisN [2 ] + std::cos (phi) * 0 + std::sin (phi) * (-axisN [0 ]);
301+ float M3_1 = (1 - std::cos (phi)) * axisN [0 ] * axisN [2 ] + std::cos (phi) * 0 + std::sin (phi) * (-axisN [1 ]);
302+ float M3_2 = (1 - std::cos (phi)) * axisN [1 ] * axisN [2 ] + std::cos (phi) * 0 + std::sin (phi) * (axisN [0 ]);
303+ float M3_3 = (1 - std::cos (phi)) * axisN [2 ] * axisN [2 ] + std::cos (phi) * 1 + std::sin (phi) * 0 ;
236304 return osg::Vec3f (M1_1*vec[0 ]+ M1_2*vec[1 ]+ M1_3*vec[2 ], M2_1*vec[0 ] + M2_2*vec[1 ] + M2_3*vec[2 ], M3_1*vec[0 ] + M3_2*vec[1 ] + M3_3*vec[2 ]);
237305}
238306
239307
240-
241-
242- Spring::Spring (float r, float rCoil, float nWindings, float l) :
308+ /* !
309+ * \brief Spring::Spring
310+ * \param center radius of the coil
311+ * \param radius of the wire
312+ * \param number of windings
313+ * \param the length
314+ * creates an osg spring geometry
315+ */
316+ Spring::Spring (float r, float rWire, float nWindings, float l) :
243317 osg::Geometry()
244318{
245319 float R = r;
246320 float L = l;
247- float RCOIL = rCoil ;
321+ float RWIRE = rWire ;
248322 float NWIND = nWindings;
249323
250324 const int ELEMENTS_WINDING = 10 ;
@@ -254,41 +328,41 @@ Spring::Spring(float r, float rCoil, float nWindings, float l) :
254328
255329 // the inner line points
256330 int numSegments = (ELEMENTS_WINDING * NWIND) + 1 ;
257- splineVertices = new osg::Vec3Array (numSegments);
331+ mpSplineVertices = new osg::Vec3Array (numSegments);
258332
259333 for (int segIdx = 0 ; segIdx < numSegments; segIdx++)
260334 {
261335 float x = std::sin (2 * M_PI / ELEMENTS_WINDING * segIdx) * R;
262336 float y = std::cos (2 * M_PI / ELEMENTS_WINDING * segIdx) * R;
263337 float z = L / numSegments * segIdx;
264- (*splineVertices )[segIdx].set (osg::Vec3 (x,y,z));
338+ (*mpSplineVertices )[segIdx].set (osg::Vec3 (x,y,z));
265339 }
266340
267341 // the outer points for the facettes
268342 int numVertices = (numSegments + 1 )*ELEMENTS_CONTOUR;
269- outerVertices = new osg::Vec3Array (numVertices);
343+ mpOuterVertices = new osg::Vec3Array (numVertices);
270344 osg::Vec3f normal;
271345 osg::Vec3f v1;
272346 osg::Vec3f v2;
273347 int vertIdx = 0 ;
274348 for (int i = 0 ; i < numSegments-1 ; i++)
275349 {
276- v1 = splineVertices ->at (i);
277- v2 = splineVertices ->at (i + 1 );
350+ v1 = mpSplineVertices ->at (i);
351+ v2 = mpSplineVertices ->at (i + 1 );
278352 normal = osg::Vec3f (v2[0 ] - v1[0 ], v2[1 ] - v1[1 ], v2[2 ] - v1[2 ]);
279353 osg::Vec3f vec0 = normal;
280- normal = getNormal (normal, RCOIL );
354+ normal = getNormal (normal, RWIRE );
281355 for (int i1 = 0 ; i1 < ELEMENTS_CONTOUR; i1++)
282356 {
283357 float angle = M_PI * 2 / ELEMENTS_CONTOUR * i1;
284- osg::Vec3f a1 = rotateArbitraryAxes (normal, vec0, angle);
285- (*outerVertices )[vertIdx].set (osg::Vec3f ((v1[0 ] + a1[0 ]), (v1[1 ] + a1[1 ]), (v1[2 ] + a1[2 ])));
358+ osg::Vec3f a1 = rotateArbitraryAxis (normal, vec0, angle);
359+ (*mpOuterVertices )[vertIdx].set (osg::Vec3f ((v1[0 ] + a1[0 ]), (v1[1 ] + a1[1 ]), (v1[2 ] + a1[2 ])));
286360 vertIdx++;
287361 }
288362 }
289363
290364 // pass the created vertex array to the points geometry object.
291- this ->setVertexArray (outerVertices );
365+ this ->setVertexArray (mpOuterVertices );
292366
293367 // PLANES
294368 // base plane bottom
@@ -302,7 +376,7 @@ Spring::Spring(float r, float rCoil, float nWindings, float l) :
302376 basePlane->push_back (i + ELEMENTS_CONTOUR-1 );
303377 this ->addPrimitiveSet (basePlane);
304378 }
305- // std::cout << "NUM " << outerVertices ->size() << std::endl;
306- // this->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, outerVertices ->size()));
379+ // std::cout << "NUM " << mpOuterVertices ->size() << std::endl;
380+ // this->addPrimitiveSet(new osg::DrawArrays(osg::PrimitiveSet::POINTS, 0, mpOuterVertices ->size()));
307381}
308382
0 commit comments