//
//  DriveByTouchViewController.m
//  iPhly
//
//  Created by Ari Krupnik on 5/18/10.
//  Copyright 2010 lib.aero. All rights reserved.
//

#import "DriveByTouchViewController.h"


@implementation DriveByTouchViewController

- (void) viewDidLoad {
	[super viewDidLoad];
	
	[self setTitle: @"Now Driving"];
	
	[swipePad addSubview: wheelOutline=[[UIImageView alloc] initWithImage: [UIImage imageNamed:@"SteeringWheelOutline.png"]]];
	[swipePad addSubview: wheel=[[UIImageView alloc] initWithImage: [UIImage imageNamed:@"SteeringWheel.png"]]];
	
	tiltXSink = [processor channelByName: @"aileron"];
	if (!tiltXSink)
		tiltXSink = [processor channelByName: @"steering"];
	tiltYSink = [processor channelByName: @"elevator"];
	swipeXSink = [processor channelByName: @"rudder"];
	swipeYSink = [processor channelByName: @"throttle"];
	
	swipeYSpring = 0.1;
	[self doDisplayThing];
}
- (void) viewDidAppear:(BOOL)animated {
	[super viewDidAppear:animated];
	[[self view] addSubview:[[[TrimmerView alloc] initWithSwipePad:swipePad andChannel: tiltXSink  inQuadrant:Q_TOP] autorelease]];
	//[[self view] addSubview:[[[TrimmerView alloc] initWithSwipePad:swipePad andChannel: tiltYSink  inQuadrant:Q_RIGHT] autorelease]];
	//[[self view] addSubview:[[[TrimmerView alloc] initWithSwipePad:swipePad andChannel: swipeXSink inQuadrant:Q_BOTTOM] autorelease]v];
	[[self view] addSubview:[[[TrimmerView alloc] initWithSwipePad:swipePad andChannel: swipeYSink inQuadrant:Q_LEFT] autorelease]];
}

- (void) doDisplayThing {
	CGAffineTransform rotation = CGAffineTransformMakeRotation(M_PI_2*[tiltXSink value]);
	CGAffineTransform translation = CGAffineTransformMakeTranslation(0, -wheel.bounds.size.width/3*[swipeYSink value]);
	wheel.transform = CGAffineTransformConcat(rotation, translation);
}

- (void) dealloc {
	[wheelOutline release];
	[wheel release];
	
	[super dealloc];
}
@end
