Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

iframeworkapp.cpp

Go to the documentation of this file.
00001 /*
00002     Sheep - A Rigid Body Dynamics Engine
00003     Copyright (C) 2001-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of Sheep.
00007 
00008     Sheep is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     Sheep is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with Sheep; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 #include "common/math/matrix3.h"
00024 #include "common/math/quaternion.h"
00025 #include "common/math/vector3.h"
00026 #include "engine/dynamics/rigidbody.h"
00027 #include "iframeworkapp.h"
00028 
00029 #include <GL/glut.h>
00030 
00031 using namespace sheep;
00032 
00033 IFrameworkApp::IFrameworkApp() :
00034     m_orbiter(
00035         Vector3(0.0),
00036         DEFAULT_AZIMUTH,
00037         DEFAULT_ELEVATION,
00038         DEFAULT_DISTANCE
00039     )
00040 {
00041 }
00042 
00043 void IFrameworkApp::Reshape(int width, int height) {
00044     glMatrixMode(GL_PROJECTION);
00045     glLoadIdentity();
00046 
00047     gluPerspective(
00048         60.0,                                   // field of view in degree
00049         static_cast<GLdouble>(width) / height,  // aspect ratio
00050         1.0,                                    // Z-near
00051         1000.0                                  // Z-far
00052     );
00053 
00054     glViewport(0, 0, width, height);
00055 
00056     glMatrixMode(GL_MODELVIEW);
00057 }
00058 
00059 void IFrameworkApp::TransformTo(const RigidBody *body) {
00060     const Vector3 &p = body->GetPosition();
00061     const Matrix3 r = Matrix3::Rotation(body->GetOrientation());
00062 
00063     GLdouble m[16];
00064 
00065     // OpenGL is column-major.
00066 
00067     m[0]  = r[0];
00068     m[1]  = r[3];
00069     m[2]  = r[6];
00070     m[3]  = 0.0;
00071     m[4]  = r[1];
00072     m[5]  = r[4];
00073     m[6]  = r[7];
00074     m[7]  = 0.0;
00075     m[8]  = r[2];
00076     m[9]  = r[5];
00077     m[10] = r[8];
00078     m[11] = 0.0;
00079     m[12] = p.m_x;
00080     m[13] = p.m_y;
00081     m[14] = p.m_z;
00082     m[15] = 1.0;
00083 
00084     glMultMatrixd(m);
00085 }

Generated on Tue May 11 01:31:50 2004 for toxic by doxygen 1.3.6