Lagrangian Liquid Simulation
Master Thesis project on simulation of liquids using Lagrangian approach and SPH
|
00001 00002 00003 00004 #include "Capsule.h" 00005 00006 #include "ngl/Transformation.h" 00007 00008 Capsule::Capsule() : Particle() 00009 { 00010 Capsule(0); 00011 } 00012 00013 Capsule::Capsule 00014 ( 00015 const Capsule& _particle 00016 ) : 00017 Particle 00018 ( 00019 _particle.getId(), 00020 _particle.getMass(), 00021 _particle.getPosition(), 00022 _particle.getColour(), 00023 _particle.getRadius(), 00024 _particle.getMoveable() 00025 ) 00026 { 00027 m_height = _particle.getHeight(); 00028 00029 m_orientationVector = _particle.getOrientationVector(); 00030 00031 m_incrementAngle = _particle.getIncrementAngle(); 00032 00033 m_angle = _particle.getAngle(); 00034 00035 m_initialAngle = _particle.getInitialAngle(); 00036 } 00037 00038 Capsule::Capsule 00039 ( 00040 const int _id, 00041 const ngl::Real _mass, 00042 const ngl::Vector _centerPosition, 00043 const ngl::Colour _colour, 00044 const ngl::Real _radius, 00045 const ngl::Real _height, 00046 const ngl::Vector _orientationVector, 00047 const ngl::Real _incrementAngle, 00048 const ngl::Real _initialAngle, 00049 const bool _moveable 00050 ) : 00051 Particle(_id, _mass, _centerPosition, _colour, _radius, _moveable) 00052 { 00053 //init params 00054 m_height = _height; 00055 00056 m_orientationVector = _orientationVector; 00057 00058 m_incrementAngle = _incrementAngle; 00059 00060 m_angle = _initialAngle; 00061 00062 m_initialAngle = _initialAngle; 00063 } 00064 00065 Capsule::~Capsule() 00066 { 00067 } 00068 00069 void Capsule::updateRotation() 00070 { 00071 //increment angle 00072 m_angle += m_incrementAngle; 00073 00074 //convert degrees to radians 00075 float angle = m_angle * (M_PI / 180.0); 00076 00077 //calculate new positions following rotations (using pythagoras theorem) 00078 float x1 = m_position.m_x + cos(angle); 00079 float z1 = m_position.m_z + sin(angle); 00080 00081 //set orientation to a normalised vector from centre position to the new position 00082 m_orientationVector = m_position - ngl::Vector(x1, m_position.m_y, z1); 00083 m_orientationVector.normalize(); 00084 }