Package com.ngt.jopenmetaverse.shared.types

Examples of com.ngt.jopenmetaverse.shared.types.Quaternion$AxisAngle


        {
            float[] mat = new float[16];

            // Transpose the quaternion (don't ask me why)
//            q = new Quaternion(q.W, q.X, q.Y, q.Z);
            q = new Quaternion(q);
            q.X = q.X * -1f;
            q.Y = q.Y * -1f;
            q.Z = q.Z * -1f;

            float x2 = q.X + q.X;
View Full Code Here


        {
            float[] mat = new float[16];

            // Transpose the quaternion (don't ask me why)
//            q = new Quaternion(q.W, q.X, q.Y, q.Z);
            q = new Quaternion(q);
            q.X = q.X * -1f;
            q.Y = q.Y * -1f;
            q.Z = q.Z * -1f;

            float x2 = q.X + q.X;
View Full Code Here

  /// </summary>
  public void Initialize()
  {
    InterpolatedPosition = new Vector3(getBasePrim().Position);
    RenderPosition =   new Vector3(getBasePrim().Position);
    InterpolatedRotation = new Quaternion(getBasePrim().Rotation);
    RenderRotation = new Quaternion(getBasePrim().Rotation);
    Initialized = true;
  }
View Full Code Here

    // Don't interpolate when parent changes (sit/stand link/unlink)
    if (previousParent != getBasePrim().ParentID)
    {
      previousParent = getBasePrim().ParentID;
      InterpolatedPosition = new Vector3(getBasePrim().Position);
      InterpolatedRotation = new Quaternion(getBasePrim().Rotation);
      return;
    }

    // Linear velocity and acceleration
    if (!getBasePrim().Velocity.equals(Vector3.Zero))
    {
      getBasePrim().Position =  Vector3.multiply(getBasePrim().Velocity,  time
          * 0.98f * dilation).add( getBasePrim().Position);
      InterpolatedPosition = new Vector3(getBasePrim().Position);
      getBasePrim().Velocity = Vector3.multiply(getBasePrim().Acceleration, time).add(getBasePrim().Velocity);
    }
    else if (!InterpolatedPosition.equals(getBasePrim().Position))
    {
      InterpolatedPosition = RHelp.Smoothed1stOrder(InterpolatedPosition, getBasePrim().Position, time);
    }

    // Angular velocity (target omega)
    if (!(getBasePrim().AngularVelocity.equals(Vector3.Zero)))
    {
      Vector3 angVel = getBasePrim().AngularVelocity;
      float angle = time * angVel.length();
      Quaternion dQ = Quaternion.createFromAxisAngle(angVel, angle);
      InterpolatedRotation = Quaternion.multiply(dQ, InterpolatedRotation);
    }
    else if (!(InterpolatedRotation.equals(getBasePrim().Rotation)) && !(this instanceof RenderAvatar))
    {
      InterpolatedRotation = Quaternion.slerp(InterpolatedRotation, getBasePrim().Rotation, time * 10f);
      if (1f - Math.abs(Quaternion.dot(InterpolatedRotation, getBasePrim().Rotation)) < 0.0001)
        InterpolatedRotation = new Quaternion(getBasePrim().Rotation);
    }
    else
    {
      InterpolatedRotation = new Quaternion(getBasePrim().Rotation);
    }
  }
View Full Code Here

              Manual = true;
              Vector3 direction = Vector3.subtract(getPosition(), getFocalPoint());
              if (horizontal)
              {
//                  Position = FocalPoint + direction * new Quaternion(0f, 0f, (float)Math.Sin(delta), (float)Math.Cos(delta));
                  setPosition(Vector3.add(getFocalPoint(),Vector3.multiply(direction, new Quaternion(0f, 0f, (float)Math.sin(delta), (float)Math.cos(delta)))));
              }
              else
              {
//                  Position = FocalPoint + direction * Quaternion.CreateFromAxisAngle(direction % Vector3.UnitZ, delta);
                setPosition(Vector3.add(getFocalPoint(),Vector3.multiply(direction, Quaternion.createFromAxisAngle(Vector3.modulus(direction, Vector3.UnitZ), delta))));
View Full Code Here

    if (getBasePrim().ParentID == 0)
    {
      // We are the root prim, return our interpolated position
      RenderPosition = new Vector3(InterpolatedPosition);
      RenderRotation = new Quaternion(InterpolatedRotation);
      return;
    }
    else
    {
      RenderPosition = new Vector3(RHelp.InvalidPosition);
      RenderRotation = new Quaternion(Quaternion.Identity);

      // Not root, find our parent
      SceneObject p = getParentSceneObject();
      if (p == null)
      {
        System.out.println("Parent Primitive is null...");
        return;
      }

      // If we don't know parent position, recursively find out
      if (!p.PositionCalculated)
      {
        p.calPrimPosAndRot(cameraRenderPosition);
        p.DistanceSquared = Vector3.distanceSquared(cameraRenderPosition, p.RenderPosition);
        p.PositionCalculated = true;
      }

      Vector3 parentPos = new Vector3(p.RenderPosition);
      Quaternion parentRot = new Quaternion(p.RenderRotation);

      if (p instanceof RenderPrimitive)
      {
        // Child prim (our parent is another prim here)
        RenderPosition = Vector3.add(parentPos, Vector3.multiply(InterpolatedPosition, parentRot));
        RenderRotation = Quaternion.multiply(parentRot, InterpolatedRotation);
      }
      else if (p instanceof RenderAvatar)
      {
        //TODO only for debug
        RenderPosition = new Vector3(p.RenderPosition);
        RenderRotation = new Quaternion(p.RenderRotation);
        //TODO implement
        //                // Calculating position and rotation of the root prim of an attachment here
        //                // (our parent is an avatar here)
        //                RenderAvatar parentav = (RenderAvatar)p;
        //
View Full Code Here

      RenderPrimitive r = renderPrimitives.get(0);
      translateX = -1* r.getBasePrim().Position.X;
      translateY = -1* r.getBasePrim().Position.Y;
      translateZ = -1* r.getBasePrim().Position.Z;
      r.RenderPosition = new Vector3(r.getBasePrim().Position);
      r.RenderRotation = new Quaternion(0, 0, 0, 1);
      System.out.println(String.format("Pos %s Rot %s", r.RenderPosition.toString(),
          r.RenderRotation.toString()));
    }
   
    System.out.println("Setup Finished...");
View Full Code Here

        return vector;
    }

    public  Quaternion asQuaternion()
    {
        Quaternion quaternion = Quaternion.Identity;

        if (this.count()== 4)
        {
            quaternion.X = (float)this.get(0).asReal();
            quaternion.Y = (float)this.get(1).asReal();
View Full Code Here

        return vec;
    }

    static Quaternion ReadQuaternion(Node root)
    {
        Quaternion quat = new Quaternion();

       
        NodeList nodeList = root.getChildNodes();   
      for(int i = 0; i < nodeList.getLength(); i++)
      {
View Full Code Here

          pos += 12;
          // Acceleration
          objectupdate.Acceleration = new Vector3(block.ObjectData, pos);
          pos += 12;
          // Rotation (theta)
          objectupdate.Rotation = new Quaternion(block.ObjectData, pos, true);
          pos += 12;
          // Angular velocity (omega)
          objectupdate.AngularVelocity = new Vector3(block.ObjectData, pos);
          pos += 12;

          break;
        case 48:
          // Collision normal for avatar
          objectupdate.CollisionPlane = new Vector4(block.ObjectData, pos);
          pos += 16;
         
          //Keep on decoding
          i = 32;
          search = true;
          break;
        case 32:
          // The data is an array of unsigned shorts
          //TODO need to handle Little Endian Data
          // Position
          objectupdate.Position = new Vector3(
              Utils.UInt16ToFloat(block.ObjectData, pos, -0.5f * 256.0f, 1.5f * 256.0f),
              Utils.UInt16ToFloat(block.ObjectData, pos + 2, -0.5f * 256.0f, 1.5f * 256.0f),
              Utils.UInt16ToFloat(block.ObjectData, pos + 4, -256.0f, 3.0f * 256.0f));
          pos += 6;
          // Velocity
          objectupdate.Velocity = new Vector3(
              Utils.UInt16ToFloat(block.ObjectData, pos, -256.0f, 256.0f),
              Utils.UInt16ToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f),
              Utils.UInt16ToFloat(block.ObjectData, pos + 4, -256.0f, 256.0f));
          pos += 6;
          // Acceleration
          objectupdate.Acceleration = new Vector3(
              Utils.UInt16ToFloat(block.ObjectData, pos, -256.0f, 256.0f),
              Utils.UInt16ToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f),
              Utils.UInt16ToFloat(block.ObjectData, pos + 4, -256.0f, 256.0f));
          pos += 6;
          // Rotation (theta)
          objectupdate.Rotation = new Quaternion(
              Utils.UInt16ToFloat(block.ObjectData, pos, -1.0f, 1.0f),
              Utils.UInt16ToFloat(block.ObjectData, pos + 2, -1.0f, 1.0f),
              Utils.UInt16ToFloat(block.ObjectData, pos + 4, -1.0f, 1.0f),
              Utils.UInt16ToFloat(block.ObjectData, pos + 6, -1.0f, 1.0f));
          pos += 8;
          // Angular velocity (omega)
          objectupdate.AngularVelocity = new Vector3(
              Utils.UInt16ToFloat(block.ObjectData, pos, -256.0f, 256.0f),
              Utils.UInt16ToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f),
              Utils.UInt16ToFloat(block.ObjectData, pos + 4, -256.0f, 256.0f));
          pos += 6;

          break;
        case 16:
          // The data is an array of single bytes (8-bit numbers)
          //TODO need to handle Little Endian Data
          // Position
          objectupdate.Position = new Vector3(
              Utils.byteToFloat(block.ObjectData, pos, -256.0f, 256.0f),
              Utils.byteToFloat(block.ObjectData, pos + 1, -256.0f, 256.0f),
              Utils.byteToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f));
          pos += 3;
          // Velocity
          objectupdate.Velocity = new Vector3(
              Utils.byteToFloat(block.ObjectData, pos, -256.0f, 256.0f),
              Utils.byteToFloat(block.ObjectData, pos + 1, -256.0f, 256.0f),
              Utils.byteToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f));
          pos += 3;
          // Accleration
          objectupdate.Acceleration = new Vector3(
              Utils.byteToFloat(block.ObjectData, pos, -256.0f, 256.0f),
              Utils.byteToFloat(block.ObjectData, pos + 1, -256.0f, 256.0f),
              Utils.byteToFloat(block.ObjectData, pos + 2, -256.0f, 256.0f));
          pos += 3;
          // Rotation
          objectupdate.Rotation = new Quaternion(
              Utils.byteToFloat(block.ObjectData, pos, -1.0f, 1.0f),
              Utils.byteToFloat(block.ObjectData, pos + 1, -1.0f, 1.0f),
              Utils.byteToFloat(block.ObjectData, pos + 2, -1.0f, 1.0f),
              Utils.byteToFloat(block.ObjectData, pos + 3, -1.0f, 1.0f));
          pos += 4;
View Full Code Here

TOP

Related Classes of com.ngt.jopenmetaverse.shared.types.Quaternion$AxisAngle

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.