Top posting users this month  
Latest topics  » Send me an EmailJanuary 8th 2016, 10:14 am by naknak» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]July 6th 2015, 7:38 pm by m27frogy» New Site PossiblyJuly 6th 2015, 4:16 pm by m27frogy» Ambassador!April 15th 2015, 11:40 pm by naknak» Boop  TagApril 13th 2015, 9:46 pm by naknak» Vip Class ScriptApril 13th 2015, 4:54 pm by naknak» Who's active?!April 13th 2015, 4:52 pm by naknak» Where to go from here.April 13th 2015, 4:51 pm by naknak» Genesis PointJuly 17th 2014, 7:04 pm by branefreez» Reward SystemJuly 17th 2014, 5:41 am by m27frogy» Script RequestJuly 10th 2014, 11:43 am by naknak» local scripts?July 10th 2014, 11:39 am by naknak» Project: Reconstruction [Died]July 10th 2014, 11:36 am by naknak» Hi. I am new hereApril 26th 2014, 4:01 pm by altshiftkey» What's your favorite sport?January 1st 2014, 2:13 pm by m27frogy» FlashLight ScriptJanuary 1st 2014, 2:11 pm by m27frogy» Gun Making! [READ DESC]January 1st 2014, 2:10 pm by m27frogy» Hi, I am new here!November 26th 2013, 3:33 pm by Keanu73» Improve CodingOctober 26th 2013, 1:12 pm by pook03» Simple ButtonSeptember 1st 2013, 6:19 pm by branefreez 
  TerrainPoint Algorithm  
 Author  Message 

MrNicNac Expert Scripter
Posts : 25 Join date : 20110306 Age : 22
 Subject: TerrainPoint Algorithm March 6th 2011, 5:28 pm  
 Using the function below, how could I find a decent way to generates points, so that when the triangles are draw (using the points as vertices), it would create some terrain?  Code:
local ply = Instance.new("WedgePart") ply.formFactor = "Custom" ply.TopSurface = 0 ply.BottomSurface = 0 ply.Anchored = true ply.Size = Vector3.new(0.2,7,7)
local msh = Instance.new("SpecialMesh") msh.MeshType = 2 msh.Parent = ply
function ParaD(a, b, c) local dot = (ba).x*(ca).x + (ba).y*(ca).y + (ba).z*(ca).z return dot / (ab).magnitude end
function PerpD(a, b, c) local par = ParaD(a, b, c) return math.sqrt((ca).magnitude^2  par^2) end
local _P0, _P1 = nil, nil
function DrawTriangle(vec1, vec2, vec3) local A, B, C = nil, nil, nil local p0, p1 = ply:clone(), ply:clone() _P0 = p0 _P1 = p1 local s1 = (vec1  vec2).magnitude s2 = (vec2  vec3).magnitude s3 = (vec3  vec1).magnitude local smax = math.max(s1, s2, s3) if (vec1  vec2).magnitude == smax then A = vec1 B = vec2 C = vec3 elseif (vec2  vec3).magnitude == smax then A = vec2 B = vec3 C = vec1 elseif (vec3  vec1).magnitude == smax then A = vec3 B = vec1 C = vec2 end local perp = PerpD(A, B, C) local para = ParaD(A, B, C) local dif_para = (AB).magnitude  para local ambig = false p0.Mesh.Scale = Vector3.new(0.1, 1,1) p0.Size = Vector3.new(.2, perp, para) p0.CFrame = CFrame.new(B, A) local Top_Look = (p0.CFrame * CFrame.fromEulerAnglesXYZ(math.pi/2, 0, 0)).lookVector local Mid_Point = A + CFrame.new(A, B).lookVector * para local Needed_Look = CFrame.new(Mid_Point, C).lookVector local dot = Top_Look.x*Needed_Look.x + Top_Look.y*Needed_Look.y + Top_Look.z*Needed_Look.z p0.CFrame = p0.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, math.acos(dot)) if ((p0.CFrame * CFrame.fromEulerAnglesXYZ(math.pi/2, 0, 0)).lookVector  Needed_Look).magnitude > 0.01 then p0.CFrame = p0.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, 2*math.acos(dot)) ambig = true end p0.CFrame = p0.CFrame * CFrame.new(0, perp/2, (dif_para + para/2)) p0.Parent = tmodel p0.Name = "P0" p1.Mesh.Scale = Vector3.new(0, 1,1) p1.Size = Vector3.new(.2, perp, dif_para) p1.CFrame = CFrame.new(B, A) * CFrame.fromEulerAnglesXYZ(0, 0, math.acos(dot)) * CFrame.fromEulerAnglesXYZ(0, math.pi, 0) if ((p1.CFrame * CFrame.fromEulerAnglesXYZ(math.pi/2, 0, 0)).lookVector  Needed_Look).magnitude > 0.01 then p1.CFrame = p1.CFrame * CFrame.fromEulerAnglesXYZ(0, 0, 2*math.acos(dot)) ambig = true end p1.CFrame = p1.CFrame * CFrame.new(0, perp/2, dif_para/2) p1.Parent = tmodel p1.Name = "P1" p0.Mesh.Scale = p0.Mesh.Scale * 0.145714286 p1.Mesh.Scale = p1.Mesh.Scale * 0.145714286 end
Last edited by MrNicNac on March 7th 2011, 9:59 pm; edited 1 time in total 
   naknak Administrator
Posts : 878 Join date : 20100730
 Subject: Re: TerrainPoint Algorithm March 6th 2011, 10:03 pm  
 I'm not sure. How would you make a triangle in the first place with pieces? 
   MrNicNac Expert Scripter
Posts : 25 Join date : 20110306 Age : 22
 Subject: Re: TerrainPoint Algorithm March 7th 2011, 8:05 am  
 I already have them made. There is a function in the code to do so. 
   naknak Administrator
Posts : 878 Join date : 20100730
 Subject: Re: TerrainPoint Algorithm March 7th 2011, 10:15 am  
 Great, now you made me want to go mess with the triangle. 
   MrNicNac Expert Scripter
Posts : 25 Join date : 20110306 Age : 22
 Subject: Re: TerrainPoint Algorithm March 7th 2011, 10:25 am  
 It's quite entertaining, I've made a tool and a place that uses them together to build while online. 
   naknak Administrator
Posts : 878 Join date : 20100730
 Subject: Re: TerrainPoint Algorithm March 7th 2011, 10:28 am  
 So, what your trying to do is make the triangle big enough to fill the drawn triangle? 
   MrNicNac Expert Scripter
Posts : 25 Join date : 20110306 Age : 22
 Subject: Re: TerrainPoint Algorithm March 7th 2011, 10:29 am  
 No no, that is all done. I just want to generate points so I can draw the triangles to look like mountains or something. 
   naknak Administrator
Posts : 878 Join date : 20100730
 Subject: Re: TerrainPoint Algorithm March 7th 2011, 10:32 am  
 I know somebody made something like that, just I don't think it was with triangles and it was just a randomized terrain. 
   MrNicNac Expert Scripter
Posts : 25 Join date : 20110306 Age : 22
 Subject: Re: TerrainPoint Algorithm March 7th 2011, 7:41 pm  
 A lot of people made random terrain, xLEGOx did a random terrain with triangles (the main way to make decent terrain). 
   blueymaddog Administrator
Posts : 1081 Join date : 20101209 Age : 19
 Subject: Re: TerrainPoint Algorithm March 8th 2011, 6:37 am  
 maybe have the points generate randomly as long as it's within a certain height to the lowest and highest points adjacent to the point. _________________ blueymaddog Administrator • Moderator • Expert Scripter PM: blueymaddog<+1 post. ujelly?> 
   blueymaddog Administrator
Posts : 1081 Join date : 20101209 Age : 19
 Subject: Re: TerrainPoint Algorithm March 8th 2011, 6:39 am  
 I was thinking of making one of these map generators myself! _________________ blueymaddog Administrator • Moderator • Expert Scripter PM: blueymaddog<+1 post. ujelly?> 
   MrNicNac Expert Scripter
Posts : 25 Join date : 20110306 Age : 22
 Subject: Re: TerrainPoint Algorithm March 8th 2011, 8:17 am  
 Sorry, but that didn't make any sense at all. 
   blueymaddog Administrator
Posts : 1081 Join date : 20101209 Age : 19
 Subject: Re: TerrainPoint Algorithm March 9th 2011, 6:21 am  
 every time you generate a point you make it generate at a random height inbetween the lowest and highest points next to the point. make more sense? _________________ blueymaddog Administrator • Moderator • Expert Scripter PM: blueymaddog<+1 post. ujelly?> 
   Guest Guest
 Subject: Re: TerrainPoint Algorithm March 9th 2011, 12:24 pm  
 Yeah Blue's way is rather efficient. I use it in my terrain generator, although since mine is rowbased rather than 2Dbased, it isn't as good as it could be. 
   MrNicNac Expert Scripter
Posts : 25 Join date : 20110306 Age : 22
 Subject: Re: TerrainPoint Algorithm March 9th 2011, 7:40 pm  
  blueymaddog wrote:
 every time you generate a point you make it generate at a random height inbetween the lowest and highest points next to the point. make more sense?
You obviously don't understand an algorithm that should be used here. I figured it should be the DiamondSquare algorithm for random trianglebased terrain. I decided to ask the Scripters on Roblox. Interesting results are being turned up. 
   blueymaddog Administrator
Posts : 1081 Join date : 20101209 Age : 19
 Subject: Re: TerrainPoint Algorithm March 10th 2011, 6:52 am  
 link to thread please, MNN? _________________ blueymaddog Administrator • Moderator • Expert Scripter PM: blueymaddog<+1 post. ujelly?> 
   MrNicNac Expert Scripter
Posts : 25 Join date : 20110306 Age : 22
 Subject: Re: TerrainPoint Algorithm March 10th 2011, 8:51 am  

Last edited by naknak on March 10th 2011, 11:30 pm; edited 1 time in total (Reason for editing : made it work.) 
   blueymaddog Administrator
Posts : 1081 Join date : 20101209 Age : 19
 Subject: Re: TerrainPoint Algorithm March 11th 2011, 6:39 am  
 lol, so your asking me how you should generate the points on the terrain generater and I give my suggestion. then you say that you should use the 'diamondsquare' algorithm. :P _________________ blueymaddog Administrator • Moderator • Expert Scripter PM: blueymaddog<+1 post. ujelly?> 
   MrNicNac Expert Scripter
Posts : 25 Join date : 20110306 Age : 22
 Subject: Re: TerrainPoint Algorithm March 11th 2011, 8:03 am  
 An algorithm is a solution, your "algorithim" was no where near a solution to keep the terrain smooth and actually look like terrain. 
   blueymaddog Administrator
Posts : 1081 Join date : 20101209 Age : 19
 Subject: Re: TerrainPoint Algorithm March 11th 2011, 5:38 pm  
 then get the average of all the point's positions and make it randomize roughly around the average. :P _________________ blueymaddog Administrator • Moderator • Expert Scripter PM: blueymaddog<+1 post. ujelly?> 
   MrNicNac Expert Scripter
Posts : 25 Join date : 20110306 Age : 22
 Subject: Re: TerrainPoint Algorithm March 11th 2011, 6:29 pm  
 I already have a solution. 
   blueymaddog Administrator
Posts : 1081 Join date : 20101209 Age : 19
 Subject: Re: TerrainPoint Algorithm March 14th 2011, 5:49 am  
 k. _________________ blueymaddog Administrator • Moderator • Expert Scripter PM: blueymaddog<+1 post. ujelly?> 
   Sponsored content
 Subject: Re: TerrainPoint Algorithm  
 
    TerrainPoint Algorithm  

 Permissions in this forum:  You cannot reply to topics in this forum
 
 
 Who is online?  In total there is 1 user online :: 0 Registered, 0 Hidden and 1 Guest
None
Most users ever online was 54 on August 2nd 2017, 2:13 am

 Please tell us what time zone you are in here
Got a really good idea? Post it in projects and it might show up here! 
