Main Page | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | File Members

Elastoid.cpp

Go to the documentation of this file.
00001 // Elastoid.cpp: implementation of the Elastoid class.
00002 //
00004 
00005 #include "Elastoid.h"
00006 #include "Simulator.h"
00007 #include "purgeContainer.h"
00008 
00010 // Construction/Destruction
00012 
00013 Elastoid::Elastoid(){
00014 }
00015 
00016 Elastoid::~Elastoid(){
00017    purgeContainer(objects);
00018 }
00019 
00020 void Elastoid::registerPrimitives(Simulator* simulator){
00021    for(PhysicalObjectPVector::iterator it=objects.begin(), 
00022             end=objects.end(); it!=end; ++it) {
00023       simulator->registerPrimitive(*it);
00024   }
00025 }
00026 
00027 void Elastoid::computeDerivativesWithoutContacts(ContactSolver* contactSolver){
00028    for(ElasticLinkVector::iterator lit=links.begin(), lend=links.end(); lit!=lend; ++lit)
00029       (*lit).applyForces();
00030    for(PhysicalObjectPVector::iterator it=objects.begin(), 
00031                                                       end=objects.end(); it!=end; ++it)
00032       (*it)->computeDerivativesWithoutContacts(contactSolver);
00033 }
00034 
00035 void Elastoid::computeDerivatives(GlobalContactInfoVector* globalContacts){
00036    for(PhysicalObjectPVector::iterator it=objects.begin(), 
00037                                                       end=objects.end(); it!=end; ++it)
00038       (*it)->computeDerivatives(globalContacts);
00039 }
00040 
00041 void Elastoid::integrate(const Integrator &integrator){
00042    boxMin.setXY(ThyrixParameters::infinity,ThyrixParameters::infinity);
00043    boxMax.setXY(-ThyrixParameters::infinity,-ThyrixParameters::infinity);
00044    for(PhysicalObjectPVector::iterator it=objects.begin(), 
00045       end=objects.end(); it!=end; ++it){
00046       (*it)->integrate(integrator);
00047       boxMin.updateMin((*it)->boxMin);
00048       boxMax.updateMax((*it)->boxMax);
00049    }
00050 }
00051 
00052 bool Elastoid::detectContacts(PhysicalObject* object, GlobalContactInfoVector* contacts) {
00053    bool isContact=false;
00054    for(PhysicalObjectPVector::iterator it=objects.begin(), 
00055                                                       end=objects.end(); it!=end; ++it)
00056       isContact = (*it)->detectContacts(object, contacts) || isContact;
00057    return isContact;
00058 }
00059 
00060 void Elastoid::detectInternalContacts(GlobalContactInfoVector* globalContacts) {
00061    PhysicalObjectPVector::iterator it1, it2, end=objects.end();
00062    for(it1=objects.begin(); it1!=end; ++it1)
00063       for(it2=it1, ++it2; it2!=end; ++it2)
00064          (*it1)->detectContacts(*it2, globalContacts);
00065 }
00066 
00067 void Elastoid::deleteContacts(){ 
00068    for(PhysicalObjectPVector::iterator it=objects.begin(), 
00069                                                       end=objects.end(); it!=end; ++it)
00070       (*it)->deleteContacts();
00071 }
00072 
00073 bool Elastoid::detectMouseContact(const Vector2& rMouse, Vector2& p, PhysicalObject*& object){
00074    bool isContact=false;
00075    for(PhysicalObjectPVector::iterator it=objects.begin(), 
00076          end=objects.end(); it!=end && !isContact; ++it){
00077          isContact = (*it)->detectMouseContact(rMouse, p, object);
00078       }
00079    return isContact;
00080 }
00081 
00082 
00083 
00084 void Elastoid::draw(GUI* gui){
00085    gui->setPenColor(Color("lightGray"));
00086    for(ElasticLinkVector::iterator lit=links.begin(), lend=links.end(); lit!=lend; ++lit)
00087       (*lit).draw(gui);
00088    for(PhysicalObjectPVector::iterator it=objects.begin(), 
00089             end=objects.end(); it!=end; ++it) {
00090       (*it)->draw(gui);
00091    }
00092 }

Thyrix homepageUsers' guide

(C) Arxia 2004-2005