Exemple #1
0
int cLevel::render(SDL_Surface* dst) {
    for (int i = 0; i < walls.size(); ++i) {
        dispWall(dst, &walls[i], &vp);
    }
    for (int i = 0; i < 4; ++i) {
        dispWall(dst, &borders[i], &vp);
    }

    if (dirOn) {
        switch (dir) {
            case enumDirLEFT:
                filledTrigonRGBA(dst, 100, 0, 0, 50, 100, 100, 255, 0, 0, 255);
                break;
            case enumDirRIGHT:
                filledTrigonRGBA(dst, 0, 0, 100, 50, 0, 100, 255, 0, 0, 255);
                break;
            case enumDirUP:
                filledTrigonRGBA(dst, 50, 0, 100, 100, 0, 100, 255, 0, 0, 255);
                break;
            case enumDirDOWN:
                filledTrigonRGBA(dst, 0, 0, 100, 0, 50, 100, 255, 0, 0, 255);
                break;
        }
    }

    coord tc;
    tc = toScreen(playerPOI[0]);
    applySurface(sEntrance, dst, tc.x - sEntrance->w/2, tc.y - sEntrance->h/2);
    tc = toScreen(playerPOI[1]);
    applySurface(sExit, dst, tc.x - sEntrance->w/2, tc.y - sEntrance->h/2);

    return 0;
}
void Application::render()
{
    simulate();

    Platform::drawBegin();
    Platform::draw(Platform::BACKGROUND, FRUITCLICK_WIDTH / 2.0f, FRUITCLICK_HEIGHT / 2.0f);

    std::string text = "Score: ";
    text += toString(m_score);
    Platform::drawText(text.c_str(), 5, FRUITCLICK_HEIGHT - 20);

    text = "Lives: ";
    text += toString(m_lives);
    Platform::drawText(text.c_str(), 5, FRUITCLICK_HEIGHT - 45);

    std::set<Apple*>::const_iterator it = m_apples.begin();
    std::set<Apple*>::const_iterator itEnd = m_apples.end();

    while (it != itEnd)
    {
        Apple* apple = *it;
        Platform::draw(Platform::APPLE,
                       toScreen(apple->x()),
                       toScreen(apple->y()),
                       apple->angle());
        ++it;
    }

    Platform::drawEnd();
}
Exemple #3
0
bool Director::mousePressed(ofPoint _mouse){
    if (inside(_mouse)){
        
        //  Is over one dot?
        //
        bool overDot = false;
        for(int i=1;i<points.size()-1;i++){
            ofPoint pos = toScreen(points[i]);
            if(pos.distance(_mouse)<20){
                overDot = true;
                break;
            }
        }
        
        if (!overDot){
            lastCLick = _mouse;
        }
        
        if(!ofGetKeyPressed() && !overDot){
            
            float lenghtToClosest = 1000;
            int closest = -1;
            
            for (int i=0;i<points.size()-1;i++){
                int next=i+1;
                
                ofVec2f AtoM = _mouse - toScreen(points[i]);
                ofVec2f AtoB = toScreen(points[next]) - toScreen(points[i]);
                
                float a = atan2f(AtoM.x, AtoM.y);
                float b = atan2f(AtoB.x, AtoB.y);
                
                if (abs(a - b) <= 0.05 &&               //  1. Is over the line
                    AtoM.length() < lenghtToClosest &&  //  2. Is the closest one
                    AtoM.length() < AtoB.length() ){    //  3. Is between those two points
                    lenghtToClosest = AtoM.length();
                    closest = next;
                }
            }
            
            if(closest!=-1){
                points.insert(points.begin()+closest, fromScreen(_mouse));
            }
            
        } else if (ofGetKeyPressed('a') && !overDot){
            points.insert(points.end()-1, fromScreen(_mouse));
        } else if( ( ofGetKeyPressed('d') || ofGetKeyPressed(OF_KEY_BACKSPACE) || ofGetKeyPressed(OF_KEY_DEL) )&& overDot){
            for(int i=1;i<points.size()-1;i++){
                ofPoint pos = toScreen(points[i]);
                if(pos.distance(_mouse)<10){
                    points.erase(points.begin()+i);
                    break;
                }
            }
        }
    }
}
Exemple #4
0
void Box::draw(ArduRCT_Graphics *graphics) {
    _xDraw = toScreen(x);
    _yDraw = toScreen(y);
#if (BOX_FILLED == 1)
    graphics->fillRectangle(_xDraw, _yDraw, _size, _size, _color);
#else
    graphics->drawRectangle(_xDraw, _yDraw, _size, _size, _color, BOX_THICKNESS);
#endif    
}
QUndoCommand* Navigator::mouseMoveEvent(QMouseEvent* e)
{
  switch (m_currentAction) {
    case Rotation: {
      QPoint delta = e->pos() - m_lastMousePosition;
      rotate(m_renderer->scene().center(), delta.y(), delta.x(), 0);
      e->accept();
      break;
    }
    case Translation: {
      Vector2f fromScreen(m_lastMousePosition.x(), m_lastMousePosition.y());
      Vector2f toScreen(e->localPos().x(), e->localPos().y());
      translate(m_renderer->scene().center(), fromScreen, toScreen);
      e->accept();
      break;
    }
    case ZoomTilt: {
      QPoint delta = e->pos() - m_lastMousePosition;
      // Tilt
      rotate(m_renderer->scene().center(), 0, 0, delta.x());
      // Zoom
      zoom(m_renderer->scene().center(), delta.y());
      e->accept();
      break;
    }
    default:;
  }

  m_lastMousePosition = e->pos();

  if (e->isAccepted())
    emit updateRequested();

  return nullptr;
}
Exemple #6
0
CInfoBoxPopup::CInfoBoxPopup(Point position, const CGHeroInstance * hero):
	CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "HEROQVBK", toScreen(position))
{
	InfoAboutHero iah;
	LOCPLINT->cb->getHeroInfo(hero, iah);

	OBJ_CONSTRUCTION_CAPTURING_ALL;
	new CHeroTooltip(Point(9, 10), iah);
}
Exemple #7
0
CInfoBoxPopup::CInfoBoxPopup(Point position, const CGGarrison * garr):
	CWindowObject(RCLICK_POPUP | PLAYER_COLORED, "TOWNQVBK", toScreen(position))
{
	InfoAboutTown iah;
	LOCPLINT->cb->getTownInfo(garr, iah);

	OBJ_CONSTRUCTION_CAPTURING_ALL;
	new CArmyTooltip(Point(9, 10), iah);
}
Exemple #8
0
void Director::draw(){
    
    ofPushStyle();
    ofPushMatrix();
    ofTranslate(x, y);
    ofSetDrawBitmapMode(OF_BITMAPMODE_MODEL);
    
    ofFill();
    ofSetColor(brigtness*255,OFX_UI_COLOR_BACK_ALPHA*4.0);
    ofRect(0,0,width,height);
    
    ofSetColor(OFX_UI_COLOR_FILL ,OFX_UI_COLOR_FILL_ALPHA);
    if(font == NULL){
        ofDrawBitmapString(name,15,15);
    } else {
        font->drawString(name,15,20);
    }
    
    ofNoFill();
    ofSetColor(brigtness*255,OFX_UI_COLOR_BACK_ALPHA);
    drawBrakets(ofRectangle(-7,-7,14,14), 5, 2 );
    drawBrakets(ofRectangle(width-7,height-7,14,14), 5, 2 );
    ofPopMatrix();
    
    ofSetColor(OFX_UI_COLOR_FILL,OFX_UI_COLOR_FILL_ALPHA);
    ofBeginShape();
    for(int i = 0; i< points.size();i++){
        ofPoint pos = toScreen(points[i]);
        ofVertex(pos);
    }
    ofEndShape(false);
    
    ofSetColor(OFX_UI_COLOR_FILL_HIGHLIGHT,OFX_UI_COLOR_FILL_HIGHLIGHT_ALPHA);
    for(int i = 1; i< points.size()-1;i++){
        ofCircle(toScreen(points[i]),5);
    }
    
    ofPopStyle();
}
void setBuffer(COLOR_VERTEX colorVertices[MAXLINELENGTH],double matrixFinal[][4],int nM,double d[],double s[],int shading,double mInverse[][4])
{
	int k;
	for(k = 0; k < thescene.mesh[nM].npolygons; k++){
		COLOR_VERTEX vertices[3] = {colorVertices[thescene.mesh[nM].polygons[k].num[0]],
																							colorVertices[thescene.mesh[nM].polygons[k].num[1]],
																							colorVertices[thescene.mesh[nM].polygons[k].num[2]]};
		int i=0;
		for(i = 0; i < 3; i++){										matrixApply(matrixFinal,vertices[i].xyzw);
		}																			toScreen(vertices[0].xyzw,vertices[1].xyzw,vertices[2].xyzw);
								triRendering(vertices[0].xyzw,vertices[1].xyzw,vertices[2].xyzw,vertices[0].rgba,vertices[1].rgba,vertices[2].rgba,d,s,shading,mInverse);
	
	}
}
Exemple #10
0
int cLevel::dispWall(SDL_Surface* dst, SDL_Rect* w, SDL_Rect* vp) {
    SDL_Rect dstRect;

    dstRect.w = w->w;
    dstRect.h = w->h;
    dstRect.x = w->x - vp->x;
    dstRect.y = w->y - vp->y;

    SDL_FillRect(dst, &dstRect, wallclr);

    coord wc = {w->x, w->y};
    wc = toScreen(wc);

    applyTile(sWall, dst, wc.x, wc.y, w->w, w->h, 0, 0);

    return 0;
}
/*virtual*/
void InputEmulatorUInput::movePointer(const int32_t x, const int32_t y) const
{
	struct input_event event;
	int32_t gx(x), gy(y);

	toScreen(&gx, &gy);

	memset(&event, 0, sizeof(event));

	event.type = EV_ABS;
	event.code = ABS_X;
	event.value = gx;
	writeEvent(&event);

	event.type = EV_ABS;
	event.code = ABS_Y;
	event.value = gy;
	writeEvent(&event);

	event.type = EV_SYN;
	event.code = SYN_REPORT;
	event.value = 0;
	writeEvent(&event);
}
Exemple #12
0
CL_Pointf Viewport::onScreen(const CL_Pointf &p_worldPoint) const
{
	return toScreen(p_worldPoint);
}
int main() {
	//Declares all of the arrays that are to be used
	char inFileName[MAXFILENAMELENGTH];
	char outFileName[MAXFILENAMELENGTH];
	int fileContents[NUMINTSINFILE];
	int addedContents[NUMINTSAFTERADDITION];
	int subtractedContents[NUMINTSAFTERSUBTRACTION];
	
	//Initializes the arrays to 0s
	initializeArray(addedContents, NUMINTSAFTERADDITION);
	initializeArray(fileContents, NUMINTSINFILE);
	initializeArray(subtractedContents, NUMINTSAFTERSUBTRACTION);
	
	//Declares the file streams to be used
	ifstream inFile;
	ofstream outFile;
	
	//Gets the input file name
	cout << "Please enter the file name to open: ";
	cin >> inFileName;
	
	//Gets the output file name
	cout << "Please enter the file name to write to: ";
	cin >> outFileName;
	
	//Reads in the values from the input file name to the input values array
	inFile.open(inFileName);
	if (!inFile.fail()) {
		cout << "Input file found." << endl;
		getIntValues(fileContents, NUMINTSINFILE, inFile);
		toScreen(fileContents, NUMINTSINFILE);
	}
	else {
		cout << "Input file not found. Ending program." << endl;
		return 1;
	}
	
	//Adds the values per instruction into another array
	addValues(fileContents, addedContents, NUMINTSINFILE, NUMINTSAFTERADDITION);
	
	//Subtracts the values per instruction into another array
	subtractValues(fileContents, subtractedContents, NUMINTSINFILE, NUMINTSAFTERSUBTRACTION);
	
	//Outputs the added and subtracted values to the output file name
	outFile.open(outFileName);
	if (!outFile.fail()) {
		cout << "Output file found." << endl;
		
		toScreen(addedContents, NUMINTSAFTERADDITION);
		toScreen(subtractedContents, NUMINTSAFTERSUBTRACTION);
		
		outFile << "Added values: " << endl;
		for (int i = 0; i < NUMINTSAFTERADDITION; i++) {
			outFile << addedContents[i] << " ";
		}
		outFile << "\nSubtracted values: " << endl;
		for (int i = 0; i < NUMINTSAFTERSUBTRACTION; i++) {
			outFile << subtractedContents[i] << " ";
		}
	}
	else {
		cout << "Output file not found. Ending program." << endl;
		return 1;
	}
	
	//Closes the file streams as to clean up system
	inFile.close();
	outFile.close();
	return 0;
}
    void paintEvent(QPaintEvent* event){
        QWidget::paintEvent(event);
	QPainter painter(this);
        painter.setRenderHint(QPainter::Antialiasing,true);
        painter.setPen(QColor(255,255,255));
        win_xmin=xmin;win_xmax=xmax;
        win_ymin=ymin;win_ymax=ymax;
        float percentXpad=.1*(win_xmax-win_xmin);
        float percentYpad=.1*(win_ymax-win_ymin);
        win_xmin-=percentXpad;
        win_xmax+=percentXpad;
        win_ymin-=percentYpad;
        win_ymax+=percentYpad;
        
        // make space for text
        int x_pad_in_pixels=25,y_pad_in_pixels=15;
        float xpad=x_pad_in_pixels*(win_xmax-win_xmin)/(width()-x_pad_in_pixels);
        float ypad=y_pad_in_pixels*(win_ymax-win_ymin)/(height()-y_pad_in_pixels);
        win_ymin-=ypad;
        win_xmax+=xpad;

        win_dx=width()/(win_xmax-win_xmin);
        win_dy=height()/(win_ymax-win_ymin);

        //int h=height();
        QPainterPath path;
        QRectF fullarea(toScreen(win_xmin,win_ymax),toScreen(win_xmax,win_ymin));
        QBrush darkbrush(QColor(100,100,100),Qt::SolidPattern);
        QRectF area(toScreen(xmin,ymax),toScreen(xmax,ymin));
        QBrush brush(QColor(150,150,150),Qt::SolidPattern);
        //painter.fillRect(fullarea,darkbrush);
        //painter.setBrush(darkbrush);
        //painter.drawRoundedRect(fullarea,3,3);
        //painter.setBrush(QBrush());
        painter.fillRect(area,brush);
        if(x.size()>0){
            path.moveTo(toScreen(x[0],y[0]));
            for(int i=1;i<(int)x.size();i++)
                path.lineTo(toScreen(x[i],y[i]));

        }
        QRectF right(toScreen(xmax,ymax),toScreen(win_xmax,ymin));
        QRectF bottom(toScreen(xmin,ymin),toScreen(xmax,win_ymin));

        painter.setPen(QColor(75,50,50));
        painter.drawPath(path);

        painter.setPen(QPen());
        painter.drawText(right,Qt::AlignTop|Qt::AlignLeft,QString("%1").arg(ymax,0,'f',1));
        painter.drawText(right,Qt::AlignBottom|Qt::AlignLeft,QString("%1").arg(ymin,0,'f',1));
        painter.drawText(bottom,Qt::AlignTop|Qt::AlignLeft,QString("%1").arg(xmin,0,'f',1));
        painter.drawText(bottom,Qt::AlignTop|Qt::AlignRight,QString("%1").arg(xmax,0,'f',1));

        painter.setBrush(QBrush(QColor(0,0,0),Qt::SolidPattern));
        for(size_t i=0;i<cpx.size();i++){
            painter.drawEllipse(toScreen(cpx[i],cpy[i]),2,2);
        }
    }
Exemple #15
0
bool Director::mouseDragged(ofPoint _mouse){
    
    bool corners = false;
    ofPoint A = ofPoint(x,y);
    ofPoint B = ofPoint(x+width,y+height);
    
    if ( A.distance( _mouse) < 20 ){
        
        ofPoint disp = ofPoint(_mouse.x - x,
                               _mouse.y - y);
        
        x += disp.x;
        y += disp.y;
        width -= disp.x;
        height -= disp.y;
        this->set(x,y, width, height);
        corners = true;
    } else if ( B.distance( _mouse) < 20 ){
        width += _mouse.x - x - width;
        height += _mouse.y - y - height;
        this->set(x,y, width, height);
        corners = true;
    }
    
    if(!corners){
        if(inside(_mouse)){
            //  Is over one dot?
            //
            bool overDot = false;
            for(int i=1;i<points.size()-1;i++){
                ofPoint pos = toScreen(points[i]);
                if(pos.distance(_mouse)<20){
                    overDot = true;
                    break;
                }
            }
            
            if(!ofGetKeyPressed()&&overDot){
                for(int i=0;i<points.size();i++){
                    ofPoint pos = toScreen(points[i]);
                    if(pos.distance(_mouse)<10){
                        points[i] = fromScreen(_mouse);
                        return true;
                    }
                }
            } else if ( ofGetKeyPressed('a') && !overDot){
                points.insert(points.end()-1, fromScreen(_mouse));
            } else if ( ofGetKeyPressed('d') || ofGetKeyPressed(OF_KEY_BACKSPACE) || ofGetKeyPressed(OF_KEY_DEL) ){
                for(int i=1;i<points.size()-1;i++){
                    ofPoint pos = toScreen(points[i]);
                    if(pos.distance(_mouse)<10){
                        points.erase(points.begin()+i);
                        return true;
                    }
                }
            } else if(!overDot){
                ofPoint diff = _mouse - lastCLick;
                x += diff.x;
                y += diff.y;
                
                lastCLick = _mouse;
            }
        } else {
            return false;
        }
    } else {
        return true;
    }
}
Exemple #16
0
void ClientWindow::menuAction(int id)
 {
  menuAction(id,toScreen(action_base));
 }
Exemple #17
0
int Render_SSD(SCENE *ascene, CAMERA *acamera)
{
  /* We clear all pixels  */
  glClearColor(ascene->bcolor.rgba[0], ascene->bcolor.rgba[1],
	       ascene->bcolor.rgba[2], ascene->bcolor.rgba[3]);
  glClear (GL_COLOR_BUFFER_BIT);
  	int i,j;
	double matrixFinal[4][4],mTransform[4][4];
	double intermediaM[4][4],mCam[4][4],mInverse[4][4],tmpMatrix[4][4];
	double mTranslate[4][4],mRotate[4][4],mScale[4][4];
	double homo_coordinates[4] = {0,0,0,1};
	//double mInverse[4][4];
	
	matrixInitial(matrixFinal);
	matrixInitial(mTransform);
	matrixInitial(mTranslate);
	matrixInitial(mRotate);
	matrixInitial(mScale);
	
	int screenW = ascene->screen_w;
	int screenH = ascene->screen_h;

	buffer = (HIDDEN *)malloc(sizeof(HIDDEN) * screenW * screenH);


	for(i = 0;i < screenW * screenH;i++)
	{
		buffer[i].rgba[0] = ascene->bcolor.rgba[0];
		buffer[i].rgba[1] = ascene->bcolor.rgba[1];
		buffer[i].rgba[2] = ascene->bcolor.rgba[2];
		buffer[i].z = 9999;
	}

	/* Camera View */
	int ii;
	matrixInitial(mInverse);
	matrixInitial(tmpMatrix);
	matrixInitial(intermediaM);
	matrixInitial(mCam);
	double u[3],v[3],w[3];
	double gaze[3] = {acamera->gaze.xyzw[0],acamera->gaze.xyzw[1],acamera->gaze.xyzw[2]};
	double upVector[3] = {acamera->upVector.xyzw[0],acamera->upVector.xyzw[1],acamera->upVector.xyzw[2]};
	
	vecUnitization(gaze,w);

	for(ii = 0; ii < 3; ii++){
		w[ii] = -w[ii];
	}
	vecCross(upVector,w,u);
	vecUnitization(u,u);
	vecCross(w,u,v);
	ii = 0;
	for(ii = 0; ii < 3; ii++){
		intermediaM[0][ii] = u[ii];
		intermediaM[1][ii] = v[ii];
		intermediaM[2][ii] = w[ii];
		mCam[ii][3] = -acamera->eye.xyzw[ii];
	}	
	matrixMultiply(intermediaM,mCam,0);
	
	/*inverse  matrixMultiply() 0:normal  1:inverse */
	matrixInitial(intermediaM);
	ii = 0;
	for(ii = 0; ii < 3; ii++){
		intermediaM[ii][0] = u[ii];
		intermediaM[ii][1] = v[ii];
		intermediaM[ii][2] = w[ii];
		tmpMatrix[ii][3] = acamera->eye.xyzw[ii];
	}	
	matrixMultiply(mInverse,tmpMatrix,1);
	matrixMultiply(mInverse,intermediaM,1);


	/*Persective(1) and Orthographic(0) Projection matrix*/
	double anglePers, nearPers, farPers, rightOrtho, topOrtho, farOrtho, nearOrtho,pjType;
	double screenWidth,screenHeight;
	screenWidth = ascene->screen_w;
	screenHeight = ascene->screen_h;
	anglePers = ascene->persp.angle;
	nearPers = ascene->persp.near;
	farPers = ascene->persp.far; 
	rightOrtho = ascene->ortho.right;
	topOrtho = ascene->ortho.top;
	farOrtho = ascene->ortho.far; 
	nearOrtho = ascene->ortho.near;
	pjType = ascene->pjType;

	getFinalTransformMatrix(anglePers, nearPers, farPers, rightOrtho, topOrtho, farOrtho, nearOrtho, pjType, screenWidth, screenHeight, mCam, matrixFinal,mInverse);

	double vpInverse[4][4];
	matrixInitial(vpInverse);
	vpInverse[0][0] = (double)2/ascene->screen_w;
	vpInverse[0][3] = (double)(1-ascene->screen_w)/ascene->screen_w;
	vpInverse[1][1] = (double)2/ascene->screen_h;
	vpInverse[1][3] = (double)(1-ascene->screen_h)/ascene->screen_h;
	matrixMultiply(mInverse,vpInverse,1);

	/* Draw floor */
	double xmin,xmax,ymin,ymax,floorEdge;
	int nX,nY;

	xmin = ascene->floor.xmin;
	xmax = ascene->floor.xmax;
	ymin = ascene->floor.ymin;
	ymax = ascene->floor.ymax;
	floorEdge = ascene->floor.size;
	nY = ((xmax-xmin)/floorEdge) + 1;
	nX = ((ymax-ymin)/floorEdge) + 1;
	Line floor[nX + nY];
	
	glLineWidth(2);
	glBegin(GL_LINES);
	glColor3f(ascene->floor.color.rgba[0],ascene->floor.color.rgba[1],ascene->floor.color.rgba[2]);
	drawFloor(xmin,xmax,ymin,ymax,nX,nY,floorEdge,matrixFinal,floor);
	glEnd();

	/* draw axis*/
	glLineWidth(ascene->axis.width);
	glBegin(GL_LINES);
	if(ascene->isAxis == 1){
		double origin[4] = {0,0,0,1};
		double axisX[4] = {ascene->axis.length,0,0,1};
		double axisY[4] = {0,ascene->axis.length,0,1};
		double axisZ[4] = {0,0,ascene->axis.length,1};
		
		matrixApply(matrixFinal,origin);
		matrixApply(matrixFinal,axisX);
		matrixApply(matrixFinal,axisY);
		matrixApply(matrixFinal,axisZ);

		glColor3f(1,0,0);
		glVertex2d(origin[0]/origin[3],origin[1]/origin[3]);
		glVertex2d(axisX[0]/axisX[3],axisX[1]/axisX[3]);
		glColor3f(0,1,0);
		glVertex2d(origin[0]/origin[3],origin[1]/origin[3]);
		glVertex2d(axisY[0]/axisY[3],axisY[1]/axisY[3]);
		glColor3f(0,0,1);
		glVertex2d(origin[0]/origin[3],origin[1]/origin[3]);
		glVertex2d(axisZ[0]/axisZ[3],axisZ[1]/axisZ[3]);
	}
	glEnd();

	/* implement objects*/
	int nT = 0;
	int nR = 0;
	int nS = 0;
	int nM = 0;
	for(i = 0; i < ascene->nidentities; i++){
		matrixInitial(mTransform);
		for(j = 0; j < ascene->identities[i].inStr_num; j++){
			if(ascene->identities[i].instr[j] == TRANSLATE_KEY){
					matrixInitial(mTranslate);
					mTranslate[0][3] = ascene->translate[nT].xyz[0];
					mTranslate[1][3] = ascene->translate[nT].xyz[1];
					mTranslate[2][3] = ascene->translate[nT].xyz[2];
					matrixMultiply(mTranslate,mTransform,0);
					nT++;
			}
			else if(ascene->identities[i].instr[j] == ROTATE_KEY){
					double axis[3];
					axis[0] = ascene->rotate[nR].xyz[0];
					axis[1] = ascene->rotate[nR].xyz[1];
					axis[2] = ascene->rotate[nR].xyz[2];
					double Pi = 3.141592653;
					double radian = (ascene->rotate[nR].angle/(double)180) * Pi;
					rotateMatrix(axis,mRotate,mTransform,radian);
					nR++;
					
			}
			else if(ascene->identities[i].instr[j] == SCALE_KEY){
					matrixInitial(mScale);
					mScale[0][0] = ascene->scale[nS].xyz[0];
					mScale[1][1] = ascene->scale[nS].xyz[1];
					mScale[2][2] = ascene->scale[nS].xyz[2];
					matrixMultiply(mScale,mTransform,0);
					nS++;
			}
			else if(ascene->identities[i].instr[j] == MESH_KEY){			
					double tM[4][4];
					matrixInitial(tM);
					matrixMultiply(mTransform,tM,0);
					matrixMultiply(matrixFinal,tM,0);
					int k,l,d;

					/*apply transform matrix to all vertices in world coordinates*/
					COLOR_VERTEX colorVertices[ascene->mesh[nM].nvertices];
					for(k = 0; k < ascene->mesh[nM].nvertices; k++){
						colorVertices[k] = ascene->mesh[nM].vertices[k];
						matrixApply(mTransform,colorVertices[k].xyzw);
					}

					//flat shading
					if(ascene->mesh[nM].shading == 0){
						for(k = 0; k < ascene->mesh[nM].npolygons; k++){				
								COLOR_VERTEX vertices[3] = {colorVertices[ascene->mesh[nM].polygons[k].num[0]],
																						colorVertices[ascene->mesh[nM].polygons[k].num[1]],
																						colorVertices[ascene->mesh[nM].polygons[k].num[2]]};
								
								double normal[3]; 
								triangleNormal(vertices[0].xyzw,vertices[1].xyzw,vertices[2].xyzw,normal);
								double center[3];
								center[0] = (vertices[0].xyzw[0] + vertices[1].xyzw[0] + vertices[2].xyzw[0])/(double)3;
								center[1] = (vertices[0].xyzw[1] + vertices[1].xyzw[1] + vertices[2].xyzw[1])/(double)3;
								center[2] = (vertices[0].xyzw[2] + vertices[1].xyzw[2] + vertices[2].xyzw[2])/(double)3;
										Illumination(normal,ascene->mesh[nM].diffuse,ascene->mesh[nM].specular,center);	
	int i;
								for(i = 0; i < 3; i++){			matrixApply(matrixFinal,vertices[i].xyzw);
								}				
								toScreen(vertices[0].xyzw,vertices[1].xyzw,vertices[2].xyzw);								triRendering(vertices[0].xyzw,vertices[1].xyzw,vertices[2].xyzw,0,0,0,0,0,0,mInverse);

						}
					}

					//phong shading
					else if (ascene->mesh[nM].shading == 2){
						double vertex_normal[ascene->mesh[nM].nvertices][3];
						for(k = 0; k < ascene->mesh[nM].nvertices; k++){
						double composeNormal[3] = {0,0,0};
							for(l = 0; l < ascene->mesh[nM].npolygons; l++){
								for(d = 0; d < ascene->mesh[nM].polygons[l].nvertices; d++){
									if(ascene->mesh[nM].polygons[l].num[d] == k){
									COLOR_VERTEX vertices[3] = {colorVertices[ascene->mesh[nM].polygons[l].num[0]],
																								colorVertices[ascene->mesh[nM].polygons[l].num[1]],
																								colorVertices[ascene->mesh[nM].polygons[l].num[2]]};
									double normal[3];
										triangleNormal(vertices[0].xyzw,vertices[1].xyzw,vertices[2].xyzw,normal);
													composeNormal[0] += normal[0];
										composeNormal[1] += normal[1];
										composeNormal[2] += normal[2];
									}
								}
							}										vecUnitization(composeNormal,composeNormal);
						int i=0;			
						for(i = 0; i < 3; i++){
							colorVertices[k].rgba[i] = composeNormal[i];
							}
						}
	setBuffer(colorVertices,matrixFinal,nM,ascene->mesh[nM].diffuse,ascene->mesh[nM].specular,2,mInverse);				
					}
					//smooth shading
					else{
					   for(k = 0; k < ascene->mesh[nM].nvertices; k++){
						double composeNormal[3] = {0,0,0};
						for(l = 0; l < ascene->mesh[nM].npolygons; l++){
						   for(d = 0; d < ascene->mesh[nM].polygons[l].nvertices; d++){
																		       if(ascene->mesh[nM].polygons[l].num[d] == k){
							     COLOR_VERTEX vertices[3] = {colorVertices[ascene->mesh[nM].polygons[l].num[0]],
																								colorVertices[ascene->mesh[nM].polygons[l].num[1]],
																								colorVertices[ascene->mesh[nM].polygons[l].num[2]]};
							     double normal[3];
					triangleNormal(vertices[0].xyzw,vertices[1].xyzw,vertices[2].xyzw,normal);	
														composeNormal[0] += normal[0];								composeNormal[1] += normal[1];								composeNormal[2] += normal[2];
							  }
						      }
						  }
	vecUnitization(composeNormal,composeNormal);
	Illumination(composeNormal,ascene->mesh[nM].diffuse,ascene->mesh[nM].specular,colorVertices[k].xyzw);

	colorVertices[k].rgba[0] = illuColor[0];
	colorVertices[k].rgba[1] = illuColor[1];
	colorVertices[k].rgba[2] = illuColor[2];
						}	
	setBuffer(colorVertices,matrixFinal,nM,0,0,1,mInverse);		
					}
					glLineWidth(ascene->mesh[nM].width);
					glBegin(GL_POINTS);
					for(k = 0; k < ascene->screen_h; k++){
						for(l = 0; l < ascene->screen_w; l++){
						   	if(buffer[k*(ascene->screen_w)+l].z < 9999){										glColor3f(buffer[k*(ascene->screen_w) + l].rgba[0],buffer[k*(ascene->screen_w) + l].rgba[1],buffer[k*(ascene->screen_w) + l].rgba[2]);										glVertex2i(l,k);
							}
						} 					
					}
					glEnd();
					nM++;

			}		
		}
	}


  for(i = 0; i < ascene->nlines; i++){
	ascene->lines[i].vertices[0].xyzw[3] = 1;
	ascene->lines[i].vertices[1].xyzw[3] = 1;
	COLOR_VERTEX vertices[2];
	vertices[0] = ascene->lines[i].vertices[0];
	vertices[1] = ascene->lines[i].vertices[1];
	matrixApply(matrixFinal,vertices[0].xyzw);
	matrixApply(matrixFinal,vertices[1].xyzw);

	glLineWidth(ascene->lines[i].width);
	glBegin(GL_LINES);
	glColor3f(vertices[0].rgba[0],vertices[0].rgba[1],vertices[0].rgba[2]);
	glVertex2d(vertices[0].xyzw[0]/vertices[0].xyzw[3],vertices[0].xyzw[1]/vertices[0].xyzw[3]);
	glColor3f(vertices[1].rgba[0],vertices[1].rgba[1],vertices[1].rgba[2]);
	glVertex2d(vertices[1].xyzw[0]/vertices[1].xyzw[3],vertices[1].xyzw[1]/vertices[1].xyzw[3]);
	glEnd();
	}

  free(buffer);
  glFlush ();
  glutSwapBuffers();
  return 0;
}
inline void Navigator::translate(const Vector3f &ref, float x, float y)
{
  Vector2f fromScreen(0, 0);
  Vector2f toScreen(x, y);
  translate(ref, fromScreen, toScreen);
}