   My own rendering pipeline
  I studies basics of Graphics API and create simply MFC application on Visual C++. In that application I draw 3D cube but I get distorion wen I draw my 3D cube. When I rotate the cube by 0 degree screenshot is .When rotate by 90 degree screenshot is.When I rotate by 180 degree screenshot is.When I rotate by 270 degree screenshot is.How you can see by 90 and 270 degree screenshot is wrong. But as a by 90 degree observer is right side screen, by 270 degree observer is left side of screen. In one word - projection of my 3D cube is wrong by 90 and 270 degree. What can I do that resolve my problem? This my code C++:void CCubeNotDXDlg::OnTimer(UINT nIDEvent) {angle+=(3.1415926/180);if(angle>3.1415926*2) angle =0;Invalidate();}void CCubeNotDXDlg::OnPaint() {CPaintDC dc(this); // device context for paintingfloat nPoint = 1.0;Side[0].x1 = -nPoint;Side[0].y1 = nPoint;Side[0].z1 = -nPoint;Side[0].x2 = nPoint;Side[0].y2 = nPoint;Side[0].z2 = -nPoint;Side[0].x3 = nPoint;Side[0].y3 = -nPoint;Side[0].z3 = -nPoint;Side[0].x4 = -nPoint;Side[0].y4 = -nPoint;Side[0].z4 = -nPoint;Side[1].x1 = nPoint;Side[1].y1 = nPoint;Side[1].z1 = -nPoint;Side[1].x2 = nPoint;Side[1].y2 = nPoint;Side[1].z2 = nPoint;Side[1].x3 = nPoint;Side[1].y3 = -nPoint;Side[1].z3 = nPoint;Side[1].x4 = nPoint;Side[1].y4 = -nPoint;Side[1].z4 = -nPoint;Side[2].x1 = nPoint;Side[2].y1 = nPoint;Side[2].z1 = nPoint;Side[2].x2 = -nPoint;Side[2].y2 = nPoint;Side[2].z2 = nPoint;Side[2].x3 = -nPoint;Side[2].y3 = -nPoint;Side[2].z3 = nPoint;Side[2].x4 = nPoint;Side[2].y4 = -nPoint;Side[2].z4 = nPoint;Side[3].x1 = -nPoint;Side[3].y1 = nPoint;Side[3].z1 = nPoint;Side[3].x2 = -nPoint;Side[3].y2 = nPoint;Side[3].z2 = -nPoint;Side[3].x3 = -nPoint;Side[3].y3 = -nPoint;Side[3].z3 = -nPoint;Side[3].x4 = -nPoint;Side[3].y4 = -nPoint;Side[3].z4 = nPoint;Side[4].x1 = -nPoint;Side[4].y1 = nPoint;Side[4].z1 = nPoint;Side[4].x2 = nPoint;Side[4].y2 = nPoint;Side[4].z2 = nPoint;Side[4].x3 = nPoint;Side[4].y3 = nPoint;Side[4].z3 = -nPoint;Side[4].x4 = -nPoint;Side[4].y4 = nPoint;Side[4].z4 = -nPoint;Side[5].x1 = -nPoint;Side[5].y1 = -nPoint;Side[5].z1 = nPoint;Side[5].x2 = nPoint;Side[5].y2 = -nPoint;Side[5].z2 = nPoint;Side[5].x3 = nPoint;Side[5].y3 = -nPoint;Side[5].z3 = -nPoint;Side[5].x4 = -nPoint;Side[5].y4 = -nPoint;Side[5].z4 = -nPoint;for (int i = 0; i < 6; i++){ //rotate around Y axisSide.x1 = Side.x1 * cos(angle) + Side.y1 * 0 - Side.z1 * sin(angle);Side.z1 = Side.x1 * -sin(angle)+ Side.y1 * 0 - Side.z1 * cos(angle);Side.x2 = Side.x2 * cos(angle) + Side.y2 * 0 - Side.z2 * sin(angle);Side.z2 = Side.x2 * -sin(angle)+ Side.y2 * 0 - Side.z2 * cos(angle);Side.x3 = Side.x3 * cos(angle) + Side.y3 * 0 - Side.z3 * sin(angle);Side.z3 = Side.x3 * -sin(angle)+ Side.y3 * 0 - Side.z3 * cos(angle);Side.x4 = Side.x4 * cos(angle) + Side.y4 * 0 - Side.z4 * sin(angle);Side.z4 = Side.x4 * -sin(angle)+ Side.y4 * 0 - Side.z4 * cos(angle);//world transformSide.x1+=0;Side.y1+=0;Side.z1+=4;Side.x2+=0;Side.y2+=0;Side.z2+=4;Side.x3+=0;Side.y3+=0;Side.z3+=4;Side.x4+=0;Side.y4+=0;Side.z4+=4;//make projectionSide.x1 /= Side.z1;Side.y1 /= Side.z1;Side.x2 /= Side.z2;Side.y2 /= Side.z2;Side.x3 /= Side.z3;Side.y3 /= Side.z3;Side.x4 /= Side.z4;Side.y4 /= Side.z4;//screen transformRECT rect;GetClientRect(&rect);Side.x1 = Side.x1 * rect.right/2 + rect.right/2;Side.y1 = (-Side.y1) * rect.bottom/2 + rect.bottom/2;Side.x2 = Side.x2 * rect.right/2 + rect.right/2;Side.y2 = (-Side.y2) * rect.bottom/2 + rect.bottom/2;Side.x3 = Side.x3 * rect.right/2 + rect.right/2;Side.y3 = (-Side.y3) * rect.bottom/2 + rect.bottom/2;Side.x4 = Side.x4 * rect.right/2 + rect.right/2;Side.y4 = (-Side.y4) * rect.bottom/2 + rect.bottom/2;//draw 3D cubeCPen penBlue;penBlue.CreatePen(PS_SOLID, 3, RGB(0, 0, 255));CPen* ppenOld;ppenOld=dc.SelectObject(&penBlue);dc.MoveTo(Side.x1, Side.y1);dc.LineTo(Side.x2, Side.y2);dc.LineTo(Side.x3, Side.y3);dc.LineTo(Side.x4, Side.y4);dc.LineTo(Side.x1, Side.y1);dc.SelectObject(ppenOld);}if (IsIconic()){...................}else{CDialog::OnPaint();}}
  Of course it doesn't work: And it's not because of the projection. You calculate the transformed vertex coordinates for 'x' component, then for 'y' component, but the formula of the 'y' contains 'x' too, which you have calculated, thus overwrote just before it. Use a separate, temporary array fro the transformed vertices, and display that.   ;  Besides what szecs has mentioned: The rotation formulas are not correct. Only 1 of the sine terms has to be negated (which one depends on whether you want to rotate lefthand or righthand) and none of the cosine terms has to be negated. E.g. so:Temp.x1 = Side.x1 * cos(angle) + Side.y1 * 0 + Side.z1 * sin(angle);Temp.z1 = Side.x1 * -sin(angle)+ Side.y1 * 0 + Side.z1 * cos(angle);;  It`s WORK! Special thank for haegarr and szecs!!! Now I'm almost a pro :-) !!!   