Skip to main content
GameDev.net gamedev.net
🔒 Locked

collision detection

Started by chennaiaras Sep 17, 2010 at 1:20 AM 8 replies 2.3k views
Original Post
chennaiaras
chennaiaras
Hi all,

I am just trying to rotate a ball randomly within four walls.

So far, did the following tasks :

1. created the window (four walls)
2. initialized directx object and device
3. loaded a ball.bmp into the window ( through backbuffer and surface)

Now,
1. how can i rotate the ball in a random fashion.?

2. provide collision detection with the walls.
(have read some tutorials on CD in articles & resources section, but could not get an clear idea on how to use it with the objects in the code. I would appreciate if someone get me any sample code on CD along with the main program)

Thanking you,
aras
Kalnos
Kalnos
2. As far as walls go with collision, you're just going to code them in regards to what the screen width and height are most likely.

For example:

//Collision with topif (ballPoisitionY < 0)   {   ballPositionY = 0;   ballDirectionY *= -1;  //On collision you reverse direction  };//Collision with bottomif (ballPositionY + ballTextureHeight > screenHeight){  ballPositionY = screnHeight - ballTextureHeight;  ballDirectionY *= -1;}


The process would be exactly the same with the X walls, the screen width and height sides are a little trickier because you have to account for how the position of your ball is calculated due to how textures are drawn.
Juliean
Juliean
I would strongly recommend you to use Sprites instead of surfaces
for objects like your ball (except for learning purposes). You can easily rotate sprites, amd
pixelcollison is a lot easier, too. Look for some tutorials on the topic sprites, maybe I can help youtoo when I'm at home.
chennaiaras
chennaiaras
Hi kalnos,

Thanks for the reply..

What u have suggested is the easiest thing, that's not really a CD.

i need to know the real CD for an object.

regards,
aras
speciesUnknown
speciesUnknown
What do you mean by rotate? A ball is totally spherical, so rotating it doesn't cause any change in shape and therefore doesn't cause any collision.

Is it friction that you are trying to simulate?
Don't thank me, thank the moon's gravitation pull! Post in My Journal and help me to not procrastinate!
Echkard
Echkard
Quote:
Original post by speciesUnknown
What do you mean by rotate? A ball is totally spherical, so rotating it doesn't cause any change in shape and therefore doesn't cause any collision.
He's obviously trying to both rotate the ball and move it (and detect wall collision while moving)

chennaiaras
chennaiaras
Hi all,

OK. Just movement of the ball within four walls.

thanks,
aras
Frisco
Frisco
Tried the orange book?

heard it describes amazing things about collision detection
chennaiaras
chennaiaras
Hi Frisco,

Orange book.. Please let me know the title and the author's name. If possible, Publisher's name.

regards,
aras


Echkard
Echkard
Quote:
Original post by chennaiaras
Hi Frisco,

Orange book.. Please let me know the title and the author's name. If possible, Publisher's name.


http://www.amazon.com/Real-Time-Collision-Detection-Interactive-Technology/dp/1558607323

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.