.NET
  Home arrow .NET arrow Page 7 - Game Development of .Nettrix: GDI+ and Col...
ASP Free Forums 
.NET  
ASP  
ASP Code  
ASP.NET  
ASP.NET Code  
BrainDump  
C#  
Code Examples  
Database  
Database Code  
IIS  
Microsoft Access  
MS SQL Server  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
ASP Web Hosting  
ASP.NET Web Hosting 
Mobile Linux 
App Generation ROI 
Windows Web Hosting
 
IBM® developerWorks 
Sun Developer Network 
Weekly Newsletter
 
Developer Updates  
Free Website Content 
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
.NET

Game Development of .Nettrix: GDI+ and Collision Detection
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 7
    2004-08-23

    Table of Contents:
  • Game Development of .Nettrix: GDI+ and Collision Detection
  • Performing Graphic Operations with a Graphics Object
  • Creating Gradients
  • Collision Detection
  • Proximity Algorithms
  • Optimizing the Number of Calculations
  • Extending the Algorithms to Add a Third Dimension
  • Develop a Real Game Proposal
  • Diagrams of Basic Game Objects
  • The Game Engine
  • The Coding Phase
  • Testing the Program
  • The Block Class
  • The Constructor
  • The Down, Right, and Left Methods
  • The Rotate Method
  • The Show and Hide Methods
  • Final Version: Coding the GameField Class and the Game Engine
  • The CheckLines Method
  • The Game Engine
  • Adding the Final Touches
  • Further Improvements

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
    ADVERTISEMENT


    Game Development of .Nettrix: GDI+ and Collision Detection - Extending the Algorithms to Add a Third Dimension


    (Page 7 of 22 )

    There are many advanced algorithms for 3-D collisions described on game-related sites all over the Internet. We’ll not stress the many implications on including a z axis in the collision detection algorithms; instead you just add some simple extensions to the preceding algorithms. This code sample depicts a proximity test with cube-like objects:

    float Dx = Math.Abs(r2.x - r1.x);
    float Dy = Math.Abs(r2.y - r1.y);
    float Dz = Math.Abs(r2.z - r1.z);

    if (Dx > (r1.extentX+r2.extentX) && (Dy > (r1.extentY+r2.extentY) && (Dz > r1.extentZ+r2.extentZ))
      // The boxes do not overlap.
    else
      // The boxes overlap.

    The next proximity algorithm extends the circle proximity test to use spheres in a 3-D space.

    Dx = Math.Abs(Object1.CenterX - Object2.CenterX);
    Dy = Math.Abs(Object1.CenterY - Object2.CenterY);
    Dz = Math.Abs(Object1.CenterZ - Object2.CenterZ);
    double Distance = Math.Sqrt(Dx*Dx + Dy*Dy + Dz*Dz);

    if (Distance > Object1.radius+ Object2.radius)
      // => The circles do not overlap.
    else
      // => The circles are overlapping.

    The last proximity test is used for Sphere/Cube intersections. You probably already get the idea on how to extend these simple intersection tests. In the case of Arvo’s Algorithm, you simply add a test for the z axis.


    // Check z axis. If Circle is outside box limits, add to distance.
    if (CircleCenterZ < this.MinZ)
      dist += Math.Sqr(CircleCenterZ – this.MinZ);
    else if (CircleCenterZ > this.MaxZ)
      dist += Math.Sqr(CircleCenterZ – this.MaxZ);

    // Now that distances along x, y, and z axis are added, check if the square
    // of the Circle's radius is longer and return the boolean 
             result. return (Radius*Radius) < dist;
    return (Radius*Radius) < dist;

    In the next sections you’ll see how to apply these theoretical ideas in a real game project.

    This chapter is from Beginning .NET Game Programming in C#, by David Weller, et al., (Apress, 2004, ISBN: 1590593197). Check it out at your favorite bookstore today.

    Buy this book now.

    More .NET Articles
    More By Apress Publishing


       · Examples from the first page are invalid. You cannot do:Graphics g = new...
     

    .NET ARTICLES

    - Using CrystalReportViewer to Display Crystal...
    - Creating Summary .Net Crystal Reports
    - More on Commands, Input and the WPF
    - Grouping and Aggregating When Querying LINQ ...
    - Commands, Input and the WPF
    - Keyboard and Ink Input with WPF
    - Mouse Input and the WPF
    - Input with Windows Presentation Foundation
    - Introducing LINQ with XML and Databases
    - An Introduction to LINQ
    - Querying LINQ to SQL: Basics
    - Completing a Simple Storefront with LINQ
    - Knowing Your Environment: the System.Environ...
    - Creating the Home Page for a Simple Storefro...
    - LINQ Quickly with Language Integrated Queries





    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 2 hosted by Hostway
    Stay green...Green IT