コード例 #1
0
//----------------------------------------------------------------------------
void EditRenderView_Scene::_ClickSelectPos(const APoint &scrPos)
{
	Scene *scene = PX2_PROJ.GetScene();
	Canvas *canvas = PX2_PROJ.GetSceneCanvas();

	APoint origin;
	AVector direction;
	canvas->GetPickRay(scrPos.X(), scrPos.Z(), origin, direction);

	ActorPicker actorPicker;
	actorPicker.Execute(scene, origin, direction, 0.0f, Mathf::MAX_REAL);

	if (actorPicker.Records.size() > 0)
	{
		const ActorPickRecord &record = actorPicker.GetClosestToZero();
		mSelectPoint = origin + direction*record.T;
		PX2_EDIT.SetPickPos(mSelectPoint);
	}
	else
	{
		PX2::TriMesh *xyPlane = PX2_GR.GetXYPlane();
		xyPlane->WorldTransform.SetTranslate(APoint::ORIGIN);

		Picker picker;
		picker.Execute(xyPlane, origin, direction, 0.0f, Mathf::MAX_REAL);
		if ((int)picker.Records.size() > 0)
		{
			const PickRecord &rec = picker.GetClosestToZero();
			mSelectPoint = origin + direction*rec.T;
			PX2_EDIT.SetPickPos(mSelectPoint);
		}
	}
}
コード例 #2
0
//----------------------------------------------------------------------------
void EditRenderView_Scene::_ClickSelectScene(const APoint &scrPos,
	SelectMode mode)
{
	Scene *scene = PX2_PROJ.GetScene();
	Canvas *canvas = PX2_PROJ.GetSceneCanvas();

	// pre
	std::map<Actor*, bool> actorsPickable;
	for (int i = 0; i < scene->GetNumChildren(); i++)
	{
		Actor *actor = DynamicCast<Actor>(scene->GetChild(i));
		if (actor)
		{
			actorsPickable[actor] = actor->IsPickable();
			actor->SetPickable(true);
		}
	}

	APoint origin;
	AVector direction;
	canvas->GetPickRay(scrPos.X(), scrPos.Z(), origin, direction);

	ActorPicker actorPicker;
	actorPicker.Execute(scene, origin, direction, 0.0f, Mathf::MAX_REAL);

	// post
	std::map<Actor*, bool>::iterator it = actorsPickable.begin();
	for (; it != actorsPickable.end(); it++)
	{
		Actor *actor = it->first;
		actor->SetPickable(it->second);
	}
	actorsPickable.clear();

	if (actorPicker.Records.size() > 0)
	{
		const ActorPickRecord &record = actorPicker.GetClosestToZero();
		Object *recordObj = record.Intersected;
		mSelectPoint = origin + direction*record.T;
		PX2_EDIT.SetPickPos(mSelectPoint);

		if (SM_SINGLE == mode)
		{
			int numObjs = PX2_SELECTION.GetNumObjects();
			if (1 == numObjs && recordObj==PX2_SELECTION.GetFirstObject())
			{
				PX2_SELECTION.Clear();
			}
			else
			{
				PX2_SELECTION.Clear();
				PX2_SELECTION.AddObject(recordObj);
			}
		}
		else if (SM_MULTI == mode)
		{
			if (PX2_SELECTION.IsObjectIn(recordObj))
			{
				PX2_SELECTION.RemoveObject(recordObj);
			}
			else
			{
				PX2_SELECTION.AddObject(recordObj);
			}
		}
	}
	else
	{
		if (SM_SINGLE == mode)
		{
			PX2_SELECTION.Clear();
		}
	}

	SelectMode mode = SM_SINGLE;
	if (PX2_EDIT.IsCtrlDown) mode = SM_MULTI;
}