Пример #1
0
//
// Starts the door going to its "up" position (simply ToggleData->vecPosition2).
//
void CBaseTrainDoor::DoorGoUp( void )
{
	// It could be going-down, if blocked.
	ASSERT( door_state == TD_CLOSED );

	door_state = TD_SHIFT_UP;

	UTIL_MakeVectors( m_vecOldAngles );

	STOP_SOUND( edict(), CHAN_STATIC, STRING( pev->noise1 ));
	EMIT_SOUND( edict(), CHAN_STATIC, STRING( pev->noise2 ), 1, ATTN_NORM );

	// Subtract 2 from size because the engine expands bboxes by 1 in all directions making the size too big
	Vector vecSize = pev->size - Vector( 2, 2, 2 );
	float depth = (fabs( gpGlobals->v_right.x * vecSize.x ) + fabs( gpGlobals->v_right.y * vecSize.y ) + fabs( gpGlobals->v_right.z * vecSize.z ) - m_flLip);

	if( pev->spawnflags & SF_TRAINDOOR_INVERSE )
		depth = -depth;

	VectorMatrix( pev->movedir, gpGlobals->v_right, gpGlobals->v_up );
	m_vecPosition3 = m_vecPosition1 + gpGlobals->v_right * -depth;

	SetMoveDone( &CBaseTrainDoor:: DoorSlideWait );
	LinearMove( m_vecPosition3, pev->speed );
}
Пример #2
0
// This function creates a VectorMatrix from the given tinyxml Element
// and its children.
//
// Input:
//   matElement: tinyxml DOM node containing a Matrix element
// Postconditions"
//   If no problems, VectorMatrix object created and
//   initialized.
// Returns:
//   VectorMatrix object (will be empty if some failure occurs).
VectorMatrix MatrixFactory::CreateVector(TiXmlElement* matElement)
{
  string type;
  string init;
  int rows, columns;
  FLOAT multiplier;
  string values;
  TiXmlHandle matHandle(matElement);

  GetAttributes(matElement, type, init, rows, columns, multiplier);

#ifdef VDEBUG
  cerr << "Creating Vector with attributes: " << type << ", " << init
       << ", " << rows << "X" << columns << ", " << multiplier << endl;
#endif

  // Get the Text node that contains the matrix values, if needed
  if (init == "none") {
    TiXmlText* valuesNode = matHandle.FirstChild().Text();
    if (valuesNode == NULL)
      throw KII_invalid_argument("Contents not specified for Vector with init='none'.");

    values = valuesNode->Value();
#ifdef VDEBUG
    cerr << "\tData present for initialization: " << values << endl;
#endif
  } else if (init == "implementation")
    throw KII_invalid_argument("MatrixFactory cannot create implementation-dependent Matrices; client program must perform creation");

  if (type == "sparse")
    throw KII_invalid_argument("Sparse matrix requested in XML but CreateVector called");

  if ((type == "complete") || (type == "diag")) {
    if ((rows > 1) && (columns > 1)) // Create a 2D Matrix
      throw KII_domain_error("Cannot create Vector with more than one dimension.");
    else                               // Create a 1D Matrix
       return VectorMatrix(type, init, rows, columns, multiplier, values);
  } else if (type == "sparse")
    throw KII_invalid_argument("No such thing as sparse Vectors");
  else
    throw KII_invalid_argument("Illegal Vector type");

  return VectorMatrix();
}
Пример #3
0
void C_NPC_Hydra::CalcBoneAngles( const Vector pos[], Quaternion q[] )
{
	int i;
	matrix3x4_t bonematrix;

	for (i = m_numHydraBones - 1; i >= 0; i--)
	{
		Vector forward;
		Vector left2;

		if (i != m_numHydraBones - 1)
		{
			QuaternionMatrix( q[i+1], bonematrix );
			MatrixGetColumn( bonematrix, 1, left2 );

			forward = (pos[i+1] - pos[i]) /* + (pos[i] - pos[i-1])*/;
			float length = VectorNormalize( forward );
			if (length == 0.0)
			{
				q[i] = q[i+1];
				continue;
			}
		}
		else
		{
			forward = m_vecHeadDir;
			VectorNormalize( forward );

			VectorMatrix( forward, bonematrix );
			MatrixGetColumn( bonematrix, 1, left2 );
		}

		Vector up = CrossProduct( forward, left2 );
		VectorNormalize( up );

		Vector left = CrossProduct( up, forward );

		MatrixSetColumn( forward, 0, bonematrix );
		MatrixSetColumn( left, 1, bonematrix );
		MatrixSetColumn( up, 2, bonematrix );

		// MatrixQuaternion( bonematrix, q[i] );
		QAngle angles;
		MatrixAngles( bonematrix, angles );
		AngleQuaternion( angles, q[i] );
	}
}