⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mathlookup.cpp

📁 手机 GAME c++ 版
💻 CPP
字号:
////////////////////////////////////////////////////////////////////////
//
// MathLookup.cpp
//
// Copyright (c) 2003 Nokia Mobile Phones Ltd.  All rights reserved.
//
////////////////////////////////////////////////////////////////////////

#include "Geometry3D.h"
#include "MathLookup.h"

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

TTrigLookup::TTrigLookup()
	{
	InitCosTable();
	}

////////////////////////////////////////////////////////////////////////

void TTrigLookup::GetTrigRatios(TInt aAngle, TInt &aCos, TInt &aSin)
	{
	TInt lookupIndex = aAngle & quadrantMask;

	TInt rawCos = iCosRatio[ lookupIndex ];
	TInt rawSin = iCosRatio[ quadrantSize - lookupIndex ];

	TInt quadrant = ( aAngle & angleMask ) >> quadrantSizeLog;

	switch ( quadrant )
		{
	case 0:
		aCos = rawCos;
		aSin = rawSin;
		break;

	case 1:
		aCos = -rawSin;
		aSin = rawCos;
		break;

	case 2:
		aCos = -rawCos;
		aSin = -rawSin;
		break;

	case 3:
	default:
		aCos = rawSin;
		aSin = -rawCos;
		break;
		}
	}

////////////////////////////////////////////////////////////////////////

void TTrigLookup::InitCosTable()
	{
	TReal degreesToRadians = 3.141592 / 180.0;

	TReal angle = 0.0;
	TReal angleStep = ( 90.0 / quadrantSize ) * degreesToRadians;

	for ( TInt r = 0 ; r < cosTableSize ; r++ )
		{
		TReal cos;
		TInt16 cosFP;

		Math::Cos(cos,angle);
		Math::Int(cosFP,cos * trigUnity);

		iCosRatio[ r ] = cosFP;

		angle += angleStep;
		}
	}

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

TRecipLookup::TRecipLookup()
	{
	InitRecipTable();
	}

////////////////////////////////////////////////////////////////////////

void TRecipLookup::GetReciprocal(TUint aValue, TInt &aReciprocal, TInt &aDownshift)
	{
	TInt value = aValue;
	TInt baseShift = Geometry3D::Reduce(value, recipTableSize - 1);

	aReciprocal = iRecip[value];
	aDownshift = iShift[value] + baseShift;
	}

////////////////////////////////////////////////////////////////////////

void TRecipLookup::InitRecipTable()
	{
	TReal unity = baseRecipUnity;

	iRecip[0] = 0;
	iShift[0] = 0;

	for ( TInt r = 1 ; r < recipTableSize ; r++ )
		{
		TReal recip = unity / r;
		TInt32 recipAsInt32;
		Math::Int(recipAsInt32, recip);
		TInt recipAsInt = recipAsInt32;

		TInt8 shift = (TInt8)( baseRecipUnityLog - Geometry3D::Reduce(recipAsInt, maxRecip) );

		iRecip[r] = (TInt16)recipAsInt;
		iShift[r] = shift;
		}
	}

////////////////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////////////////

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -