Wimo135 Posted January 4, 2022 Share Posted January 4, 2022 (edited) I have a mesh with a rigidbody and a global water object how can i make this mesh interact with the waves of the global water object Edited January 6, 2022 by Wimo135 Link to comment
fox Posted January 10, 2022 Share Posted January 10, 2022 Hi Wimo135, This video may help you! Thanks! Link to comment
Wimo135 Posted January 10, 2022 Author Share Posted January 10, 2022 Thank you for your response. This is helpful but i already knew this, i would like to simulate the waves on the whole global water body/ Link to comment
silent Posted January 11, 2022 Share Posted January 11, 2022 Wimo135 That would be impossible to achieve with the current hardware, unfortunately. You can use ObjectWaterGlobal API to get the wave height at the specific points and implement simplified ship buoyancy logic based on the information you get. If you are using C++ you can check SDK Browser -> Demos -> CPP Samples -> Water Global with this approach implementation. For C# right now we don't have similar sample available out of the box, but it shouldn't be hard to port this code. Thanks! 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
Wimo135 Posted January 11, 2022 Author Share Posted January 11, 2022 Thank you very much for your response, Im looking into this now. Link to comment
Wimo135 Posted January 18, 2022 Author Share Posted January 18, 2022 Ive been trying to integrate this into my project recently but im running into a problem where my code just outputs a seemingly random number. This is my code: using System; using System.Collections; using System.Collections.Generic; using Unigine; using UnigineApp; [Component(PropertyGuid = "c0bb98fbb56cba1ef20a5ae58789cf003de8765f")] public class WaveDetector : Component { public ObjectWaterGlobal water; public NodeDummy node; public float z; public Unigine.Object boat; private void Init() { // write here code to be called on component initialization } private void Update() { // write here code to be called before updating each render frame z = water.FetchHeight(node.Position); Log.Error(z); //boat.Position = new vec3(boat.Position.x, boat.Position.y, boat.Position.z + z); } } Link to comment
silent Posted January 19, 2022 Share Posted January 19, 2022 What do you mean by random number? Can you show us full output? FetchHeight returns distance between your point and wave height just below this point, so it can sometimes be negative (when your point is inside water volume). 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
Wimo135 Posted January 19, 2022 Author Share Posted January 19, 2022 I've resolved the issue, the issue was that i was using the local position of the dummy nodes instead of the world position, i have it working now. Link to comment
Wimo135 Posted January 19, 2022 Author Share Posted January 19, 2022 However i still can't figure out how to rotate the object according to the points position. Link to comment
silent Posted January 20, 2022 Share Posted January 20, 2022 In C++ water samples there was an example that shows how to that rotation (in cpp_samples/source/water_buoy/BuoyComponent.cpp). You need at least 3 points that would represents ship. 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
Wimo135 Posted January 20, 2022 Author Share Posted January 20, 2022 Ive looked into that c++ file but i only see code for the location not the rotation of the boat. Link to comment
silent Posted January 20, 2022 Share Posted January 20, 2022 And what do you mean by rotation? Do you have any references? 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
Wimo135 Posted January 20, 2022 Author Share Posted January 20, 2022 I have been able to get the boat to move over the waves but i cant figure out how to make the boat rotate to the waves. for example if a wave is in front of the boat it should rotate up then go over the wave. Link to comment
cash-metall Posted January 21, 2022 Share Posted January 21, 2022 Hi in BuoyComponent.cpp if (water) { auto node_transform = node->getWorldTransform(); // current transform matrix: (TRS: translate-rotation-scale) // point0, point1, point2 - position of control points Vec3 point0 = point_front_center->getWorldPosition(); Vec3 point1 = point_back_left->getWorldPosition(); Vec3 point2 = point_back_right->getWorldPosition(); //create basis before transformation by 3 point Vec3 tmp_z = normalize(cross(normalize(point1 - point0), normalize(point2 - point0))); // up vector if (getAngle(vec3(tmp_z), vec3_up) > 90) tmp_z = -tmp_z; Vec3 tmp_y = normalize(point1 - point0); Vec3 tmp_x = tmp_y; cross(tmp_x, tmp_y, tmp_z).normalize(); // right vector cross(tmp_y, tmp_z, tmp_x).normalize(); // forward Mat4 old_basis; old_basis.setTranslate(point0); old_basis.setColumn3(0, tmp_x); old_basis.setColumn3(1, tmp_y); old_basis.setColumn3(2, tmp_z); // find height for each controll point Scalar h0 = water->fetchHeight(Vec3(point0.x, point0.y, 0.0f)); Scalar h1 = water->fetchHeight(Vec3(point1.x, point1.y, 0.0f)); Scalar h2 = water->fetchHeight(Vec3(point2.x, point2.y, 0.0f)); Scalar lerp_k = Game::getIFps() * mass_coef; // smooth change height for each control point point0.z = lerp(point0.z, h0, lerp_k); point1.z = lerp(point1.z, h1, lerp_k); point2.z = lerp(point2.z, h2, lerp_k); // calculate new basis the same way tmp_z = normalize(cross(normalize(point1 - point0), normalize(point2 - point0))); tmp_y = normalize(point1 - point0); cross(tmp_x, tmp_y, tmp_z).normalize(); cross(tmp_y, tmp_z, tmp_x).normalize(); Mat4 new_basis; new_basis.setTranslate(point0); new_basis.setColumn3(0, tmp_x); new_basis.setColumn3(1, tmp_y); new_basis.setColumn3(2, tmp_z); // calculate matrix for translation from old_basis to new_basis Mat4 translation_basis, new_transform; mul(translation_basis, new_basis, inverse(old_basis)); // change node_transform by translation_basis mul(new_transform, translation_basis, node_transform); // apply node_transform node->setWorldTransform(new_transform); } } for better accurancy you need to take more than 3 points. 1 Link to comment
Wimo135 Posted February 6, 2022 Author Share Posted February 6, 2022 I understand this but i don't understand how to implement this in c#. Link to comment
karpych11 Posted February 7, 2022 Share Posted February 7, 2022 Hello, I ported buoyancy sample logic to C#. Hope this helps. BuoyComponent.cs BuoySample.cs 1 1 Link to comment
Wimo135 Posted February 8, 2022 Author Share Posted February 8, 2022 (edited) Thanks very much this helped a lot! Edited February 8, 2022 by Wimo135 1 Link to comment
Recommended Posts