1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89
|
/****************************************************************************
Copyright (C) 2002-2007 Gilles Debunne (Gilles.Debunne@imag.fr)
This file is part of the QGLViewer library.
Version 2.2.6-3, released on August 28, 2007.
http://artis.imag.fr/Members/Gilles.Debunne/QGLViewer
libQGLViewer is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
libQGLViewer 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 General Public License for more details.
You should have received a copy of the GNU General Public License
along with libQGLViewer; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*****************************************************************************/
#include "frameTransform.h"
using namespace std;
using namespace qglviewer; // Vec
void Viewer::init()
{
restoreStateFromFile();
setSceneRadius(1.5);
showEntireScene();
setAxisIsDrawn();
glDisable(GL_LIGHTING);
help();
}
void Viewer::draw()
{
// Draws line sets (red, green, blue) with different origins, but with a common
// end point, located on a circle in the XY plane.
const float nbLines = 50.0;
glBegin(GL_LINES);
for (float i=0; i<nbLines; ++i)
{
float angle = 2.0*M_PI*i/nbLines;
glColor3f(.8,.2,.2);
// These lines will never be seen as they are always aligned with the viewing direction.
glVertex3fv(camera()->position());
glVertex3f (cos(angle), sin(angle), 0.0);
glColor3f(.2,.8,.2);
// World Coordinates are infered from the camera, and seem to be immobile in the screen.
glVertex3fv(camera()->worldCoordinatesOf(Vec(.3*cos(angle), .3*sin(angle), -2.0)));
glVertex3f (cos(angle), sin(angle), 0.0);
glColor3f(.2,.2,.8);
// These lines are defined in the world coordinate system and will move with the camera.
glVertex3f(1.5*cos(angle), 1.5*sin(angle), -1.0);
glVertex3f(cos(angle), sin(angle), 0.0);
}
glEnd();
// Here, the camera position in world coord. system is camera()->position().
// The world origin position in camera frame can be obtained from camera()->cameraCoordinatesOf(Vec(0.0, 0.0, 0.0))
}
QString Viewer::helpString() const
{
QString text("<h2>F r a m e T r a n s f o r m</h2>");
text += "This example illustrates how easy it is to switch between the camera and ";
text += "the world coordinate systems using the <i>camera()->cameraCoordinatesOf()</i> ";
text += "and <i>camera::worldCoordinatesOf()</i> functions.<br><br>";
text += "You can create your own hierarchy of local coordinates systems and each of ";
text += "them can be manipulated with the mouse (see the <i>manipulatedFrame</i> and <i>luxo</i> examples). ";
text += "Standard functions allow you to convert from any local frame to any other, ";
text += "the world/camera conversion presented here simply being an illustration.<br><br>";
text += "See <i>examples/frameTransform.html</i> for an explanation of the meaning of these weird lines.";
return text;
}
|