Geometry Math Library for C Game Developers MathFu

Today were announcing the 1.0 release of MathFu, a cross-platform geometry math library for C++ game developers. MathFu is a C++ math library developed primarily for games focused on simplicity and efficiency.

It provides a suite of vector, matrix and quaternion classes to perform basic geometry suitable for game developers. This functionality can be used to construct geometry for graphics libraries like OpenGL or perform calculations for animation or physics systems.

The library is written in portable C++ with SIMD compiler intrinsics and has been tested on Android, Linux, OS X and Windows.

You can download the latest open source release from our GitHub page. We invite you to contribute to the project and join our discussion list!

By Stewart Miles, Fun Propulsion Labs at Google*

*Fun Propulsion Labs is a team within Google thats dedicated to advancing gaming on Android and other platforms.
Read More..

Raising Sweet C Cane for Well Dressed Animals

Posted by Stewart Miles, Fun Propulsion Labs*

To celebrate the holiday season at Fun Propulsion Labs, were trading our sushi mats and baking pans for candy canes and snowballs. Please join us for a special holiday-themed version of Pie Noon and Zooshi! Zooshi and Pie Noon are open source, cross-platform games built from a suite of libraries that eager C++ developers can use to build their own projects.

You can download and run Zooshis Santa mode on Google Play and find the latest open source release on our GitHub page. The holiday version of Pie Noon is available on Google Play as Snowdown in Santa Tracker and on our GitHub page. Happy Holidays!

* Fun Propulsion Labs is a team within Google thats dedicated to advancing gaming on Android and other platforms.

Read More..

Random number generator in c programming

This tutorial contains
  • How to generate a random number using rand()
  • Simple example using rand() function
  • Generate random number in a specific range dice example

To generate a random number in c++ program first we have to include a header file which is
#include<cstdlib> because we have to use a function from that library which is “rand();” this functions simple returns a random number

Let use that function

#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
  cout<<rand()<<endl;
return 0;
}


It will return a random number for example
41
 Let use a loop and generate some more random numbers using that function

#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
 for(int i=1;i<=10;i++)
    cout<<rand()<<endl;
return 0;
}

It will generate 10 random  numbers
What if we want to generate random numbers with in the specific range like we want to generate random numbers between 1 to 10 or 50 to 100

for example range is 1 to 10

We think something like that cout<<rand()%10;

How it will work
It will take a random number divide it by 10 and return us the number the number can be from 0 to 9
After getting the output we see that if we add 1 in the result value we can get our required range values
So we will change it like that << 1 + ( rand() % 10 ) ;

Lets take another example of a dice it can generate numbers 1 to 6 randomly

 we will simple something like that
But is it write or not


for(int i=1;i<=6;i++)

    cout<< rand()%6<<endl;


And there is a problem it will return us number from 0 to 5 to make the logic of our program we will change it like that
for(int i=1;i<=6;i++)

    cout<< 1+ (rand()%6)<<endl;

So this will work fine in this case 0 is eliminate and whatever number will return 1 will be added in it like if 0 is generated it will result as 1 if 5 is generated it will return us 6
  
Hope this tutorial will help to understand the basic about of random number
Read More..

Learn to Define and Use Functions in C

Functions can be thought of as separate programs that are designed to perform
specific tasks. For example, in a program, separate functions can be so designed
to perform specific tasks such as taking input, doing calculation, giving output
etc.

In this article we will be discussing about what functions are and how they
are designed in C++.

Generally, programs have many logically different parts (input, output etc.)
which can be coded separately as function. This makes programs easily manageable
and understandable.

Suppose we have to design an invoice program that takes input, calculates and
at last displays the output. We have two options to do so, we can either program
the whole thing linearly or we can make separate functions for each of the tasks
(input, output etc.), this would make the program far more manageable and upgradeable.
(In the future, if you need to change certain things, you only need to alter
the functions)

In this way if you divide various activities of the program into different
function, then it would be easy for you to code and check each of the function
besides making the program easier to understand and manage.

Have a look at this program:


   //C++ program
#include<iostream.h>

   int sqr(int x);//declaration of the function
   void main(void)
{
int a=9;
cout<<"square of "<<a<<" is ";
cout<<sqr(a)<<endl;//function is being called here
}

int sqr(int x)//no ;(semicolon) here
{
x=x*x;
return (x);//return keyword is used
//to return values, in this case
//the value of x is returned
}

Few points about the program:


  • In C++, it is necessary to declare a function before defining it as we have
    done in the line:

    int sqr(int x);//declaration
    of the function


  • One function cannot be defined inside another. Therefore sqr(int x) function
    cannot be defined inside main () which itself is a function.


  • A function can return any type of values except arrays.
    The value is returned in the line:

    return (x);

    and the value got accepted and printed in the line:
    cout<<sqr(a);


Now that you understand how to declare and use functions, let me give you a
slightly more complex program:


   //C++ program
#include<iostream.h>

   //declaration of functions
int take_input(void);
void play(void);//it is optional to use the void keyword
void help(void);
void quit(void);

   //main program starts from here
void main(void)
{
int choice;
choice=take_input();//take input

   //perform action as per the value returned
if(choice==1) play();
else if(choice==2) help();
else if(choice==3) quit();
}

   //functions are defined below
int take_input()
{
int ch=0;
cout<<" MAIN MENU";
cout<<endl<<endl;
cout<<"1> PLAY"<<endl;
cout<<"2> HELP"<<endl;
cout<<"3> QUIT"<<endl;
cout<<endl<<endl;
cout<<"enter choice and press enter"<<endl;

while (ch!=1 && ch!=2 && ch!=3)
{
cin>>ch;
}

return (ch);
}

   void play(void)
{
cout<<"write code for PLAY"<<endl;
}

   void help(void)
{
cout<<"write code for HELP"<<endl;
}

   void quit(void)
{
cout<<"write code for QUIT"<<endl;
}

This is a simple program to illustrate how the various activities of a program
can be divided into separate functions. Notice how easy it is to understand
the program. Even if the functions play (), help () etc. had 100’s of
lines of code, the program would have been easily understandable.


Hope this helps…


Related Articles:


Read More..

Blog Archive

Powered by Blogger.