-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcercise_1.4_vectorMath.js
More file actions
executable file
·114 lines (94 loc) · 3.19 KB
/
excercise_1.4_vectorMath.js
File metadata and controls
executable file
·114 lines (94 loc) · 3.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
"use strict";
// Require the max-api module to connect to Max via node.script
const maxAPI = require("max-api");
var add = require("vectors/add")(2);
var sub = require("vectors/sub")(2);
var mult = require("vectors/mult")(2);
var div = require("vectors/div")(2);
var mag = require("vectors/mag")(2);
var dot = require("vectors/dot")(2);
var norm = require("vectors/normalize")(2);
var heading = require("vectors/heading")(2);
var location = [];
var speed = [];
// When nodescript gets the symbol "text", the remainder will be passed to this function.
// The "..." is the spread operator. All of the arguments to this function will go into args as an array.
maxAPI.addHandler("text1", (...args) => {
// The outlet function sends the arguments right back to Max. Hence, echo.
maxAPI.outlet(...args);
});
maxAPI.addHandler("textRoute", (...args) => {
add(location, speed);
// The outlet function sends the arguments right back to Max. Hence, echo.
// maxAPI.outlet("textRouteOutput", ...args);
maxAPI.outlet("addVectors", 5);
});
maxAPI.addHandler("locationVelocity", (...args) => {
location = [args[1], args[2]];
speed = [args[3], args[4]];
add(location, speed);
maxAPI.outlet(location);
maxAPI.outlet("locationVelocityOutput", ...location);
});
maxAPI.addHandler("addingVectors", (...args) => {
var vector1 = [args[1], args[2]];
var vector2 = [args[3], args[4]];
var vector3 = [args[5], args[6]];
add(vector1, vector2);
add(vector1, vector3);
maxAPI.outlet(vector1);
maxAPI.outlet("addingVectorsOutput", ...vector1);
});
maxAPI.addHandler("subtractVectors", (...args) => {
var vector1 = [args[1], args[2]];
var vector2 = [args[3], args[4]];
// var vector3 = [args[5], args[6]];
sub(vector1, vector2);
// sub(vector1,vector3)
maxAPI.outlet(vector1);
maxAPI.outlet("subtractVectorsOutput", ...vector1);
});
maxAPI.addHandler("multVectors", (...args) => {
var vector1 = [args[1], args[2]];
var vector2 = [args[3], args[4]];
// var vector3 = [args[5], args[6]];
mult(vector1, vector2);
maxAPI.outlet(vector1);
maxAPI.outlet("multVectorsOutput", ...vector1);
});
maxAPI.addHandler("divVectors", (...args) => {
var vector1 = [args[1], args[2]];
var vector2 = [args[3], args[4]];
// var vector3 = [args[5], args[6]];
div(vector1, vector2);
maxAPI.outlet(vector1);
maxAPI.outlet("divVectorsOutput", ...vector1);
});
maxAPI.addHandler("magVector", (...args) => {
var vector1 = [args[1], args[2]];
// var vector3 = [args[5], args[6]];
mag(vector1);
maxAPI.outlet(vector1);
maxAPI.outlet("magVectorOutput", vector1[1]);
});
maxAPI.addHandler("normVector", (...args) => {
var vector1 = [args[1], args[2]];
// var vector3 = [args[5], args[6]];
norm(vector1);
maxAPI.outlet(vector1);
maxAPI.outlet("normVectorOutput", vector1[1]);
});
maxAPI.addHandler("headingVector", (...args) => {
var vector1 = [args[1], args[2]];
var vector2 = [args[3], args[4]];
var head = (heading(vector1, vector2)) * 180 / Math.PI;
maxAPI.outlet(head);
maxAPI.outlet("headingVectorOutput", head);
});
maxAPI.addHandler("dotVector", (...args) => {
var vector1 = [args[1], args[2]];
var vector2 = [args[3], args[4]];
var dots = dot(vector1, vector2);
maxAPI.outlet(dots);
maxAPI.outlet("dotVectorOutput", dot(vector1, vector2));
});