コード例 #1
0
/**
 *	@param fX	X position to convert to a column.
 *	@param fY	Y position to convert to a column.
 *	@param iColumn	Filled in with a column.
 *	@return true if the position maps to a column.
 */
bool CGameBoard::PositionToColumn( FLOAT32 fX, FLOAT32 fY, int& iColumn ) const
{
//	 fPIECE_RADIUS+fPIECE_SPACING+(fPIECE_SPACING + fPIECE_RADIUS*2)*x;
	fY -= fPIECE_SPACING;
	if ( fY < 0.0f )
	{
		return false;
	}
	if ( fY >= fPIECE_RADIUS+(fPIECE_SPACING + fPIECE_RADIUS*2.0f)*FLOAT32(m_iHeight) )
	{
		return false;
	}

	fX -= fPIECE_SPACING;
	if ( fX < 0.0f )
	{
		return false;
	}
	fX/= (fPIECE_SPACING + fPIECE_RADIUS*2.0f);
	if ( fX >= FLOAT32(m_iWidth) )
	{
		return false;
	}
	iColumn = int(fX);
	return true;
}
コード例 #2
0
	//! Returns the animated mesh based on a detail level. 0 is the lowest, 255 the highest detail.
	IMesh* CAnimatedMeshMD3::getMesh(SINT32 frame, SINT32 detailLevel, SINT32 startFrameLoop, SINT32 endFrameLoop)
	{
		if (0 == Mesh)
			return 0;

		//! check if we have the mesh in our private cache
		SCacheInfo candidate(frame, startFrameLoop, endFrameLoop);
		if (candidate == Current)
			return MeshIPol;

		startFrameLoop = SINT32_max(0, startFrameLoop >> IPolShift);
		endFrameLoop = if_c_a_else_b(endFrameLoop < 0, Mesh->MD3Header.numFrames - 1, endFrameLoop >> IPolShift);

		const UINT32 mask = 1 << IPolShift;

		SINT32 frameA;
		SINT32 frameB;
		FLOAT32 iPol;

		if (LoopMode)
		{
			// correct frame to "pixel center"
			frame -= mask >> 1;

			// interpolation
			iPol = FLOAT32(frame & (mask - 1)) * reciprocal(FLOAT32(mask));

			// wrap anim
			frame >>= IPolShift;
			frameA = if_c_a_else_b(frame < startFrameLoop, endFrameLoop, frame);
			frameB = if_c_a_else_b(frameA + 1 > endFrameLoop, startFrameLoop, frameA + 1);
		}
		else
		{
コード例 #3
0
	//!
	SINT32 CGUIScrollBar::getPosFromMousePos(const Position2d &pos) const
	{
		FLOAT32 w, p;
		if (Horizontal)
		{
			w = RelativeRect.getWidth() - FLOAT32(RelativeRect.getHeight())*3.0f;
			p = pos.x - AbsoluteRect.UpperLeftCorner.x - RelativeRect.getHeight()*1.5f;
		}
		else
		{
			w = RelativeRect.getHeight() - FLOAT32(RelativeRect.getWidth())*3.0f;
			p = pos.y - AbsoluteRect.UpperLeftCorner.y - RelativeRect.getWidth()*1.5f;
		}
		return (SINT32)(p / w * range()) + Min;
	}
コード例 #4
0
ファイル: ASCFont.cpp プロジェクト: Matt392/Ascension
FLOAT32 
ASCFont::Width(ASCString& strString)
{
	UINT32 iWidth = 0;
	UINT32 uNewWidth = 0;

	for( UINT32 uChar = 0; uChar < strString.length(); ++uChar )
	{
		if(strString[uChar] == '\n')
		{
			if(uNewWidth > iWidth)
			{
				iWidth = uNewWidth;
			}
			uNewWidth = 0;
		}
		else
		{
			SCharacter& CharData = GetCharacter(strString[uChar]);
				uNewWidth += 
					(UINT32)CharData.fPixelsBeforeChar 
					+ CharData.sRect.m_iWidth 
					+ (UINT32)CharData.fPixelsAfterChar;
		}
	}
	if(uNewWidth > iWidth)
	{
		iWidth = uNewWidth;
	}

	return( FLOAT32( iWidth ) );
}
コード例 #5
0
// Returns the distance between two histograms.
FLOAT32 CObjectTracker::FindDistance(UBYTE8 (*histogram))
{
  SINT16  i = 0;
  FLOAT32 distance = 0;

  
  for(i=0;i<HISTOGRAM_LENGTH;i++)
	  distance += FLOAT32(sqrt(DOUBLE64(m_sTrackingObjectTable[m_cActiveObject].initHistogram[i]
                  *histogram[i])));

  return(distance);
}
コード例 #6
0
ファイル: ASCFont.cpp プロジェクト: Matt392/Ascension
FLOAT32 
ASCFont::GetStringWidth( ASCString& strMessage )
{
	UINT32 iWidth = 0;

	for( UINT32 uChar = 0; uChar < strMessage.length(); ++uChar )
	{
		SCharacter& CharData = GetCharacter(strMessage[uChar]);
			iWidth += 
				(UINT32)CharData.fPixelsBeforeChar 
				+ CharData.sRect.m_iWidth 
				+ (UINT32)CharData.fPixelsAfterChar;
	}

	return( FLOAT32( iWidth ) );
}
コード例 #7
0
//An alternative distance measurement 
FLOAT32 CObjectTracker::CompareHistogram(UBYTE8 (*histogram))
{
  SINT16  i	 = 0;
  FLOAT32 distance = 0.0;
  FLOAT32 difference = 0.0;

  
  for (i=0;i<HISTOGRAM_LENGTH;i++)
  {
	  difference = FLOAT32(m_sTrackingObjectTable[m_cActiveObject].initHistogram[i]
                         -histogram[i]);

	  if (difference>0)
		  distance += difference;
	  else
  		  distance -= difference;
  }
  return(distance);
}
コード例 #8
0
ファイル: Scene31.cpp プロジェクト: sunzhiyuan/opencl
//--------------------------------------------------------------------------------------
// Name: SetupGaussWeights()
// Desc: 
//--------------------------------------------------------------------------------------
VOID CSample31::SetupGaussWeights()
{
    FLOAT32 GaussSum = 0.0f;
    for( int i = 0; i < 4; i++ )
    {
        // normalize to -1..1
        FLOAT32 X = ( FLOAT32( i ) / 3.0f );
        X = ( X - 0.5f ) * 2.0f;

        // spread is tunable
        X *= m_BlurShader.GaussSpread;

        m_BlurShader.GaussWeight[i] = GaussianDistribution31( X, 0.0f, m_BlurShader.GaussRho );

        GaussSum += m_BlurShader.GaussWeight[i];
    }

    m_BlurShader.GaussInvSum = ( 1.0f / GaussSum );
}
コード例 #9
0
ファイル: ASCFont.cpp プロジェクト: Matt392/Ascension
FLOAT32 
ASCFont::GetLineWidth( ASCString& strMessage, UINT32 uStart )
{
	UINT32 iWidth = 0;

	for( UINT32 uChar = uStart; uChar < strMessage.length(); ++uChar )
	{
		if(strMessage[uChar] == '\n')
		{
			break;
		}
		SCharacter& CharData = GetCharacter(strMessage[uChar]);
			iWidth += 
				(UINT32)CharData.fPixelsBeforeChar 
				+ CharData.sRect.m_iWidth 
				+ (UINT32)CharData.fPixelsAfterChar;
	}

	return( FLOAT32( iWidth ) );
}
コード例 #10
0
void U_Unpackfp32( float *fp32 )
{

	switch( packedmode )
	{
	case U_PACKED_BIN:
		memcpy( fp32, cur_pos, 4 );

		*fp32 = FLOAT32( *fp32 );
		cur_pos+=4;
		cur_size+=4;
		break;
	
	case U_PACKED_ASC:
		U_UnpackToken();
		*fp32 = atof( u_token );
		break;

	default:
		__error( "unknown packedmode\n" );
	}
}
コード例 #11
0
/*
  ====================
  U_Packfp32

  ====================
*/
void U_Packfp32( float fp32 )
{
	char	tmp[4];

	if ( cur_size + 4 >= cur_maxsize )
	{

	}

	fp32 = FLOAT32( fp32 );

	memcpy( tmp, &fp32, 4 );

	*cur_pos = tmp[0];
	cur_pos++;
	*cur_pos = tmp[1];
	cur_pos++;
	*cur_pos = tmp[2];
	cur_pos++;
	*cur_pos = tmp[3];
	cur_pos++;

	cur_size += 4;	
}
コード例 #12
0
			frame -= mask >> 1;

			// interpolation
			iPol = FLOAT32(frame & (mask - 1)) * reciprocal(FLOAT32(mask));

			// wrap anim
			frame >>= IPolShift;
			frameA = if_c_a_else_b(frame < startFrameLoop, endFrameLoop, frame);
			frameB = if_c_a_else_b(frameA + 1 > endFrameLoop, startFrameLoop, frameA + 1);
		}
		else
		{
			// correct frame to "pixel center"
			frame -= mask >> 1;

			iPol = FLOAT32(frame & (mask - 1)) * reciprocal(FLOAT32(mask));

			// clamp anim
			frame >>= IPolShift;
			frameA = SINT32_clamp(frame, startFrameLoop, endFrameLoop);
			frameB = SINT32_min(frameA + 1, endFrameLoop);
		}

		// build current vertex
		for (UINT32 i = 0; i != Mesh->Buffer.size(); ++i)
		{
			buildVertexArray(frameA, frameB, iPol,
				Mesh->Buffer[i],
				(SMeshBufferLightMap*)MeshIPol->getMeshBuffer(i));
		}
		MeshIPol->recalculateBoundingBox();
コード例 #13
0
void	CSquirrel::Update( FLOAT32 fTimeDelta )
{
	if ( 0 == m_uNumLives )
	{
		return;
	}

	const static CFVec2 s_vMoveOffsets[] = 
	{
		SFVec2( -1.0f,  0.0f ), //"Left",
		SFVec2(  1.0f,  0.0f ), //"Right",
		SFVec2(  0.0f, -1.0f ), //"Up",
		SFVec2(  0.0f,  1.0f ), //"Down"
	};

	_COMPILE_ASSERT( _ARRAY_SIZE( s_vMoveOffsets ) == EMove_COUNT );

	CFVec2 vMove = SFVec2( 0.0f, 0.0f );
	for ( UINT32 i=0; i< EMove_COUNT; i++ )
	{
		if ( m_Movements[i].m_bValue )
		{
			vMove += s_vMoveOffsets[i];
		}
	}

	// great, now we have the movement direction.
	if ( vMove.SquareMagnitude() != 0.0f )
	{
		m_fDistTimeMoving += fTimeDelta;
		vMove.Normalise();
		FLOAT32 fStep = 1.0f;
		CFVec2 vTestedMove = vMove * fTimeDelta * m_fSpeed * fStep;
		// now check the target position -  is it embedded in any walls?
		CCircle TargetBounds;
		while ( fStep > 0.0f )
		{
			TargetBounds.Initialise( m_vPosition + vTestedMove, m_fRadius );
			if ( false == CMMMContext::GetInstance().CircleIntersectsGeometry( TargetBounds ) )
			{
				break;	// found a valid, allowable movement.
			}
			fStep -= 0.2f;
			vTestedMove = vMove * fTimeDelta * m_fSpeed * fStep;
		}
		// now update to the new position
		m_vPosition += vTestedMove;

		// finally what happens at the new position
		// is an acorn collected?
		if ( m_uNumAcorns != m_uMaxAcorns )
		{
			CAcorn* pLevelAcorns;
			UINT32 uNumLevelAcorns;
			CMMMContext::GetInstance().GetAcorns( pLevelAcorns, uNumLevelAcorns );
			for ( UINT32 i=0; i<uNumLevelAcorns; i++ )
			{
				if ( pLevelAcorns[i].GetState() == CAcorn::ES_Available )
				{
					if ( pLevelAcorns[i].Intersects( TargetBounds ) )
					{
						pLevelAcorns[i].SetState( CAcorn::ES_Carried );
						m_ppAcorns[m_uNumAcorns++] = pLevelAcorns+i;
						if ( m_uNumAcorns == m_uMaxAcorns )
						{
							break;	// cannont collect any more!
						}
					}
				}
			}
		}
		// is a tunnel reached?
		if ( m_uNumAcorns > 0 )
		{
			CTunnel*	pTunnels;
			UINT32		uNumTunnels;
			CMMMContext::GetInstance().GetTunnels( pTunnels, uNumTunnels );
			for ( UINT32 i=0; i<uNumTunnels; i++ )
			{
				if ( pTunnels[i].Intersects( TargetBounds ) )
				{
					// reached the tunnel.
					for ( UINT32 i=0; i<m_uNumAcorns; i++ )
					{
						m_ppAcorns[i]->SetState( CAcorn::ES_Collected );
						m_uScore++;
					}
					m_uNumAcorns = 0;
				}
			}
		}
	}

	m_fTimeToDisturbance -= fTimeDelta;
	if ( m_fTimeToDisturbance <= 0.0f )
	{
		// schedule the next disturbance.
		m_fTimeToDisturbance = FLOAT32(rand())/FLOAT32(RAND_MAX);
		m_fTimeToDisturbance *= m_fMaxDistSep-m_fMinDistSep;
		m_fTimeToDisturbance += m_fMinDistSep;

		// create this disturbance:
		FLOAT32 fRad = m_fLastDistDelay=0.0f?0.0f:m_fDistTimeMoving/m_fLastDistDelay;
//		DbgPrint( "Creating Disturbance strength %0.2f, next delay %0.2f\n", fRad,m_fTimeToDisturbance );
		fRad *= m_fMaxDistRad-m_fMinDistRad;
		fRad += m_fMinDistRad;

		if ( fRad >= 0.0f )
		{
			CCircle Dist;
			Dist.Initialise( m_vPosition, fRad );
			CMMMContext::GetInstance().CreateDisturbance( Dist );
		}
		m_fDistTimeMoving = 0.0f;
		m_fLastDistDelay = m_fTimeToDisturbance;
	}



}
コード例 #14
0
ファイル: ASCFont.cpp プロジェクト: Matt392/Ascension
void 
ASCFont::ProcessLetterLine( ASCString& strLine, UINT32 iCurCharacter )
{
	UINT32 i = 0;
	bool bHex = strLine[0] != '\"';
	if(bHex)
	{
		UINT32 iChar = 0;
		const char strHex[2] = { strLine[ 0 ], strLine[ 1 ] };
#ifdef ASC_IOS
		sscanf( strHex, "%2x", &iChar );
#else
		sscanf_s( strHex, "%2x", &iChar );
#endif
		m_pCharacters[ iCurCharacter ].cCharacter = static_cast< char >( iChar );
	}
	else
	{
		++i;
		m_pCharacters[ iCurCharacter ].cCharacter = strLine[ i ];
	}
	++i;

	ASCString strTemp;
	strLine.substr(i, strTemp);
	strLine = strTemp;

	ASCString strWorkWith;
	ASCString strTheRest;
	UINT32 iInfoBitsFound = 0;

	SINT32 iAt = strLine.find(',');
	if(iAt >= 0)
	{
		ASCString strTemp;
		strLine.substr(iAt+1, strTemp);
		strLine = strTemp;
	}

	while(iAt >= 0 && iInfoBitsFound < 6)
	{
		iAt = strLine.find(',');
		strLine.split(iAt+1, strWorkWith, strTheRest);
		ASCString strTemp;
		strLine.substr(iAt+1, strTemp);
		strLine = strTemp;
		if(strWorkWith[0] == ',')
		{
			continue;
		}

		switch( iInfoBitsFound )
		{
		case 0:
			{
				//m_pCharacters[ iCurCharacter ].sRect.iLeft = atoi( strWorkWith.c_str() );
				m_pCharacters[ iCurCharacter ].sRect.m_iX = atoi( strWorkWith.c_str() );
			}
			break;
		case 1:
			{
				//m_pCharacters[ iCurCharacter ].sRect.iTop = atoi( strWorkWith.c_str() );
				m_pCharacters[ iCurCharacter ].sRect.m_iY = atoi( strWorkWith.c_str() );
			}
			break;
		case 2:
			{
				//m_pCharacters[ iCurCharacter ].sRect.iRight = atoi( strWorkWith.c_str() );
				m_pCharacters[ iCurCharacter ].sRect.m_iWidth = atoi( strWorkWith.c_str() );
			}
			break;
		case 3:
			{
				//m_pCharacters[ iCurCharacter ].sRect.iBottom = atoi( strWorkWith.c_str() );
				m_pCharacters[ iCurCharacter ].sRect.m_iHeight = atoi( strWorkWith.c_str() );
			}
			break;
		case 4:
			{
				m_pCharacters[ iCurCharacter ].fPixelsBeforeChar = FLOAT32( atof( strWorkWith.c_str() ) );
			}
			break;
		case 5:
			{
				m_pCharacters[ iCurCharacter ].fPixelsAfterChar = FLOAT32( atof( strWorkWith.c_str() ) );
			}
			break;
		default:break;
		}
		++iInfoBitsFound;
		iAt = strLine.find(',');
		if(iAt < 0 && iInfoBitsFound == 5)
		{
			m_pCharacters[ iCurCharacter ].fPixelsAfterChar = FLOAT32( atof( strLine.c_str() ) );
		}
	}
}