package me.drton.jmavsim;

import me.drton.jmavsim.vehicle.AbstractVehicle;

import javax.vecmath.Matrix3d;
import javax.vecmath.Vector3d;
import java.util.List;

/**
 * User: ton Date: 21.03.14 Time: 23:22
 */
public class CameraGimbal2D extends KinematicObject {
    private DynamicObject baseObject;
    private int pitchChannel = -1;
    private double pitchScale = 1.0;

    public CameraGimbal2D(World world) {
        super(world);
    }

    public void setBaseObject(DynamicObject object) {
        this.baseObject = object;
    }

    public void setPitchChannel(int pitchChannel) {
        this.pitchChannel = pitchChannel;
    }

    public void setPitchScale(double pitchScale) {
        this.pitchScale = pitchScale;
    }

    @Override
    public void update(long t) {
        this.position = baseObject.position;
        this.velocity = baseObject.velocity;
        this.acceleration = baseObject.acceleration;
        double yaw = Math.atan2(baseObject.rotation.getElement(1, 0), baseObject.rotation.getElement(0, 0));
        this.rotation.rotZ(yaw);
        if (pitchChannel >= 0 && baseObject instanceof AbstractVehicle) {
            // Control camera pitch
            List<Double> control = ((AbstractVehicle) baseObject).getControl();
            if (control.size() > pitchChannel) {
                Matrix3d r = new Matrix3d();
                r.rotY(control.get(4) * pitchScale);
                this.rotation.mul(r);
            }
        }
    }
}

@@ -367,16 +367,86 @@
 e = 1.0;
+%0A    private int rollChannel = -1;%0A    private double rollScale = 1.0;
 %0A%0A    pu
@@ -797,24 +797,197 @@
 ale;%0A    %7D%0A%0A
+    public void setRollChannel(int channel) %7B%0A        this.rollChannel = channel;%0A    %7D%0A%0A    public void setRollScale(double scale) %7B%0A        this.rollScale = scale;%0A    %7D%0A%0A
     @Overrid
@@ -1317,16 +1317,17 @@
      if 
+(
 (pitchCh
@@ -1336,16 +1336,37 @@
 nel %3E= 0
+ %7C%7C rollChannel %3E= 0)
  && base
@@ -1437,16 +1437,21 @@
 ra pitch
+/roll
 %0A       
@@ -1535,20 +1535,82 @@
         
-if (
+Matrix3d r = new Matrix3d();%0A            if (pitchChannel %3E= 0 && 
 control.
@@ -1623,34 +1623,32 @@
  %3E pitchChannel)
- %7B
 %0A               
@@ -1652,36 +1652,121 @@
     
-Matrix3d r = new Matrix3d();
+r.rotY(control.get(pitchChannel) * pitchScale);%0A            if (rollChannel %3E= 0 && control.size() %3E rollChannel)
 %0A   
@@ -1775,33 +1775,33 @@
            r.rot
-Y
+X
 (control.get(4) 
@@ -1801,18 +1801,27 @@
 get(
-4) * pitch
+rollChannel) * roll
 Scal
@@ -1832,28 +1832,24 @@
             
-   
- 
 this.rotatio
@@ -1862,22 +1862,8 @@
 r);%0A
-            %7D%0A
     

Add roll control option to CameraGimbal2D.