kick
/Users/morten/Programmering/cpp/kick/src/kick/math/misc.cpp
00001 //
00002 // Created by morten on 19/09/14.
00003 //
00004 
00005 #include "misc.h"
00006 #include <glm/gtc/constants.hpp>
00007 
00008 namespace kick {
00009 
00010     glm::vec4 uint32ToVec4(int32_t uint32) {
00011         uint8_t * ptr = (uint8_t *)(&uint32);
00012         glm::vec4 dest;
00013         for (int i = 0; i < 4; i++) {
00014             dest[i] = ptr[i]/255.0f;
00015         }
00016         return dest;
00017     }
00018 
00019     int32_t vec4ToUint32(glm::vec4 vec) {
00020         int32_t uint32;
00021         uint8_t * ptr = (uint8_t *)(&uint32);
00022         for (int i = 0; i < 4; i++) {
00023             ptr [i] = (uint8_t)(vec[i]*255);
00024         }
00025         return uint32;
00026     }
00027 
00028     int32_t vec4ToUint32(glm::u8vec4 vec){
00029         int32_t uint32;
00030         uint8_t * ptr = (uint8_t *)(&uint32);
00031         for (int i = 0; i < 4; i++) {
00032             ptr [i] = vec[i];
00033         }
00034         return uint32;
00035     }
00036 
00037     float clamp01(float value) {
00038         if (value < 0.f)
00039         {
00040             return 0.f;
00041         }
00042         if (value > 1.f)
00043         {
00044             return 1.f;
00045         }
00046         return value;
00047     }
00048 
00049     float repeat(float t, float length) {
00050         return t - floor (t / length) * length;
00051     }
00052 
00053     float lerpAngle(float a, float b, float t) {
00054         float num = repeat (b - a, glm::pi<float>()*2);
00055                 if (num > glm::pi<float>())
00056         {
00057                         num -= glm::pi<float>() * 2;
00058         }
00059         return a + num * clamp01 (t);
00060     }
00061 
00062     glm::vec3 faceNormal(glm::vec3 a, glm::vec3 b, glm::vec3 c) {
00063         return glm::normalize(glm::cross(c - a, b - a));
00064     }
00065 }
 All Classes Functions Variables