public cMovement(cMovement original) { this.m_size = original.m_size; if (m_size > 0) { this.m_buffer = new iVector[m_size]; for (int i = 0; i < m_size; i++) { m_buffer[i] = original.m_buffer[i]; } } else { m_buffer = new iVector[0]; } }
public bool copy(cMovement original) { this.m_size = original.m_size; if (m_size > 0) { this.m_buffer = new iVector[m_size]; for (int i = 0; i < m_size; i++) { m_buffer[i] = original.m_buffer[i]; } } else { m_buffer = new iVector[0]; } return(true); }
/*! Change the size of a movement * \note OutputVector buffer will be created automatically if needed * \note The function have better results if input movements are positive (see note in the code) * \return Success */ bool changeVectorSize( cMovement inputMovement, /**< Input movement used as model */ int newSize, /**< Size of the new vector */ cMovement ptOutputMovement ) /**< Output vector resized */ { // input checks if( null == ptOutputMovement || inputMovement == ptOutputMovement) { return false; } if( ptOutputMovement.m_size != newSize ) { // output buffer creation if( ptOutputMovement.m_buffer.Length==0 ) { ptOutputMovement.m_buffer=new iVector[0]; } ptOutputMovement.m_size = newSize; ptOutputMovement.m_buffer = new iVector[ newSize ]; } // Compute normalised vector for( int i=0; i<newSize; i++ ) { // Start End // S-------X-------X------E Movement // A B // S----------X-----------E Normalised // C = value to find // A B, closed value to C // // X = value(A)*(distanceBC/distanceAB) + value(B)*(distanceAC/distanceAB) // distanceAB = 1/ (movement vector size -1) // distanceSA = distanceAB* A index (same for SB) // distanceSC = ( 1/ (normalised vector size -1) ) * C index // distanceAC = distanceSC - distanceSA // distanceBC = distanceSB - distanceSC int indexC = i; float distanceAB = ( 1.0f/((float)inputMovement.m_buffer.Length -1.0f) ); float distanceSC = ( 1.0f/((float)ptOutputMovement.m_buffer.Length-1.0f) ) * indexC; int indexA=0, indexB=0; for( int j=0; j<inputMovement.m_buffer.Length; j++) { if( j*distanceAB == distanceSC ) { indexA = j; indexB = j; break; } if( j*distanceAB > distanceSC ) { indexA = j-1; indexB = j; break; } } float distanceSA = distanceAB * indexA; float distanceSB = distanceAB * indexB; float distanceAC = distanceSC - distanceSA; float distanceBC = distanceSB - distanceSC; if( indexA == indexB ) { ptOutputMovement.m_buffer[i] = inputMovement.m_buffer[indexA]; } else { // 0.5f added to have a better float to int cast // NOTE : this works ONLY when the float value is greater than 0 // In the case of the accelerometers values as used in AGR, this is not an issue. ptOutputMovement.m_buffer[i].x = (int)( 0.5f + inputMovement.m_buffer[indexA].x*(distanceBC/distanceAB) + inputMovement.m_buffer[indexB].x*(distanceAC/distanceAB) ); ptOutputMovement.m_buffer[i].y = (int)( 0.5f + inputMovement.m_buffer[indexA].y*(distanceBC/distanceAB) + inputMovement.m_buffer[indexB].y*(distanceAC/distanceAB) ); ptOutputMovement.m_buffer[i].z = (int)( 0.5f + inputMovement.m_buffer[indexA].z*(distanceBC/distanceAB) + inputMovement.m_buffer[indexB].z*(distanceAC/distanceAB) ); } } return true; }
public bool copy(cMovement original){ this.m_size=original.m_size; if(m_size>0){ this.m_buffer=new iVector[m_size]; for(int i=0;i<m_size;i++){ m_buffer[i]=original.m_buffer[i]; } } else m_buffer=new iVector[0]; return true; }
/*! Change the size of a movement * \note OutputVector buffer will be created automatically if needed * \note The function have better results if input movements are positive (see note in the code) * \return Success */ bool changeVectorSize(cMovement inputMovement, /**< Input movement used as model */ int newSize, /**< Size of the new vector */ cMovement ptOutputMovement) /**< Output vector resized */ { // input checks if (null == ptOutputMovement || inputMovement == ptOutputMovement) { return(false); } if (ptOutputMovement.m_size != newSize) { // output buffer creation if (ptOutputMovement.m_buffer.Length == 0) { ptOutputMovement.m_buffer = new iVector[0]; } ptOutputMovement.m_size = newSize; ptOutputMovement.m_buffer = new iVector[newSize]; } // Compute normalised vector for (int i = 0; i < newSize; i++) { // Start End // S-------X-------X------E Movement // A B // S----------X-----------E Normalised // C = value to find // A B, closed value to C // // X = value(A)*(distanceBC/distanceAB) + value(B)*(distanceAC/distanceAB) // distanceAB = 1/ (movement vector size -1) // distanceSA = distanceAB* A index (same for SB) // distanceSC = ( 1/ (normalised vector size -1) ) * C index // distanceAC = distanceSC - distanceSA // distanceBC = distanceSB - distanceSC int indexC = i; float distanceAB = (1.0f / ((float)inputMovement.m_buffer.Length - 1.0f)); float distanceSC = (1.0f / ((float)ptOutputMovement.m_buffer.Length - 1.0f)) * indexC; int indexA = 0, indexB = 0; for (int j = 0; j < inputMovement.m_buffer.Length; j++) { if (j * distanceAB == distanceSC) { indexA = j; indexB = j; break; } if (j * distanceAB > distanceSC) { indexA = j - 1; indexB = j; break; } } float distanceSA = distanceAB * indexA; float distanceSB = distanceAB * indexB; float distanceAC = distanceSC - distanceSA; float distanceBC = distanceSB - distanceSC; if (indexA == indexB) { ptOutputMovement.m_buffer[i] = inputMovement.m_buffer[indexA]; } else { // 0.5f added to have a better float to int cast // NOTE : this works ONLY when the float value is greater than 0 // In the case of the accelerometers values as used in AGR, this is not an issue. ptOutputMovement.m_buffer[i].x = (int)(0.5f + inputMovement.m_buffer[indexA].x * (distanceBC / distanceAB) + inputMovement.m_buffer[indexB].x * (distanceAC / distanceAB)); ptOutputMovement.m_buffer[i].y = (int)(0.5f + inputMovement.m_buffer[indexA].y * (distanceBC / distanceAB) + inputMovement.m_buffer[indexB].y * (distanceAC / distanceAB)); ptOutputMovement.m_buffer[i].z = (int)(0.5f + inputMovement.m_buffer[indexA].z * (distanceBC / distanceAB) + inputMovement.m_buffer[indexB].z * (distanceAC / distanceAB)); } } return(true); }