Skip to main content

Useful simple maths collection for games development

Here, I've collected the useful mathematics calculation to be used in everyday game development. Keep me posted if you have other useful daily mathematics calculate useful in game.

Calculating percentage from current and maximum value

float percent =(current / maximum) * 100.0f

Calculating value from the current and percentage

float value = (current * percentage) / 100.0f

Calculating Row And Columns in 2D array

     /// Get the row number of the grid cell in a given index  
    public int GetRowFromIndex(int index, int numRows)  
    {  
      int row =  Mathf.FloorToInt((float)index / (float)numColumns); 
      return row;  
    }  
    /// Get the column number of the grid cell in a given index  
    public int GetColumnFromIndex(int index, int numColumns)  
    {  
      int col = index % numColumns;  
      return col;  
    }  
    /// Get the index from the given row and column  
    public int GetIndexFromRowCol(int curRow, int curCol, int numRows, int numColumns)  
    {  
      int index = (curRow * numColumns) + curCol;  
      return index;  
    }  


Comments

Popular posts from this blog

Using XAML on Monogame for WinRT (Part 2)

Integrating Monogame with XAML Metro UI If you're coming from the previous section, you now have a metro UI application project with blank page and also have monogame.windows8 library reference to the project. Now Let's fix some source code for the  pages to get XAML working with monogame. Step01 ( Hacking App.xaml.cs file) App.xaml.cs delivers the most important start point while rendering a particular page in Metro UI application. I added gamePage and mainPage as  a public variables as they become accessible from other classes to for page nagivations. Here is the source code for to see what it looks like for the final App.xaml.cs file. sealed partial class App : Application     {         public ContentManager Content { get; set; }         public GameServiceContainer Services { get; set; }         public GamePage gamePage;         public MainPage mainPage;   ...

Using CloudyRec Code Generator

The greatest CloudyRec feature among other backend service provider is the Code Generator where it can generate the native modal source code with the specified schema in the previous " Getting Started " section. Sandbox Environment When you’ve satisfied the attributes and resources for the applications, you can start loading into the sandbox to make the apps ready for testing.  Go to the Define tab of the dashboard and click the “Load to sandbox” button located at the right side of the application name as shown in the figure below. Figure 1.0 Loading to Sandbox environment Note : In CloudyRec, there are two types of development modes available called Sandbox and Production. Sandbox is for testing the applications while developing and it’s totally free and developer doesn’t needs to pay a penny while using Sandbox.  I would recommend to put into production mode once you’ve published the apps as the data from the Sandbox will be flushed in ti...

Getting Started with Monogame for WinRT

Monogame is the opensource XNA development framework where the XNA developers for XBox, Windows and WP7 can be able to port their games for iOS, Android, Mac OSX, Linux, Windows 8 Metro Style apps and PlayStation Mobiles. As XNA framework is not allowed to create Windows 8 Metro App anymore,  Monogame becomes the best framework to port the current games written in XNA. Monogame framework rewrite the XNA wrappers using SharpDX which is the current fastest Direct X Wrapper for C#. Although there are opensource game development frameworks for WinRT is available, Monogame is the one that shouldn't miss if you're a former XNA developer or C# programmer. You will need the following software and tools if you're really new to WinRT development environments. Windows 8 Release Preview   Visual Studio 2012 Release Candidate   They're currently in beta, so you can go unlimited trials for these until the final releases comes out. If you're not planning to...