-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexcercise_1.4_vectorMath_geom.js
More file actions
executable file
·102 lines (83 loc) · 2.92 KB
/
excercise_1.4_vectorMath_geom.js
File metadata and controls
executable file
·102 lines (83 loc) · 2.92 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
"use strict";
// Require the max-api module to connect to Max via node.script
const maxAPI = require("max-api");
var Victor = require("victor");
// var vectorArray= [];
var location = [];
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.
// maxAPIoutlet("textRouteOutput", ...args);
maxAPI.outlet("addVectors", 5);
});
maxAPI.addHandler("locationVelocity", (...args) => {
location = [args[1], args[2]];
maxAPI.outlet(location);
maxAPI.outlet("locationVelocityOutput", ...location);
});
maxAPI.addHandler("addingVectors", (...args) => {
var vector1 = new Victor(args[1], args[2]);
var vector2 = new Victor(args[3], args[4]);
var ret = vector1.add(vector2);
var vectorArray = [ret.x, ret.y];
// maxAPIoutlet(vector1);
maxAPI.outlet("addingVectorsOutput", ...vectorArray);
});
maxAPI.addHandler("subtractVectors", (...args) => {
var vector1 = new Victor(args[1], args[2]);
var vector2 = new Victor(args[3], args[4]);
var ret = vector1.subtract(vector2);
var vectorArray = [ret.x, ret.y];
// maxAPIoutlet(vector1);
maxAPI.outlet("subtracVectorsOutput", ...vectorArray);
});
maxAPI.addHandler("multVectors", (...args) => {
var vector1 = new Victor(args[1], args[2]);
var vector2 = new Victor(args[3], args[4]);
var ret = vector1.multiply(vector2);
var vectorArray = [ret.x, ret.y];
maxAPI.outlet(vector1);
maxAPI.outlet("multVectorsOutput", ...vectorArray);
});
maxAPI.addHandler("divVectors", (...args) => {
var vector1 = new Victor(args[1], args[2]);
var vector2 = new Victor(args[3], args[4]);
var ret = vector1.divide(vector2);
var vectorArray = [ret.x, ret.y];
// maxAPIoutlet(vector1);
maxAPI.outlet(vector1);
maxAPI.outlet("divVectorsOutput", ...vectorArray);
});
maxAPI.addHandler("magVector", (...args) => {
var vector1 = new Victor(args[1], args[2]);
// var vector3 = [args[5], args[6]];
var ret = vector1.magnitude();
maxAPI.outlet(ret);
maxAPI.outlet("magVectorOutput", ret);
});
maxAPI.addHandler("normVector", (...args) => {
var vector1 = new Victor(args[1], args[2]);
var ret = vector1.normalize();
var vectorArray = [ret.x, ret.y];
maxAPI.outlet(...vectorArray);
maxAPI.outlet("normVectorOutput", ...vectorArray);
});
maxAPI.addHandler("headingVector", (...args) => {
var vector1 = new Victor(args[1], args[2]);
// var heading = (heading(vector1,vector2))
// var head = (heading(vector1,vector2)) * 180 / Math.PI
var heading = vector1.verticalAngleDeg();
maxAPI.outlet(heading);
maxAPI.outlet("headingVectorOutput", heading);
});
maxAPI.addHandler("dotVector", (...args) => {
var vector1 = new Victor(args[1], args[2]);
var vector2 = new Victor(args[3], args[4]);
var dots = vector1.dot(vector2);
maxAPI.outlet(dots);
maxAPI.outlet("dotVectorOutput", dots);
});