コード例 #1
0
ファイル: Mole.cpp プロジェクト: bullfrognz/MoleMadness
void
CMole::UpdateRotation(float _fTimeDelta, const CFVec2& _kvrForce)
{
	if (_kvrForce.X() != 0.0f ||
		_kvrForce.Y() != 0.0f)
	{
		// Create heading vector
		CFVec2 vHeading(0.0f, -1.0f);
		vHeading.RotateZ(m_fHeading);


		// Cross
		float fCross = 0.0f;
		fCross  = vHeading.X() * _kvrForce.Y();
		fCross -= _kvrForce.X() * vHeading.Y();


		float fRotationVelocity = m_fRotationVelocity + fDegsToRad(static_cast<float>(DIFFICULTY_ROTATION_VELOCITY_INCR * m_iDifficultyLevel));


		if (fCross > 0.0f)
		{
			// Turn left
			m_fHeading += fRotationVelocity * _fTimeDelta;
		}
		else
		{
			// Turn right
			m_fHeading += fRotationVelocity * - _fTimeDelta;
		}
	}
}
コード例 #2
0
ファイル: Wall.cpp プロジェクト: roosen5/media-design-school
/**
 *	Check this wall with an infinite ray, given in parametric form and return the collision if applicable.
 *	@param vRayStart	Start point for parametric equation of infinite ray.
 *	@param vRayEnd		Direction vector (coefficient of t) for paremetric equation of infinitie ray.
 *	@param fT			To be filled in with the time (paremetric T) of intersection.
 *	@return				True if the intersection occurs within this line segment.
 */
bool CWall::GetLineIntersectionTime(  CFVec2Arg vRayStart, CFVec2Arg vRayOffset, FLOAT32& fT ) const
{
	// http://local.wasp.uwa.edu.au/~pbourke/geometry/lineline2d/
	const CFVec2& P1 = m_vEnd[0];
	const CFVec2& P2 = m_vEnd[1];
	const CFVec2& P3 = vRayStart;
	// no P4 required..
	const CFVec2 V1 = P2-P1;
	const CFVec2& V2 = vRayOffset;
	
	const FLOAT32 fDenom = V2.Y()*V1.X() - V2.X()*V1.Y();
	
	if ( fDenom == 0.0f )
	{
		return false; // no intersections, or the lines are the same!
	}

	const FLOAT32 fDRecip = 1.0f/fDenom;
	// and then, finally Q (for x/y1 - x/y3)
	const CFVec2 Q = P1-P3;

	const FLOAT32 fTimeThis = (V2.X()*Q.Y() - V2.Y()*Q.X())*fDRecip;

	if ( fTimeThis < 0.0f || fTimeThis > 1.0f )
	{
		// outside of the wall line segment.
		return false;
	}
	fT = (V1.X()*Q.Y() - V1.Y()*Q.X())*fDRecip;
	return true;
}
コード例 #3
0
ファイル: Box2D.cpp プロジェクト: roosen5/media-design-school
bool	CBox2D::Intersects( const CCircle& Circle ) const
{
	CFVec2 vOffset = (Circle.Centre() - m_vCentre);
	vOffset.SetAbs();
	vOffset -= m_vExtents;
	return ( vOffset.X() < Circle.Radius() && vOffset.Y() < Circle.Radius() );
}
コード例 #4
0
ファイル: Box2D.cpp プロジェクト: roosen5/media-design-school
bool	CBox2D::ContainsPoint( CFVec2Arg vPoint ) const
{
	CFVec2 vOffset = (vPoint - m_vCentre);
	vOffset.SetAbs();
	vOffset -= m_vExtents;
	return ( vOffset.X() < 0.0f && vOffset.Y() < 0.0f );

}
コード例 #5
0
/**
 *	@param fX Filled with the mouse X coordinate.
 *	@param fY Filled with the mouse Y coordinate.
 *	@param bWasClicked Filled with a bool to say if the mouse was clicked.
 */
bool CGameBoard::GetMouseInfo( FLOAT32& fX, FLOAT32& fY, bool& bWasClicked ) const
{
	CFVec2 vMousePos;
	CConnect4Context::GetInstance().GetMouse()->GetPosition( vMousePos );
	bWasClicked = CConnect4Context::GetInstance().GetMouse()->WasClicked();
	fX = vMousePos.X();
	fY = vMousePos.Y();
	return true;	
}
コード例 #6
0
ファイル: Box2D.cpp プロジェクト: roosen5/media-design-school
bool	CBox2D::Intersects( const CBox2D& Box ) const
{
	CFVec2 vOffset = (Box.m_vCentre - m_vCentre);
	vOffset.SetAbs();
	vOffset -= m_vExtents;
	vOffset -= Box.m_vExtents;
	return ( vOffset.X() < 0.0f && vOffset.Y() < 0.0f );

}
コード例 #7
0
ファイル: Mole.cpp プロジェクト: bullfrognz/MoleMadness
void
CMole::ComputeWallForce(CFVec2& _vrRepelForce)
{
	for (unsigned int i = 0; i < MAX_WHISKER; ++ i)
	{
		CFVec2 vLineRepelForce;
		CWall* pClosestWall = 0;
		float fImpactTime = 0;
		bool bIntersected = FindWiskerClosestWall(static_cast<EWhisker>(i), pClosestWall, fImpactTime);


		if (bIntersected)
		{
			// Time radio
			float fTimeRatio = 1.0f - (fImpactTime / 1.0f);
			fTimeRatio *= 1.8f;


			if (fTimeRatio > 1.0f)
			{
				fTimeRatio = 1.0f;
			}


			CFVec2 vPointDisplacement(pClosestWall->GetStartPoint());
			vPointDisplacement -= pClosestWall->GetEndPoint();


			// Line direction
			CFVec2 vLineDirection(vPointDisplacement);
			vLineDirection.Normalise();


			// Get Normal
			CFVec2 vLineNormal(pClosestWall->GetNormal());
			vLineNormal.Normalise();


			CFVec2 vStart = pClosestWall->GetStartPoint();
			CFVec2 vEnd = pClosestWall->GetEndPoint();


			// Which side is the cat on
			float fPerpendicularDot = (vEnd.X() - vStart.X()) * (m_vPosition.Y() - vStart.Y()) - (vEnd.Y() - vStart.Y()) * (m_vPosition.X() - vStart.X());


			bool bOnNormalSide = (fPerpendicularDot > 0);

			
			// Cat going against the normal
			if (bOnNormalSide)
			{
				// Cat has to be on normal side
				vLineRepelForce = vLineNormal;
				vLineRepelForce.RotateZ(fDegsToRad(180.0f));
			}


			// Cat going towards normal
			else
			{
				// Cat has to be not on normal side
				vLineRepelForce = vLineNormal;
			}


			// Scale based on collision time
			//vLineRepelForce *= 1.25f;
			vLineRepelForce *= fTimeRatio;


			_vrRepelForce += vLineRepelForce;
			m_pWhiskers[i].SetColour(0xFFFF0000);
		}
	}
}