5 * Created by Bryan Donlan on Sun Jul 23 2006
6 * Copyright (c) 2006 Bryan Donlan. All rights reserved.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2 of the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
25 #define PI (atanf(1)*4)
28 * VEC: MAKE (vector) x (float) y (float)
31 * Creates and returns a vector with the given components.
33 * Openc2e-only command
36 void caosVM::v_VEC_MAKE() {
40 result
.setVector(Vector
<float>(x
, y
));
44 * VEC: GETC (command) vec (vector) x (variable) y (variable)
47 * Extracts the components of vector vec and places them in x and y.
49 * Openc2e-only command
52 void caosVM::c_VEC_GETC() {
62 * VEC: ANGL (float) vec (vector)
65 * Find and return the angle from the X-axis of the given vector.
66 * This is computed using atan(y/x) if X is nonzero, and a hard-coded
67 * return if X is nonzero. If the input vector is the null vector (0,0),
68 * zero will be returned.
70 * The returned angle is in degrees, and in the range -180 to 180 degrees.
72 * Openc2e-only command.
75 void caosVM::v_VEC_ANGL() {
80 ret
= atanf(fabsf(vec
.y
/vec
.x
))*180/PI
;
93 ret
= 180; // hacky -_-;;
99 * VEC: SUBV (command) vec1 (variable) vec2 (vector)
102 * Subtracts vec2 from vec1 and stores the result in vec1.
104 * Openc2e-only command.
107 void caosVM::c_VEC_SUBV() {
108 VM_PARAM_VECTOR(vec2
)
109 VM_PARAM_VARIABLE(vec1
)
111 if (!vec1
->hasVector())
112 throw badParamException();
114 vec1
->setVector(vec1
->getVector() - vec2
);
118 * VEC: ADDV (command) vec1 (variable) vec2 (vector)
121 * Adds vec1 to vec2 and stores the result in vec1.
123 * Openc2e-only command.
126 void caosVM::c_VEC_ADDV() {
127 VM_PARAM_VECTOR(vec2
)
128 VM_PARAM_VARIABLE(vec1
)
130 if (!vec1
->hasVector())
131 throw badParamException();
133 vec1
->setVector(vec1
->getVector() + vec2
);
137 * VEC: MULV (command) vec (variable) mag (decimal)
140 * Multiplies the magnitude of the vector vec by mag, and stores the result
143 * Openc2e-only command
146 void caosVM::c_VEC_MULV() {
148 VM_PARAM_VARIABLE(vec
)
150 if (!vec
->hasVector())
151 throw badParamException();
152 vec
->setVector(vec
->getVector().scale(mag
));
156 * VEC: UNIT (vector) angle (decimal)
159 * Constructs and returns a unit vector with angle angle.
161 * Openc2e-only command,
164 void caosVM::v_VEC_UNIT() {
165 VM_PARAM_FLOAT(angle
)
167 result
.setVector(Vector
<float>::unitVector(angle
* PI
/ 180));
174 * Returns the nullary (0,0) vector.
176 * Openc2e-only command
179 void caosVM::v_VEC_NULL() {
180 result
.setVector(Vector
<float>(0,0));
184 * VEC: MAGN (float) vec (vector)
187 * Returns the magnitude of the passed vector.
189 * Openc2e-only command.
191 void caosVM::v_VEC_MAGN() {
194 result
.setFloat(vec
.getMagnitude());
198 * VEC: SETV (command) dest (variable) src (vector)
201 * Sets the variable passed in dest to the vector in src
203 * Openc2e-only command
205 void caosVM::c_VEC_SETV() {
207 VM_PARAM_VARIABLE(dest
)
209 dest
->setVector(src
);