//=============================================================================
// FILE: app.h
//
//                  Copyright (c) 2017 QUALCOMM Technologies Inc.
//                              All Rights Reserved.
//
//=============================================================================

#pragma once

#include "../../common/spatialaudio_common.h"
#include <glm/glm.hpp>


class Soundfield : public SpatialAudioCommon
{
public:
	virtual void Initialize();
	virtual void Shutdown();

	enum { kRotationOptionA, kRotationOptionB, kRotationOptionC, kRotationOptionD, kRotationOptionsNum };
	enum { kRotationOptionStartIndex = kGazeBoxReverbNum + kGazeBoxMiscNum };
	enum { kGazeBoxSoundfieldNum = kRotationOptionStartIndex + kRotationOptionsNum };

protected:
	virtual void OnTouchScreen();
	virtual void RenderModelCallback(int whichEye, float elapsedTime);
	virtual void RenderCallback(float elapsedTime);

private:
	#define						SPATIAL_AUDIO_SOUND_FIELD_NUM 2
	float						mSoundFieldRotationSpeedRadiansPerSecond;
	glm::vec3					mSoundFieldRotationAxis;
	float						mSoundFieldCurrentRotationAboutAxis;
	Q3DSound					mSoundField[SPATIAL_AUDIO_SOUND_FIELD_NUM];

	Svr::SvrGeometry*           mpFocalSoundModel;///<used to visualize the "focal sound" of the soundfield
	Svr::SvrShader              mFocalSoundShader;
	GLuint						mFocalSoundTexture;
	glm::vec3                   mFocalSoundModelLocalOffset[SPATIAL_AUDIO_SOUND_FIELD_NUM];
	glm::vec3                   mFocalSoundModelColor[SPATIAL_AUDIO_SOUND_FIELD_NUM];

	Q3DSoundCrossFader			mCrossfader;
	int							mSoundLastPlayedIndex;

	Svr::SvrGeometry*           mpGazeBoxModel;
	Svr::SvrShader              mGazeBoxShader;
	
	GLuint						mGazeBoxTexture[kGazeBoxSoundfieldNum];
    GLuint                      mGazeBoxTextureSampler;
	bool						mGazeBoxActive[kGazeBoxSoundfieldNum];
	float						mGazeBoxLastHsvSaturation[kGazeBoxSoundfieldNum];
	float						mGazeBoxLastHsvValue[kGazeBoxSoundfieldNum];

	Svr::SvrGeometry*           mpSkyModel;
	Svr::SvrShader              mSkyShader;

	Svr::SvrGeometry*           mpFloorModel;
	Svr::SvrShader              mFloorShader;


	void SetLoopingAndUpdateUi(const bool looping);
	glm::mat4 GetSoundfieldOrientation();
	bool SetRotationBehavior(const int configFileSettingIndex);
};