100 lines
2.7 KiB
C++
100 lines
2.7 KiB
C++
/* libsegl - Sebas Extended GL Library
|
|
* Collection of Opengl/3D-Math helpers
|
|
*
|
|
* Copyright (c) 2008 by Sebastian Lohff, seba@seba-geek.de
|
|
* http://www.seba-geek.de
|
|
*
|
|
* This library is free software; you can redistribute it and/or
|
|
* modify it under the terms of the GNU Library General Public
|
|
* License as published by the Free Software Foundation; either
|
|
* version 2 of the License, or (at your option) any later version.
|
|
*
|
|
* This library is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
* Library General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU Library General Public
|
|
* License along with this library; if not, write to the
|
|
* Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
|
|
* Boston, MA 02110-1301, USA.
|
|
*/
|
|
|
|
#include "emath_opengl.h"
|
|
|
|
namespace segl {
|
|
|
|
void rotFrom2VecTo2Vec(Punkt3D a, Punkt3D b, Punkt3D c, Punkt3D d, Punkt3D *rvec, float *rvecdeg, Punkt3D *rvec2, float *rvecdeg2) {
|
|
Punkt3D rotvec, rotvec2, nullvec;
|
|
float rotvecdeg = 0.0f, rotvecdeg2 = 0.0f;
|
|
|
|
rotvec = a.kreuzprodukt(b);
|
|
rotvecdeg = a.calcAngle(b);
|
|
if(std::abs(rotvecdeg)==180.0f) {
|
|
rotvec = a.getOrtographic();
|
|
}
|
|
|
|
if(rotvec==nullvec) {
|
|
rotvec.set(1.0f, 0.0f, 0.0f);
|
|
rotvecdeg = 0.0f;
|
|
}
|
|
|
|
Rotationsmatrix rotnobj(rotvec, -rotvecdeg);
|
|
c = Rotationsmatrix(rotvec, rotvecdeg) * c;
|
|
|
|
rotvec2 = c.kreuzprodukt(d);
|
|
rotvecdeg2 = c.calcAngle(d);
|
|
if(std::abs(rotvecdeg2)==180.0f) {
|
|
rotvec2 = b;
|
|
}
|
|
|
|
if(rotvec2==nullvec) {
|
|
rotvec2.set(1.0f, 0.0f, 0.0f);
|
|
rotvecdeg2 = 0.0f;
|
|
}
|
|
|
|
rotvec2 = rotnobj * rotvec2;
|
|
|
|
*rvec = rotvec;
|
|
*rvecdeg = rotvecdeg;
|
|
*rvec2 = rotvec2;
|
|
*rvecdeg2 = rotvecdeg2;
|
|
}
|
|
|
|
void rotFrom2VecTo2Vec(Punkt3D a, Punkt3D b, Punkt3D c, Punkt3D d) {
|
|
Punkt3D rvec, rvec2;
|
|
float rvecdeg, rvecdeg2;
|
|
rotFrom2VecTo2Vec(a, b, c, d, &rvec, &rvecdeg, &rvec2, &rvecdeg2);
|
|
// if(rvecdeg)
|
|
glRotatef(rvecdeg, rvec);
|
|
// if(rvecdeg2)
|
|
glRotatef(rvecdeg2, rvec2);
|
|
// std::cout << rvecdeg << ", " << rvecdeg2 << std::endl;
|
|
// rvec.print("rvecdeg");
|
|
// rvec2.print("rvecdeg2");
|
|
|
|
}
|
|
|
|
void rotvec2(Punkt3D a, Punkt3D b, Punkt3D c, Punkt3D d, float *dega, Punkt3D *veca, float *degb, Punkt3D *vecb) {
|
|
*dega = a.calcAngle(b);
|
|
if(*dega==180.0f)
|
|
*veca = a.getOrtographic();
|
|
else if(*dega==0.0f)
|
|
veca->set(1.0f, 0.0f, 0.0f);
|
|
else
|
|
*veca = a.kreuzprodukt(b);
|
|
*degb = 0.0f;
|
|
vecb->set(1.0f, 0.0f, 0.0f);
|
|
c = Rotationsmatrix(*veca, *dega) * c;
|
|
|
|
*degb = c.calcAngle(d);
|
|
if(*degb==180.0f)
|
|
*vecb = c.getOrtographic();
|
|
else if(*degb==0.0f)
|
|
vecb->set(1.0f, 0.0f, 0.0f);
|
|
else
|
|
*vecb = c.kreuzprodukt(d);
|
|
}
|
|
|
|
} // namespace segl
|