Beispiel #1
0
INT WINAPI WinMain ( HINSTANCE hInstance, HINSTANCE hPrevInstanse, CHAR *CmdLine, INT ShowCmd )
{
  MATRIX M1, M2, M3;
  VEC V1, V2;
  static char BUF[300];
/*  M1 = MatrIdenity( );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, "I matric ( M1 )", MB_OK | MB_ICONINFORMATION );
  M1 = MatrTranslate( 1, 3, 25 );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, "Transpose matric (x = 1, y = 3, z = 25) ( M1 )", MB_OK | MB_ICONINFORMATION );
  M2 = MatrScale(2, 4, 8);
  PrintMatrix( BUF, M2 );
  MessageBox( NULL, BUF, "Scale matric (x = 2, y = 4, z = 8) ( M2 )", MB_OK | MB_ICONINFORMATION );
  M3 = MatrMulMatr( M1, M2 );
  PrintMatrix( BUF, M3 );
  MessageBox( NULL, BUF, " M1 * M2 ( M3 )", MB_OK | MB_ICONINFORMATION );
  M3 = MatrMulMatr( M2, M1 );
  PrintMatrix( BUF, M3 );
  MessageBox( NULL, BUF, " M2 * M1 ( M3 )", MB_OK | MB_ICONINFORMATION );
  M1 = MatrTranspose( M3 );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, " (M3)t ( M1 )", MB_OK | MB_ICONINFORMATION );
  M2 = MatrInverse( M3 );
  PrintMatrix( BUF, M2 );
  MessageBox( NULL, BUF, " (M3)^-1 ( M2 )", MB_OK | MB_ICONINFORMATION );
  M1 = MatrMulMatr( M3, M2 );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, " M3 * M2 ( M1 )", MB_OK | MB_ICONINFORMATION );
  M1 = MatrMulMatr( M2, M3 );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, " M2 * M3 ( M1 )", MB_OK | MB_ICONINFORMATION );*/
/*  M1 = MatrRotateX( 30 );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, " rotate X 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION );
  M1 = MatrRotateY( 30 );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, " rotate Y 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION );
  M1 = MatrRotateZ( 30 );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, " rotate Z 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION );*/
/*  M1 = MatrRotateX( 30 );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, " rotate X 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION );
  M1 = MatrRotateVec( 30, 1, 0, 0 );
  MessageBox( NULL, BUF, " rotate X 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION );
  M1 = MatrRotateVec( 30, -1, 0, 0 );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, " rotate X 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION );
  M1 = MatrRotateVec( 30, 0, 1, 0 );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, " rotate X 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION );
  M1 = MatrRotateVec( 30, 0, 0, 1 );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, " rotate X 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION );
  M1 = MatrRotateVec( 30, 1, 1, 1 );
  PrintMatrix( BUF, M1 );
  MessageBox( NULL, BUF, " rotate (1,1,1) 30 deg ( M1 )", MB_OK | MB_ICONINFORMATION );*/
  PrintMatrix( "Ematr", MatrIdenity( ) );
}
Beispiel #2
0
/* Init animation function.
 * ARGUMENTS:
 *   - hWnd of window:
 *       HWND hWnd;
 * RETURNS: None.
 */
BOOL EF2_AnimInit( HWND hWnd )
{
  INT i;
  LARGE_INTEGER li;
  PIXELFORMATDESCRIPTOR pfd = {0};

  /* init of screen parametrs */
  EF2_Anim.hDC = GetDC(hWnd);
  EF2_Anim.hWnd = hWnd;
  EF2_Anim.W = 30;
  EF2_Anim.H = 30;
  EF2_Anim.NumOfUnits = 0;
  
  pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI | PFD_DOUBLEBUFFER;
  pfd.iPixelType = PFD_TYPE_RGBA;
  pfd.cColorBits = 32;
  i = ChoosePixelFormat(EF2_Anim.hDC, &pfd);
  DescribePixelFormat(EF2_Anim.hDC, i, sizeof(pfd), &pfd);
  SetPixelFormat(EF2_Anim.hDC, i, &pfd);

  /* создаем контекст построения */
  EF2_Anim.hRC = wglCreateContext(EF2_Anim.hDC);
  /* делаем текущими контексты */
  wglMakeCurrent(EF2_Anim.hDC, EF2_Anim.hRC);

  /* init glew.h */
  if (glewInit() != GLEW_OK ||
      !(GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader))
  {
    wglMakeCurrent(NULL, NULL);
    wglDeleteContext(EF2_Anim.hRC);
    ReleaseDC(EF2_Anim.hWnd, EF2_Anim.hDC);
    memset(&EF2_Anim, 0, sizeof(ef2ANIM));
    return FALSE;
  }

  /* default parametrs for OpenGL */

  /* init of timer */
  QueryPerformanceFrequency(&li);
  TimeFreq = li.QuadPart;

  QueryPerformanceCounter(&li);
  TimeStart = TimeOld = TimeFPS = li.QuadPart;
  TimePause = 0;
  FrameCounter = 0;

  /* Параметры проецирования */
  EF2_Anim.Wp = 4, EF2_Anim.Hp = 3,     /* размеры обрасти проецирования */
  EF2_Anim.ProjDist = 5;              /* расстояние до плоскости проекции */
  EF2_Anim.MatrWorld =  
    EF2_Anim.MatrView = 
    EF2_Anim.MatrProjection = MatrIdenity();
  EF2_Anim.ProjSize = 1;
  EF2_Anim.PosCam.X = EF2_Anim.PosCam.Y = EF2_Anim.PosCam.Z = 25;
  /* Init mouse hook */
  EF2_hMouseHook = SetWindowsHookEx(WH_MOUSE_LL, EF2_MouseHook, GetModuleHandle(NULL), 0);
  return TRUE;
} /* End of 'EF2_AnimInit' function */
Beispiel #3
0
/* Функция инициализации анимации.
 * АРГУМЕНТЫ:
 *   - дескриптор окна:
 *       HWND hWnd;
 * ВОЗВРАЩАЕМОЕ ЗНАЧЕНИЕ: Нет.
 */
BOOL OK2_AnimInit( HWND hWnd )
{
  LARGE_INTEGER li;
  INT i;

  /* Init window parametrs */
  OK2_Anim.hDC = GetDC(hWnd);
  OK2_Anim.hWnd = hWnd;
  OK2_Anim.W = 30;
  OK2_Anim.H = 30;
  OK2_Anim.NumOfUnits = 0;
  
  /*** Инициализация OpenGL ***/

  /* описываем формат точки */
  pfd.nSize = sizeof(PIXELFORMATDESCRIPTOR);
  pfd.dwFlags = PFD_SUPPORT_OPENGL | PFD_SUPPORT_GDI | PFD_DOUBLEBUFFER;
  pfd.iPixelType = PFD_TYPE_RGBA;
  pfd.cColorBits = 32;
  i = ChoosePixelFormat(OK2_Anim.hDC, &pfd);
  DescribePixelFormat(OK2_Anim.hDC, i, sizeof(pfd), &pfd);
  SetPixelFormat(OK2_Anim.hDC, i, &pfd);

  /* создаем контекст построения */
  OK2_Anim.hRC = wglCreateContext(OK2_Anim.hDC);
  /* делаем текущими контексты */
  wglMakeCurrent(OK2_Anim.hDC, OK2_Anim.hRC);

  /* инициализируем расширения */
  if (glewInit() != GLEW_OK ||
      !(GLEW_ARB_vertex_shader && GLEW_ARB_fragment_shader))
  {
    wglMakeCurrent(NULL, NULL);
    wglDeleteContext(OK2_Anim.hRC);
    ReleaseDC(OK2_Anim.hWnd, OK2_Anim.hDC);
    memset(&OK2_Anim, 0, sizeof(ok2ANIM));
    return FALSE;
  }
  /* параметры OpenGL по-умолчанию */

  /* инициализируем таймер */
  QueryPerformanceFrequency(&li);
  TimeFreq = li.QuadPart;

  QueryPerformanceCounter(&li);
  TimeStart = TimeOld = TimeFPS = li.QuadPart;
  TimePause = 0;
  FrameCounter = 0;
  
  /* инициализируем захват сообщений от мыши */
  SetWindowsHookEx(WH_MOUSE_LL, OK2_MouseHook, GetModuleHandle(NULL), 0);

  /* Параметры проецирования */
  OK2_Anim.Wp = 4.0, OK2_Anim.Hp = 3.0,     /* размеры обрасти проецирования */
  OK2_Anim.ProjDist = 1.0,              /* расстояние до плоскости проекции */
  OK2_Anim.FarClip = 1000.0,
  OK2_Anim.ProjSize = 1.0;

  OK2_Anim.MatrWorld = /* матрица преобразования мировой СК */
  OK2_Anim.MatrView =  /* матрица преобразования видовой СК */
  OK2_Anim.MatrProjection = MatrIdenity(); /* матрица проекции */
  glEnable(GL_DEPTH_TEST);
  glEnable(GL_ALPHA_TEST);
  //glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);

  return TRUE;
} /* End of 'OK2_AnimInit' function */
Beispiel #4
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 */