Example #1
0
void AiCarStandard::Visualize()
{
	SceneNode& topnode  = car->GetNode();
	ConfigureDrawable(brakedraw, topnode, 0,1,0);
	ConfigureDrawable(steerdraw, topnode, 0,0,1);
	//ConfigureDrawable(avoidancedraw, topnode, 1,0,0);

	Drawable & brakedrawable = topnode.GetDrawList().normal_noblend.get(brakedraw);
	Drawable & steerdrawable = topnode.GetDrawList().normal_noblend.get(steerdraw);

	brakedrawable.SetVertArray(&brakeshape);
	brakeshape.Clear();
	for (std::vector <Bezier>::iterator i = brakelook.begin(); i != brakelook.end(); ++i)
	{
		Bezier & patch = *i;
		AddLinePoint(brakeshape, patch.GetBL());
		AddLinePoint(brakeshape, patch.GetFL());
		AddLinePoint(brakeshape, patch.GetFR());
		AddLinePoint(brakeshape, patch.GetBR());
		AddLinePoint(brakeshape, patch.GetBL());
	}

	steerdrawable.SetVertArray(&steershape);
	steershape.Clear();
	for (std::vector <Bezier>::iterator i = steerlook.begin(); i != steerlook.end(); ++i)
	{
		Bezier & patch = *i;
		AddLinePoint(steershape, patch.GetBL());
		AddLinePoint(steershape, patch.GetFL());
		AddLinePoint(steershape, patch.GetBR());
		AddLinePoint(steershape, patch.GetFR());
		AddLinePoint(steershape, patch.GetBL());
	}
}
void AI_Car_Experimental::Visualize()
{
	SCENENODE& topnode  = car->GetNode();
	ConfigureDrawable(brakedraw, topnode, 0,1,0);
	ConfigureDrawable(steerdraw, topnode, 0,0,1);
	ConfigureDrawable(raycastdraw, topnode, 1,0,0);
	//ConfigureDrawable(avoidancedraw, topnode, 1,0,0);

	DRAWABLE & brakedrawable = topnode.GetDrawlist().normal_noblend.get(brakedraw);
	DRAWABLE & steerdrawable = topnode.GetDrawlist().normal_noblend.get(steerdraw);
	DRAWABLE & raycastdrawable = topnode.GetDrawlist().normal_noblend.get(raycastdraw);

	brakedrawable.SetLineSize(4);
	brakedrawable.SetVertArray(&brakeshape);
	brakeshape.Clear();
	for (std::vector <BEZIER>::iterator i = brakelook.begin(); i != brakelook.end(); ++i)
	{
		BEZIER & patch = *i;
		AddLinePoint(brakeshape, TransformToWorldspace(patch.GetBL()));
		AddLinePoint(brakeshape, TransformToWorldspace(patch.GetFL()));
		AddLinePoint(brakeshape, TransformToWorldspace(patch.GetFR()));
		AddLinePoint(brakeshape, TransformToWorldspace(patch.GetBR()));
		AddLinePoint(brakeshape, TransformToWorldspace(patch.GetBL()));
	}

	steerdrawable.SetLineSize(4);
	steerdrawable.SetVertArray(&steershape);
	steershape.Clear();
	for (std::vector <BEZIER>::iterator i = steerlook.begin(); i != steerlook.end(); ++i)
	{
		BEZIER & patch = *i;
		AddLinePoint(steershape, TransformToWorldspace(patch.GetBL()));
		AddLinePoint(steershape, TransformToWorldspace(patch.GetFL()));
		AddLinePoint(steershape, TransformToWorldspace(patch.GetBR()));
		AddLinePoint(steershape, TransformToWorldspace(patch.GetFR()));
		AddLinePoint(steershape, TransformToWorldspace(patch.GetBL()));
	}

	raycastdrawable.SetLineSize(4);
	raycastdrawable.SetVertArray(&raycastshape);
}
float AI_Car_Experimental::RayCastDistance( MATHVECTOR <float, 3> direction, float max_length){
	btVector3 pos = car->GetCarDynamics().GetPosition();
	btVector3 dir = car->GetCarDynamics().LocalToWorld(ToBulletVector(direction));
	dir -= pos;
	COLLISION_CONTACT contact;
	car->GetDynamicsWorld()->castRay(
		pos,
		dir,
		max_length,
		&car->GetCarDynamics().getCollisionObject(),
		contact
		);
	float depth = contact.GetDepth();
	float dist = std::min(max_length, depth);
#ifdef VISUALIZE_AI_DEBUG
	MATHVECTOR<float, 3> pos_start(ToMathVector<float>(pos));
	MATHVECTOR<float, 3> pos_end = pos_start + (ToMathVector<float>(dir) * dist);
	AddLinePoint(raycastshape, pos_start);
	AddLinePoint(raycastshape, pos_end);
#endif
	return dist;
}