de-Roo.Lukas Posted December 3, 2017 Share Posted December 3, 2017 Many functions in ObjectTerrain class need to use the grid point such as float getHeight(int x, int y) int getHole(int x, int y) Math::vec3 getNormal(int x, int y) int x - X coordinate of the point on the terrain grid in range from 0 to the maximum terrain widwth. int y - Y coordinate of the point on the terrain grid in range from 0 to the maximum terrain length. how can I know which gird point in the terrain that my current position belongs to ? Thanks Link to comment
fox Posted December 5, 2017 Share Posted December 5, 2017 Hello de-Roo.Lukas, Check out the code sample below (C++ ). It should help you to get the coordinates you need. void updateHeight(ObjectTerrainPtr terrain, Vec3 player_position) { vec4 local_position = vec4(terrain->getIWorldTransform() * Vec4(player_position, 1.0f)); // checking if the player is above the terrain if (local_position.x > 0 && local_position.y > 0){ // calculating x,y coordinates of terrain point under the player and updating height value int x = ftoi(local_position.x / terrain->getStep()); int y = ftoi(local_position.y / terrain->getStep()); terrain->setHeight(x, y, 1.0f); } } To get current player's position you can use: Vec3 player_position = Game::get()->getPlayer()->getWorldPosition()); Thanks! Link to comment
de-Roo.Lukas Posted December 11, 2017 Author Share Posted December 11, 2017 Thanks, fox. It is helpful. Link to comment
de-Roo.Lukas Posted June 13, 2018 Author Share Posted June 13, 2018 Now I update to 2.7.1 there is no objectTerrain, if in Global Terrain how should I get current terrain height? Thanks Link to comment
fox Posted June 13, 2018 Share Posted June 13, 2018 Hi de-Roo.Lukas, Guess the ObjectTerrainGlobal::fetchTopologyData() method should help in your case. E.g, to get terrain height under the current player's position you can use the following code: double getTerrainHeightAt(ObjectTerrainGlobalPtr terrain, Vec3 player_position) { // auxiliary variables to store topology data Vec3 t_point; vec3 normal; vec3 up; // getting local position of the player vec4 local_position = vec4(terrain->getIWorldTransform() * Vec4(player_position, 1.0f)); // fetching topology data for the point that corresponds to player's position terrain->fetchTopologyData(local_position.x, local_position.y, t_point, normal, up, 1); // returning terrain height at player's position return t_point.z; } Current player's position is obtained the same way: Vec3 player_position = Game::get()->getPlayer()->getWorldPosition()); Thanks! Link to comment
Greg.Mildenhall Posted June 13, 2018 Share Posted June 13, 2018 6 hours ago, de-Roo.Lukas said: Now I update to 2.7.1 there is no objectTerrain Is this true??? Or is it being removed in 2.8 as scheduled? I couldn't find any reference to it in the change logs. We intend to port our terrain generator and various rendering modifications to TerrainGlobal on the final 2.7.x because 2.6 doesn't have the migration tools. But 2.7 sounds very buggy and we were planning to skip it. Link to comment
silent Posted June 13, 2018 Share Posted June 13, 2018 Hi Greg, ObjectTerrain is still there and will be removed in 2.8 as planned, don't worry :) 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
Recommended Posts