00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
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
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
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;
00051
float massEach = 1.0f;
00052
00053
unsigned int i, j;
00054
Vertex *vertex;
00055
PointMass *point, *point2;
00056
Spring *spring;
00057
00058
00059
00060 m_surface.
loadFromFile(m_filename);
00061
if(m_surface.
numVertices() > 0)
00062 massEach = mass / m_surface.
numVertices();
00063
00064
00065
00066
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
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 }