Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Spline {
- private ArrayList<Node> nodes = new ArrayList<Node>();
- private int precisionSteps = 15;
- private float node_step;
- private double totalLenght= 0;
- public Spline(Node node) {
- nodes.add(node);
- calculate();
- }
- public void add(Node n) {
- nodes.add(n);
- calculate();
- }
- public void addNode(Node n ) {
- nodes.add(n);
- calculate();
- }
- public void addNode(Node n , int i ) {
- nodes.add(i , n);
- calculate();
- }
- public Node getNode(int i) {
- return nodes.get(i);
- }
- public void removeNode(int i) {
- nodes.remove(i);
- calculate();
- }
- // na nowo oblicza calego spline
- // dlugosc , oraz skok
- public void calculate() {
- totalLenght = 0;
- for (Node n : nodes) {
- n.reCalculate();
- totalLenght += n.getLength();
- }
- // node_step = (float) 1/(nodes.size()-1);
- // double s;
- // totalLenght = 0;
- // Vector last ;
- // Vector v ;
- // for (int n = 0 ; n < nodes.size()-1 ; n++) {
- // s = 0;
- // last = nodes.get(n).position;
- // float jump = (float) 1/precisionSteps;
- // for (int j = 0 ; j <= precisionSteps ; j++) {
- //
- // v = calculate(n , jump*j );
- // System.out.println("zasieg : " + last.distance(v));
- //
- // s += last.distance(v);
- // last = v;
- //
- // }
- // nodes.get(n).lenght = s;
- // totalLenght += s;
- // }
- // System.out.println("nodestep:" + node_step);
- // System.out.println("totalLenght:" + totalLenght);
- // int i = 0;
- // for (Node an : nodes) {
- // System.out.println("node " +i +" totalLenght " + an.lenght);
- // i++;
- // }
- }
- // od zero do 1 wylicza przebieg po krzywej
- // 0 to punkt position 0 node z listy
- // 1 dla ostatniego node wektor end
- public Vector calculate(float range) {
- if (range < 0 || range > 1)
- return null;
- int n = getNodeIndex(range);
- return calculate(n, restFromNode(n, range));
- }
- //rnge od 0-1 to sao co powyrzej ale dla jednego wezla i tylko dla niego
- public Vector calculate(int nodeIndex , float range) {
- return nodes.get(nodeIndex).calculate(range);
- }
- public float restFromNode(int node , float f) {
- float x = f-(node*node_step);
- return x / node_step;
- }
- public int getNodeIndex(float f) {
- int i = ((int) (f/(node_step)));
- if (i == nodes.size()-1)
- return i-1;
- return i;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement