/* 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 */
/* Unit clock inter frame events handle function. * ARGUMENTS: * - self-pointer to unit object: * vg4UNIT_CLOCK *Uni; * - animation context: * vg4ANIM *Ani; * RETURNS: None. */ static VOID VG4_UnitResponse( vg4UNIT_CLOCK *Uni, vg4ANIM *Ani ) { DBL r; if (Ani->Keys[VK_SPACE]) VG4_AnimAddUnit(VG4_UnitCreateBall()); if (Ani->Keys['C']) VG4_AnimAddUnit(VG4_UnitCreateCube()); if (Ani->KeysClick[VK_RETURN] && Ani->Keys[VK_MENU]) VG4_AnimFlipFullScreen(); if (Ani->KeysClick[VK_ESCAPE]) VG4_AnimDoExit(); if (Ani->KeysClick['P']) Ani->IsPause = !Ani->IsPause; /* Uni->Pos.Y += Ani->JY * Ani->GlobalDeltaTime; */ Uni->Pos = VecMulMatr43(Uni->Pos, MatrRotateX(59 * Ani->JY * Ani->GlobalDeltaTime)); Uni->Pos = VecMulMatr43(Uni->Pos, MatrRotateY(59 * Ani->JX * Ani->GlobalDeltaTime)); if (Ani->Keys[VK_LBUTTON]) { Uni->Pos = VecMulMatr43(Uni->Pos, MatrRotateY(59 * Ani->Mdx * Ani->GlobalDeltaTime)); Uni->Pos = VecMulMatr43(Uni->Pos, MatrRotateX(59 * Ani->Mdy * Ani->GlobalDeltaTime)); } Uni->Pos = VecMulMatr43(Uni->Pos, MatrRotateY(59 * Ani->Keys[VK_RIGHT] * Ani->GlobalDeltaTime)); Uni->Pos = VecMulMatr43(Uni->Pos, MatrRotateY(-59 * Ani->Keys[VK_LEFT] * Ani->GlobalDeltaTime)); r = VecLen(Uni->Pos); Uni->Pos = VecMulNum(Uni->Pos, (r + Ani->Mdz * Ani->DeltaTime * 0.1) / r); VG4_RndMatrView = MatrView(Uni->Pos, VecSet(0, 0, 0), VecSet(0, 1, 0)); } /* End of 'VG4_UnitResponse' 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 */
static VOID CubeUnitRender( as4UNIT_CUBE *Unit, as4ANIM *Ani ) { VEC p = {1, 0, 0}; /*POINT pt;*/ /*AS4_RndMatrView = MatrViewLookAt(VecSet(5, 5, 5), VecSet(0, 0, 0), VecSet(0, 1, 0)); AS4_RndMatrWorld = MatrRotateY(Ani->Time * 30);*/ AS4_RndMatrView = MatrViewLookAt(VecTransform(VecSet(0, 0, 15), MatrRotateX(0)), VecSet(0, 0, 0), VecSet(0, 1, 0)); AS4_RndMatrWorld = MatrRotateY(-cl.x / 3.0); AS4_RndMatrWorld = MatrMulMatr(AS4_RndMatrWorld, MatrRotateX(-cl.y / 3.0)); AS4_RndMatrWorld = MatrMulMatr(AS4_RndMatrWorld, MatrScale(3.5 - AS4_Anim.JPOV / 8.0, 3.5 - AS4_Anim.JPOV / 8.0, 3.5 - AS4_Anim.JPOV / 8.0)); SelectObject(Ani->hDC, GetStockObject(NULL_PEN)); SetDCBrushColor(Ani->hDC, RGB(0, 0, 0)); AS4_RndGObjDraw(&Unit->Cow, Ani->hDC); } /* End of 'CubeUnitRender' 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-dir function. * ARGUMENTS: * - Angle: * DBL Angle; * RETURNS: None. */ VOID II2_RndCameraRotateDir( ii2CAMERA *Cam, DBL Angle ) { MATR RotMat; Cam->Dir = VecSubVec(Cam->At, Cam->Loc); Cam->Right = VecCrossVec(VecNormalize(Cam->Dir), Cam->Up); II2_RndCameraNormalize(Cam); RotMat = II2_RndCameraGetMatrix(Cam); RotMat = MatrMulMatr(MatrRotateX(Angle), RotMat); Cam->At = VecAddVec(Cam->Loc, VecSet(RotMat.A[0][0], RotMat.A[0][1], RotMat.A[0][2])); } /* End of 'II2_RndCameraRotateDir' funciton */
/* Функция построения объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * ak1UNIT_BALL *Uni; * - указатель на контекст анимации: * ak1ANIM *Ani; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ static VOID AK1_AnimCowRender( ak1UNIT_COW *Uni, ak1ANIM *Ani ) { int i, l = -1; DBL X1 = Ani->PosX; AK1_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrRotateX(Ani->AngleX), MatrRotateY(Ani->AngleY)), MatrScale(10, 10, 10)); AK1_RndMatrView = MatrView(VecSet(8, 8, 8), VecSet(0, 0, 0), VecSet(0, 1, 0)); SetDCPenColor(Ani->hDC, RGB(255, 255, 255)); // AK1_RndGObjDraw(&Uni->Model); for (i = 0; i < 3; i++) { Ani->PosX = X1 + (i + l) * 600; AK1_RndGObjDraw(&Uni->Model); } Ani->PosX = X1; } /* End of 'ak1_AnimUnitRender' function */
/* Camera rotation by camera-axes-dir function. * ARGUMENTS: * - Angle: * DBL Angle; * RETURNS: None. */ VOID RK2_RndCameraRotateDir( rk2CAMERA *Cam, DBL Angle ) { rk2MATR4x4 RotMat; Cam->Dir = VecSubVec(Cam->At, Cam->Loc); Cam->Right = VecCrossVec(VecNormalize(Cam->Dir), Cam->Up); RK2_RndCameraNormalize(Cam); RotMat = RK2_RndCameraGetMatrix(Cam); RotMat = MatrMultMatr(MatrRotateX(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_RndCameraRotateDir' funciton */
/* Draw object functioln. * ARGUMENTS: * - context of the window: * HDC hDC; * - the size of the window: * INT W, H; * RETURNS: None. */ VOID ObjDraw( HDC hDC, INT X, INT Y, DWORD Color, PK2ANIM *Ani ) { INT i; DBL x = sin(30); srand(30); for (i = 0; i < ObjNumOfV; i++) { if (!Ani->IsPause) ObjV[i] = VecMulMatr3(ObjV[i], MatrMulMatr(MatrRotateY(sin(Ani->Time * 0.5)), MatrRotateX(sin(Ani->Time * 3)))); else ObjV[i] = VecMulMatr3(ObjV[i], MatrIdentity()); SetDCBrushColor(hDC, Color); Ellipse(hDC,X + ObjV[i].X - 4, Y - ObjV[i].Y - 4, X + ObjV[i].X + 4, Y - ObjV[i].Y + 4); } } /* End of 'ObjDraw' function */
static VOID MP2_UnitResponse( mp2CONTROL *Uni, mp2ANIM *Ani ) { DBL r; VEC Dir = VecNormalize(VecSubVec(View, Uni->Pos)), Right = VecNormalize(VecCrossVec(Dir, VecSet(0, 1, 0))); if (Ani->Keys['T']) glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); if (Ani->Keys['Y']) glPolygonMode(GL_FRONT, GL_LINE); if (Ani->Keys['U']) glPolygonMode(GL_BACK, GL_LINE); /*if (Ani->Keys[VK_SPACE]) MP2_AnimAddUnit(MP2_UnitCreateBall()); */ if (Ani->KeysClick['C']) MP2_AnimAddUnit(MP2_UnitCreateCube(/*Rnd1() * 4, Rnd1() * 4, Rnd1() * 4*/0, 0, 0)); if (Ani->KeysClick['V']) MP2_AnimAddUnit(MP2_UnitCreateSTATICMODEL(/*Rnd1() * 4, Rnd1() * 4, Rnd1() * 4*/0, 0, 0)); if (Ani->KeysClick[VK_RETURN] && Ani->Keys[VK_MENU]) MP2_FlipFullScreen(MP2_Anim.hWnd); /*if (Ani->KeysClick[VK_ESCAPE]) MP2_AnimDoExit();*/ if (Ani->KeysClick['P']) Ani->IsPause = !Ani->IsPause; /* Uni->Pos.Y += Ani->JY * Ani->GlobalDeltaTime; */ Uni->Pos = PointTransform(Uni->Pos, MatrRotate((50 * Ani->JY * Ani->GlobalDeltaTime), Right)); Uni->Pos = PointTransform(Uni->Pos, MatrRotateY(10 * Ani->JX * Ani->GlobalDeltaTime)); if (Ani->Keys[VK_LBUTTON]) { Uni->Pos = PointTransform(Uni->Pos, MatrRotateY(10 * Ani->Mdx * Ani->GlobalDeltaTime)); Uni->Pos = PointTransform(Uni->Pos, MatrRotateX(10 * Ani->Mdy * Ani->GlobalDeltaTime)); } View.X += Ani->JZ / 10; View.Z += Ani->JR / 10; Uni->Pos = PointTransform(Uni->Pos, MatrRotateY(10 * Ani->Keys[VK_RIGHT] * Ani->GlobalDeltaTime)); Uni->Pos = PointTransform(Uni->Pos, MatrRotateY(-10 * Ani->Keys[VK_LEFT] * Ani->GlobalDeltaTime)); r = VecLen(Uni->Pos); Uni->Pos = VecMulNum(Uni->Pos, (r + (-Ani->Mdz) * Ani->DeltaTime * 1.0) / r); MP2_RndMatrView = MatrView(VecAddVec(Uni->Pos, View), View, VecSet(0, 1, 0)); }
/* Функция обновления межкадровых параметров объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * vg4UNIT_CTRL *Uni; * - указатель на контекст анимации: * vg4ANIM *Ani; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ static VOID VG4_AnimUnitResponse( vg4UNIT_CTRL *Uni, vg4ANIM *Ani ) { VEC Dir, Move; static FLT y = -0.067452297, z = 2.6340842; static DBL time = 5; time += VG4_Anim.GlobalDeltaTime; if (time > 5) { time = 0; VG4_ShaderFree(Uni->Axes.ProgId); VG4_ShaderFree(Uni->Helic.ProgId); Uni->Helic.ProgId = VG4_ShaderLoad("HELIC"); Uni->Axes.ProgId = VG4_ShaderLoad("AXIS"); Uni->Sph.ProgId = Uni->Axes.ProgId; } /* позиционирование вертолета */ Uni->Omega = -3000 * Ani->JR * Ani->DeltaTime; Uni->Head += -3 * 30 * Ani->JR * Ani->DeltaTime; Dir = VecMulMatr3(VecSet(0, 0, 1), MatrRotateY(Uni->Head)); Uni->V += -30 * Ani->JY * Ani->DeltaTime; Uni->V *= max(1 - Ani->GlobalDeltaTime, 0); Uni->Pos = VecAddVec(Uni->Pos, VecMulNum(Dir, Uni->V * Ani->DeltaTime)); Uni->Pos = VecAddVec(Uni->Pos, VecMulNum(VecMulMatr3(Dir, MatrRotateY(-90)), 30 * Ani->JX * Ani->DeltaTime)); Uni->Pos.Y += 30 * (Ani->JButs[1] - Ani->JButs[2]) * Ani->DeltaTime; /* точка "интереса" */ Uni->At = VecSubVec(Uni->Pos, VecMulNum(Dir, 9)); Uni->At.Y += 5.30; Move = VecSubVec(Uni->At, Uni->CPos); Uni->CPos = VecAddVec(Uni->CPos, VecMulNum(Move, Ani->DeltaTime)); VG4_RndMatrView = MatrView(Uni->CPos, Uni->Pos, 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); if (Ani->Keys[VK_ESCAPE]) VG4_AnimDoExit(); if (Ani->KeysClick['F']) VG4_AnimFlipFullScreen(); if (Ani->KeysClick['P']) VG4_AnimSetPause(!Ani->IsPause); /* анимация вертолета */ Uni->Helic.Prims[2].M = MatrRotateY(999 * Ani->Time); Uni->Helic.Prims[4].M = MatrMulMatr(MatrMulMatr(MatrTranslate(0, y, z), MatrRotateX(888 * Ani->Time)), MatrTranslate(0, -y, -z)); y += Ani->Keys[VK_ADD] * Ani->GlobalDeltaTime * 0.1 - Ani->Keys[VK_SUBTRACT] * Ani->GlobalDeltaTime * 0.1; z += Ani->Keys['A'] * Ani->GlobalDeltaTime * 0.1 - Ani->Keys['Z'] * Ani->GlobalDeltaTime * 0.1; } /* End of 'VG4_AnimUnitResponse' function */
/* Функция инициализации объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * vg4UNIT_CTRL *Uni; * - указатель на контекст анимации: * vg4ANIM *Ani; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ static VOID VG4_AnimUnitInit( vg4UNIT_CTRL *Uni, vg4ANIM *Ani ) { vg4PRIM pr; Uni->hFnt = CreateFont(30, 0, 0, 0, FW_BOLD, FALSE, FALSE, FALSE, RUSSIAN_CHARSET, OUT_DEFAULT_PRECIS, CLIP_DEFAULT_PRECIS, PROOF_QUALITY, VARIABLE_PITCH, "Bookman Old Style"); VG4_RndPrimMatrConvert = MatrMulMatr(MatrMulMatr(MatrScale(0.0024, 0.0024, 0.0024), MatrRotateX(-0)), MatrTranslate(0, 0, 0)); VG4_GeomLoad(&Uni->Helic, "MODELS\\Mi8\\havoc.g3d"); Uni->Helic.ProgId = VG4_ShaderLoad("HELIC"); VG4_RndPrimDefaultColor = ColorSet(1, 0, 0, 1); VG4_PrimCreatePlane(&pr, VecSet(-500, -0.030, 0), VecSet(1000, 0, 0), VecSet(0, 0.059, 0), 2, 2); VG4_GeomAddPrim(&Uni->Axes, &pr); VG4_RndPrimDefaultColor = ColorSet(0, 0, 1, 1); VG4_PrimCreatePlane(&pr, VecSet(0, -0.030, -500), VecSet(0, 0, 1000), VecSet(0, 0.059, 0), 2, 2); VG4_GeomAddPrim(&Uni->Axes, &pr); VG4_RndPrimDefaultColor = ColorSet(0, 1, 0, 1); VG4_PrimCreatePlane(&pr, VecSet(-0.030, -500, 0), VecSet(0, 1000, 0), VecSet(0.059, 0, 0), 2, 2); VG4_GeomAddPrim(&Uni->Axes, &pr); Uni->Axes.ProgId = VG4_ShaderLoad("AXIS"); VG4_RndPrimDefaultColor = ColorSet(0.7, 0.5, 0.3, 1); VG4_PrimCreateSphere(&Uni->Sph, VecSet(0, 0, 0), 1, 8, 15); Uni->Sph.ProgId = Uni->Axes.ProgId; /* начальные параметры вертолета */ Uni->Pos = VecSet(0, 18, 0); Uni->V = 0; Uni->Head = 0; Uni->Omega = 0; Uni->CPos = VecSet(59, 30, 59); } /* End of 'VG4_AnimUnitInit' function */