78 lines
1.8 KiB
C++
78 lines
1.8 KiB
C++
#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
|