Skip to content
Snippets Groups Projects
Commit 40052e62 authored by Christophe Geuzaine's avatar Christophe Geuzaine
Browse files

Corrige les rotations

parent 863e1998
Branches
Tags
No related merge requests found
/* $Id: Context.cpp,v 1.20 2000-12-09 22:26:12 geuzaine Exp $ */
/* $Id: Context.cpp,v 1.21 2000-12-10 00:06:50 geuzaine Exp $ */
#include "Gmsh.h"
#include "Const.h"
......@@ -392,26 +392,105 @@ void Print_Context(char *filename){
}
}
void Context_T::buildRotmatrix(float m[4][4])
/*
3 rotations successives autour de x, y et z:
c(y)c(z) s(x)s(y)c(z)+c(x)s(z) -c(x)s(y)c(z)+s(x)s(z)
t[][] = -c(y)s(z) -s(x)s(y)s(z)+c(x)c(z) c(x)s(y)s(z)+s(x)c(z)
s(y) -s(x)c(y) c(x)c(y)
get the position angles:
y = asin(t31)
Pi - asin(t31)
si y != +- Pi/2 :
x = atan(-t32/t33) si t33 cos y > 0
atan(-t32/t33)+Pi si t33 cos y < 0
z = atan(-t21/t11) si t11 cos y > 0
atan(-t21/t11)+Pi si t11 cos y < 0
*/
void Context_T::buildRotmatrix(void)
{
double r0, r1, r2;
double x, y, z;
extern void set_r(int i, double val);
build_rotmatrix(m, quaternion);
if(CTX.useTrackball){
build_rotmatrix(rot, quaternion);
// get the position angles
/*
double x=0., y=0., z=0.
y = asin(rot[2][0]) ; y = Pi - asin(rot[2][0]) ; // choix ???
if(fabs(y) != Pi/2.){
if(rot[2][2]*cos(y) > 0.) x = atan2(-rot[2][1],rot[2][2]);
else x = atan2(-rot[2][1],rot[2][2]) + Pi;
if(rot[0][0]*cos(y) > 0.) z = atan2(-rot[1][0],rot[0][0]);
else z = atan2(-rot[1][0],rot[0][0]) + Pi;
}
set_r(0, x * 180./Pi);
set_r(1, y * 180./Pi);
set_r(2, z * 180./Pi);
*/
/*
double r0, r1, r2;
r1 = atan2(-m[0][2],sqrt(m[1][2]*m[1][2] + m[2][2]*m[2][2]));
r1 = atan2(-rot[0][2],sqrt(rot[1][2]*rot[1][2] + rot[2][2]*rot[2][2]));
double c = cos(r1);
if(c != 0.0)
{
r0 = atan2(m[1][2]/c,m[2][2]/c) ;
r2 = atan2(-m[1][0]/c,m[0][0]/c) ;
if(c != 0.0){
r0 = atan2(rot[1][2]/c,rot[2][2]/c) ;
r2 = atan2(-rot[1][0]/c,rot[0][0]/c) ;
r0 *= 180./(Pi);
r2 *= 180./(Pi);
}
set_r(0, r0);
set_r(1, r1 * 180./(Pi)); // lazyyyyyy
set_r(2, r2);
*/
// until we can compute this correctly
set_r(0, 0.);
set_r(1, 0.);
set_r(2, 0.);
}
else{
x = r[0] * Pi / 180.;
y = r[1] * Pi / 180.;
z = r[2] * Pi / 180.;
rot[0][0] = cos(y)*cos(z) ;
rot[0][1] = sin(x)*sin(y)*cos(z)+cos(x)*sin(z);
rot[0][2] = -cos(x)*sin(y)*cos(z)+sin(x)*sin(z);
rot[0][3] = 0.0;
rot[1][0] = -cos(y)*sin(z);
rot[1][1] = -sin(x)*sin(y)*sin(z)+cos(x)*cos(z);
rot[1][2] = cos(x)*sin(y)*sin(z)+sin(x)*cos(z);
rot[1][3] = 0.0;
rot[2][0] = sin(y);
rot[2][1] = -sin(x)*cos(y);
rot[2][2] = cos(x)*cos(y);
rot[2][3] = 0.0;
rot[3][0] = 0.0 ;
rot[3][1] = 0.0 ;
rot[3][2] = 0.0 ;
rot[3][3] = 1.0 ;
/*
glRotated (CTX.r[0], 1., 0., 0.);
glRotated (CTX.r[1], 0., 1., 0.);
glRotated (CTX.r[2], 0., 0., 1.);
*/
}
}
void Context_T::addQuaternion (float p1x, float p1y, float p2x, float p2y)
......
/* $Id: Context.h,v 1.18 2000-12-09 17:33:39 geuzaine Exp $ */
/* $Id: Context.h,v 1.19 2000-12-10 00:06:50 geuzaine Exp $ */
#ifndef _CONTEXT_H_
#define _CONTEXT_H_
......@@ -59,10 +59,11 @@ class Context_T {
int verbosity; /* 0=silent -> 3=debug */
int expose; /* 1 if everything is ready to expose and draw */
double r[3], t[3], s[3]; /* current rotation, translation and scale */
float rot[4][4]; /* current rotation matrix */
double r[3]; /* position angles (if succ. rot. along x, y and z) */
double t[3], s[3]; /* current translation and scale */
int rlock[3], tlock[3], slock[3];
/* locks for r, t and s */
float quaternion[4]; /* the actual quaternion used for "trackball" rotating */
int useTrackball; /* do or do not use the trackball for rotations */
......@@ -145,7 +146,7 @@ class Context_T {
} print;
// trackball functions
void buildRotmatrix(float m[4][4]);
void buildRotmatrix(void);
void setQuaternion (float p1x, float p1y, float p2x, float p2y);
void addQuaternion (float p1x, float p1y, float p2x, float p2y);
};
......
/* $Id: Draw.cpp,v 1.9 2000-12-05 23:01:06 geuzaine Exp $ */
/* $Id: Draw.cpp,v 1.10 2000-12-10 00:06:50 geuzaine Exp $ */
#include "Gmsh.h"
#include "GmshUI.h"
......@@ -230,18 +230,8 @@ void InitPosition(void){
glScaled (CTX.s[0], CTX.s[1], CTX.s[2]);
glTranslated(CTX.t[0], CTX.t[1], CTX.t[2]);
if(CTX.useTrackball)
{
float m[4][4];
CTX.buildRotmatrix(m);
glMultMatrixf(&(m[0][0]));
}
else
{
glRotated (CTX.r[0], 1., 0., 0.);
glRotated (CTX.r[1], 0., 1., 0.);
glRotated (CTX.r[2], 0., 0., 1.);
}
CTX.buildRotmatrix();
glMultMatrixf(&(CTX.rot[0][0]));
}
/* ------------------------------------------------------------------------ */
......
/* $Id: Scale.cpp,v 1.7 2000-12-05 15:23:56 geuzaine Exp $ */
/* $Id: Scale.cpp,v 1.8 2000-12-10 00:06:50 geuzaine Exp $ */
#include "Gmsh.h"
#include "GmshUI.h"
......@@ -287,21 +287,16 @@ void Draw_Scales(void){
/* ------------------------------------------------------------------------ */
void Draw_SmallAxes(void){
double a,b,c;
double l,o,xx,xy,yx,yy,zx,zy,cx,cy;
a = CTX.r[0] * Pi/180. ;
b = CTX.r[1] * Pi/180. ;
c = CTX.r[2] * Pi/180. ;
l = 30 ;
o = 2 ;
cx = CTX.viewport[2] - 45;
cy = CTX.viewport[1] + 35;
xx = l*cos(b)*cos(c) ; xy = l*(sin(a)*sin(b)*cos(c)+cos(a)*sin(c)) ;
yx = -l*cos(b)*sin(c) ; yy = -l*(sin(a)*sin(b)*sin(c)-cos(a)*cos(c)) ;
zx = l*sin(b) ; zy = -l*sin(a)*cos(b) ;
xx = l*CTX.rot[0][0] ; xy = l*CTX.rot[0][1] ;
yx = l*CTX.rot[1][0] ; yy = l*CTX.rot[1][1] ;
zx = l*CTX.rot[2][0] ; zy = l*CTX.rot[2][1] ;
glColor4ubv((GLubyte*)&CTX.color.small_axes);
......
/* $Id: CbGeneral.cpp,v 1.5 2000-11-27 10:58:59 geuzaine Exp $ */
/* $Id: CbGeneral.cpp,v 1.6 2000-12-10 00:06:50 geuzaine Exp $ */
#include "Gmsh.h"
#include "GmshUI.h"
......@@ -133,6 +133,14 @@ void CurrentInfoCb (Widget w, XtPointer client_data, XtPointer call_data){
------------------------------------------------------------------------ */
void set_r(int i, double val){
if(CTX.useTrackball){
if(XtIsManaged(WID.OD.viewportDialog)){
sprintf(label, "---");
XtVaSetValues(WID.OD.viewportText[0][i], XmNvalue, label, NULL);
XmUpdateDisplay(WID.OD.viewportText[0][i]);
}
}
else{
if(!CTX.rlock[i]){
CTX.r[i] = val;
if(XtIsManaged(WID.OD.viewportDialog)){
......@@ -142,6 +150,7 @@ void set_r(int i, double val){
}
}
}
}
void set_t(int i, double val){
if(!CTX.tlock[i]){
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment