/*
QtWagon: a project about 3D objects.
Science and technology promotion license applied. Third party license automatically cascaded.
Zhikai Wang/ www.heteroclinic.net 2013
You can do anything with this file or any file(s) published as part QtWagon project, given this header is kept.
*/
/****************************************************************************
**
** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies).
** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the examples of the Qt Toolkit.
**
** $QT_BEGIN_LICENSE:LGPL$
** Commercial Usage
** Licensees holding valid Qt Commercial licenses may use this file in
** accordance with the Qt Commercial License Agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Nokia.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Nokia gives you certain additional
** rights.  These rights are described in the Nokia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
** GNU General Public License Usage
** Alternatively, this file may be used under the terms of the GNU
** General Public License version 3.0 as published by the Free Software
** Foundation and appearing in the file LICENSE.GPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU General Public License version 3.0 requirements will be
** met: http://www.gnu.org/copyleft/gpl.html.
**
** If you have questions regarding the use of this file, please contact
** Nokia at qt-info@nokia.com.
** $QT_END_LICENSE$
**
****************************************************************************/

#include <QtGui>
#include <QtOpenGL>

#include <math.h>

#include "glwidget.h"
#include "qtCameraSingleton.h"

#ifndef GL_MULTISAMPLE
#define GL_MULTISAMPLE  0x809D
#endif

void pointMinusPoint (Point  * v, Point * w, Vector * result)
{
	result->x = v->x - w->x;
	result->y = v->y - w->y;
	result->z = v->z - w->z;
}
void drawRectangleWithNormal2 (Point * pt0,Point * pt1,
	Point * pt2,Point * pt3){
		Vector v[3];
		//glCullFace(GL_BACK);
		
		pointMinusPoint (pt0, pt2, &v[0]);
		pointMinusPoint (pt1, pt3, &v[1]);
		crossVector (&v[0], &v[1], &v[2]);
	

	Vector v4 ;
		v4.x = -v[2].x;
		v4.y = -v[2].y;
		v4.z = -v[2].z;
				glBegin(GL_POLYGON);
	
				//glCullFace(GL_BACK);
		glNormal3fv((myfloat *)&v4);
				//glNormal3fv((myfloat *)&v[2]);
				glVertex3fv((myfloat *)pt0);
		glVertex3fv((myfloat *)pt1);
		glVertex3fv((myfloat *)pt2);
		glVertex3fv((myfloat *)pt3);



		//glVertex3fv((myfloat *)pt0);
		//glVertex3fv((myfloat *)pt1);
		//glVertex3fv((myfloat *)pt2);
		//glVertex3fv((myfloat *)pt3);
		glEnd();



}

void drawRectangleWithNormal (Point * pt0,Point * pt1,
	Point * pt2,Point * pt3){
		Vector v[3];
		//glCullFace(GL_BACK);
		
		pointMinusPoint (pt0, pt2, &v[0]);
		pointMinusPoint (pt1, pt3, &v[1]);
		crossVector (&v[0], &v[1], &v[2]);
		//glBegin(GL_POLYGON);
		//crossVector (&v[1], &v[0], &v[2]);
		//glNormal3fv((myfloat *)&v[2]);
		//std::cout<<v[2].x <<" "<<v[2].y <<" "<<v[2].z <<" "<<std::endl;
		//glVertex3fv((myfloat *)pt0);
		//glVertex3fv((myfloat *)pt1);
		//glVertex3fv((myfloat *)pt2);
		//glVertex3fv((myfloat *)pt3);
		//glEnd();


	Vector v4 ;
		v4.x = -v[2].x;
		v4.y = -v[2].y;
		v4.z = -v[2].z;
				glBegin(GL_POLYGON);
	
				//glCullFace(GL_BACK);
		glNormal3fv((myfloat *)&v[2]);
				//glNormal3fv((myfloat *)&v[2]);
				glVertex3fv((myfloat *)pt0);
		glVertex3fv((myfloat *)pt1);
		glVertex3fv((myfloat *)pt2);
		glVertex3fv((myfloat *)pt3);



		//glVertex3fv((myfloat *)pt0);
		//glVertex3fv((myfloat *)pt1);
		//glVertex3fv((myfloat *)pt2);
		//glVertex3fv((myfloat *)pt3);
		glEnd();


	//					glBegin(GL_POLYGON);
	////glNormal3fv((myfloat *)&v[4]);
	//			//glCullFace(GL_FRONT);
	//	//glNormal3fv((myfloat *)&v4);
	//			//glNormal3fv((myfloat *)&v[2]);
	//			glVertex3fv((myfloat *)pt0);
	//	glVertex3fv((myfloat *)pt1);
	//	glVertex3fv((myfloat *)pt2);
	//	glVertex3fv((myfloat *)pt3);



	//	//glVertex3fv((myfloat *)pt0);
	//	//glVertex3fv((myfloat *)pt1);
	//	//glVertex3fv((myfloat *)pt2);
	//	//glVertex3fv((myfloat *)pt3);
	//	glEnd();

}

GLdouble crossVector (Vector  * v, Vector * w, Vector * crossVector)
{
	GLdouble cosinTheta, sinTheta, crossVectorLength;
	// dot production v->w
	float lv = Length((*v));
	float lw = Length((*w));
	v->x = v->x/lv;
	v->y = v->y/lv;
	v->z = v->z/lv;

	w->x = w->x/lw;
	w->y = w->y/lw;
	w->z = w->z/lw;


	GLdouble vw = v->x*w->x + v->y*w->y + v->z*w->z;

	cosinTheta = vw / (Length((*v))*Length((*w)));
	sinTheta = sqrt(1-cosinTheta*cosinTheta);
	crossVectorLength = Length((*v))*Length((*w))*sinTheta;

	// Normalize it
	crossVector->x = (v->y*w->z - v->z*w->y) / crossVectorLength;
	crossVector->y = (v->z*w->x - v->x*w->z) / crossVectorLength;
	crossVector->z = (v->x*w->y - v->y*w->x) / crossVectorLength;

	return crossVectorLength;
}

void drawCuboid (myfloat h1,myfloat h2,
	myfloat l1,myfloat l2,
	myfloat w1,myfloat w2){
		Point p[8];
		p[0].x = l2,p[0].y = h1,p[0].z = -w1;
		p[1].x = l2,p[1].y = h1,p[1].z = w1;
		p[2].x = -l1,p[2].y = h1,p[2].z = w2;
		p[3].x = -l1,p[3].y = h1,p[3].z = -w2;
		p[0+4].x = l2,p[0+4].y = -h2,p[0+4].z = -w1;
		p[1+4].x = l2,p[1+4].y = -h2,p[1+4].z = w1;
		p[2+4].x = -l1,p[2+4].y = -h2,p[2+4].z = w2;
		p[3+4].x = -l1,p[3+4].y = -h2,p[3+4].z = -w2;
		drawRectangleWithNormal (&p[3],&p[2],&p[1],&p[0]);
		drawRectangleWithNormal (&p[2],&p[3],&p[7],&p[6]);
		drawRectangleWithNormal (&p[0],&p[1],&p[5],&p[4]);
		drawRectangleWithNormal (&p[0],&p[4],&p[7],&p[3]);
		drawRectangleWithNormal (&p[2],&p[6],&p[5],&p[1]);
		drawRectangleWithNormal (&p[4],&p[5],&p[6],&p[7]);
}
void GLWidget::slotLight3dMoveOrders(int op,float oprand) {
	//camera * current_camera = NULL;qtLightSingleton
	camera * current_camera = qtLightSingleton::getInstance ()->getCurrentCamera ();
	std::cout<<op<<"slotLight3dMoveOrders(int op,float oprand)" <<oprand<<std::endl;
	//qtLightSingletongetInstance ()->

	if (NULL != current_camera)  {
		camera * currentCamera= current_camera;
		//		std::cout<<"NULL != current_camera"<<std::endl;
		//std::cout<<op<<" "<<oprand<<std::endl;
		//zoom,
		//cfb,
		//swirlud,// up/down
		//swirlrl // right/left
		float ftmp = 0.0f;
		mathPoint<GLfloat> focus,oldpos,newpos;
		switch (op) {

		case enum3dops::global_positionx://this signal is from qtmovingobj
			focus =  currentCamera->getLookedAt();
			oldpos =  currentCamera->getPosition();
			//std::cout<<"Lookat: "<<tmpt<<std::endl;
			newpos = mathPoint<GLfloat>(oprand,oldpos.gety(),oldpos.getz()) ;
			ftmp = (newpos-focus).norm();
			if (ftmp >=  currentCamera->safe_lookat_radius) {
				currentCamera->setPosition(newpos);
				currentCamera->orthorganalizeToWorld();
				currentCamera->setLookedAt ( focus);
			}

			break;
		case enum3dops::global_positiony:
				focus =  currentCamera->getLookedAt();
			oldpos =  currentCamera->getPosition();
			//std::cout<<"Lookat: "<<tmpt<<std::endl;
			newpos = mathPoint<GLfloat>(oldpos.getx(),oprand,oldpos.getz()) ;
			ftmp = (newpos-focus).norm();
			if (ftmp >=  currentCamera->safe_lookat_radius) {
				currentCamera->setPosition(newpos);
				currentCamera->orthorganalizeToWorld();
				currentCamera->setLookedAt ( focus);
			}
			break;
		case enum3dops::global_positionz:
				focus =  currentCamera->getLookedAt();
			oldpos =  currentCamera->getPosition();
			//std::cout<<"Lookat: "<<tmpt<<std::endl;
			newpos = mathPoint<GLfloat>(oldpos.getx(),oldpos.gety(),oprand) ;
			ftmp = (newpos-focus).norm();
			if (ftmp >=  currentCamera->safe_lookat_radius) {
				currentCamera->setPosition(newpos);
				currentCamera->orthorganalizeToWorld();
				currentCamera->setLookedAt ( focus);
			}
			break;
		//case enum3dops::focus_x:
		//	????
		//	break;
		//case enum3dops::focus_y:
		//	????
		//	break;
		//case enum3dops::focus_z:
		//	????
		//	break;

		case enum3dops::wfb :
			//ingl_mvopt->forward(oprand);
			current_camera->forward(oprand);
			break;
		case enum3dops::yaw:
			//ingl_mvopt->yaw(oprand);
			current_camera->yaw(oprand);
			break;
		case enum3dops::roll:
			//ingl_mvopt->roll(oprand);
			current_camera->roll(oprand);
			break;

		case enum3dops::pitch:
			//ingl_mvopt->pitch(oprand);
			current_camera->pitch(oprand);
			break;


		case enum3dops::zoom :
			//mvopt->forward(oprand);
			if (oprand > 0)
				current_camera->zoomIn();
			else
				current_camera->zoomOut();

			break;
		case enum3dops::cfb:
			//mvopt->yaw(oprand);
			//increase_lookat_radius()
			//decrease_lookat_radius()
			if (oprand > 0)
				current_camera->decrease_lookat_radius();
			else
				current_camera->increase_lookat_radius();

			break;
		case enum3dops::swirlud:
			//mvopt->roll(oprand);
			{
				mathVector<float> tmpv;


				//mathVector<float> tmpv = cross<float >(current_camera->getFrontVectorRef(),
				//	mathVector<GLfloat>(0,1,0));
				//std::cout<<"current_camera->getFrontVectorRef(): "<<current_camera->getFrontVectorRef()<<std::endl;
				//std::cout<<"tmpv.norm() "<<tmpv.norm()<<std::endl;
				////glOrientation<float> tmpo =  current_camera->getLastorientation();
				////tmpv.normalize ( );
				////if ( isAlmost( tmpv.norm ( ),0.1f)  ) {
				//if (  tmpv.norm ( )< 0.01f  ) {
				//	std::cout<<"1    "<<isAlmost( tmpv.norm ( )) <<tmpv<<std::endl;
				//	tmpv = cross<float >(current_camera->getLastorientation().getFrontVectorRef(),
				//		mathVector<GLfloat>(0,1,0));
				//	//tmpv.normalize ( );
				//	if (  tmpv.norm ( )< 0.01f  ) {
				//		std::cout<<"2    "<<isAlmost( tmpv.norm ( )) <<tmpv<<std::endl;
				//		//std::cout<<"if ( isAlmost( tmpv.norm ( ))  )"<<std::endl;
				//		tmpv = current_camera->getLeftVectorRef();
				//		//tmpv.normalize ( );
				//	}
				//}
				//std::cout<<current_camera->default_deta_swirl<<"    "<<tmpv<<std::endl;
				tmpv = current_camera->getSwirludvector();		
				//std::cout<<"tmpv "<<tmpv<<std::endl;
				//drawVector<float>(tmpv,	 3.0);
				tmpv.normalize ( );
				//current_camera->initSwirlVectors();
				//std::cout<<*current_camera<<std::endl;

				////swirl(myfloat angles,mathVector<myfloat> tmpY )
				if (oprand > 0)
					current_camera->swirl( current_camera->default_deta_swirl,tmpv );
				else
					current_camera->swirl(  -1.0 *     current_camera->default_deta_swirl,tmpv );
				break;

			}

		case enum3dops::swirlrl:
			//mvopt->pitch(oprand);
			//mvopt->roll(oprand); 
			{
				mathVector<GLfloat> tmpv = mathVector<GLfloat>(0,1,0);
				mathVector<float> r;
				//swirl(myfloat angles,mathVector<myfloat> tmpY )
				if (oprand > 0) {
					current_camera->swirl(current_camera->default_deta_swirl,tmpv );
					mathVector<float> w = current_camera->getSwirludvector();
					w.normalize ( );
					r = glOrientation<float>::rotateAboutAVector( tmpv  ,w ,current_camera->default_deta_swirl);

				}
				else {
					current_camera->swirl(  -1.0 *     current_camera->default_deta_swirl,tmpv );
					mathVector<float> w = current_camera->getSwirludvector();
					w.normalize ( );
					r = glOrientation<float>::rotateAboutAVector ( tmpv  ,w ,-1.0 *     current_camera->default_deta_swirl);
				}
				//current_camera->initSwirlVectors();
				//mathVector<T> rotateAboutAVector (const mathVector<T> & v, const mathVector<T> & w, T theta)
				//mathVector<float> r
				current_camera->setSwirlVectors(r);
				//std::cout<<"r: "<<r<<std::endl;

				break;
			}


		default:
			// you should never get here, but in case
			break;
		}
		emit
			//sigMVOUpdateWagonValueOnly();
			//sigCAMUpdateWagonValueOnly();
			sigLightUpdateWagonValueOnly();
		updateGL();
	}
}

void GLWidget::slotCAM3dMoveOrders(int op,float oprand) {
	//camera * current_camera = NULL;
	camera * current_camera = qtCameraSingleton::getInstance ()->getCurrentCamera ();
	std::cout<<op<<"slotCAM3dMoveOrders(int op,float oprand)" <<oprand<<std::endl;

	if (NULL != current_camera)  {
		camera * currentCamera= current_camera;
		//		std::cout<<"NULL != current_camera"<<std::endl;
		//std::cout<<op<<" "<<oprand<<std::endl;
		//zoom,
		//cfb,
		//swirlud,// up/down
		//swirlrl // right/left
		float ftmp = 0.0f;
		mathPoint<GLfloat> focus,oldpos,newpos;
		switch (op) {

		case enum3dops::global_positionx://this signal is from qtmovingobj
			focus =  currentCamera->getLookedAt();
			oldpos =  currentCamera->getPosition();
			//std::cout<<"Lookat: "<<tmpt<<std::endl;
			newpos = mathPoint<GLfloat>(oprand,oldpos.gety(),oldpos.getz()) ;
			ftmp = (newpos-focus).norm();
			if (ftmp >=  currentCamera->safe_lookat_radius) {
				currentCamera->setPosition(newpos);
				currentCamera->orthorganalizeToWorld();
				currentCamera->setLookedAt ( focus);
			}

			break;
		case enum3dops::global_positiony:
				focus =  currentCamera->getLookedAt();
			oldpos =  currentCamera->getPosition();
			//std::cout<<"Lookat: "<<tmpt<<std::endl;
			newpos = mathPoint<GLfloat>(oldpos.getx(),oprand,oldpos.getz()) ;
			ftmp = (newpos-focus).norm();
			if (ftmp >=  currentCamera->safe_lookat_radius) {
				currentCamera->setPosition(newpos);
				currentCamera->orthorganalizeToWorld();
				currentCamera->setLookedAt ( focus);
			}
			break;
		case enum3dops::global_positionz:
				focus =  currentCamera->getLookedAt();
			oldpos =  currentCamera->getPosition();
			//std::cout<<"Lookat: "<<tmpt<<std::endl;
			newpos = mathPoint<GLfloat>(oldpos.getx(),oldpos.gety(),oprand) ;
			ftmp = (newpos-focus).norm();
			if (ftmp >=  currentCamera->safe_lookat_radius) {
				currentCamera->setPosition(newpos);
				currentCamera->orthorganalizeToWorld();
				currentCamera->setLookedAt ( focus);
			}
			break;
		//case enum3dops::focus_x:
		//	????
		//	break;
		//case enum3dops::focus_y:
		//	????
		//	break;
		//case enum3dops::focus_z:
		//	????
		//	break;

		case enum3dops::wfb :
			//ingl_mvopt->forward(oprand);
			current_camera->forward(oprand);
			break;
		case enum3dops::yaw:
			//ingl_mvopt->yaw(oprand);
			current_camera->yaw(oprand);
			break;
		case enum3dops::roll:
			//ingl_mvopt->roll(oprand);
			current_camera->roll(oprand);
			break;

		case enum3dops::pitch:
			//ingl_mvopt->pitch(oprand);
			current_camera->pitch(oprand);
			break;


		case enum3dops::zoom :
			//mvopt->forward(oprand);
			if (oprand > 0)
				current_camera->zoomIn();
			else
				current_camera->zoomOut();

			break;
		case enum3dops::cfb:
			//mvopt->yaw(oprand);
			//increase_lookat_radius()
			//decrease_lookat_radius()
			if (oprand > 0)
				current_camera->decrease_lookat_radius();
			else
				current_camera->increase_lookat_radius();

			break;
		case enum3dops::swirlud:
			//mvopt->roll(oprand);
			{
				mathVector<float> tmpv;


				//mathVector<float> tmpv = cross<float >(current_camera->getFrontVectorRef(),
				//	mathVector<GLfloat>(0,1,0));
				//std::cout<<"current_camera->getFrontVectorRef(): "<<current_camera->getFrontVectorRef()<<std::endl;
				//std::cout<<"tmpv.norm() "<<tmpv.norm()<<std::endl;
				////glOrientation<float> tmpo =  current_camera->getLastorientation();
				////tmpv.normalize ( );
				////if ( isAlmost( tmpv.norm ( ),0.1f)  ) {
				//if (  tmpv.norm ( )< 0.01f  ) {
				//	std::cout<<"1    "<<isAlmost( tmpv.norm ( )) <<tmpv<<std::endl;
				//	tmpv = cross<float >(current_camera->getLastorientation().getFrontVectorRef(),
				//		mathVector<GLfloat>(0,1,0));
				//	//tmpv.normalize ( );
				//	if (  tmpv.norm ( )< 0.01f  ) {
				//		std::cout<<"2    "<<isAlmost( tmpv.norm ( )) <<tmpv<<std::endl;
				//		//std::cout<<"if ( isAlmost( tmpv.norm ( ))  )"<<std::endl;
				//		tmpv = current_camera->getLeftVectorRef();
				//		//tmpv.normalize ( );
				//	}
				//}
				//std::cout<<current_camera->default_deta_swirl<<"    "<<tmpv<<std::endl;
				tmpv = current_camera->getSwirludvector();		
				//std::cout<<"tmpv "<<tmpv<<std::endl;
				//drawVector<float>(tmpv,	 3.0);
				tmpv.normalize ( );
				//current_camera->initSwirlVectors();
				//std::cout<<*current_camera<<std::endl;

				////swirl(myfloat angles,mathVector<myfloat> tmpY )
				if (oprand > 0)
					current_camera->swirl( current_camera->default_deta_swirl,tmpv );
				else
					current_camera->swirl(  -1.0 *     current_camera->default_deta_swirl,tmpv );
				break;

			}

		case enum3dops::swirlrl:
			//mvopt->pitch(oprand);
			//mvopt->roll(oprand); 
			{
				mathVector<GLfloat> tmpv = mathVector<GLfloat>(0,1,0);
				mathVector<float> r;
				//swirl(myfloat angles,mathVector<myfloat> tmpY )
				if (oprand > 0) {
					current_camera->swirl(current_camera->default_deta_swirl,tmpv );
					mathVector<float> w = current_camera->getSwirludvector();
					w.normalize ( );
					r = glOrientation<float>::rotateAboutAVector( tmpv  ,w ,current_camera->default_deta_swirl);

				}
				else {
					current_camera->swirl(  -1.0 *     current_camera->default_deta_swirl,tmpv );
					mathVector<float> w = current_camera->getSwirludvector();
					w.normalize ( );
					r = glOrientation<float>::rotateAboutAVector ( tmpv  ,w ,-1.0 *     current_camera->default_deta_swirl);
				}
				//current_camera->initSwirlVectors();
				//mathVector<T> rotateAboutAVector (const mathVector<T> & v, const mathVector<T> & w, T theta)
				//mathVector<float> r
				current_camera->setSwirlVectors(r);
				//std::cout<<"r: "<<r<<std::endl;

				break;
			}


		default:
			// you should never get here, but in case
			break;
		}
		emit
			//sigMVOUpdateWagonValueOnly();
			sigCAMUpdateWagonValueOnly();
		updateGL();
	}
}

void GLWidget::slotQtMovobj3DOrders(int op,float oprand) {
	//std::cout<<"GLWidget::slotMOV3dMoveOrders(int op,float oprand)"<<std::endl;

	glMovingObjectf * ingl_mvopt = qtmovingobjectSingleton::getInstance ()->getMovingObjPt();
	//std::cout<<op<<"  "<<oprand;  

	if (NULL !=  ingl_mvopt)  {
		mathPoint<GLfloat> oldpos,newpos;
		switch (op) {


		case enum3dops::global_positionx://this signal is from qtmovingobj
			oldpos =  ingl_mvopt->getPosition();
			//std::cout<<"Lookat: "<<tmpt<<std::endl;
			newpos = mathPoint<GLfloat>(oprand,oldpos.gety(),oldpos.getz()) ;
			ingl_mvopt->setPosition(newpos);

			break;
		case enum3dops::global_positiony:
			oldpos =  ingl_mvopt->getPosition();
			
			newpos = mathPoint<GLfloat>(oldpos.getx(),oprand,oldpos.getz()) ;
			ingl_mvopt->setPosition(newpos);
			break;
		case enum3dops::global_positionz:
			oldpos =  ingl_mvopt->getPosition();
			newpos = mathPoint<GLfloat>(oldpos.getx(),oldpos.gety(),oprand) ;
			ingl_mvopt->setPosition(newpos);
			break;
		case enum3dops::wfb :
			ingl_mvopt->forward(oprand);
			break;
		case enum3dops::yaw:
			ingl_mvopt->yaw(oprand);
			break;
		case enum3dops::roll:
			ingl_mvopt->roll(oprand);
			break;

		case enum3dops::pitch:
			ingl_mvopt->pitch(oprand);
			break;
		default:
			// you should never get here, but in case
			break;
		}
		//connect(this,SIGNAL( sigQtMovobjSetControl()), qtmvopt,SLOT( slotUpdateControlsValueOnly() ));
		emit
			sigQtMovobjSetControl();
		//void sigQtMovobjSetControl();

		updateGL();
	}


};
//void GLWidget::slotMOV3dMoveOrderspt(int op,float oprand,glMovingObjectf * newgmvopt) {
//	//std::cout<<"GLWidget::slotMOV3dMoveOrders(int op,float oprand)"<<std::endl;
//
//	glMovingObjectf * ingl_mvopt = newgmvopt;
//	//std::cout<<op<<"  "<<oprand;  
//
//	if (NULL !=  ingl_mvopt)  {
//		switch (op) {
//		case enum3dops::wfb :
//			ingl_mvopt->forward(oprand);
//			break;
//		case enum3dops::yaw:
//			ingl_mvopt->yaw(oprand);
//			break;
//		case enum3dops::roll:
//			ingl_mvopt->roll(oprand);
//			break;
//
//		case enum3dops::pitch:
//			ingl_mvopt->pitch(oprand);
//			break;
//		default:
//			// you should never get here, but in case
//			break;
//		}
//		updateGL();
//	}
//}



//void GLWidget::slotMOV3dMoveOrders(int op,float oprand) {
//	//std::cout<<"GLWidget::slotMOV3dMoveOrders(int op,float oprand)"<<std::endl;
//
//	glMovingObjectf * ingl_mvopt = gmvopt;
//	//std::cout<<op<<"  "<<oprand;  
//
//	if (NULL !=  ingl_mvopt)  {
//		switch (op) {
//		case enum3dops::wfb :
//			ingl_mvopt->forward(oprand);
//			break;
//		case enum3dops::yaw:
//			ingl_mvopt->yaw(oprand);
//			break;
//		case enum3dops::roll:
//			ingl_mvopt->roll(oprand);
//			break;
//
//		case enum3dops::pitch:
//			ingl_mvopt->pitch(oprand);
//			break;
//		default:
//			// you should never get here, but in case
//			break;
//		}
//		updateGL();
//	}
//}

//! [0]
GLWidget::GLWidget(QWidget *parent)
	: QGLWidget(QGLFormat(QGL::SampleBuffers), parent)
{
	wwidth = 0,  wheight= 0;
	logo = 0;
	xRot = 0;
	yRot = 0;
	zRot = 0;

	qtGreen = QColor::fromCmykF(0.40, 0.0, 1.0, 0.0);
	qtPurple = QColor::fromCmykF(0.39, 0.39, 0.0, 0.0);

}
//! [0]

//! [1]
GLWidget::~GLWidget()
{
}
//! [1]

//! [2]
QSize GLWidget::minimumSizeHint() const
{
	return QSize(50, 50);
}
//! [2]

//! [3]
QSize GLWidget::sizeHint() const
	//! [3] //! [4]
{
	return QSize(400, 400);
}
//! [4]

static void qNormalizeAngle(int &angle)
{
	while (angle < 0)
		angle += 360 * 16;
	while (angle > 360 * 16)
		angle -= 360 * 16;
}

//! [5]
void GLWidget::setXRotation(int angle)
{
	qNormalizeAngle(angle);
	if (angle != xRot) {
		xRot = angle;
		emit xRotationChanged(angle);
		updateGL();
	}
}
//! [5]

void GLWidget::setYRotation(int angle)
{
	qNormalizeAngle(angle);
	if (angle != yRot) {
		yRot = angle;
		emit yRotationChanged(angle);
		updateGL();
	}
}

void GLWidget::setZRotation(int angle)
{
	qNormalizeAngle(angle);
	if (angle != zRot) {
		zRot = angle;
		emit zRotationChanged(angle);
		updateGL();
	}
}

//! [6]
void GLWidget::initializeGL()
{
	camera * current_camera = qtCameraSingleton::getInstance ()->getCurrentCamera ();
	//StructPserpective spStructPserpective;
	//StructOrthorgonal soStructOrthorgonal;

	/*
	typedef struct _StructPserpective {
	float fovy;
	float near_z;
	float far_z;
	float fovy_min;
	float fovy_max;

	} StructPserpective, * p_StructPserpective;
	typedef struct _StructOrthorgonal {
	float o_size1;
	float o_size2;
	float o_size3;
	float o_size4;
	float near_z;
	float far_z;
	float o_size_limit;
	} StructOrthorgonal, * p_StructOrthorgonal;
	*/
	/*
	orthoganal_clip_size2 = orthoganal_clip_size	= 10.0;
	eyex = 0 ,eyey= 0 ,eyez = -20;
	lookatx =0,lookaty =0,lookatz=0;
	NEAR_Z	=		1.0;
	FAR_Z	=		300.0;
	scale = 1.0;

	glClearColor (1.0, 1.0, 1.0, 1.0);
	glShadeModel(GL_FLAT);
	glEnable(GL_DEPTH_TEST);
	glEnable(GL_CULL_FACE);
	glShadeModel(GL_SMOOTH);
	*/
	orthoganal_clip_size2 = orthoganal_clip_size	= 4.0;
	eyex = 2 ,eyey= 2 ,eyez = 2;
	lookatx =0,lookaty =0,lookatz=0;
	NEAR_Z	=		1.0;
	FAR_Z	=		300.0;
	scale = 1.0;

	//glClearColor (1.0, 1.0, 1.0, 1.0);
	glClearColor (1.0, 1.0, 1.0, 1.0);
	glShadeModel(GL_FLAT);
	glEnable(GL_DEPTH_TEST);
	//glEnable(GL_CULL_FACE);
	glDisable(GL_CULL_FACE);
	glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);
	//glEnable(GL_CULL_FACE);
	glShadeModel(GL_SMOOTH);


	current_camera->yawThenRollToPinAPoint(current_camera->LookedAt);
	current_camera->initSwirlVectors();
	////SIGNAL(sigMVOUpdateWagonValueOnly())
	//emit 
	//sigMVOUpdateWagonValueOnly();
	emit
		//sigMVOUpdateWagonValueOnly();
		sigCAMUpdateWagonValueOnly();}
//! [6]

//! [7]
void GLWidget::paintGL()
{
	//current_camera->yawThenRollToPinAPoint(current_camera->LookedAt);
	camera * current_camera = qtCameraSingleton::getInstance ()->getCurrentCamera ();	
	glMatrixMode(GL_PROJECTION); 
	glLoadIdentity();
	if (NULL !=  current_camera)  {
		if (current_camera->orthorgonal_disp ) {
			glOrtho(-current_camera->soStructOrthorgonal.o_size1,
				current_camera->soStructOrthorgonal.o_size1,
				-current_camera->soStructOrthorgonal.o_size1,
				current_camera->soStructOrthorgonal.o_size1,
				current_camera->soStructOrthorgonal.near_z,
				current_camera->soStructOrthorgonal.far_z);
		}
		else {
			gluPerspective(
				current_camera->spStructPserpective.fovy, 
				(float)wwidth/(float)wheight, 
				current_camera->spStructPserpective.near_z,
				current_camera->spStructPserpective.far_z);
		}
	} else {
		glOrtho(-orthoganal_clip_size, orthoganal_clip_size, -orthoganal_clip_size2,  orthoganal_clip_size2,  NEAR_Z, FAR_Z);
	}
	glMatrixMode(GL_MODELVIEW);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glClearColor (1.0,1.0, 1.0, 1.0);
	glLoadIdentity();	

	if (NULL !=  current_camera)  {
		mathPoint<GLfloat>  pl = current_camera->getLookedAt();
		mathPoint<GLfloat>  pe = current_camera->getPosition();
		mathVector<GLfloat>  vu = current_camera->getUpVectorRef();

		gluLookAt(pe.getx(),pe.gety(), pe.getz(),  pl.getx(), 
			pl.gety(), pl.getz(), vu.getx(),vu.gety(),vu.getz());

	}
	else 
		gluLookAt(eyex,eyey, eyez, lookatx, 
		lookaty, lookatz, 0,1,0);

	// Never change this scale value, soft-scale is bad.
	glScalef(scale,scale,scale);


	




	/*
	struct MATERIAL {
   char description[30];
   GLfloat *specular[4];
   GLfloat *diffuse[4];
   GLfloat *ambient[4];
   GLfloat shininess;
};

	*/
   //{"Red Shiny Material",
    //{1.0f, 0.0f, 0.0f, 1.0f},
    //{1.0f, 0.0f, 0.0f, 1.0f},
    //{1.0f, 0.0f, 0.0f, 1.0f},
    //100.0f},



	//GLfloat specular[] = { 1.0, 0.0, 0.0, 1.0 };
	//GLfloat diffuse[] = {0.3, 0, 0.0, 1.0 };
	//GLfloat ambient[] = {0.5f, 0.0f, 0.0f, 1.0f };
	//GLfloat shineness = 100.0f;
 //  glMaterialfv(GL_FRONT, GL_SPECULAR, specular);
 //  glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse);
 //  glMaterialfv(GL_FRONT, GL_AMBIENT, ambient);
 //  glMaterialf(GL_FRONT, GL_SHININESS, shineness);

   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);

   /*
GLfloat light_ambient[] = { 1.0, 1.0, 1.0, 0.3};
GLfloat light_diffuse[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat light_position[] = { 0.0, 0.0, 10.0, 0.0 };

glLightfv(GL_LIGHT0, GL_AMBIENT, light_ambient);
glLightfv(GL_LIGHT0, GL_DIFFUSE, light_diffuse);
glLightfv(GL_LIGHT0, GL_SPECULAR, light_specular);
glLightfv(GL_LIGHT0, GL_POSITION, light_position);
*/
   //light_default;

   glLight * current_light = qtLightSingleton::getInstance ()->getCurrentLight ();
   if (NULL !=  current_light)  {
	     glLightfv(GL_LIGHT0, GL_AMBIENT, current_light->get_data_GL_AMBIENTfv () );
   glLightfv(GL_LIGHT0, GL_DIFFUSE, current_light->get_data_GL_DIFFUSEfv () );
   glLightfv(GL_LIGHT0, GL_SPECULAR, current_light->get_data_GL_SPECULARfv () );
   glLightfv(GL_LIGHT0, GL_POSITION, current_light->get_data_GL_POSITIONfv () );

   } else {
	   std::cout<<"if (NULL ==  current_light)"<<std::endl;  
	      glLightfv(GL_LIGHT0, GL_AMBIENT, light_default.get_data_GL_AMBIENTfv () );
   glLightfv(GL_LIGHT0, GL_DIFFUSE, light_default.get_data_GL_DIFFUSEfv () );
   glLightfv(GL_LIGHT0, GL_SPECULAR, light_default.get_data_GL_SPECULARfv () );
   glLightfv(GL_LIGHT0, GL_POSITION, light_default.get_data_GL_POSITIONfv () );

   }

 
 //  float color[4] = {0.0f, 0.0f, 0.0f,0.2};
	//color[0] =0.2,color[1] = 0.2,color[2] = 0.2,color[3] = 1.0;
	//glLightfv(GL_LIGHT0, GL_AMBIENT, color );
	//color[0] = 1.0,color[1] = 1.0,color[2] = 1.00,color[3] = 1.0;
	//glLightfv(GL_LIGHT0, GL_DIFFUSE,color);
	//color[0] = 1.0,color[1] = 1.0,color[2] = 1.0,color[3] = 1.0;
	//glLightfv(GL_LIGHT0, GL_SPECULAR, color );
	//color[0] = 0.0,color[1] = 0.0,color[2] = 10.0,color[3] = 0.0;
	////While the ambient, diffuse, specular and emission material parameters
 ////           all have alpha components, only the diffuse alpha component is used in
 ////           the lighting computation.
	//glLightfv(GL_LIGHT0, GL_POSITION, color);


		float specular2[] = { 0.33, 0.22, 0.03, 1.0 };
	float diffuse2[] = {0.78, 0.57, 0.11, 1.0 };
	float ambient2[] = {0.99, 0.91, 0.81, 0.3};
	float shineness2 =  27.8;

	   glMaterialfv(GL_FRONT, GL_SPECULAR, specular2);
   glMaterialfv(GL_FRONT, GL_DIFFUSE, diffuse2);
   glMaterialfv(GL_FRONT, GL_AMBIENT, ambient2);
   glMaterialf(GL_FRONT, GL_SHININESS, shineness2);

   

  // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
   //glutSolidSphere(1.0, 20, 16);
	glPushMatrix();
	//glTranslatef(2.0f,0.0f,0.0f);
	//glutSolidSphere(1.0, 20, 16);
	glFrontFace(	 GL_CW);// for glutSolidTeapot
	 glutSolidTeapot(1.5f);
	glPopMatrix();


	// draw non-lighted stuff here, e.g., axis, vectors etc.
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glPushMatrix();

	glDisable(GL_LIGHTING);
	drawablesSingleton::getInstance()->draw();
	if (NULL !=  current_camera)  {
		if (current_camera->showFocus )
			current_camera->drawFocus ();
	} ;

	glColor3d(1,0,0);
	
	//glBegin(GL_LINES);
	//glVertex3d(0,0,0);
	//glVertex3d(zero[0],zero[1],zero[2]);
	//glEnd();

	glPopMatrix();
	glPopAttrib();


   /*
    {"Brass Material",
    {0.33f, 0.22f, 0.03f, 1.0f},
    {0.78f, 0.57f, 0.11f, 1.0f},
    {0.99f, 0.91f, 0.81f, 1.0f},
    27.8f}
	*/





	/*
	  GLfloat mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
   GLfloat mat_shininess[] = { 50.0 };
   GLfloat light_position[] = { 1.0, 1.0, 1.0, 0.0 };
   glClearColor (0.0, 0.0, 0.0, 0.0);
   glShadeModel (GL_SMOOTH);

   glMaterialfv(GL_FRONT, GL_SPECULAR, mat_specular);
   glMaterialfv(GL_FRONT, GL_SHININESS, mat_shininess);
   glLightfv(GL_LIGHT0, GL_POSITION, light_position);

   glEnable(GL_LIGHTING);
   glEnable(GL_LIGHT0);
   glEnable(GL_DEPTH_TEST);

    glutSolidSphere (1.0, 20, 16);
	*/



	/*
	float color[4] = {0.0f, 0.0f, 0.0f,0.2};
	glEnable(GL_LIGHTING);
	//GL_LIGHT i where i ranges from 0 to the value of GL_MAX_LIGHTS - 1.
	//GL_LIGHT i = GL_LIGHT0 + i.
	
	glEnable(GL_POLYGON_OFFSET_FILL);
	glShadeModel(GL_SMOOTH);
	glEnable(GL_NORMALIZE);

	int maxlightsno = 0;
	glGetIntegerv(GL_MAX_LIGHTS,&maxlightsno);
	
	int i = 0;
	for (; i<maxlightsno; i++ )  {
		glDisable(GL_LIGHT0+i);
	}

	float zero[4];
	zero[0]=0.0f,zero[1]=0.0f,zero[2]=10.0f,zero[3]=1.0f;

	glEnable(GL_LIGHT1);
	glLightfv(GL_LIGHT1, GL_POSITION, zero);
	color[0] = 1.0,color[1] = 1.0,color[2] = 1.0,color[3] = 0.3;
	glLightfv(GL_LIGHT1, GL_AMBIENT, color );
	color[0] = 1.0,color[1] = 1.0,color[2] = 1.00,color[3] = 1.0;
	glLightfv(GL_LIGHT1, GL_DIFFUSE,color);
	color[0] = 1.0,color[1] = 1.0,color[2] = 1.0,color[3] = 1.0;
	glLightfv(GL_LIGHT1, GL_SPECULAR, color );




	//glRotated(xRot / 16.0, 1.0, 0.0, 0.0);
	//glRotated(yRot / 16.0, 0.0, 1.0, 0.0);
	//glRotated(zRot / 16.0, 0.0, 0.0, 1.0);
	glScalef(scale,scale,scale);

	GLfloat green_shiny_mat_shininess[] = { 100.0 };
GLfloat green_shiny_mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat green_shiny_mat_diffuse[] = { 0.0, 0.7, 0.0,1.0};
GLfloat green_shiny_mat_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat green_shiny_mat_emission[] = { 0.0, 0.0,0.0, 1.0 };

GLfloat back_green_shiny_mat_shininess[] = { 35.0 };
GLfloat back_green_shiny_mat_specular[] = { 0.3, 0.3, 0.3, 1.0 };
GLfloat back_green_shiny_mat_diffuse[] = { 0.0, 0.2, 0.0,1.0};
GLfloat back_green_shiny_mat_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
GLfloat back_green_shiny_mat_emission[] = { 0.0, 0.0,0.0, 1.0 };


GLfloat red_shiny_mat_shininess[] = { 100.0 };
GLfloat red_shiny_mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat red_shiny_mat_diffuse[] = { 0.7, 0.0, 0.0,1.0};
GLfloat red_shiny_mat_ambient[] = { 1.0, 1.0, 1.0, 1.0 };
GLfloat red_shiny_mat_emission[] = { 0.0, 0.0,0.0, 1.0 };


	////set materials
	//GLfloat green_shiny_mat_shininess[] = { 100.0 };
	//GLfloat green_shiny_mat_specular[] = { 1.0, 1.0, 1.0, 1.0 };
	//GLfloat green_shiny_mat_diffuse[] = { 0.0, 0.7, 0.0,1.0};
	//GLfloat green_shiny_mat_ambient[] = { 0.0, 0.1, 0.0, 1.0 };
	//GLfloat green_shiny_mat_emission[] = { 0.0, 0.0,0.0, 1.0 };

	//GLfloat back_green_shiny_mat_shininess[] = { 100.0 };
	//GLfloat back_green_shiny_mat_specular[] = { 0.3, 0.3, 0.3, 1.0 };
	//GLfloat back_green_shiny_mat_diffuse[] = { 0.0, 0.0, 0.0,1.0};
	//GLfloat back_green_shiny_mat_ambient[] = { 0.0, 0.0, 0.0, 1.0 };
	//GLfloat back_green_shiny_mat_emission[] = { 0.0, 0.0,0.0, 1.0 };

	glMaterialfv(GL_FRONT, GL_AMBIENT, green_shiny_mat_ambient);
	glMaterialfv(GL_FRONT, GL_DIFFUSE, green_shiny_mat_diffuse);
	glMaterialfv(GL_FRONT, GL_SPECULAR, green_shiny_mat_specular);	
	glMaterialfv(GL_FRONT, GL_SHININESS, green_shiny_mat_shininess);
	glMaterialfv(GL_FRONT, GL_EMISSION, green_shiny_mat_emission);

	glMaterialfv(GL_BACK, GL_AMBIENT, red_shiny_mat_ambient);
	glMaterialfv(GL_BACK, GL_DIFFUSE, red_shiny_mat_diffuse);
	glMaterialfv(GL_BACK, GL_SPECULAR, red_shiny_mat_specular);	
	glMaterialfv(GL_BACK, GL_SHININESS, red_shiny_mat_shininess);
	glMaterialfv(GL_BACK, GL_EMISSION, red_shiny_mat_emission);

	//glFrontFace(	 GL_CW);

	// draw lighted stuff here.
	glPushMatrix();
	Point p1,p2,p3,p4;
	p1.x = -1.0, p1.y = 1.0, p1.z = 1.0;
	p2.x = 1.0, p2.y = 1.0, p2.z = 1.0;
	p3.x = 1.0, p3.y = -1.0, p3.z = 1.0;
	p4.x = -1.0, p4.y = -1.0, p4.z = 1.0;
	drawRectangleWithNormal (&p4,&p3,&p2,&p1);
	//drawRectangleWithNormal (&p1,&p2,&p3,&p4);
	//glutSolidSphere (1.0, 20, 16);

	//	p1.x = -1.0, p1.y = 1.0, p1.z = -1.0;
	//p2.x = 1.0, p2.y = 1.0, p2.z = -1.0;
	//p3.x = 1.0, p3.y = -1.0, p3.z = -1.0;
	//p4.x = -1.0, p4.y = -1.0, p4.z = -1.0;

	////drawRectangleWithNormal (&p4,&p3,&p2,&p1);
	//drawRectangleWithNormal (&p1,&p2,&p3,&p4);


			p1.x = -1.0, p1.y = 1.0, p1.z = 0.2;
	p2.x = 1.0, p2.y = 1.0, p2.z = 0.2;
	p3.x = 1.0, p3.y = -1.0, p3.z = 0.2;
	p4.x = -1.0, p4.y = -1.0, p4.z = 0.2;

	//drawRectangleWithNormal (&p4,&p3,&p2,&p1);
	drawRectangleWithNormal2 (&p4,&p3,&p2,&p1);

	//void glutSolidTeapot            (GLdouble size           );

	//glutSolidTeapot (1.0);
	//glutSolidCube(1.0);
	
	//glTranslated(0,0,1);

	//drawCuboid (1,1,1,1,1,1);
	glPopMatrix();


	// draw non-lighted stuff here, e.g., axis, vectors etc.
	glPushAttrib(GL_ALL_ATTRIB_BITS);
	glPushMatrix();

	glDisable(GL_LIGHTING);
	drawablesSingleton::getInstance()->draw();
	if (NULL !=  current_camera)  {
		if (current_camera->showFocus )
			current_camera->drawFocus ();
	} ;

	glColor3d(1,0,0);
	
	//glBegin(GL_LINES);
	//glVertex3d(0,0,0);
	//glVertex3d(zero[0],zero[1],zero[2]);
	//glEnd();

	glPopMatrix();
	glPopAttrib();
	*/
}
//! [7]

//! [8]
void GLWidget::resizeGL(int width, int height)
{
	camera * current_camera = qtCameraSingleton::getInstance ()->getCurrentCamera ();	
	wwidth = width,  wheight= height;
	//this->width = width, this->height = height;
	//int side = qMin(width, height);
	//glViewport((width - side) / 2, (height - side) / 2, side, side);
	glViewport(0, 0, width,height);	
	glMatrixMode(GL_PROJECTION); 
	glLoadIdentity();
	if (NULL !=  current_camera)  {
		//mvopt->drawv();
		if (current_camera->orthorgonal_disp ) {
			//std::cout<<"glOrtho"<<std::endl;
			glOrtho(-current_camera->soStructOrthorgonal.o_size1,
				current_camera->soStructOrthorgonal.o_size1,
				-current_camera->soStructOrthorgonal.o_size1,
				current_camera->soStructOrthorgonal.o_size1,
				current_camera->soStructOrthorgonal.near_z,
				current_camera->soStructOrthorgonal.far_z);
		}
		else {
			//std::cout<<"gluPerspective"<<std::endl;
			gluPerspective(current_camera->spStructPserpective.fovy, (GLfloat)width/(GLfloat)height, 
				current_camera->spStructPserpective.near_z,
				current_camera->spStructPserpective.far_z);
		}
	} else {
		glOrtho(-orthoganal_clip_size, orthoganal_clip_size, -orthoganal_clip_size2,  orthoganal_clip_size2,  NEAR_Z, FAR_Z);
	}
	glMatrixMode(GL_MODELVIEW);
	/*
	//glViewport(0, 0, w, h);				// whole window area
	int side = qMin(width, height);
	glViewport((width - side) / 2, (height - side) / 2, side, side);
	//
	// set the projection transformation,
	glMatrixMode(GL_PROJECTION); 
	glLoadIdentity();
	glOrtho(-orthoganal_clip_size, orthoganal_clip_size, 		-orthoganal_clip_size2,  orthoganal_clip_size2,  NEAR_Z, FAR_Z);
	glMatrixMode(GL_MODELVIEW);
	*/
}
//! [8]

//! [9]
void GLWidget::mousePressEvent(QMouseEvent *event)
{
	lastPos = event->pos();
}
//! [9]

//! [10]
void GLWidget::mouseMoveEvent(QMouseEvent *event)
{
	int dx = event->x() - lastPos.x();
	int dy = event->y() - lastPos.y();

	if (event->buttons() & Qt::LeftButton) {
		setXRotation(xRot + 8 * dy);
		setYRotation(yRot + 8 * dx);
	} else if (event->buttons() & Qt::RightButton) {
		setXRotation(xRot + 8 * dy);
		setZRotation(zRot + 8 * dx);
	}
	lastPos = event->pos();
}
//! [10]

//#ifdef __USE_DOUBLE
//void GLWidget::slotglMovingObjectMoveOrders(glMovingObject<double> * glmvopt, int op,double oprand) {
//#else
//void GLWidget::slotglMovingObjectMoveOrders(glMovingObject<float> *  glmvopt, int op,float oprand) {
//
//#endif
//	if (NULL != glmvopt) {
//		switch (op) {
//		case enum3dops::wfb :
//			glmvopt->forward(oprand);
//			break;
//		case enum3dops::yaw:
//			glmvopt->yaw(oprand);
//			break;
//		case enum3dops::roll:
//			glmvopt->roll(oprand);
//			break;
//
//		case enum3dops::pitch:
//			glmvopt->pitch(oprand);
//			break;
//		case enum3dops::localposition:
//			glmvopt->calculateAllLocalPositions();
//			break;
//		default:
//			break;
//		}
//		emit
//			sigUpdateWagonValueOnly();
//		//sigback to update qtwagon
//		updateGL();
//	}
//}
