Question about 3D terrain (was: Hellow everyone!!!)

Hellow ,I’m the new person to use codea,I have a problem ,how to make 3D terrain in codea ,please give me some idea or some help~~~~~~~~~~~~~ please :wink:

I mean I want to make a 3D game world ,so I need to make…for example mountain,lake,river,or something else…I really want to make and do then so can someone give me some idea or some examples ,please ~

How familiar are you with Codea? If you’re just starting out you might be better off trying something a little simpler: something like drawing some shapes that move when you touch them, and then maybe try making a 2D top-down game world with terrain, rivers and trees.

3D is possible (and you would do it with mesh) but it’s more involved.

@steelswing Tell us your coding experience. Obviously you’re new to Codea, but have you done any coding in any other languages. How we answer your questions would depend on your experience.

@Simeon @dave1707
Thank you to answer me ,I made a mistake,I’m not a new person of codea but is the “codea talk” ,befor I have tried some simple things, as you said @Simeon .but I haven’t done any coding in any other language,include haven’t learnt any other language

@steelswing You said you tried simple things. Have you tried doing anything with meshes, or anything with 3D. For 3D terrain, think of a very large checker board where you can raise or lower by different amounts where the squares meet each other to give the effect of hills or valleys. Each of the squares could have a different mesh texture or the whole board could be overlayed with one large mesh. Even after you create the terrain, then you have to write the code to move the camera around the terrain. It takes a lot of work and can be done kind of easy if you have the experience, but if you don’t it could be almost impossible even if you have examples. So my suggestion is to play with meshes and simple 3D code until you’re comfortable with it.

@dave1707 thanks for your suggestion , I haven’t done any things about 3D or mesh~~~~~~~~ so can you give me some course of study or teach me some about thatbecause the reference in codea is…hard to understand~ so,can you help me :slight_smile: ?

@steelswing See the personal message I sent you.

@steelswing Here’s a small example of a 3D terrain. This just shows a 3 by 3 array, and the pos slider lets you raise or lower one portion of the terrain. A real terrain would have a larger array and the high and low points would be calculated when the terrain is created. Also, I’m using a small single texture over and over, but multiple textures could be used to create different effects. A large single texture that contains a landscape could be used to cover the whole array.

function setup()
    parameter.integer("eyeX",-4000,4000,0)
    parameter.integer("eyeY",-100,900,600)
    parameter.integer("eyeZ",-4000,4000,2000)
    ground={}
    ss=200
    ss2=ss/2
    buf={}
    for x=-1,1 do
        for z=-1,1 do
            table.insert(ground,chunks(x*ss,0,z*ss))
        end
    end
    parameter.integer("pos",-400,200,-100,adjust)
end

function draw()   
    background(40, 40, 50)
    fill(255)
    perspective()
    camera(eyeX,eyeY,eyeZ, 0,0,0,0,1,0)
    for a,b in pairs(ground) do
        b:draw()
    end
end

chunks=class()

function chunks:init(x,y,z)
    v={ vec3(-ss2+x, -ss2+y, -ss2+z),   -- front left
        vec3( ss2+x, -ss2+y, -ss2+z),   -- front right 
        vec3( ss2+x, -ss2+y,  ss2+z),   -- back right    
        vec3(-ss2+x, -ss2+y,  ss2+z)    -- back left
      }
    t={ vec2(0,0),vec2(1,0),vec2(0,1),vec2(1,1) }
    self.ms=mesh()
    self.ms.vertices={ v[1],v[2],v[3],v[1],v[3],v[4] }
    self.ms.texCoords={ t[1],t[2],t[4],t[1],t[4],t[3] } 
    self.ms.texture="Platformer Art:Block Brick"
    table.insert(buf,self.ms:buffer("position"))
end

function chunks:draw()
    self.ms:draw()
end

function adjust()
    buf[1][3]=vec3(buf[1][3].x,pos,buf[1][3].z)
    buf[1][5]=vec3(buf[1][5].x,pos,buf[1][3].z)
    buf[2][2]=vec3(buf[2][2].x,pos,buf[2][2].z)
    buf[4][6]=vec3(buf[4][6].x,pos,buf[4][6].z)
    buf[5][1]=vec3(buf[5][1].x,pos,buf[5][1].z)
    buf[5][4]=vec3(buf[5][4].x,pos,buf[5][4].z)
end

@dave1707 thank you and thanks for your suggestion,I will learn more ,and try to make more things and getting better,thank you :slight_smile:

@steelswing I guess I didn’t ask what kind of 3D terrain you wanted to create. Was it a smooth landscape with slight hills and valleys, or a block landscape made up from a bunch of cubes. If it’s cubes, then it would be easier than the hills and valleys.

@dave1707 hello Dave ,my goal is to create a smooth landscape ,like you said ,mountain valleys…and so on,because that is for kind of RTS game ,but it is not very hurry, it is my final goal.

@steelswing do a forum search, I remember seeing the code for a 3D terrain with mountains and hills, etc. and I also remember seeing one called 3D fractal mountains

@CamelCoder oh~really?thank you ~

@CamelCoder excuse me ,where can I do the forum search?

@steelswing The upper right of the screen, just above New Discussion.

@dave1707 ok ,thank you

But…I can’t find anything…only a few websites???

@dave1707 and yesterday you asked me what kind of terrain I want to create …en~why do you want to ask me??? I mean en

@steelswing Just curious. The creation of a smooth terrain is different than a cube terrain.