示例#1
0
/* Vector normalization function.
 * ARGUMENTS:
 *   - vector to be normalize:
 *       VEC V;
 * RETURNS:
 *   (VEC) normalized vector value.
 */
VEC VecNormalize( VEC V )
{
  DBL len = VecDotVec(V, V);

  if (len != 1 && len != 0)
    len = sqrt(len), V.X /= len, V.Y /= len, V.Z /= len;
  return V;
} /* End of 'VecNormalize' function */
示例#2
0
文件: VEC.C 项目: Killaz/SUM2014
MATR MatrViewLookAt( VEC Loc, VEC At, VEC UpApprox )
{
  VEC Right, Up, Dir;
  MATR r;
  		
  Dir = VecNormalize(VecSubVec(At, Loc));
  Right = VecNormalize(VecCrossVec(Dir, UpApprox));
  Up = VecCrossVec(Right, Dir);

  r.A[0][0] = Right.x; r.A[0][1] = Up.x; r.A[0][2] = -Dir.x; r.A[0][3] = 0;
  r.A[1][0] = Right.y; r.A[1][1] = Up.y; r.A[1][2] = -Dir.y; r.A[1][3] = 0;
  r.A[2][0] = Right.z; r.A[2][1] = Up.z; r.A[2][2] = -Dir.z; r.A[2][3] = 0;
  r.A[3][0] = -VecDotVec(Loc, Right);
  r.A[3][1] = -VecDotVec(Loc, Up);
  r.A[3][2] = VecDotVec(Loc, Dir);
  r.A[3][3] = 1;
  return r;
}
示例#3
0
/* ‘ункци¤ преобразовани¤ из мировой системы коорлинат в кадр.
 * ј–√”ћ≈Ќ“џ:
 *   - исходна¤ точка:
 *       VEC Loc, VEC At, VEC Upaprox;
 * ¬ќ«¬–јўј≈ћќ≈ «Ќј„≈Ќ»≈:
 *   (MATR) ћатрица преоброзаваний камеры.
 */
MATR II2_VieverCamera( VEC Loc, VEC At, VEC Upaprox )
{
  VEC Right, Up, Dir;
  MATR r;

  Dir = VecNormalize(VecSubVec(At, Loc));
  Right = VecNormalize(VecCrossVec(Dir, Upaprox));
  Up = VecCrossVec(Right, Dir);

  r.A[0][0] = Right.X; r.A[0][1] = Up.X; r.A[0][2] = -Dir.X; r.A[0][3] = 0;
  r.A[1][0] = Right.Y; r.A[1][1] = Up.Y; r.A[1][2] = -Dir.Y; r.A[1][3] = 0;
  r.A[2][0] = Right.Z; r.A[2][1] = Up.Z; r.A[2][2] = -Dir.Z; r.A[2][3] = 0;
  r.A[3][0] = -VecDotVec(Loc, Right);
  r.A[3][1] = -VecDotVec(Loc, Up);
  r.A[3][2] = VecDotVec(Loc, Dir);
  r.A[3][3] = 1;


  /*r.A[0][0] = Right.X;
  r.A[1][0] = Up.X;
  r.A[2][0] = -Dir.X;
  r.A[3][0] = 0;
     
  r.A[0][1] = Right.Y;
  r.A[1][1] = Up.Y;
  r.A[2][1] = -Dir.Y;
  r.A[3][1] = 0;
     
  r.A[0][2] = Right.Z;
  r.A[1][2] = Up.Z;
  r.A[2][2] = -Dir.Z;
  r.A[3][2] = 0;
     
  r.A[0][3] = -VecDotVec(Loc, Right);
  r.A[1][3] = -VecDotVec(Loc, Up);
  r.A[2][3] = -VecDotVec(Loc, Dir);
  r.A[3][3] = 1;*/

  return r;
} /* End of 'Ani->WorldToScreen' function */