/*
 * HUDScene.m
 *
 * Cocos3D 2.0.2
 * Author: Bill Hollings
 * Copyright (c) 2010-2014 The Brenwill Workshop Ltd. All rights reserved.
 * http://www.brenwill.com
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 * 
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 *
 * http://en.wikipedia.org/wiki/MIT_License
 * 
 * See header file HUDLayer.h for full API documentation.
 */

#import "HUDScene.h"
#import "CC3Camera.h"
#import "CC3Light.h"
#import "CC3UtilityMeshNodes.h"

#define kGlobeName				@"Globe"
#define kBackDropOpacityFactor	0.4


@implementation HUDScene

/** Create the camera and light. Other items are added from the main scene. */
-(void) initializeScene {

	self.backdrop = [CC3Backdrop node];
	
	// Create the camera, place it back a bit, and add it to the scene
	CC3Camera* cam = [CC3Camera nodeWithName: @"Camera"];
	cam.location = cc3v( 0.0, 0.0, 1.0 );
	[self addChild: cam];
	
	// Create a light and attach it to the camera.
	CC3Light* lamp = [CC3Light nodeWithName: @"Lamp"];
	[cam addChild: lamp];
}

/** 
 * Since this scene is drawn as an overlay on top of the main scene, we must clear the depth
 * buffer before drawing, so objects in this scene won't hide behind objects in the main scene.
 */
-(void) drawSceneContentWithVisitor: (CC3NodeDrawingVisitor*) visitor {
	[visitor.renderSurface clearDepthContent];
	[super drawSceneContentWithVisitor: visitor];
}

-(CCOpacity) opacity { return _backdrop.opacity / kBackDropOpacityFactor; }

/** Whatever the opacity of this scene is set to, make the backdrop more transparent. */
-(void) setOpacity: (CCOpacity) opacity {
	super.opacity = opacity;
	_backdrop.opacity = (opacity * kBackDropOpacityFactor);
}

/** Ensure the camera frames the globe. */
-(void) onOpen {
	[self.activeCamera moveToShowAllOf: [self getNodeNamed: kGlobeName] withPadding: -0.1f];
}

@end
