/* Camera move by Right-Axes function. * ARGUMENTS: * - Distance to move: * DBL Coef; * RETURNS: None. */ VOID II2_RndCameraMoveRight( ii2CAMERA *Cam, DBL Coef ) { Cam->Dir = VecSubVec(Cam->At, Cam->Loc); Cam->Right = VecCrossVec(Cam->Dir, Cam->Up); Cam->Loc = VecAddVec(Cam->Loc, VecMulNum(VecNormalize(Cam->Right), Coef)); Cam->At = VecAddVec(Cam->At, VecMulNum(VecNormalize(Cam->Right), Coef)); } /* End of 'II2_RndCameraMoveByDir' funciton */
/* GOST unit * response function * base unit response arguments */ static VOID GOSTUnitResponse( in1UNIT_GOST *Unit, in1ANIM *Ani ) { MATRIXd R; VEC M; if((Ani->KeysClick[VK_NUMPAD9] || Ani->JsButClick[4]) && !Ani->IsPause) { Unit->Head.Dir = VecNormalize( VecNeg( Unit->Head.Loc ) ); Unit->Head.Right = VecNormalize( VecCrossVec( Unit->Head.Dir, VecSet( 0, 1, 0 ) ) ); Unit->Head.Up = VecCrossVec( Unit->Head.Right, Unit->Head.Dir ); } R = MatrMulMatr( MatrMulMatr( MatrRotateVec( Ani->DeltaTime * Ani->JsR * 30, Unit->Head.Dir.X, Unit->Head.Dir.Y, Unit->Head.Dir.Z ), MatrRotateVec( Ani->DeltaTime * Ani->JsY * 30, Unit->Head.Right.X, Unit->Head.Right.Y, Unit->Head.Right.Z ) ), MatrRotateVec( Ani->DeltaTime * Ani->JsX * 30, Unit->Head.Up.X, Unit->Head.Up.Y, Unit->Head.Up.Z ) ); M = VecSet( Unit->Head.Dir.X * Ani->JsZ * 3 * Ani->DeltaTime, Unit->Head.Dir.Y * Ani->JsZ * 3 * Ani->DeltaTime, Unit->Head.Dir.Z * Ani->JsZ * 3 * Ani->DeltaTime ); if (Ani->JsPOV == 1 || Ani->JsPOV == 2 || Ani->JsPOV == 8) M = VecAddVec( M, VecMulNum( Unit->Head.Dir, Ani->DeltaTime * 3 ) ); if (Ani->JsPOV == 4 || Ani->JsPOV == 5 || Ani->JsPOV == 6) M = VecAddVec( M, VecMulNum( Unit->Head.Dir, -Ani->DeltaTime * 3 ) ); if (Ani->JsPOV == 2 || Ani->JsPOV == 3 || Ani->JsPOV == 4) M = VecAddVec( M, VecMulNum( Unit->Head.Right, Ani->DeltaTime * 3 ) ); if (Ani->JsPOV == 6 || Ani->JsPOV == 7 || Ani->JsPOV == 8) M = VecAddVec( M, VecMulNum( Unit->Head.Right, -Ani->DeltaTime * 3 ) ); Unit->Head.Dir = VectorTransformer( Unit->Head.Dir, R ); Unit->Head.Right = VectorTransformer( Unit->Head.Right, R ); Unit->Head.Up = VectorTransformer( Unit->Head.Up, R ); Unit->Head.Loc = VecAddVec( Unit->Head.Loc, M ); }
/* Unit render function. * ARGUMENTS: * - self-pointer to unit object: * al5UNIT_BALL *Uni; * - animation context: * al5ANIM *Ani; * RETURNS: None. */ static VOID AL5_UnitRender( al5UNIT_BALL_CONT *Uni, al5ANIM *Ani ) { VEC p = VecAddVec(Uni->Pos, Uni->Shift); SetDCBrushColor(Ani->hDC, Uni->Color); Ellipse(Ani->hDC, p.X - 20, p.Y - 20, p.X + 20, p.Y + 20); } /* End of 'AL5_UnitRender' function */
/* Unit render function. * ARGUMENTS: * - self-pointer to unit object: * VK3UNIT_CUBE *Uni; * - animation context: * VK3ANIM *Ani; * RETURNS: None. */ static VOID VK3_UnitRender( vk3UNIT_CUBE *Uni, vk3Anim *Ani ) { VK3_RndMatrWorld = MatrMulMatr(MatrScale(VecSet(0.1F, 0.1F, 0.1F)), MatrMulMatr(MatrRotateY((Uni->TimerSpeed * Ani->Time) * 30 + Uni->TimerShift), MatrTranslate(VecAddVec(Uni->Pos, VecMulNum(VecSet(Ani->JX, Ani->JY, Ani->JZ), 3))))); VK3_RndPrimDraw(&Uni->Pr); } /* End of ‘VK3_UnitRender' function */
/* Unit render function. * ARGUMENTS: * - self-pointer to unit object: * ra3UNIT_LUIGI *Uni; * - animation context: * ra3ANIM *Ani; * RETURNS: None. */ static VOID RA3_UnitRender( ra3UNIT_LUIGI *Uni, ra3ANIM *Ani ) { RA3_RndMatrWorld = MatrMulMatr(MatrScale(VecSet(1, 1, 1)), MatrMulMatr(MatrRotateY((Uni->TimerSpeed * Ani->Time) * 30 + Uni->TimerShift), MatrTranslate(VecAddVec(Uni->Pos, VecMulNum(VecSet(Ani->JX *2, Ani->JY * 2, Ani->JZ * 2), 3))))); RA3_RndObjDraw(&Uni->Luigi); } /* End of 'RA3_UnitRender' function */
/* Unit render function. * ARGUMENTS: * - self-pointer to unit object: * ra3UNIT_CUBE *Uni; * - animation context: * ra3ANIM *Ani; * RETURNS: None. */ static VOID RA3_UnitRender( ra3UNIT_CUBE *Uni, ra3ANIM *Ani ) { RA3_RndMatrWorld = MatrMulMatr(MatrScale(VecSet(0.1, 0.1, 0.1)), MatrMulMatr(MatrRotateY((Uni->TimerSpeed * Ani->Time) * 30 + Uni->TimerShift), MatrTranslate(VecAddVec(Uni->Pos, VecMulNum(VecSet(Ani->JX, Ani->JY, Ani->JZ), 3))))); RA3_RndPrimDraw(&Cube); } /* End of 'RA3_UnitRender' 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 */
/* Функция обновления межкадровых параметров объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * ao5UNIT_CTRL *Uni; * - указатель на контекст анимации: * ao5ANIM *Ani; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ static VOID AO5_AnimUnitResponse( ao5UNIT_CTRL *Uni, ao5ANIM *Ani ) { VEC Move, Dir, At; if (Ani->Keys[VK_ESCAPE]) AO5_AnimDoExit(); if (Ani->KeysClick['F']) AO5_AnimFlipFullScreen(); if (Ani->KeysClick['P']) AO5_AnimSetPause(!Ani->IsPause); /* позиционирование корабля */ //Uni->Omega = -3000 * Ani->JX * Ani->DeltaTime; //Uni->Head += -3 * 30 * Ani->JR * Ani->DeltaTime; Dir = VectorTransform(VecSet(0, 0, 1), MatrRotateY(Uni->Head)); //Uni->V += -3 * Ani->JY * Ani->DeltaTime; //Uni->V *= max(1 - Ani->GlobalDeltaTime, 0); if(Ani->Keys['D']) Uni->Head -= 1; if(Ani->Keys['A']) Uni->Head += 1; if(Ani->Keys['W']) Uni->V = -5; else if(Ani->Keys['S']) Uni->V = 5; else Uni->V = 0; Uni->Pos = VecAddVec(Uni->Pos, VecMulNum(Dir, Uni->V * Ani->DeltaTime)); Uni->Pos = VecAddVec(Uni->Pos, VecMulNum(VectorTransform(Dir, MatrRotateY(-90)), Uni->V)); //Uni->Pos.Y += 30 * (Ani->JButs[1] - Ani->JButs[2]) * Ani->DeltaTime; Uni->At = VecSubVec(Uni->Pos, VecMulNum(Dir, 100)); Uni->At.Y += 10; Move = VecSubVec(Uni->At, Uni->CPos); Uni->CPos = VecAddVec(Uni->CPos, VecMulNum(Move, Ani->DeltaTime)); AO5_RndMatrView = MatrView(Uni->CPos, Uni->Pos, VecSet(0, 1, 0)); AO5_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrRotateY(Uni->Head), MatrTranslate(Uni->Pos.X, Uni->Pos.Y, Uni->Pos.Z)), MatrScale(0.1, 0.1, 0.1)); } /* End of 'AO5_AnimUnitResponse' function */
/* Unit render function. * ARGUMENTS: * - self-pointer to unit object: * sa2UNIT_CUBE *Uni; * - animation context: * sa2ANIM *Ani; * RETURNS: None. */ static VOID SA2_UnitRender( sa2UNIT_CUBE *Uni, sa2ANIM *Ani ) { SA2_RndMatrWorld = MatrMulMatr(SA2_RndMatrWorld, MatrScale(VecSet(0.8F, 0.8F, 0.8F)), MatrTranslate(VecAddVec(Uni->Pos, VecMulNum(VecSet(Ani->JX, Ani->JY, Ani->JZ),3)))); /* SA2_RndMatrWorld = MatrMulMatr(MatrScale(VecSet(0.8F, 0.8F, 0.8F)), MatrMulMatr(MatrRotateY((Uni->TimerSpeed * Ani->Time) * 30 + Uni->TimerShift), MatrTranslate(VecAddVec(Uni->Pos, VecMulNum(VecSet(Ani->JX, Ani->JY, Ani->JZ), 3))))); */ SA2_RndObjDraw(&Uni->Obj); } /* End of 'SA2_UnitRender' 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)); }
/* Grid vertex normals evaluation function. * ARGUMENTS: * - grid pointer: * ak2GRID *G; * RETURNS: None. */ VOID AK2_GridEvalNormals( ak2GRID *G ) { INT p, x, y, n0, n1, n2; VEC N; /* Set to zero all vertex normqal vectors */ for (p = 0; p < G->W * G->H; p++) G->V[p].N = VecSet(0, 0, 0); /* Evaluate all triangles normals */ for (p = 0, y = 0; y < G->H - 1; y++, p++) for (x = 0; x < G->W - 1; x++, p++) { /* 0 triangle */ n0 = p; n1 = p + G->W + 1; n2 = p + G->W; N = AK2_TriangleNormal(G->V[n0].P, G->V[n1].P, G->V[n2].P); G->V[n0].N = VecAddVec(G->V[n0].N, N); G->V[n1].N = VecAddVec(G->V[n1].N, N); G->V[n2].N = VecAddVec(G->V[n2].N, N); /* 1 triangle */ n0 = p; n1 = p + 1; n2 = p + G->W + 1; N = AK2_TriangleNormal(G->V[n0].P, G->V[n1].P, G->V[n2].P); G->V[n0].N = VecAddVec(G->V[n0].N, N); G->V[n1].N = VecAddVec(G->V[n1].N, N); G->V[n2].N = VecAddVec(G->V[n2].N, N); } /* Normalize all vertex normqal vectors */ for (p = 0; p < G->W * G->H; p++) G->V[p].N = VecNormalize(G->V[p].N); } /* End of 'AK2_GridEvalNormals' function */
/* Primitive create function. * ARGUMENTS: * - primitive structure pointer: * avdPRIM *Pr; * - vertex array: * avdVERTEX *V; * - vertex array size: * INT NumOfV; * - index array: * INT *I; * - INT array size: * INT NumOfI; * RETURNS: None. */ VOID AVD_RndPrimCreate( avdPRIM *Pr, avdVERTEX *V, INT NumOfV, INT *I, INT NumOfI ) { INT i; memset(Pr, 0, sizeof(avdPRIM)); Pr->M = MatrIdentity(); Pr->NumOfI = NumOfI; /* Get min-max primitive info */ Pr->Min = Pr->Max = V[0].P; for (i = 1; i < NumOfV; i++) { Pr->Min.X = AVD_MIN(Pr->Min.X, V[i].P.X); Pr->Min.Y = AVD_MIN(Pr->Min.Y, V[i].P.Y); Pr->Min.Z = AVD_MIN(Pr->Min.Z, V[i].P.Z); Pr->Max.X = AVD_MAX(Pr->Max.X, V[i].P.X); Pr->Max.Y = AVD_MAX(Pr->Max.Y, V[i].P.Y); Pr->Max.Z = AVD_MAX(Pr->Max.Z, V[i].P.Z); } /* Set central point */ Pr->Center = VecDivNum(VecAddVec(Pr->Min, Pr->Max), 2); /* Create OpenGL buffers */ glGenVertexArrays(1, &Pr->VA); glGenBuffers(1, &Pr->VBuf); glGenBuffers(1, &Pr->IBuf); /* Activate vertex array */ glBindVertexArray(Pr->VA); /* Activate vertex buffer */ glBindBuffer(GL_ARRAY_BUFFER, Pr->VBuf); /* Store vertex data */ glBufferData(GL_ARRAY_BUFFER, sizeof(avdVERTEX) * NumOfV, V, GL_STATIC_DRAW); /* Setup data order */ /* layout, * components count, * type * should be normalize, * vertex structure size in bytes (stride), * offset in bytes to field start */ glVertexAttribPointer(0, 3, GL_FLOAT, FALSE, sizeof(avdVERTEX), (VOID *)0); /* position */ glVertexAttribPointer(1, 2, GL_FLOAT, FALSE, sizeof(avdVERTEX), (VOID *)sizeof(VEC)); /* texture coordinates */ glVertexAttribPointer(2, 3, GL_FLOAT, FALSE, sizeof(avdVERTEX), (VOID *)(sizeof(VEC) + sizeof(VEC2))); /* normal */ glVertexAttribPointer(3, 4, GL_FLOAT, FALSE, sizeof(avdVERTEX), (VOID *)(sizeof(VEC) * 2 + sizeof(VEC2))); /* color */ /* Enable used attributes */ glEnableVertexAttribArray(0); glEnableVertexAttribArray(1); glEnableVertexAttribArray(2); glEnableVertexAttribArray(3); /* Indices */ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Pr->IBuf); glBufferData(GL_ELEMENT_ARRAY_BUFFER, sizeof(INT) * NumOfI, I, GL_STATIC_DRAW); /* Disable vertex array */ glBindVertexArray(0); glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0); } /* End of 'VG4_RndPrimCreate' function */
/* Unit render function. * ARGUMENTS: * - self-pointer to unit object: * ra3UNIT_BALL *Uni; * - animation context: * ra3ANIM *Ani; * RETURNS: None. */ static VOID RA3_UnitRender( ra3UNIT_BALL *Uni, ra3ANIM *Ani ) { VEC p = VecAddVec(Uni->Pos, Uni->Shift); p = p; } /* End of 'RA3_UnitRender' function */
/* Camera move by Up-Axes function. * ARGUMENTS: * - Distance to move: * DBL Coef; * RETURNS: None. */ VOID II2_RndCameraMoveUp( ii2CAMERA *Cam, DBL Coef ) { Cam->Loc = VecAddVec(Cam->Loc, VecMulNum(VecNormalize(Cam->Up), Coef)); Cam->At = VecAddVec(Cam->At, VecMulNum(VecNormalize(Cam->Up), Coef)); } /* End of 'II2_RndCameraMoveByDir' funciton */
/* Camera move by Dir-axes properties * ARGUMENTS: * - Distance to move: * DBL Coef; * RETURNS: None. */ VOID II2_RndCameraMoveDir( ii2CAMERA *Cam, DBL Coef ) { Cam->Dir = VecNormalize(VecSubVec(Cam->At, Cam->Loc)); Cam->Loc = VecAddVec(Cam->Loc, VecMulNum(Cam->Dir, Coef)); Cam->At = VecAddVec(Cam->At, VecMulNum(Cam->Dir, Coef)); } /* End of 'II2_RndCameraMoveByDir' funciton */
/* Функция обновления межкадровых параметров объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * 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 */