Esempio n. 1
0
//
// XInputGamePad::normAxisPair
//
// Normalize a bonded pair of analog axes.
//
void XInputGamePad::normAxisPair(float &axisx, float &axisy, int threshold, 
                                 int min, int max)
{
   float deadzone = (float)threshold / max;
   v2float_t vec = { axisx, axisy };

   // put components into the range of -1.0 to 1.0
   vec.x = (vec.x - min) * 2.0f / (max - min) - 1.0f;
   vec.y = (vec.y - min) * 2.0f / (max - min) - 1.0f;

   float magnitude = M_MagnitudeVec2(vec);

   if(magnitude < deadzone)
   {
      axisx = 0.0f;
      axisy = 0.0f;
   }
   else
   {
      M_NormalizeVec2(vec, magnitude);

      // rescale to smooth edge of deadzone
      axisx = vec.x * ((magnitude - deadzone) / (1 - deadzone));
      axisy = vec.y * ((magnitude - deadzone) / (1 - deadzone));
   }
}
Esempio n. 2
0
void	Scene_SetWindVector(float x, float y)
{
	SET_VEC2(wind_vec, x, y);
	
	for(int i=0;i<4;i++) {
		SET_VEC2(wind_waves[i].dir, M_Randnum(0.1, 6.0), M_Randnum(-6.0, 6.0));
		M_NormalizeVec2(wind_waves[i].dir);
		//SET_VEC2(wind_waves[i].dir, wind_waves[i].dir[1], -wind_waves[i].dir[0]); 
	}
}
Esempio n. 3
0
void NavRep_RenderLine(vec2_t src, vec2_t dest, float height)
{
#ifndef _S2_DONT_INCLUDE_GL
	pointinfo_t pi;
	vec2_t dir;
	float x, y, mag, t;
	M_SubVec2(dest, src, dir);
	mag = M_NormalizeVec2(dir);

	for ( t = 0 ; t < navrep_rendertess.value ; ++t )
	{
		x = src[0] + dir[0]*mag*t/(float)navrep_rendertess.value;
		y = src[1] + dir[1]*mag*t/(float)navrep_rendertess.value;
		World_SampleGround(x, y, &pi);
		glVertex3f(x, y, pi.z+height);
		x = src[0] + dir[0]*mag*(t+1)/(float)navrep_rendertess.value;
		y = src[1] + dir[1]*mag*(t+1)/(float)navrep_rendertess.value;
		World_SampleGround(x, y, &pi);
		glVertex3f(x, y, pi.z+height);
	}
#endif
}