Converting simple coordinates to vectors.
in
Contributed Library Questions
•
10 months ago
Hello,
I have a little problem, as I want to convert all the coordinates from my script to Vectors.
Now I get an error in a class line:
return pt.x * width / (gridWidth - 1);
Error says: cannot convert from float to Vec3D.
I think it is about GridNode node loop, as it is written using coordinate, not vectors.
I just want to change everything to vectors...
Thank you.
I have a little problem, as I want to convert all the coordinates from my script to Vectors.
Now I get an error in a class line:
return pt.x * width / (gridWidth - 1);
Error says: cannot convert from float to Vec3D.
I think it is about GridNode node loop, as it is written using coordinate, not vectors.
I just want to change everything to vectors...
Thank you.
- import toxi.geom.*;
//import plethora.core.*;
import peasy.*;
PeasyCam cam;
//Ple_Agent bob;
GridNode[][] nodes = new GridNode[600][600];
int gridWidth = 10;
int gridHeight = 10;
void setup() {
size(600, 600, OPENGL);
cam = new PeasyCam(this, 100);
// Vec3D v = new Vec3D();
// bob = new Ple_Agent(this, v);
for (int x = 0; x < gridWidth; x++) {
for (int y = 0; y < gridHeight; y++) {
GridNode node = new GridNode();
node.pt.x = x;
node.pt.y = y;
nodes[x][y] = node;
}
}
}
void draw() {
background(235);
stroke(0);
noFill();
strokeWeight(2);
translate(300, 300, 0);
box(600);
translate(-300, -300, 0);
stroke(255, 0, 0);
strokeWeight(5);
//bob.displayPoint();
update();
drawVectors();
}
void drawVectors() {
for (int x = 0; x < gridWidth; x++) {
for (int y = 0; y < gridHeight; y++) {
GridNode node = nodes[x][y];
line(node.getPixelX().x, node.getPixelY().y, node.getDifferentialPixelX(), node.getDifferentialPixelY());
}
}
}
void update() {
for (int x = 0; x < gridWidth; x++) {
for (int y = 0; y < gridHeight; y++) {
GridNode node = nodes[x][y];
node.dx = mouseX - node.getPixelX().x;
node.dy = mouseY - node.getPixelY().y;
node.dx *=-0.1;
node.dy *=-0.1;
}
}
}
- class GridNode {
Vec3D pt = new Vec3D();
double dx, dy;
Vec3D getPixelX() {
return pt.x * width / (gridWidth - 1);
}
Vec3D getPixelY() {
return pt.y * height / (gridHeight - 1);
}
int getDifferentialPixelX() {
return (int) (getPixelX() + dx);
}
int getDifferentialPixelY() {
return (int) (getPixelY() + dy);
}
}
1