Jump to content

  • Log In with Google      Sign In   
  • Create Account

Sam Sandeep

Member Since 25 Apr 2011
Offline Last Active Feb 25 2013 10:19 PM

Topics I've Started

Rectangle Line collision problem

08 January 2013 - 11:58 PM


I'm working on 2d top down car racing game.  Could anyone tell me the simplest way of the detecting the collision between the car (rectangle) and the track edges(lines).  The logic I'm currently using is not working as I expected.  I tried to check for line to line collision between the car's rectangle (4 lines) and the track lines.  Also if it not vector based it would be great, so I could use it right away in my  project. 





How do I rotate a rectangle with the four vertices

08 January 2013 - 03:57 AM



Could anyone please help me out here?


I have the top left corner co ordinates of a rectangle.  And also the width and height.  Now, say, I want to rotate the rectangle 30 deg with the top left vertex as it s axis.  How do I calculate the four vertices.  


I'm trying to do this in opengl without using the glRotatef function, but for some reason the texture gets distorted with the rectangle rotates.


I'm currently using this logic.




currentTopLeftX = Vertices[ 0 ].x;
currentTopLeftY = Vertices[ 0 ].y;

currentTopRightX = Vertices[ 0 ].x + w*cos(angle*PI/180);
currentTopRightY = Vertices[ 0 ].y + w*sin(angle*PI/180);

currentBottomRightX = Vertices[ 0 ].x + w*cos(angle*PI/180) - h*sin(angle*PI/180);
currentBottomRightY = Vertices[ 0 ].y + w*sin(angle*PI/180) - h*cos(angle*PI/180);

currentBottomLeftX = Vertices[ 0 ].x + h*sin(angle*PI/180);
currentBottomLeftY = Vertices[ 0 ].y + h*cos(angle*PI/180);



Collision Detection HELP! openGL SDL c++, 2D top down racing game

01 January 2013 - 11:55 PM



I'm trying to build a simple top down car racing game using SDL, I'm using openGL for rendering.  I've drawn the track using parallel bezier curves and taking the points and drawing them as Quads with texture.  I've got the car physics up and running.  

Now, I would like start off with the collision between the car and the track.  Could anyone help me out by giving a simple and practical solution for this.