A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeFAQRegisterLog in
If you're a experienced coder make some tutorials! It would really help the site grow.
Make sure you read the rules(Which can be found by clicking here)
If you're a beginner at coding, try some tutorials.
We have many Moderators/Admins watching this site. Contact them with Questions.
Let us know what your favorite sport is. By clicking here to vote (Click here)
This site is becoming inactive. Lets make it active.
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
Top posters
blueymaddog
 
naknak
 
Supernapalm
 
m27frogy
 
slayer9365
 
myrco919
 
branefreez
 
ninga95
 
CloneTrooper787
 
raboy117
 
Top posting users this month
Latest topics
» Send me an Email
January 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 Possibly
July 6th 2015, 4:16 pm by m27frogy

» Ambassador!
April 15th 2015, 11:40 pm by naknak

» Boop - Tag
April 13th 2015, 9:46 pm by naknak

» Vip Class Script
April 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 Point
July 17th 2014, 7:04 pm by branefreez

» Reward System
July 17th 2014, 5:41 am by m27frogy

» Script Request
July 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 here
April 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
January 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
January 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 Coding
October 26th 2013, 1:12 pm by pook03

» Simple Button
September 1st 2013, 6:19 pm by branefreez


Share | 
 

 Terrain-Point Algorithm

View previous topic View next topic Go down 
AuthorMessage
MrNicNac
Expert Scripter
Expert Scripter
avatar

Posts : 25
Join date : 2011-03-06
Age : 21

PostSubject: Terrain-Point 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 = (b-a).x*(c-a).x + (b-a).y*(c-a).y + (b-a).z*(c-a).z
   return dot / (a-b).magnitude
end

function PerpD(a, b, c)
   local par = ParaD(a, b, c)
   return math.sqrt((c-a).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 = (A-B).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
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Terrain-Point Algorithm   March 6th 2011, 10:03 pm

I'm not sure. How would you make a triangle in the first place with pieces?
Back to top Go down
MrNicNac
Expert Scripter
Expert Scripter
avatar

Posts : 25
Join date : 2011-03-06
Age : 21

PostSubject: Re: Terrain-Point Algorithm   March 7th 2011, 8:05 am

I already have them made. There is a function in the code to do so.
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Terrain-Point Algorithm   March 7th 2011, 10:15 am

Great, now you made me want to go mess with the triangle.
Back to top Go down
MrNicNac
Expert Scripter
Expert Scripter
avatar

Posts : 25
Join date : 2011-03-06
Age : 21

PostSubject: Re: Terrain-Point 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.
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Terrain-Point Algorithm   March 7th 2011, 10:28 am

So, what your trying to do is make the triangle big enough to fill the drawn triangle?
Back to top Go down
MrNicNac
Expert Scripter
Expert Scripter
avatar

Posts : 25
Join date : 2011-03-06
Age : 21

PostSubject: Re: Terrain-Point 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.
Back to top Go down
naknak
Administrator
Administrator
avatar

Posts : 878
Join date : 2010-07-30

PostSubject: Re: Terrain-Point 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.
Back to top Go down
MrNicNac
Expert Scripter
Expert Scripter
avatar

Posts : 25
Join date : 2011-03-06
Age : 21

PostSubject: Re: Terrain-Point 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).
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Terrain-Point 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?>
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Terrain-Point 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?>
Back to top Go down
MrNicNac
Expert Scripter
Expert Scripter
avatar

Posts : 25
Join date : 2011-03-06
Age : 21

PostSubject: Re: Terrain-Point Algorithm   March 8th 2011, 8:17 am

Sorry, but that didn't make any sense at all.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Terrain-Point Algorithm   March 9th 2011, 6:21 am

every time you generate a point you make it generate at a random height in-between the lowest and highest points next to the point. make more sense?

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
Guest
Guest



PostSubject: Re: Terrain-Point 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 row-based rather than 2D-based, it isn't as good as it could be.
Back to top Go down
MrNicNac
Expert Scripter
Expert Scripter
avatar

Posts : 25
Join date : 2011-03-06
Age : 21

PostSubject: Re: Terrain-Point Algorithm   March 9th 2011, 7:40 pm

blueymaddog wrote:
every time you generate a point you make it generate at a random height in-between 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 Diamond-Square algorithm for random triangle-based terrain. I decided to ask the Scripters on Roblox. Interesting results are being turned up.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Terrain-Point Algorithm   March 10th 2011, 6:52 am

link to thread please, MNN?

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
MrNicNac
Expert Scripter
Expert Scripter
avatar

Posts : 25
Join date : 2011-03-06
Age : 21

PostSubject: Re: Terrain-Point Algorithm   March 10th 2011, 8:51 am

Here is the link.


Last edited by naknak on March 10th 2011, 11:30 pm; edited 1 time in total (Reason for editing : made it work.)
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Terrain-Point 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 'diamond-square' algorithm. :P

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
MrNicNac
Expert Scripter
Expert Scripter
avatar

Posts : 25
Join date : 2011-03-06
Age : 21

PostSubject: Re: Terrain-Point 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.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Terrain-Point 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?>
Back to top Go down
MrNicNac
Expert Scripter
Expert Scripter
avatar

Posts : 25
Join date : 2011-03-06
Age : 21

PostSubject: Re: Terrain-Point Algorithm   March 11th 2011, 6:29 pm

I already have a solution.
Back to top Go down
blueymaddog
Administrator
Administrator
avatar

Posts : 1081
Join date : 2010-12-09
Age : 18

PostSubject: Re: Terrain-Point Algorithm   March 14th 2011, 5:49 am

k.

_________________
blueymaddog
Administrator • Moderator • Expert Scripter
PM: blueymaddog
<+1 post. ujelly?>
Back to top Go down
Sponsored content




PostSubject: Re: Terrain-Point Algorithm   

Back to top Go down
 
Terrain-Point Algorithm
View previous topic View next topic Back to top 
Page 1 of 1
 Similar topics
-
» 1000 Point Grey Knights Army
» 2000 point skaven list
» Completed GW Terrain.... War of the Ring Scenario...
» 2000 or 2500 point Khorne Assult Army
» What is the current point norm? 1750, 1850, 2000?

Permissions in this forum:You cannot reply to topics in this forum
A Roblox Community :: Questions and Help :: Scripting-
Jump to: