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 DragonAge2 {
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(ctx.getParams()[0].getFloat());
46 }
47 
49  ctx.getReturn() = sinf(ctx.getParams()[0].getFloat());
50 }
51 
53  ctx.getReturn() = tanf(ctx.getParams()[0].getFloat());
54 }
55 
57  ctx.getReturn() = acosf(ctx.getParams()[0].getFloat());
58 }
59 
61  ctx.getReturn() = asinf(ctx.getParams()[0].getFloat());
62 }
63 
65  ctx.getReturn() = 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() = std::rand() % ctx.getParams()[0].getInt();
82 }
83 
85  ctx.getReturn() = (float)std::rand() / (float)RAND_MAX;
86 }
87 
89  ctx.getReturn() = (float) ctx.getParams()[0].getInt();
90 }
91 
93  ctx.getReturn() = (int32) ctx.getParams()[0].getFloat();
94 }
95 
97  ctx.getReturn().setVector(ctx.getParams()[0].getFloat(),
98  ctx.getParams()[1].getFloat(),
99  ctx.getParams()[2].getFloat());
100 }
101 
103  static const float kEpsilon = 1e-5f;
104 
105  float x, y, z;
106  ctx.getParams()[0].getVector(x, y, z);
107 
108  ctx.getReturn() = (ABS(x) < kEpsilon) && (ABS(y) < kEpsilon) && (ABS(z) < kEpsilon);
109 }
110 
112  float x, y, z;
113  ctx.getParams()[0].getVector(x, y, z);
114 
115  ctx.getReturn() = sqrtf(x*x + y*y + z*z);
116 }
117 
119  float x, y, z;
120  ctx.getParams()[0].getVector(x, y, z);
121 
122  const float length = sqrtf(x*x + y*y + z*z);
123 
124  ctx.getReturn().setVector(x / length, y / length, z / length);
125 }
126 
128  ctx.getReturn() = (int32) ctx.getParams()[0].getArraySize();
129 }
130 
131 } // End of namespace DragonAge2
132 
133 } // End of namespace Engines
T ABS(T x)
Definition: util.h:69
void tan(Aurora::NWScript::FunctionContext &ctx)
Context of an NWScript function.
Mathematical helpers.
void sqrt(Aurora::NWScript::FunctionContext &ctx)
void getVectorNormalize(Aurora::NWScript::FunctionContext &ctx)
void getArraySize(Aurora::NWScript::FunctionContext &ctx)
void abs(Aurora::NWScript::FunctionContext &ctx)
void randomFloat(Aurora::NWScript::FunctionContext &ctx)
const float kEpsilon
Definition: trigger.cpp:33
void asin(Aurora::NWScript::FunctionContext &ctx)
Utility templates and functions.
void acos(Aurora::NWScript::FunctionContext &ctx)
void vector(Aurora::NWScript::FunctionContext &ctx)
void pow(Aurora::NWScript::FunctionContext &ctx)
void setVector(float x, float y, float z)
Definition: variable.cpp:335
void intToFloat(Aurora::NWScript::FunctionContext &ctx)
void fabs(Aurora::NWScript::FunctionContext &ctx)
void sin(Aurora::NWScript::FunctionContext &ctx)
void atan(Aurora::NWScript::FunctionContext &ctx)
void random(Aurora::NWScript::FunctionContext &ctx)
void getVectorMagnitude(Aurora::NWScript::FunctionContext &ctx)
void cos(Aurora::NWScript::FunctionContext &ctx)
void log(Aurora::NWScript::FunctionContext &ctx)
void floatToInt(Aurora::NWScript::FunctionContext &ctx)
Dragon Age II engine functions.
void isVectorEmpty(Aurora::NWScript::FunctionContext &ctx)
int32_t int32
Definition: types.h:203