void Physics_Cloth::ResizeHooks(float _ratio)
{
	m_hooks = (int)round(_ratio * (m_particlesWidthCount - m_minHooks)) + m_minHooks;


	m_hooks++;
	ResetCloth();	// reset the cloth to see changes
}
void Physics_Cloth::ResizeHeight(float _ratio)
{
	m_height = (int)round(_ratio * (m_maxHeight - m_minHeight)) + m_minHeight;

	if (m_height % 2 == 0)
	{
		// Cloth is even height, want odd
		m_height++;
	}

	// Update Particle Height Count based on new height
	m_particlesHeightCount = m_height + 1;

	// Set the initialized to false to recreate the cloth again
	m_initialisedParticles = false;
	ResetCloth();	// reset the cloth to see changes
}
void Physics_Cloth::ResizeWidth(float _ratio)
{
	m_width = (int)round(_ratio * (m_maxWidth - m_minWidth)) + m_minWidth;

	if (m_width % 2 == 0)
	{
		// Cloth is even width, want odd
		m_width++;
	}

	// Update Particle Width Count based on new width
	m_particlesWidthCount = m_width + 1;

	// Set the initialized to false to recreate the cloth again
	m_initialisedParticles = false;
	ResetCloth();	// reset the cloth to see changes
}
bool Physics_Cloth::Initialise(DX10_Renderer* _pRenderer, DX10_Shader_Cloth* _pShader, int _width, int _height, float _damping, float _timeStep)
{
	if (_pRenderer == 0 || _pShader == 0)
	{
		// Pointer is NULL, initialization failed
		return false;
	}

	// Assign member variables
	BaseInitialise();
	m_pRenderer = _pRenderer;
	m_pShader = _pShader;
	m_width = _width;
	m_height = _height;
	m_particlesWidthCount = m_width + 1;
	m_particlesHeightCount = m_height + 1;
	m_damping = _damping;
	m_timeStep = _timeStep;

	m_minWidth = m_minHeight = 5;
	m_maxWidth = m_maxHeight = 35;

	m_hooks = 3;
	m_minHooks = 2;
	m_maxHooks = m_maxWidth;

	m_selfCollisionRad = 0.85f;

	m_constraintIterations = 3;
	m_breakModifier = 2.4f;
	m_windSpeed = 1.0f;
	m_initialisedParticles = false;
	m_burnTime = 1.5f;
	m_complexWeave = true;

	m_maxBlastRadius = 25.0f;
	m_blastRadius = 10.0f;

	// Set the cloth to initial positions and constraints
	VALIDATE(ResetCloth());

	return true;
}
示例#5
0
void CCloth::Init( int nGridSize, D3DXVECTOR3 v3Gravity, FLOAT fSpringConstant, 
				   FLOAT fNaturalLength, FLOAT fMass, FLOAT fDampFactor, int nPatchTesselation,
				   LPDIRECT3DTEXTURE9 pTexture, D3DXMATRIX* pWorldM )
{
	m_nGridSize = nGridSize;
	
	m_v3Gravity = v3Gravity;
	
	m_fSpringConstant = fSpringConstant;
	m_fNaturalLength  = fNaturalLength;
	
	m_fMass = fMass;
	
	m_fDampFactor = fDampFactor;
	
	m_nPatchTesselation = nPatchTesselation;
	
	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
	//Calculate number of balls
	m_nNumBalls = m_nGridSize * m_nGridSize;
	
	//Calculate number of springs
	//There is a spring pointing right for each ball which is not on the right edge, 
	//and one pointing down for each ball not on the bottom edge
	m_nNumSprings=(m_nGridSize-1)*m_nGridSize*2;
	
	//There is a spring pointing down & right for each ball not on bottom or right,
	//and one pointing down & left for each ball not on bottom or left
	m_nNumSprings+=(m_nGridSize-1)*(m_nGridSize-1)*2;
	
	//There is a spring pointing right (to the next but one ball)
	//for each ball which is not on or next to the right edge, 
	//and one pointing down for each ball not on or next to the bottom edge
	m_nNumSprings+=(m_nGridSize-2)*m_nGridSize*2;
	
	//Create space for balls & springs
	m_pBalls1=new BALL[m_nNumBalls];
	m_pBalls2=new BALL[m_nNumBalls];
	m_pSprings=new SPRING[m_nNumSprings];

	if(!m_pBalls1 || !m_pBalls2 || !m_pSprings)
	{
		//TRACE( "CCloth::Init" );
		return;
	}
	
	m_dStartTime = (double)timeGetTime();
	m_pTexture = pTexture;

	//Reset cloth
	ResetCloth(pWorldM);
/*
	for(int i=0; i<m_nGridSize-1; ++i)
	{
		for(int j=0; j<m_nGridSize-1; ++j)
		{
			D3DXVec3TransformCoord( &m_pCurrentBalls[i*m_nGridSize+j].m_v3Pos, &m_pCurrentBalls[i*m_nGridSize+j].m_v3Pos, pWorldM );
			D3DXVec3TransformCoord( &m_pCurrentBalls[i*m_nGridSize+j+1].m_v3Pos, &m_pCurrentBalls[i*m_nGridSize+j+1].m_v3Pos, pWorldM );
			D3DXVec3TransformCoord( &m_pCurrentBalls[(i+1)*m_nGridSize+j].m_v3Pos, &m_pCurrentBalls[(i+1)*m_nGridSize+j].m_v3Pos, pWorldM );
			D3DXVec3TransformCoord( &m_pCurrentBalls[(i+1)*m_nGridSize+j].m_v3Pos, &m_pCurrentBalls[(i+1)*m_nGridSize+j].m_v3Pos, pWorldM );
			D3DXVec3TransformCoord( &m_pCurrentBalls[i*m_nGridSize+j+1].m_v3Pos, &m_pCurrentBalls[i*m_nGridSize+j+1].m_v3Pos, pWorldM );
			D3DXVec3TransformCoord( &m_pCurrentBalls[(i+1)*m_nGridSize+j+1].m_v3Pos, &m_pCurrentBalls[(i+1)*m_nGridSize+j+1].m_v3Pos, pWorldM );
			
			D3DXVec3TransformCoord( &m_pCurrentBalls[i*m_nGridSize+j].m_v3Normal, &m_pCurrentBalls[i*m_nGridSize+j].m_v3Normal, pWorldM );
			D3DXVec3TransformCoord( &m_pCurrentBalls[i*m_nGridSize+j+1].m_v3Normal, &m_pCurrentBalls[i*m_nGridSize+j+1].m_v3Normal, pWorldM );
			D3DXVec3TransformCoord( &m_pCurrentBalls[(i+1)*m_nGridSize+j].m_v3Normal, &m_pCurrentBalls[(i+1)*m_nGridSize+j].m_v3Normal, pWorldM );
			D3DXVec3TransformCoord( &m_pCurrentBalls[(i+1)*m_nGridSize+j].m_v3Normal, &m_pCurrentBalls[(i+1)*m_nGridSize+j].m_v3Normal, pWorldM );
			D3DXVec3TransformCoord( &m_pCurrentBalls[i*m_nGridSize+j+1].m_v3Normal, &m_pCurrentBalls[i*m_nGridSize+j+1].m_v3Normal, pWorldM );
			D3DXVec3TransformCoord( &m_pCurrentBalls[(i+1)*m_nGridSize+j+1].m_v3Normal, &m_pCurrentBalls[(i+1)*m_nGridSize+j+1].m_v3Normal, pWorldM );
		}
	}
		
/**/
}