.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  
Silverlight  
Visual Basic.NET  
Windows Scripting  
Windows Security  
XML  
Mobile Linux 
App Generation ROI 
IBM® developerWorks 
ASP Web Hosting  
ASP.NET Web Hosting 
Windows Web Hosting
 
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 / 8
    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

    - Building Applications with Windows Workflow ...
    - Building the Data and Business Layers Using ...
    - The Transformed XML Explorer in MFC
    - List Control and Property Grid with the MFC ...
    - Font, Shell and Masked Edit Controls for MFC
    - Color, Link and Image Editor Controls for M...
    - New Controls for MFC
    - The Windows Ribbon Framework
    - Markup Language for the Ribbon Framework
    - Visually Upgrade Your MFC Project
    - New Features for the Statusbar in MFC
    - Working with the Statusbar in MFC
    - Iron Speed Design v60 Review
    - Binary and XML Serialization
    - Using CrystalReportViewer to Display Crystal...





    © 2003-2009 by Developer Shed. All rights reserved. DS Cluster 6 Hosted by Hostway
    For more Enterprise Application Development news, visit eWeek