From d0a4c086edf98f5ccb1374251804c87d3c9f2591 Mon Sep 17 00:00:00 2001 From: hikerstk Date: Thu, 22 Sep 2011 07:24:27 +0000 Subject: [PATCH] Implemented rubber ball avoidance: if the new and previous position of the rubber ball crosses a line running through the rear wheels it is removed. This condition is nearly impossible to fulfill - I only managed to do this by driving in a tight circle (and then it was like 1 out of 10 balls that I could avoid). Not really useful, I commit only to see if other people have more luck :) git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/trunk@9884 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/items/rubber_ball.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/items/rubber_ball.cpp b/src/items/rubber_ball.cpp index 18305b748..a8cffe19b 100644 --- a/src/items/rubber_ball.cpp +++ b/src/items/rubber_ball.cpp @@ -24,6 +24,7 @@ #include "items/projectile_manager.hpp" #include "karts/kart.hpp" #include "modes/linear_world.hpp" +#include "physics/btKart.hpp" #include "physics/triangle_mesh.hpp" #include "tracks/track.hpp" @@ -295,6 +296,24 @@ bool RubberBall::updateAndDelete(float dt) // towards it. Vec3 diff = m_target->getXYZ()-getXYZ(); next_xyz = getXYZ() + (dt*m_speed/diff.length())*diff; + + // To see if we have overtaken the target, construct a line through + // the rear axles of the kart, and see if the current and the new + // position of the ball are on different sides of the line. + const btVector3 &w1 = m_target->getVehicle() + ->getWheelInfo(2).m_raycastInfo.m_contactPointWS; + const btVector3 &w2 = m_target->getVehicle() + ->getWheelInfo(3).m_raycastInfo.m_contactPointWS; + core::line2df axle(w1.getX(), w1.getZ(), w2.getX(), w2.getZ()); + // This is basically impossible to fulfill. I've only managed to do + // this by driving in a very tight circle, then in about 1 out of 10 + // balls I avoided the ball. + if( axle.getPointOrientation(getXYZ().toIrrVector2d()) * + axle.getPointOrientation(next_xyz.toIrrVector2d())<0) + { + printf("Congrats, rubber ball removed.\n"); + return true; + } } else {