|
#include "StdAfx.h"
#include "BounceWall.h"
#include "Ball.h"
#include "Situation.h"
//#include <iostream>
// std::cout << "Next event predicted at " << Time() << std::endl;
CBounceWall::CBounceWall(CBall *ball, int d)
{
this->ball = ball;
this->d = d;
}
CBounceWall::~CBounceWall(void)
{
}
CSimulator *CBounceWall::Simulator()
{
return ball->Simulator();
}
void CBounceWall::PredictCollisionBetweenBallAndWall( double t0 )
{
CSituation *sit = &ball->situation;
const double epsilon = 0.0;
double v = sit->GetVelocity()[d];
double x;
if (v > epsilon)
x = 10 - ball->radius;
else if( v < epsilon )
x = ball->radius - 10;
else
{
Enable( false );
return;
}
double t1 = sit->GetBaseTime() +
(x - sit->GetBasePosition()[d]) / sit->GetVelocity()[d];
ChangeTime(t1);
Enable( true );
}
void CBounceWall::Expire()
{
CSituation *sit = &ball->situation;
sit->SetBaseTime( Time() );
osg::Vec3d v = sit->GetVelocity();
v[d] = -v[d];
sit->SetVelocity( v );
#ifdef WITH_QUAT
// Note: Axis of rotation is not accurate
// Balls that rotate on collision should lose energy too
v[d] = 0;
sit->SetAngularVelocity( v );
#endif
ball->PredictChanges();
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.
I develop rail signalling simulation technology at EDM where I use C++ and C#, but also love to dabble in functional programming languages such as Clean and Cat.