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
|