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

Gravity.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 "Gravity.h" 00013 #include <OpenCAL/PhysicalObject.h> 00014 #include <OpenCAL/PhysicsSystem.h> 00015 #include <OpenCAL/ObjectIterator.h> 00016 using namespace OpenCAL; 00017 00018 using namespace std; 00019 00020 00021 /****************************** 00022 * Constructors and destructor * 00023 ******************************/ 00024 00025 Gravity::Gravity(PhysicsSystem *parent, const Vector3 &gravity) 00026 : Force(parent), m_gravity(gravity) 00027 { 00028 } 00029 00030 Gravity::Gravity(PhysicsSystem *parent, float downGravity) 00031 : Force(parent), m_gravity(Vector3(0, -downGravity, 0)) 00032 { 00033 } 00034 00035 Gravity::~Gravity() 00036 { 00037 } 00038 00039 00040 /************************ 00041 * Get and set functions * 00042 ************************/ 00043 00044 00045 /****************** 00046 * Other functions * 00047 ******************/ 00048 00054 void Gravity::execute(float seconds) 00055 { 00057 00058 //if(!m_enabled) return; 00059 Force::execute(seconds); 00060 00061 ObjectIterator it(m_parent); 00062 while(*it) 00063 { 00064 PhysicalObject *object = (PhysicalObject *) *it; 00065 object->addForce(object->getMass() * m_gravity); 00066 00067 ++it; 00068 } 00069 00070 /* 00071 for(unsigned int i = 0; i < m_parent->numObjects(); ++i) 00072 { 00073 PhysicalObject *object = (PhysicalObject *) m_parent->getObject(i); 00074 object->addForce(object->getMass() * m_gravity); 00075 } 00076 */ 00077 } 00078 00079 00080 /********************** 00081 * Protected functions * 00082 **********************/

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