Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5978937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T21:35:19+00:00 2026-05-22T21:35:19+00:00

Recently I was just reading the book XNA 4.0 Game Developmeny by Example. In

  • 0

Recently I was just reading the book XNA 4.0 Game Developmeny by Example. In one the of the chapters this code is written for bouncing (reflecting) the objects after collision detection:

private void BounceAsteroids(Sprite asteroid1, Sprite asteroid2)
{

    Vector2 cOfMass = (asteroid1.Velocity + asteroid2.Velocity) / 2;
    Vector2 normal1 = asteroid2.Center - asteroid1.Center;
    normal1.Normalize();
    Vector2 normal2 = asteroid1.Center - asteroid2.Center;
    normal2.Normalize();

    asteroid1.Velocity -= cOfMass;
    asteroid1.Velocity = Vector2.Reflect(asteroid1.Velocity, normal1);
    asteroid1.Velocity += cOfMass;

    asteroid2.Velocity -= cOfMass;
    asteroid2.Velocity = Vector2.Reflect(asteroid2.Velocity, normal2);
    asteroid2.Velocity += cOfMass;
}

Can anybody explain me this code with some diagram or some example which is easy to visualize. I am not able to visualize this code. If anybody knows any book where I can learn this type of physics stuff useful for game programming then also I’ll be very grateful.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T21:35:19+00:00Added an answer on May 22, 2026 at 9:35 pm

    this is trying to simulate a bounce.

    the Normalize and center calculations are making the blobs start the bounce when their edges touch, as opposed to when their centers might hit.

    then the velocity is changed according to some calculation involving masses of each asteroid.

    the Reflect function no doubt calculates some angles so things go in the proper direction.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently forced myself to study C++ and I just finished reading the book
I've read the whole Dragon Book recently (just for fun, I'm not really planning
I just recently started diving into Real World Haskell and the book provides some
I recently started reading OpenGL Superbible 5th edition and noticed the following: Having just
I recently just installed Eclipse onto a Ubuntu 10.04 machine. Now, I'm reading Getting
With the help of this community, I just recently solved some issues with PHPExcel
Recently I was reading the following piece of code from oracle collection tutorial when
I was reading through some source code recently that updated the code on a
Recently I was reading about partitioning code with .NET assemblies and stumbled upon a
I've recently been reading Louis Davidson's book on Sql Server Database Design and found

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.