Tiberian Technologies Scripts Reference Revision: 9000
Loading...
Searching...
No Matches
engine_math.h
1/* Renegade Scripts.dll
2 Copyright 2013 Tiberian Technologies
3
4 This file is part of the Renegade scripts.dll
5 The Renegade scripts.dll is free software; you can redistribute it and/or modify it under
6 the terms of the GNU General Public License as published by the Free
7 Software Foundation; either version 2, or (at your option) any later
8 version. See the file COPYING for more details.
9 In addition, an exemption is given to allow Run Time Dynamic Linking of this code with any closed source module that does not contain code covered by this licence.
10 Only the source code to the module(s) containing the licenced code has to be released.
11*/
12
13#ifndef SCRIPTS_INCLUDE__ENGINE_MATH_H
14#define SCRIPTS_INCLUDE__ENGINE_MATH_H
15
16#define RAD2DEG(rad) ((rad) / WWMATH_PI * 180)
17#define DEG2RAD(deg) ((deg) / 180.f * WWMATH_PI)
18#define divideRoundUp(x, y) (((x) + (y) - 1) / (y))
19
20class Vector3;
21
22inline unsigned long F2DW(float f)
23{
24 return *((unsigned long*)&f);
25}
26
27inline unsigned long F2DW(float* f)
28{
29 return *((unsigned long*)f);
30};
31
32template<typename T> inline T sqr(T value)
33{
34 return value * value;
35}
36
37template<typename T> inline T clamp(T value, T min, T max)
38{
39 if (value < min)
40 return min;
41
42 if (value > max)
43 return max;
44
45 return value;
46}
47
48template<typename T> inline T wrap(T value, T min, T max)
49{
50 return (max - min) % (value - min) + min;
51}
52
53template<> inline float wrap<float>(float value, float min, float max)
54{
55 return fmod(max - min, value - min) + min;
56}
57
58
59
60template<typename T> inline T lerp(T a, T b, float fraction)
61{
62 return a + (T)((b - a) * fraction);
63}
64
65
66
67inline bool isPowerOfTwo(int number)
68{
69 return number != 0 && ((number - 1) & number) == 0;
70}
71
72
73
74inline uint GetColorUInt(int a, int r, int g, int b)
75{
76 return ((a & 0xFF) << 24) | ((r & 0xFF) << 16) | ((g & 0xFF) << 8) | (b & 0xFF);
77}
78
79inline float sgn(float x)
80{
81 return (x < 0.0f) ? -1.0f : 1.0f;
82}
83
84int SCRIPTS_API Find_POT_LT(int i);
85
93Vector3 rayPlaneIntersect(const Vector3& rayDirection, const Vector3& planeOrigin);
94
102Vector3 rayPlaneIntersect(const Vector3& rayDirection, const Vector3& planeNormal, const float planeDistance);
103
104#endif