Ejemplo n.º 1
0
/* 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 );

} 
Ejemplo n.º 2
0
/* 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 */
Ejemplo n.º 3
0
/* 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 */
Ejemplo n.º 4
0
/* 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 */
Ejemplo n.º 5
0
/* 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 */
Ejemplo n.º 6
0
/* 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 */
Ejemplo n.º 7
0
/* Функция обновления межкадровых параметров объекта анимации.
 * АРГУМЕНТЫ:
 *   - указатель на "себя" - сам объект анимации:
 *       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 */
Ejemplo n.º 8
0
/* 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 */
Ejemplo n.º 9
0
/* Draw object functioln.
 * ARGUMENTS:
 *   - object (*.OBJ) file name:
 *       CHAR *FileName;
 * RETURNS:
 *   (BOOL) TRUE if loading is success, FALSE otherwise.
 */
BOOL ObjLoad( CHAR *FileName )
{
  FILE *F;
  INT nv = 0;
  static CHAR Buf[10000];
 

  /* Open file */
  if ((F = fopen(FileName, "r")) == NULL)
    return FALSE;

  /* Count vertices */
  while (fgets(Buf, sizeof(Buf), F) != NULL)
  {
    if (Buf[0] == 'v' && Buf[1] == ' ')
      nv++;
  }

  /* Allocate memory for data */
  if ((ObjV = malloc(sizeof(VEC) * nv)) == NULL)
  {
    fclose(F);
    return FALSE;
  }

  /* Read vertices */
  rewind(F);
  nv = 0;
  while (fgets(Buf, sizeof(Buf), F) != NULL)
  {
    if (Buf[0] == 'v' && Buf[1] == ' ')
    {
      sscanf(Buf + 2, "%lf%lf%lf",
        &ObjV[nv].X, &ObjV[nv].Y, &ObjV[nv].Z);
      ObjV[nv] = VecMulNum(ObjV[nv], 40);
      ObjV[nv] = VecRotateZ(ObjV[nv], 180);
      nv++;
    }
  }

  fclose(F);

  ObjNumOfV = nv;
  return TRUE;
} /* End of 'ObjLoad' function */
Ejemplo n.º 10
0
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));
}
Ejemplo n.º 11
0
/* 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 */
Ejemplo n.º 12
0
/* 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 */
Ejemplo n.º 13
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 */