//----------------------------------------------------------------------------
void EditRenderView_Scene::_UpdateBrushPos(const APoint &pos)
{
	Project *proj = Project::GetSingletonPtr();
	if (!proj) return;

	Scene *scene = proj->GetScene();
	if (!scene) return;

	TerrainActor *terrainActor = scene->GetTerrainActor();
	if (!terrainActor) return;

	RawTerrain *terrain = terrainActor->GetRawTerrain();

	APoint origin;
	AVector dir;
	mRenderStep->GetPickRay(pos.X(), pos.Z(), origin, dir);

	Movable *pickObject = terrain;

#ifdef _DEBUG
	pickObject = PX2_GR.GetXYPlane();
	pickObject->WorldTransform.SetTranslate(APoint::ORIGIN);
#endif

	if (pickObject)
	{
		PX2::Picker picker;
		picker.Execute(pickObject, origin, dir, 0.0f, Mathf::MAX_REAL);
		if ((int)picker.Records.size() > 0)
		{
			PX2::PickRecord pickRecord = picker.GetClosestToZero();
			PX2::APoint dest = origin + dir*pickRecord.T;

			PX2_EDIT.GetTerrainEdit()->GetBrush()->SetPos(dest);
		}
	}
}
Esempio n. 2
0
//----------------------------------------------------------------------------
SceneNodeCtrl::DragType SceneNodeCtrl::GetDragType(RenderStep *renderStep,
	const PX2::APoint &point)
{
	APoint origin;
	AVector direction;
	renderStep->GetPickRay(point.X(), point.Z(), origin, direction);

	PX2::Picker picker;

	PX2::Movable *ctrlX = GetCurrentCtrlX();
	PX2::Movable *ctrlY = GetCurrentCtrlY();
	PX2::Movable *ctrlZ = GetCurrentCtrlZ();
	PX2::Movable *ctrlXYZ = GetCurrentCtrlXYZ();
	PX2::Movable *ctrlXY = GetCurrentCtrlXY();
	PX2::Movable *ctrlYZ = GetCurrentCtrlYZ();
	PX2::Movable *ctrlXZ = GetCurrentCtrlXZ();

	bool xDrag = false;
	float xDragT = Mathf::MAX_REAL;

	bool yDrag = false;
	float yDragT = Mathf::MAX_REAL;

	bool zDrag = false;
	float zDragT = Mathf::MAX_REAL;

	bool xyzDrag = false;
	float xyzDragT = Mathf::MAX_REAL;

	bool xyDrag = false;
	float xyDragT = Mathf::MAX_REAL;

	bool yzDrag = false;
	float yzDragT = Mathf::MAX_REAL;

	bool xzDrag = false;
	float xzDragT = Mathf::MAX_REAL;

	GetCtrlsGroup()->Update(Time::GetTimeInSeconds(), false);

	picker.Execute(ctrlX, origin, direction, -Mathf::MAX_REAL, Mathf::MAX_REAL);
	if ((int)picker.Records.size() > 0)
	{
		xDrag = true;
		xDragT = picker.GetClosestNonnegative().T;
	}

	picker.Execute(ctrlY, origin, direction, -Mathf::MAX_REAL, Mathf::MAX_REAL);
	if ((int)picker.Records.size() > 0)
	{
		yDrag = true;
		yDragT = picker.GetClosestNonnegative().T;
	}

	picker.Execute(ctrlZ, origin, direction, -Mathf::MAX_REAL, Mathf::MAX_REAL);
	if ((int)picker.Records.size() > 0)
	{
		zDrag = true;
		zDragT = picker.GetClosestNonnegative().T;
	}

	picker.Execute(ctrlXYZ, origin, direction, -Mathf::MAX_REAL, Mathf::MAX_REAL);
	if ((int)picker.Records.size() > 0)
	{
		xyzDrag = true;
		xyzDragT = picker.GetClosestNonnegative().T;
	}

	picker.Execute(ctrlXY, origin, direction, -Mathf::MAX_REAL, Mathf::MAX_REAL);
	if ((int)picker.Records.size() > 0)
	{
		xyDrag = true;
		xyDragT = picker.GetClosestNonnegative().T;
	}

	picker.Execute(ctrlYZ, origin, direction, -Mathf::MAX_REAL, Mathf::MAX_REAL);
	if ((int)picker.Records.size() > 0)
	{
		yzDrag = true;
		yzDragT = picker.GetClosestNonnegative().T;
	}

	picker.Execute(ctrlXZ, origin, direction, -Mathf::MAX_REAL, Mathf::MAX_REAL);
	if ((int)picker.Records.size() > 0)
	{
		xzDrag = true;
		xzDragT = picker.GetClosestNonnegative().T;
	}

	if (xDrag)
		return DT_X;
	else if (yDrag)
		return DT_Y;
	else if (zDrag)
		return DT_Z;
	else if (xyzDrag)
		return DT_XYZ;
	else if (xyDrag)
		return DT_XY;
	else if (yzDrag)
		return DT_YZ;
	else if (xzDrag)
		return DT_XZ;

	return DT_NONE;
}