Esempio n. 1
0
void RoboCatServer::Update()
{
	RoboCat::Update();
	
	Vector3 oldLocation = GetLocation();
	Vector3 oldVelocity = GetVelocity();
	float oldRotation = GetRotation();

	ClientProxyPtr client = NetworkManagerServer::sInstance->GetClientProxy( GetPlayerId() );
	if( client )
	{
		MoveList& moveList = client->GetUnprocessedMoveList();
		for( const Move& unprocessedMove : moveList )
		{
			const InputState& currentState = unprocessedMove.GetInputState();
			float deltaTime = unprocessedMove.GetDeltaTime();
			ProcessInput( deltaTime, currentState );
			SimulateMovement( deltaTime );
		}

		moveList.Clear();
	}

	HandleShooting();

	if( !RoboMath::Is2DVectorEqual( oldLocation, GetLocation() ) ||
		!RoboMath::Is2DVectorEqual( oldVelocity, GetVelocity() ) ||
		oldRotation != GetRotation() )
	{
		NetworkManagerServer::sInstance->SetStateDirty( GetNetworkId(), ECRS_Pose );
	}
}
Esempio n. 2
0
void CObject::Move ( const CVector& vecPosition, const CVector& vecRotation, unsigned long ulTime )
{
    // Are we already moving?
    if ( IsMoving () )
    {
        // Stop our current movement
        StopMoving ();
    }

    // If it's more than 0 milliseconds
    if ( ulTime > 0 )
    {
        // Setup our move data
        m_moveData.vecStartPosition = GetPosition ();
        m_moveData.vecStopPosition = vecPosition;
        GetRotation ( m_moveData.vecStartRotation );
        m_moveData.vecStopRotation = vecRotation;
        m_moveData.ulTime = ulTime;
        m_moveData.ulTimeStart = GetTime ();
        m_moveData.ulTimeStop = m_moveData.ulTimeStart + ulTime;
        m_moveData.bActive = true;
    }
    // If we have a time of 0, move there now
    else
    {
        SetPosition ( vecPosition );
        CVector vecTemp;
        GetRotation ( vecTemp );
        SetRotation ( vecTemp + vecRotation );
    }
}
Esempio n. 3
0
LineSegment OrientedBoxShape::GetEdge(int EdgeIdx)const
{
	sf::Vector2f P1 = GetHalfExtents();
	sf::Vector2f P2 = GetHalfExtents();

	switch(EdgeIdx % 4) 
	{
	case 0:/* top edge */
		P1.x = -P1.x;
		break;
	case 1:/* right edge */
		P2.y = -P2.y;
		break;
	case 2:/* bottom edge */
		P1.y = -P1.y;
		P2 = -P2;
		break;
	default:/* left edge */
		P1 = -P1;
		P2.x = -P2.x;
		break;
	}

	P1 = MathUtils::RotateVector(P1, GetRotation());
	P1 = P1 + GetCenter();

	P2 = MathUtils::RotateVector(P1, GetRotation());
	P2 = P2 + GetCenter();

	return LineSegment(P1, P2);
}
Esempio n. 4
0
void Player::Move()
{
	//fprintf(stderr, "Move Forward\n");
	Vector2 rotation = this->GetRotation();
	Vector2 velocity = this->GetVelocity();
	rotation = Vector2(GetRotation().GetX(), GetRotation().GetY());
	velocity = velocity + rotation * 4 * pEngine->GetDeltaTime();
	SetVelocity(velocity);
}
Esempio n. 5
0
void Wall::OnDestroy( bool bomb )
{
    if ( bomb )
        return;
    Vec2 d = _dir;
    d.Rotate( M_PI / M_TWO );
    Vec2 v = GetPosition() + d * M_TEN * 3;
    if ( v._x >= 0 && v._x <= Lib::WIDTH && v._y >= 0 && v._y <= Lib::HEIGHT )
        Spawn( new Square( v, GetRotation() ) );
    v = GetPosition() - d * M_TEN * 3;
    if ( v._x >= 0 && v._x <= Lib::WIDTH && v._y >= 0 && v._y <= Lib::HEIGHT )
        Spawn( new Square( v, GetRotation() ) );
}
Esempio n. 6
0
void cEntity::TakeDamage(eDamageType a_DamageType, cEntity * a_Attacker, int a_RawDamage, int a_FinalDamage, double a_KnockbackAmount)
{
	TakeDamageInfo TDI;
	TDI.DamageType = a_DamageType;
	TDI.Attacker = a_Attacker;
	TDI.RawDamage = a_RawDamage;
	TDI.FinalDamage = a_FinalDamage;
	Vector3d Heading;
	Heading.x = sin(GetRotation());
	Heading.y = 0.4;  // TODO: adjust the amount of "up" knockback when testing
	Heading.z = cos(GetRotation());
	TDI.Knockback = Heading * a_KnockbackAmount;
	DoTakeDamage(TDI);
}
Esempio n. 7
0
uint32_t TommyCoin::Write( OutgoingPacketBuffer& inPacket, uint32_t inDirtyState ) const 
{

	uint32_t writtenState = 0;

	uint32_t remainingBytes = inPacket.GetRemainingBytes();

	if( remainingBytes >= 3 * sizeof( float ) + sizeof( XMVECTOR ) )
	{
		bool poseDirty = inDirtyState & ETCRS_Pose;
		bool colorDirty = inDirtyState & ETCRS_Color;

		inPacket.Write(poseDirty);
		if (poseDirty) {
			XMVECTORF32 location; location.v = GetLocation();
			inPacket.Write(location.f[0]);
			inPacket.Write(location.f[1]);

			inPacket.Write(GetRotation());
		}

		inPacket.Write(colorDirty);
		if (colorDirty) {
			inPacket.Write(GetColor());
		}

		writtenState |= inDirtyState;
	}

	return writtenState;
}
Esempio n. 8
0
void MovingObstacle::Update(float dt)
{
    if(this->IsDestroyed() || m_snake == NULL)
    {
        return;
    }
    
    Actor::Update(dt);
    const float rotation = GetRotation();
    SetRotation((rotation + 190 * dt));
    
    Vector2 position = GetPosition();
    
    position += m_direction * (m_speed * dt);
    
    SetPosition(position);
    
    
    if(++m_movementCount % m_maxMovements == 0)
    {
        m_direction *= -1;
    }
    
    if(!m_snake->isInvulnerable() && m_snake->collided(this))
    {
        m_snake->collide();
    }    
}
Esempio n. 9
0
void Viewer3dParam::Print( FILE *fp )
{
    fprintf(fp, "%f %f %f ", eye[0], eye[1], eye[2]);
    Quaternion q = GetRotation();
    q.Print(fp);
    fprintf(fp, "\n");
}
Esempio n. 10
0
void CClientVehicle::Serialize(CBitStream * pBitStream)
{
	// Write the vehicle position
	CVector3 vecPosition;
	GetPosition(vecPosition);
	pBitStream->Write(vecPosition);

	// Write the vehicle rotation
	CVector3 vecRotation;
	GetRotation(vecRotation);
	pBitStream->Write(vecRotation);

	// Write the vehicle move speed
	CVector3 vecMoveSpeed;
	GetMoveSpeed(vecMoveSpeed);
	pBitStream->Write(vecMoveSpeed);

	// Write the vehicle turn speed
	CVector3 vecTurnSpeed;
	GetTurnSpeed(vecTurnSpeed);
	pBitStream->Write(vecTurnSpeed);

	// Write the vehicle health
	pBitStream->Write(GetHealth());
}
Esempio n. 11
0
void CTextureNode::Render()
{
	// Check if the texture is loaded
	if ( m_GLTexture.IsLoaded() && m_Visible )
	{
		glLoadIdentity();
		glTranslatef( m_PositionAbsolute.x, m_PositionAbsolute.y, m_PositionAbsolute.z);
		glRotatef( GetRotation() ,0.0f,0.0f,1.0f);

		m_GLTexture.Bind();
		m_VBO[m_FrameNum]->BindBuffer();
		glTexCoordPointer(2,GL_FLOAT,5 * sizeof(GLfloat), ((GLubyte *) 0) );
		glVertexPointer(3,GL_FLOAT,5 * sizeof(GLfloat), ((GLubyte *) 0 + (2*sizeof(GLfloat))) );

		glEnableClientState(GL_TEXTURE_COORD_ARRAY);
		glEnableClientState(GL_VERTEX_ARRAY);

		glDrawArrays(GL_TRIANGLE_STRIP,0,4);

		glDisableClientState(GL_COLOR_ARRAY);
		glDisableClientState(GL_TEXTURE_COORD_ARRAY);
		m_VBO[m_FrameNum]->UnBindBuffer();
		m_GLTexture.UnBind();

	}
	CBaseNode::Render();
}
Esempio n. 12
0
bool cPlayer::SaveToDisk()
{
    cFile::CreateFolder(FILE_IO_PREFIX + AString("players"));

    // create the JSON data
    Json::Value JSON_PlayerPosition;
    JSON_PlayerPosition.append(Json::Value(GetPosX()));
    JSON_PlayerPosition.append(Json::Value(GetPosY()));
    JSON_PlayerPosition.append(Json::Value(GetPosZ()));

    Json::Value JSON_PlayerRotation;
    JSON_PlayerRotation.append(Json::Value(GetRotation()));
    JSON_PlayerRotation.append(Json::Value(GetPitch()));
    JSON_PlayerRotation.append(Json::Value(GetRoll()));

    Json::Value JSON_Inventory;
    m_Inventory.SaveToJson(JSON_Inventory);

    Json::Value root;
    root["position"]       = JSON_PlayerPosition;
    root["rotation"]       = JSON_PlayerRotation;
    root["inventory"]      = JSON_Inventory;
    root["health"]         = m_Health;
    root["xpTotal"]        = m_LifetimeTotalXp;
    root["xpCurrent"]      = m_CurrentXp;
    root["air"]            = m_AirLevel;
    root["food"]           = m_FoodLevel;
    root["foodSaturation"] = m_FoodSaturationLevel;
    root["foodTickTimer"]  = m_FoodTickTimer;
    root["foodExhaustion"] = m_FoodExhaustionLevel;
    root["world"] = GetWorld()->GetName();

    if (m_GameMode == GetWorld()->GetGameMode())
    {
        root["gamemode"] = (int) eGameMode_NotSet;
    }
    else
    {
        root["gamemode"] = (int) m_GameMode;
    }

    Json::StyledWriter writer;
    std::string JsonData = writer.write(root);

    AString SourceFile;
    Printf(SourceFile, "players/%s.json", m_PlayerName.c_str() );

    cFile f;
    if (!f.Open(SourceFile, cFile::fmWrite))
    {
        LOGERROR("ERROR WRITING PLAYER \"%s\" TO FILE \"%s\" - cannot open file", m_PlayerName.c_str(), SourceFile.c_str());
        return false;
    }
    if (f.Write(JsonData.c_str(), JsonData.size()) != (int)JsonData.size())
    {
        LOGERROR("ERROR WRITING PLAYER JSON TO FILE \"%s\"", SourceFile.c_str());
        return false;
    }
    return true;
}
Esempio n. 13
0
void CVehicle::GetMatrix( CMatrix& matrix )
{
    CVector vecRotation;
    GetRotation( vecRotation );
    matrix.SetRotation( vecRotation );
    matrix.vPos = GetPosition();
}
Esempio n. 14
0
void CVehicleEntity::SetTargetRotation(const CVector3& vecRotation, unsigned long ulDelay)
{
    // Are we spawned?
    if(IsSpawned())
	{
        // Update our target rotation
        UpdateTargetRotation();

        // Get the current time
        unsigned long ulTime = SharedUtility::GetTime();

        // Get our local rotation
        CVector3 vecLocalRotation;
        GetRotation(vecLocalRotation);

        // Set the target rotation
        m_interp.rot.vecTarget = vecRotation;

        // Get the error
        m_interp.rot.vecError = Math::GetOffsetDegrees(vecLocalRotation, vecRotation);

        // Get the interpolation interval
        m_interp.rot.ulStartTime = ulTime;
        m_interp.rot.ulFinishTime = (ulTime + ulDelay);

        // Initialize the interpolation
        m_interp.rot.fLastAlpha = 0.0f;
    }

    // Set our rotation straight
    m_vecRotation = vecRotation;
}
Esempio n. 15
0
bool FTransform::DebugEqualMatrix(const FMatrix& Matrix) const
{
	FTransform TestResult(Matrix);
	if (!Equals(TestResult))
	{
		// see now which one isn't equal		
		if (!Scale3DEquals(TestResult.Scale3D, ScalarRegister(0.01f)))
		{
			UE_LOG(LogTransform, Log, TEXT("Matrix(S)\t%s"), *TestResult.GetScale3D().ToString());
			UE_LOG(LogTransform, Log, TEXT("VQS(S)\t%s"), *GetScale3D().ToString());
		}

		// see now which one isn't equal
		if (!RotationEquals(TestResult.Rotation))
		{
			UE_LOG(LogTransform, Log, TEXT("Matrix(R)\t%s"), *TestResult.GetRotation().ToString());
			UE_LOG(LogTransform, Log, TEXT("VQS(R)\t%s"), *GetRotation().ToString());
		}

		// see now which one isn't equal
		if (!TranslationEquals(TestResult.Translation, ScalarRegister(0.01f)))
		{
			UE_LOG(LogTransform, Log, TEXT("Matrix(T)\t%s"), *TestResult.GetTranslation().ToString());
			UE_LOG(LogTransform, Log, TEXT("VQS(T)\t%s"), *GetTranslation().ToString());
		}
		return false;
	}

	return true;
}
Esempio n. 16
0
File: Wall.cpp Progetto: 7kia/CG
void CWall::Advance(float dt)
{
	(void)dt;
	m_visual.SetPosition(GetPosition());
	m_visual.SetRotation(GetRotation());

}
Esempio n. 17
0
void wxTransformMatrix::SetRotation(double rotation)
{
    double x=GetValue(2,0);
    double y=GetValue(2,1);
    Rotate(-GetRotation(), x, y);
    Rotate(rotation, x, y);
}
	//! called during the update of the entity	
	void LaserSwiper::Update()
	{
		super::Update();

		if(m_HitPoints < 0)
		{
			return;
		}

		LaserSwiperSettings* pSettings = static_cast<LaserSwiperSettings*>(m_Settings.Get());

		// aim
		Player* pPlayer = Player::Instance();
		Vector3 vPosition = GetTransformationMatrix().GetTranslation();			
		Vector3 vPlayerMeshPos = pPlayer->GetMeshEntity()->GetTransformationMatrix().GetTranslation();
		Vector3 vToPlayer = (vPlayerMeshPos-vPosition).Normalize();			
		f32 fDestAngle = Math::ATan2(vToPlayer.X, -vToPlayer.Y)*Math::RadToDegFactor;
		f32 fRotation = Math::Damp(GetRotation().Z, 180.0f-fDestAngle, g_fDeltaTime, pSettings->m_fAimDuration);
		m_fCurrentAngle = Math::Damp(m_fCurrentAngle, fDestAngle, g_fDeltaTime, pSettings->m_fAimDuration);
		SetRotation(Vector3::Create(0.0f, 0.0f, fRotation));

		f32 fDistSquared = (vPosition-vPlayerMeshPos).GetLengthSquared();
		if(fDistSquared < m_fLaserLengthSquared)
		{
			// swipe
			Vector3 vPosition = GetTransformationMatrix().GetTranslation();
			Vector3 vOffset = Vector3::Create(0.0f, -pSettings->m_fLaserOffset, 0.0f);
			Vector3 vRotatedOffset = Quaternion(Vector3::Create(0.0f, 0.0f, 1.0f), m_fCurrentAngle*Math::DegToRadFactor).Rotate(vOffset);

			if(!m_pLaser || m_pLaser->fLife < 0.0f)
			{
				// shoot
				Laser::Params params;					
				params.vStart = vPosition + vRotatedOffset;
				params.vDir = vRotatedOffset.Normalize();
				params.fSpeed = pSettings->m_fLaserSpeed;
				params.fMaxLength = pSettings->m_fLaserLength;
				params.fLife = 999.0f;
				params.bStatic = true;
				params.fThickness = pSettings->m_fLaserThickness;
				m_pLaser = SFXManager::Instance()->GetEnemyLaserManager()->AddLaser(params);
			}
			else
			{
				// update laser
				m_pLaser->vStart = vPosition + vRotatedOffset;
				m_pLaser->vDir = vRotatedOffset.Normalize();
			}
		}
		else
		{
			Translate(Vector3::Create(0.0f, -pSettings->m_fSpeed*g_fDeltaTime, 0.0f));

			if(m_pLaser)
			{
				m_pLaser->fLife = 0.0f;
				m_pLaser = NULL;
			}
		}
	}
Esempio n. 19
0
void CPed::GetMatrix( CMatrix& matrix )
{
    CVector vecRotation;
    vecRotation.fZ = GetRotation();
    matrix.SetRotation( vecRotation );
    matrix.vPos = GetPosition();
}
Esempio n. 20
0
int         CasteroidIGC::Export(void* data) const
{
    if (data)
    {
        DataAsteroidIGC*  dataAsteroid = (DataAsteroidIGC*)data;
        dataAsteroid->asteroidDef = m_asteroidDef;

        dataAsteroid->position = GetPosition();
        {
            const Orientation&  o = GetOrientation();
            dataAsteroid->forward = o.GetForward();
            dataAsteroid->up      = o.GetUp();
        }
        dataAsteroid->rotation = GetRotation();

        assert (GetCluster());
        dataAsteroid->clusterID = GetCluster()->GetObjectID();
        dataAsteroid->signature = GetSignature();

        dataAsteroid->fraction = m_fraction;
        
        const char* pszName = GetName();
        if (*pszName == '\0')
            memcpy(dataAsteroid->name, GetName(), sizeof(dataAsteroid->name));
        else
            UTL::putName(dataAsteroid->name, GetName());
    }

    return sizeof(DataAsteroidIGC);
}
Esempio n. 21
0
void World::InteractBetweenPlayerAndEnemy(Entity &subject, float time, bool &isBreak) {
	float distance = GetDistance(subject.getRect(), player->getRect());
	if (IntersectsRects(subject.getRect(), player->getRect())) {
		EnemyDamagedPlayer(kickHit, subject, *player, time);
	}
	else {
		subject.isMove = true;
	}
	if (distance <= ENEMY_VIEW_RANGE) {
		if (subject.name == HARD_ENEMY) {
			ActHardEnemy(*player, subject, distance, kickHit, time);
		}
		else if (subject.name == MEDIUM_ENEMY) {
			FightRotateMediumEnemy(subject.sprite, GetRotation({ player->rect.left, player->rect.top }, { subject.rect.left, subject.rect.top }));
			if (playerWeapon->shootEnemyTimer > DEFAULT_ENEMY_SHOOT_SPEED / GET_HALF) {
				EnemyShootAtPlayer(lvl, subject, *player, entities, *playerWeapon, bulletImage);
				isBreak = true;
			}
		}
		else if (subject.name == EASY_ENEMY && IntersectsRects(subject.getEnemyView(), player->getRect())) {
			subject.sprite.setColor(Color::Red);
		}
		else {
			subject.sprite.setColor(Color::White);
			subject.isFight = false;
		}
	}
	else {
		subject.sprite.setRotation(0);
		subject.isFight = false;
	}
}
Esempio n. 22
0
void CVehicleEntity::UpdateTargetRotation()
{
	// Do we have a target rotation?
    if(HasTargetRotation())
    {
        // Get our current rotation
        CVector3 vecCurrentRotation;
        GetRotation(vecCurrentRotation);

        // Get the factor of time spent from the interpolation start
        // to the current time.
        unsigned long ulCurrentTime = SharedUtility::GetTime();
        float fAlpha = Math::Unlerp(m_interp.rot.ulStartTime, ulCurrentTime, m_interp.rot.ulFinishTime);

        // Don't let it to overcompensate the error
        fAlpha = Math::Clamp(0.0f, fAlpha, 1.0f);

        // Get the current error portion to compensate
        float fCurrentAlpha = (fAlpha - m_interp.rot.fLastAlpha);
        m_interp.rot.fLastAlpha = fAlpha;

        // Compensate the error
        CVector3 vecCompensation = Math::Lerp(CVector3(), fCurrentAlpha, m_interp.rot.vecError);

        // If we finished compensating the error, finish it for the next pulse
        if(fAlpha == 1.0f)
            m_interp.rot.ulFinishTime = 0;

        // Set the new rotation
        SetRotation((vecCurrentRotation + vecCompensation), false);
    }
}
bool
HwcComposer2D::TryRender(Layer* aRoot,
                         const gfxMatrix& aGLWorldTransform)
{
    MOZ_ASSERT(Initialized());
    if (mList) {
        mList->numHwLayers = 0;
    }
    // XXX use GL world transform instead of GetRotation()
    int rotation = GetRotation();

    int fbHeight, fbWidth;

    if (rotation == 0 || rotation == HWC_TRANSFORM_ROT_180) {
        fbWidth = mScreenWidth;
        fbHeight = mScreenHeight;
    } else {
        fbWidth = mScreenHeight;
        fbHeight = mScreenWidth;
    }

    if (!PrepareLayerList(aRoot, nsIntRect(0, 0, fbWidth, fbHeight))) {
        LOGD("Render aborted. Nothing was drawn to the screen");
        return false;
    }

    if (mHwc->set(mHwc, mDpy, mSur, mList)) {
        LOGE("Hardware device failed to render");
        return false;
    }

    LOGD("Frame rendered");
    return true;
}
Esempio n. 24
0
// creates a proper rectangle which can be drawn to the screen
sf::Shape WorldShape::CreateRectangle() {
  sf::Shape s = sf::Shape::Rectangle(0, 0, w * WorldConfig::scale, h * WorldConfig::scale,
                                     color, 1.0f, sf::Color::Black);
  s.SetCenter(w * WorldConfig::scale / 2, h * WorldConfig::scale / 2);
  s.SetRotation(GetRotation());
  s.SetPosition(GetPosition());
  return s;
}
Esempio n. 25
0
bool Spell::Render(float dt) {
	UpdatePos(dt);
	animation->RenderEx(xPos, yPos, GetRotation());
	animation->Update(dt);
	if (distance > range)
		return true;
	return false;
}
Esempio n. 26
0
 void SegmentShape2D::UpdateParameters()
 {
     revision = GetSpatialRevision();
     rotatedDirection = direction;
     rotatedDirection.Rotate(GetRotation());
     startPoint = GetPosition() + (rotatedDirection * GetBackLength()  * GetScale());
     endPoint   = GetPosition() + (rotatedDirection * GetFrontLength() * GetScale());
 }
Esempio n. 27
0
void CObject::Rotate(const CVector3& vecRotation, unsigned int uiTime)
{
	GetRotation(m_interp.rot.vecStart);
	m_interp.rot.vecTarget = vecRotation;
	unsigned int ulCurrentTime = SharedUtility::GetTime();
	m_interp.rot.ulStartTime = ulCurrentTime;
	m_interp.rot.ulFinishTime = (ulCurrentTime + uiTime);
}
Esempio n. 28
0
File: Wall.cpp Progetto: 7kia/CG
void CWall::SetVisual()
{
	m_visual.SetWidth(m_width);
	m_visual.SetHeight(m_height);
	m_visual.SetRotation(GetRotation());
	m_visual.SetOrigin(GetOrigin());
	m_visual.SetReferenceSystemOrigin(GetReferenceSystemOrigin());
	m_visual.SetPosition(GetPosition());
}
Esempio n. 29
0
void Object::FillFullPacket( const PacketPtr& packet ) {
	(*packet) << static_cast<sf::Uint16>( ServerToClient::SERVER_OBJECT ) << GetId() << static_cast<sf::Uint16>( ServerToClientObject::OBJECT_STATE )
	          << GetType() << GetName()
	          << GetResourceId()
	          << GetSize().x << GetSize().y
	          << GetPosition().x << GetPosition().y
	          << GetVelocity().x << GetVelocity().y
	          << GetRotation() << GetRotationalVelocity();
}
Esempio n. 30
0
void Entity::SetScale(Vector3 a_vScale)
{
	float fRotation = GetRotation();
	Vector3 vPosition = GetPosition();

	m_oLocalTransform = Matrix3x3::setupTranslation(vPosition)
		* Matrix3x3::setupRotation(fRotation)
		* Matrix3x3::setupScale(a_vScale);
}