Package com.jme3.math

Examples of com.jme3.math.Quaternion


      else if (velocityInputTime < 0)
        targetSpeed -= 0.5f;

      // Velocity
      Vector3f currentVelocity = new Vector3f(vehicleControl.getLinearVelocity());
      Quaternion currentRotation = new Quaternion(vehicleControl.getPhysicsRotation());

      Vector3f targetVelocity = currentRotation.mult(new Vector3f(0f, 0f, targetSpeed));

      float xDiff = currentVelocity.x - targetVelocity.x;
      float zDiff = currentVelocity.z - targetVelocity.z;
      Vector3f diffVector = new Vector3f(xDiff, 0f, zDiff);

      // diffVector nach z drehen
      diffVector = currentRotation.inverse().mult(diffVector);

      float zThrust = 0f, yThrust, xThrust = 0f;
      float engine = .1f, thrust = .1f;

      if (diffVector.z < 0) { // accelerate
        zThrust = (-diffVector.z > engine) ? engine : -diffVector.z;
      } else if (diffVector.z > 0) { // brake
        zThrust = (diffVector.z > engine) ? -engine : -diffVector.z;
      }

      if (diffVector.x < 0) { // accelerate
        xThrust = (-diffVector.x > engine) ? engine : -diffVector.x;
      } else if (diffVector.x > 0) { // brake
        xThrust = (diffVector.x > engine) ? -engine : -diffVector.x;
      }

      Vector3f hemisphereVector = new Vector3f(0f, 0f, 1f);
      hemisphereVector = currentRotation.multLocal(hemisphereVector);

      xThrust = (hemisphereVector.x > 0) ? xThrust : xThrust;
      zThrust = (hemisphereVector.z > 0) ? zThrust : zThrust;

      Vector3f impulse = new Vector3f(xThrust, 0f, zThrust);

      vehicleControl.applyImpulse(currentRotation.mult(impulse), Vector3f.ZERO);

      // // Velocity

      // System.out.println(vehicleControl.getPhysicsRotation().mult(v));
      // System.out.println("tar: " + targetVelocity);
View Full Code Here


    Spatial character = app.getAssetManager().loadModel("character/" + id + "/Mesh.mesh.xml");
    character.setLocalTranslation(0f, 0f, 5f);
    Material mat_character = new Material(app.getAssetManager(), "Common/MatDefs/Light/Lighting.j3md");
    mat_character.setTexture("DiffuseMap", app.getAssetManager().loadTexture("character/male/male.png"));
    character.setMaterial(mat_character);
    Quaternion rotate = new Quaternion();
    rotate.fromAngleAxis(-FastMath.PI / 2, new Vector3f(1, 0, 0));
    character.setLocalRotation(rotate);
    characterNode.attachChild(character);
    app.getRootNode().attachChild(characterNode);

    System.out.println(cam.getDirection());
View Full Code Here

      if(KeyState.containsKey("Up") && KeyState.get("Up"))
        CurrentRotation.x--;
      if(KeyState.containsKey("Down") && KeyState.get("Down"))
        CurrentRotation.x++;

      Quaternion q = new Quaternion();//Quaternion.DIRECTION_Z;
      q.fromAngles(Rotation.x, Rotation.y, Rotation.z);
     
     
      q.mult(CurrentMovement, CurrentMovement);
     
      Position.addLocal(CurrentMovement.multLocal(MovementSpeed * tpf));
      Rotation.addLocal(CurrentRotation.multLocal(RotationSpeed * tpf));
     
      Camera.setLocation(Position);
      Camera.lookAt(q.mult(View).addLocal(Position), q.mult(Up));
     
      CurrentMovement.set(0,0,0);
      CurrentRotation.set(0,0,0);
    }
View Full Code Here

  {

  @Override
  public AIResult Execute(AbstractControlledObject<?, ?> obj, AIContext ctx, float gameTime)
    {
    Quaternion rotation = obj.dataObject.getRotation();
    if(rotation == null)
      rotation = new Quaternion();
   
    //TODO: use angular velocity
    float rot = 0.01f * gameTime;
    obj.dataObject.setRotation(rotation.mult(new Quaternion(rot, rot, rot, 1)));

    return AIResult.Success;
    }
View Full Code Here

   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setRotation(Quaternion newRotation) {
    Quaternion oldRotation = rotation;
    rotation = newRotation;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BasePackage.ABSTRACT_NAMED_ENTITY__ROTATION, oldRotation, rotation));
  }
View Full Code Here

   * <!-- begin-user-doc -->
   * <!-- end-user-doc -->
   * @generated
   */
  public void setAngularVelocity(Quaternion newAngularVelocity) {
    Quaternion oldAngularVelocity = angularVelocity;
    angularVelocity = newAngularVelocity;
    if (eNotificationRequired())
      eNotify(new ENotificationImpl(this, Notification.SET, BasePackage.ABSTRACT_NAMED_ENTITY__ANGULAR_VELOCITY, oldAngularVelocity, angularVelocity));
  }
View Full Code Here

        guiNode.setCullHint(CullHint.Never);
        viewPort.attachScene(rootNode);
        guiViewPort.attachScene(guiNode);
        createAxis();
       
        cam.setRotation(new Quaternion(0,1,0,0));

        if (inputManager != null) {
            flyCam = new FlyByCamera(cam);
            flyCam.registerWithInput(inputManager);
View Full Code Here

            if (name.equals("SIMPLEAPP_Exit")) {
                stop();
            } else if (name.equals("SIMPLEAPP_CameraPos")) {
                if (cam != null) {
                    Vector3f loc = cam.getLocation();
                    Quaternion rot = cam.getRotation();
                    System.out.println("Camera Position: ("
                            + loc.x + ", " + loc.y + ", " + loc.z + ")");
                    System.out.println("Camera Rotation: " + rot);
                    System.out.println("Camera Direction: " + cam.getDirection());
                }
            } else if (name.equals("SIMPLEAPP_Memory")) {
                BufferUtils.printCurrentDirectMemory(null);
            }
           
            else if (name.equals("SIMPLEAPP_ResetPos")) {
                cam.setRotation(new Quaternion(0,1,0,0));
                cam.setLocation(new Vector3f(3, 3, 3));
                cam.lookAt(new Vector3f(0,0,0), new Vector3f(0,0,1));
            }
        }
View Full Code Here

  }

  public void rotateEpsilon(float epsilon) {

    Quaternion quat = new Quaternion();
    // seems silly to make this over and over.
    quat.fromAngleAxis(epsilon, Vector3f.UNIT_Y);
    quat.mult(viewDirection, viewDirection);
    player.setViewDirection(viewDirection);
  }
View Full Code Here

     * applies the current transform to the given jme Node if the location has been updated on the physics side
     * @param spatial
     */
    public boolean applyTransform(Spatial spatial) {
        Vector3f localLocation = spatial.getLocalTranslation();
        Quaternion localRotationQuat = spatial.getLocalRotation();
        boolean physicsLocationDirty = applyTransform(motionStateId, localLocation, localRotationQuat);
        if (!physicsLocationDirty) {
            return false;
        }
        if (!applyPhysicsLocal && spatial.getParent() != null) {
View Full Code Here

TOP

Related Classes of com.jme3.math.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.