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

Sphere.cpp

00001 /*************************************************************************** 00002 * This file is part of OpenCAL: Open Computer Animation Library * 00003 * I created OpenCAL as my master's thesis Computer Science (multimedia) * 00004 * at the tUL university in Diepenbeek, Belgium * 00005 * * 00006 * Copyright (C) 2003-2004 by Jeroen Dierckx * 00007 * jeroen.dierckx@student.luc.ac.be * 00008 * * 00009 ***************************************************************************/ 00010 00011 // Includes 00012 #include "Sphere.h" 00013 #include <OpenCAL/System.h> 00014 #include <OpenCAL/Renderer.h> 00015 using namespace OpenCAL; 00016 using namespace Utils; 00017 00018 using namespace std; 00019 00020 00021 /****************************** 00022 * Constructors and destructor * 00023 ******************************/ 00024 00025 Sphere::Sphere(System *parent, float radius, float mass) 00026 : RigidBody(parent, mass), m_radius(radius) 00027 { 00028 #ifdef VERBOSE 00029 Debug::print("Sphere constructor", 2); 00030 #endif // VERBOSE 00031 //cout << "mass = " << mass << endl; 00032 } 00033 00034 Sphere::~Sphere() 00035 { 00036 } 00037 00038 00039 /************************ 00040 * Get and set functions * 00041 ************************/ 00042 00043 00044 /****************** 00045 * Other functions * 00046 ******************/ 00047 00048 void Sphere::render() 00049 { 00050 Renderer *renderer = m_parent->getRenderer(); 00051 if(!renderer) return; 00052 00053 // Push the current transformation on the stack 00054 renderer->pushTransformation(); 00055 00056 renderer->translate(m_position); 00057 renderer->rotate(m_rotation); 00058 renderer->renderSphere(m_radius); 00059 00060 // Pop the transformation stack 00061 renderer->popTransformation(); 00062 } 00063 00064 void Sphere::calculateVolume() 00065 { 00066 m_volume = 2 * Math::pi * Math::squared(m_radius); 00067 } 00068 00069 void Sphere::calculateInversedInertia() 00070 { 00071 m_invInertia.identity(); 00072 m_invInertia *= 5.0f / (2.0f * getMass() * Math::squared(m_radius)); 00073 00074 cout << "Inversed inertia (body space):" << endl; 00075 m_invInertia.print(); 00076 } 00077 00078 /* 00079 #ifdef USE_OPENGL 00080 void Sphere::initializeGL() 00081 { 00082 #ifdef VERBOSE 00083 Debug::print("Sphere initializeGL", 2); 00084 #endif // VERBOSE 00085 00086 Rigid::initializeGL(); 00087 00088 GLUquadric *quadric = gluNewQuadric(); 00089 00090 // Compile the sphere 00091 glNewList(m_displayList, GL_COMPILE); 00092 gluSphere(quadric, m_radius, 20, 20); 00093 glEndList(); 00094 00095 gluDeleteQuadric(quadric); 00096 } 00097 #endif // USE_OPENGL 00098 */ 00099 00100 00101 /********************** 00102 * Protected functions * 00103 **********************/

Generated on Sun Aug 15 19:19:23 2004 for OpenCAL: Open Computer Animation Library by doxygen 1.3.8