c++ Archive

  • There will be a less predictable image in a future post, once I produce something worth looking at that makes sense to you. I’ve been spending the past few weeks...

    Linear Algebra, Analytic Geometry and other stuff you never saw the point of

    There will be a less predictable image in a future post, once I produce something worth looking at that makes sense to you. I’ve been spending the past few weeks...

    Continue Reading...

  • // Finds the angle that is 180 degrees from the given angle, but in radians fmodf((angle + M_PI), (M_PI * 2))

    Find opposite angle in radians

    // Finds the angle that is 180 degrees from the given angle, but in radians fmodf((angle + M_PI), (M_PI * 2))

    Continue Reading...

  • I’ve been trying to make a simple Service Locator class work but had a problem with bizarre linker errors, where the static member variable couldn’t be resolved. After a lot...

    Static class variable initialisation in C++

    I’ve been trying to make a simple Service Locator class work but had a problem with bizarre linker errors, where the static member variable couldn’t be resolved. After a lot...

    Continue Reading...

  • #include < stdio.h > #include < math.h >   #define M_PI 3.141 #define PI180 (M_PI/180) #define DEG2RAD(x) (x * PI180)   float getShortAngle(float a1, float a2) { float angle =...

    LERP between angles in radians

    #include < stdio.h > #include < math.h >   #define M_PI 3.141 #define PI180 (M_PI/180) #define DEG2RAD(x) (x * PI180)   float getShortAngle(float a1, float a2) { float angle =...

    Continue Reading...

  • // Between a and b, using steps of 'f' size float lerp(float a, float b, float f) { return a + f * (b - a); } // From http://stackoverflow.com/questions/4353525/floating-point-linear-interpolation

    LERP

    // Between a and b, using steps of 'f' size float lerp(float a, float b, float f) { return a + f * (b - a); } // From http://stackoverflow.com/questions/4353525/floating-point-linear-interpolation

    Continue Reading...

  • float getShortAngle(float a1, float a2) { float angle = abs(a1 - a2)%360;   if(angle > 180) angle = 360 - angle;   return angle; };   printf ("%f", getShortAngle(360, 720));

    Shortest distance between two angles

    float getShortAngle(float a1, float a2) { float angle = abs(a1 - a2)%360;   if(angle > 180) angle = 360 - angle;   return angle; };   printf ("%f", getShortAngle(360, 720));

    Continue Reading...

  • #include <stdio.h> #include <time.h> #include <stdlib.h>   int main() { srand(time(NULL)); for (int i = 0; i < 100; i++) { float val = (2.0*((float)rand()/RAND_MAX))-1.0; printf ("%f\n", val); } }

    Random numbers between -1 and 1

    #include <stdio.h> #include <time.h> #include <stdlib.h>   int main() { srand(time(NULL)); for (int i = 0; i < 100; i++) { float val = (2.0*((float)rand()/RAND_MAX))-1.0; printf ("%f\n", val); } }

    Continue Reading...

  • Inspired by a post over on the Beercave, here’s a summary of the goings on this year…

    2010 Review

    Inspired by a post over on the Beercave, here’s a summary of the goings on this year…

    Continue Reading...

  • My game engine now has scrolling tilemaps in it. I have arbitrarily chosen each tile to be 32×32 pixels, and the maps to contain 256×256 tiles. This gives me a virtual display...

    Scrolling Tilemaps

    My game engine now has scrolling tilemaps in it. I have arbitrarily chosen each tile to be 32×32 pixels, and the maps to contain 256×256 tiles. This gives me a virtual display...

    Continue Reading...

  • Well, this is a bit fun! One of the main points of my game environment is that I should be able to easily modify entity behaviour without having to hard...

    Adding Lua to my software

    Well, this is a bit fun! One of the main points of my game environment is that I should be able to easily modify entity behaviour without having to hard...

    Continue Reading...