Implements an interface of a library

hello. im trying to create a path tube with shape3D library, but i have a problem to implements a I_PathGen interface… is the first time that i “implements” a interface and i dont know how exactly make it works.

import shapes3d.*;
import shapes3d.animation.*;
import shapes3d.utils.*;

I_PathGen[] pathh;
PathTube path;
Points points;


Tube tube;
PeasyCam cam;

void setup() {
 
  size(600, 600, P3D);

  pathh = new I_PathGen[20];


  pathh[0] = new Points();
  pathh[0].x(1000);
  pathh[0].y(100);
  pathh[0].z(100);

  path = new PathTube(this, pathh[0], 5, 300, 10, false);
  path.fill(color(0, 255, 0), S3D.E_CAP);
}

void draw() {

  background(0);


  path.draw();
}

class Points implements I_PathGen {


}

the reference of I_PathGen

thanks a lot…

Hello,

When you implement an interface, you need to define some functions listed in the interface.

In that case, you need to define the 3 following functions in your class :

  • public float x(float t);
  • public float y(float t);
  • public float z(float t);

For more explanations :

some like this ?

maybe need also some information about this library…

import shapes3d.*;
import shapes3d.animation.*;
import shapes3d.utils.*;

I_PathGen[] pathh;
PathTube path;
Points points;


Tube tube;
PeasyCam cam;

void setup() {
 
  size(600, 600, P3D);

  pathh = new I_PathGen[20];


  pathh[0] = new Points(0, 0,0);
  pathh[0].x(1000);
  pathh[0].y(100);
  pathh[0].z(100);

  path = new PathTube(this, pathh[0], 5, 300, 10, false);
  path.fill(color(0, 255, 0), S3D.E_CAP);
}

void draw() {

  background(0);


  path.draw();
}

class Points implements I_PathGen {

float xx, yy, zz;

Points (float _x, float _y, float _z){
xx = _x;
yy = _y;
zz = _z;
}

public float x(float t){
return t;
}
public float y(float t){
return t;
}
public float z(float t){
return t;
}

}

Yep, looks good to me.

thanks. but still dont understand. i just wanna connect two points with a tube… but i dont find any example. this is ok?

class Points implements I_PathGen {

float xx, yy, zz;

Points (float _x, float _y, float _z){
xx = _x;
yy = _y;
zz = _z;
}

public float x(float t){
t = xx;
return t;
}
public float y(float t){
t = yy;
return t;
}
public float z(float t){
t = zz;
return t;
}

}

cos i expected to set a point but this dont display anything

I don’t know the library so I can’t be 100% sure but I don’t think that you need to set all the points manually.

The 3 functions x, y, and z are the equations that defines the shape of your path.

So when you write :

public float x(float t){
return t;
}
public float y(float t){
return t;
}
public float z(float t){
return t;
}

You are actually building a straight path that follows :
x(t) = t
y(t) = t
z(t) = t

I’m afraid I can’t really help more than that

Parameters die along its function, so it’s useless to re-assign them! :neutral_face:

I believe you were meant to assign the x()'s t parameter to the Points::xx field instead: xx = t; :thinking:

@Override float x(final float t) {
  return xx = t;
}
import shapes3d.*;
import shapes3d.animation.*;
import shapes3d.utils.*;

I_PathGen[] pathh;
PathTube path;
Points points;


Tube tube;


void setup() {
 
  size(600, 600, P3D);

  pathh = new I_PathGen[20];


  pathh[0] = new Points(2, 500, 6);

  path = new PathTube(this, pathh[0], 50, 300, 10, false);
  path.fill(color(0, 255, 0), S3D.E_CAP);
}

void draw() {

  background(0);

  translate(width/2, height/2);
  path.draw();
}

class Points implements I_PathGen {

float xx, yy, zz;

Points (float _x, float _y, float _z){
xx = _x;
yy = _y;
zz = _z;
}

@Override float x(final float t) {
  return xx = t;
}

@Override float y(final float t) {
  return yy = t;
}
@Override float z(final float t) {
  return zz = t;
}

}

try this and this is the result… dont know, im so lost…

Did you check the documentation?

Lib page: http://www.lagers.org.uk/s3d4p/index.html

Doc: http://www.lagers.org.uk/s3d4p/ref/classshapes3d_1_1_path_tube.html

What do you want to do?

Kf

I want to connect two points with a tube. first in a rect line, later, generate a spline or bezier curve