(Added GetNormal) |
(Added GetSlope, GetContour) |
||
Line 4: | Line 4: | ||
{{ScriptFunction|float|GetHeight|(float x, float y)|Gets the height at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively (if the terrain's bottom left corner is at the origin). |5= | {{ScriptFunction|float|GetHeight|(float x, float y)|Gets the height at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively (if the terrain's bottom left corner is at the origin). |5= | ||
− | ''-- In this example, we are going to calculate the height of the 512x512 terrain at a global point (206, 198).''<br> | + | ''-- In this example, we are going to calculate the height of the 512x512 terrain at a global point (x = 206, z = 198).''<br> |
''-- 1 Object Reference to the Terrain object, Name: "terrain".''<br><br> | ''-- 1 Object Reference to the Terrain object, Name: "terrain".''<br><br> | ||
local terrain = Space.Host.GetReference("terrain");<br><br> | local terrain = Space.Host.GetReference("terrain");<br><br> | ||
Space.Log(terrain.Terrain.GetHeight (206/512,198/512)); | Space.Log(terrain.Terrain.GetHeight (206/512,198/512)); | ||
− | ''-- prints the height of the terrain at the global point (206,198) to the console.''}} | + | ''-- prints the height of the terrain at the global point (x = 206, z = 198) to the console.''}} |
{{ScriptFunction|float|GetSteepness|(float x, float y)|Gets the steepness at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively. |5= | {{ScriptFunction|float|GetSteepness|(float x, float y)|Gets the steepness at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively. |5= | ||
− | ''-- In this example, we are going to calculate the steepness of the | + | ''-- In this example, we are going to calculate the steepness of the 1024x1024 terrain at a global point (x = 408, z = 63).''<br> |
''-- 1 Object Reference to the Terrain object, Name: "terrain".''<br><br> | ''-- 1 Object Reference to the Terrain object, Name: "terrain".''<br><br> | ||
local terrain = Space.Host.GetReference("terrain");<br><br> | local terrain = Space.Host.GetReference("terrain");<br><br> | ||
− | Space.Log(terrain.Terrain.GetSteepness (408/ | + | Space.Log(terrain.Terrain.GetSteepness (408/1024,63/1024));<br> |
− | ''-- prints the steepness of the terrain at the global point (408,63) to the console.''}} | + | ''-- prints the steepness of the terrain at the global point (x = 408, z = 63) to the console.''}} |
{{ScriptFunction|SVector|GetNormal|(float x, float y)|Gets the normal vector (perpendicular to the surface) at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively. |5= | {{ScriptFunction|SVector|GetNormal|(float x, float y)|Gets the normal vector (perpendicular to the surface) at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively. |5= | ||
− | ''-- In this example, we are going to | + | ''-- In this example, we are going to find the normal vector of the 512x256 terrain at a global point (x = 172, z = 428).''<br> |
''-- 1 Object Reference to the Terrain object, Name: "terrain".''<br><br> | ''-- 1 Object Reference to the Terrain object, Name: "terrain".''<br><br> | ||
− | local terrain = Space.Host.GetReference("terrain"); | + | local terrain = Space.Host.GetReference("terrain");<br><br> |
− | Space.Log(terrain.Terrain.GetNormal(172/512,428/ | + | Space.Log(terrain.Terrain.GetNormal(172/512,428/256)); <br> |
− | ''-- prints x,y,z values of the normal vector at the global point (172,428) to the console.''}} | + | ''-- prints x,y,z values of the normal vector at the global point (x = 172, z = 428) to the console.''}} |
+ | |||
+ | {{ScriptFunction|SVector|GetSlope|(float x, float y)|Gets the slope vector at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively.|5= | ||
+ | ''-- In this example, we are going to find the slope vector of the 1024x512 terrain at a global point (x = 256, z = 256).''<br> | ||
+ | ''-- 1 Object Reference to the Terrain object, Name: "terrain".''<br><br> | ||
+ | local terrain = Space.Host.GetReference("terrain");<br><br> | ||
+ | Space.Log(terrain.Terrain.GetSlope(256/1024,256/512)); <br> | ||
+ | ''-- prints x,y,z values of the slope vector at the global point (x = 256, z = 256) to the console.''}} | ||
+ | |||
+ | {{ScriptFunction|SVector|GetContour|(float x, float y)|Gets the contour of the surface, expressed as a vector, at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively.|5= | ||
+ | ''-- In this example, we are going to find the slope vector of the 512x512 terrain at a global point (x = 128, z = 128).''<br> | ||
+ | ''-- 1 Object Reference to the Terrain object, Name: "terrain".''<br><br> | ||
+ | local terrain = Space.Host.GetReference("terrain");<br><br> | ||
+ | Space.Log(terrain.Terrain.GetContour(128/512,128/512));<br> | ||
+ | ''-- prints x,y,z values of the contour direction at the global point (x = 128, z = 128) to the console.''<br> | ||
+ | ''-- The z value is going to be 0, because contours are two-dimensional.''}} | ||
{{Scripting Navbox}} | {{Scripting Navbox}} |
The STerrain class allows the script to work with the terrain-related data.
Gets the height at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively (if the terrain's bottom left corner is at the origin).
-- 1 Object Reference to the Terrain object, Name: "terrain".
local terrain = Space.Host.GetReference("terrain");
Space.Log(terrain.Terrain.GetHeight (206/512,198/512));
Gets the steepness at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively.
-- 1 Object Reference to the Terrain object, Name: "terrain".
local terrain = Space.Host.GetReference("terrain");
Space.Log(terrain.Terrain.GetSteepness (408/1024,63/1024));
Gets the normal vector (perpendicular to the surface) at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively.
-- 1 Object Reference to the Terrain object, Name: "terrain".
local terrain = Space.Host.GetReference("terrain");
Space.Log(terrain.Terrain.GetNormal(172/512,428/256));
Gets the slope vector at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively.
-- 1 Object Reference to the Terrain object, Name: "terrain".
local terrain = Space.Host.GetReference("terrain");
Space.Log(terrain.Terrain.GetSlope(256/1024,256/512));
Gets the contour of the surface, expressed as a vector, at the (x,y) point. Floats x,y are given within the range from 0 to 1. If we want this script to work with global x, z coordinates, we need to divide their values by the width/length of the terrain respectively.
-- 1 Object Reference to the Terrain object, Name: "terrain".
local terrain = Space.Host.GetReference("terrain");
Space.Log(terrain.Terrain.GetContour(128/512,128/512));
-- prints x,y,z values of the contour direction at the global point (x = 128, z = 128) to the console.
|