Example #1
0
void World::Step()
{
	float delta = (float)mTimer.GetDelta();
	delta = min(delta, 0.1f);

	timeBank += delta;

	deltaTime = 0.01f;
	deltaTimeScaled = deltaTime * DeltaTimeScalingFactor;
	deltaTimeScaledSquared = deltaTimeScaled * deltaTimeScaled;

#if DEBUG || 1
	timeBank = deltaTime + (deltaTime/2);
#endif

	//while(timeBank > deltaTime)
	{
		//CalculateViscoElasticity();
		UpdateGrid();
		CalculateDensity();
		CalculatePressure();
		UpdateParticles();
		DoCollision();

		timeBank -= deltaTime;
	}
}
Example #2
0
State& State::operator=(const State& rhs) {
    if(this == &rhs) return *this;

    this->_mass = rhs._mass;
    this->_gravMod = rhs._gravMod;
    this->_position = rhs._position;
    this->_velocity = rhs._velocity;
    this->_acceleration = rhs._acceleration;
    this->_forces = rhs._forces;
    this->_impulses = rhs._impulses;
    this->_active = rhs._active;
    this->_mat = rhs._mat;

    IBoundingBox* bb = nullptr;
    if(rhs._bounding_rectangle && dynamic_cast<AABB*>(rhs._bounding_rectangle)) {
        bb = new AABB(*dynamic_cast<AABB*>(rhs._bounding_rectangle));
    }
    if(rhs._bounding_rectangle && dynamic_cast<OBB*>(rhs._bounding_rectangle)) {
        bb = new OBB(*dynamic_cast<OBB*>(rhs._bounding_rectangle));
    }
    this->_bounding_rectangle = bb;

    a2de::Shape* cs = nullptr;
    if(rhs._collision_shape) {
        cs = a2de::Shape::Clone(rhs._collision_shape);
    }
    this->_collision_shape = cs;
    this->_density = CalculateDensity();
    this->_damper = rhs._damper;
    return *this;
}
Example #3
0
//-----------------------------------------------------------------------------
// Name: CSimulationSpace::InterpolateDensitySpace( float fAlpha )
// Desc: calculate the current density space by interpolating the density spaces of the last phase and the next phase
//-----------------------------------------------------------------------------
void CSimulationSpace::InterpolateDensitySpace( float fAlpha)
{
	if( fAlpha <= 0.0 ) // fAlpha is the interpolation factor
	{
		m_pCurrentDensitySpace = m_apDensitySpace[m_uLastPhaseIndex];
	}
	else if( fAlpha >= 1.0 ) 
	{       
		// exchange the indexes of the last phase and the next phase;
		m_uLastPhaseIndex = m_uNextPhaseIndex;
		m_uNextPhaseIndex = !m_uLastPhaseIndex;

		// point current DensitySpace to the DensitySpace of last phase
		m_pCurrentDensitySpace = m_apDensitySpace[m_uLastPhaseIndex];

		// Create the next DensitySpace of the next phase
		CelluarAutomate( m_uNextPhaseIndex );
		CalculateDensity( m_uNextPhaseIndex );
	}
	else
	{
		int index;

		for( int i = 0; i < m_iLength; i++ )
		{
			for( int j = 0; j < m_iHeight; j++)
			{
				for( int k = 0; k < m_iWidth; k++ )
				{
					if( ! IsCellInVolume(i,j,k,&index) ) continue;
					m_pMidDensitySpace[index] = (float)(( 1.0 - fAlpha ) * m_apDensitySpace[m_uLastPhaseIndex][index] 
					+ fAlpha * m_apDensitySpace[m_uNextPhaseIndex][index]);
				}
			}
		}

		m_pCurrentDensitySpace = m_pMidDensitySpace;	
	}
}
Example #4
0
bool CSimulationSpace::Setup( UINT uLength, UINT uWidth, UINT uHigh )
{
	m_iLength = uLength;
	m_iWidth = uWidth; 
	m_iHeight = uHigh;
	int size = uLength * uWidth * uHigh;
	m_uLastPhaseIndex = 0;
	m_uNextPhaseIndex = 1;
	m_iElapsedSteps = 0;

	if(		NewByteSpace( size, &m_apHumSpace[0] )
		&& 	NewByteSpace( size, &m_apHumSpace[1] )
		&& 	NewByteSpace( size, &m_apCldSpace[0] )
		&& 	NewByteSpace( size, &m_apCldSpace[1] )
		&& 	NewByteSpace( size, &m_apActSpace[0] )
		&& 	NewByteSpace( size, &m_apActSpace[1] )
		&&	NewByteSpace( size, &m_pActFactorSpace )
		&& 	NewFloatSpace( size, &m_apDensitySpace[0] )
		&& 	NewFloatSpace( size, &m_apDensitySpace[1] )

		&& 	NewByteSpace( size, &m_pShapeSpace )
		&& 	NewFloatSpace( size, &m_pHumProbSpace )
		&& 	NewFloatSpace( size, &m_pExtProbSpace )
		&& 	NewFloatSpace( size, &m_pActProbSpace )
		&& 	NewFloatSpace( size, &m_pMidDensitySpace )
		)
	{
		m_uTotalNumCells = size;
		InitProbSpace();
		ShapeVolume();
		CelluarAutomate( m_uNextPhaseIndex );
		CalculateDensity( m_uNextPhaseIndex );
		return true;
	}
	else
		return false;
}
	void OpenSMOKE_MatrixSparsityPattern::FindDependence()
	{
		const int max_length_int_vector = static_cast<int> (std::pow(2., 32.) - 1);

		if (is_dependence_available_ == true)
			return;

		is_dependence_available_ = true;

		ElementSparsityPattern *elem;
		number_elements_ = 0;
		max_elements_in_rows_ = 0;
		min_elements_in_rows_ = columns_;
		max_elements_in_cols_ = 0;
		min_elements_in_cols_ = rows_;

		number_equations_per_variable_ = new int[columns_ + 1];
		memset(number_equations_per_variable_, 0, (columns_ + 1)*sizeof(int));

		int maxRow, minRow;
		OpenSMOKE::OpenSMOKEVectorInt elementsInColumn(columns_);
		number_zeros_on_diagonal_ = 0;
		for (int row = 1; row <= rows_; row++)
		{
			maxRow = 0;
			minRow = 0;
			elem = element_row_[row];
			while (elem != 0)
			{
				elementsInColumn(elem->column)++;
				if (elem->column == row)
					number_zeros_on_diagonal_++;
				maxRow++;
				minRow++;
				number_elements_++;
				number_equations_per_variable_[elem->column]++;
				if (number_elements_ == max_length_int_vector)
					OpenSMOKE::FatalErrorMessage("MatrixSparsityPattern::FindDependence(): Too many element dependencies");

				elem = elem->next;
			}
			if (maxRow > max_elements_in_rows_)
			{
				max_elements_in_rows_ = maxRow;
				index_max_row_ = row;
			}
			if (minRow < min_elements_in_rows_)
			{
				min_elements_in_rows_ = minRow;
				index_min_row_ = row;
			}
		}

		max_elements_in_cols_ = elementsInColumn.Max(&index_max_col_);
		min_elements_in_cols_ = elementsInColumn.Min(&index_min_col_);
		number_zeros_on_diagonal_ = Min(rows_, columns_) - number_zeros_on_diagonal_;

		dependencies_ = new int *[columns_ + 1];
		dependencies_[0] = new int[number_elements_ + 1];
		dependencies_[1] = dependencies_[0];
		int *ptrInt = dependencies_[0] + 1;
		int *ivar = new int[columns_ + 1];
		memset(ivar, 0, (columns_ + 1)*sizeof(int));

		for (int var = 1; var < columns_; var++)
			dependencies_[var + 1] = dependencies_[var] + number_equations_per_variable_[var];
		for (int row = 1; row <= rows_; row++)
		{
			elem = element_row_[row];
			while (elem != 0)
			{
				ivar[elem->column]++;
				dependencies_[elem->column][ivar[elem->column]] = row;
				elem = elem->next;
			}
		}
		delete ivar;
		ptrInt = dependencies_[0] + 1;
		char *tempFunz = new char[rows_ + 1];
		char *tempVar = new char[columns_ + 1];
		memset(tempVar, 0, (columns_ + 1)*sizeof(char));
		ptr_derivatives_ = new int[columns_ + 1];
		int *tempDer = new int[columns_ + 1];

		int k;
		int ider = 1;
		int jder = 1;
		int kder;
		number_groups_ = 0;

		int var;
		while (1)
		{
			memset(tempFunz, 0, (rows_ + 1)*sizeof(char));

			for (var = 1; var <= columns_; var++)
			if (tempVar[var] == 0)
				break;

			if (var > columns_)
				break;

			tempVar[var] = 1;
			ptr_derivatives_[ider++] = var;
			number_groups_++;
			kder = 1;
			for (k = 1; k <= number_equations_per_variable_[var]; k++)
				tempFunz[dependencies_[var][k]] = 1;
			while (1)
			{
				for (var += 1; var <= columns_; var++)
				if (tempVar[var] == 0)break;
				if (var > columns_)
				{
					tempDer[jder++] = kder;
					break;
				}
				char no = 0;
				for (k = 1; k <= number_equations_per_variable_[var]; k++)
				{
					if (tempFunz[dependencies_[var][k]] == 1)
					{
						no = 1; break;
					}
				}
				if (no == 0)
				{
					for (k = 1; k <= number_equations_per_variable_[var]; k++)
						tempFunz[dependencies_[var][k]] = 1;
					tempVar[var] = 1;
					ptr_derivatives_[ider++] = var;
					kder++;
				}
			}
		}
		variable_in_group_ = new int *[number_groups_ + 1];
		number_variables_in_group_ = new int[number_groups_ + 1];
		var = 0;
		for (k = 1; k <= number_groups_; k++)
		{
			number_variables_in_group_[k] = tempDer[k];
			variable_in_group_[k] = &ptr_derivatives_[var];
			var += tempDer[k];
		}
		max_number_of_elements_ = rows_*columns_;

		delete tempFunz;
		delete tempVar;
		delete tempDer;

		// Additional analyses
		AnalyzeBand();
		CalculateDensity();
	}
Example #6
0
void State::SetMass(double mass) {
    this->_mass = mass;
    this->_density = CalculateDensity();
}
Example #7
0
State::State(const State& other)
     : _mass(other._mass), _gravMod(other._gravMod), _position(other._position), _velocity(other._velocity), _acceleration(other._acceleration), _forces(other._forces), _impulses(other._impulses), _active(other._active), _mat(other._mat), _bounding_rectangle(nullptr), _collision_shape(nullptr), _density(), _damper(DEFAULT_DAMPER_VALUE) {
    SetBoundingRectangle(other._bounding_rectangle);
    SetCollisionShape(other._collision_shape);
    _density = CalculateDensity();
}
Example #8
0
State::State(double mass, const Vector2D& gravMod, const Vector2D& position, const Vector2D& velocity, double restitution, double static_friction, double kinetic_friction)
     : _mass(mass), _gravMod(gravMod), _position(position), _velocity(velocity), _acceleration(0.0, 0.0), _forces(), _impulses(), _active(true), _mat(restitution, static_friction, kinetic_friction), _bounding_rectangle(nullptr), _collision_shape(nullptr), _density(), _damper(DEFAULT_DAMPER_VALUE) {
    SetBoundingRectangle(_bounding_rectangle);
    SetCollisionShape(_collision_shape);
    _density = CalculateDensity();
}
Example #9
0
void State::SetBoundingRectangle(IBoundingBox* rectangle) {
    delete _bounding_rectangle;
    _bounding_rectangle = rectangle;
    _density = CalculateDensity();
}