// **************************************************
//            OVERRIDDEN ENTITY FUNCTIONS
// **************************************************
void TransitionBarbarian_cl::InitFunction()
{
  if (!HasMesh())
    return;

  SetCastShadows(TRUE);
  
  // Setup all animation sequences
	SetupAnimations();
  if (!m_bModelValid)
    return;

  if( !m_pPhys)
  {
    m_pPhys = new vHavokCharacterController();
    m_pPhys->Initialize();

    hkvAlignedBBox bbox;
    VDynamicMesh *pMesh = GetMesh();
    pMesh->GetCollisionBoundingBox(bbox);

    float r = bbox.getSizeX() * 0.5f;
    m_pPhys->Capsule_Radius = r;
    m_pPhys->Character_Top.set(0,0,bbox.m_vMax.z - r);
    m_pPhys->Character_Bottom.set(0,0,bbox.m_vMin.z + r);

    m_pPhys->Max_Slope = 75.0f;
    AddComponent(m_pPhys);
    //	pPhys->SetDebugRendering(TRUE);
  }
 
  // Get Model
  VDynamicMesh* pModel = GetMesh();
	VASSERT(pModel);

  // Transition table to use
  VTransitionTable *pTable = VTransitionManager::GlobalManager().LoadTransitionTable(pModel,"Barbarian.vTransition");
  VASSERT(pTable && pTable->IsLoaded());

	// Setup the state machine component and pass the filename of the transition file
  // in which the transitions between the various animation states are defined.
	m_pStateMachine = new VTransitionStateMachine();
  m_pStateMachine->Init(this, pTable);
	AddComponent(m_pStateMachine);

	// Set initial state
	m_pStateMachine->SetState(m_pSkeletalSequenceList[ANIMID_IDLE]);
}
void VLineFollowerComponent::InitPhysics(float fPathPos)
{
  VisBaseEntity_cl* pOwner = (VisBaseEntity_cl *)GetOwner();
  if (!pOwner)
    return;

  hkvVec3 vPos;
  hkvVec3 vDir;
  hkvAlignedBBox bbox;

  m_fCurrentPathPos = fPathPos;
  if(m_pFollowPath)
    m_pFollowPath->EvalPoint(fPathPos, vPos, &vDir);
  else
    vPos = pOwner->GetPosition();

  // to determine correct height on the ground, perform a ray-cast:
  if (Vision::GetApplication()->GetPhysicsModule()!=NULL && Model_CapsuleHeight>0)
  {
    hkvVec3 vRayStart(vPos.x,vPos.y,vPos.z+Model_CapsuleHeight);
    hkvVec3 vRayEnd(vPos.x,vPos.y,vPos.z-Model_CapsuleHeight);
    VisPhysicsHit_t hitPoint;
    if (Vision::GetApplication()->GetPhysicsModule()->Raycast(vRayStart, vRayEnd, hitPoint)) // hit?
    {
      vPos.z = hitPoint.vImpactPoint.z + 5.f*Vision::World.GetGlobalUnitScaling(); // add some margin
    }
  }

  VDynamicMesh *pMesh = pOwner->GetMesh();
  if (pMesh)
  {
    pMesh->GetCollisionBoundingBox(bbox);
    vPos.z -= bbox.m_vMin.z;

    // Use model size if not set
    if (Model_CapsuleRadius<=0.f) Model_CapsuleRadius = hkvMath::Min( bbox.getSizeX(), bbox.getSizeY() )/2.f;
    if (Model_CapsuleHeight<=0.f) Model_CapsuleHeight = bbox.getSizeZ();
  } else
  { 
    // No model - set some sane values if not set
    if (Model_CapsuleRadius<=0.f) Model_CapsuleRadius = 40.f;
    if (Model_CapsuleHeight<=0.f) Model_CapsuleHeight = 90.f;
  }

  // Create the physics object 
  pOwner->SetPosition(vPos);
  if (!m_pPhys)
  {
    m_pPhys = new vHavokCharacterController();
    m_pPhys->Capsule_Radius = Model_CapsuleRadius;
    float h = Model_CapsuleHeight * 0.5f;
    float fPivot = Model_GroundOffset;
    m_pPhys->Character_Top.set(0, 0, h - fPivot);
    m_pPhys->Character_Bottom.set(0, 0, -h - fPivot);
    pOwner->AddComponent(m_pPhys);
  }

  // Update position
  m_pPhys->SetPosition(vPos);

  // Enable debug rendering
  m_pPhys->SetDebugRendering(Debug_RenderMesh);
  m_pPhys->SetDebugColor(V_RGBA_RED);
}