Exemplo n.º 1
0
void CurrencyOrb::DoTrackPlayer(float delta)
{
	mSineWaveProps.DoSineWave = false;

	Player * player = GameObjectManager::Instance()->GetPlayer();
	if (!player)
	{
		return;
	}

	// accelerate towards the target
	Vector3 direction = Vector3(player->CollisionCentreX(), player->CollisionCentreY(), player->Z()) - m_position;

	direction.Normalise();

	m_direction = direction;

	float multiplier = mTimeTracking > 2.0f ? 3.0f : 1.0f;

	bool prioritiseX = false;
	if (std::abs(m_direction.X) > std::abs(m_direction.Y))
	{
		AccelerateX(m_direction.X, kAccelerateRate * multiplier);
		prioritiseX = true;
	}
	else
	{
		AccelerateY(m_direction.Y, kAccelerateRate * multiplier);
	}

	if (prioritiseX && ((m_direction.X < 0 && m_velocity.X > 0) ||
		(m_direction.X > 0 && m_velocity.X < 0)))
	{
		// the velocity of the orb is still moving in the opposite x direction
		// let's give it a helping hand to catch up by accelerating harshly
		AccelerateX(m_direction.X, kHarshAccelerateRate * multiplier);
	}

	if (!prioritiseX && ((m_direction.Y < 0 && m_velocity.Y > 0) ||
		(m_direction.Y > 0 && m_velocity.Y < 0)))
	{
		// the velocity of the orb is still moving in the opposite y direction
		// let's give it a helping hand to catch up by accelerating harshly
		AccelerateY(m_direction.Y, kHarshAccelerateRate * multiplier);
	}

	Vector2 dir = Vector2(m_velocity.X, m_velocity.Y);
	dir.Normalise();

	if (dir.X > 0)
	{
		SetRotationAngle(-acos(dir.Dot(Vector2(0, -1))));
	}
	else
	{
		SetRotationAngle(acos(dir.Dot(Vector2(0, -1))));
	}
}
Exemplo n.º 2
0
void CIntegralRotation::Init (const CIntegralRotationDesc &Desc, int iRotationAngle)

//	Init
//
//	Initialize

	{
	//	Defaults

	m_iMaxRotationRate = Desc.GetMaxRotationSpeed();
	m_iRotationAccel = Desc.GetRotationAccel();
	m_iRotationAccelStop = Desc.GetRotationAccelStop();

	if (iRotationAngle != -1)
		SetRotationAngle(Desc, iRotationAngle);
	}
void
EllipsoidSliceAttributes::SetFromNode(DataNode *parentNode)
{
    if(parentNode == 0)
        return;

    DataNode *searchNode = parentNode->GetNode("EllipsoidSliceAttributes");
    if(searchNode == 0)
        return;

    DataNode *node;
    if((node = searchNode->GetNode("origin")) != 0)
        SetOrigin(node->AsDoubleArray());
    if((node = searchNode->GetNode("radii")) != 0)
        SetRadii(node->AsDoubleArray());
    if((node = searchNode->GetNode("rotationAngle")) != 0)
        SetRotationAngle(node->AsDoubleArray());
}
Exemplo n.º 4
0
void ScreenBase::UpdateDependentParameters()
{
  m_PixelRect = CalculatePixelRect(m_Scale);

  m_PtoG = math::Shift( /// 5. shifting on (E0, N0)
               math::Rotate( /// 4. rotating on the screen angle
                   math::Scale( /// 3. scaling to translate pixel sizes to global
                       math::Scale( /// 2. swapping the Y axis??? why??? supposed to be a rotation on -pi / 2 here.
                           math::Shift( /// 1. shifting for the pixel center to become (0, 0)
                               math::Identity<double, 3>(),
                               - m_PixelRect.Center()
                               ),
                           1,
                           -1
                           ),
                       m_Scale,
                       m_Scale
                       ),
                   m_Angle.cos(),
                   m_Angle.sin()
               ),
               m_Org
           );

  m_GtoP = math::Inverse(m_PtoG);

  m2::PointD const pxC = m_PixelRect.Center();
  double const szX = PtoG(m2::PointD(m_PixelRect.maxX(), pxC.y)).Length(PtoG(m2::PointD(pxC)));
  double const szY = PtoG(m2::PointD(pxC.x, m_PixelRect.minY())).Length(PtoG(m2::PointD(pxC)));

  m_GlobalRect = m2::AnyRectD(m_Org, m_Angle, m2::RectD(-szX, -szY, szX, szY));
  m_ClipRect = m_GlobalRect.GetGlobalRect();

  double const kEps = 1e-5;
  double angle = CalculatePerspectiveAngle(m_Scale);
  m_isPerspective = angle > 0.0;
  if (fabs(angle - m_3dAngleX) > kEps)
  {
    m_3dMaxAngleX = angle;
    m_3dScale = CalculateScale3d(angle);
    SetRotationAngle(angle);
  }
}
Exemplo n.º 5
0
void CIntegralRotation::ReadFromStream (SLoadCtx &Ctx, const CIntegralRotationDesc &Desc)

//	ReadFromStream
//
//	Reads data

	{
	DWORD dwLoad;

	Init(Desc);

	Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
	m_iRotationFrame = (int)dwLoad;

	Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD));
	m_iRotationSpeed = (int)dwLoad;

	//	Make sure our frame is within bounds; this can change if the ship's
	//	rotation count is altered in the XML.

	if (GetFrameIndex() >= Desc.GetFrameCount())
		SetRotationAngle(Desc, 0);
	}
Exemplo n.º 6
0
void ViewPort::SetBoxes( void )
{

    //  In the case where canvas rotation is applied, we need to define a larger "virtual" pixel window size to ensure that
    //  enough chart data is fatched and available to fill the rotated screen.
    rv_rect = wxRect( 0, 0, pix_width, pix_height );

    //  Specify the minimum required rectangle in unrotated screen space which will supply full screen data after specified rotation
    if (( fabs( skew ) > .0001 ) || (fabs(rotation )>.0001 )) {

        double rotator = rotation;
        double lpixh = pix_height;
        double lpixw = pix_width;

        lpixh = wxMax(lpixh, (fabs(pix_height * cos(skew)) + fabs(pix_width * sin(skew))));
        lpixw = wxMax(lpixw, (fabs(pix_width * cos(skew)) + fabs(pix_height * sin(skew))));

        int dy = wxRound(
                     fabs( lpixh * cos( rotator ) ) + fabs( lpixw * sin( rotator ) ) );
        int dx = wxRound(
                     fabs( lpixw * cos( rotator ) ) + fabs( lpixh * sin( rotator ) ) );

        //  It is important for MSW build that viewport pixel dimensions be multiples of 4.....
        if( dy % 4 ) dy += 4 - ( dy % 4 );
        if( dx % 4 ) dx += 4 - ( dx % 4 );

        int inflate_x = wxMax(( dx - pix_width ) / 2, 0);
        int inflate_y = wxMax(( dy - pix_height ) / 2, 0);

        //  Grow the source rectangle appropriately
        rv_rect.Inflate( inflate_x, inflate_y );
    }

    //  Compute Viewport lat/lon reference points for co-ordinate hit testing

    //  This must be done in unrotated space with respect to full unrotated screen space calculated above
    double rotation_save = rotation;
    SetRotationAngle(0.0);

    wxPoint ul( rv_rect.x, rv_rect.y ), lr( rv_rect.x + rv_rect.width, rv_rect.y + rv_rect.height );
    double dlat_min, dlat_max, dlon_min, dlon_max;

    bool hourglass = false;
    switch(m_projection_type) {
    case PROJECTION_TRANSVERSE_MERCATOR:
    case PROJECTION_STEREOGRAPHIC:
    case PROJECTION_GNOMONIC:
        hourglass = true;
    case PROJECTION_POLYCONIC:
    case PROJECTION_POLAR:
    case PROJECTION_ORTHOGRAPHIC:
    {
        double d;

        if( clat > 0 ) { // north polar
            wxPoint u( rv_rect.x + rv_rect.width/2, rv_rect.y );
            wxPoint ur( rv_rect.x + rv_rect.width, rv_rect.y );
            GetLLFromPix( ul, &d, &dlon_min );
            GetLLFromPix( ur, &d, &dlon_max );
            GetLLFromPix( lr, &dlat_min, &d );
            GetLLFromPix( u, &dlat_max, &d );

            if(fabs(fabs(d - clon) - 180) < 1) { // the pole is onscreen
                dlat_max = 90;
                dlon_min = -180;
                dlon_max = 180;
            } else if(wxIsNaN(dlat_max))
                dlat_max = 90;

            if(hourglass) {
                // near equator, center may be less
                wxPoint l( rv_rect.x + rv_rect.width/2, rv_rect.y + rv_rect.height );
                double dlat_min2;
                GetLLFromPix( l, &dlat_min2, &d );
                dlat_min = wxMin(dlat_min, dlat_min2);
            }

            if(wxIsNaN(dlat_min)) //  world is off-screen
                dlat_min = clat - 90;
        } else { // south polar
            wxPoint l( rv_rect.x + rv_rect.width/2, rv_rect.y + rv_rect.height );
            wxPoint ll( rv_rect.x, rv_rect.y + rv_rect.height );
            GetLLFromPix( ul, &dlat_max, &d );
            GetLLFromPix( lr, &d, &dlon_max );
            GetLLFromPix( ll, &d, &dlon_min );
            GetLLFromPix( l, &dlat_min, &d );

            if(fabs(fabs(d - clon) - 180) < 1) { // the pole is onscreen
                dlat_min = -90;
                dlon_min = -180;
                dlon_max = 180;
            } else if(wxIsNaN(dlat_min))
                dlat_min = -90;

            if(hourglass) {
                // near equator, center may be less
                wxPoint u( rv_rect.x + rv_rect.width/2, rv_rect.y );
                double dlat_max2;
                GetLLFromPix( u, &dlat_max2, &d );
                dlat_max = wxMax(dlat_max, dlat_max2);
            }

            if(wxIsNaN(dlat_max)) //  world is off-screen
                dlat_max = clat + 90;
        }

        if(wxIsNaN(dlon_min)) {
            // if neither pole is visible, but left and right of the screen are in space
            // we can avoid drawing the far side of the earth
            if(dlat_max < 90 && dlat_min > -90) {
                dlon_min = clon - 90 - fabs(clat); // this logic is not optimal, is it always correct?
                dlon_max = clon + 90 + fabs(clat);
            } else {
                dlon_min = -180;
                dlon_max = 180;
            }
        }
    }
    break;

    default: // works for mercator and equirectangular
    {
        GetLLFromPix( ul, &dlat_max, &dlon_min );
        GetLLFromPix( lr, &dlat_min, &dlon_max );
    }
    }

    if( clon < dlon_min )
        dlon_min -= 360;
    else if(clon > dlon_max)
        dlon_max += 360;

    //  Set the viewport lat/lon bounding box appropriately
    vpBBox.Set( dlat_min, dlon_min, dlat_max, dlon_max );

    // Restore the rotation angle
    SetRotationAngle( rotation_save );
}
Exemplo n.º 7
0
void               P3DBranchingAlgStd::Load
                                      (P3DInputStringFmtStream
                                                          *SourceStream,
                                       const P3DFileVersion
                                                          *Version)
 {
  char                                 StrValue[255 + 1];
  float                                FloatValue;
  unsigned int                         UintValue;
  bool                                 BoolValue;

  SourceStream->ReadFmtStringTagged("Density","f",&FloatValue);
  SetDensity(FloatValue);
  SourceStream->ReadFmtStringTagged("DensityV","f",&FloatValue);
  SetDensityV(FloatValue);

  if (Version->Minor > 5)
   {
    SourceStream->ReadFmtStringTagged("MinNumber","u",&UintValue);
    SetMinNumber(UintValue);
    SourceStream->ReadFmtStringTagged("MaxLimitEnabled","b",&BoolValue);
    SetMaxLimitEnabled(BoolValue);
    SourceStream->ReadFmtStringTagged("MaxNumber","u",&UintValue);
    SetMaxNumber(UintValue);
   }
  else
   {
    SetMinNumber(0);
    SetMaxLimitEnabled(false);
    SetMaxNumber(0);
   }

  if (Version->Minor > 1)
   {
    SourceStream->ReadFmtStringTagged("Multiplicity","u",&UintValue);
    SetMultiplicity(UintValue);
   }
  else
   {
    Multiplicity = 1;
   }

  if (Version->Minor > 7)
   {
    SourceStream->ReadFmtStringTagged("StartRevAngle","f",&FloatValue);
    SetStartRevAngle(FloatValue);
   }
  else
   {
    StartRevAngle = 0.0f;
   }

  SourceStream->ReadFmtStringTagged("RevAngle","f",&FloatValue);
  SetRevAngle(FloatValue);
  SourceStream->ReadFmtStringTagged("RevAngleV","f",&FloatValue);
  SetRevAngleV(FloatValue);

  SourceStream->ReadFmtStringTagged("RotAngle","f",&FloatValue);
  SetRotationAngle(FloatValue);

  SourceStream->ReadFmtStringTagged("MinOffset","f",&FloatValue);
  SetMinOffset(FloatValue);
  SourceStream->ReadFmtStringTagged("MaxOffset","f",&FloatValue);
  SetMaxOffset(FloatValue);

  SourceStream->ReadFmtStringTagged("DeclinationCurve","s",StrValue,sizeof(StrValue));
  P3DLoadSplineCurve(&DeclinationCurve,SourceStream,StrValue);
  SourceStream->ReadFmtStringTagged("DeclinationV","f",&FloatValue);
  SetDeclinationV(FloatValue);
 }
Exemplo n.º 8
0
void ViewPort::SetBoxes( void )
{

    //  In the case where canvas rotation is applied, we need to define a larger "virtual" pixel window size to ensure that
    //  enough chart data is fatched and available to fill the rotated screen.
    rv_rect = wxRect( 0, 0, pix_width, pix_height );

    //  Specify the minimum required rectangle in unrotated screen space which will supply full screen data after specified rotation
    if( ( g_bskew_comp && ( fabs( skew ) > .001 ) ) || ( fabs( rotation ) > .001 ) ) {

        double rotator = rotation;
        if(g_bskew_comp)
            rotator -= skew;

        int dy = wxRound(
                     fabs( pix_height * cos( rotator ) ) + fabs( pix_width * sin( rotator ) ) );
        int dx = wxRound(
                     fabs( pix_width * cos( rotator ) ) + fabs( pix_height * sin( rotator ) ) );

        //  It is important for MSW build that viewport pixel dimensions be multiples of 4.....
        if( dy % 4 ) dy += 4 - ( dy % 4 );
        if( dx % 4 ) dx += 4 - ( dx % 4 );

        int inflate_x = wxMax(( dx - pix_width ) / 2, 0);
        int inflate_y = wxMax(( dy - pix_height ) / 2, 0);
        
        //  Grow the source rectangle appropriately
        if( fabs( rotator ) > .001 )
            rv_rect.Inflate( inflate_x, inflate_y );

    }

    //  Compute Viewport lat/lon reference points for co-ordinate hit testing

    //  This must be done in unrotated space with respect to full unrotated screen space calculated above
    double rotation_save = rotation;
    SetRotationAngle( 0. );

    double lat_ul, lat_ur, lat_lr, lat_ll;
    double lon_ul, lon_ur, lon_lr, lon_ll;

    GetLLFromPix( wxPoint( rv_rect.x, rv_rect.y ), &lat_ul, &lon_ul );
    GetLLFromPix( wxPoint( rv_rect.x + rv_rect.width, rv_rect.y ), &lat_ur, &lon_ur );
    GetLLFromPix( wxPoint( rv_rect.x + rv_rect.width, rv_rect.y + rv_rect.height ), &lat_lr,
                  &lon_lr );
    GetLLFromPix( wxPoint( rv_rect.x, rv_rect.y + rv_rect.height ), &lat_ll, &lon_ll );

    if( clon < 0. ) {
        if( ( lon_ul > 0. ) && ( lon_ur < 0. ) ) {
            lon_ul -= 360.;
            lon_ll -= 360.;
        }
    } else {
        if( ( lon_ul > 0. ) && ( lon_ur < 0. ) ) {
            lon_ur += 360.;
            lon_lr += 360.;
        }
    }

    if( lon_ur < lon_ul ) {
        lon_ur += 360.;
        lon_lr += 360.;
    }

    if( lon_ur > 360. ) {
        lon_ur -= 360.;
        lon_lr -= 360.;
        lon_ul -= 360.;
        lon_ll -= 360.;
    }

    double dlat_min = lat_ul;
    dlat_min = fmin ( dlat_min, lat_ur );
    dlat_min = fmin ( dlat_min, lat_lr );
    dlat_min = fmin ( dlat_min, lat_ll );

    double dlon_min = lon_ul;
    dlon_min = fmin ( dlon_min, lon_ur );
    dlon_min = fmin ( dlon_min, lon_lr );
    dlon_min = fmin ( dlon_min, lon_ll );

    double dlat_max = lat_ul;
    dlat_max = fmax ( dlat_max, lat_ur );
    dlat_max = fmax ( dlat_max, lat_lr );
    dlat_max = fmax ( dlat_max, lat_ll );

    double dlon_max = lon_ur;
    dlon_max = fmax ( dlon_max, lon_ul );
    dlon_max = fmax ( dlon_max, lon_lr );
    dlon_max = fmax ( dlon_max, lon_ll );

    //  Set the viewport lat/lon bounding box appropriately
    vpBBox.SetMin( dlon_min, dlat_min );
    vpBBox.SetMax( dlon_max, dlat_max );

    // Restore the rotation angle
    SetRotationAngle( rotation_save );
}
Exemplo n.º 9
0
void BombProjectile::Update(float delta)
{
	float targetDelta =  Timing::Instance()->GetTargetDelta();
	float percentDelta = delta / targetDelta;

	// apply gravity to the 
	if (!mIsOnSolidLine)
	{
		if (!mIsInWater)
		{
			m_velocity.Y -= 0.3f * percentDelta;
		}
		else
		{
			m_velocity.Y -= 0.06f * percentDelta;
		}
	}

	// nice simple update
	if (mIsInWater)
	{
		m_velocity.X *= 0.92f; // slow down significantly
		//m_velocity.Y *= 0.9f; // slow down significantly
	}

	m_direction = m_velocity;
	m_direction.Normalise();

	m_position += m_velocity * percentDelta;

	// we dont need complicated movement so we'll ignore the MovingSprite class
	Sprite::Update(delta);

	if (IsOnSolidSurface())
	{
		// StopYAccelerating();

		if (!mIsInWater)
		{
			SetRotationAngle(GetRotationAngle() + ((m_velocity.X * -0.04) *percentDelta));
		}
		else
		{
			SetRotationAngle(GetRotationAngle() + ((m_velocity.X * -0.009) *percentDelta));
		}
	}
	else
	{
		if (!mIsInWater)
		{
			SetRotationAngle(GetRotationAngle() + ((m_velocity.X * -0.01) * percentDelta));
		}
		else
		{
			SetRotationAngle(GetRotationAngle() + ((m_velocity.X * -0.005) * percentDelta));
		}
	}

	if (!m_isActive)
	{
		float currentTime = Timing::Instance()->GetTotalTimeSeconds();
		float timeToDie = m_timeBecameInactive + m_maxTimeInActive;

		if(currentTime > timeToDie)
		{
			// time to kill ourselves
			GameObjectManager::Instance()->RemoveGameObject(this);
		}
	}

	if (mTimeUntilNextParticleSpray > 0.0f)
	{
		mTimeUntilNextParticleSpray -= delta;

		if (mTimeUntilNextParticleSpray < 0.0f)
		{
			mTimeUntilNextParticleSpray = 0.0f;
		}
	}
}