@ ChibiGirl901
Welcome to Processing and I hope you enjoy it. Processing is for everyone from newbies to experienced software developers.
I like it because it supports people being creative and creativity is fun.
@Chrisir
Quote:I am more interested in the question how to put your tube between two defined points x1,y1,z1 and x2,y2,z2.
I just do not know how it's done...
It is not easy because inside the Shapes3D library the tube is represented by a position (x/y/z) and 3 angles of rotation (one per axis). To create a tube given a start and end position requires some serious math. This library uses the apache commons math library and I have used that for the math.
To create a '3D line' first create a Tube object and then call the setTubePosition passing the tube object and PVector(s) for the start and end positions.
The code inside the method looks horrendous because I have also used the PeasyCam library and that also uses the Math library so references to Vector3D and Rotation have to state which classes to use. The code inside this method does not need the PeasyCam to be present to work it is solely dependent on the Shapes3D library.
I am working on the next version of the library and I will include this feature in it. If you have problems with this let me know the version of the library I am using is halfway between the one you have and the next one.
It it works I have another example for James which creates a smooth 3D bezier ciurve.
Code:import shapes3d.utils.*;
import shapes3d.org.apache.commons.math.util.*;
import shapes3d.org.apache.commons.math.*;
import shapes3d.org.apache.commons.math.geometry.*;
import shapes3d.*;
import processing.opengl.*;
import peasy.org.apache.commons.math.*;
import peasy.*;
import peasy.org.apache.commons.math.geometry.*;
// The 3D line
Tube line;
float tubeRad = 2.0f;
PVector start, end;
// End line markers to confirm working
Ellipsoid es, ee;
PeasyCam pcam;
void setup(){
size(300,300,OPENGL);
pcam = new PeasyCam(this,0,0,0,240);
// Create the vectors for the start and end line positions
start = new PVector(-50,-50,60);
end = new PVector(-70,-30,-10);
// Create the tube will be used for the line
line = new Tube(this,1,20);
line.fill(color(0,0,128));
// Set the tube to go from start to end
setTubePosition(line, start, end);
// Green start line marker to confirm it works
es = new Ellipsoid(this,6,6);
es.fill(color(0,128,0));
es.setRadius(tubeRad);
es.moveTo(start);
// Red end line marker to confirm it works
ee = new Ellipsoid(this,6,6);
ee.fill(color(255,0,0));
ee.setRadius(tubeRad);
ee.moveTo(end);
noStroke();
}
// Change the tube attributes so it goes from
// position vector start to position vector end
void setTubePosition(Tube tube, PVector start, PVector end){
double[] angles = new double[]{
0,0,0 };
PVector pos = PVector.add(start, end);
pos.div(2);
tube.moveTo(pos);
float tubeLength = PVector.dist(start, end);
tube.setSize(tubeRad, tubeRad, tubeRad, tubeRad, tubeLength);
//PVector dir = PVector.sub(end, start);
shapes3d.org.apache.commons.math.geometry.Vector3D dir = VecTransform.p2v(PVector.sub(end, pos));
shapes3d.org.apache.commons.math.geometry.Vector3D e =
new shapes3d.org.apache.commons.math.geometry.Vector3D(0,1,0);
shapes3d.org.apache.commons.math.geometry.Rotation rot =
new shapes3d.org.apache.commons.math.geometry.Rotation(e,dir);
try{
angles = rot.getAngles(shapes3d.org.apache.commons.math.geometry.RotationOrder.XYZ);
}
catch(Exception excp){
println("ERROR");
}
tube.rotateToX((float)angles[0]);
tube.rotateToY((float)angles[1]);
tube.rotateToZ((float)angles[2]);
}
void draw(){
background(64);
ambientLight(200,200,200);
directionalLight(120, 120, 120, 0, -1, 0);
line.draw();
es.draw();
ee.draw();
}