xoreos  0.0.5
functions_math.cpp
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #include "src/common/util.h"
26 #include "src/common/maths.h"
27 
29 
31 
32 namespace Engines {
33 
34 namespace NWN2 {
35 
37  ctx.getReturn() = ABS(ctx.getParams()[0].getInt());
38 }
39 
41  ctx.getReturn() = ABS(ctx.getParams()[0].getFloat());
42 }
43 
45  ctx.getReturn() = cosf(Common::deg2rad(ctx.getParams()[0].getFloat()));
46 }
47 
49  ctx.getReturn() = sinf(Common::deg2rad(ctx.getParams()[0].getFloat()));
50 }
51 
53  ctx.getReturn() = tanf(Common::deg2rad(ctx.getParams()[0].getFloat()));
54 }
55 
57  ctx.getReturn() = Common::rad2deg(acosf(ctx.getParams()[0].getFloat()));
58 }
59 
61  ctx.getReturn() = Common::rad2deg(asinf(ctx.getParams()[0].getFloat()));
62 }
63 
65  ctx.getReturn() = Common::rad2deg(atanf(ctx.getParams()[0].getFloat()));
66 }
67 
69  ctx.getReturn() = logf(ctx.getParams()[0].getFloat());
70 }
71 
73  ctx.getReturn() = powf(ctx.getParams()[0].getFloat(), ctx.getParams()[1].getFloat());
74 }
75 
77  ctx.getReturn() = sqrtf(ctx.getParams()[0].getFloat());
78 }
79 
81  ctx.getReturn() = getRandom(0, ctx.getParams()[0].getInt() - 1);
82 }
83 
85  ctx.getReturn() = getRandom(1, 2, ctx.getParams()[0].getInt());
86 }
87 
89  ctx.getReturn() = getRandom(1, 3, ctx.getParams()[0].getInt());
90 }
91 
93  ctx.getReturn() = getRandom(1, 4, ctx.getParams()[0].getInt());
94 }
95 
97  ctx.getReturn() = getRandom(1, 6, ctx.getParams()[0].getInt());
98 }
99 
101  ctx.getReturn() = getRandom(1, 8, ctx.getParams()[0].getInt());
102 }
103 
105  ctx.getReturn() = getRandom(1, 10, ctx.getParams()[0].getInt());
106 }
107 
109  ctx.getReturn() = getRandom(1, 12, ctx.getParams()[0].getInt());
110 }
111 
113  ctx.getReturn() = getRandom(1, 20, ctx.getParams()[0].getInt());
114 }
115 
117  ctx.getReturn() = getRandom(1, 100, ctx.getParams()[0].getInt());
118 }
119 
121  ctx.getReturn() = (float) ctx.getParams()[0].getInt();
122 }
123 
125  ctx.getReturn() = (int32) ctx.getParams()[0].getFloat();
126 }
127 
129  ctx.getReturn().setVector(ctx.getParams()[0].getFloat(),
130  ctx.getParams()[1].getFloat(),
131  ctx.getParams()[2].getFloat());
132 }
133 
135  float x, y, z;
136  ctx.getParams()[0].getVector(x, y, z);
137 
138  ctx.getReturn() = sqrtf(x*x + y*y + z*z);
139 }
140 
142  float x, y, z;
143  ctx.getParams()[0].getVector(x, y, z);
144 
145  const float length = sqrtf(x*x + y*y + z*z);
146 
147  ctx.getReturn().setVector(x / length, y / length, z / length);
148 }
149 
150 } // End of namespace NWN2
151 
152 } // End of namespace Engines
T ABS(T x)
Definition: util.h:69
void vectorNormalize(Aurora::NWScript::FunctionContext &ctx)
void d12(Aurora::NWScript::FunctionContext &ctx)
Context of an NWScript function.
Mathematical helpers.
void fabs(Aurora::NWScript::FunctionContext &ctx)
void d100(Aurora::NWScript::FunctionContext &ctx)
void pow(Aurora::NWScript::FunctionContext &ctx)
void d6(Aurora::NWScript::FunctionContext &ctx)
void d4(Aurora::NWScript::FunctionContext &ctx)
void vectorMagnitude(Aurora::NWScript::FunctionContext &ctx)
void sqrt(Aurora::NWScript::FunctionContext &ctx)
void intToFloat(Aurora::NWScript::FunctionContext &ctx)
static int32 getRandom(int min, int max, int32 n=1)
Definition: functions.cpp:102
Neverwinter Nights 2 engine functions.
Utility templates and functions.
void acos(Aurora::NWScript::FunctionContext &ctx)
void setVector(float x, float y, float z)
Definition: variable.cpp:335
void floatToInt(Aurora::NWScript::FunctionContext &ctx)
void random(Aurora::NWScript::FunctionContext &ctx)
void d8(Aurora::NWScript::FunctionContext &ctx)
void d20(Aurora::NWScript::FunctionContext &ctx)
void vector(Aurora::NWScript::FunctionContext &ctx)
void asin(Aurora::NWScript::FunctionContext &ctx)
void atan(Aurora::NWScript::FunctionContext &ctx)
void tan(Aurora::NWScript::FunctionContext &ctx)
void d2(Aurora::NWScript::FunctionContext &ctx)
void d10(Aurora::NWScript::FunctionContext &ctx)
static float rad2deg(float rad)
Definition: maths.h:93
void abs(Aurora::NWScript::FunctionContext &ctx)
void log(Aurora::NWScript::FunctionContext &ctx)
static float deg2rad(float deg)
Definition: maths.h:97
void d3(Aurora::NWScript::FunctionContext &ctx)
void cos(Aurora::NWScript::FunctionContext &ctx)
void sin(Aurora::NWScript::FunctionContext &ctx)
int32_t int32
Definition: types.h:203