2009-01-21 01:00:31 +01:00
|
|
|
/* 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.
|
|
|
|
*/
|
|
|
|
|
2008-02-09 13:43:23 +01:00
|
|
|
#include "emath_opengl.h"
|
|
|
|
|
2008-08-10 17:14:54 +02:00
|
|
|
namespace segl {
|
|
|
|
|
2008-02-09 13:43:23 +01:00
|
|
|
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);
|
2008-06-08 14:09:56 +02:00
|
|
|
// if(rvecdeg)
|
2008-02-09 13:43:23 +01:00
|
|
|
glRotatef(rvecdeg, rvec);
|
2008-06-08 14:09:56 +02:00
|
|
|
// if(rvecdeg2)
|
2008-02-09 13:43:23 +01:00
|
|
|
glRotatef(rvecdeg2, rvec2);
|
2008-06-08 14:09:56 +02:00
|
|
|
// std::cout << rvecdeg << ", " << rvecdeg2 << std::endl;
|
|
|
|
// rvec.print("rvecdeg");
|
|
|
|
// rvec2.print("rvecdeg2");
|
|
|
|
|
2008-02-09 13:43:23 +01:00
|
|
|
}
|
2008-06-21 20:31:11 +02:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2008-08-10 17:14:54 +02:00
|
|
|
|
|
|
|
} // namespace segl
|