Package com.thecrouchmode.vector

Examples of com.thecrouchmode.vector.Quaternion


   
    Matrix4f scale = Matrix4f.scale(1);
    Matrix4f translation = Matrix4f.translation(0,0,0);
    Matrix4f rotation = Matrix4f.identity;
    //Matrix4f model = translation.multiply(scale);
    Quaternion zrotation = new Quaternion(-Math.PI/360, new Vector3f(0,1,2));
    Quaternion rotQ = zrotation;
   
    float ztrans = 0;
    float xtrans = 0;
   
    Vector3f camForw = Vector3f.zUnit;
    Vector3f camSide = Vector3f.xUnit.scale(-1);
   
    double value = 0;
   
    time = System.currentTimeMillis();
    int fpsMod = 0;
   
    Light light = Light.builder()
        .intensity(255/1, 255/2, 255/3)
        .pos(1, 1, 1).build();
    shader.setUniform("lightPos", light.pos.xyz());
    shader.setUniform("lightIntensity", light.intensity);
   
    Matrix4f view = Matrix4f.view(
        new Vector3f(0, 0, -5),
        camForw,
        Vector3f.cross(camSide, camForw));
   
    float camX = 0;
    float camZ = 0;
   
    Vector3f trans = new Vector3f(1, 0.5, -4);
   
    while(true){
      try{
        if(Display.isCloseRequested()){
          Display.destroy();
          Keyboard.destroy();
          //cleanup
          break;
        }
        else{
         
          Keyboard.poll();
          //Mouse.poll();
          //System.out.println("Mouse: " +Mouse.getDX());

          //view = Matrix4f.product(Matrix4f.rotation(Mouse.getDX()/(1000*Math.PI), Vector3f.yUnit), view);
          //view = Matrix4f.product(Matrix4f.rotation(-Mouse.getDY()/(1000*Math.PI), Vector3f.xUnit), view);
         
         

         
          while(Keyboard.next()){
            int keyNo = Keyboard.getEventKey();
            char character = Keyboard.getEventCharacter();
            boolean down = Keyboard.getEventKeyState();
           
            //System.out.print("Key " + keyNo + "(" + character +") ");
           
            float moveSpeed = 0.1f;
            if(keyNo == 17 && down){
              xtrans += moveSpeed;
            }
            if(keyNo == 30 && down){
              ztrans -= moveSpeed;
            }
            if(keyNo == 31 && down){
              xtrans -= moveSpeed;
            }
            if(keyNo == 32 && down){
              ztrans += moveSpeed;
            }
           
            if(keyNo == 17 && !down){
              xtrans -= moveSpeed;
            }
            if(keyNo == 30 && !down){
              ztrans += moveSpeed;
            }
            if(keyNo == 31 && !down){
              xtrans += moveSpeed;
            }
            if(keyNo == 32 && !down){
              ztrans -= moveSpeed;
            }
          }
         
          trans = Vector3f.sum(
              trans,
              camForw.xz().unit().scale(xtrans),
              camSide.xz().unit().scale(ztrans));
         
//          Matrix4f camRot = Quaternion.product(
//                  new Quaternion(Mouse.getDY()/(600*Math.PI), camSide),
//                  new Quaternion(-Mouse.getDX()/(600*Math.PI), Vector3f.yUnit)).normalize().rotationMatrix();
         
          Matrix4f camRot = Quaternion.product(
              new Quaternion(-Mouse.getDX()/(600*Math.PI), Vector3f.yUnit),
              new Quaternion(Mouse.getDY()/(600*Math.PI), camSide)).normalize().rotationMatrix();
         
          view = Matrix4f.product();
          camForw = camRot.multiply(camForw, 1).xyz();
          camSide = camRot.multiply(camSide, 1).xyz();
         
          view = Matrix4f.view(
              trans,
              camForw,
              Vector3f.cross(camSide, camForw));
         
          value = value+0.01
         
          Renderer.clear();


//          light.pos = new Vector4f(
//              1+3*(float)Math.sin(-2*value),
//              1+1*(float)Math.cos(-2*value),
//              1f,//,
//              1.0f);
         
          light.pos = new Vector4f(trans, 1.0f);

         
          shader.use();
         
          shader.setUniform("lightPos", light.pos.xyz());
          shader.setUniform("lightInt", light.intensity);
          shader.setUniform("flip", 0);
         
          //rotQ = rotQ.multiply(zrotation);//.normalize();
          rotation = rotQ.rotationMatrix();
         
          translation = Matrix4f.translation(0, 0, 0);
          Matrix4f m = Matrix4f.product(translation, rotation, scale, dragon.normalization);
          Matrix4f vp = Matrix4f.product(projection, view);
          shader.setUniform("M", m);
View Full Code Here


        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.Quaternion

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.