GDN Header

This page is for the gdn header file we're working on. It'll probably be deleted when we're finished.

#ifndef GDN_H
#define GDN_H
 
#include <cstdlib>
 
namespace GDN
{
    /**
        Seed random generator
        */
    void Randomize( unsigned int seed );
 
    /**
        Returns uniformly distributed random numbers in range [0,1)
        */
    float Random();
 
    /**
        Returns uniformly distributed random numbers between low and high
        */
    float Random( float low, float high );
 
    /**
        Returns true if value is between low and high (both inclusive)
        */
    bool InRange( int value, int low, int high );
 
        /**
        Returns true if ...
        */
    bool PointInObject(Object a, Object b);
 
        /**
        Returns true if ...
        */
    bool within_screen(Object a, int screen_width, int screen_height);
 
        /**
        Returns true if ...
        */
    bool ObjectInObject(Object a, Object b);
}
 
typedef struct GDN::Object
{
    signed int x, y;
    unsigned int w, h;
} Object;
 
// cpp file starts here
void GDN::Randomize( unsigned int seed )
{
    srand( seed );
}
 
float GDN::Random()
{
    return (float)rand() / ((float)RAND_MAX + 1);
}
 
float GDN::Random( float low, float high )
{
    return ( GDN::Random() * (high - low) + low );
}
 
bool GDN::InRange(int value, int low, int high)
{
    return (value >= low && value <= high);
}
 
float GDN::MoveSpeedDirectionX(float x, float y, float speed, float direction)
{
// calculates next x location based on speed and direction
}
 
float GDN::MoveSpeedDirectionY(float x, float y, float speed, float direction)
{
// calculates next y location based on speed and direction
}
 
float GDN::WrapValue( float value, float min, float max )
{
// wraps a value like wrapping an angle with 0 to 359, but with any min / max values
}
 
bool GDN::within_screen(Object a, int screen_width, int screen_height)
{
    return ((a.x > 0) && (a.y > 0) && (a.x < screen_width) && (a.y < screen_height));
}
 
bool GDN::PointInObject(Object a, Object b)
{
    return ((a.x > b.x) && (a.x < b.x + b.w) && (a.y > b.y) && (a.y < b.y + b.h));
}
 
bool GDN::ObjectInObject(Object a, Object b)
{
    return ((a.x + a.w > b.x) && (a.x < b.x + b.w) && (a.y + a.h > b.y) && (a.y < b.y + b.h));
}
 
float gdn::point_distance2d(float x, float y, float x2, float y2)
{
// calculates the distance between two points in 23
}
 
float gdn::point_distance3d(float x, float y, float z, float x2, float y2 float z2)
{
// calculates the distance between two points in 3D
}
 
float gdn:point_direction2d( float x, float y, float x2, float y2)
{
// calculates the direction between two points
}
 
float gdn:point_in circle( float x, float y, float circle_x, float circle_y, float circle_radius )
{
// checks if a point is in a circle
}
 
bool is_positive(float number)
{
    if ( abs ((int)number) == (int)number )
    {
        return true;
    }
    else
    {
        return false;
    }
}
 
bool is_negative(float number)
{
    return !is_positive(number);
}
page_revision: 15, last_edited: 1246181065|%e %b %Y, %H:%M %Z (%O ago)