Exemplo n.º 1
0
void AttractableSystem::Update(double DeltaTime)
{
    for (auto actor : mScene.GetActorsFromMap( GetType_static() ))
    {
        auto attractableC( actor->Get<IAttractableComponent>() );
        auto accelerationC( actor->Get<IAccelerationComponent>() );
        auto targetHolderC( actor->Get<ITargetHolderComponent>() );
        auto moveC( actor->Get<IMoveComponent>() );
        if (!attractableC.IsValid() || !accelerationC.IsValid() || !targetHolderC.IsValid() || !moveC.IsValid())
        {
            continue;
        }

        auto const accel = accelerationC->GetAcceleration();
        auto currentTarget( mScene.GetActor( targetHolderC->GetTargetGUID() ) );
        targetHolderC->SetTargetGUID( -1 );
        accelerationC->SetAcceleration( -1 * attractableC->GetDeceleration() );

        if (currentTarget.IsValid())
        {
            auto healthC( currentTarget->Get<IHealthComponent>() );
            if (healthC.IsValid() && healthC->IsAlive())
            {
                accelerationC->SetAcceleration( accel );
                targetHolderC->SetTargetGUID( currentTarget->GetGUID() );
                moveC->SetMoving( true );
                attractableC->GetTurnToTargetAct().Update( *actor, DeltaTime );
            }
        }
    }
}
Exemplo n.º 2
0
void State::Update(double deltaTime) {

    if(IsActive() == false) {
        ClearImpulses();
        ClearForces();
        SetVelocity(0.0, 0.0);
        SetAcceleration(0.0, 0.0);
        return;
    }

    a2de::Vector2D total_forces;
    std::for_each(_forces.begin(), _forces.end(), [&total_forces] (ForceContainer::value_type& current_force) mutable -> a2de::Vector2D 
    {
        if(current_force.second < 0.0) return Vector2D();
        total_forces += current_force.first;
        return total_forces;
    });

    Vector2D total_impulses = std::accumulate(_impulses.begin(), _impulses.end(), Vector2D());
    Vector2D F(total_forces + total_impulses);
    ClearImpulses();
    double mass = GetMass();

    //If static body, do nothing.
    if(Math::IsEqual(mass, 0.0)) {
        ClearImpulses();
        ClearForces();
        SetVelocity(0.0, 0.0);
        SetAcceleration(0.0, 0.0);
        Sleep();
        return;
    }

    //Integrate from constant acceleration.
    //a = F / m
    //v = at + v;
    //p = (1/2)at^2 + vt + p

    SetAcceleration(F / mass);
    SetVelocity(GetAcceleration() * deltaTime + GetVelocity());
    SetPosition(((0.5 * GetAcceleration()) * deltaTime * deltaTime) + (GetVelocity() * deltaTime) + GetPosition());

    _forces.remove_if([=](ForceContainer::value_type& current_force)->bool {
        current_force.second -= deltaTime;
        return (current_force.second < 0.0);
    });

    if(_impulses.empty() && _forces.empty() &&
      ((a2de::Math::IsEqual(_acceleration.GetX(), 0.0) && a2de::Math::IsEqual(_acceleration.GetY(), 0.0)) &&
      (a2de::Math::IsEqual(_velocity.GetX(), 0.0) && a2de::Math::IsEqual(_velocity.GetY(), 0.0))))
    {
        SetVelocity(0.0, 0.0);
        SetAcceleration(0.0, 0.0);
        Sleep();
    } else {
        Wake();
    }      

}
Exemplo n.º 3
0
	Ball::Ball(Rules& rules) : Entity(rules) {
		rules.numBalls++;

		_ignited = false;
		_dying = false;

		_scoreSound = SoundManager::Instance().GetSound("res/ding.wav", false);
		_bounceSound = SoundManager::Instance().GetSound("res/bounce.wav", false);

		_ballSprite = ImageManager::Instance().CreateSprite("res/ball3.png");
		_ballSprite.SetColor(sf::Color(232, 243, 255));
		_ballSprite.Resize(BALL_SIZE, BALL_SIZE);

		MATH::Vector2 randomVector(0, -1.0f);
		randomVector = MATH::Rotate(randomVector, sf::Randomizer::Random(-0.1f, 0.1f));
		randomVector = MATH::Normalize(randomVector);

		SetAcceleration(1.0f);
		SetVelocity(randomVector * 300.0f);
		SetMass(1.0f);

		SetPhysicsModel(PHY_TOUCHING | PHY_SOLID | PHY_BOUNCING);
		SetCollisionModel(PHY_SOLID);

		SetBBox(MATH::BBox2(MATH::Vector2(0.0f, 0.0f),
			MATH::Vector2(BALL_SIZE, BALL_SIZE)));
	}
Exemplo n.º 4
0
void CPointerAction::ReadProfileData(wxConfigBase* pConfObj)
{
	long val;
	bool valb;

	pConfObj->SetPath (_T("pointerAction"));

	if (pConfObj->Read(_T("xSpeed"), &val))	SetXSpeed(val);
	if (pConfObj->Read(_T("ySpeed"), &val))	SetYSpeed(val);
	if (pConfObj->Read(_T("acceleration"), &val)) SetAcceleration(val);
	if (pConfObj->Read(_T("smoothness"), &val)) SetSmoothness(val);
	if (pConfObj->Read(_T("easyStop"), &val)) SetEasyStopValue(val);
	if (pConfObj->Read(_T("enabledWorkspace"), &valb)) SetRestrictedWorkingArea(valb);
	if (pConfObj->Read(_T("enabledWrapPointer"), &valb)) SetWrapPointer(valb);
	if (pConfObj->Read(_T("topWorkspace"), &val)) SetTopWorkspace(val);
	if (pConfObj->Read(_T("leftWorkspace"), &val)) SetLeftWorkspace(val);
	if (pConfObj->Read(_T("rightWorkspace"), &val)) SetRightWorkspace(val);
	if (pConfObj->Read(_T("bottomWorkspace"), &val)) SetBottomWorkspace(val);
	if (pConfObj->Read(_T("clickMode"), &val)) SetClickMode((CPointerAction::EClickMode) val);
	pConfObj->Read(_T("beepOnClick"), &m_beepOnClick);	

	m_pDwellClick->ReadProfileData(pConfObj);
	m_pGestureClick->ReadProfileData(pConfObj);

	pConfObj->SetPath (_T(".."));
}
void CFireParticleSystem::Initialize(OpenGLES::OpenGLESContext *_gl, GLuint *_textureImageID, Env * _env, int _point_number)
{
	gl = _gl;
	textureImageID = _textureImageID;
	env = _env;
	point_number = _point_number;
	
	fire_particles = new CFireParticle[point_number]();
	particle_x = new int[point_number];
	particle_y = new int[point_number];
	last_particle_initialized = 0;
	
	totalTime = 0.0f;
	signal = 1;
	change_cycle = RANDOM_FLOAT * 0.5f;
	
	m_fMinDieAge = 1.5f;
	m_fMaxDieAge = 0.5f;
	SetCreationDieColor(Vector3D(0.9f,0.8f,0.3f),Vector3D(0.9f,0.9f,0.4f),Vector3D(0.8f,0.724f,0.16f),Vector3D(0.81f,0.725f,0.17f));
	SetAlphaValues(1.0f,1.0f,0.0f,0.0f);
	SetSpinSpeed(-0.82*GLT_PI,0.82*GLT_PI);
	
#define SIZE_ONE 0.5f
	
	SetSizeValues(SIZE_ONE,2*SIZE_ONE,SIZE_ONE,2*SIZE_ONE);
	SetAcceleration(Vector3D(0.0f,-10.0f,0.0f),1.3f,0.4f);
	m_fMaxEmitSpeed = 40.0f;
	m_fMinEmitSpeed = 10.0f;
	SetEmissionDirection(Vector3D(0.0f,0.0f,0.0f),Vector3D(0.0f,0.0f,0.0f));
	SetEmitter(Vector3D(0.0f,0.0f,0.0f), Vector3D(0.2f,0.2f,0.0f));
}
Exemplo n.º 6
0
	Block::Block(Rules& rules, const sf::Color& color, int health) : Entity(rules) {
		_highlight = false;
		_highlightPhase = 0.0f;

		_drop = false;
		_health = health;
		_decay = 1.0f;
		_rotation = 0.0f;
		_angularVelocity = 0.0f;

		_color = color;

		_blockSprite = ImageManager::Instance().CreateSprite("res/brick.png");
		_blockSprite.Resize(BLOCK_WIDTH, BLOCK_HEIGHT);
		_blockSprite.SetColor(_color);

		SetBBox(MATH::BBox2(MATH::Vector2(0.0f, 0.0f),
			MATH::Vector2(BLOCK_WIDTH, BLOCK_HEIGHT)));

		SetPhysicsModel(PHY_GHOST);
		SetCollisionModel(PHY_SOLID);

		SetAcceleration(1.0f);
		SetVelocity(MATH::Vector2(0.0f, 0.0f));
		SetMass(100000.0f);
	}
Exemplo n.º 7
0
void CGameObject::Stop()
{
	SetVelocity(D3DXVECTOR2(0,0));
	SetAcceleration(D3DXVECTOR2(0,0));
	SetMaxAcceleration(D3DXVECTOR2(0,0));
	SetMaxVelocity(D3DXVECTOR2(0,0));
}
Exemplo n.º 8
0
/** Reset this game object back to the center of the game world. */
void GameObject::Reset()
{
	SetPosition(GLVector3f(0,0,0));
	SetVelocity(GLVector3f(0,0,0));
	SetAcceleration(GLVector3f(0,0,0));
	SetAngle(0);
	SetRotation(0);
}
Exemplo n.º 9
0
void Character::UpdateItSelf( float dTime )
{
	// 가속
	if ( IsAccelerating() )
	{
		if ( timeGetTime() - GetAccelerationStartTime() > ACCELERATION_TIME )
		{
			// 가속 끝났다
			SetIsAccelerating( false );
			SetAcceleration( ZERO_VECTOR3 );
		}
	}

	if ( !m_CharacterClass->IsAlive() )
	{
		//printf_s( "player %d is dead \n", m_CharacterId );
		return;
	}

	m_Matrix = GetTransform()->MatrixTransform();

	if ( IsSpinning() )
	{
		AddSpinTime( dTime );

		// 회전축을 기준으로 물체를 회전시킵니다.
		D3DXMATRIXA16 spinTransform;
		D3DXVECTOR3 tmpSpinAxis = GetSpinAxis();
		float tmpSpinAngle = GetSpinAngularVelocity();
		D3DXMatrixRotationAxis( &spinTransform, &tmpSpinAxis, tmpSpinAngle * GetSpinTime() );
		// D3DXMatrixMultiply( &m_Matrix, &m_Matrix, &spinTransform );
		D3DXMatrixMultiply( &m_Matrix, &spinTransform, &m_Matrix );
	}

	D3DXVECTOR3 tmpVec3 = GetTransform()->GetPosition();
	D3DXVECTOR3 tmpVel = GetVelocity();

	Physics::CalcCurrentPosition( &tmpVec3, &tmpVel, GetAcceleration(), dTime, GetSpeedConstant() );

	// 최대 이동거리 제한
	float currentDistanceFromOrigin = D3DXVec3Length( &tmpVec3 );
	if ( currentDistanceFromOrigin > MAX_DISTANCE_FROM_ORIGIN )
		m_CharacterClass->SetOxygen( 0.0f );

	// 최대 속도 제한
	float currentSpeed = D3DXVec3Length( &tmpVel );
	if ( currentSpeed > MAX_PLAYER_SPEED )
	{
		D3DXVec3Normalize( &tmpVel, &tmpVel );
		tmpVel *= MAX_PLAYER_SPEED;
	}

	GetTransform()->SetPosition( tmpVec3 );
	SetVelocity( tmpVel );

	// 산소량 감소등의 작업 처리
	GetClassComponent()->Update( dTime );
}
Exemplo n.º 10
0
void Weapon::Clone(Weapon *pClone)
{
	Component::Clone(pClone);

	SetAcceleration(pClone->GetAcceleration());
	SetCooldown(pClone->GetCooldown());
	SetSpeed(pClone->GetSpeed());
	SetDamage(pClone->GetDamage());
}
void Energy::Update (Zeni::Time::Second_Type elapsedTime)
{
    Zeni::Point2f hero = HeroComponent::GetInstance().GetPosition();
    Zeni::Vector3f a (hero.x - position.x, hero.y - position.y, 0.0f);
    a.normalize();

    SetAcceleration (100.0f * a);

    Simulateable::UpdatePosition (elapsedTime);
}
Exemplo n.º 12
0
	void Ball::Think(float secsPassed) {
		_emitter.Move(secsPassed);
		_blur.Move(secsPassed);

		if(!_dying) {
			MATH::Vector2 position(GetPosition());
			sf::Vector2f offset = 0.5f * _ballSprite.GetSize();
			position.x += offset.x;
			position.y += offset.y;
			_blur.SetPosition(position);
			_blur.Emit();
		}

		/*
		okay, this is of course super non-realistic, but we need
		a (not too) fast ball to keep the game going
		*/
		float vel = GetVelocity().Length();
		
		if(900.0f < vel) {
			SetVelocity(900.0f * MATH::Normalize(GetVelocity()));
		}
		
		if(300.0f < vel) {
			SetAcceleration(0.98f);
		} else if(300.0f > vel)  {
			SetAcceleration(1.02f);
		} else {
			SetAcceleration(1.0f);
		}

		if(_dying) {
			_health -= _decayRate * secsPassed;
			if(0.0f >= _health) {
				GetRules().numBalls--;
				Die();
			}
		}
	}
Exemplo n.º 13
0
void Actor::UpdateItSelf( float dTime )
{
    // 가속
    if ( IsAccelerating() )
    {
        if ( timeGetTime() - GetAccelerationStartTime() > ACCELERATION_TIME )
        {
            // 가속 끝났다
            SetIsAccelerating( false );
            SetAcceleration( ZERO_VECTOR3 );
        }
    }
}
	ExtraBallItem::ExtraBallItem(Rules& rules) : Entity(rules) {
		_itemSprite = ImageManager::Instance().CreateSprite("res/item_extraball.png");
		_itemSprite.Resize(ITEM_WIDTH, ITEM_HEIGHT);

		SetBBox(MATH::BBox2(MATH::Vector2(0.0f, 0.0f),
			MATH::Vector2(ITEM_WIDTH, ITEM_HEIGHT)));

		SetAcceleration(1.0f);
		SetVelocity(MATH::Vector2(0.0f, 1.0f) * 100.0f);
		SetMass(1.0f);

		SetPhysicsModel(PHY_TOUCHING | PHY_GHOST);
		SetCollisionModel(PHY_GHOST);
	}
Exemplo n.º 15
0
// Configuration methods
void CPointerAction::InitDefaults()
{
	// General attributes
	SetXSpeed (12);
	SetYSpeed (10);
	SetAcceleration (2);
	SetClickMode (CPointerAction::DWELL);
	SetBeepOnClick (true);
	SetSmoothness (4);
	SetEasyStopValue (1); 
	SetWrapPointer(false);
	
	// Workspace limits
	SetRestrictedWorkingArea (false);
	SetTopWorkspace(1);
	SetLeftWorkspace(1);
	SetRightWorkspace(1);
	SetBottomWorkspace(1);
}
Exemplo n.º 16
0
Humanoid::Humanoid(int iType, int iPlayerFlag) : Character(iType, iPlayerFlag) 
{
	bGroundClamped = true;

	SetAcceleration(100);
	SetFriction(35);
	SetJumpStrength(15);


	iSelectedArrow=Arrow::ARROW_TYPE_NORMAL;

	SetWHO(Vector(0, 0.5f, 1.0f));


	//initialize all elements in iActionArray to -1 (-1 is a bogus entry)
	for(int i=0; i< HUMANOID_NUM; ++i)
		iActionArray[i]=-1;

	if(cPlayer==CHARACTER_PLAYER1||cPlayer==CHARACTER_PLAYER2)
	{
		pActionMap->GetJoystick()->SetDeadZone(900);

		iActionArray[HUMANOID_JUMP]=pActionMap->AddAction("Jump", DIK_SPACE, -1, JOYSTICK_BUTTON(2));

		iActionArray[HUMANOID_SHOOT_ARROW]=pActionMap->AddAction("Shoot Arrow", DIK_UP, -1, JOYSTICK_BUTTON(0));

		iActionArray[HUMANOID_SWITCH_ARROW]=pActionMap->AddAction("Switch Arrow", DIK_DOWN, -1, JOYSTICK_BUTTON(3));

		iActionArray[HUMANOID_SWING_CAMERA_LEFT]=pActionMap->AddAction("Camera Left", DIK_LEFT, -1, JOYSTICK_BUTTON(4));

		iActionArray[HUMANOID_SWING_CAMERA_RIGHT]=pActionMap->AddAction("Camera Right", DIK_RIGHT, -1, JOYSTICK_BUTTON(5));

		//keyboard movement controls
		//iActionArray[HUMANOID_MOVE_FORWARD]=pActionMap->AddAction("Move Forward", DIK_W, NULL, NULL);
		//iActionArray[HUMANOID_MOVE_BACKWARD]=pActionMap->AddAction("Move Backward", DIK_S, NULL, NULL);
		//iActionArray[HUMANOID_MOVE_RIGHT]=pActionMap->AddAction("Move Right", DIK_D, NULL, NULL);
		//iActionArray[HUMANOID_MOVE_LEFT]=pActionMap->AddAction("Move Left", DIK_A, NULL, NULL);
	}
}
Exemplo n.º 17
0
//-----------------------------------------------------------------------------
// Purpose: Run a frame for the ship
//-----------------------------------------------------------------------------
void CShip::RunFrame()
{
	if ( m_bDisabled )
		return;

	const uint64 ulCurrentTickCount = m_pGameEngine->GetGameTickCount();

	// Look for expired photon beams
	int nNextAvailablePhotonBeamSlot = -1;  // Track next available slot for use spawning new beams below
	for( int i=0; i < MAX_PHOTON_BEAMS_PER_SHIP; ++i )
	{
		if ( m_rgPhotonBeams[i] )
		{
			if ( m_rgPhotonBeams[i]->BIsBeamExpired() )
			{
				delete m_rgPhotonBeams[i];
				m_rgPhotonBeams[i] = NULL;
			}
		}

		if ( !m_rgPhotonBeams[i] && nNextAvailablePhotonBeamSlot == -1 )
			nNextAvailablePhotonBeamSlot = i;
	}

	// run all the photon beams we have outstanding
	for( int i=0; i < MAX_PHOTON_BEAMS_PER_SHIP; ++i )
	{
		if ( m_rgPhotonBeams[i] )
			m_rgPhotonBeams[i]->RunFrame();
	}

	// run all the space debris
	{
		std::list<CShipDebris *>::iterator iter;
		for( iter = m_ListDebris.begin(); iter != m_ListDebris.end(); ++iter )
			(*iter)->RunFrame();
	}

	if ( m_bIsLocalPlayer )
	{
		m_SpaceWarClientUpdateData.SetTurnLeftPressed( false );
		m_SpaceWarClientUpdateData.SetTurnRightPressed( false );

		if ( m_pGameEngine->BIsKeyDown( m_dwVKLeft ) )
		{
			m_SpaceWarClientUpdateData.SetTurnLeftPressed( true );
		}
		
		if ( m_pGameEngine->BIsKeyDown( m_dwVKRight ) )
		{
			m_SpaceWarClientUpdateData.SetTurnRightPressed( true );
		}
	}
	else if ( m_bIsServerInstance )
	{
		// Server side
		float flRotationDelta = 0.0f;
		if ( m_SpaceWarClientUpdateData.GetTurnLeftPressed() )
		{
			flRotationDelta += (PI_VALUE/2.0f) * -1.0f * (float)m_pGameEngine->GetGameTicksFrameDelta()/400.0f;
		}

		if ( m_SpaceWarClientUpdateData.GetTurnRightPressed() )
		{
			flRotationDelta += (PI_VALUE/2.0f) * (float)m_pGameEngine->GetGameTicksFrameDelta()/400.0f;
		}
		SetRotationDeltaNextFrame( flRotationDelta );
	}
	
	// Compute acceleration
	if ( m_bIsLocalPlayer )
	{
		// client side
		m_SpaceWarClientUpdateData.SetReverseThrustersPressed( false );
		m_SpaceWarClientUpdateData.SetForwardThrustersPressed( false );
		if ( m_pGameEngine->BIsKeyDown( m_dwVKForwardThrusters ) || m_pGameEngine->BIsKeyDown( m_dwVKReverseThrusters ) )
		{
			if ( m_pGameEngine->BIsKeyDown( m_dwVKReverseThrusters ) )
			{
				m_SpaceWarClientUpdateData.SetReverseThrustersPressed( true );
			}
			else
			{
				m_SpaceWarClientUpdateData.SetForwardThrustersPressed( true );
			}
		}
	}
	else if ( m_bIsServerInstance )
	{
		// Server side
		float xThrust = 0;
		float yThrust = 0;
		m_bReverseThrustersActive = false;
		m_bForwardThrustersActive = false;
		if ( m_SpaceWarClientUpdateData.GetReverseThrustersPressed() || m_SpaceWarClientUpdateData.GetForwardThrustersPressed() )
		{
			float flSign = 1.0f;
			if ( m_SpaceWarClientUpdateData.GetReverseThrustersPressed() )
			{
				m_bReverseThrustersActive = true;
				flSign = -1.0f;
			}
			else
			{
				m_bForwardThrustersActive = true;
			}

			if ( m_ulLastThrustStartedTickCount == 0 )
				m_ulLastThrustStartedTickCount = ulCurrentTickCount;

			// You have to hold the key for a second to reach maximum thrust
			float factor = MIN( ((float)(ulCurrentTickCount - m_ulLastThrustStartedTickCount) / 500.0f) + 0.2f, 1.0f );

			xThrust = flSign * (float)(MAXIMUM_SHIP_THRUST * factor * sin( GetAccumulatedRotation() ) );
			yThrust = flSign * -1.0f * (float)(MAXIMUM_SHIP_THRUST * factor * cos( GetAccumulatedRotation() ) );
		}
		else
		{
			m_ulLastThrustStartedTickCount = 0;
		}

		SetAcceleration( xThrust, yThrust );
	}


	// We'll use these values in a few places below to compute positions of child objects
	// appropriately given our rotation
	float sinvalue = (float)sin( GetAccumulatedRotation() );
	float cosvalue = (float)cos( GetAccumulatedRotation() );

	if ( m_bIsLocalPlayer )
	{
		// client side
		if ( m_pGameEngine->BIsKeyDown( m_dwVKFire ) )
		{
			m_SpaceWarClientUpdateData.SetFirePressed( true );
		}
	}
	else if ( m_bIsServerInstance )
	{
		// server side
		if ( nNextAvailablePhotonBeamSlot != -1 && !m_bExploding && m_SpaceWarClientUpdateData.GetFirePressed() && ulCurrentTickCount - PHOTON_BEAM_FIRE_INTERVAL_TICKS > m_ulLastPhotonTickCount )
		{
			m_ulLastPhotonTickCount = ulCurrentTickCount;

			float xVelocity = GetXVelocity() + ( sinvalue * 275 );
			float yVelocity = GetYVelocity() - ( cosvalue * 275 );

			// Offset 12 points up from the center of the ship, compensating for rotation
			float xPos = GetXPos() - sinvalue*-12.0f;
			float yPos = GetYPos() + cosvalue*-12.0f;

			m_rgPhotonBeams[nNextAvailablePhotonBeamSlot] = new CPhotonBeam( m_pGameEngine, xPos, yPos, m_dwShipColor, GetAccumulatedRotation(), xVelocity, yVelocity );
		}
	}

	CSpaceWarEntity::RunFrame();

	// Finally, update the thrusters ( we do this after the base class call as they rely on our data being fully up-to-date)
	m_ForwardThrusters.RunFrame();
	m_ReverseThrusters.RunFrame();
}
Exemplo n.º 18
0
void CFireParticleSystem::OnRotateWithAccelerometer(double x, double y, double z)
{
	SetAcceleration(Vector3D(x*10, y*10, z*10), 1.3f, 0.4f);
}
Exemplo n.º 19
0
// Move the ray vertically
void MantaRayControls::MoveVertical(float acceleration)
{
	SetAcceleration(vector3(rayAcceleration.x, rayAcceleration.y + acceleration, rayAcceleration.z));
}
Exemplo n.º 20
0
// Moves the ray sideways
void MantaRayControls::MoveSideways(float acceleration)
{
	SetAcceleration(vector3(rayAcceleration.x + acceleration, rayAcceleration.y, rayAcceleration.z));
}
Exemplo n.º 21
0
//Moves the ray forward, NOTE: This is currently not implemented
void MantaRayControls::MoveForward(float acceleration)
{
	SetAcceleration(vector3(rayAcceleration.x, rayAcceleration.y, rayAcceleration.z + acceleration));
}
Exemplo n.º 22
0
void MantaRayControls::Update(void)
{
	if (boIndex == -1){
		boIndex = BoundingObjectManager::GetInstance()->AddBox("MantaRay", MeshManagerSingleton::GetInstance()->GetVertexList("MantaRay"));
	}

	vector3 v3Acceleration = rayAcceleration / rayMass;
	v3Acceleration = glm::clamp(v3Acceleration, -rayMaxAcceleration, rayMaxAcceleration);
	rayVelocity += v3Acceleration;
	rayPosition += rayVelocity;

	matrix4 m4ToWorld = glm::translate(rayPosition)*glm::scale(vector3(0.25,0.25,0.25));
	BoundingObjectManager::GetInstance()->boundingObjects[boIndex]->SetModelMatrix(m4ToWorld);

	if (rayVelocity != vector3(0.0f))
	{
		if (rayVelocity.x > 0.0f)
		{
			rayVelocity.x -= rayFriction;
		}
		if (rayVelocity.x < 0.0f)
		{
			rayVelocity.x += rayFriction;
		}
		if (rayVelocity.y > 0.0f)
		{
			rayVelocity.y -= rayFriction;
		}
		if (rayVelocity.y < 0.0f)
		{
			rayVelocity.y += rayFriction;
		}
		if (rayVelocity.z > 0.0f)
		{
			rayVelocity.z -= rayFriction;
		}
		if (rayVelocity.z < 0.0f)
		{
			rayVelocity.z += rayFriction;
		}
	}

	if (rayPosition.x > boundary.x)
	{
		SetPosition(vector3(boundary.x + rayAcceleration.x, rayPosition.y, rayPosition.z));
		SetAcceleration(vector3(0.0f, rayAcceleration.y, rayAcceleration.z));
		SetVelocity(vector3(0.0f, rayVelocity.y, rayVelocity.z));
	}
	else if (rayPosition.x < -boundary.x)
	{
		SetPosition(vector3(-boundary.x + rayAcceleration.x, rayPosition.y, rayPosition.z));
		SetAcceleration(vector3(0.0f));
		SetVelocity(vector3(0.0f));
	}

	if (rayPosition.y > boundary.y)
	{
		SetPosition(vector3(rayPosition.x, boundary.y + rayAcceleration.y, rayPosition.z));
		SetAcceleration(vector3(rayAcceleration.x, 0.0f, rayAcceleration.z));
		SetVelocity(vector3(rayVelocity.x, 0.0f, rayVelocity.z));
	}
	else if (rayPosition.y < -boundary.y)
	{
		SetPosition(vector3(rayPosition.x, -boundary.y + rayAcceleration.y, rayPosition.z));
		SetAcceleration(vector3(0.0f));
		SetVelocity(vector3(0.0f));
	}
}
Exemplo n.º 23
0
void State::SetAcceleration(double x, double y) { SetAcceleration(Vector2D(x, y)); }
Exemplo n.º 24
0
void State::SetYAcceleration(double y) { SetAcceleration(_acceleration.GetX(), y); }
Exemplo n.º 25
0
void State::SetXAcceleration(double x) { SetAcceleration(x, _acceleration.GetY()); }