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

JellyMesh.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 "JellyMesh.h" 00013 #include <OpenCAL/System.h> 00014 #include <OpenCAL/Vertex.h> 00015 #include <OpenCAL/PointMass.h> 00016 #include <OpenCAL/Spring.h> 00017 using namespace OpenCAL; 00018 00019 using namespace std; 00020 00021 00022 /****************************** 00023 * Constructors and destructor * 00024 ******************************/ 00025 00026 JellyMesh::JellyMesh(System *parent, const string &filename, const Vector3 &position) 00027 : MassSpringSystem(parent), m_filename(filename) 00028 { 00029 constructMesh(position); 00030 } 00031 00032 JellyMesh::~JellyMesh() 00033 { 00034 } 00035 00036 00037 /********************** 00038 * Protected functions * 00039 **********************/ 00040 00046 void JellyMesh::constructMesh(const Vector3 &position) 00047 { 00048 const float stiffness = 10.0f; 00049 const float damping = 0.2f; 00050 const float mass = 1.0f; // Mass of the mesh 00051 float massEach = 1.0f; 00052 00053 unsigned int i, j; 00054 Vertex *vertex; 00055 PointMass *point, *point2; 00056 Spring *spring; 00057 00058 00059 // Load the triangle mesh 00060 m_surface.loadFromFile(m_filename); 00061 if(m_surface.numVertices() > 0) 00062 massEach = mass / m_surface.numVertices(); 00063 00064 00065 /********* 00066 * Points * 00067 *********/ 00068 00069 for(i = 0; i < m_surface.numVertices(); ++i) 00070 { 00071 vertex = m_surface.getVertex(i); 00072 point = new PointMass(this, massEach); 00073 point->setPosition(vertex->getPosition() + position); 00074 vertex->linkPosition(point->getPositionP()); 00075 } 00076 00077 00078 /********** 00079 * Springs * 00080 **********/ 00081 00082 for(i = 0; i < numObjects(); ++i) 00083 { 00084 point = getPoint(i); 00085 00086 for(j = i + 1; j < numObjects(); ++j) 00087 { 00088 point2 = getPoint(j); 00089 00090 spring = new Spring(this, point, point2); 00091 spring->setStiffness(stiffness); 00092 spring->setDamping(damping); 00093 } 00094 } 00095 }

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