Exemple #1
0
	void EditorPoint::setMinAndMaxShiftPoint(int p_index)
	{
		if (p_index >= 0 && p_index < m_track.getPointCount())
		{
			const TrackPoint& trackPoint = m_track.getPoint(p_index);

			float minShift = -1.0f - trackPoint.getShift();
			float maxShift = 1.0f - trackPoint.getShift();
			float radius = trackPoint.getRadius();

			CL_Vec2f guide = m_gfxLevel.getTrackTriangulator().getGuide(p_index);

			guide /= guide.length();

			CL_Vec2f minShiftGuide = guide;
			setToPerpendicular(minShiftGuide, true);
			minShiftGuide *= radius * minShift;

			CL_Vec2f maxShiftGuide = guide;
			setToPerpendicular(maxShiftGuide, true);
			maxShiftGuide *= radius * maxShift;

			const CL_Pointf& pos = trackPoint.getPosition();

			m_impl->m_minShiftPoint = pos + minShiftGuide;
			m_impl->m_maxShiftPoint = pos + maxShiftGuide;
		}
	}
Exemple #2
0
void Car::applyCollision(const CL_LineSegment2f &p_seg)
{
	static const float DAMAGE_MULT = 0.2f;

	const float side = -p_seg.point_right_of_line(m_impl->m_position);

	const CL_Vec2f segVec = p_seg.q - p_seg.p;

	// need front normal (crash side)
	CL_Vec2f fnormal(segVec.y, -segVec.x); // right side normal
	fnormal.normalize();

	if (side < 0) {
		fnormal *= -1;
	}

	// move away
	m_impl->m_position += (fnormal * fabs(m_impl->m_speed));

	// calculate collision angle to estaminate speed reduction
	CL_Angle angleDiff(m_impl->m_phyMoveRot - m_impl->vecToAngle(fnormal));
	Workarounds::clAngleNormalize180(&angleDiff);

	const float colAngleDeg = fabs(angleDiff.to_degrees()) - 90.0f;
	const float reduction = fabs(1.0f - fabs(colAngleDeg - 90.0f) / 90.0f);

	// calculate and apply damage
	const float damage = m_impl->m_speed * reduction * DAMAGE_MULT;
	m_impl->m_damage =
			Math::Float::reduce(m_impl->m_damage + damage, 0.0f, 1.0f);

	cl_log_event(LOG_DEBUG, "damage: %1, total: %2", damage, m_impl->m_damage);

	// reduce speed
	m_impl->m_speed -= m_impl->m_speed * reduction;

	// bounce movement vector and angle away

	// get mirror point
	if (m_impl->m_phyMoveVec.length() > 0.01f) {
		m_impl->m_phyMoveVec.normalize();

		const float lengthProj = m_impl->m_phyMoveVec.length() * cos(segVec.angle(m_impl->m_phyMoveVec).to_radians());
		const CL_Vec2f mirrorPoint(segVec * (lengthProj / segVec.length()));

		// invert move vector by mirror point
		const CL_Vec2f mirrorVec = (m_impl->m_phyMoveVec - mirrorPoint) * -1;
		m_impl->m_phyMoveVec = mirrorPoint + mirrorVec;

		// update physics angle
		m_impl->m_phyMoveRot = m_impl->vecToAngle(m_impl->m_phyMoveVec);

	}

}
Exemple #3
0
void Misil::mover(float dt)
{
	if(perseguidor)
	{
		int tiempdodesdedisparo= CL_System::get_time() - tiempodisparo;

		if(tiempdodesdedisparo >= 10)
		{	
			CL_Vec2f vector = Posicion - TargetTanque->getPos();
			
			float distancia = vector.length();
			mundo->AgregarCadenaChat(cl_format("%1",distancia));

			CL_Vec2f up(0.0f, 1.0f);
			float angulodest = up.angle(vector).to_degrees();

			/*if(TargetTanque->getPos().x < Posicion.x)
				angulodest = 360.0f - angulo;*/
			/*	else
				angulodest = 360.0f  angulo;*/

			angulodelta = angulodest - angulo;

			if(distancia < 150)
			{
				if(angulodelta > 0)
					angulodelta +=5;
			}
				
			if(angulodelta > 180.0f)	
			{
				angulodelta -= 360.0f;
				angulo += 360.0f;
			}
			if(angulodelta < -180.0f)
			{
				angulodelta += 360.0f;
				angulo -= 360.0f;
			}

			angulo +=angulodelta*dt/velocidad;

			setAngulo(angulo);
		}

	}

	Posicion.x += dt* float(sin(angulo* CL_PI / 180.0f));
	Posicion.y += dt* float(-cos(angulo * CL_PI / 180.0f));
	collisionMisil->set_translation(Posicion.x, Posicion.y);
}
Exemple #4
0
	void EditorPoint::getShiftRect(int p_index, int* x1, int* y1, int* x2, int* y2)
	{
		const TrackPoint& p_trackPoint = m_track.getPoint(p_index);

		CL_Vec2f guide = m_gfxLevel.getTrackTriangulator().getGuide(p_index);

		float guideLength = guide.length();
		guide *= p_trackPoint.getShift() * p_trackPoint.getRadius();
		guide /= guideLength;

		setToPerpendicular(guide, false);

		const CL_Pointf& pos = p_trackPoint.getPosition();

		*x1 = pos.x;
		*y1 = pos.y;
		*x2 = pos.x + guide.x;
		*y2 = pos.y + guide.y;
	}
void  DrawLine( GLuint rgba,   float ax, float ay, float bx, float by, float lineWidth )
{
	SetupOrtho();
	//g_globalBatcher.Flush();

	glDisable( GL_TEXTURE_2D );

	glEnableClientState(GL_VERTEX_ARRAY);	
	glDisableClientState(GL_TEXTURE_COORD_ARRAY);
	glDisable(GL_CULL_FACE);

	static GLfloat	vertices[3*4];

	CL_Vec2f start = CL_Vec2f(ax, ay);
	CL_Vec2f end = CL_Vec2f(bx, by);

	float dx = ax - bx;
	float dy = ay - by;

	CL_Vec2f rightSide = CL_Vec2f(dy, -dx);

	if (rightSide.length() > 0) 
	{
		rightSide.normalize();
		rightSide *= lineWidth/2;
	}
	
	CL_Vec2f  leftSide =CL_Vec2f(-dy, dx);
	
	if (leftSide.length() > 0) 
	{
		leftSide.normalize();
		leftSide *= lineWidth/2;
	}

	CL_Vec2f one = leftSide + start;

	CL_Vec2f two = rightSide + start;

	CL_Vec2f three = rightSide + end;

	CL_Vec2f four = leftSide = end;

	vertices[0*3+0] = one.x; vertices[0*3+1] = one.y;
	vertices[1*3+0] = two.x; vertices[1*3+1] = two.y;
	vertices[2*3+0] = three.x; vertices[2*3+1] = three.y;
	vertices[3*3+0] = four.x; vertices[3*3+1] = four.y;

	//set the Z
	vertices[0*3+2] = 0;
	vertices[1*3+2] = 0;
	vertices[2*3+2] = 0;
	vertices[3*3+2] = 0;
	
	glVertexPointer(3, GL_FLOAT, 0, vertices);
	//glColor4f(1, 1, 1, 1);
	glEnable( GL_BLEND );
	glColor4x( (rgba >>8 & 0xFF)*256,  (rgba>>16& 0xFF)*256, (rgba>>24& 0xFF)*256, (rgba&0xFF)*256);

	glDrawArrays(GL_TRIANGLE_FAN, 0, 4);
	glColor4x(1 << 16, 1 << 16, 1 << 16, 1 << 16);

	glEnable(GL_CULL_FACE);

	glDisable( GL_BLEND );
	glEnable( GL_TEXTURE_2D );
	glEnableClientState(GL_TEXTURE_COORD_ARRAY);	
	CHECK_GL_ERROR();
}