Package com.thecrouchmode.vector

Examples of com.thecrouchmode.vector.Vector3f


    List<Vector3f> flatNormals = new ArrayList<>();
   
   
    //from row two and no. points rows forward
    List<Vector3f> vertices = new ArrayList<>();
    Vector3f min = null;
    Vector3f max = null;
    for(int row = 2; row < points+2; row++){
      String[] line = lines.get(row).split("\\s+");
      normalLists.add(new ArrayList<Vector3f>());
      Vector3f vertex = new Vector3f(
          Float.parseFloat(line[0]),
          Float.parseFloat(line[1]),
          Float.parseFloat(line[2]));
      vertices.add(vertex);
      if(min == null) min = vertex;
      if(max == null) max = vertex;
     
      if(vertex.x > max.x) max = new Vector3f(vertex.x, max.y, max.z);
      if(vertex.y > max.y) max = new Vector3f(max.x, vertex.y, max.z);
      if(vertex.z > max.z) max = new Vector3f(max.x, max.y, vertex.z);
     
      if(vertex.x < min.x) min = new Vector3f(vertex.x, min.y, min.z);
      if(vertex.y < min.y) min = new Vector3f(min.x, vertex.y, min.z);
      if(vertex.z < min.z) min = new Vector3f(min.x, min.y, vertex.z);
    }
   
    Vector3f lengths = max.subtract(min);
    float maxLength = Math.max(Math.max(lengths.x, lengths.y), lengths.z);
    Vector3f midPoint = Vector3f.sum(max, min).scale(-0.5);
   
    normalization = Matrix4f.product(
        Matrix4f.scale(1.0/maxLength),
        Matrix4f.translation(midPoint));
   
    List<Integer> indices = new ArrayList<>();
   
    //indices start at row 2+points, every row's a face
    for(int row = 2+points; row < faces+points+2; row++){
      String[] line = lines.get(row).split("\\s+");
     
      //calculate the normal
      Vector3f v1 = vertices.get(Integer.parseInt(line[1]));
      Vector3f v2 = vertices.get(Integer.parseInt(line[2]));
      Vector3f v3 = vertices.get(Integer.parseInt(line[3]));
     
      Vector3f normal = Vector3f.cross(
          v2.subtract(v1).unit(),
          v3.subtract(v1).unit()).unit();
     
      //System.out.println("Normal: "+normal);
     
      if(smooth) for(int i = 0; i < Integer.parseInt(line[0]); i++){
        normalLists.get(Integer.parseInt(line[i+1])).add(normal);
      }
       
      //triangulate and add indices to index list.
      for(int i = 0; i < Integer.parseInt(line[0])-2; i++){
        indices.add(Integer.parseInt(line[1]));
        indices.add(Integer.parseInt(line[i+2]));
        indices.add(Integer.parseInt(line[i+3]));
        if(!smooth){
          flatNormals.add(normal);
          flatNormals.add(normal);
          flatNormals.add(normal);
        }
      }
    }
   
    //create buffer of indices here TODO
   
   
    float[] dataBuffer;
    int[] indexBuffer;
   
    if(smooth){
      dataBuffer = new float[vertices.size()*elements];
      indexBuffer = new int[indices.size()];
     
      for(int i = 0; i < indices.size(); i++){
        indexBuffer[i] = indices.get(i);
      }
     
      for(int i = 0; i < vertices.size(); i++){
       
        Vector3f vertex = vertices.get(i);
        dataBuffer[i*elements] = vertex.x;
        dataBuffer[i*elements+1] = vertex.y;
        dataBuffer[i*elements+2] = vertex.z;
       
        Vector3f normal = new Vector3f(0, 0, 0);
        for(Vector3f normalTerm : normalLists.get(i)){
          normal = normal.add(normalTerm);
        }
        normal = normal.scale(1.0/normalLists.get(i).size());
        //normal = new Vector3f(1, 0, 0);
       
        dataBuffer[i*elements+3] = normal.x;
        dataBuffer[i*elements+4] = normal.y;
        dataBuffer[i*elements+5] = normal.z;
       
        dataBuffer[i*elements+6] = vertex.x;
        dataBuffer[i*elements+7] = vertex.y;
      }
    }
    else{
      dataBuffer = new float[indices.size()*elements];
      indexBuffer = new int[indices.size()];
     
     
      for(int i = 0; i < indices.size(); i++){
        indexBuffer[i] = i;
       
        //Positions
        Vector3f vertex = vertices.get(indices.get(i));
        dataBuffer[i*elements] = vertex.x;
        dataBuffer[i*elements+1] = vertex.y;
        dataBuffer[i*elements+2] = vertex.z;
       
        //Normals
        Vector3f normal = flatNormals.get(i);
        dataBuffer[i*elements+3] = normal.x;
        dataBuffer[i*elements+4] = normal.y;
        dataBuffer[i*elements+5] = normal.z;
       
        //UVs
View Full Code Here


   
    System.out.println();
    System.out.println(Vector3f.sum(new ArrayList<Vector3f>()));
    System.out.println();
   
    Vector3f pos = new Vector3f(4, 3, 3);
   
    Vector3f target = new Vector3f(0,0,0);
   
    Vector3f up = new Vector3f(0,1,0);

    Matrix4f view = Matrix4f.lookAt(pos, target, up);
    Matrix4f projection = Matrix4f.perspective((float)Math.PI/2, 1, 1, 100);
    Matrix4f model = Matrix4f.translation(42, 23, 0);
    Matrix4f model2 = Matrix4f.translation(42, 41, 314);
   
   
    Matrix4f MVP_manual = view.multiply(projection.multiply(model.multiply(model2)));
    Matrix4f MVP_loop = Matrix4f.product(view, projection, model, model2);
   
    System.out.println(MVP_manual);
    System.out.println(MVP_loop);
   
    System.out.println();
   
    System.out.println(Matrix4f.sum(Matrix4f.identity, new Matrix4f(
        4, 0, 0, 1,
        0, 0, 2, 0,
        0, 3, 0, 0,
        4, 0, 0, 1)));
   
    System.out.println();
   
    Quaternion p = new Quaternion(1, 2, 3, 4);
    Quaternion q = new Quaternion(3, 5, 6, 4);
   
    System.out.println(p.conjugate().conjugate());
    System.out.println(p.multiply(q));
    System.out.println(q.multiply(p));
    System.out.println(p.multiply(q).conjugate());
    System.out.println(q.conjugate().multiply(p.conjugate()));

    Quaternion r = p.normalize();
 
    System.out.println(1-2*r.j*r.j-2*r.k*r.k);
    System.out.println(r.r*r.r+r.i*r.i-r.j*r.j-r.k*r.k);
   
    System.out.println(1-2*r.i*r.i-2*r.k*r.k);
    System.out.println(r.r*r.r-r.i*r.i+r.j*r.j-r.k*r.k);
   
    System.out.println(1-2*r.i*r.i-2*r.j*r.j);
    System.out.println(r.r*r.r-r.i*r.i-r.j*r.j+r.k*r.k);
   
    System.out.println();
    Vector3f axis = new Vector3f(43, 4, 4);
    System.out.println(axis);
    Matrix4f rotation = new Quaternion(2, axis).rotationMatrix();
    //System.out.println(Matrix4f.identity.multiply(axis));
   
    System.out.println();
   
    System.out.println(new Quaternion(4, new Vector3f(0,1,3).unit()).rotationMatrix());
    System.out.println(new Quaternion(4, new Vector3f(0,1,3)).rotationMatrix());
   
    System.out.println();
   
    System.out.println(new Quaternion(4, new Vector3f(0,3,0)).rotationMatrix());
    System.out.println(new Quaternion(4, new Vector3f(0,3,0)).rotationMatrix());
 
 
    System.out.println();
   
    Vector4f a4 = new Vector4f(43, 1, 5, 6);
View Full Code Here

TOP

Related Classes of com.thecrouchmode.vector.Vector3f

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.