Sevdat Posted July 16 Share Posted July 16 (edited) Good evening, I'm using the code below, but when the spheres are created they are not in the center of the mouse which means the code won't cast rays to the correct cursor point vec3: public PlayerSpectator cam; public ObjectMeshDynamic createSphere(float radius,vec3 position,int i){ ObjectMeshDynamic sphere = Primitives.CreateSphere(radius, 9, 32); sphere.TriggerInteractionEnabled = true; sphere.SetIntersection(true, 0); sphere.SetIntersectionMask(0x00000080, 0); // check the BulletIntersection bit sphere.WorldPosition = position; sphere.Name = $"{i}"; return sphere; } private void Init(){ ControlsApp.MouseHandle = Input.MOUSE_HANDLE.USER; } void Update(){ if (Input.IsMouseButtonDown(Input.MOUSE_BUTTON.LEFT)){ ivec2 mainWindow = WindowManager.MainWindow.Size; int mouseX = Gui.GetCurrent().MouseX; int mouseY = Gui.GetCurrent().MouseY; vec3 cursorDirection = new vec3(cam.GetDirectionFromScreen(mouseX, mouseY, 0, 0, mainWindow.x, mainWindow.y)) * 50; createSphere(1f,cam.WorldPosition + cursorDirection,1); } } How can I center the created spheres to the mouse cursor? Edited July 16 by Sevdat Link to comment
silent Posted July 17 Share Posted July 17 Try to use getDirectionFromMainWindow instead. Probably it would provide better results: Math::ivec2 mouse = InputMousePosition(); vec3 cursorDirection = new vec3(cam.getDirectionFromMainWindow(mouse.x, mouse.y) * 50; 1 How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Sevdat Posted July 17 Author Share Posted July 17 1 hour ago, silent said: Try to use getDirectionFromMainWindow instead. Probably it would provide better results: Math::ivec2 mouse = Input::getMousePosition(); vec3 cursorDirection = new vec3(cam.getDirectionFromMainWindow(mouse.x, mouse.y) * 50; Good day silent, You are a genius. The code works perfectly: ivec2 mouse = Input.MousePosition; vec3 cursorDirection = new vec3(cam.GetDirectionFromMainWindow(mouse.x, mouse.y)) * 50; but I think in C# getMousePosition is MousePosition which is strange. I think naming C++ and C# functions the same would be better for future development. https://developer.unigine.com/en/docs/future/api/library/controls/class.input?rlang=cpp Link to comment
silent Posted July 17 Share Posted July 17 It's C# naming convention from Microsoft, more friendly to C# programmers. So I guess it would remain as it designed :) How to submit a good bug report --- FTP server for test scenes and user uploads: ftp://files.unigine.com user: upload password: 6xYkd6vLYWjpW6SN Link to comment
Recommended Posts