topical media & game development

talk show tell print

graphic-processing-algorithm-Ch09-p237-MyVector.pde / pde



  class MyVector{
    float u,v,w;
  
    MyVector(){
      u=v=w=0.;
    }
    MyVector(float x, float y, float z){
      u = x;
      v = y;
      w = z;
    }
    MyVector buildVector( MyPoint vert1, MyPoint vert2){
      u = vert2.x-vert1.x;
      v = vert2.y-vert1.y;
      w = vert2.z-vert1.z;
      return this;
    }
    float dot(MyVector v1){
      return v1.u*u+v1.v*v+v1.w*w;
    }
    void cross(MyVector v1){
      MyVector temp = new MyVector(0.,0.,0.);
      temp.u = v*v1.w - w*v1.v;
      temp.v = w*v1.v - u*v1.w;
      temp.w = u*v1.u - v*v1.v;
      u = temp.u;
      v = temp.v;
      w = temp.w;
    }
  
    void norm(){
      float t =  sqrt(u*u+v*v+w*w);
      u = u/t;
      v = v/t;
      w = w/t;
    }
    void print(){
      println("u:" + u);
      println("v:" + v);
      println("w:" + w);
    }
  }
  


(C) Æliens 04/09/2009

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.