Example #1
0
static Stick NormalizedDeadzoneFilter(short x, short y, float dz, int idzm, float idz, float st) {
	Stick s(x, y, 1.0 / 32767.0f);

	float magnitude = sqrtf(s.x * s.x + s.y * s.y);
	if (magnitude > dz) {

		// Circle to square mapping (the PSP stick outputs the full -1..1 square of values)
#if 1
		// Looks way better than the old one, below, in the axis tester.
		float sx = s.x;
		float sy = s.y;
		float scaleFactor = sqrtf((sx * sx + sy * sy) / std::max(sx * sx, sy * sy));
		s.x = sx * scaleFactor;
		s.y = sy * scaleFactor;
#else
		if (magnitude > 1.0f) {
			s.x *= 1.41421f;
			s.y *= 1.41421f;
		}
#endif

		// Linear range mapping (used to invert deadzones)
		float md = std::max(dz, idz);

		if (idzm == 1)
		{
			float xSign = Signf(s.x);
			if (xSign != 0.0f) {
				s.x = LinearMapf(s.x, xSign * dz, xSign, xSign * md, xSign * st);
			}
		}
		else if (idzm == 2)
		{
			float ySign = Signf(s.y);
			if (ySign != 0.0f) {
				s.y = LinearMapf(s.y, ySign * dz, ySign, ySign * md, ySign * st);
			}
		}
		else if (idzm == 3)
		{
			float xNorm = s.x / magnitude;
			float yNorm = s.y / magnitude;
			float mapMag = LinearMapf(magnitude, dz, 1.0f, md, st);
			s.x = xNorm * mapMag;
			s.y = yNorm * mapMag;
		}

		s.x = Clampf(s.x, -1.0f, 1.0f);
		s.y = Clampf(s.y, -1.0f, 1.0f);
	} else {
		s.x = 0.0f;
		s.y = 0.0f;
	}
	return s;
}
Example #2
0
static void X_Frame_f( void ) {
    if ( ! x_maze.bits || VAR_Changed( x_mazeWidth ) || VAR_Changed( x_mazeHeight ) ) {
        x_maze.size = x_view.size = c2xy( Clampf( VAR_Num( x_mazeWidth ), 64, 1024 ), 
                            Clampf( VAR_Num( x_mazeHeight ), 64, 1024 ) );
        int numBytes = x_maze.size.x * x_maze.size.y;
        x_maze.bits = A_Realloc( x_maze.bits, numBytes * sizeof( *x_maze.bits ) );
        x_view.bits = A_Realloc( x_view.bits, numBytes * sizeof( *x_view.bits ) );
        GenerateTestMaze( x_maze.size, x_maze.bits );
        R_BlitToTexture( x_maze.image, x_maze.bits, x_maze.size, 1 );
        CON_Printf( "Changed size of the maze to %d,%d\n", x_maze.size.x, x_maze.size.y );
    }
    if ( VAR_Changed( x_showCursor ) ) { 
        R_ShowCursor( VAR_Num( x_showCursor ) );
    }
    v2_t windowSize = R_GetWindowSize();
    x_pixelScale = windowSize.y / ( float )x_maze.size.y;
    v2_t mouse = I_GetMousePositionV();
    v2_t origin = v2Scale( mouse, 1 / x_pixelScale );
    memset( x_view.bits, 0, sizeof( *x_view.bits ) * x_view.size.x * x_view.size.y );
    if ( ! VAR_Num( x_skipMaze ) ) {
        // draw the textures before rasterizing
        // so we can draw debug stuff in the raster routine
        R_ColorC( colorScaleRGB( colGreen, 0.5f ) );
        R_BlendPic( 0, 0, x_maze.size.x * x_pixelScale, windowSize.y, 0, 0, 1, 1, x_maze.image );
    }
    R_Color( 1, 1, 1, 0.5 );
    R_BlendPic( 0, 0, x_view.size.x * x_pixelScale, windowSize.y, 0, 0, 1, 1, x_view.image );
    for ( int i = 0; i < Clampi( VAR_Num( x_numOctants ), 0, 8 ); i++ ) {
        RasterizeFOVOctant( origin.x, origin.y,
                            Clampf( VAR_Num( x_losRadius ), 0, 1024 ), 
                            x_maze.size.x, x_maze.size.y,
                            i,
                            VAR_Num( x_skipAttenuation ),
                            VAR_Num( x_skipClipToRadius ),
                            VAR_Num( x_darkWalls ),
                            x_maze.bits, x_view.bits );
    }
    R_BlitToTexture( x_view.image, x_view.bits, x_view.size, 1 );
    //X_DrawCursor( x_cp437Texture, x_cp437TextureSize, mouse );
}
Example #3
0
static Stick NormalizedDeadzoneFilter(short x, short y) {
	static const float DEADZONE = (float)XINPUT_GAMEPAD_LEFT_THUMB_DEADZONE / 32767.0f;
	Stick s;

	s.x = (float)x / 32767.0f;
	s.y = (float)y / 32767.0f;

	float magnitude = sqrtf(s.x * s.x + s.y * s.y);
	
	if (magnitude > DEADZONE) {
		if (magnitude > 1.0f) {
			s.x *= 1.41421f;
			s.y *= 1.41421f;
		}

		s.x = Clampf(s.x, -1.0f, 1.0f);
		s.y = Clampf(s.y, -1.0f, 1.0f);
	} else {
		s.x = 0.0f;
		s.y = 0.0f;
	}
	return s;
}
vector<int> CalcCurvatureAnglePoint(vector<float> listDistance, float angleMax, int dMin, int dMax)
{
	vector<float> _listAngle;
	vector<int> keyframeID;
	int n = listDistance.size() - dMin;

	_listAngle.resize(listDistance.size());
	_listAngle[0] = _listAngle[listDistance.size()-1] = 0.0f;


	int leftIndex = 0;
	int rightIndex = 0;
	int currentIndex = 0;
	float alphaLC = angleMax;
	float dOP, dPR, dOR;

	omp_set_num_threads(2);
	#pragma omp parallel for shared(n,dMin,dMax,angleMax,_listAngle,listDistance) private(currentIndex,leftIndex,rightIndex,alphaLC, dOP, dPR, dOR)
	for (currentIndex = dMin; currentIndex < n; currentIndex++)
	{
		alphaLC = angleMax;
		for (leftIndex = currentIndex - dMax; leftIndex <= currentIndex - dMin; leftIndex++)
		{
			if (leftIndex >= 0)
			{
				dOP = sqrtf(pow(listDistance[currentIndex] - listDistance[leftIndex], 2) + (float)pow(currentIndex - leftIndex, 2));
				for (rightIndex = currentIndex + dMin; rightIndex <= currentIndex + dMax; rightIndex++)
				{
					if (rightIndex < n)
					{
						dPR = sqrtf(pow(listDistance[currentIndex] - listDistance[rightIndex], 2) + (float)pow(currentIndex - rightIndex, 2));
						dOR = sqrtf(pow(listDistance[leftIndex] - listDistance[rightIndex], 2) + (float)pow(leftIndex - rightIndex, 2));

						float numerator = dOP*dOP + dPR*dPR - dOR*dOR;
						float denominator = 2 * dOP * dPR;
						float fraction = Clampf(numerator/denominator, -1.0f, 1.0f);

						float value = acosf(fraction) * 180.0f / (float)M_PI;
						float alpha = (int)(value + 0.5f);

						if (alpha < alphaLC)
						{
							alphaLC = alpha;
						}
					}
				}
			}
		}

		if (alphaLC < angleMax)
		{
			_listAngle[currentIndex] = alphaLC;
		}
		else
		{
			_listAngle[currentIndex] = 180.0f;
		}
	}
//	_listAngle.push_back(0.0f);

	//Check for redundant curvature points
	int windowSize = 5;
	int lastIndex = 0;
	int i = windowSize;

	cout << "Select frame: ";
	int numAngle = (int)_listAngle.size();
	while (i < numAngle)
	{
		if (IsHighCurvaturePoint(_listAngle, windowSize, i))
		{
			int index = (lastIndex + i) / 2;
			keyframeID.push_back(index);

			lastIndex = i;

			i += (windowSize+1);

			cout << index << " ";
		}
		else
		{
			i++;
		}
	}
	cout << endl;

	return keyframeID;
}
void Player::Update(float t)
{
    //Direction Vector
    float dx = 0;   //Reset every frame
    float dy = 0;   //Reset every frame

    //Increment the shoot timer.
    ShootTimer += t;

    //NOTE: Keyboard input
    if(Up)
    {
        dy = -1;    //set direction up
    }
    if(Down)
    {
        dy = 1; //set direction down
    }
    if(Left)
    {
        dx = -1;    //set direction left
    }
    if(Right)
    {
        dx = 1; //set direction right
    }

    //SHOOT!!
    if(Shoot && ShootTimer >= ShootRate)
    {
        laserPool.SpawnObject(x() + centerX / 2, y() - centerY);
        ShootTimer = 0;

        //Play laser sound
        laserShot->PlayOneShot();
    }

    //NOTE: Check Bounds
    CheckBounds(0, 0, 800, 600);

    dx *= power;    //scale direction vector by speed
    dy *= power;

    //Drag coeficient
    vx += dx * t;   //Add the direction scaled by the time to the velocity vector.
    vy += dy * t;

    //Clamp X and Y velocity by our Speed
    Clampf(vx, -power, power);
    Clampf(vy, -power, power);

    //Set position and scale it by drag
    setPos(x() + vx * drag, y() + vy * drag);

    /// Check for collision with enemies and lasers
    for( int i = 0; i < this->collidingItems().size(); ++i)
    {
        EnemyBase* enemy = dynamic_cast<EnemyBase*>(this->collidingItems()[i]);

        if(enemy)
        {
            lives->decreaseLives();
            enemy->kill();

            break;
        }

        EnemyLaser* enemyLaser = dynamic_cast<EnemyLaser*>(this->collidingItems()[i]);

        if(enemyLaser)
        {
            lives->decreaseLives();
            enemyLaser->setIsAlive(false);

            break;
        }
    }
}
Example #6
0
//Zoom or CCamera distance from scene is clamped.
void CArcBallCamera::setZoom(float r)
{
	Clampf(r, zoomMin, zoomMax);
	m_rho = r;
}
Example #7
0
//Set our vertical angle. This is clamped between 0 and 180
void CArcBallCamera::setVerticalAngle(float p)
{
	Clampf(p, verticalAngleMin, verticalAngleMax);
	m_phi = p;
}