/* Функция построения объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * 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 */
/* Primitive draw function. * ARGUMENTS: * - primtive to draw: * vg4PRIM *Pr; * RETURNS: None. */ VOID VG4_RndPrimDraw( vg4PRIM *Pr ) { INT i; MATR M; POINT *pts; /* Build transform matrix */ M = MatrMulMatr(VG4_RndMatrWorld, MatrMulMatr(VG4_RndMatrView, VG4_RndMatrProj)); /* Transform all points */ pts = malloc(sizeof(POINT) * Pr->NumOfP); if (pts == NULL) return; for (i = 0; i < Pr->NumOfP; i++) { /* NDC */ VEC p = VecMulMatr(Pr->P[i], M); pts[i].x = (p.X + 1) * VG4_Anim.W / 2; pts[i].y = (-p.Y + 1) * VG4_Anim.H / 2; } /* Draw all lines */ for (i = 0; i < Pr->NumOfE; i++) { INT n0 = Pr->Edges[i][0], n1 = Pr->Edges[i][1]; MoveToEx(VG4_Anim.hDC, pts[n0].x, pts[n0].y, NULL); LineTo(VG4_Anim.hDC, pts[n1].x, pts[n1].y); } free(pts); } /* End of 'VG4_RndPrimDraw' function */
VOID DK6_RndGObjDraw( DK6GOBJ *GObj ) { INT i; POINT *pnts; if ((pnts = malloc(sizeof(POINT) * GObj->NumOfV)) == NULL) return; DK6_RndMatrWorldViewProj = MatrMulMatr(MatrMulMatr(DK6_RndMatrWorld, DK6_RndMatrView), DK6_RndMatrProj); for (i = 0; i < GObj->NumOfV; i++) pnts[i] = DK6_RndWorldToScreen(GObj->V[i]); for (i = 0; i < GObj->NumOfF; i++) { INT n1 = GObj->F[i][0], n2 = GObj->F[i][1], n3 = GObj->F[i][2]; MoveToEx(DK6_Anim.hDC, pnts[n1].x, pnts[n1].y, NULL); LineTo(DK6_Anim.hDC, pnts[n2].x, pnts[n2].y); LineTo(DK6_Anim.hDC, pnts[n3].x, pnts[n3].y); LineTo(DK6_Anim.hDC, pnts[n1].x, pnts[n1].y); } free(pnts); } /* End of 'DK6_RndGObjDraw' 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 */
/* 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 ); }
/* Функция построения объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * as3UNIT_MODEL *Uni; * - указатель на контекст анимации: * as3ANIM *Ani; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ static VOID AS3_AnimUnitRender( as3UNIT_MODEL *Uni, as3ANIM *Ani ) { INT i, j; AS3_RndMatrView = MatrView(VecSet(8, 8, 8), 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); for (i = -2; i < 2; i++) for (j = -2; j < 2; j++) { AS3_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrTranslate(Ani->JX * 228, Ani->JY * 228, 0), MatrScale(0.1, 0.1, 0.1)), MatrRotateY(30 * Ani->Time + Ani->JR * 180)), MatrTranslate(j * 2.5, 0, i * 2.5 + 228 * Ani->JZ)); glColor3d(i & 1, j & 1, 1 - ((i & 1) + (j & 1)) / 2); AS3_RndGObjDraw(&Uni->Model); } } /* End of 'AS3_AnimUnitRender' 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: * 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_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 */
static VOID DrawUnitInPosition( ok2GEOM *Geo, ok2ANIM *Ani, FLT Scale, FLT Rad, FLT Angle ) { FLT unscale = 1.0 / Scale; Ani->MatrWorld = MatrMulMatr(MatrRotate(Angle, 0.0, 1.0, 0.0), Ani->MatrWorld); Ani->MatrWorld = MatrMulMatr(MatrTranslate(Rad, 0.0, 0.0), Ani->MatrWorld); Ani->MatrWorld = MatrMulMatr(Ani->MatrWorld, MatrScale(Scale, Scale, Scale)); OK2_GeomDraw(Geo); Ani->MatrWorld = MatrMulMatr(Ani->MatrWorld, MatrScale(unscale, unscale, unscale)); Ani->MatrWorld = MatrMulMatr(MatrTranslate(-Rad, 0.0, 0.0), Ani->MatrWorld); //Ani->MatrWorld = MatrMulMatr(MatrRotate(-Angle, 0.0, 1.0, 0.0), Ani->MatrWorld); }
/* Функция построения объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * 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 */
/* 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 */
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 */
/* Функция построения объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * vg4UNIT_MODEL *Uni; * - указатель на контекст анимации: * vg4ANIM *Ani; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ static VOID VG4_AnimUnitRender( vg4UNIT_MODEL *Uni, vg4ANIM *Ani ) { INT i; VG4_RndMatrView = MatrView(VecSet(8, 8, 8), VecSet(0, 0, 0), VecSet(0, 1, 0)); for (i = 0; i < 8; i++) { VG4_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrTranslate(Ani->JX * 59, Ani->JY * 88, 0), MatrScale(0.1, 0.1, 0.1)), MatrRotateY(30 * Ani->Time + Ani->JR * 180)), MatrTranslate((i - 2) * 2, 0, 100 * Ani->JZ)); VG4_RndGObjDraw(&Uni->Model); } } /* End of 'VG4_AnimUnitRender' function */
VOID AL5_AnimInit( HWND hWnd ) { INT i; PIXELFORMATDESCRIPTOR pfd = {0}; LARGE_INTEGER t; AL5_Anim.NumOfUnits = 0; memset(&AL5_Anim, 0, sizeof(al5ANIM)); AL5_Anim.hWnd = hWnd; AL5_Anim.hDC = GetDC(hWnd); /*** openGl ***/ pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR); pfd.nVersion = 1; pfd.dwFlags = PFD_DOUBLEBUFFER | PFD_SUPPORT_OPENGL; pfd.cColorBits = 32; pfd.cDepthBits = 32; i = ChoosePixelFormat(AL5_Anim.hDC, &pfd); DescribePixelFormat(AL5_Anim.hDC, i, sizeof(pfd), &pfd); SetPixelFormat(AL5_Anim.hDC, i, &pfd); /* OpenGL init: setup rendering context */ AL5_Anim.hGLRC = wglCreateContext(AL5_Anim.hDC); wglMakeCurrent(AL5_Anim.hDC, AL5_Anim.hGLRC); /* OpenGL init: setup extensions: GLEW library */ if (glewInit() != GLEW_OK || !(GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader)) { wglMakeCurrent(NULL, NULL); wglDeleteContext(AL5_Anim.hGLRC); ReleaseDC(AL5_Anim.hWnd, AL5_Anim.hDC); exit(0); } /*** init timer ***/ QueryPerformanceFrequency(&t); AL5_TimePerSec = t.QuadPart; QueryPerformanceCounter(&t); AL5_StartTime = AL5_OldTime = AL5_OldTimeFPS = t.QuadPart; AL5_PauseTime = 0; AL5_RndMatrProj = MatrFrustum(-1, 1, -1, 1, 1, 100); AL5_RndMatrWorld = MatrIdentity(); AL5_RndMatrView = MatrMulMatr(MatrIdentity(), MatrTranslate(VecSet(-1, -1, 0))); /* OpenGL specific initialization */ glClearColor(0.3, 0.5, 0.7, 1); glEnable(GL_DEPTH_TEST ); /* glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); */ AL5_RndPrg = AL5_RndShaderLoad("a"); }
/* Функция инициализации объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * 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 */
/* Функция построения объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * 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 */
/* Функция обновления межкадровых параметров объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * 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 */
/* Primitive draw function. * ARGUMENTS: * - primtive to draw: * mm3PRIM *Pr; * RETURNS: None. */ VOID MM3_RndPrimDraw( mm3PRIM *Pr ) { INT i; MATR M; POINT *pts; /* Build transform matrix */ M = MatrMulMatr(MM3_RndMatrWorld, MatrMulMatr(MM3_RndMatrView, MM3_RndMatrProj)); /* Transform all points */ pts = malloc(sizeof(POINT) * Pr->NumOfP); if (pts == NULL) return; SelectObject(MM3_Anim.hDC, GetStockObject(DC_PEN)); SetDCPenColor(MM3_Anim.hDC, RGB(255, 255, 255)); for (i = 0; i < Pr->NumOfP; i++) { /* NDC */ VEC p = PointTransform4(Pr->P[i], M); pts[i].x = (INT)((p.X + 1) * MM3_Anim.W / 2); pts[i].y = (INT)((-p.Y + 1) * MM3_Anim.H / 2); } /* Draw all lines */ for (i = 0; i < Pr->NumOfE; i++) { INT n0 = Pr->Edges[i][0], n1 = Pr->Edges[i][1]; SetDCPenColor(MM3_Anim.hDC, RGB(i * 255 / Pr->NumOfE, 0, 255 - i * 255 / Pr->NumOfE)); MoveToEx(MM3_Anim.hDC, pts[n0].x, pts[n0].y, NULL); LineTo(MM3_Anim.hDC, pts[n1].x, pts[n1].y); } free(pts); } /* End of 'MM3_RndPrimDraw' 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 */
/* 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 */
/* Primitive draw function. * ARGUMENTS: * - primitive structure pointer: * avdPRIM *Pr; * RETURNS: None. */ VOID AVD_RndPrimDraw( avdPRIM *Pr ) { INT loc, mtl; MATR M, MSave; /* Build transform matrix */ MSave = AVD_RndMatrWorld; AVD_RndMatrWorld = MatrMulMatr(Pr->M, AVD_RndMatrWorld); M = MatrMulMatr(AVD_RndMatrWorld, MatrMulMatr(AVD_RndMatrView, AVD_RndMatrProj)); glLoadMatrixf(M.A[0]); if ((GetAsyncKeyState(VK_CONTROL) & 0x8000) && (GetAsyncKeyState(VK_MENU) & 0x8000) && (GetAsyncKeyState(VK_SHIFT) & 0x8000)) { glBegin(GL_QUADS); glVertex3fv(&Pr->Min.X); glVertex3f(Pr->Min.X, Pr->Max.Y, Pr->Min.Z); glVertex3fv(&Pr->Max.X); glVertex3f(Pr->Max.X, Pr->Min.Y, Pr->Max.Z); glEnd(); } /* Enable base shader */ glUseProgram(AVD_RndPrg); mtl = Pr->MtlNo; if (mtl == -1) mtl = 0; /* Setup texture */ if (AVD_RndMaterials[mtl].TexNo != 0) { glBindTexture(GL_TEXTURE_2D, AVD_RndMaterials[mtl].TexNo); if ((loc = glGetUniformLocation(AVD_RndPrg, "IsTexture")) != -1) glUniform1i(loc, 1); } else if ((loc = glGetUniformLocation(AVD_RndPrg, "IsTexture")) != -1) glUniform1i(loc, 0); if ((loc = glGetUniformLocation(AVD_RndPrg, "Ka")) != -1) glUniform3fv(loc, 1, &AVD_RndMaterials[mtl].Ka.X); if ((loc = glGetUniformLocation(AVD_RndPrg, "Kd")) != -1) glUniform3fv(loc, 1, &AVD_RndMaterials[mtl].Kd.X); if ((loc = glGetUniformLocation(AVD_RndPrg, "Ks")) != -1) glUniform3fv(loc, 1, &AVD_RndMaterials[mtl].Ks.X); if ((loc = glGetUniformLocation(AVD_RndPrg, "Ph")) != -1) glUniform1f(loc, AVD_RndMaterials[mtl].Ph); if ((loc = glGetUniformLocation(AVD_RndPrg, "Trans")) != -1) glUniform1f(loc, AVD_RndMaterials[mtl].Trans); if ((loc = glGetUniformLocation(AVD_RndPrg, "Id")) != -1) glUniform1i(loc, Pr->Id); /* Setup global variables */ if ((loc = glGetUniformLocation(AVD_RndPrg, "MatrWVP")) != -1) glUniformMatrix4fv(loc, 1, FALSE, M.A[0]); if ((loc = glGetUniformLocation(AVD_RndPrg, "MatrWorld")) != -1) glUniformMatrix4fv(loc, 1, FALSE, AVD_RndMatrWorld.A[0]); if ((loc = glGetUniformLocation(AVD_RndPrg, "MatrView")) != -1) glUniformMatrix4fv(loc, 1, FALSE, AVD_RndMatrView.A[0]); if ((loc = glGetUniformLocation(AVD_RndPrg, "MatrProj")) != -1) glUniformMatrix4fv(loc, 1, FALSE, AVD_RndMatrProj.A[0]); if ((loc = glGetUniformLocation(AVD_RndPrg, "CamLoc")) != -1) glUniform3fv(loc, 1, &AVD_RndCamLoc.X); if ((loc = glGetUniformLocation(AVD_RndPrg, "Time")) != -1) glUniform1f(loc, AVD_Anim.Time); /* Activete primitive vertex array */ glBindVertexArray(Pr->VA); /* Activete primitive index buffer */ glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, Pr->IBuf); /* Draw primitive */ glDrawElements(GL_TRIANGLES, Pr->NumOfI, GL_UNSIGNED_INT, NULL); glBindTexture(GL_TEXTURE_2D, 0); glBindVertexArray(0);; glUseProgram(0); AVD_RndMatrWorld = MSave; } /* End of 'AVD_RndPrimDraw' function */
/* Функция построения объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * as3UNIT_MODEL *Uni; * - указатель на контекст анимации: * as3ANIM *Ani; * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет. */ static VOID AS3_AnimUnitRender(as3UNIT_MODEL *Uni, as3ANIM *Ani) { static INT i = 0, j = 0, k = 0; if (Ani->JR > 0) k += 105; if (Ani->JR < -0.0002) k -= 105; if (Ani->JZ > 0) i += 105; if (Ani->JZ < -0.0002) i -= 105; if (Ani->JY > 0) j += 1000; AS3_RndMatrView = MatrView(VecSet(600 + k, 600 + k, 600 + k), VecSet(i, 0, i), 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->KeysClick['S']) j = 1; glEnable(GL_DEPTH_TEST); AS3_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrRotate(0.00001141552511 * 365 * j * Ani->Time, 0, 1, 0), //Земля MatrScale(100, 100, 100)), MatrTranslate(0, -50, 1200)), MatrRotateY(0.00001141552511 * j * Ani->Time)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Uni->TextId); AS3_GeomDraw(&Uni->Geom[0]); AS3_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrRotate(0, 0, 1, 0), //Солнце MatrScale(800, 800, 800)), MatrTranslate(0, 0, 0)), MatrRotateY(0)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Uni->TextId1); AS3_GeomDraw(&Uni->Geom[1]); AS3_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrRotate(0.6 * 0.0004 * j * Ani->Time, 0, 1, 0), //Меркурий MatrScale(30, 30, 30)), MatrTranslate(0, 0, 800)), MatrRotateY(0.0004 * j * Ani->Time)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Uni->TextId2); AS3_GeomDraw(&Uni->Geom[2]); AS3_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrRotate(-1.1 * 0.0001 * j * Ani->Time, 0, 1, 0), //Венера MatrScale(100, 100, 100)), MatrTranslate(0, 0, 1000)), MatrRotateY(0.0001 * j * Ani->Time)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Uni->TextId3); AS3_GeomDraw(&Uni->Geom[3]); AS3_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrRotate(669 * 0.000006 * j * Ani->Time, 0, 1, 0), //Марс MatrScale(90, 90, 90)), MatrTranslate(0, 0, 1500)), MatrRotateY(0.000006 * j * Ani->Time)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Uni->TextId4); AS3_GeomDraw(&Uni->Geom[4]); AS3_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrRotate(10683 * 0.0000009 * j * Ani->Time, 0, 1, 0), //Юпитер MatrScale(500, 500, 500)), MatrTranslate(0, 0, 1800)), MatrRotateY(0.0000009 * j * Ani->Time)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Uni->TextId5); AS3_GeomDraw(&Uni->Geom[5]); AS3_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrRotate(21170 * 0.0000004 * j * Ani->Time, 0, 1, 0), //Сатурн MatrScale(400, 400, 400)), MatrTranslate(0, 0, 2500)), MatrRotateY(0.0000004 * j * Ani->Time)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Uni->TextId6); AS3_GeomDraw(&Uni->Geom[6]); /* AS3_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrRotate(100 * Ani->Time, 0, 1, 0), //0.004050925925925926 MatrScale(10, 8, 10)), MatrTranslate(0, 0, 2500)), MatrRotateX(-90)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Uni->TextId61); AS3_GeomDraw(&Uni->Geom[7]); */ AS3_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrRotate(43800 * 0.0000001 * j * Ani->Time, 0, 1, 0), //Уран MatrScale(350, 350, 350)), MatrTranslate(0, 0, 3000)), MatrRotateY(0.0000001 * j * Ani->Time)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Uni->TextId7); AS3_GeomDraw(&Uni->Geom[8]); AS3_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrRotate(86036 * 0.00000007 * j * Ani->Time, 0, 1, 0), //Нептун MatrScale(350, 350, 350)), MatrTranslate(0, 0, 3500)), MatrRotateY(0.00000007 * j * Ani->Time)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Uni->TextId8); AS3_GeomDraw(&Uni->Geom[9]); AS3_RndMatrWorld = MatrMulMatr(MatrMulMatr(MatrMulMatr( MatrRotate(0, 0, 1, 0), // nebo MatrScale(20000, 20000, 20000)), MatrTranslate(0, 0, 0)), MatrRotateY(0)); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, Uni->TextId9); AS3_GeomDraw(&Uni->Geom[10]); } /* End of 'AS3_AnimUnitRender' function */
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);
VOID AS4_RndMatrSetup( VOID ) { AS4_RndMatrWorldViewProj = MatrMulMatr(MatrMulMatr(AS4_RndMatrWorld, AS4_RndMatrView), AS4_RndMatrProjection); } /* End of 'AS4_RndMatrSetup' function */
/* Функция обновления межкадровых параметров объекта анимации. * АРГУМЕНТЫ: * - указатель на "себя" - сам объект анимации: * 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 */
/* ‘ункци¤ построени¤ объекта анимации. * ј–√”ћ≈Ќ“џ: * - указатель на "себ¤" - сам объект анимации: * 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 */
VOID PK2_PrimDraw( PK2PRIM *Prim ) { INT loc; MATR M; PK2_RndMatrWorldViewProj = MatrMulMatr(MatrMulMatr(PK2_RndMatrWorld, PK2_RndMatrView), PK2_RndMatrProj); glLoadMatrixf(PK2_RndMatrWorldViewProj.A[0]); glBindVertexArray(Prim->VA); glUseProgram(PK2_RndProg); loc = glGetUniformLocation(PK2_RndProg, "MatrWorld"); if (loc != -1) glUniformMatrix4fv(loc, 1, FALSE, PK2_RndMatrWorld.A[0]); loc = glGetUniformLocation(PK2_RndProg, "MatrView"); if (loc != -1) glUniformMatrix4fv(loc, 1, FALSE, PK2_RndMatrView.A[0]); loc = glGetUniformLocation(PK2_RndProg, "MatrProj"); if (loc != -1) glUniformMatrix4fv(loc, 1, FALSE, PK2_RndMatrProj.A[0]); loc = glGetUniformLocation(PK2_RndProg, "MatrWVP"); if (loc != -1) glUniformMatrix4fv(loc, 1, FALSE, PK2_RndMatrWorldViewProj.A[0]); M = MatrTranspose(MatrInverse(MatrMulMatr(PK2_RndMatrWorld, PK2_RndMatrView))); loc = glGetUniformLocation(PK2_RndProg, "MatrWVInverse"); if (loc != -1) glUniformMatrix4fv(loc, 1, FALSE, M.A[0]); M = MatrTranspose(MatrInverse(PK2_RndMatrWorld)); loc = glGetUniformLocation(PK2_RndProg, "MatrWInverse"); if (loc != -1) glUniformMatrix4fv(loc, 1, FALSE, M.A[0]); M = MatrMulMatr(PK2_RndMatrWorld, PK2_RndMatrView); loc = glGetUniformLocation(PK2_RndProg, "MatrWV"); if (loc != -1) glUniformMatrix4fv(loc, 1, FALSE, M.A[0]); loc = glGetUniformLocation(PK2_RndProg, "Time"); if (loc != -1) glUniform1f(loc, PK2_Anim.Time); loc = glGetUniformLocation(PK2_RndProg, "Ka"); if (loc != -1) glUniform3fv(loc, 1, &PK2_MtlLib[Prim->MtlNo].Ka.X); loc = glGetUniformLocation(PK2_RndProg, "Kd"); if (loc != -1) glUniform3fv(loc, 1, &PK2_MtlLib[Prim->MtlNo].Kd.X); loc = glGetUniformLocation(PK2_RndProg, "Ks"); if (loc != -1) glUniform3fv(loc, 1, &PK2_MtlLib[Prim->MtlNo].Ks.X); loc = glGetUniformLocation(PK2_RndProg, "Kp"); if (loc != -1) glUniform1f(loc, PK2_MtlLib[Prim->MtlNo].Kp); loc = glGetUniformLocation(PK2_RndProg, "Kt"); if (loc != -1) glUniform1f(loc, PK2_MtlLib[Prim->MtlNo].Kt); loc = glGetUniformLocation(PK2_RndProg, "IsTextureUse"); if (PK2_MtlLib[Prim->MtlNo].TexId == 0) glUniform1f(loc, 0); else { glUniform1f(loc, 1); glBindTexture(GL_TEXTURE_2D, PK2_MtlLib[Prim->MtlNo].TexId); } glPrimitiveRestartIndex(0xFFFFFFFF); if (Prim->Type == PK2_PRIM_GRID) glDrawElements(GL_TRIANGLE_STRIP, Prim->NumOfI, GL_UNSIGNED_INT, NULL); else glDrawElements(GL_TRIANGLES, Prim->NumOfI, GL_UNSIGNED_INT, NULL); glUseProgram(0); glBindVertexArray(0); } /* End of 'PK2_PrimDraw' function */
/* ‘ункци¤ рисовани¤. * ј–√”ћ≈Ќ“џ: * - геометрический объект: * ap6GEOM *G; * ¬ќ«¬–јўј≈ћќ≈ «Ќј„≈Ќ»≈: Ќет. */ VOID AP6_GeomDraw( ap6GEOM *G ) { INT i, loc; MATR WVP, MatrWorldInvTrans = {{{0}}}; VEC V; UINT SaveProgId; /* вычислили матрицы преобразовани¤ */ WVP = MatrMulMatr(AP6_Anim.MatrWorld, MatrMulMatr(AP6_Anim.MatrView, AP6_Anim.MatrProjection)); MatrWorldInvTrans = MatrTranspose(MatrInverse(AP6_Anim.MatrWorld)); /* отладочный вывод */ glLoadMatrixf(WVP.A[0]); /* ѕерезагружаем шейдера раз в секунду */ if (G->ProgName[0] != 0) { if (G->ProgTime + 1.0 < AP6_Anim.GlobalTime) { static CHAR Buf[2][MAX_STR]; AP6_ShadProgClose(G->ProgId); sprintf(Buf[0], "SHADERS\\%s.vert", G->ProgName); sprintf(Buf[1], "SHADERS\\%s.frag", G->ProgName); G->ProgTime = AP6_Anim.GlobalTime; G->ProgId = AP6_ShadProgInit(Buf[0], Buf[1]); } } /* сохран¤ем шейдера */ if (G->ProgId != 0) { SaveProgId = AP6_ShaderProg; AP6_ShaderProg = G->ProgId; } /* выбор программы шейдеров вывода примитивов */ glUseProgram(AP6_ShaderProg); loc = glGetUniformLocation(AP6_ShaderProg, "MatrWVP"); if (loc != -1) glUniformMatrix4fv(loc, 1, FALSE, WVP.A[0]); loc = glGetUniformLocation(AP6_ShaderProg, "MatrWorldInverseTranspose"); if (loc != -1) glUniformMatrix4fv(loc, 1, FALSE, MatrWorldInvTrans.A[0]); loc = glGetUniformLocation(AP6_ShaderProg, "MatrWorld"); if (loc != -1) glUniformMatrix4fv(loc, 1, FALSE, AP6_Anim.MatrWorld.A[0]); loc = glGetUniformLocation(AP6_ShaderProg, "MatrView"); if (loc != -1) glUniformMatrix4fv(loc, 1, FALSE, AP6_Anim.MatrView.A[0]); loc = glGetUniformLocation(AP6_ShaderProg, "Time"); if (loc != -1) glUniform1f(loc, AP6_Anim.Time); V = VecSet(-AP6_Anim.MatrView.A[0][2], -AP6_Anim.MatrView.A[1][2], -AP6_Anim.MatrView.A[2][2]); loc = glGetUniformLocation(AP6_ShaderProg, "ViewDir"); if (loc != -1) glUniform3fv(loc, 1, &V.X); V = VecSet(AP6_Anim.MatrView.A[3][0], AP6_Anim.MatrView.A[3][1], AP6_Anim.MatrView.A[3][2]); loc = glGetUniformLocation(AP6_ShaderProg, "ViewPos"); if (loc != -1) glUniform3fv(loc, 1, &V.X); loc = glGetUniformLocation(AP6_ShaderProg, "NumOfParts"); if (loc != -1) glUniform1f(loc, G->NumOfPrims); for (i = 0; i < G->NumOfPrims; i++) { INT mtl = G->Prims[i].Mtl; loc = glGetUniformLocation(AP6_ShaderProg, "PartNo"); if (loc != -1) glUniform1f(loc, i); /* подготавливаем материал */ if (G->Mtls != NULL && mtl >= 0 && mtl < G->NumOfMtls) { INT loc; if (G->Mtls[mtl].TexNo == 0 && G->Mtls[mtl].MapD[0] != 0) { INT j; IMAGE Img; ImageLoad(&Img, G->Mtls[mtl].MapD); /* получаем свободный номер текстуры */ glGenTextures(1, &G->Mtls[mtl].TexNo); /* делаем ее активной */ glBindTexture(GL_TEXTURE_2D, G->Mtls[mtl].TexNo); for (j = 0; j < Img.W * Img.H; j++) Img.Bits[j] |= 0xFF000000; /* отправл¤ем картинку в видеопам¤ть */ gluBuild2DMipmaps(GL_TEXTURE_2D, 4, Img.W, Img.H, GL_BGRA_EXT, GL_UNSIGNED_BYTE, Img.Bits); /* ѕараметры вывода */ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR); glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0); } /* передаем параметры */ if (G->Mtls[mtl].TexNo != 0) { loc = glGetUniformLocation(AP6_ShaderProg, "IsTextureUsed"); if (loc != -1) glUniform1f(loc, 1); loc = glGetUniformLocation(AP6_ShaderProg, "DrawTexture"); if (loc != -1) glUniform1i(loc, 0); //glEnable(GL_TEXTURE_2D); glActiveTexture(GL_TEXTURE0); glBindTexture(GL_TEXTURE_2D, G->Mtls[mtl].TexNo); //glActiveTexture(GL_TEXTURE1); //glBindTexture(GL_TEXTURE_2D, G->Mtls[mtl].TexNo); } else { loc = glGetUniformLocation(AP6_ShaderProg, "IsTextureUsed"); if (loc != -1) glUniform1f(loc, 0); } loc = glGetUniformLocation(AP6_ShaderProg, "Ka"); if (loc != -1) glUniform3fv(loc, 1, &G->Mtls[mtl].Ka.X); loc = glGetUniformLocation(AP6_ShaderProg, "Kd"); if (loc != -1) glUniform3fv(loc, 1, &G->Mtls[mtl].Kd.X); loc = glGetUniformLocation(AP6_ShaderProg, "Ks"); if (loc != -1) glUniform3fv(loc, 1, &G->Mtls[mtl].Ks.X); loc = glGetUniformLocation(AP6_ShaderProg, "Phong"); if (loc != -1) glUniform1f(loc, G->Mtls[mtl].Phong); loc = glGetUniformLocation(AP6_ShaderProg, "Trans"); if (loc != -1) glUniform1f(loc, G->Mtls[mtl].Trans); } loc = glGetUniformLocation(AP6_ShaderProg, "PartNo"); if (loc != -1) glUniform1f(loc, i); AP6_PrimDraw(G->Prims + i); glDisable(GL_TEXTURE_2D); glBindTexture(GL_TEXTURE_2D, 0); } /* восстанавливаем шейдера */ if (G->ProgId != 0) AP6_ShaderProg = SaveProgId; } /* End of 'AP6_GeomDraw' function */