GreenJuiceTeam/GreenJuiceTeam.Shared/game/Block.cpp
/**
* Updates the street in relation to the camera
* @param camera
*/
Updates the street in relation to the camera
Updates the street in relation to the camera
void Block::update(const std::vector<int>& camera){
	paint_=true;
	view[Z] = position[Z] - camera[Z];
	view[Y] = camera[Y] - position[Y]; 
	view[X] = position[X] - camera[X];
	int topY = project(view[Y],view[Z]);
	poligonPoints[TOP_LEFT][Y] = topY;
	poligonPoints[TOP_RIGHT][Y] = topY;
	poligonPoints[TOP_LEFT][X] = project(view[X]-width/2,view[Z]);
	poligonPoints[TOP_RIGHT][X] = project(view[X]+width/2,view[Z]);
	poligonPoints[BOTTOM_LEFT][Y] = previous->poligonPoints[TOP_LEFT][Y];
	poligonPoints[BOTTOM_RIGHT][Y] = previous->poligonPoints[TOP_RIGHT][Y];
	poligonPoints[BOTTOM_LEFT][X] = previous->poligonPoints[TOP_LEFT][X];
	poligonPoints[BOTTOM_RIGHT][X] = previous->poligonPoints[TOP_RIGHT][X];
	if(previous->position[Z] <= camera[Z] || position[Z] - previous->position[Z] <= 0){
		paint_= false;
		return;
	} else if(poligonPoints[TOP_LEFT][Y] - previous->poligonPoints[TOP_LEFT][Y] >= 0){
		paint_= false;
		return;
	} else if(drawLine){
		for(int i = 1; i < numSegments; i++){
			linesPoints[TOP_LEFT][X] = project(view[X]-LINE_WIDTH/2,view[Z]);
			linesPoints[TOP_LEFT][Y] = poligonPoints[TOP_LEFT][Y];
			linesPoints[TOP_RIGHT][X] = project(view[X]+LINE_WIDTH/2,view[Z]);
			linesPoints[TOP_RIGHT][Y] = poligonPoints[TOP_LEFT][Y];
			linesPoints[BOTTOM_LEFT][X] = project(previous->view[X]-LINE_WIDTH/2,previous->view[Z]);
			linesPoints[BOTTOM_LEFT][Y] = previous->poligonPoints[TOP_LEFT][Y];
			linesPoints[BOTTOM_RIGHT][X] = project(previous->view[X]+LINE_WIDTH/2,previous->view[Z]);
			linesPoints[BOTTOM_RIGHT][Y] = previous->poligonPoints[TOP_LEFT][Y];
		}
	}
}
void Block :: update ( const std :: vector < int > & camera ) { paint_ = true ; view [ Z ] = position [ Z ] - camera [ Z ] ; view [ Y ] = camera [ Y ] - position [ Y ] ; view [ X ] = position [ X ] - camera [ X ] ; int topY = project ( view [ Y ] , view [ Z ] ) ; poligonPoints [ TOP_LEFT ] [ Y ] = topY ; poligonPoints [ TOP_RIGHT ] [ Y ] = topY ; poligonPoints [ TOP_LEFT ] [ X ] = project ( view [ X ] - width / 2 , view [ Z ] ) ; poligonPoints [ TOP_RIGHT ] [ X ] = project ( view [ X ] + width / 2 , view [ Z ] ) ; poligonPoints [ BOTTOM_LEFT ] [ Y ] = previous -> poligonPoints [ TOP_LEFT ] [ Y ] ; poligonPoints [ BOTTOM_RIGHT ] [ Y ] = previous -> poligonPoints [ TOP_RIGHT ] [ Y ] ; poligonPoints [ BOTTOM_LEFT ] [ X ] = previous -> poligonPoints [ TOP_LEFT ] [ X ] ; poligonPoints [ BOTTOM_RIGHT ] [ X ] = previous -> poligonPoints [ TOP_RIGHT ] [ X ] ; if ( previous -> position [ Z ] <= camera [ Z ] || position [ Z ] - previous -> position [ Z ] <= 0 ) { paint_ = false ; return ; } else if ( poligonPoints [ TOP_LEFT ] [ Y ] - previous -> poligonPoints [ TOP_LEFT ] [ Y ] >= 0 ) { paint_ = false ; return ; } else if ( drawLine ) { for ( int i = 1 ; i < numSegments ; i ++ ) { linesPoints [ TOP_LEFT ] [ X ] = project ( view [ X ] - LINE_WIDTH / 2 , view [ Z ] ) ; linesPoints [ TOP_LEFT ] [ Y ] = poligonPoints [ TOP_LEFT ] [ Y ] ; linesPoints [ TOP_RIGHT ] [ X ] = project ( view [ X ] + LINE_WIDTH / 2 , view [ Z ] ) ; linesPoints [ TOP_RIGHT ] [ Y ] = poligonPoints [ TOP_LEFT ] [ Y ] ; linesPoints [ BOTTOM_LEFT ] [ X ] = project ( previous -> view [ X ] - LINE_WIDTH / 2 , previous -> view [ Z ] ) ; linesPoints [ BOTTOM_LEFT ] [ Y ] = previous -> poligonPoints [ TOP_LEFT ] [ Y ] ; linesPoints [ BOTTOM_RIGHT ] [ X ] = project ( previous -> view [ X ] + LINE_WIDTH / 2 , previous -> view [ Z ] ) ; linesPoints [ BOTTOM_RIGHT ] [ Y ] = previous -> poligonPoints [ TOP_LEFT ] [ Y ] ; } } }
Updates the street in relation to the camera
Updates the street in relation to the camera
//The view is the difference between the block position and the camera position //The Y is inverted - it raises as it goes up in the screen //The Poligon points represents the road of the block //The projected Y position is the same on the TOP_LEFT and TOP_RIGHT //The TOP_LEFT and TOP_RIGHT projected position is the position //of the view plus and minus (respectively) half the road width. //It gets the bottom position from the previous top position //It shouldn't paint if the position is behind the camera or in the first //block (it's previous position is bigger it's current)  //It doesn't paint if the block is too much thin //Calculates the line positions	