Esempio n. 1
0
Vector UTIL_YawToVector( float yaw )
{
	Vector ret;
	
	ret.z = 0;
	float angle = DEG2RAD( yaw );
	SinCos( angle, &ret.y, &ret.x );

	return ret;
}
//-----------------------------------------------------------------------------
// Purpose: 
// Input  : pMaterial - 
//			source - 
//			color - 
//-----------------------------------------------------------------------------
void DrawHaloOriented( const Vector& source, float scale, float const *color, float roll )
{
	Vector point, screen;
	
	CMatRenderContextPtr pRenderContext( materials );
	IMesh* pMesh = pRenderContext->GetDynamicMesh();

	CMeshBuilder meshBuilder;
	meshBuilder.Begin( pMesh, MATERIAL_QUADS, 1 );

	// Transform source into screen space
	ScreenTransform( source, screen );

	Vector right, up;
	float sr, cr;

	SinCos( roll, &sr, &cr );

	for ( int i = 0; i < 3; i++ )
	{
		right[i] = CurrentViewRight()[i] * cr + CurrentViewUp()[i] * sr;
		up[i] = CurrentViewRight()[i] * -sr + CurrentViewUp()[i] * cr;
	}

	meshBuilder.Color3fv (color);
	meshBuilder.TexCoord2f (0, 0, 1);
	VectorMA (source, -scale, up, point);
	VectorMA (point, -scale, right, point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv (color);
	meshBuilder.TexCoord2f (0, 0, 0);
	VectorMA (source, scale, up, point);
	VectorMA (point, -scale, right, point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv (color);
	meshBuilder.TexCoord2f (0, 1, 0);
	VectorMA (source, scale, up, point);
	VectorMA (point, scale, right, point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();

	meshBuilder.Color3fv (color);
	meshBuilder.TexCoord2f (0, 1, 1);
	VectorMA (source, -scale, up, point);
	VectorMA (point, scale, right, point);
	meshBuilder.Position3fv (point.Base());
	meshBuilder.AdvanceVertex();
	
	meshBuilder.End();
	pMesh->Draw();
}
Esempio n. 3
0
void nospread::ApplySpread(int sequence_number, Entity *pl, Angle &angles, float factor)
{
	Entity *w = pl->GetActiveWeapon();

	int random_seed = md5_random(sequence_number) & 0x7fffffff;

#if defined(CSS) || defined(CSGO)
	RandomSeed(random_seed + 1 & 0xff);

	w->UpdateAccuracyPenalty();

	float random1 = RandomFloat(0.0f, pi * 2.0f);
	float spread1 = RandomFloat(0.0f, w->GetWeaponCone());
	float random2 = RandomFloat(0.0f, pi * 2.0f);
	float spread2 = RandomFloat(0.0f, w->GetWeaponSpread());

	float sin1, cos1, sin2, cos2;
	SinCos(random1, sin1, cos1);
	SinCos(random2, sin2, cos2);

	Vector spread = Vector(1.0f, (cos1 * spread1 + cos2 * spread2) * -factor, (sin1 * spread1 + sin2 * spread2) * factor);
	spread.Normalize();

	Angle shake;
	VectorAngles(spread, shake);

	angles += shake;
#endif

#if defined(L4D) || defined(L4D2)
	static auto SharedRandomFloat = (float (*)(const char *, float, float, int))util::FindProlog(util::FindString(GetModuleHandle("client"), "SharedRandomFloat"));
	static int &r_random_seed = **(int **)util::FindPattern((void *)SharedRandomFloat, 0x100, ((const pattern *)"\x01\x01\x00\x00\x00\xA1"));

 	r_random_seed = random_seed;

	float spread = w->GetWeaponSpread();

	angles.x += SharedRandomFloat("CTerrorGun::FireBullet HorizSpread", -spread, spread, 0) * factor;
	angles.y += SharedRandomFloat("CTerrorGun::FireBullet VertSpread",  -spread, spread, 0) * factor;
#endif
}
Esempio n. 4
0
void	RotateVector2D(Vec2f &vec, Float Angle)
{ 
	Vec2f tp;

	Vec2f   SC;
	SinCos(SC,Angle);

	tp.x = SC.y*vec.x - SC.x*vec.y;
	tp.y = SC.x*vec.x + SC.y*vec.y;

	vec.x=tp.x;
	vec.y=tp.y;
}
Esempio n. 5
0
inline void CVector3::Rotate2D(const float f)
{
	float _x, _y;

	float s, c;

	SinCos(DEG2RAD(f), s, c);

	_x = x;
	_y = y;

	x = (_x * c) - (_y * s);
	y = (_x * s) + (_y * c);
}
Esempio n. 6
0
/*
===============
CL_EntityParticles

set EF_BRIGHTFIELD effect
===============
*/
void CL_EntityParticles( cl_entity_t *ent )
{
	float		angle;
	float		sr, sp, sy, cr, cp, cy;
	vec3_t		forward;	
	particle_t	*p;
	int		i;

	for( i = 0; i < NUMVERTEXNORMALS; i++ )
	{
		p = CL_AllocParticle( NULL );
		if( !p ) return;

#ifdef VECTORIZE_SINCOS
		SinCosFastVector( cl.time * cl_avelocities[i][0], cl.time * cl_avelocities[i][1], cl.time * cl_avelocities[i][2], 0,
						  &sy, &sp, &sr, NULL,
						  &cy, &cp, &cr, NULL);
#else
		angle = cl.time * cl_avelocities[i][0];
		SinCos( angle, &sy, &cy );
		angle = cl.time * cl_avelocities[i][1];
		SinCos( angle, &sp, &cp );
		angle = cl.time * cl_avelocities[i][2];
		SinCos( angle, &sr, &cr );
#endif
	
		VectorSet( forward, cp * cy, cp * sy, -sp ); 

		p->die += 0.01f;
		p->color = 111;		// yellow
		p->type = pt_explode;

		p->org[0] = ent->origin[0] + cl_avertexnormals[i][0] * 64.0f + forward[0] * 16.0f;
		p->org[1] = ent->origin[1] + cl_avertexnormals[i][1] * 64.0f + forward[1] * 16.0f;		
		p->org[2] = ent->origin[2] + cl_avertexnormals[i][2] * 64.0f + forward[2] * 16.0f;
	}
}
Esempio n. 7
0
Quat	&Quat::operator= (const Vec3f &RV)
{
	Float	_w=RV.GetNorm();
	if (_w<Float_Eps)
	{
		xyzw().SetDefault();
		return *this;
	}

	Vec2f	Toto;
	SinCos(Toto,_w*0.5f);
	xyz()=RV*(Toto.x/_w);
	w=Toto.y;
	return *this;
}
Esempio n. 8
0
TinyMatrix& TinyMatrix::SetRotate(FLOAT degrees)
{
    FLOAT sina = 0;
    FLOAT cosa = 0;
    sina = SinCos(DegreesToRadians(degrees), &cosa);
    FLOAT e11 = cosa*eM11 + sina*eM21;
    FLOAT e12 = cosa*eM12 + sina*eM22;
    FLOAT e21 = -sina*eM11 + cosa*eM21;
    FLOAT e22 = -sina*eM12 + cosa*eM22;
    eM11 = e11;
    eM12 = e12;
    eM21 = e21;
    eM22 = e22;
    return *this;
}
Esempio n. 9
0
inline void AngleVectors(const Angle &angles, Vector &forward, Vector &right, Vector &up)
{
	float sp, sy, sr, cp, cy, cr;

	SinCos(Deg2Rad(angles.x), sp, cp);
	SinCos(Deg2Rad(angles.y), sy, cy);
	SinCos(Deg2Rad(angles.z), sr, cr);


	forward.x = cp * cy;
	forward.y = cp * sy;
	forward.z = -sp;
	forward.Normalize();

	right.x = -(sr * sp * cy) + (cr * sy);
	right.y = -(sr * sp * sy) + -(cr * cy);
	right.z = -(sr * cp);
	right.Normalize();

	up.x = cr * sp * cy + -sr * -sy;
	up.y = cr * sp * sy + -sr * cy;
	up.z = cr * cp;
	up.Normalize();
}
Esempio n. 10
0
void Quat::SetFromAxisAngle(const float3 &axis, float angle)
{
#if defined(MATH_AUTOMATIC_SSE) && defined(MATH_SSE)
	SetFromAxisAngle(load_vec3(axis.ptr(), 0.f), angle);
#else
	assume1(axis.IsNormalized(), axis);
	assume1(MATH_NS::IsFinite(angle), angle);
	float sinz, cosz;
	SinCos(angle*0.5f, sinz, cosz);
	x = axis.x * sinz;
	y = axis.y * sinz;
	z = axis.z * sinz;
	w = cosz;
#endif
}
Esempio n. 11
0
qboolean SV_StepDirection( edict_t *ent, float yaw, float dist )
{
	int	ret;
	float	cSin, cCos;
	vec3_t	move;

	yaw = yaw * M_PI2 / 360.0f;
	SinCos( yaw, &cSin, &cCos );
	VectorSet( move, cCos * dist, cSin * dist, 0.0f );

	ret = SV_MoveStep( ent, move, false );
	SV_LinkEdict( ent, true );

	return ret;
}
Esempio n. 12
0
Quat Quat::operator* ( const Float f) const
{
	Float	w2=w*w;
	if (w2<(1.f-Float_Eps))
	{
		Float	s=Sqrt(1.f-w2);
		Vec2f	Toto;
		ASSERTC_Z((w <= 1.f) && (w >= -1.f),"ACOS will bug with val >1.f");
		SinCos(Toto,ACos(w)*f);
		Quat	r;
		r.v=v*(Toto.x/s);
		r.w=Toto.y;
		return r;
	}
	return *this;
}
Esempio n. 13
0
Bool	Quat::Maximize( Float f)
{
	if (w<-1.f) w=-1.f;
	if (w>1.f) w=1.f;
	Float	s=Sqrt(1.f-w*w);

	if (s>Float_Eps)
	{
		f*=0.5f;
		Vec2f	Toto;
		Float	a=ACos(w);
		if (a<-f) a=-f;
		else if (a>f) a=f;
		else return FALSE;
		SinCos(Toto,a);
		v*=(1.f/s)*Toto.x;
		w=Toto.y;
		return TRUE;
	}
	return FALSE;
}
Esempio n. 14
0
	void RotateMatrix4Y(float angle, Matrix4 &result)
	{
		// Y axis rotation 
		// /--           --\
		// | cosT  0 -sinT |
		// | 0     1    0  |
		// | sinT  0  cosT |
		// \--           --/
		result.Identity();

		// Convert angle to radian
		float theta = ToRadian(angle);
		float sine, cosine;
		SinCos(cosine, sine, theta);

		// X axis rotation
		result.xX = cosine;
		result.xZ = -sine;

		// Z axis rotation
		result.zX = sine;
		result.zZ = cosine;
	}
Esempio n. 15
0
File: SSE.hpp Progetto: Eynx/R3D
    // Projection Matrix ------------------------------------------------------------------
    static Float4x4 VFunction PerspectiveFovLH(Float fov, Float aspect, Float near, Float far)
    {
        // n - rotation axis; a - theta; v - vector being rotated
        // v * cos(a) + (dot(v, n) * n * (1 - cos(a))) + (cross(n, v) * sin(a));

        // NOTE: PROJECTION MATRIX IS HARDCODED FOR Forward-Right-Up
        // THIS MEANS TRANSPOSE OF ZXY, WHICH IS YZX

        Float2 angles = SinCos(0.5f * fov);

        Float fRange = far / (far - near);
        // Note: This is recorded on the stack
        Float Height = angles.y / angles.x;
        Vector rMem = { Height / aspect, Height, fRange, -fRange * near };
        // Copy from memory to SSE register
        Vector vValues = rMem;
        Vector vTemp = _mm_setzero_ps();
        // Copy x only
        vTemp = _mm_move_ss(vTemp, vValues);
        // CosFov / SinFov,0,0,0
        Float4x4 M;
        M.y = vTemp;
        // 0,Height / AspectHByW,0,0
        vTemp = vValues;
        vTemp = _mm_and_ps(vTemp, Constant::MaskY);
        M.z = vTemp;
        // x=fRange,y=-fRange * NearZ,0,1.0f
        vTemp = _mm_setzero_ps();
        vValues = _mm_shuffle_ps(vValues, Constant::IdentityR3, _MM_SHUFFLE(3, 2, 3, 2));
        // 0,0,fRange,1.0f
        vTemp = _mm_shuffle_ps(vTemp, vValues, _MM_SHUFFLE(3, 0, 0, 0));
        M.x = vTemp;
        // 0,0,-fRange * NearZ,0.0f
        vTemp = _mm_shuffle_ps(vTemp, vValues, _MM_SHUFFLE(2, 1, 0, 0));
        M.w = vTemp;
        return M;
    }
Esempio n. 16
0
		Matrix3x3 &Matrix3x3::Rotate( const ZED_FLOAT32 p_Angle,
			const Vector3 &p_Axis )
		{
			ZED_FLOAT32 Cos = 0.0f, Sin = 0.0f;
			SinCos( p_Angle, Sin, Cos );

			ZED_FLOAT32 Tan = 1.0f - Cos;

			Vector3 nAxis;
			nAxis.Copy( p_Axis );

			// Intermediate values
			ZED_FLOAT32 TanX = Tan*nAxis[ 0 ];
			ZED_FLOAT32 TanY = Tan*nAxis[ 1 ];
			ZED_FLOAT32 TanZ = Tan*nAxis[ 2 ];

			ZED_FLOAT32 SinX = Sin*nAxis[ 0 ];
			ZED_FLOAT32 SinY = Sin*nAxis[ 1 ];
			ZED_FLOAT32 SinZ = Sin*nAxis[ 2 ];
			
			ZED_FLOAT32 TanXY = TanX*nAxis[ 1 ];
			ZED_FLOAT32 TanYZ = TanY*nAxis[ 2 ];
			ZED_FLOAT32 TanXZ = TanX*nAxis[ 2 ];

			// Set up the matrix
			m_M[ 0 ] = TanX*nAxis[ 0 ] + Cos;
			m_M[ 3 ] = TanXY - SinZ;
			m_M[ 6 ] = TanXZ + SinY;
			m_M[ 1 ] = TanXY + SinZ;
			m_M[ 4 ] = TanY*nAxis[ 1 ] + Cos;
			m_M[ 7 ] = TanYZ - SinX;
			m_M[ 2 ] = TanXZ - SinY;
			m_M[ 5 ] = TanYZ + SinX;
			m_M[ 8 ] = TanZ*nAxis[ 2 ] + Cos;

			return *this;
		}
Esempio n. 17
0
	void RotateMatrix4X(float angle, Matrix4 &result)
	{
		// X axis rotation 
		// /--           --\
		// | 1    0     0  |
		// | 0  cosT -sinT |
		// | 0  sinT  cosT |
		// \--           --/

		result.Identity();

		// Convert angle to radian
		float theta = ToRadian(angle);
		float sine, cosine;
		SinCos(cosine, sine, theta);

		// Y axis rotation
		result.yY = cosine;
		result.yZ = -sine;

		// Z axis rotation
		result.zY = sine;
		result.zZ = cosine;
	}
Esempio n. 18
0
	void RotateMatrix4Z(float angle, Matrix4 &result)
	{
		// Z axis rotation 
		// /--           --\
		// | cosT sinT  0  |
		// |-sinT cosT  0  |
		// | 0    0     1  |
		// \--           --/

		result.Identity();

		// Convert angle to radian
		float theta = ToRadian(angle);
		float sine, cosine;
		SinCos(cosine, sine, theta);

		// X axis rotation
		result.xX = cosine;
		result.xY = sine;

		// Y axis rotation;
		result.yX = -sine;
		result.yY = cosine;
	}
Esempio n. 19
0
void __thiscall hooked_SetViewAngles(void *t, Angle &angles)
{
	bpaware();

	register UserCmd *ucmd asm("esi");

#ifdef GMOD
	if (ucmd && ucmd->tick_count == 0 && ucmd->predicted)
		return;
#endif

	org_SetViewAngles(t, angles);


	if (ucmd && ucmd->command_number == bp->next->arg<int>(1))
	{
		Entity *lp = LocalPlayer();
		Entity *weapon = lp->GetActiveWeapon();

		float curtime = (float)lp->GetTickCount() * globals->interval();

		if (!lp->IsAlive())
			return;


		// static int speedcmd = 0;

		// if (speedfix[(ucmd->command_number+1) % sizeof(speedfix)] = (GetAsyncKeyState(VK_LSHIFT) && --speedcmd > 0))
		// {
		// 	bp->next->next->next->next->ret -= 5;
		// }
		// else
		// {
		// 	speedcmd = 5;
		// }


		aimbot::RunCommand(ucmd);

		Angle viewang = ucmd->viewangles;
		bool canshoot = weapon && weapon->Clip1() > 0;

#ifdef VORANGEBOX
		bool &sendpacket = *((bool *)bp->next->next->next - 1);
#endif
#ifdef VL4D
		bool &sendpacket = *((bool *)bp->next->next->next - 0x21);
#endif

#ifdef CSGO
		bool &sendpacket = *((bool *)bp->next - 0x1c);
#endif

		if (1 && !lp->HasFlag(FL_ONGROUND)) // menu/bhop
			ucmd->buttons.del(IN_JUMP);

		if (1 && canshoot) // menu.aimbot
		{
			if (aimbot::Think(ucmd) && 0)
			{
			//	org_SetViewAngles(t, ucmd->viewangles);
			}
		}

		if (1) // menu.norecoil
		{
			nospread::ApplyRecoil(lp, ucmd->viewangles, -1.0f);
		}

		if (canshoot && ucmd->buttons.test(IN_ATTACK))
		{
			//if (1) // menu/nospread
			//	nospread::ApplySpread(ucmd->command_number, lp, ucmd->viewangles, -1.0f);

			if (1 && weapon->GetNextPrimaryFire() > curtime) // menu/autopistol
				ucmd->buttons.del(IN_ATTACK);

			if (1)
			{
				if (weapon->GetNextPrimaryFire() > curtime)
				{
					ucmd->viewangles = viewang;
				}
				else
				{
					sendpacket = false;
				}
			}

			if (weapon->GetNextPrimaryFire() <= curtime)
				aimbot::Next();
		}


		Angle move;
		VectorAngles(ucmd->move, move);

		float velocity = ucmd->move.Length2D();
		float sin, cos;
		SinCos(Deg2Rad(ucmd->viewangles.y - viewang.y + move.y), sin, cos);

		if (ucmd->viewangles.x < -90.0f || ucmd->viewangles.x > 90.0f)
		{
			ucmd->move.x = sin * velocity;
			ucmd->move.y = cos * velocity;
		}
		else
		{
			ucmd->move.x = cos * velocity;
			ucmd->move.y = sin * velocity;
		}

		// ucmd->move.RotateInPlace();
	}
}
Esempio n. 20
0
File: SSE.hpp Progetto: Eynx/R3D
 // Things -------------------------------------------------------------------------
 static Quaternion VFunction ToQuaternion(Library::AxisAngle axisAngle)
 {
     Library::Float2 sincos = SinCos(axisAngle.w * 0.5f);
     Float4 scale = Load(Library::Float4(Library::Float3(sincos.x), sincos.y));
     return _mm_mul_ps(Load(axisAngle), scale);
 }
Esempio n. 21
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void C_RotorWashEmitter::ClientThink( void )
{
	SetNextClientThink( gpGlobals->curtime + ROTORWASH_THINK_INTERVAL );

	trace_t	tr;
	UTIL_TraceLine( GetAbsOrigin(), GetAbsOrigin()+(Vector(0, 0, -1024)), (MASK_SOLID_BRUSHONLY|CONTENTS_WATER|CONTENTS_SLIME), NULL, COLLISION_GROUP_NONE, &tr );

	if ( /*!m_bIgnoreSolid && */(tr.fraction == 1.0f || tr.startsolid || tr.allsolid) )
		return;

	// If we hit the skybox, don't do it either
	if ( tr.surface.flags & SURF_SKY )
		return;

	float heightScale = RemapValClamped( tr.fraction * 1024, 512, 1024, 1.0f, 0.0f );

	Vector vecDustColor;

	if ( tr.contents & CONTENTS_WATER )
	{
		vecDustColor.x = 0.8f;
		vecDustColor.y = 0.8f;
		vecDustColor.z = 0.75f;
	}
	else if ( tr.contents & CONTENTS_SLIME )
	{
		vecDustColor.x = 0.6f;
		vecDustColor.y = 0.5f;
		vecDustColor.z = 0.15f;
	}
	else
	{
		vecDustColor.x = 0.35f;
		vecDustColor.y = 0.3f;
		vecDustColor.z = 0.25f;
	}

#ifndef _XBOX

	InitSpawner();

	if ( m_pSimple.IsValid() == false )
		return;

	m_pSimple->SetSortOrigin( GetAbsOrigin() );

	PMaterialHandle	*hMaterial;
	
	// Cache and set our material based on the surface we're over (ie. water)
	if ( tr.contents & (CONTENTS_WATER|CONTENTS_SLIME) )
	{
		if ( m_hWaterMaterial[0] == NULL )
		{
			m_hWaterMaterial[0] = m_pSimple->GetPMaterial("effects/splash1");
			m_hWaterMaterial[1] = m_pSimple->GetPMaterial("effects/splash2");
		}
		hMaterial = m_hWaterMaterial;
	}
	else
	{
		hMaterial = g_Mat_DustPuff;
	}

#endif // !XBOX

	// If we're above water, make ripples
	if ( tr.contents & (CONTENTS_WATER|CONTENTS_SLIME) )
	{
		float flScale = random->RandomFloat( 7.5f, 8.5f );

		Vector	color = Vector( 0.8f, 0.8f, 0.75f );
		Vector startPos = tr.endpos + Vector(0,0,8);
		Vector endPos = tr.endpos + Vector(0,0,-64);

		if ( tr.fraction < 1.0f )
		{
			//Add a ripple quad to the surface
			FX_AddQuad( tr.endpos + ( tr.plane.normal * 0.5f ), 
						tr.plane.normal, 
						64.0f * flScale, 
						128.0f * flScale, 
						0.8f,
						0.75f * heightScale, 
						0.0f,
						0.75f,
						random->RandomFloat( 0, 360 ),
						random->RandomFloat( -2.0f, 2.0f ),
						vecDustColor, 
						0.2f,  
						"effects/splashwake3",
						(FXQUAD_BIAS_SCALE|FXQUAD_BIAS_ALPHA) );
		}
	}

#ifndef _XBOX
	int		numRingSprites = 32;
	float	yaw = random->RandomFloat( 0, 2*M_PI ); // Randomly placed on the unit circle
	float	yawIncr = (2*M_PI) / numRingSprites;
	Vector	vecForward;
	Vector	offset;
	SimpleParticle	*pParticle;

	// Draw the rings
	for ( int i = 0; i < numRingSprites; i++ )
	{
		// Get our x,y on the unit circle
		SinCos( yaw, &vecForward.y, &vecForward.x );
		
		// Increment ahead
		yaw += yawIncr;

		// @NOTE toml (3-28-07): broke out following expression because vc2005 optimizer was screwing up in presence of SinCos inline assembly. Would also
		// go away if offset were referenced below as in the AddLineOverlay()
		//offset = ( RandomVector( -4.0f, 4.0f ) + tr.endpos ) + ( vecForward * 128.0f );

		offset = vecForward * 128.0f;
		offset += tr.endpos + RandomVector( -4.0f, 4.0f );


		pParticle = (SimpleParticle *) m_pSimple->AddParticle( sizeof(SimpleParticle), hMaterial[random->RandomInt(0,1)], offset );

		if ( pParticle != NULL )
		{
			pParticle->m_flLifetime = 0.0f;
			pParticle->m_flDieTime	= random->RandomFloat( 0.25f, 1.0f );

			pParticle->m_vecVelocity = vecForward * random->RandomFloat( 1000, 1500 );
		
			#if __EXPLOSION_DEBUG
			debugoverlay->AddLineOverlay( m_vecOrigin, m_vecOrigin + pParticle->m_vecVelocity, 255, 0, 0, false, 3 );
			#endif

			if ( tr.contents & CONTENTS_SLIME )
			{
				vecDustColor.x = random->RandomFloat( 0.4f, 0.6f );
				vecDustColor.y = random->RandomFloat( 0.3f, 0.5f );
				vecDustColor.z = random->RandomFloat( 0.1f, 0.2f );
			}

			pParticle->m_uchColor[0] = vecDustColor.x * 255.0f;
			pParticle->m_uchColor[1] = vecDustColor.y * 255.0f;
			pParticle->m_uchColor[2] = vecDustColor.z * 255.0f;

			pParticle->m_uchStartSize	= random->RandomInt( 16, 64 );
			pParticle->m_uchEndSize		= pParticle->m_uchStartSize * 4;

			pParticle->m_uchStartAlpha	= random->RandomFloat( 16, 32 ) * heightScale;
			pParticle->m_uchEndAlpha	= 0;
			
			pParticle->m_flRoll			= random->RandomInt( 0, 360 );
			pParticle->m_flRollDelta	= random->RandomFloat( -16.0f, 16.0f );
		}
	}
#endif // !XBOX
}
Esempio n. 22
0
//-----------------------------------------------------------------------------
// Purpose: 
//-----------------------------------------------------------------------------
void C_BaseExplosionEffect::CreateCore( void )
{
	if ( m_fFlags & TE_EXPLFLAG_NOFIREBALL )
		return;

	Vector	offset;
	int		i;

	//Spread constricts as force rises
	float force = m_flForce;

	//Cap our force
	if ( force < EXPLOSION_FORCE_MIN )
		force = EXPLOSION_FORCE_MIN;
	
	if ( force > EXPLOSION_FORCE_MAX )
		force = EXPLOSION_FORCE_MAX;

	float spread = 1.0f - (0.15f*force);

	SimpleParticle	*pParticle;

	CSmartPtr<CExplosionParticle> pSimple = CExplosionParticle::Create( "exp_smoke" );
	pSimple->SetSortOrigin( m_vecOrigin );
	pSimple->SetNearClip( 64, 128 );

	pSimple->GetBinding().SetBBox( m_vecOrigin - Vector( 128, 128, 128 ), m_vecOrigin + Vector( 128, 128, 128 ) );
	
	if ( m_Material_Smoke == NULL )
	{
		m_Material_Smoke = g_Mat_DustPuff[1];
	}

	//FIXME: Better sampling area
	offset = m_vecOrigin + ( m_vecDirection * 32.0f );

	//Find area ambient light color and use it to tint smoke
	Vector worldLight = WorldGetLightForPoint( offset, true );
	
	Vector	tint;
	float	luminosity;
	if ( worldLight == vec3_origin )
	{
		tint = vec3_origin;
		luminosity = 0.0f;
	}
	else
	{
		UTIL_GetNormalizedColorTintAndLuminosity( worldLight, &tint, &luminosity );
	}

	// We only take a portion of the tint
	tint = (tint * 0.25f)+(Vector(0.75f,0.75f,0.75f));
	
	// Rescale to a character range
	luminosity *= 255;

	if ( (m_fFlags & TE_EXPLFLAG_NOFIREBALLSMOKE) == 0 )
	{
		//
		// Smoke - basic internal filler
		//

		for ( i = 0; i < 4; i++ )
		{
			pParticle = (SimpleParticle *) pSimple->AddParticle( sizeof( SimpleParticle ), m_Material_Smoke, m_vecOrigin );

			if ( pParticle != NULL )
			{
				pParticle->m_flLifetime = 0.0f;

	#ifdef INVASION_CLIENT_DLL
				pParticle->m_flDieTime	= random->RandomFloat( 0.5f, 1.0f );
	#endif
	#ifdef _XBOX
				pParticle->m_flDieTime	= 1.0f;
	#else
				pParticle->m_flDieTime	= random->RandomFloat( 2.0f, 3.0f );
	#endif

				pParticle->m_vecVelocity.Random( -spread, spread );
				pParticle->m_vecVelocity += ( m_vecDirection * random->RandomFloat( 1.0f, 6.0f ) );
				
				VectorNormalize( pParticle->m_vecVelocity );

				float	fForce = random->RandomFloat( 1, 750 ) * force;

				//Scale the force down as we fall away from our main direction
				ScaleForceByDeviation( pParticle->m_vecVelocity, m_vecDirection, spread, &fForce );

				pParticle->m_vecVelocity *= fForce;
				
				#if __EXPLOSION_DEBUG
				debugoverlay->AddLineOverlay( m_vecOrigin, m_vecOrigin + pParticle->m_vecVelocity, 255, 0, 0, false, 3 );
				#endif

				int nColor = random->RandomInt( luminosity*0.5f, luminosity );
				pParticle->m_uchColor[0] = ( worldLight[0] * nColor );
				pParticle->m_uchColor[1] = ( worldLight[1] * nColor );
				pParticle->m_uchColor[2] = ( worldLight[2] * nColor );
				
				pParticle->m_uchStartSize	= 72;
				pParticle->m_uchEndSize		= pParticle->m_uchStartSize * 2;
				
				pParticle->m_uchStartAlpha	= 255;
				pParticle->m_uchEndAlpha	= 0;
				
				pParticle->m_flRoll			= random->RandomInt( 0, 360 );
				pParticle->m_flRollDelta	= random->RandomFloat( -2.0f, 2.0f );
			}
		}


		//
		// Inner core
		//

#ifndef _XBOX

		for ( i = 0; i < 8; i++ )
		{
			offset.Random( -16.0f, 16.0f );
			offset += m_vecOrigin;

			pParticle = (SimpleParticle *) pSimple->AddParticle( sizeof( SimpleParticle ), m_Material_Smoke, offset );

			if ( pParticle != NULL )
			{
				pParticle->m_flLifetime = 0.0f;

	#ifdef INVASION_CLIENT_DLL
				pParticle->m_flDieTime	= random->RandomFloat( 0.5f, 1.0f );
	#else
				pParticle->m_flDieTime	= random->RandomFloat( 0.5f, 1.0f );
	#endif

				pParticle->m_vecVelocity.Random( -spread, spread );
				pParticle->m_vecVelocity += ( m_vecDirection * random->RandomFloat( 1.0f, 6.0f ) );
				
				VectorNormalize( pParticle->m_vecVelocity );

				float	fForce = random->RandomFloat( 1, 2000 ) * force;

				//Scale the force down as we fall away from our main direction
				ScaleForceByDeviation( pParticle->m_vecVelocity, m_vecDirection, spread, &fForce );

				pParticle->m_vecVelocity *= fForce;
				
				#if __EXPLOSION_DEBUG
				debugoverlay->AddLineOverlay( m_vecOrigin, m_vecOrigin + pParticle->m_vecVelocity, 255, 0, 0, false, 3 );
				#endif

				int nColor = random->RandomInt( luminosity*0.5f, luminosity );
				pParticle->m_uchColor[0] = ( worldLight[0] * nColor );
				pParticle->m_uchColor[1] = ( worldLight[1] * nColor );
				pParticle->m_uchColor[2] = ( worldLight[2] * nColor );
						
				pParticle->m_uchStartSize	= random->RandomInt( 32, 64 );
				pParticle->m_uchEndSize		= pParticle->m_uchStartSize * 2;

				pParticle->m_uchStartAlpha	= random->RandomFloat( 128, 255 );
				pParticle->m_uchEndAlpha	= 0;
				
				pParticle->m_flRoll			= random->RandomInt( 0, 360 );
				pParticle->m_flRollDelta	= random->RandomFloat( -8.0f, 8.0f );
			}
		}
#endif // !_XBOX

		//
		// Ground ring
		//

		Vector	vRight, vUp;
		VectorVectors( m_vecDirection, vRight, vUp );

		Vector	forward;

#ifndef INVASION_CLIENT_DLL

#ifndef _XBOX 
		int	numRingSprites = 32;
#else
		int	numRingSprites = 8;
#endif

		float flIncr = (2*M_PI) / (float) numRingSprites; // Radians
		float flYaw = 0.0f;

		for ( i = 0; i < numRingSprites; i++ )
		{
			flYaw += flIncr;
			SinCos( flYaw, &forward.y, &forward.x );
			forward.z = 0.0f;

			offset = ( RandomVector( -4.0f, 4.0f ) + m_vecOrigin ) + ( forward * random->RandomFloat( 8.0f, 16.0f ) );

			pParticle = (SimpleParticle *) pSimple->AddParticle( sizeof( SimpleParticle ), m_Material_Smoke, offset );

			if ( pParticle != NULL )
			{
				pParticle->m_flLifetime = 0.0f;
				pParticle->m_flDieTime	= random->RandomFloat( 0.5f, 1.5f );

				pParticle->m_vecVelocity = forward;
			
				float	fForce = random->RandomFloat( 500, 2000 ) * force;

				//Scale the force down as we fall away from our main direction
				ScaleForceByDeviation( pParticle->m_vecVelocity, pParticle->m_vecVelocity, spread, &fForce );

				pParticle->m_vecVelocity *= fForce;
				
				#if __EXPLOSION_DEBUG
				debugoverlay->AddLineOverlay( m_vecOrigin, m_vecOrigin + pParticle->m_vecVelocity, 255, 0, 0, false, 3 );
				#endif

				int nColor = random->RandomInt( luminosity*0.5f, luminosity );
				pParticle->m_uchColor[0] = ( worldLight[0] * nColor );
				pParticle->m_uchColor[1] = ( worldLight[1] * nColor );
				pParticle->m_uchColor[2] = ( worldLight[2] * nColor );

				pParticle->m_uchStartSize	= random->RandomInt( 16, 32 );
				pParticle->m_uchEndSize		= pParticle->m_uchStartSize * 4;

				pParticle->m_uchStartAlpha	= random->RandomFloat( 16, 32 );
				pParticle->m_uchEndAlpha	= 0;
				
				pParticle->m_flRoll			= random->RandomInt( 0, 360 );
				pParticle->m_flRollDelta	= random->RandomFloat( -8.0f, 8.0f );
			}
		}
#endif
	}

#ifndef _XBOX

	//
	// Embers
	//

	if ( m_Material_Embers[0] == NULL )
	{
		m_Material_Embers[0] = pSimple->GetPMaterial( "effects/fire_embers1" );
	}

	if ( m_Material_Embers[1] == NULL )
	{
		m_Material_Embers[1] = pSimple->GetPMaterial( "effects/fire_embers2" );
	}

	for ( i = 0; i < 16; i++ )
	{
		offset.Random( -32.0f, 32.0f );
		offset += m_vecOrigin;

		pParticle = (SimpleParticle *) pSimple->AddParticle( sizeof( SimpleParticle ), m_Material_Embers[random->RandomInt(0,1)], offset );

		if ( pParticle != NULL )
		{
			pParticle->m_flLifetime = 0.0f;
			pParticle->m_flDieTime	= random->RandomFloat( 2.0f, 3.0f );

			pParticle->m_vecVelocity.Random( -spread*2, spread*2 );
			pParticle->m_vecVelocity += m_vecDirection;
			
			VectorNormalize( pParticle->m_vecVelocity );

			float	fForce = random->RandomFloat( 1.0f, 400.0f );

			//Scale the force down as we fall away from our main direction
			float	vDev = ScaleForceByDeviation( pParticle->m_vecVelocity, m_vecDirection, spread );

			pParticle->m_vecVelocity *= fForce * ( 16.0f * (vDev*vDev*0.5f) );
			
			#if __EXPLOSION_DEBUG
			debugoverlay->AddLineOverlay( m_vecOrigin, m_vecOrigin + pParticle->m_vecVelocity, 255, 0, 0, false, 3 );
			#endif

			int nColor = random->RandomInt( 192, 255 );
			pParticle->m_uchColor[0]	= pParticle->m_uchColor[1] = pParticle->m_uchColor[2] = nColor;
			
			pParticle->m_uchStartSize	= random->RandomInt( 8, 16 ) * vDev;

			pParticle->m_uchStartSize	= clamp( pParticle->m_uchStartSize, 4, 32 );

			pParticle->m_uchEndSize		= pParticle->m_uchStartSize;
			
			pParticle->m_uchStartAlpha	= 255;
			pParticle->m_uchEndAlpha	= 0;
			
			pParticle->m_flRoll			= random->RandomInt( 0, 360 );
			pParticle->m_flRollDelta	= random->RandomFloat( -8.0f, 8.0f );
		}
	}
#endif // !_XBOX

	//
	// Fireballs
	//

	if ( m_Material_FireCloud == NULL )
	{
		m_Material_FireCloud = pSimple->GetPMaterial( "effects/fire_cloud2" );
	}

#ifndef _XBOX
	int numFireballs = 32;
#else
	int numFireballs = 16;
#endif

	for ( i = 0; i < numFireballs; i++ )
	{
		offset.Random( -48.0f, 48.0f );
		offset += m_vecOrigin;

		pParticle = (SimpleParticle *) pSimple->AddParticle( sizeof( SimpleParticle ), m_Material_FireCloud, offset );

		if ( pParticle != NULL )
		{
			pParticle->m_flLifetime = 0.0f;
			pParticle->m_flDieTime	= random->RandomFloat( 0.2f, 0.4f );

			pParticle->m_vecVelocity.Random( -spread*0.75f, spread*0.75f );
			pParticle->m_vecVelocity += m_vecDirection;
			
			VectorNormalize( pParticle->m_vecVelocity );

			float	fForce = random->RandomFloat( 400.0f, 800.0f );

			//Scale the force down as we fall away from our main direction
			float	vDev = ScaleForceByDeviation( pParticle->m_vecVelocity, m_vecDirection, spread );

			pParticle->m_vecVelocity *= fForce * ( 16.0f * (vDev*vDev*0.5f) );

			#if __EXPLOSION_DEBUG
			debugoverlay->AddLineOverlay( m_vecOrigin, m_vecOrigin + pParticle->m_vecVelocity, 255, 0, 0, false, 3 );
			#endif

			int nColor = random->RandomInt( 128, 255 );
			pParticle->m_uchColor[0]	= pParticle->m_uchColor[1] = pParticle->m_uchColor[2] = nColor;
			
			pParticle->m_uchStartSize	= random->RandomInt( 32, 85 ) * vDev;

			pParticle->m_uchStartSize	= clamp( pParticle->m_uchStartSize, 32, 85 );

			pParticle->m_uchEndSize		= (int)((float)pParticle->m_uchStartSize * 1.5f);
			
			pParticle->m_uchStartAlpha	= 255;
			pParticle->m_uchEndAlpha	= 0;
			
			pParticle->m_flRoll			= random->RandomInt( 0, 360 );
			pParticle->m_flRollDelta	= random->RandomFloat( -16.0f, 16.0f );
		}
	}
}
Esempio n. 23
0
void BillboardSet::UpdateVertexBuffer(const FrameInfo& frame)
{
    // If using animation LOD, accumulate time and see if it is time to update
    if (animationLodBias_ > 0.0f && lodDistance_ > 0.0f)
    {
        animationLodTimer_ += animationLodBias_ * frame.timeStep_ * ANIMATION_LOD_BASESCALE;
        if (animationLodTimer_ >= lodDistance_)
            animationLodTimer_ = fmodf(animationLodTimer_, lodDistance_);
        else
        {
            // No LOD if immediate update forced
            if (!forceUpdate_)
                return;
        }
    }

    unsigned numBillboards = billboards_.Size();
    unsigned enabledBillboards = 0;
    const Matrix3x4& worldTransform = node_->GetWorldTransform();
    Matrix3x4 billboardTransform = relative_ ? worldTransform : Matrix3x4::IDENTITY;
    Vector3 billboardScale = scaled_ ? worldTransform.Scale() : Vector3::ONE;

    // First check number of enabled billboards
    for (unsigned i = 0; i < numBillboards; ++i)
    {
        if (billboards_[i].enabled_)
            ++enabledBillboards;
    }

    sortedBillboards_.Resize(enabledBillboards);
    unsigned index = 0;

    // Then set initial sort order and distances
    for (unsigned i = 0; i < numBillboards; ++i)
    {
        Billboard& billboard = billboards_[i];
        if (billboard.enabled_)
        {
            sortedBillboards_[index++] = &billboard;
            if (sorted_)
                billboard.sortDistance_ = frame.camera_->GetDistanceSquared(billboardTransform * billboards_[i].position_);
        }
    }

    batches_[0].geometry_->SetDrawRange(TRIANGLE_LIST, 0, enabledBillboards * 6, false);

    bufferDirty_ = false;
    forceUpdate_ = false;
    if (!enabledBillboards)
        return;

    if (sorted_)
    {
        Sort(sortedBillboards_.Begin(), sortedBillboards_.End(), CompareBillboards);
        Vector3 worldPos = node_->GetWorldPosition();
        // Store the "last sorted position" now
        previousOffset_ = (worldPos - frame.camera_->GetNode()->GetWorldPosition());
    }

    float* dest = (float*)vertexBuffer_->Lock(0, enabledBillboards * 4, true);
    if (!dest)
        return;

    if (faceCameraMode_ != FC_DIRECTION)
    {
        for (unsigned i = 0; i < enabledBillboards; ++i)
        {
            Billboard& billboard = *sortedBillboards_[i];

            Vector2 size(billboard.size_.x_ * billboardScale.x_, billboard.size_.y_ * billboardScale.y_);
            unsigned color = billboard.color_.ToUInt();
            if (fixedScreenSize_)
                size *= billboard.screenScaleFactor_;

            float rotationMatrix[2][2];
            SinCos(billboard.rotation_, rotationMatrix[0][1], rotationMatrix[0][0]);
            rotationMatrix[1][0] = -rotationMatrix[0][1];
            rotationMatrix[1][1] = rotationMatrix[0][0];

            dest[0] = billboard.position_.x_;
            dest[1] = billboard.position_.y_;
            dest[2] = billboard.position_.z_;
            ((unsigned&)dest[3]) = color;
            dest[4] = billboard.uv_.min_.x_;
            dest[5] = billboard.uv_.min_.y_;
            dest[6] = -size.x_ * rotationMatrix[0][0] + size.y_ * rotationMatrix[0][1];
            dest[7] = -size.x_ * rotationMatrix[1][0] + size.y_ * rotationMatrix[1][1];

            dest[8] = billboard.position_.x_;
            dest[9] = billboard.position_.y_;
            dest[10] = billboard.position_.z_;
            ((unsigned&)dest[11]) = color;
            dest[12] = billboard.uv_.max_.x_;
            dest[13] = billboard.uv_.min_.y_;
            dest[14] = size.x_ * rotationMatrix[0][0] + size.y_ * rotationMatrix[0][1];
            dest[15] = size.x_ * rotationMatrix[1][0] + size.y_ * rotationMatrix[1][1];

            dest[16] = billboard.position_.x_;
            dest[17] = billboard.position_.y_;
            dest[18] = billboard.position_.z_;
            ((unsigned&)dest[19]) = color;
            dest[20] = billboard.uv_.max_.x_;
            dest[21] = billboard.uv_.max_.y_;
            dest[22] = size.x_ * rotationMatrix[0][0] - size.y_ * rotationMatrix[0][1];
            dest[23] = size.x_ * rotationMatrix[1][0] - size.y_ * rotationMatrix[1][1];

            dest[24] = billboard.position_.x_;
            dest[25] = billboard.position_.y_;
            dest[26] = billboard.position_.z_;
            ((unsigned&)dest[27]) = color;
            dest[28] = billboard.uv_.min_.x_;
            dest[29] = billboard.uv_.max_.y_;
            dest[30] = -size.x_ * rotationMatrix[0][0] - size.y_ * rotationMatrix[0][1];
            dest[31] = -size.x_ * rotationMatrix[1][0] - size.y_ * rotationMatrix[1][1];

            dest += 32;
        }
    }
    else
    {
        for (unsigned i = 0; i < enabledBillboards; ++i)
        {
            Billboard& billboard = *sortedBillboards_[i];

            Vector2 size(billboard.size_.x_ * billboardScale.x_, billboard.size_.y_ * billboardScale.y_);
            unsigned color = billboard.color_.ToUInt();
            if (fixedScreenSize_)
                size *= billboard.screenScaleFactor_;

            float rot2D[2][2];
            SinCos(billboard.rotation_, rot2D[0][1], rot2D[0][0]);
            rot2D[1][0] = -rot2D[0][1];
            rot2D[1][1] = rot2D[0][0];

            dest[0] = billboard.position_.x_;
            dest[1] = billboard.position_.y_;
            dest[2] = billboard.position_.z_;
            dest[3] = billboard.direction_.x_;
            dest[4] = billboard.direction_.y_;
            dest[5] = billboard.direction_.z_;
            ((unsigned&)dest[6]) = color;
            dest[7] = billboard.uv_.min_.x_;
            dest[8] = billboard.uv_.min_.y_;
            dest[9] = -size.x_ * rot2D[0][0] + size.y_ * rot2D[0][1];
            dest[10] = -size.x_ * rot2D[1][0] + size.y_ * rot2D[1][1];

            dest[11] = billboard.position_.x_;
            dest[12] = billboard.position_.y_;
            dest[13] = billboard.position_.z_;
            dest[14] = billboard.direction_.x_;
            dest[15] = billboard.direction_.y_;
            dest[16] = billboard.direction_.z_;
            ((unsigned&)dest[17]) = color;
            dest[18] = billboard.uv_.max_.x_;
            dest[19] = billboard.uv_.min_.y_;
            dest[20] = size.x_ * rot2D[0][0] + size.y_ * rot2D[0][1];
            dest[21] = size.x_ * rot2D[1][0] + size.y_ * rot2D[1][1];

            dest[22] = billboard.position_.x_;
            dest[23] = billboard.position_.y_;
            dest[24] = billboard.position_.z_;
            dest[25] = billboard.direction_.x_;
            dest[26] = billboard.direction_.y_;
            dest[27] = billboard.direction_.z_;
            ((unsigned&)dest[28]) = color;
            dest[29] = billboard.uv_.max_.x_;
            dest[30] = billboard.uv_.max_.y_;
            dest[31] = size.x_ * rot2D[0][0] - size.y_ * rot2D[0][1];
            dest[32] = size.x_ * rot2D[1][0] - size.y_ * rot2D[1][1];

            dest[33] = billboard.position_.x_;
            dest[34] = billboard.position_.y_;
            dest[35] = billboard.position_.z_;
            dest[36] = billboard.direction_.x_;
            dest[37] = billboard.direction_.y_;
            dest[38] = billboard.direction_.z_;
            ((unsigned&)dest[39]) = color;
            dest[40] = billboard.uv_.min_.x_;
            dest[41] = billboard.uv_.max_.y_;
            dest[42] = -size.x_ * rot2D[0][0] - size.y_ * rot2D[0][1];
            dest[43] = -size.x_ * rot2D[1][0] - size.y_ * rot2D[1][1];

            dest += 44;
        }
    }

    vertexBuffer_->Unlock();
    vertexBuffer_->ClearDataLost();
}
Esempio n. 24
0
void CC_CollisionTest( const CCommand &args )
{
	if ( !physenv )
		return;

	Msg( "Testing collision system\n" );
	int i;
	CBaseEntity *pSpot = gEntList.FindEntityByClassname( NULL, "info_player_start");
	Vector start = pSpot->GetAbsOrigin();
	static Vector *targets = NULL;
	static bool first = true;
	static float test[2] = {1,1};
	if ( first )
	{
		targets = new Vector[NUM_COLLISION_TESTS];
		float radius = 0;
		float theta = 0;
		float phi = 0;
		for ( i = 0; i < NUM_COLLISION_TESTS; i++ )
		{
			radius += NUM_COLLISION_TESTS * 123.123;
			radius = fabs(fmod(radius, 128));
			theta += NUM_COLLISION_TESTS * 76.76;
			theta = fabs(fmod(theta, DEG2RAD(360)));
			phi += NUM_COLLISION_TESTS * 1997.99;
			phi = fabs(fmod(phi, DEG2RAD(180)));
			
			float st, ct, sp, cp;
			SinCos( theta, &st, &ct );
			SinCos( phi, &sp, &cp );

			targets[i].x = radius * ct * sp;
			targets[i].y = radius * st * sp;
			targets[i].z = radius * cp;
			
			// make the trace 1024 units long
			Vector dir = targets[i] - start;
			VectorNormalize(dir);
			targets[i] = start + dir * 1024;
		}
		first = false;
	}

	//Vector results[NUM_COLLISION_TESTS];

	int testType = 0;
	if ( args.ArgC() >= 2 )
	{
		testType = atoi( args[1] );
	}
	float duration = 0;
	Vector size[2];
	size[0].Init(0,0,0);
	size[1].Init(16,16,16);
	unsigned int dots = 0;

	for ( int j = 0; j < 2; j++ )
	{
		float startTime = engine->Time();
		if ( testType == 1 )
		{
			const CPhysCollide *pCollide = g_PhysWorldObject->GetCollide();
			trace_t tr;

			for ( i = 0; i < NUM_COLLISION_TESTS; i++ )
			{
				physcollision->TraceBox( start, targets[i], -size[j], size[j], pCollide, vec3_origin, vec3_angle, &tr );
				dots += physcollision->ReadStat(0);
				//results[i] = tr.endpos;
			}
		}
		else
		{
			testType = 0;
			CBaseEntity *pWorld = GetContainingEntity( INDEXENT(0) );
			trace_t tr;

			for ( i = 0; i < NUM_COLLISION_TESTS; i++ )
			{
				UTIL_TraceModel( start, targets[i], -size[j], size[j], pWorld, COLLISION_GROUP_NONE, &tr );
				//results[i] = tr.endpos;
			}
		}

		duration += engine->Time() - startTime;
	}
	test[testType] = duration;
	Msg("%d collisions in %.2f ms (%u dots)\n", NUM_COLLISION_TESTS, duration*1000, dots );
	Msg("Current speed ratio: %.2fX BSP:JGJK\n", test[1] / test[0] );
#if 0
	int red = 255, green = 0, blue = 0;
	for ( i = 0; i < NUM_COLLISION_TESTS; i++ )
	{
		NDebugOverlay::Line( start, results[i], red, green, blue, false, 2 );
	}
#endif
}
Esempio n. 25
0
void FX_ThumperDust( const CEffectData &data )
{
	Vector vecDustColor;
	vecDustColor.x = 0.85f;
	vecDustColor.y = 0.75f;
	vecDustColor.z = 0.52f;

	CSmartPtr<ThumperDustEmitter> pSimple = ThumperDustEmitter::Create( "thumperdust" );

	C_BaseEntity *pEnt = C_BaseEntity::Instance( data.m_hEntity );
	if ( pEnt )
	{
		Vector vWorldMins, vWorldMaxs;
		float scale = pEnt->CollisionProp()->BoundingRadius();
		vWorldMins[0] = data.m_vOrigin[0] - scale;
		vWorldMins[1] = data.m_vOrigin[1] - scale;
		vWorldMins[2] = data.m_vOrigin[2] - scale;
		vWorldMaxs[0] = data.m_vOrigin[0] + scale;
		vWorldMaxs[1] = data.m_vOrigin[1] + scale;
		vWorldMaxs[2] = data.m_vOrigin[2] + scale;
		pSimple->GetBinding().SetBBox( vWorldMins, vWorldMaxs, true );
	}

	pSimple->SetSortOrigin( data.m_vOrigin );
	pSimple->SetNearClip( 32, 64 );

	SimpleParticle	*pParticle = NULL;

	Vector	offset;

	//int	numPuffs = IsXbox() ? THUMPER_MAX_PARTICLES/2 : THUMPER_MAX_PARTICLES;
	int	numPuffs = THUMPER_MAX_PARTICLES;

	float flYaw = 0;
	float flIncr = (2*M_PI) / (float) numPuffs; // Radians
	Vector forward;
	Vector vecColor;
	int i = 0;

	float flScale = min( data.m_flScale, 255 );

	// Setup the color for these particles
	engine->ComputeLighting( data.m_vOrigin, NULL, true, vecColor );
	VectorLerp( vecColor, vecDustColor, 0.5, vecColor );
	vecColor *= 255;

	for ( i = 0; i < numPuffs; i++ )
	{
		flYaw += flIncr;
		SinCos( flYaw, &forward.y, &forward.x );	
		forward.z = 0.0f;

		offset = ( RandomVector( -4.0f, 4.0f ) + data.m_vOrigin ) + ( forward * 128.0f );

		pParticle = (SimpleParticle *) pSimple->AddParticle( sizeof(SimpleParticle), g_Mat_DustPuff[random->RandomInt(0,1)], offset );
		if ( pParticle != NULL )
		{	
			pParticle->m_flLifetime		= 0.0f;
			pParticle->m_flDieTime		= 1.5f;
	
			Vector dir = (offset - data.m_vOrigin);
			float length = dir.Length();
			VectorNormalize( dir );

			pParticle->m_vecVelocity	= dir * ( length * 2.0f );
			pParticle->m_vecVelocity[2]	= data.m_flScale / 3;

			pParticle->m_uchColor[0]	= vecColor[0];
			pParticle->m_uchColor[1]	= vecColor[1];
			pParticle->m_uchColor[2]	= vecColor[2];

			pParticle->m_uchStartAlpha	= random->RandomInt( 64, 96 );
			pParticle->m_uchEndAlpha	= 0;

			pParticle->m_uchStartSize	= flScale * 0.25f;
			pParticle->m_uchEndSize		= flScale * 0.5f;

			pParticle->m_flRoll			= random->RandomInt( 0, 360 );
			pParticle->m_flRollDelta	= random->RandomFloat( -6.0f, 6.0f );
		}
	}
}
Esempio n. 26
0
bool Sphere::Intersect( Ray const &ray, float *tHit, float *epsilon, DifferentialGeometry *geom ) const {
    Transform tf = Tform();
    Ray r = ray * Inverse( tf );

    float t;
    if( !Intersect( ray, &t ) )
        return false;

    // compute differential geometry
    Vec4 p = ray.Point( t );

    float x = p.X();
    float y = p.Y();
    float z = p.Z();

    if( x == 0.0f && z == 0.0f ) {
        // can't have both atan2 arguments be zero
        z = kEpsilon * m_radius;
    }
    float theta = atan2( p.X(), p.Z() );

    if( theta < 0.0f ) {
        // remap theta to [0, 2pi] to match sphere's definition
        theta += k2Pi;
    }

    float phi = Acos( Clamp( z / m_radius, -1.0f, 1.0f ) );

    // parameterize sphere hit
    float u = theta * kInv2Pi;
    float v = phi * kInvPi;

    float sTheta, cTheta;
    float sPhi, cPhi;
    SinCos( theta, &sTheta, &cTheta );
    SinCos( phi, &sPhi, &cPhi );

    Vec4 dpdu( k2Pi * z, 0.0f, -k2Pi * x, 0.0f );
    Vec4 dpdv( kPi * y * sTheta, -kPi * m_radius * sPhi, kPi * y * cTheta, 0.0f );
    Vec4 d2pdu2( -k2Pi * k2Pi * x, 0.0f, -k2Pi * k2Pi * z, 0.0f );
    Vec4 d2pduv( k2Pi * kPi * y * cTheta, 0.0f, -k2Pi * kPi * y * sTheta, 0.0f );
    Vec4 d2pdv2( -kPi * kPi * x, -kPi * kPi * y, -kPi * kPi * z, 0.0f );

    // change in normal is computed using Weingarten equations
    Scalar E = Dot( dpdu, dpdu );
    Scalar F = Dot( dpdu, dpdv );
    Scalar G = Dot( dpdv, dpdv );
    Vec4 N = Normalize( Cross(  dpdu, dpdv ) );
    Scalar e = Dot( N, d2pdu2 );
    Scalar f = Dot( N, d2pduv );
    Scalar g = Dot( N, d2pdv2 );

    Scalar h = 1.0f / ( E * G - F * F );
    Vec4 dndu = ( f * F - e * G ) * h * dpdu + ( e * F - f * E ) * h * dpdv;
    Vec4 dndv = ( g * F - f * G ) * h * dpdu + ( f * F - g * E ) * h * dpdv;

    *tHit = t;
    *epsilon = 5e-4f * t;

    // return world space differential geometry
    *geom = DifferentialGeometry( Handle(), p * tf, dpdu * tf, dpdv * tf, Normal( dndu ) * tf, Normal( dndv ) * tf, u, v );

    return true;
}
Esempio n. 27
0
//-----------------------------------------------------------------------------
// Purpose: Determine sprite orientation axes
// Input  : type - 
//			forward - 
//			right - 
//			up - 
//-----------------------------------------------------------------------------
void C_SpriteRenderer::GetSpriteAxes( SPRITETYPE type, 
	const Vector& origin,
	const QAngle& angles,
	Vector& forward, 
	Vector& right, 
	Vector& up )
{
	int				i;
	float			dot, angle, sr, cr;
	Vector			tvec;

	// Automatically roll parallel sprites if requested
	if ( angles[2] != 0 && type == SPR_VP_PARALLEL )
	{
		type = SPR_VP_PARALLEL_ORIENTED;
	}

	switch( type )
	{
	case SPR_FACING_UPRIGHT:
		{
			// generate the sprite's axes, with vup straight up in worldspace, and
			// r_spritedesc.vright perpendicular to modelorg.
			// This will not work if the view direction is very close to straight up or
			// down, because the cross product will be between two nearly parallel
			// vectors and starts to approach an undefined state, so we don't draw if
			// the two vectors are less than 1 degree apart
			tvec[0] = -origin[0];
			tvec[1] = -origin[1];
			tvec[2] = -origin[2];
			VectorNormalize (tvec);
			dot = tvec[2];	// same as DotProduct (tvec, r_spritedesc.vup) because
			//  r_spritedesc.vup is 0, 0, 1
			if ((dot > 0.999848f) || (dot < -0.999848f))	// cos(1 degree) = 0.999848
				return;
			up[0] = 0;
			up[1] = 0;
			up[2] = 1;
			right[0] = tvec[1];
			// CrossProduct(r_spritedesc.vup, -modelorg,
			right[1] = -tvec[0];
			//              r_spritedesc.vright)
			right[2] = 0;
			VectorNormalize (right);
			forward[0] = -right[1];
			forward[1] = right[0];
			forward[2] = 0;
			// CrossProduct (r_spritedesc.vright, r_spritedesc.vup,
			//  r_spritedesc.vpn)
		}
		break;

	case SPR_VP_PARALLEL:
		{
			// generate the sprite's axes, completely parallel to the viewplane. There
			// are no problem situations, because the sprite is always in the same
			// position relative to the viewer
			for (i=0 ; i<3 ; i++)
			{
				up[i]		= CurrentViewUp()[i];
				right[i]	= CurrentViewRight()[i];
				forward[i]	= CurrentViewForward()[i];
			}
		}
		break;

	case SPR_VP_PARALLEL_UPRIGHT:
		{
			// generate the sprite's axes, with g_vecVUp straight up in worldspace, and
			// r_spritedesc.vright parallel to the viewplane.
			// This will not work if the view direction is very close to straight up or
			// down, because the cross product will be between two nearly parallel
			// vectors and starts to approach an undefined state, so we don't draw if
			// the two vectors are less than 1 degree apart
			dot = CurrentViewForward()[2];	// same as DotProduct (vpn, r_spritedesc.g_vecVUp) because
			//  r_spritedesc.vup is 0, 0, 1
			if ((dot > 0.999848f) || (dot < -0.999848f))	// cos(1 degree) = 0.999848
				return;
			up[0] = 0;
			up[1] = 0;
			up[2] = 1;
			right[0] = CurrentViewForward()[1];
			// CrossProduct (r_spritedesc.vup, vpn,
			right[1] = -CurrentViewForward()[0];	//  r_spritedesc.vright)
			right[2] = 0;
			VectorNormalize (right);
			forward[0] = -right[1];
			forward[1] = right[0];
			forward[2] = 0;
			// CrossProduct (r_spritedesc.vright, r_spritedesc.vup,
			//  r_spritedesc.vpn)
		}
		break;

	case SPR_ORIENTED:
		{
			// generate the sprite's axes, according to the sprite's world orientation
			AngleVectors( angles, &forward, &right, &up );
		}
		break;
		
	case SPR_VP_PARALLEL_ORIENTED:
		{
			// generate the sprite's axes, parallel to the viewplane, but rotated in
			// that plane around the center according to the sprite entity's roll
			// angle. So vpn stays the same, but vright and vup rotate
			angle = angles[ROLL] * (M_PI*2.0f/360.0f);
			SinCos( angle, &sr, &cr );
			
			for (i=0 ; i<3 ; i++)
			{
				forward[i] = CurrentViewForward()[i];
				right[i] = CurrentViewRight()[i] * cr + CurrentViewUp()[i] * sr;
				up[i] = CurrentViewRight()[i] * -sr + CurrentViewUp()[i] * cr;
			}
		}
		break;

	default:
		Warning( "GetSpriteAxes: Bad sprite type %d\n", type );
		break;
	}
}
Esempio n. 28
0
void __attribute__((interrupt, no_auto_psv)) _ADC1Interrupt(void)
{
        IFS0bits.AD1IF = 0;
        
        // acumulate encoder counts since last interrupt  
        CalcVelIrp();
        
        /** Increment count variable that controls stop */
        iStopLoopCnt++;     
        
        if(!uGF.bit.TStop)
        {
            
            /* check if lock time elapsed */
            if(iStopLoopCnt == BUTTON_STOP_TIME)
            {
                /* set stop command */
                uGF.bit.TStop = 1;
                /** Disable the driver IC on the motor control PCB */
                pinPWMOutputEnable_ = 1;
            }
        }
        /** it was a previous stop, time to recover is considered */
        else 
        {
            /* check the counter for BUTTON_STOP_TIME */
            /* if elapsed, stop may be deaserted */
            if(iStopLoopCnt == BUTTON_STOP_TIME)
            {
                uGF.bit.TStop = 0;
            }
        }
        
        if( eStateControl != CNTRL_STOP )
        {
                // Calculate qIa,qIb
                MeasCompCurr();
                
                // Calculate qId,qIq from qSin,qCos,qIa,qIb
                ClarkePark();
                               
                // Calculate control values
                DoControl();
                
                // Calculate qSin,qCos from qAngle
                SinCos();
                
                // Calculate qValpha, qVbeta from qSin,qCos,qVd,qVq
                InvPark();
                
                // Calculate Vr1,Vr2,Vr3 from qValpha, qVbeta 
                CalcRefVec();
                
                // Calculate and set PWM duty cycles from Vr1,Vr2,Vr3
                CalcSVGen();
                
                /** Increment count variable that controls buttons lock */
                iLockLoopCnt++;
                /* check if lock time elapsed */
                if((uGF.bit.TLock)&&(iLockLoopCnt == BUTTON_LOCK_TIME))
                {
                    /* reset lock for buttons command */
                    uGF.bit.TLock = 0; /* reset lock */
                }
        }
}
void
GlueMapWindow::UpdateProjection()
{
  const PixelRect rc = GetClientRect();

  /* not using MapWindowBlackboard here because these methods are
     called by the main thread */
  const NMEAInfo &basic = CommonInterface::Basic();
  const DerivedInfo &calculated = CommonInterface::Calculated();
  const MapSettings &settings_map = CommonInterface::GetMapSettings();
  const bool circling =
    CommonInterface::GetUIState().display_mode == DisplayMode::CIRCLING;

  const RasterPoint center = rc.GetCenter();

  if (circling || !IsNearSelf())
    visible_projection.SetScreenOrigin(center.x, center.y);
  else if (settings_map.cruise_orientation == DisplayOrientation::NORTH_UP ||
           settings_map.cruise_orientation == DisplayOrientation::WIND_UP) {
    RasterPoint offset{0, 0};
    if (settings_map.glider_screen_position != 50 &&
        settings_map.map_shift_bias != MapShiftBias::NONE) {
      fixed x = fixed(0);
      fixed y = fixed(0);
      if (settings_map.map_shift_bias == MapShiftBias::TRACK) {
        if (basic.track_available &&
            basic.ground_speed_available &&
             /* 8 m/s ~ 30 km/h */
            basic.ground_speed > fixed(8)) {
          auto angle = basic.track.Reciprocal() - visible_projection.GetScreenAngle();

          const auto sc = angle.SinCos();
          x = sc.first;
          y = sc.second;
        }
      } else if (settings_map.map_shift_bias == MapShiftBias::TARGET) {
        if (calculated.task_stats.current_leg.solution_remaining.IsDefined()) {
          auto angle = calculated.task_stats.current_leg.solution_remaining
              .vector.bearing.Reciprocal() - visible_projection.GetScreenAngle();

          const auto sc = angle.SinCos();
          x = sc.first;
          y = sc.second;
        }
      }
      fixed position_factor = fixed(50 - settings_map.glider_screen_position) / 100;
      offset.x = PixelScalar(x * (rc.right - rc.left) * position_factor);
      offset.y = PixelScalar(y * (rc.top - rc.bottom) * position_factor);
      offset_history.Add(offset);
      offset = offset_history.GetAverage();
    }
    visible_projection.SetScreenOrigin(center.x + offset.x, center.y + offset.y);
  } else
    visible_projection.SetScreenOrigin(center.x,
        ((rc.top - rc.bottom) * settings_map.glider_screen_position / 100) + rc.bottom);

  if (!IsNearSelf()) {
    /* no-op - the Projection's location is updated manually */
  } else if (circling && calculated.thermal_locator.estimate_valid) {
    const fixed d_t = calculated.thermal_locator.estimate_location.Distance(basic.location);
    if (!positive(d_t)) {
      SetLocationLazy(basic.location);
    } else {
      const fixed d_max = Double(visible_projection.GetMapScale());
      const fixed t = std::min(d_t, d_max)/d_t;
      SetLocation(basic.location.Interpolate(calculated.thermal_locator.estimate_location,
                                               t));
    }
  } else if (basic.location_available)
    // Pan is off
    SetLocationLazy(basic.location);
  else if (!visible_projection.IsValid() && terrain != nullptr)
    /* if there's no GPS fix yet and no home waypoint, start at the
       map center, to avoid showing a fully white map, which confuses
       users */
    SetLocation(terrain->GetTerrainCenter());

  visible_projection.UpdateScreenBounds();
}
Esempio n. 30
0
void Matrix4x4_CreateFromEntity( matrix4x4 out, const vec3_t angles, const vec3_t origin, float scale )
{
	float	angle, sr, sp, sy, cr, cp, cy;

	if( angles[ROLL] )
	{
		angle = angles[YAW] * (M_PI*2 / 360);
		SinCos( angle, &sy, &cy );
		angle = angles[PITCH] * (M_PI*2 / 360);
		SinCos( angle, &sp, &cp );
		angle = angles[ROLL] * (M_PI*2 / 360);
		SinCos( angle, &sr, &cr );

		out[0][0] = (cp*cy) * scale;
		out[0][1] = (sr*sp*cy+cr*-sy) * scale;
		out[0][2] = (cr*sp*cy+-sr*-sy) * scale;
		out[0][3] = origin[0];
		out[1][0] = (cp*sy) * scale;
		out[1][1] = (sr*sp*sy+cr*cy) * scale;
		out[1][2] = (cr*sp*sy+-sr*cy) * scale;
		out[1][3] = origin[1];
		out[2][0] = (-sp) * scale;
		out[2][1] = (sr*cp) * scale;
		out[2][2] = (cr*cp) * scale;
		out[2][3] = origin[2];
		out[3][0] = 0;
		out[3][1] = 0;
		out[3][2] = 0;
		out[3][3] = 1;
	}
	else if( angles[PITCH] )
	{
		angle = angles[YAW] * (M_PI*2 / 360);
		SinCos( angle, &sy, &cy );
		angle = angles[PITCH] * (M_PI*2 / 360);
		SinCos( angle, &sp, &cp );

		out[0][0] = (cp*cy) * scale;
		out[0][1] = (-sy) * scale;
		out[0][2] = (sp*cy) * scale;
		out[0][3] = origin[0];
		out[1][0] = (cp*sy) * scale;
		out[1][1] = (cy) * scale;
		out[1][2] = (sp*sy) * scale;
		out[1][3] = origin[1];
		out[2][0] = (-sp) * scale;
		out[2][1] = 0;
		out[2][2] = (cp) * scale;
		out[2][3] = origin[2];
		out[3][0] = 0;
		out[3][1] = 0;
		out[3][2] = 0;
		out[3][3] = 1;
	}
	else if( angles[YAW] )
	{
		angle = angles[YAW] * (M_PI*2 / 360);
		SinCos( angle, &sy, &cy );

		out[0][0] = (cy) * scale;
		out[0][1] = (-sy) * scale;
		out[0][2] = 0;
		out[0][3] = origin[0];
		out[1][0] = (sy) * scale;
		out[1][1] = (cy) * scale;
		out[1][2] = 0;
		out[1][3] = origin[1];
		out[2][0] = 0;
		out[2][1] = 0;
		out[2][2] = scale;
		out[2][3] = origin[2];
		out[3][0] = 0;
		out[3][1] = 0;
		out[3][2] = 0;
		out[3][3] = 1;
	}
	else
	{
		out[0][0] = scale;
		out[0][1] = 0;
		out[0][2] = 0;
		out[0][3] = origin[0];
		out[1][0] = 0;
		out[1][1] = scale;
		out[1][2] = 0;
		out[1][3] = origin[1];
		out[2][0] = 0;
		out[2][1] = 0;
		out[2][2] = scale;
		out[2][3] = origin[2];
		out[3][0] = 0;
		out[3][1] = 0;
		out[3][2] = 0;
		out[3][3] = 1;
	}
}