/* Функция преобразования вершин. * АРГУМЕНТЫ: * - геометрический объект: * as4GEOM *G; * - матрица преобразования: * MATR M; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ VOID AS4_GeomTransform( as4GEOM *G, MATR M ) { INT i, j; MATR InvM = MatrTranspose(MatrInverse(M)); InvM.A[3][0] = InvM.A[3][1] = InvM.A[3][2] = 0; for (i = 0; i < G->NumOfPrims; i++) for (j = 0; j < G->Prims[i].NumOfV; j++) { G->Prims[i].V[j].P = PointTransform(G->Prims[i].V[j].P, M); G->Prims[i].V[j].N = PointTransform(G->Prims[i].V[j].N, InvM); } } /* End of 'AS4_GeomTransform' function */
POINT DK6_RndWorldToScreen( VEC P ) { POINT Ps; P = PointTransform(P, DK6_RndMatrWorldViewProj); Ps.x = (P.X / 2 + 0.5) * DK6_Anim.W + DK6_Anim.PosModel.X; Ps.y = (-P.Y / 2 + 0.5) * DK6_Anim.H + DK6_Anim.PosModel.Y; return Ps; } /* End of 'DK6_RndWorldToScreen' function */
POINT AS4_RndWorldToScreen( VEC P ) { POINT Ps; VEC Pp; /* преобразование СК */ Pp = PointTransform(P, AS4_RndMatrWorldViewProj); /* проецирование */ Ps.x = ( Pp.x + 0.5) * (AS4_RndWs - 1); Ps.y = (-Pp.y + 0.5) * (AS4_RndHs - 1); return Ps; } /* End of 'AS4_RndWorldToScreen' 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)); }
/* ‘ункци¤ построени¤ объекта анимации. * ј–√”ћ≈Ќ“џ: * - указатель на "себ¤" - сам объект анимации: * 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 */