示例#1
0
void AGameObject::Walk( float t )
{
  CheckWaypoint();

  // Alter destination based on locations of other units.
  FVector ToDest = Dest - Pos;
  
  // Clamp travel length so that we can't overshoot destination
  if( float Len = ToDest.Size() )
  {
    Dir = ToDest / Len; // normalize
    if( !Stats.SpeedMax )  error( FS("%s had 0 speed", *GetName()) );
    
    // I am maxing out the speed here.
    Speed = Stats.SpeedMax;

    // The direction of travel is modified by repulsion forces
    FVector repulsionForces = GetRepulsionForcesFromOverlappedUnits();
    FVector modDir = Dir + repulsionForces;
    modDir.Normalize();
    FVector Vel = modDir*Speed;
    //Game->flycam->DrawDebug( Pos, Pos + Vel, 5.f, FLinearColor::Red, 0.f );
    FVector travel = Vel*t;

    // If travel exceeds destination, then jump to dest,
    // so we don't jitter over the final position.
    if( Len < travel.Size() )
    {
      // snap to position & stop moving.
      Pos = Dest; // we are @ destination.
      travel = ToDest; // This is the displacement we actually moved.
      Speed = 0;
    }
    else
    {
      Pos += travel;
      if( Grounds )
      {
        FVector newPos = Pos + UnitZ * 10.f;
        // Travel in direction plus some amount straight up.
        // The straight up amount ensures that the unit doesn't sink underground
        if( Game->flycam->SetOnGround( newPos ) )  Pos = newPos;
        else  error( FS( "%s Object was trying to leave the ground plane.", *GetName() ) );
      }
      SetRot( Dir.Rotation() );
    }
  }
  else
  {
    // We're at the destination, so the velocity becomes 0
    Speed = 0.f;
  }
}
示例#2
0
CHitSquare::CHitSquare()
{
	SetLocalPos(0,0,0);
	SetLocalScale(1,1,1);
	SetScale(0,0,0);
	SetRot(0,0,0);
	m_Direction = 1;
#ifdef DEBUG
	m_pDebugFont = new CDebugFont;
	m_pDebugFont->SetUp();
#endif
}
示例#3
0
void AGameObject::Face( FVector point )
{
  if( Dead )
  {
    error( "Face dead unit" );
    return;
  }
  FVector to = point - Pos;
  if( float len = to.Size() )
  {
    to /= len;
    SetRot( to.Rotation() );
  }
}
void CameraComponent::SetDirNormed(const mm::vec3& dir)
{
	cam->SetDirNormed(dir);
	SetRot(cam->GetRot());
}
示例#5
0
/**
*@brief 軸設定スピンボックスの値(ヨー角)を変更したときのスロット
* @param value ヨー
*/
void SimJointSetWidget::YawSlot(double value)
{
	SetRot();
}
示例#6
0
/**
*@brief 軸設定スピンボックスの値(ピッチ角)を変更したときのスロット
* @param value ピッチ
*/
void SimJointSetWidget::PitchSlot(double value)
{
	SetRot();
}
示例#7
0
bool Player::ProcessEvent(const SGUIEvent* e)
{
	SWRayObjIntersect isc; //screen ray intersection
	bool rc = false; //rotation change flag
	mmask_t modb = BUTTON_CTRL | BUTTON_SHIFT | BUTTON_ALT;

	switch (e->t) {
	case GUIEV_MOUSE:

		if (e->m.bstate & (GUISCRL_UP | GUISCRL_DW)) {
			//Wheel (camera rotation)
			if ((e->m.bstate & modb) == rot_ver)
				rot.X += (e->m.bstate & GUISCRL_UP)? rspd:-rspd;

			else if ((e->m.bstate & modb) == rot_hor)
				rot.Z -= (e->m.bstate & GUISCRL_UP)? rspd:-rspd;

			else return false;

			rc = true;

		} else if (e->m.bstate == BUTTON1_PRESSED) {
			//Action button
			isc = *(world->ScreenRay(vector2di(e->m.x,e->m.y)));
			switch (state) {
			case PCS_EXPLORING:
				if (!isc.model) return true;
				if (isc.model == model) {
					world->LogMsg("SELFPOINT_LOG");
				} else if (isc.actor) {
					world->GetMsgSys()->SetActorName(isc.actor->GetAttributes().name);
					if (isc.actor->GetAttributes().female)
						world->LogMsg("ACTRESS_LOG");
					else
						world->LogMsg("ACTOR_LOG");
				}
				break;

			case PCS_INTERACTING:
				//TODO
				break;

			case PCS_COMBAT:
				if (isc.pnt != vector3di(-1))
					world->FireTo(isc.pnt,&isc);
				break;

			default: break;
			}
		} else
			return false;
		break;

	case GUIEV_KEYPRESS:

		switch (binder->DecodeKey(e->k)) {
		default: return false;

		case PAKEY_WALK_FORW: Move(LMOVE_FORW,1.2f); break; //FIXME: use speed value
		case PAKEY_WALK_BACK: Move(LMOVE_BACK,1.2f); break;
		case PAKEY_WALK_LEFT: Move(LMOVE_LEFT,1.2f); break;
		case PAKEY_WALK_RGHT: Move(LMOVE_RGHT,1.2f); break;

		case PAKEY_RUN_FORW: Move(LMOVE_FORW,2.2f); break; //FIXME: use speed value
		case PAKEY_RUN_BACK: Move(LMOVE_BACK,2.2f); break;
		case PAKEY_RUN_LEFT: Move(LMOVE_LEFT,2.2f); break;
		case PAKEY_RUN_RGHT: Move(LMOVE_RGHT,2.2f); break;

		case PAKEY_TURN_LEFT: rot.Z += rspd; rc = true; break;
		case PAKEY_TURN_RGHT: rot.Z -= rspd; rc = true; break;
		case PAKEY_TURN_UP: rot.X += rspd; rc = true; break;
		case PAKEY_TURN_DW: rot.X -= rspd; rc = true; break;

		case PAKEY_TOG_STATE:
			//TODO: check conditions, apply some changes etc
			switch (state) {
			case PCS_EXPLORING:
				state = PCS_INTERACTING;
				break;
			case PCS_INTERACTING:
				state = PCS_COMBAT;
				break;
			case PCS_COMBAT:
				state = PCS_EXPLORING;
				break;
			case PCS_VEHICLE: break;
			}

		}
		break;

	default:
		return false;
	}

	if (rc) SetRot(rot); //Update rotation

	return true;
}