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)); }
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); } } } }
void MaterialScreen::onInit(ScreenContext& sc) { // Store engine ref mEngine = sc.GetEngine(); // Store file data cache ref mFileDataCache = sc.GetFileDataCache(); // Add sample UV Sphere ModelData sphereModel = GenUVSphere(1, 32, 32); mEngine->GetModelStore().Load("sphere", std::move(sphereModel)); // Create scene mScene = std::make_unique<Scene>(); // Create materials int id = 0; for (int metallic = 0; metallic <= 1; ++metallic) { for (float roughness = 0.0f; roughness < 1.0f; roughness += 0.1f) { for (float reflectivity = 0.0f; reflectivity < 1.0; reflectivity += 0.1f) { // Create and store the material std::string materialName; materialName += metallic == 1 ? "m" : "d"; materialName += "r" + std::to_string(roughness); materialName += "f" + std::to_string(reflectivity); Material m; m.SetMetallic(static_cast<float>(metallic)); m.SetRoughness(roughness); m.SetFresnel(reflectivity); m.SetDiffuseColor(glm::vec3(255.0f, 0.0f, 0.0f)); mEngine->GetMaterialStore().Load(materialName, m); // Create and store the object that will be made of the material previously defined SceneNode* node = mScene->CreateNode( "sphere", {materialName}, std::to_string(id), Category::Normal, sphereModel.boundingBox ); node->Move(glm::vec3(roughness * 20.0f -10.0f + 22.0f * metallic, reflectivity * 20.0f - 10.0f, 0.0f)); ++id; } } } // Setup scene lights Lights& lights = mEngine->GetRenderer().GetLights(); // Add directional light DirLight dirLight; dirLight.direction = glm::vec3(-0.3f, -0.5f, -0.5f); dirLight.color = glm::vec3(0.9f); lights.dirLights.push_back(dirLight); // Camera initial position mCamera.SetPos(glm::vec3(-6, 8, 12)); mCamera.Look(std::make_tuple(450.0f, 450.0f)); // Load the skybox ImageLoader imLoader; auto& cubemapStore = mEngine->GetCubemapStore(); cubemapStore.Load(skybox, imLoader.Load(*(*mFileDataCache)["ext/Assets/Textures/Skybox/Indoors/indoors.tga"], "tga")); mEngine->GetSkyboxRenderer().SetCubemapId(cubemapStore[skybox]->id); // Load the irr map mEngine->GetCubemapStore().Load(irrmap, imLoader.Load(*(*mFileDataCache)["ext/Assets/Textures/Skybox/Indoors/indoors_irr.tga"], "tga")); // Load the rad map for (unsigned int i = 0; i < 9; ++i) { mEngine->GetCubemapStore().Load( radmap, imLoader.Load(*(*mFileDataCache)[ "ext/Assets/Textures/Skybox/Indoors/indoors_rad_" + std::to_string(i) + ".tga"], "tga"), i); } // Init renderform creator mRenderformCreator = std::make_unique<RenderformCreator>(&(mEngine->GetModelStore()), &(mEngine->GetMaterialStore())); }