modelX with peasycam
in
Contributed Library Questions
•
1 year ago
this works very good for getting the screenX position:
- PVector peasyScreenXYZ(float x, float y, float z) {
- pushMatrix();
- translate(x, y, z);
- float[] rota = cam.getRotations();
- rotateX(rota[0]);
- rotateY(rota[1]);
- rotateZ(rota[2]);
- x = screenX(0, 0, 0);
- y = screenY(0, 0, 0);
- z = screenZ(0, 0, 0);
- popMatrix();
- return new PVector(x, y, z);
- }
I try to get it for model as well but i can't get it correct.
Hope someone can help.
- import peasy.*;
- import processing.opengl.*;
- PeasyCam cam;
- void setup() {
- size(400, 400, OPENGL);
- smooth();
- cam = new PeasyCam(this, 400);
- }
- // . . . . . . . . . . . . . . . . . . .
- void draw() {
- background(0);
- lights();
- fill(200);
- noStroke();
- sphere(50);
- pushMatrix();
- rotateX(radians(45));
- rotateY(radians(45));
- translate(50, 0);
- stroke(255, 0, 0);
- line(0, 0, 0, 100, 0, 0);
- PVector sPos = peasyScreenXYZ(100, 0, 0);
- PVector mPos = peasyModelXYZ(100, 0, 0);
- popMatrix();
- pushMatrix();
- translate(mPos.x, mPos.y, mPos.z);
- sphere(10);
- popMatrix();
- cam.beginHUD();
- ellipse(sPos.x, sPos.y, 10, 10);
- cam.endHUD();
- }
- // . . . . . . . . . . . . . . . . . . .
- PVector peasyModelXYZ(float x, float y, float z) {
- pushMatrix();
- translate(x, y, z);
- float[] rota = cam.getRotations();
- rotateX(rota[0]);
- rotateY(rota[1]);
- rotateZ(rota[2]);
- x = modelX(0, 0, 0);
- y = modelY(0, 0, 0);
- z = modelZ(0, 0, 0);
- popMatrix();
- return new PVector(x, y, z);
- }
- // . . . . . . . . . . . . . . . . . . .
- PVector peasyScreenXYZ(float x, float y, float z) {
- pushMatrix();
- translate(x, y, z);
- float[] rota = cam.getRotations();
- rotateX(rota[0]);
- rotateY(rota[1]);
- rotateZ(rota[2]);
- x = screenX(0, 0, 0);
- y = screenY(0, 0, 0);
- z = screenZ(0, 0, 0);
- popMatrix();
- return new PVector(x, y, z);
- }
1