/* Begin of 'WinMain' function */ INT WINAPI WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, CHAR *CmdLine, INT ShowCmd ) { MATR m = {{ {2, 0, 0, 0}, {1, 2, 0, 0}, {1, 1, 2, 0}, {1, 1, 1, 2} }}; DBL g; m = MatrIdentity(); m = MatrTranslate(VecSet(1, 2, 3)); m = MatrScale(VecSet(1, 2, 3)); m = MatrRotateX(30); m = MatrRotateY(30); m = MatrRotateZ(30); m = MatrRotate(30, VecSet(1, 2, 3)); m = MatrMulMatr(MatrRotateX(90), MatrScale(VecSet(2, 2, 2))); m = MatrInverse(m); g = MatrDeterm(m); m = MatrTranspose(m); return 0; }/* Begin of 'WinMain' function */
/* Функция построения объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * AO5UNIT_MODEL *Uni; * - указатель на контекст анимации: * AO5ANIM *Ani; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ static VOID AO5_AnimUnitRender( ao5UNIT_MODEL *Uni, ao5ANIM *Ani ) { INT i, j; static BOOL ok = TRUE; AO5_RndMatrView = MatrView(VecSet(0, 5, 10), VecSet(0, 0, 0), VecSet(0, 1, 0)); if (Ani->KeysClick['W']) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); if (Ani->KeysClick['Q']) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_DEPTH_TEST); if (ok) AO5_RndMatrWorld = MatrMulMatr(MatrRotateY(30 * Ani->Time + 180), MatrTranslate(0, -1.5, 0)); else AO5_RndMatrWorld = MatrMulMatr(MatrRotateX(90), MatrRotateZ(90)); if(Ani->KeysClick['Z']) ok = !ok; for (i = 0; i < 1; i++) for (j = 0; j < 1; j++) { glColor3d(i & 1, j & 1, 1 - ((i & 1) + (j & 1)) / 2); AO5_GeomDraw(&Uni->Model); } //MatrMulMatr(MatrRotateZ(30 * sin(Ani->Time * 3.0)), MatrRotateY(30 * Ani->Time)); //AO5_GeomDraw(&Uni->Geom); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Uni->TextId); //AO5_PrimDraw(&Uni->Pr); } /* End of 'AO5_AnimUnitRender' function */
/* Функция построения объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * vg4UNIT_CTRL *Uni; * - указатель на контекст анимации: * vg4ANIM *Ani; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ static VOID VG4_AnimUnitRender( vg4UNIT_CTRL *Uni, vg4ANIM *Ani ) { HFONT hFntOld = SelectObject(Ani->hDC, Uni->hFnt); static DBL count = 30; static CHAR Buf[1000]; count += Ani->GlobalDeltaTime; if (count > 1) { count = 0; sprintf(Buf, "FPS: %.3f", Ani->FPS); SetWindowText(Ani->hWnd, Buf); } /* вертолет */ VG4_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrRotateX(-Ani->JY * 30), MatrRotateZ(Ani->JX * 59)), MatrRotateY(Uni->Head)), MatrTranslate(Uni->Pos.X, Uni->Pos.Y, Uni->Pos.Z)); VG4_GeomDraw(&Uni->Helic); /* оси */ VG4_RndMatrWorld = MatrIdentity(); VG4_GeomDraw(&Uni->Axes); //VG4_RndMatrWorld = MatrTranslate(Uni->At.X, Uni->At.Y, Uni->At.Z); //VG4_PrimDraw(&Uni->Sph); } /* End of 'VG4_AnimUnitRender' function */
/* Функция построения объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * od6UNIT_COW *Unit; * - указатель на контекст анимации: * od6ANIM *Ani; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ static VOID CowUnitRender( od6UNIT_COW *Unit, od6ANIM *Ani ) { INT i, N = 0; VEC p = {1, 0, 0}; POINT pt; static DBL Delta = 0.1; Delta += Ani->JZ * Ani->GlobalDeltaTime; OD6_RndMatrView = MatrViewLookAt(VecMulMatr(VecSet(0, 0, Ani->JX * Delta + 15), MatrRotateX(90 * Ani->JY)), VecSet(0, 0, 0), VecSet(0, 1, 0)); OD6_RndMatrWorld = MatrRotateZ(-Ani->Time); OD6_RndMatrWorld = MatrMulMatr(OD6_RndMatrWorld, MatrScale(0.30, 0.30, 0.30)); SetDCBrushColor(Ani->hDC, RGB(255, 255, 255)); SetDCPenColor(Ani->hDC, RGB(255, 255, 255)); srand(30); for (i = 0; i < N; i++) { p.X = 2.0 * rand() / RAND_MAX - 1 ; p.Y = 2.0 * rand() / RAND_MAX - 1 ; p.Z = 2.0 * rand() / RAND_MAX - 1 ; pt = OD6_RndWorldToScreen(p); if (i == 0) MoveToEx(Ani->hDC, pt.x , pt.y, NULL); else LineTo(Ani->hDC, pt.x , pt.y); } OD6_RndGObjDraw(&Unit->Cow, Ani->hDC); /* OD6_RndMatrWorld = MatrRotateZ(-Ani->GlobalTime / 60); OD6_RndMatrWorld = MatrMulMatr(OD6_RndMatrWorld, MatrScale(0.30, 0.30, 0.30)); SetDCBrushColor(Ani->hDC, RGB(0, 255, 255)); SetDCPenColor(Ani->hDC, RGB(0, 255, 255)); OD6_RndGObjDraw(&Unit->Cow, Ani->hDC); OD6_RndMatrWorld = MatrRotateZ(-Ani->GlobalTime / 60 / 60); OD6_RndMatrWorld = MatrMulMatr(OD6_RndMatrWorld, MatrScale(0.30, 0.30, 0.30)); SetDCBrushColor(Ani->hDC, RGB(255, 255, 0)); SetDCPenColor(Ani->hDC, RGB(255, 255, 0)); OD6_RndGObjDraw(&Unit->Cow, Ani->hDC); OD6_RndMatrWorld = MatrRotateY(Ani->Time * 30); OD6_RndMatrWorld = MatrMulMatr(OD6_RndMatrWorld, MatrScale(0.30, 0.30, 0.30)); OD6_RndMatrWorld = MatrMulMatr(MatrTranslate(0.0, 0.0, 3 * 3.30), OD6_RndMatrWorld); OD6_RndGObjDraw(&Unit->Cow, Ani->hDC); */ } /* End of 'CowUnitRender' function */
/* Camera rotation by camera-axes-right function. * ARGUMENTS: * - Angle: * DBL Angle; * RETURNS: None. */ VOID II2_RndCameraRotateRight( ii2CAMERA *Cam, DBL Angle ) { MATR RotMat; /* if (Angle == 0) return; */ Cam->Dir = VecSubVec(Cam->At, Cam->Loc); Cam->Right = VecCrossVec(VecNormalize(Cam->Dir), Cam->Up); II2_RndCameraNormalize(Cam); RotMat = II2_RndCameraGetMatrix(Cam); RotMat = MatrMulMatr(MatrRotateZ(Angle), RotMat); Cam->At = VecAddVec(Cam->Loc, VecSet(RotMat.A[0][0], RotMat.A[0][1], RotMat.A[0][2])); } /* End of 'II2_RndCameraRotateRight' funciton */
/* Camera rotation by camera-axes-right function. * ARGUMENTS: * - Angle: * DBL Angle; * RETURNS: None. */ VOID RK2_RndCameraRotateRight( rk2CAMERA *Cam, DBL Angle ) { rk2MATR4x4 RotMat; /* if (Angle == 0) return; */ Cam->Dir = VecSubVec(Cam->At, Cam->Loc); Cam->Right = VecCrossVec(VecNormalize(Cam->Dir), Cam->Up); RK2_RndCameraNormalize(Cam); RotMat = RK2_RndCameraGetMatrix(Cam); RotMat = MatrMultMatr(MatrRotateZ(MatrDefault(), Angle), RotMat); RK2_RndCameraSet(Cam, Cam->Loc, /* Location */ VecSumVec(Cam->Loc, VecSet(RotMat.A[0][0], RotMat.A[0][1], RotMat.A[0][2])), /* At */ Cam->Up); /* Up */ } /* End of 'RK2_RndCameraRotateRight' funciton */
mtl.Ka = VecSet(0.1, 0.1, 0.1); mtl.Kd = VecSet(1, 1, 1); mtl.Ks = VecSet(0, 0, 0); mtl.Phong = 30; mtl.Trans = 1; mtl.TexNo = 0; mtl.MapD[0] = 0; strcpy(mtl.MapD, "map2-hf.bmp"); strcpy(mtl.Name, "Height Field Material"); prim.Mtl = VG4_GeomAddMaterial(&Unit->Obj, &mtl); VG4_GeomAddPrim(&Unit->Obj, &prim); . . . Ani->MatrWorld = MatrIdentity(); Ani->MatrView = MatrViewLookAt( VecMulMatr(VecMulMatr(VecSet(25, 25, 25), MatrRotateY(Ani->JR * 180)), MatrRotateZ(Ani->JY * 180)), VecSet(0, 0, 0), VecSet(0, 1, 0)); WVP = MatrMulMatr(VG4_Anim.MatrWorld, MatrMulMatr(VG4_Anim.MatrView, VG4_Anim.MatrProjection)); glLoadMatrixf(WVP.A[0]); . . . Ani->MatrWorld = MatrMulMatr(MatrRotateX(-0), MatrTranslate(0, 0, 0.30 * sin(Ani->Time))); VG4_GeomDraw(&Unit->Obj);
/* ‘ункци¤ построени¤ объекта анимации. * ј–√”ћ≈Ќ“џ: * - указатель на "себ¤" - сам объект анимации: * ok2UNIT_CUBE *Unit; * - указатель на контекст анимации: * ok2ANIM *Ani; * ¬ќ«¬–јўј≈ћќ≈ «Ќј„≈Ќ»≈: Ќет. */ static VOID CubeUnitRender( ok2UNIT_CUBE *Unit, ok2ANIM *Ani ) { /* INT i, s = 5, N = 0; VEC p = {1, 0, 0}; static FLT Delta = 0.1; MATR WVP; Delta += Ani->JZ * Ani->GlobalDeltaTime; //Ani->MatrWorld = MatrRotateY(30); //Ani->MatrView = MatrLookAt(VecSet(15, 15, 15), VecSet(0, 0, 0), VecSet(0, 1, 0)); Ani->MatrView = MatrLookAt(PointTransform(VecSet(20, 20, Ani->JX * Delta + 20), MatrRotateX(80 * Ani->JY)), VecSet(0, 0, 0), VecSet(0, 1, 0)); Ani->MatrWorld = MatrMulMatr(Ani->MatrWorld, MatrRotateX(Ani->DeltaTime * 80)); for (i = 0; i < 12; i++) { Ani->MatrWorld = MatrMulMatr(MatrTranslate(0.0, 5.0, 0.0), Ani->MatrWorld); Ani->MatrWorld = MatrMulMatr(MatrRotate(30, 1.0, 0.0, 1.0), Ani->MatrWorld); WVP = MatrMulMatr(Ani->MatrWorld, MatrMulMatr(Ani->MatrView, Ani->MatrProjection)); glLoadMatrixf(WVP.A[0]); OK2_RndGObjDraw(&Unit->Cow, Ani->hDC); } //OK2_RndGObjDraw(&Unit->Cow, Ani->hDC); */ INT i; MATR WVP; static DBL time; /* оси и позици¤ наблюдател¤ */ Ani->MatrWorld = MatrIdenity(); Ani->MatrView = MatrLookAt( PointTransform(PointTransform(VecSet(25, 25, 25), MatrRotateY(Ani->JR * 180)), MatrRotateZ(Ani->JY * 180)), VecSet(0, 0, 0), VecSet(0, 1, 0)); WVP = MatrMulMatr(OK2_Anim.MatrWorld, MatrMulMatr(OK2_Anim.MatrView, OK2_Anim.MatrProjection)); glLoadMatrixf(WVP.A[0]); glLineWidth(3); glBegin(GL_LINES); glColor3d(1, 0.5, 0.5); glVertex3d(-3, 0, 0); glVertex4d(1, 0, 0, 0); glColor3d(0.5, 1, 0.5); glVertex3d(0, -3, 0); glVertex4d(0, 1, 0, 0); glColor3d(0.5, 0.5, 1); glVertex3d(0, 0, -3); glVertex4d(0, 0, 1, 0); glEnd(); glColorMask(1, 1, 1, 0); for (i = -3; i < 30; i++) { glBegin(GL_TRIANGLE_STRIP); glVertex3d(-0.1, -0.1, i); glVertex3d(-0.1, 0.1, i); glVertex3d( 0.1, -0.1, i); glVertex3d( 0.1, 0.1, i); glEnd(); } /* –исуем примитивы */ time += Ani->GlobalDeltaTime; if (time > 1) { time = 0; OK2_ShadProgClose(OK2_ShaderProg); OK2_ShaderProg = OK2_ShadProgInit("a.vert", "a.frag"); } glLineWidth(1); if (Ani->Keys['Q']) glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); else glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); //Ani->MatrWorld = MatrTranslate(0, 0, 0.30 * sin(Ani->Time)); Ani->MatrWorld = MatrMulMatr(Ani->MatrWorld, MatrRotateY(30.0 * Ani->Time)); /* for (i = 0; i < 12; i++) { Ani->MatrWorld = MatrMulMatr(MatrRotate(30.0, 0.0, 1.0, 0.0), Ani->MatrWorld); Ani->MatrWorld = MatrMulMatr(MatrTranslate(1.0, 0.0, 0.0), Ani->MatrWorld); OK2_GeomDraw(&Unit->Geom); } */ /* for (i = 0; i < 6; i++) DrawUnitInPosition(&Unit->Geom[i], Ani, Unit->Scale`[i], 10.0, 30.0); */ Ani->MatrWorld = MatrMulMatr(Ani->MatrWorld, MatrScale(0.001, 0.001, 0.001)); for (i = 0; i < 12; i++) { Ani->MatrWorld = MatrMulMatr(MatrRotate(30.0, 0.0, 1.0, 0.0), Ani->MatrWorld); Ani->MatrWorld = MatrMulMatr(MatrTranslate(20000.0, 0.0, 0.0), Ani->MatrWorld); //Ani->MatrWorld = MatrMulMatr(MatrRotate(30.0, 0.0, 1.0, 0.0), Ani->MatrWorld); OK2_GeomDraw(&Unit->Geom[3]); Ani->MatrWorld = MatrMulMatr(MatrTranslate(-20000.0, 0.0, 0.0), Ani->MatrWorld); } //Ani->MatrWorld = MatrMulMatr(Ani->MatrWorld, MatrScale(50, 50, 50)); } /* End of 'OK2_AnimUnitRender' function */