Esempio n. 1
0
	void RenderWindow::Update()
	{
		if (!mFocus)
			return ;

		SceneNode * cam = World::Instance()->MainCameraNode();

		// camera
		if (IMouse::Instance()->MouseMoved() && IMouse::Instance()->KeyPressed(MKC_BUTTON1))
		{
			Point2i pt = IMouse::Instance()->GetPositionDiff();

			if (abs(pt.y) >abs(pt.x))
			{
				cam->Pitch(pt.y * 0.005f, TS_LOCAL);
			}
			else
			{
				cam->Yaw(pt.x * 0.005f, TS_PARENT);
			}
		}

		if (IMouse::Instance()->MouseWheel())
		{
			cam->Move(0.1f * mWheelStep * IMouse::Instance()->MouseWheel());
		}

		MyGUI::IntCoord rc = mRenderWindow->getClientCoord();
		MyGUI::IntPoint pt = mRenderWindow->getAbsolutePosition();

		Point2i mousePt = IMouse::Instance()->GetPosition();
		float mouseX = (mousePt.x - pt.left) / (float)rc.width;
		float mouseY = (mousePt.y - pt.top) / (float)rc.height;

		Editor::Instance()->_SetMousePosition(Point2f(mouseX, mouseY));
	}
Esempio n. 2
0
	void RenderWindow::Update()
	{
		if (!mFocus || !xScene::Instance()->IsInited())
			return ;

		SceneNode * cam = World::Instance()->MainCameraNode();

		if (IKeyboard::Instance()->KeyPressed(KC_W))
		{
			cam->Move(5.0f);
		}
		else if (IKeyboard::Instance()->KeyPressed(KC_S))
		{
			cam->Move(-5.0f);
		}
		else if (IKeyboard::Instance()->KeyPressed(KC_A))
		{
			cam->Right(-5.0f);
		}
		else if (IKeyboard::Instance()->KeyPressed(KC_D))
		{
			cam->Right(5.0f);
		}
		else if (IKeyboard::Instance()->KeyUp(KC_DELETE))
		{
			for (int i = 0; i < Editor::Instance()->GetSelectedShapeSize(); ++i)
				ShapeManager::Instance()->Distroy(Editor::Instance()->GetSelectedShape(i));

			if (Editor::Instance()->GetSelectedShapeSize() > 0)
				Editor::Instance()->SetSelectedShape(NULL);
		}

		// parse 
		else if (IKeyboard::Instance()->KeyPressed(KC_LCONTROL) &&
			IKeyboard::Instance()->KeyUp(KC_V))
		{
			int count = 0;
			Shape * objs[1024];

			for (int i = 0; i < Editor::Instance()->GetSelectedShapeSize(); ++i)
			{
				Shape * newObj = Editor::Instance()->GetSelectedShape(i)->Clone();

				if (newObj)
					objs[count++] = newObj;
			}

			if (count)
				Editor::Instance()->SetSelectedShapes(objs, count);
		}

		// undo
		else if (IKeyboard::Instance()->KeyPressed(KC_LCONTROL) &&
			IKeyboard::Instance()->KeyUp(KC_Z))
		{
			xUndoRedoManager::Instance()->Undo();
		}

		// redo
		else if (IKeyboard::Instance()->KeyPressed(KC_LCONTROL) &&
			IKeyboard::Instance()->KeyUp(KC_Y))
		{
			xUndoRedoManager::Instance()->Redo();
		}
		

		// camera
		if (IMouse::Instance()->MouseMoved() && IMouse::Instance()->KeyPressed(MKC_BUTTON1))
		{
			Point2i pt = IMouse::Instance()->GetPositionDiff();

			if (abs(pt.y) >abs(pt.x))
			{
				cam->Pitch(pt.y * 0.005f, TS_LOCAL);
			}
			else
			{
				cam->Yaw(pt.x * 0.005f, TS_PARENT);
			}
		}

		if (IMouse::Instance()->MouseWheel())
		{
			cam->Move(0.5f * IMouse::Instance()->MouseWheel());
		}

		MyGUI::IntCoord rc = mRenderWindow->getClientCoord();
		MyGUI::IntPoint pt = mRenderWindow->getAbsolutePosition();

		Point2i mousePt = IMouse::Instance()->GetPosition();
		float mouseX = (mousePt.x - pt.left) / (float)rc.width;
		float mouseY = (mousePt.y - pt.top) / (float)rc.height;

		Editor::Instance()->_SetMousePosition(Point2f(mouseX, mouseY));

		// pick
		eOperator op = Editor::Instance()->GetOperator();
		if ((op == eOP_Pick || op == eOP_Move || op == eOP_Rotate || op == eOP_Scale) &&
			IMouse::Instance()->KeyUp(MKC_BUTTON0) && !Gizmo::Instance()->IsPicked())
		{
			float x = mouseX, y = mouseY;

			if (x > 0 && x < 1 && y > 0 && y < 1)
			{
				Ray ray = World::Instance()->MainCamera()->GetViewportRay(x, y);

				HitInfoSetArray infos;

				IPhyWorld::Instance()->RayCheck(infos, ray, 1000.0f, PICK_Flag, true);

				if (infos.Size() > 0 && infos[0].node)
				{
					Shape * obj = ShapeManager::Instance()->Get(infos[0].node);

					if (obj)
						Editor::Instance()->SetSelectedShape(obj);
				}
				else
				{
					Editor::Instance()->SetSelectedShape(NULL);
				}
			}
		}

		Gizmo::Instance()->Update(mouseX, mouseY);


		if (op != eOP_Terrain && Utils::IsMouseDoubleClick(MKC_BUTTON0))
		{
			TString128 type = ToolControl::Instance()->GetSelectObject();

			if (type != "")
			{
				Shape * shape = ShapeManager::Instance()->Create(type.c_str());

				if (shape)
				{
					Vec3 pos = Editor::Instance()->GetHitPosition(mouseX, mouseY);

					shape->SetPosition(pos);

					Editor::Instance()->SetSelectedShape(shape);
				}
			}
		}
	}