コード例 #1
0
void Player::CalculatePlayerCubeCollision(OBB p_collidingBoxes)
{
	float speedXDeltaTime = m_speed * (float)GLOBAL::GetInstance().GetDeltaTime();
	Sphere playerSphere = Sphere(m_position, m_playerSphere.m_radius - 0.1f);
	playerSphere.m_position.x = m_position.x;
	playerSphere.m_position.z = m_position.z - 1.0f * speedXDeltaTime;
	bool aboveBox = CollisionManager::GetInstance()->CheckCollisionWithAllStaticObjects(playerSphere);
	playerSphere.m_position.x = m_position.x;
	playerSphere.m_position.z = m_position.z + 1.0f * speedXDeltaTime;
	bool belowBox = CollisionManager::GetInstance()->CheckCollisionWithAllStaticObjects(playerSphere);
	playerSphere.m_position.x = m_position.x + 1.0f * speedXDeltaTime;
	playerSphere.m_position.z = m_position.z;
	bool leftOfBox = CollisionManager::GetInstance()->CheckCollisionWithAllStaticObjects(playerSphere);
	playerSphere.m_position.x = m_position.x - 1.0f * speedXDeltaTime;
	playerSphere.m_position.z = m_position.z;
	bool rightOfBox = CollisionManager::GetInstance()->CheckCollisionWithAllStaticObjects(playerSphere);

	float x = m_direction.x;
	float z = m_direction.z;
	float dt = (float)GLOBAL::GetInstance().GetDeltaTime();
	if (x < 0 && z < 0)//down left
	{
		if (rightOfBox && aboveBox)
		{
			SetPosition(DirectX::XMFLOAT3(m_position.x - x * dt, m_position.y, m_position.z - z * dt));
			//SetPosition(DirectX::XMFLOAT3(m_position.x, m_position.y, p_collidingBoxes.m_center.z + p_collidingBoxes.m_extents.z + m_playerSphere.m_radius*1.1f));
			x = -1;
			z = 0;
		}
		else
		{
			if (rightOfBox)
			{
				x = 0;
				z = -1;
			}
			if (aboveBox)
			{
				x = -1;
				z = 0;
			}
		}
	}
	else if (x > 0 && z < 0)//down right
	{
		if (leftOfBox && aboveBox)
		{
			SetPosition(DirectX::XMFLOAT3(m_position.x - x * dt, m_position.y, m_position.z - z * dt));
			//SetPosition(DirectX::XMFLOAT3(p_collidingBoxes.m_center.x - p_collidingBoxes.m_extents.x - m_playerSphere.m_radius*1.1f, m_position.y, m_position.z));
			x = 0;
			z = -1;
		}
		else
		{
			if (leftOfBox)
			{
				x = 0;
				z = -1;
			}
			if (aboveBox)
			{
				x = 1;
				z = 0;
			}
		}
	}
	else if (x < 0 && z > 0)//up left // works goood
	{
		if (rightOfBox && belowBox)
		{
			SetPosition(DirectX::XMFLOAT3(m_position.x - x * dt, m_position.y, m_position.z - z * dt));
			//SetPosition(DirectX::XMFLOAT3(p_collidingBoxes.m_center.x + p_collidingBoxes.m_extents.x + m_playerSphere.m_radius*1.1f, m_position.y, m_position.z));
			x = 0;
			z = 1;
		}
		else
		{
			if (rightOfBox)
			{
				x = 0;
				z = 1;
			}
			if (belowBox)
			{
				x = -1;
				z = 0;
			}
		}
	}
	else if (x > 0 && z > 0)//up right // works goood
	{
		if (leftOfBox && belowBox)
		{
			SetPosition(DirectX::XMFLOAT3(m_position.x - x * dt, m_position.y, m_position.z - z * dt));
			//SetPosition(DirectX::XMFLOAT3(m_position.x, m_position.y, p_collidingBoxes.m_center.z - p_collidingBoxes.m_extents.z - m_playerSphere.m_radius*1.1f));
			x = 1;
			z = 0;
		}
		else
		{
			if (leftOfBox)
			{
				x = 0;
				z = 1;
			}
			if (belowBox)
			{
				x = 1;
				z = 0;
			}
		}
	}
	SetDirection(DirectX::XMFLOAT3(x, 0.0f, z));
}
コード例 #2
0
void Skybox::Render(ID3D11DeviceContext *context, XMMATRIX viewMatrix, XMMATRIX projectionMatrix, Light *light, XMFLOAT3 cameraPos)
{
	SetPosition(cameraPos);
	GameObject::Render(context, viewMatrix, projectionMatrix, m_skyBoxAmbientLight, cameraPos);
}
コード例 #3
0
ファイル: CTriangle.cpp プロジェクト: cugone/Abrams2010
void Triangle::SetY(double y) {
    SetPosition(GetX(), y);
}
コード例 #4
0
ファイル: Music.cpp プロジェクト: freemaul/SFML
////////////////////////////////////////////////////////////
/// Set the position of a music
////////////////////////////////////////////////////////////
void sfMusic_SetPosition(sfMusic* Music, float X, float Y, float Z)
{
    CSFML_CALL(Music, SetPosition(sf::Vector3f(X, Y, Z)));
}
コード例 #5
0
ファイル: mythuieditbar.cpp プロジェクト: DocOnDev/mythtv
void MythUIEditBar::SetPosition(long long position)
{
    SetPosition((double)position);
}
コード例 #6
0
int GetSearchReplaceString(
	bool IsReplaceMode,
	const wchar_t *Title,
	const wchar_t *SubTitle,
	string& SearchStr,
	string& ReplaceStr,
	const wchar_t *TextHistoryName,
	const wchar_t *ReplaceHistoryName,
	bool* pCase,
	bool* pWholeWords,
	bool* pReverse,
	bool* pRegexp,
	bool* pPreserveStyle,
	const wchar_t *HelpTopic,
	bool HideAll,
	const GUID* Id)
{
	int Result = 0;

	if (!TextHistoryName)
		TextHistoryName = L"SearchText";

	if (!ReplaceHistoryName)
		ReplaceHistoryName = L"ReplaceText";

	if (!Title)
		Title=MSG(IsReplaceMode?MEditReplaceTitle:MEditSearchTitle);

	if (!SubTitle)
		SubTitle=MSG(MEditSearchFor);


	bool Case=pCase?*pCase:false;
	bool WholeWords=pWholeWords?*pWholeWords:false;
	bool Reverse=pReverse?*pReverse:false;
	bool Regexp=pRegexp?*pRegexp:false;
	bool PreserveStyle=pPreserveStyle?*pPreserveStyle:false;

	#if 1
	//Maximus: поддержка "узких" дисплеев
	int BorderW = (72<(ScrX-1))?72:(ScrX-1);
	int ElemW = BorderW - 2; // 70
	int ElemX2 = (BorderW + 4) / 2; // 40
	#endif

	if (IsReplaceMode)
	{
		/*
		  0         1         2         3         4         5         6         7
		  0123456789012345678901234567890123456789012345678901234567890123456789012345
		00
		01   +----------------------------- Replace ------------------------------+
		02   | Search for                                                         |
		03   |                                                                   |
		04   | Replace with                                                       |
		05   |                                                                   |
		06   +--------------------------------------------------------------------+
		07   | [ ] Case sensitive                 [ ] Regular expressions         |
		08   | [ ] Whole words                    [ ] Preserve style              |
		09   | [ ] Reverse search                                                 |
		10   +--------------------------------------------------------------------+
		11   |                      [ Replace ]  [ Cancel ]                       |
		12   +--------------------------------------------------------------------+
		13
		*/
		FarDialogItem ReplaceDlgData[]=
		{
			#if 1
			//Maximus: поддержка "узких" дисплеев
			{DI_DOUBLEBOX,3,1,BorderW,12,0,nullptr,nullptr,0,Title},
			#else
			{DI_DOUBLEBOX,3,1,72,12,0,nullptr,nullptr,0,Title},
			#endif
			{DI_TEXT,5,2,0,2,0,nullptr,nullptr,0,SubTitle},
			#if 1
			//Maximus: поддержка "узких" дисплеев
			{DI_EDIT,5,3,ElemW,3,0,TextHistoryName,nullptr,DIF_FOCUS|DIF_USELASTHISTORY|(*TextHistoryName?DIF_HISTORY:0),SearchStr.data()},
			#else
			{DI_EDIT,5,3,70,3,0,TextHistoryName,nullptr,DIF_FOCUS|DIF_USELASTHISTORY|(*TextHistoryName?DIF_HISTORY:0),SearchStr.data()},
			#endif
			{DI_TEXT,5,4,0,4,0,nullptr,nullptr,0,MSG(MEditReplaceWith)},
			#if 1
			//Maximus: поддержка "узких" дисплеев
			{DI_EDIT,5,5,ElemW,5,0,ReplaceHistoryName,nullptr,(*ReplaceHistoryName?DIF_HISTORY:0)/*|DIF_USELASTHISTORY*/,ReplaceStr.data()},
			#else
			{DI_EDIT,5,5,70,5,0,ReplaceHistoryName,nullptr,(*ReplaceHistoryName?DIF_HISTORY:0)/*|DIF_USELASTHISTORY*/,ReplaceStr.data()},
			#endif
			{DI_TEXT,-1,6,0,6,0,nullptr,nullptr,DIF_SEPARATOR,L""},
			{DI_CHECKBOX,5,7,0,7,Case,nullptr,nullptr,0,MSG(MEditSearchCase)},
			{DI_CHECKBOX,5,8,0,8,WholeWords,nullptr,nullptr,0,MSG(MEditSearchWholeWords)},
			{DI_CHECKBOX,5,9,0,9,Reverse,nullptr,nullptr,0,MSG(MEditSearchReverse)},
			#if 1
			//Maximus: поддержка "узких" дисплеев
			{DI_CHECKBOX,ElemX2,7,0,7,Regexp,nullptr,nullptr,0,MSG(MEditSearchRegexp)},
			#else
			{DI_CHECKBOX,40,7,0,7,Regexp,nullptr,nullptr,0,MSG(MEditSearchRegexp)},
			#endif
			{DI_CHECKBOX,40,8,0,8,PreserveStyle,nullptr,nullptr,0,MSG(MEditSearchPreserveStyle)},
			{DI_TEXT,-1,10,0,10,0,nullptr,nullptr,DIF_SEPARATOR,L""},
			{DI_BUTTON,0,11,0,11,0,nullptr,nullptr,DIF_DEFAULTBUTTON|DIF_CENTERGROUP,MSG(MEditReplaceReplace)},
			{DI_BUTTON,0,11,0,11,0,nullptr,nullptr,DIF_CENTERGROUP,MSG(MEditSearchCancel)},
		};
		auto ReplaceDlg = MakeDialogItemsEx(ReplaceDlgData);

		if (!pCase)
			ReplaceDlg[6].Flags |= DIF_DISABLE; // DIF_HIDDEN ??
		if (!pWholeWords)
			ReplaceDlg[7].Flags |= DIF_DISABLE; // DIF_HIDDEN ??
		if (!pReverse)
			ReplaceDlg[8].Flags |= DIF_DISABLE; // DIF_HIDDEN ??
		if (!pRegexp)
			ReplaceDlg[9].Flags |= DIF_DISABLE; // DIF_HIDDEN ??
		if (!pPreserveStyle)
			ReplaceDlg[10].Flags |= DIF_DISABLE; // DIF_HIDDEN ??

		auto Dlg = Dialog::create(ReplaceDlg);
		#if 1
		//Maximus: поддержка "узких" дисплеев
		Dlg->SetPosition(-1,-1,BorderW+4,14);
		#else
		Dlg->SetPosition(-1,-1,76,14);
		#endif

		if (HelpTopic && *HelpTopic)
			Dlg->SetHelp(HelpTopic);

		if(Id) Dlg->SetId(*Id);

		Dlg->Process();

		if(Dlg->GetExitCode() == 12)
		{
			Result = 1;
			SearchStr = ReplaceDlg[2].strData;
			ReplaceStr = ReplaceDlg[4].strData;
			Case=ReplaceDlg[6].Selected == BSTATE_CHECKED;
			WholeWords=ReplaceDlg[7].Selected == BSTATE_CHECKED;
			Reverse=ReplaceDlg[8].Selected == BSTATE_CHECKED;
			Regexp=ReplaceDlg[9].Selected == BSTATE_CHECKED;
			PreserveStyle=ReplaceDlg[10].Selected == BSTATE_CHECKED;
		}
	}
	else
	{
		/*
		  0         1         2         3         4         5         6         7
		  0123456789012345678901234567890123456789012345678901234567890123456789012345
		00
		01   +------------------------------ Search ------------------------------+
		02   | Search for                                                         |
		03   |                                                                   |
		04   +--------------------------------------------------------------------+
		05   | [ ] Case sensitive                 [ ] Regular expressions         |
		06   | [ ] Whole words                    [ ] Reverse search              |
		07   +--------------------------------------------------------------------+
		08   |                   { Search } [ All ] [ Cancel ]                    |
		09   +--------------------------------------------------------------------+
		*/
		FarDialogItem SearchDlgData[]=
		{
			#if 1
			//Maximus: поддержка "узких" дисплеев
			{DI_DOUBLEBOX,3,1,BorderW,9,0,nullptr,nullptr,0,Title},
			#else
			{DI_DOUBLEBOX,3,1,72,9,0,nullptr,nullptr,0,Title},
			#endif
			{DI_TEXT,5,2,0,2,0,nullptr,nullptr,0,SubTitle},
			#if 1
			//Maximus: поддержка "узких" дисплеев
			{DI_EDIT,5,3,ElemW,3,0,TextHistoryName,nullptr,DIF_FOCUS|DIF_USELASTHISTORY|(*TextHistoryName?DIF_HISTORY:0),SearchStr.data()},
			#else
			{DI_EDIT,5,3,70,3,0,TextHistoryName,nullptr,DIF_FOCUS|DIF_USELASTHISTORY|(*TextHistoryName?DIF_HISTORY:0),SearchStr.data()},
			#endif
			{DI_TEXT,-1,4,0,4,0,nullptr,nullptr,DIF_SEPARATOR,L""},
			{DI_CHECKBOX,5,5,0,5,Case,nullptr,nullptr,0,MSG(MEditSearchCase)},
			{DI_CHECKBOX,5,6,0,6,WholeWords,nullptr,nullptr,0,MSG(MEditSearchWholeWords)},
			#if 1
			//Maximus: поддержка "узких" дисплеев
			{DI_CHECKBOX,ElemX2,5,0,5,Regexp,nullptr,nullptr,0,MSG(MEditSearchRegexp)},
			{DI_CHECKBOX,ElemX2,6,0,6,Reverse,nullptr,nullptr,0,MSG(MEditSearchReverse)},
			#else
			{DI_CHECKBOX,40,5,0,5,Regexp,nullptr,nullptr,0,MSG(MEditSearchRegexp)},
			{DI_CHECKBOX,40,6,0,6,Reverse,nullptr,nullptr,0,MSG(MEditSearchReverse)},
			#endif
			{DI_TEXT,-1,7,0,7,0,nullptr,nullptr,DIF_SEPARATOR,L""},
			{DI_BUTTON,0,8,0,8,0,nullptr,nullptr,DIF_DEFAULTBUTTON|DIF_CENTERGROUP,MSG(MEditSearchSearch)},
			{DI_BUTTON,0,8,0,8,0,nullptr,nullptr,DIF_CENTERGROUP,MSG(MEditSearchAll)},
			{DI_BUTTON,0,8,0,8,0,nullptr,nullptr,DIF_CENTERGROUP,MSG(MEditSearchCancel)},
		};
		auto SearchDlg = MakeDialogItemsEx(SearchDlgData);

		if (!pCase)
			SearchDlg[4].Flags |= DIF_DISABLE; // DIF_HIDDEN ??
		if (!pWholeWords)
			SearchDlg[5].Flags |= DIF_DISABLE; // DIF_HIDDEN ??
		if (!pRegexp)
			SearchDlg[6].Flags |= DIF_DISABLE; // DIF_HIDDEN ??
		if (!pReverse)
			SearchDlg[7].Flags |= DIF_DISABLE; // DIF_HIDDEN ??

		if (HideAll)
			SearchDlg[10].Flags |= DIF_HIDDEN;

		auto Dlg = Dialog::create(SearchDlg);
		#if 1
		//Maximus: поддержка "узких" дисплеев
		Dlg->SetPosition(-1,-1,BorderW+4,11);
		#else
		Dlg->SetPosition(-1,-1,76,11);
		#endif

		if (HelpTopic && *HelpTopic)
			Dlg->SetHelp(HelpTopic);

		if(Id) Dlg->SetId(*Id);

		Dlg->Process();
		int ExitCode = Dlg->GetExitCode();

		if (ExitCode == 9 || ExitCode == 10)
		{
			Result = ExitCode == 9? 1 : 2;
			SearchStr = SearchDlg[2].strData;
			ReplaceStr.clear();
			Case=SearchDlg[4].Selected == BSTATE_CHECKED;
			WholeWords=SearchDlg[5].Selected == BSTATE_CHECKED;
			Regexp=SearchDlg[6].Selected == BSTATE_CHECKED;
			Reverse=SearchDlg[7].Selected == BSTATE_CHECKED;
		}
	}

	if (pCase)
		*pCase=Case;
	if (pWholeWords)
		*pWholeWords=WholeWords;
	if (pReverse)
		*pReverse=Reverse;
	if (pRegexp)
		*pRegexp=Regexp;
	if (pPreserveStyle)
		*pPreserveStyle=PreserveStyle;

	return Result;
}
コード例 #7
0
ファイル: Entity.cpp プロジェクト: FX-Master/MCServer
void cEntity::TeleportToCoords(double a_PosX, double a_PosY, double a_PosZ)
{
	SetPosition(a_PosX, a_PosY, a_PosZ);
	m_World->BroadcastTeleportEntity(*this);
}
コード例 #8
0
void SFApp::FireProjectile() {
  auto pb = make_shared<SFAsset>(SFASSET_PROJECTILE, sf_window);
  auto v  = player->GetPosition();
  pb->SetPosition(v);
  projectiles.push_back(pb);
}
コード例 #9
0
void VirtualMonitorManager::Update(double frame_time) {
  switch (mStage) {
    case UpdateStage::UpdateLiveWindowsSet: {
      // this shouldn't take much time so we just do this step to completion
      mLiveHwnds.clear();
      mLiveHwnds = mScreenshotProducer->GetVisibleWindows();
      // only proceed with next stage if we have live windows
      if (mLiveHwnds.size() > 0) {
        mStage = UpdateStage::InitDeadWindowSet;
        mLiveHwndIndex = 0;
      }
      break;
    }
    case UpdateStage::InitDeadWindowSet: {
      mDeadMonitors.clear();
      // populate from existing sets
      for (auto& iter : mRootMonitors) {
        mDeadMonitors.insert(iter.first);
      }
      for (auto& iter : mChildMonitors) {
        mDeadMonitors.insert(iter.first);
      }
      mStage = UpdateStage::BlitWindows;
      break;
    }
    case UpdateStage::BlitWindows: {
      WindowID win = mLiveHwnds[mLiveHwndIndex];
      mDeadMonitors.erase(win);

      ScreenshotPtr screenshot = mScreenshotProducer->Get(win);
      if (screenshot) {
        bool is_root = IsAltTabWindow(win);
        if (is_root) {
          // make sure it exists
          if (mRootMonitors.find(win) == mRootMonitors.end()) {
            mRootMonitors[win] = std::make_shared<VirtualMonitor>(mScene, win);
          }
          auto monitor = mRootMonitors[win];

          monitor->Blit(screenshot);
        }
      }

      mLiveHwndIndex++;
      if (mLiveHwndIndex >= mLiveHwnds.size()) {
        mStage = UpdateStage::RemoveDeadWindows;
      }
      break;
    }
    case UpdateStage::RemoveDeadWindows: {
      for (WindowID win : mDeadMonitors) {
        mRootMonitors.erase(win);
        mChildMonitors.erase(win);
      }
      mStage = UpdateStage::UpdateWindowSRT;
      break;
    }
    case UpdateStage::UpdateWindowSRT: {
      float num_root_monitors = static_cast<float>(mRootMonitors.size());
      const float r = 0.5f;

      int i = 0;
      for (auto iter : mRootMonitors) {
        auto monitor = iter.second;

        monitor->UpdateScale();

        float deg = 360.0f * (i / num_root_monitors);
        float rad = deg * 3.14159f / 180.0f;
        float x = r * cos(rad);
        float y = r * sin(rad);
        monitor->SetPosition(x, 0, -y);

        monitor->FocusAtUser();

        ++i;
      }
      mStage = UpdateStage::UpdateLiveWindowsSet;
      break;
    }
  }

}
コード例 #10
0
ファイル: RigidBody.cpp プロジェクト: PeteX/Urho3D
void RigidBody::HandleTargetPosition(StringHash eventType, VariantMap& eventData)
{
    // Copy the smoothing target position to the rigid body
    if (!physicsWorld_ || !physicsWorld_->IsApplyingTransforms())
        SetPosition(static_cast<SmoothedTransform*>(GetEventSender())->GetTargetWorldPosition());
}
コード例 #11
0
ファイル: RigidBody.cpp プロジェクト: PeteX/Urho3D
void RigidBody::UpdateMass()
{
    if (!body_)
        return;
    
    btTransform principal;
    principal.setRotation(btQuaternion::getIdentity());
    principal.setOrigin(btVector3(0.0f, 0.0f, 0.0f));
    
    // Calculate center of mass shift from all the collision shapes
    unsigned numShapes = compoundShape_->getNumChildShapes();
    if (numShapes)
    {
        PODVector<float> masses(numShapes);
        for (unsigned i = 0; i < numShapes; ++i)
        {
            // The actual mass does not matter, divide evenly between child shapes
            masses[i] = 1.0f;
        }
        
        btVector3 inertia(0.0f, 0.0f, 0.0f);
        compoundShape_->calculatePrincipalAxisTransform(&masses[0], principal, inertia);
    }
    
    // Add child shapes to shifted compound shape with adjusted offset
    while (shiftedCompoundShape_->getNumChildShapes())
        shiftedCompoundShape_->removeChildShapeByIndex(shiftedCompoundShape_->getNumChildShapes() - 1);
    for (unsigned i = 0; i < numShapes; ++i)
    {
        btTransform adjusted = compoundShape_->getChildTransform(i);
        adjusted.setOrigin(adjusted.getOrigin() - principal.getOrigin());
        shiftedCompoundShape_->addChildShape(adjusted, compoundShape_->getChildShape(i));
    }
    
    // If shifted compound shape has only one child with no offset/rotation, use the child shape
    // directly as the rigid body collision shape for better collision detection performance
    bool useCompound = !numShapes || numShapes > 1;
    if (!useCompound)
    {
        const btTransform& childTransform = shiftedCompoundShape_->getChildTransform(0);
        if (!ToVector3(childTransform.getOrigin()).Equals(Vector3::ZERO) ||
            !ToQuaternion(childTransform.getRotation()).Equals(Quaternion::IDENTITY))
            useCompound = true;
    }
    body_->setCollisionShape(useCompound ? shiftedCompoundShape_ : shiftedCompoundShape_->getChildShape(0));
    
    // If we have one shape and this is a triangle mesh, we use a custom material callback in order to adjust internal edges
    if (!useCompound && body_->getCollisionShape()->getShapeType() == SCALED_TRIANGLE_MESH_SHAPE_PROXYTYPE &&
        physicsWorld_->GetInternalEdge())
        body_->setCollisionFlags(body_->getCollisionFlags() | btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
    else
        body_->setCollisionFlags(body_->getCollisionFlags() & ~btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);

    // Reapply rigid body position with new center of mass shift
    Vector3 oldPosition = GetPosition();
    centerOfMass_ = ToVector3(principal.getOrigin());
    SetPosition(oldPosition);
    
    // Calculate final inertia
    btVector3 localInertia(0.0f, 0.0f, 0.0f);
    if (mass_ > 0.0f)
        shiftedCompoundShape_->calculateLocalInertia(mass_, localInertia);
    body_->setMassProps(mass_, localInertia);
    body_->updateInertiaTensor();
    
    // Reapply constraint positions for new center of mass shift
    if (node_)
    {
        for (PODVector<Constraint*>::Iterator i = constraints_.Begin(); i != constraints_.End(); ++i)
            (*i)->ApplyFrames();
    }
}
コード例 #12
0
void FieldCharacter::SetPositionByAnchorPosition(Vector2 targetPosition)
{
    SetPosition(GetPosition() + (targetPosition - GetVectorAnchorPosition()));
}
コード例 #13
0
void    plOGGCodec::IOpen( const char *path, plAudioCore::ChannelSelect whichChan )
{
    hsAssert( path != nil, "Invalid path specified in plOGGCodec reader" );

    // plNetClientApp::StaticDebugMsg("Ogg Open %s, t=%f, start", path, hsTimer::GetSeconds());

    strncpy( fFilename, path, sizeof( fFilename ) );
    fWhichChannel = whichChan;

    /// Open the file as a plain binary stream
    fFileHandle = fopen( path, "rb" );
    if( fFileHandle != nil )
    {
        /// Create the OGG data struct
        fOggFile = new OggVorbis_File;

        /// Open the OGG decompressor
        if( ov_open( fFileHandle, fOggFile, NULL, 0 ) < 0 )
        {
            IError( "Unable to open OGG source file" );
            return;
        }

        /// Construct some header info from the ogg info
        vorbis_info *vInfo = ov_info( fOggFile, -1 );

        fHeader.fFormatTag = 1;
        fHeader.fNumChannels = vInfo->channels;
        fHeader.fNumSamplesPerSec = vInfo->rate;
    
        // Funny thing about the bits per sample: we get to CHOOSE. Go figure! 
        fHeader.fBitsPerSample = ( fDecodeFormat == k8bitUnsigned ) ? 8 : 16;

        // Why WAV files hold this info when it can be calculated is beyond me...
        fHeader.fBlockAlign = ( fHeader.fBitsPerSample * fHeader.fNumChannels ) >> 3;
        fHeader.fAvgBytesPerSec = fHeader.fNumSamplesPerSec * fHeader.fBlockAlign;

        
        /// The size in bytes of our PCM data stream
        /// Note: OGG sometimes seems to be off by 1 sample, which causes our reads to suck
        /// because we end up waiting for 1 more sample than we actually have. So, on the
        /// assumption that OGG is just slightly wrong sometimes, we just subtract 1 sample
        /// from what it tells us. As Brice put it, who's going to miss 1/40,000'ths of a second?
        fDataSize = (uint32_t)(( ov_pcm_total( fOggFile, -1 ) - 1 ) * fHeader.fBlockAlign);

        /// Channel select
        if( fWhichChannel != plAudioCore::kAll )
        {
            fChannelAdjust = 2;
            fChannelOffset = ( fWhichChannel == plAudioCore::kLeft ) ? 0 : 1;
        }
        else
        {
            fChannelAdjust = 1;
            fChannelOffset = 0;
        }
        

        /// Construct our fake header for channel adjustment
        fFakeHeader = fHeader;
        fFakeHeader.fAvgBytesPerSec /= fChannelAdjust;
        fFakeHeader.fNumChannels /= (uint16_t)fChannelAdjust;
        fFakeHeader.fBlockAlign /= (uint16_t)fChannelAdjust;

        SetPosition( 0 );
    }
コード例 #14
0
ファイル: dircalc.cpp プロジェクト: 0-wiz-0/WCMCommander
	DirCalcThreadWin( NCDialogParent* parent, const char* name, OperDirCalcData* pD, const unicode_t* dirName )
		:  NCDialog( ::createDialogAsChild, 0, parent, utf8_to_unicode( name ).data(), bListOk ),
		   pData( pD ),
		   lo( 12, 10 ),
		   cPathWin( this ),
		   curFileCount( -1 ),
		   curFolderCount( -1 ),
		   curSumSize( -1 ),
		   curBadDirs( -1 ),
		   dirString( 0, this, ScanedDirString( dirName ).data() ),
		   fileCountName( uiVariable, this, utf8_to_unicode( _LT( "Files:" ) ).data() ),
		   fileCountNum( uiValue, this, utf8_to_unicode( "AAAAAAAAAA" ).data() ),
		   folderCountName( uiVariable, this, utf8_to_unicode( _LT( "Folders:" ) ).data() ),
		   folderCountNum( uiValue, this, utf8_to_unicode( "AAAAAAAAAA" ).data() ),
		   sumSizeName( uiVariable, this, utf8_to_unicode( _LT( "Files size:" ) ).data() ),
		   sumSizeNum( uiValue, this, utf8_to_unicode( "AAAAAAAAAAAAAAAAAAAA" ).data() ),
		   badDirsName( uiVariable, this, utf8_to_unicode( _LT( "Not readable folders:" ) ).data() ),
		   badDirsNum( uiValue, this, utf8_to_unicode( "AAAAAAAAAA" ).data() )
	{
		lo.AddWin( &dirString, 0, 0, 0, 3 );
		lo.AddWin( &cPathWin, 9, 0, 9, 3 );
		lo.LineSet( 1, 10 );
		lo.AddWin( &fileCountName, 3, 1 );
		lo.AddWin( &folderCountName, 4, 1 );
		lo.AddWin( &sumSizeName, 5, 1 );
		lo.AddWin( &fileCountNum, 3, 2 );
		lo.AddWin( &folderCountNum, 4, 2 );
		lo.AddWin( &sumSizeNum, 5, 2 );
		lo.LineSet( 6, 7 );
		lo.AddWin( &badDirsName, 7, 1 );
		lo.AddWin( &badDirsNum, 7, 2 );
		lo.LineSet( 8, 10 );

		dirString.Show();
		dirString.Enable();
		cPathWin.Show();
		cPathWin.Enable();
		fileCountName.Show();
		fileCountName.Enable();
		fileCountNum.Show();
		fileCountNum.Enable();

		folderCountName.Show();
		folderCountName.Enable();
		folderCountNum.Show();
		folderCountNum.Enable();

		sumSizeName.Show();
		sumSizeName.Enable();
		sumSizeNum.Show();
		sumSizeNum.Enable();
		badDirsName.Show();
		badDirsName.Enable();
		badDirsNum.Show();
		badDirsNum.Enable();

		lo.SetColGrowth( 3 );
		lo.SetColGrowth( 0 );

		this->AddLayout( &lo );
		this->SetEnterCmd( CMD_OK );
		SetPosition();

		RefreshCounters();
	}
コード例 #15
0
ファイル: Control.cpp プロジェクト: hnefatl/Pong
void Control::SetPosition(const SDL_Point &NewPosition)
{
	return SetPosition(NewPosition.x, NewPosition.y);
}
コード例 #16
0
bool wxBitmapButton::Create(wxWindow *parent, wxWindowID id,
    const wxBitmap& bitmap,
    const wxPoint& pos,
    const wxSize& size, long style,
    const wxValidator& wxVALIDATOR_PARAM(validator),
    const wxString& name)
{
    m_bmpNormal = bitmap;
    SetName(name);

#if wxUSE_VALIDATORS
    SetValidator(validator);
#endif // wxUSE_VALIDATORS

    parent->AddChild(this);

    m_backgroundColour = parent->GetBackgroundColour();
    m_foregroundColour = parent->GetForegroundColour();
    m_windowStyle = style;

    if ( style & wxBU_AUTODRAW )
    {
        m_marginX = wxDEFAULT_BUTTON_MARGIN;
        m_marginY = wxDEFAULT_BUTTON_MARGIN;
    }

    if (id == wxID_ANY)
        m_windowId = NewControlId();
    else
        m_windowId = id;

    long msStyle = WS_VISIBLE | WS_TABSTOP | WS_CHILD | BS_OWNERDRAW ;

    if ( m_windowStyle & wxCLIP_SIBLINGS )
        msStyle |= WS_CLIPSIBLINGS;

#ifdef __WIN32__
    if(m_windowStyle & wxBU_LEFT)
        msStyle |= BS_LEFT;
    if(m_windowStyle & wxBU_RIGHT)
        msStyle |= BS_RIGHT;
    if(m_windowStyle & wxBU_TOP)
        msStyle |= BS_TOP;
    if(m_windowStyle & wxBU_BOTTOM)
        msStyle |= BS_BOTTOM;
#endif

    m_hWnd = (WXHWND) CreateWindowEx(
                    0,
                    wxT("BUTTON"),
                    wxEmptyString,
                    msStyle,
                    0, 0, 0, 0,
                    GetWinHwnd(parent),
                    (HMENU)m_windowId,
                    wxGetInstance(),
                    NULL
                   );

    // Subclass again for purposes of dialog editing mode
    SubclassWin(m_hWnd);

    SetPosition(pos);
    SetBestSize(size);

    return true;
}
コード例 #17
0
int GetString(
	const wchar_t *Title,
	const wchar_t *Prompt,
	const wchar_t *HistoryName,
	const wchar_t *SrcText,
	string &strDestText,
	const wchar_t *HelpTopic,
	DWORD Flags,
	int *CheckBoxValue,
	const wchar_t *CheckBoxText,
	Plugin* PluginNumber,
	const GUID* Id
)
{
	int Substract=5; // дополнительная величина :-)
	int ExitCode;
	bool addCheckBox=Flags&FIB_CHECKBOX && CheckBoxValue && CheckBoxText;
	int offset=addCheckBox?2:0;
	FarDialogItem StrDlgData[]=
	{
		{DI_DOUBLEBOX, 3, 1, 72, 4, 0, nullptr, nullptr, 0,                                L""},
		{DI_TEXT,      5, 2,  0, 2, 0, nullptr, nullptr, DIF_SHOWAMPERSAND,                L""},
		{DI_EDIT,      5, 3, 70, 3, 0, nullptr, nullptr, DIF_FOCUS|DIF_DEFAULTBUTTON,      L""},
		{DI_TEXT,     -1, 4,  0, 4, 0, nullptr, nullptr, DIF_SEPARATOR,                    L""},
		{DI_CHECKBOX,  5, 5,  0, 5, 0, nullptr, nullptr, 0,                                L""},
		{DI_TEXT,     -1, 6,  0, 6, 0, nullptr, nullptr, DIF_SEPARATOR,                    L""},
		{DI_BUTTON,    0, 7,  0, 7, 0, nullptr, nullptr, DIF_CENTERGROUP,                  L""},
		{DI_BUTTON,    0, 7,  0, 7, 0, nullptr, nullptr, DIF_CENTERGROUP,                  L""},
	};
	auto StrDlg = MakeDialogItemsEx(StrDlgData);

	if (addCheckBox)
	{
		Substract-=2;
		StrDlg[0].Y2+=2;
		StrDlg[4].Selected = *CheckBoxValue != 0;
		StrDlg[4].strData = CheckBoxText;
	}

	if (Flags&FIB_BUTTONS)
	{
		Substract-=3;
		StrDlg[0].Y2+=2;
		StrDlg[2].Flags&=~DIF_DEFAULTBUTTON;
		StrDlg[5+offset].Y1=StrDlg[4+offset].Y1=5+offset;
		StrDlg[4+offset].Type=StrDlg[5+offset].Type=DI_BUTTON;
		StrDlg[4+offset].Flags=StrDlg[5+offset].Flags=DIF_CENTERGROUP;
		StrDlg[4+offset].Flags|=DIF_DEFAULTBUTTON;
		StrDlg[4+offset].strData = MSG(MOk);
		StrDlg[5+offset].strData = MSG(MCancel);
	}

	if (Flags&FIB_EXPANDENV)
	{
		StrDlg[2].Flags|=DIF_EDITEXPAND;
	}

	if (Flags&FIB_EDITPATH)
	{
		StrDlg[2].Flags|=DIF_EDITPATH;
	}

	if (Flags&FIB_EDITPATHEXEC)
	{
		StrDlg[2].Flags|=DIF_EDITPATHEXEC;
	}

	if (HistoryName)
	{
		StrDlg[2].strHistory=HistoryName;
		StrDlg[2].Flags|=DIF_HISTORY|(Flags&FIB_NOUSELASTHISTORY?0:DIF_USELASTHISTORY);
	}

	if (Flags&FIB_PASSWORD)
		StrDlg[2].Type=DI_PSWEDIT;

	if (Title)
		StrDlg[0].strData = Title;

	if (Prompt)
	{
		StrDlg[1].strData = Prompt;
		TruncStrFromEnd(StrDlg[1].strData, 66);

		if (Flags&FIB_NOAMPERSAND)
			StrDlg[1].Flags&=~DIF_SHOWAMPERSAND;
	}

	if (SrcText)
		StrDlg[2].strData = SrcText;

	{
		auto Dlg = Dialog::create(make_range(StrDlg.data(), StrDlg.data() + StrDlg.size() - Substract));
		Dlg->SetPosition(-1,-1,76,offset+((Flags&FIB_BUTTONS)?8:6));
		if(Id) Dlg->SetId(*Id);

		if (HelpTopic)
			Dlg->SetHelp(HelpTopic);

		Dlg->SetPluginOwner(PluginNumber);

		Dlg->Process();

		ExitCode=Dlg->GetExitCode();

		if (ExitCode == -2 && Global->CtrlObject->Macro.IsExecuting() != MACROSTATE_NOMACRO)
			Global->CtrlObject->Macro.SendDropProcess();
	}

	if (ExitCode == 2 || ExitCode == 4 || (addCheckBox && ExitCode == 6))
	{
		if (!(Flags&FIB_ENABLEEMPTY) && StrDlg[2].strData.empty())
			return FALSE;

		strDestText = StrDlg[2].strData;

		if (addCheckBox)
			*CheckBoxValue=StrDlg[4].Selected;

		return TRUE;
	}

	return FALSE;
}
コード例 #18
0
ファイル: WITVolumeViz.cpp プロジェクト: DougHamil/WIT
//Set the vtk volume for display
void WITVolumeViz::SetVolume(DTIScalarVolume *vol, float left, float right)
{
    //Volume is being set for the first time so display the border

    const DTIScalarVolume* oldVol = _vol;
    _vol = vol;

    // use the brightness and contrast by using the left and right variables
    _lutBW->SetTableRange (left, right);
    double window = right - left;
    double level = left + window/2.0;
    // adjust the range
    _lutBW->SetWindow(window);
    // adjust the midpoint
    _lutBW->SetLevel(level);
    _lutBW->Modified();

    this->updateActors();


    uint dim[4];
    double voxSize[3];
    _vol->getDimension(dim[0], dim[1], dim[2], dim[3]);
    _vol->getVoxelSize(voxSize[0], voxSize[1], voxSize[2]);

    if (oldVol == NULL)
    {
        // Start in center of volume
        double localPos[4]= {dim[0]/2, dim[1]/2, dim[2]/2, 1};
        LocalToWorld(_vol->getTransformMatrix(), localPos, _vPos);

    }

    _img->Modified();

    if (dim[3] == 1) // more common case
    {
        // copy the background image data to a cache(_img)
        float *dataPtr = _vol->getDataPointer();
        float *destinationPtr = static_cast<float *>(_img->GetScalarPointer());
        memcpy (destinationPtr, dataPtr, dim[0]*dim[1]*dim[2]*dim[3]*sizeof(float));
    }
    else {
        for(uint k=0; k<dim[2]; k++) {
            for(uint j=0; j<dim[1]; j++) {
                for(uint i=0; i<dim[0]; i++) {
                    for (uint c = 0; c<dim[3]; c++) {
                        float f = _vol->getScalar(i,j,k,c)*255;
                        _img->SetScalarComponentFromFloat (i,j,k,c,f);
                    }
                }
            }
        }
    }

    SetPosition(_vPos);

    // check to see if this is the very first image that has been loaded.
    // if so set the camera to a default position and orientation
    if(_nActiveImage == -1)
    {
        DTISceneActorID n = DTI_ACTOR_CORONAL_TOMO;
        SetActiveImage(n);

        for(std::map<vtkRenderWindow*, ActorSet*>::iterator it = this->windowToActorSet.begin();
                it != this->windowToActorSet.end(); it++)
        {
            vtkRenderWindow *win = it->first;

            vtkRendererCollection *rends = win->GetRenderers();

            rends->InitTraversal();
            while(vtkRenderer *rend = rends->GetNextItem())
            {
                this->SetCameraToDefault(rend);
            }
        }
    }
}
コード例 #19
0
void Transporter::TransportPassengers(uint32 mapid, uint32 oldmap, float x, float y, float z)
{
	sEventMgr.RemoveEvents(this, EVENT_TRANSPORTER_NEXT_WAYPOINT);

#ifdef CLUSTERING
	WorldPacket data(ICMSG_TRANSPORTER_MAP_CHANGE, 24);
	data << GetEntry() << mapid << oldmap << x << y << z;
	sClusterInterface.SendPacket(&data);
#endif

	if(mPassengers.size() > 0)
	{
		PassengerIterator itr = mPassengers.begin();
		PassengerIterator it2;

		WorldPacket Pending(SMSG_TRANSFER_PENDING, 12);
		Pending << mapid << GetEntry() << oldmap;

		WorldPacket NewWorld;
		LocationVector v;

		for(; itr != mPassengers.end();)
		{
			it2 = itr;
			++itr;

			Player* plr = objmgr.GetPlayer(it2->first);
			if(!plr)
			{
				// remove from map
				mPassengers.erase(it2);
				continue;
			}
			if(!plr->GetSession() || !plr->IsInWorld()) 
				continue;

			v.x = x + plr->m_TransporterX;
			v.y = y + plr->m_TransporterY;
			v.z = z + plr->m_TransporterZ;
			v.o = plr->GetOrientation();

			if(mapid == 530 && !plr->GetSession()->HasFlag(ACCOUNT_FLAG_XPACK_01))
			{
				// player is not flagged to access bc content, repop at graveyard
				plr->RepopAtGraveyard(plr->GetPositionX(), plr->GetPositionY(), plr->GetPositionZ(), plr->GetMapId());
				continue;
			}

			if(mapid == 571 && !plr->GetSession()->HasFlag(ACCOUNT_FLAG_XPACK_02))
			{
				plr->RepopAtGraveyard(plr->GetPositionX(), plr->GetPositionY(), plr->GetPositionZ(), plr->GetMapId());
				continue;
			}

			// Lucky bitch. Do it like on official.
			if(plr->isDead())
			{
				/*plr->ResurrectPlayer(NULL);
				plr->SetUInt32Value(UNIT_FIELD_HEALTH, plr->GetUInt32Value(UNIT_FIELD_MAXHEALTH));
				plr->SetUInt32Value(UNIT_FIELD_POWER1, plr->GetUInt32Value(UNIT_FIELD_MAXPOWER1));*/
				plr->RemoteRevive();
			}

			if( plr->m_CurrentVehicle )
				plr->m_CurrentVehicle->RemovePassenger( plr );

			plr->m_lockTransportVariables = true;
			plr->GetSession()->SendPacket(&Pending);

		}
	}

	// Set our position
	RemoveFromWorld(false);
	SetPosition(x,y,z,m_position.o,false);
#ifndef CLUSTERING
	SetMapId(mapid);
	AddToWorld();
#endif
}
コード例 #20
0
void MODULE::Move( const wxPoint& aMoveVector )
{
    wxPoint newpos = m_Pos + aMoveVector;
    SetPosition( newpos );
}
コード例 #21
0
ファイル: Entity.cpp プロジェクト: FX-Master/MCServer
void cEntity::HandlePhysics(float a_Dt, cChunk & a_Chunk)
{
	int BlockX = POSX_TOINT;
	int BlockY = POSY_TOINT;
	int BlockZ = POSZ_TOINT;

	// Position changed -> super::HandlePhysics() called
	GET_AND_VERIFY_CURRENT_CHUNK(NextChunk, BlockX, BlockZ)

	// TODO Add collision detection with entities.
	a_Dt /= 1000;  // Convert from msec to sec
	Vector3d NextPos = Vector3d(GetPosX(), GetPosY(), GetPosZ());
	Vector3d NextSpeed = Vector3d(GetSpeedX(), GetSpeedY(), GetSpeedZ());
	
	if ((BlockY >= cChunkDef::Height) || (BlockY < 0))
	{
		// Outside of the world		
		AddSpeedY(m_Gravity * a_Dt);
		AddPosition(GetSpeed() * a_Dt);
		return;
	}
	
	int RelBlockX = BlockX - (NextChunk->GetPosX() * cChunkDef::Width);
	int RelBlockZ = BlockZ - (NextChunk->GetPosZ() * cChunkDef::Width);
	BLOCKTYPE BlockIn = NextChunk->GetBlock( RelBlockX, BlockY, RelBlockZ );
	BLOCKTYPE BlockBelow = (BlockY > 0) ? NextChunk->GetBlock(RelBlockX, BlockY - 1, RelBlockZ) : E_BLOCK_AIR;
	if (!cBlockInfo::IsSolid(BlockIn))  // Making sure we are not inside a solid block
	{
		if (m_bOnGround)  // check if it's still on the ground
		{
			if (!cBlockInfo::IsSolid(BlockBelow))  // Check if block below is air or water.
			{
				m_bOnGround = false;
			}
		}
	}
	else
	{
		// Push out entity.
		BLOCKTYPE GotBlock;

		static const struct
		{
			int x, y, z;
		} gCrossCoords[] =
		{
			{ 1, 0,  0},
			{-1, 0,  0},
			{ 0, 0,  1},
			{ 0, 0, -1},
		} ;

		bool IsNoAirSurrounding = true;
		for (size_t i = 0; i < ARRAYCOUNT(gCrossCoords); i++)
		{
			if (!NextChunk->UnboundedRelGetBlockType(RelBlockX + gCrossCoords[i].x, BlockY, RelBlockZ + gCrossCoords[i].z, GotBlock))
			{
				// The pickup is too close to an unloaded chunk, bail out of any physics handling
				return;
			}
			if (!cBlockInfo::IsSolid(GotBlock))
			{
				NextPos.x += gCrossCoords[i].x;
				NextPos.z += gCrossCoords[i].z;
				IsNoAirSurrounding = false;
				break;
			}
		}  // for i - gCrossCoords[]
			
		if (IsNoAirSurrounding)
		{
			NextPos.y += 0.5;
		}

		m_bOnGround = true;

		/*
		// DEBUG:
		LOGD("Entity #%d (%s) is inside a block at {%d, %d, %d}",
			m_UniqueID, GetClass(), BlockX, BlockY, BlockZ
		);
		*/
	}

	if (!m_bOnGround)
	{
		float fallspeed;
		if (IsBlockWater(BlockIn))
		{
			fallspeed = m_Gravity * a_Dt / 3;  // Fall 3x slower in water.
		}
		else if (BlockIn == E_BLOCK_COBWEB)
		{
			NextSpeed.y *= 0.05;  // Reduce overall falling speed
			fallspeed = 0;  // No falling.
		}
		else
		{
			// Normal gravity
			fallspeed = m_Gravity * a_Dt;
		}
		NextSpeed.y += fallspeed;
	}
	else
	{
		// Friction
		if (NextSpeed.SqrLength() > 0.0004f)
		{
			NextSpeed.x *= 0.7f / (1 + a_Dt);
			if (fabs(NextSpeed.x) < 0.05)
			{
				NextSpeed.x = 0;
			}
			NextSpeed.z *= 0.7f / (1 + a_Dt);
			if (fabs(NextSpeed.z) < 0.05)
			{
				NextSpeed.z = 0;
			}
		}
	}

	// Adjust X and Z speed for COBWEB temporary. This speed modification should be handled inside block handlers since we
	// might have different speed modifiers according to terrain.
	if (BlockIn == E_BLOCK_COBWEB)
	{
		NextSpeed.x *= 0.25;
		NextSpeed.z *= 0.25;
	}
					
	//Get water direction
	Direction WaterDir = m_World->GetWaterSimulator()->GetFlowingDirection(BlockX, BlockY, BlockZ);

	m_WaterSpeed *= 0.9f;		//Reduce speed each tick

	switch(WaterDir)
	{
		case X_PLUS:
			m_WaterSpeed.x = 0.2f;
			m_bOnGround = false;
			break;
		case X_MINUS:
			m_WaterSpeed.x = -0.2f;
			m_bOnGround = false;
			break;
		case Z_PLUS:
			m_WaterSpeed.z = 0.2f;
			m_bOnGround = false;
			break;
		case Z_MINUS:
			m_WaterSpeed.z = -0.2f;
			m_bOnGround = false;
			break;
			
	default:
		break;
	}

	if (fabs(m_WaterSpeed.x) < 0.05)
	{
		m_WaterSpeed.x = 0;
	}

	if (fabs(m_WaterSpeed.z) < 0.05)
	{
		m_WaterSpeed.z = 0;
	}

	NextSpeed += m_WaterSpeed;

	if (NextSpeed.SqrLength() > 0.f)
	{
		cTracer Tracer(GetWorld());
		// Distance traced is an integer, so we round up from the distance we should go (Speed * Delta), else we will encounter collision detection failurse
		int DistanceToTrace = (int)(ceil((NextSpeed * a_Dt).SqrLength()) * 2);
		bool HasHit = Tracer.Trace(NextPos, NextSpeed, DistanceToTrace);

		if (HasHit)
		{
			// Oh noez! We hit something: verify that the (hit position - current) was smaller or equal to the (position that we should travel without obstacles - current)
			// This is because previously, we traced with a length that was rounded up (due to integer limitations), and in the case that something was hit, we don't want to overshoot our projected movement
			if ((Tracer.RealHit - NextPos).SqrLength() <= (NextSpeed * a_Dt).SqrLength())
			{
				// Block hit was within our projected path
				// Begin by stopping movement in the direction that we hit something. The Normal is the line perpendicular to a 2D face and in this case, stores what block face was hit through either -1 or 1.
				// For example: HitNormal.y = -1 : BLOCK_FACE_YM; HitNormal.y = 1 : BLOCK_FACE_YP
				if (Tracer.HitNormal.x != 0.f) NextSpeed.x = 0.f;
				if (Tracer.HitNormal.y != 0.f) NextSpeed.y = 0.f;
				if (Tracer.HitNormal.z != 0.f) NextSpeed.z = 0.f;

				if (Tracer.HitNormal.y == 1) // Hit BLOCK_FACE_YP, we are on the ground
				{
					m_bOnGround = true;
				}

				// Now, set our position to the hit block (i.e. move part way along our intended trajectory)
				NextPos.Set(Tracer.RealHit.x, Tracer.RealHit.y, Tracer.RealHit.z);
				NextPos.x += Tracer.HitNormal.x * 0.1;
				NextPos.y += Tracer.HitNormal.y * 0.05;
				NextPos.z += Tracer.HitNormal.z * 0.1;
			}
			else
			{
				// We have hit a block but overshot our intended trajectory, move normally, safe in the warm cocoon of knowledge that we won't appear to teleport forwards on clients,
				// and that this piece of software will come to be hailed as the epitome of performance and functionality in C++, never before seen, and of such a like that will never
				// be henceforth seen again in the time of programmers and man alike
				// </&sensationalist>
				NextPos += (NextSpeed * a_Dt);
			}
		}
		else
		{
			// We didn't hit anything, so move =]
			NextPos += (NextSpeed * a_Dt);
		}
	}

	SetPosition(NextPos);
	SetSpeed(NextSpeed);
}
コード例 #22
0
ファイル: Character.cpp プロジェクト: superhakgoman/CPP
void CCharacter::SetPosition(int x, int y) {
	Position pos;
	pos.x = x;
	pos.y = y;
	SetPosition(pos);
}
コード例 #23
0
ファイル: VTooltip.cpp プロジェクト: guozanhua/projectanarchy
void VTooltip::OnPaint(VGraphicsInfo &Graphics, const VItemRenderInfo &parentState)
{
  if (m_fDelay>0.f)
    return;

  hkvVec2 vMousePos = GetContext()->GetCurrentMousePos();
  VCursor *pCursor = GetContext()->GetCurrentCursor();
  if (!pCursor)
    return;

  // offset tooltip position by cursor size
  VRectanglef rect;
  rect = pCursor->GetCursorRect();
  vMousePos += rect.m_vMax;

  const float fFullBorder = m_fBorderSize+m_fTextBorder;
  
  VRectanglef textRect;
  hkvVec2 v = m_pText->GetSize(&textRect);
  SetSize(v.x,v.y);
  m_pText->SetTextOfs(-textRect.m_vMin);

  float xpos= vMousePos.x-fFullBorder;
  float ypos= vMousePos.y-fFullBorder;

  int iSizeX, iSizeY;
  Vision::Contexts.GetCurrentContext()->GetSize(iSizeX, iSizeY);

  if((xpos + v.x) > iSizeX)
    xpos = iSizeX - v.x - fFullBorder*2;

  if((ypos + v.y) > iSizeY)
    ypos = iSizeY - v.y - fFullBorder*2;

  SetPosition(xpos,ypos);
  

  // fade in the tooltip
  float fFadeValue = hkvMath::Abs (m_fDelay)*4.f;
  if (fFadeValue>1.f) fFadeValue = 1.f;

  // render text on background
  VItemRenderInfo thisState(parentState,this,fFadeValue);
  if (m_iBackgroundColor.a>0)
  {
    VRectanglef clientRect = GetBoundingBox();
    VSimpleRenderState_t iState = VGUIManager::DefaultGUIRenderState();
    if (m_fBorderSize>0.f)
    {
      VColorRef iColor = m_iBorderColor;
      iColor.a = (int)((float)iColor.a*fFadeValue);
      hkvVec2 vb(fFullBorder,fFullBorder);
      Graphics.Renderer.DrawSolidQuad(clientRect.m_vMin-vb,clientRect.m_vMax+vb,iColor,iState);
    }
    
    VColorRef iColor = m_iBackgroundColor;
    iColor.a = (int)((float)iColor.a*fFadeValue);
    hkvVec2 vb(m_fTextBorder,m_fTextBorder);
    Graphics.Renderer.DrawSolidQuad(clientRect.m_vMin-vb,clientRect.m_vMax+vb,iColor,iState);
  }
  m_pText->OnPaint(Graphics,thisState);
}
コード例 #24
0
ファイル: INIFile.cpp プロジェクト: viticm/pap2
void INIFile::SetINI(const String& sField, const String& sKey, const String& sValue)
{
	SetPosition(0);

	vector< String > sv;
	String sTemp;
	while(!IsFileEOF())  // Read all original lines into our vector
	{
		sTemp = ReadLine();
		sTemp.Trim();
		sv.push_back(sTemp);
	}

	std::vector< String >::iterator i, iend;
	i = sv.begin();
	iend = sv.end();
	bool bDone = false;
	for(; i != iend; ++i)
	{
		sTemp = *i;
		if(sTemp == "[" + sField + "]")  // find the field
		{
			for(++i; i != iend; ++i)
			{
				if(i->IfContain("["))  // Touch another field
				{
					sv.insert(i, sKey + " = " + sValue);

					bDone = true;
					break;
				}
				else
				{
					sTemp = *i;

					String::size_type PosOfSep = sTemp.find('=');
					if(PosOfSep != String::npos)
					{
						sTemp = sTemp.substr(0, PosOfSep);
					}

					sTemp.Trim();
					if(sTemp == sKey)  // Find the item, set it!
					{
						i->operator = (sKey + " = " + sValue);

						bDone = true;
						break;
					}
				}
			}

			if(!bDone)
			{
				sv.push_back(sKey + " = " + sValue);
				bDone = true;
			}

			break;
		}
	}

	if(!bDone)
	{
		sv.push_back("[" + sField + "]");
		sv.push_back(sKey + " = " + sValue);

		bDone = true;
	}


	// Now update the ini file...

	Close();  // First, close the ini file cause we open it as read-writable file

	WOFile inif;
	inif.SetFilename(m_sFilename);
	inif.Open();

	for(unsigned int j = 0; j < sv.size() - 1; ++j)
	{
		sTemp = sv[j];
		inif.WriteLine(sTemp);
	}
	sTemp = sv[j];  // The last line
	inif.WriteBuffer((const void*)sTemp.c_str(), sTemp.GetSize());

	inif.Close();

	Open();  // Open the ini file for the following use
}
コード例 #25
0
void CUser::Regene(uint8 regene_type, uint32 magicid /*= 0*/)
{
	ASSERT(GetMap() != nullptr);

	_OBJECT_EVENT* pEvent = nullptr;
	_START_POSITION* pStartPosition = nullptr;
	float x = 0.0f, z = 0.0f;

	if (!isDead())
		return;

	if (regene_type != 1 && regene_type != 2)
		regene_type = 1;

	if (regene_type == 2) 
	{
		magicid = 490041;	// The Stone of Ressurection magic ID

		// Is our level high enough to be able to resurrect using this skill?
		if (GetLevel() <= 5
			// Do we have enough resurrection stones?
				|| !RobItem(379006000, 3 * GetLevel()))
				return;
	}

	// If we're in a home zone, we'll want the coordinates from there. Otherwise, assume our own home zone.
	pStartPosition = g_pMain->m_StartPositionArray.GetData(GetZoneID());
	if (pStartPosition == nullptr)
		return;

	UserInOut(INOUT_OUT);

	pEvent = GetMap()->GetObjectEvent(m_sBind);	

	// If we're not using a spell to resurrect.
	if (magicid == 0) 
	{
		// Resurrect at a bind/respawn point
		if (pEvent && pEvent->byLife == 1)
		{
			SetPosition(pEvent->fPosX + x, 0.0f, pEvent->fPosZ + z);
		}
		// Are we trying to respawn in a home zone?
		// If we're in a war zone (aside from snow wars, which apparently use different coords), use BattleZone coordinates.
		else if ((GetZoneID() <= ZONE_ELMORAD) || (GetZoneID() != ZONE_SNOW_BATTLE && GetZoneID() == (ZONE_BATTLE_BASE + g_pMain->m_byBattleZone))) 
		{
			// Use the proper respawn area for our nation, as the opposite nation can
			// enter this zone at a war's invasion stage.
			x = (float)((GetNation() == KARUS ? pStartPosition->sKarusX :  pStartPosition->sElmoradX) + myrand(0, pStartPosition->bRangeX));
			z = (float)((GetNation() == KARUS ? pStartPosition->sKarusZ :  pStartPosition->sElmoradZ) + myrand(0, pStartPosition->bRangeZ));
		}
		else
		{
			// If we're in a war zone (aside from snow wars, which apparently use different coords), use BattleZone coordinates.
			if (GetZoneID() == ZONE_MORADON && isInArena())
			{
				x = (float)(MINI_ARENA_RESPAWN_X + myrand(-MINI_ARENA_RESPAWN_RADIUS, MINI_ARENA_RESPAWN_RADIUS));
				z = (float)(MINI_ARENA_RESPAWN_Z + myrand(-MINI_ARENA_RESPAWN_RADIUS, MINI_ARENA_RESPAWN_RADIUS));
			}
			// For all else, just grab the start position (/town coordinates) from the START_POSITION table.
			else
			{
				short sx, sz;
				GetStartPosition(sx, sz);
				x = sx;
				z = sz;
			}
		}

		SetPosition(x, 0.0f, z);

		m_bResHpType = USER_STANDING;	
		m_bRegeneType = REGENE_NORMAL;
	}
	else // we're respawning using a resurrect skill.
	{
		_MAGIC_TYPE5 * pType = g_pMain->m_Magictype5Array.GetData(magicid);     
		if (pType == nullptr)
			return;

		MSpChange(-m_iMaxMp); // reset us to 0 MP. 

		if (m_sWhoKilledMe == -1) 
			ExpChange((m_iLostExp * pType->bExpRecover) / 100); // Restore 

		m_bResHpType = USER_STANDING;
		m_bRegeneType = REGENE_MAGIC;
	}

	Packet result(WIZ_REGENE);
	result << GetSPosX() << GetSPosZ() << GetSPosY();
	Send(&result);

	HpChange(GetMaxHealth());

	m_tLastRegeneTime = UNIXTIME;
	m_sWhoKilledMe = -1;
	m_iLostExp = 0;

	if (magicid == 0)
		BlinkStart();

	if (!isBlinking())
	{
		result.Initialize(AG_USER_REGENE);
		result << GetSocketID() << m_sHp;
		Send_AIServer(&result);
	}

	SetRegion(GetNewRegionX(), GetNewRegionZ());

	UserInOut(INOUT_RESPAWN);		

	g_pMain->RegionUserInOutForMe(this);
	g_pMain->RegionNpcInfoForMe(this);

	InitializeStealth();
	SendUserStatusUpdate(USER_STATUS_DOT, USER_STATUS_CURE);
	SendUserStatusUpdate(USER_STATUS_POISON, USER_STATUS_CURE);

	if (isInArena())
		SendUserStatusUpdate(USER_STATUS_SPEED, USER_STATUS_CURE);

	RecastSavedMagic();

	// If we actually respawned (i.e. we weren't resurrected by a skill)...
	if (magicid == 0)
	{
		// In PVP zones (not war zones), we must kick out players if they no longer
		// have any national points.
		if (GetLoyalty() == 0 
			&& (GetMap()->isWarZone()
			|| isInPKZone() || Event()))
			KickOutZoneUser();
	}
}
コード例 #26
0
ファイル: Obj_Bus.cpp プロジェクト: gitrider/wxsj2
BOOL CObject_Bus::Tick_Move(UINT uElapseTime)
{
	FLOAT fElapseTime = (FLOAT)uElapseTime / 1000.f;
	FLOAT fMoveDist = fElapseTime * GetMoveSpeed();
	FLOAT fDist = KLU_GetDist(fVector3(GetPosition().x, 0.f, GetPosition().z), fVector3(m_fvMoveTargetPos.x, 0.f, m_fvMoveTargetPos.z));
	if(fMoveDist >= fDist)
	{
		if(m_fvMoveTargetPos.y <= DEF_BUS_PATH_NODE_INVALID_Y)
		{
			SetMapPosition(fVector2(m_fvMoveTargetPos.x, m_fvMoveTargetPos.z));
		}
		else
		{
			SetPosition(m_fvMoveTargetPos);
		}
		StopMove();
	}
	else
	{
		if(fDist > 0.f)
		{
			fVector3 fvThisPos = GetPosition();
			fVector3 fvLen = m_fvMoveTargetPos - fvThisPos;
			if(m_fvMoveTargetPos.y <= DEF_BUS_PATH_NODE_INVALID_Y)
			{
				fvThisPos.x += (fvLen.x/fDist) * fMoveDist;
				fvThisPos.z += (fvLen.z/fDist) * fMoveDist;
				SetMapPosition(fVector2(fvThisPos.x, fvThisPos.z));
			}
			else
			{
				fvThisPos.x += (fvLen.x/fDist) * fMoveDist;
				fvThisPos.y += (fvLen.y/fDist) * fMoveDist;
				fvThisPos.z += (fvLen.z/fDist) * fMoveDist;
				SetPosition(fvThisPos);
			}
		}
	}

	FLOAT fFaceDir = GetFaceDir();
	if(fabsf(m_fTargetDir - fFaceDir) > 0.01f)
	{
		if(fabsf(m_fTargetDir - fFaceDir) < __PI * 5.f / 4.f
			&& fabsf(m_fTargetDir - fFaceDir) > __PI * 3.f / 4.f)
		{
			SetFaceDir(m_fTargetDir);
		}
		else
		{
			FLOAT fElapseDir = fElapseTime * __PI;
			if(m_fTargetDir - fFaceDir > __PI
				|| (m_fTargetDir - fFaceDir < 0.f && m_fTargetDir - fFaceDir > -__PI))
			{// 正转
				fFaceDir -= fElapseDir;
				if(fFaceDir < 0.f)
				{
					fFaceDir += 2.f *__PI;
				}
				SetFaceDir(fFaceDir);
			}
			else
			{// 反转
				fFaceDir += fElapseDir;
				if(fFaceDir > m_fTargetDir)
				{
					fFaceDir = m_fTargetDir;
				}
				SetFaceDir(fFaceDir);
			}
		}
	}
	return TRUE;
}
コード例 #27
0
ファイル: CTriangle.cpp プロジェクト: cugone/Abrams2010
void Triangle::SetX(double x) {
    SetPosition(x, GetY());
}
コード例 #28
0
ファイル: hfaentry.cpp プロジェクト: StephenHolzman/UVAmisc
CPLErr HFAEntry::FlushToDisk()

{
/* -------------------------------------------------------------------- */
/*      If we are the root node, call SetPosition() on the whole        */
/*      tree to ensure that all entries have an allocated position.     */
/* -------------------------------------------------------------------- */
    if( poParent == NULL )
        SetPosition();

/* ==================================================================== */
/*      Only write this node out if it is dirty.                        */
/* ==================================================================== */
    if( bDirty )
    {
/* -------------------------------------------------------------------- */
/*      Ensure we know where the relative entries are located.          */
/* -------------------------------------------------------------------- */
        if( poNext != NULL )
            nNextPos = poNext->nFilePos;

        if( poChild != NULL )
            nChildPos = poChild->nFilePos;

/* -------------------------------------------------------------------- */
/*      Write the Ehfa_Entry fields.                                    */
/* -------------------------------------------------------------------- */

        //VSIFFlushL( psHFA->fp );
        if( VSIFSeekL( psHFA->fp, nFilePos, SEEK_SET ) != 0 )
        {
            CPLError( CE_Failure, CPLE_FileIO,
                      "Failed to seek to %d for writing, out of disk space?",
                      nFilePos );
            return CE_Failure;
        }

        GUInt32 nLong = nNextPos;
        HFAStandard( 4, &nLong );
        bool bOK = VSIFWriteL( &nLong, 4, 1, psHFA->fp ) > 0;

        if( poPrev != NULL )
            nLong = poPrev->nFilePos;
        else
            nLong = 0;
        HFAStandard( 4, &nLong );
        bOK &= VSIFWriteL( &nLong, 4, 1, psHFA->fp ) > 0;

        if( poParent != NULL )
            nLong = poParent->nFilePos;
        else
            nLong = 0;
        HFAStandard( 4, &nLong );
        bOK &= VSIFWriteL( &nLong, 4, 1, psHFA->fp ) > 0;

        nLong = nChildPos;
        HFAStandard( 4, &nLong );
        bOK &= VSIFWriteL( &nLong, 4, 1, psHFA->fp ) > 0;

        nLong = nDataPos;
        HFAStandard( 4, &nLong );
        bOK &= VSIFWriteL( &nLong, 4, 1, psHFA->fp ) > 0;

        nLong = nDataSize;
        HFAStandard( 4, &nLong );
        bOK &= VSIFWriteL( &nLong, 4, 1, psHFA->fp ) > 0;

        bOK &= VSIFWriteL( szName, 1, 64, psHFA->fp ) > 0;
        bOK &= VSIFWriteL( szType, 1, 32, psHFA->fp ) > 0;

        nLong = 0; /* Should we keep the time, or set it more reasonably? */
        bOK &= VSIFWriteL( &nLong, 4, 1, psHFA->fp ) > 0;
        if( !bOK )
        {
            CPLError( CE_Failure, CPLE_FileIO,
                      "Failed to write HFAEntry %s(%s), out of disk space?",
                      szName, szType );
            return CE_Failure;
        }

/* -------------------------------------------------------------------- */
/*      Write out the data.                                             */
/* -------------------------------------------------------------------- */
        //VSIFFlushL( psHFA->fp );
        if( nDataSize > 0 && pabyData != NULL )
        {
            if( VSIFSeekL( psHFA->fp, nDataPos, SEEK_SET ) != 0
                || VSIFWriteL( pabyData, nDataSize, 1, psHFA->fp ) != 1 )
            {
                CPLError( CE_Failure, CPLE_FileIO,
                          "Failed to write %d bytes HFAEntry %s(%s) data,\n"
                          "out of disk space?",
                          nDataSize, szName, szType );
                return CE_Failure;
            }
        }

        //VSIFFlushL( psHFA->fp );
    }

/* -------------------------------------------------------------------- */
/*      Process all the children of this node                           */
/* -------------------------------------------------------------------- */
    for( HFAEntry *poThisChild = poChild;
         poThisChild != NULL;
         poThisChild = poThisChild->poNext )
    {
        CPLErr eErr = poThisChild->FlushToDisk();
        if( eErr != CE_None )
            return eErr;
    }

    bDirty = FALSE;

    return CE_None;
}
コード例 #29
0
ファイル: CTriangle.cpp プロジェクト: cugone/Abrams2010
void Triangle::SetPosition(double x, double y) {
    SetPosition(x, y);
}
コード例 #30
0
ファイル: BoneMoveable.cpp プロジェクト: fjz13/Medusa
void BoneMoveable::SetLocalPosition(const Point3F& val)
{
	SetPosition(val);
}