Altering vehicle pitch and yaw

Hi there,

I'm currently working with a simple sky box and 3D model of an aircraft. The aircraft can move forwards, backwards and can rotate round to the left and right. I'm trying to make the aircraft tilt in different ways at the moment, particularly with pitch, so that it can look like its taking off. Does anyone have any ideas which methods could be used for this? Or would it be a case of defining my own?

Thanks

Chloe

You must multiply your current rotation like this:


         private void yaw(float angle) {
      Quaternion qTemp = new Quaternion();
      qTemp.fromAngleAxis(angle, Vector3f.UNIT_X);
      getLocalRotation().multLocal(qTemp);
   }

   private void pitch(float angle) {
      Quaternion qTemp = new Quaternion();
      qTemp.fromAngleAxis(angle, Vector3f.UNIT_Y);
      getLocalRotation().multLocal(qTemp);
   }
   
   private void roll(float angle) {
      Quaternion qTemp = new Quaternion();
                qTemp.fromAngleAxis(angle, Vector3f.UNIT_Z);
      getLocalRotation().multLocal(qTemp);
   }



Moreover, you can get the direction vector of your current object via:


    getLocalRotation().getRotationColumn(2); //Get the Z axis of your object



Good luck ;)

Hi there,

I tried those methods that you suggested, I am currently working with the Flagrush tutorial code from lesson 7, which I have altered, this is the Vehicle class with the new methods:



import com.jme.math.Quaternion;
import com.jme.math.Vector3f;
import com.jme.scene.Node;
import com.jme.scene.Spatial;
public class Vehicle extends Node {
    private static final long serialVersionUID = 1L;
    private Spatial model;
    private float weight;
    private float velocity;
    private float acceleration;
    private float braking;
    private float turnSpeed;
    
    private float maxSpeed = 30;
    private float minSpeed = 10;
    

    private static final Vector3f tempVa = new Vector3f();
        public Vehicle(String id, Spatial model) {
        super(id);
        setModel(model);
    }
    
        public Vehicle(String id, Spatial model, float maxSpeed, float minSpeed,
            float weight, float acceleration, float braking, float turnSpeed) {
        super(id);
        setModel(model);
        this.maxSpeed = maxSpeed;
        this.minSpeed = minSpeed;
        this.weight = weight;
        this.acceleration = acceleration;
        this.braking = braking;
        this.turnSpeed = turnSpeed;
    }
    
  
    public void update(float time) {
        this.localTranslation.addLocal(this.localRotation.getRotationColumn(2, tempVa)
                .multLocal(velocity * time));
    }
    
  
    public void setWeight(float weight) {
        this.weight = weight;
    }
    
  
    public float getWeight() {
        return weight;
    }

    
    public float getAcceleration() {
        return acceleration;
    }

  
    public void setAcceleration(float acceleration) {
        this.acceleration = acceleration;
    }


    public float getBraking() {
        return braking;
    }

  
    public void setBraking(float braking) {
        this.braking = braking;
    }

    
    public Spatial getModel() {
        return model;
    }

  
    public void setModel(Spatial model) {
        this.detachChild(this.model);
        this.model = model;
        this.attachChild(this.model);
    }

    public float getVelocity() {
        return velocity;
    }

    public void setVelocity(float velocity) {
        this.velocity = velocity;
    }
    
  
    public float getTurnSpeed() {
        return turnSpeed;
    }


    public void setTurnSpeed(float turnSpeed) {
        this.turnSpeed = turnSpeed;
    }
    
  
    public float getMaxSpeed() {
        return maxSpeed;
    }


    public void setMaxSpeed(float maxSpeed) {
        this.maxSpeed = maxSpeed;
    }

  
    public float getMinSpeed() {
        return minSpeed;
    }

    
    public void setMinSpeed(float minSpeed) {
        this.minSpeed = minSpeed;
    }
    
    public void brake(float time) {
        velocity -= time * braking;
        if(velocity < -minSpeed) {
            velocity = -minSpeed;
        }
    }
    

    public void accelerate(float time) {
        velocity += time * acceleration;
        if(velocity > maxSpeed) {
            velocity = maxSpeed;
        }
    }
    
  
    public void drift(float time) {
        if(velocity < 0) {
            velocity += ((weight/5) * time);
        } else {
            velocity -= ((weight/5) * time);
        }
    }
    
    public void yaw(float angle) {
      Quaternion qTemp = new Quaternion();
      qTemp.fromAngleAxis(angle, Vector3f.UNIT_X);
      getLocalRotation().multLocal(qTemp);
   
   }

   public void pitch(float angle) {
      Quaternion qTemp = new Quaternion();
      qTemp.fromAngleAxis(angle, Vector3f.UNIT_Y);
      getLocalRotation().multLocal(qTemp);
   }
   
   public void roll(float angle) {
      Quaternion qTemp = new Quaternion();
        qTemp.fromAngleAxis(angle, Vector3f.UNIT_Z);
      getLocalRotation().multLocal(qTemp);
   }
   
   
    

    
}



Then I have the lesson 7 class as well to which I have imported a .3ds model of a plane. I am implementing the methods like this: (pseudo-code)
Vehicle v;
v.pitch(100f);
and then assigning this to an action key.
When I try to implement the methods provided the vehicle does not appear to respond in the way I expect it to, is there something more I should be doing? For example when I use the pitch methods, the plane appears to jump around in a circle, and the yaw and roll methods don't really do anything.

Thanks for your time :)