• Advertisement
Sign in to follow this  

Collsion detection with other objects

This topic is 2169 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi,

I am trying to implement some collision detection on two OpenGL objects a player and a triangle. I have a collision detection method in a class that draws a triangle:


bool CTriangleCollision::testCollision (float x, float y, float z, float r)
{
float d = sqrt ((x-m_xCPos)*(x-m_xCPos) + (y-m_yCPos)*(y-m_yCPos));

if(d < r)
{
return true;
}
else
{
return false;
}
}

The parameter x has the x position of the player passed in and the same with the y parameter.

I then call this in main in my loop:

if(g_TriangleCollision.testCollision(g_Player1.getPosX(), g_Player1.getPosY(), 0 ,250))
{
g_TriangleCollision.delete();
}
else{ }

I have used the delete function it has flagged an error and I am not sure about the condition for my collision detection function feedback on those would be good

Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement