I'm making the plane using the memblock to mesh function.
This is what I worked up:
From that I wrote:
// Create terrian polygons
triangles as Triangle3D[0]
// Needed parts
a as Vector3
b as Vector3
c as Vector3
tri as Triangle3D
// Top triangles
for row = 0 to array_grid.length - 1
offset = row + 1
for col = 0 to array_grid.length - 1
// -------------------------------------------------------
// Point A of Triangle
//--------------------
a.x = offset * terrian_spread
a.y = array_grid[offset, col + 1]
a.z = (col + 1) * terrian_spread
// -------------------------------------------------------
// -------------------------------------------------------
// Point B of Triangle
//--------------------
b.x = row * terrian_spread
b.y = array_grid[row, col + 1]
b.z = (col + 1) * terrian_spread
// -------------------------------------------------------
// -------------------------------------------------------
// Point C of Triangle
//--------------------
c.x = row * terrian_spread
c.y = array_grid[row, col]
c.z = col * terrian_spread
// -------------------------------------------------------
// Increase triangles for new triangle
triangles.length = triangles.length + 1
// Create new triangle
tri.a = a
tri.b = b
tri.c = c
// Add triangle
triangles[triangles.length - 1] = tri
next col
next row
// Bottom vertices
for col = 0 to array_grid.length - 1
offset = col + 1
for row = 0 to array_grid.length - 1
// -------------------------------------------------------
// Point A of Triangle
//--------------------
a.x = row * terrian_spread
a.y = array_grid[row, col]
a.z = col * terrian_spread
// -------------------------------------------------------
// -------------------------------------------------------
// Point B of Triangle
//--------------------
b.x = (row + 1) * terrian_spread
b.y = array_grid[row + 1, col]
b.z = col * terrian_spread
// -------------------------------------------------------
// -------------------------------------------------------
// Point C of Triangle
//--------------------
c.x = (row + 1) * terrian_spread
c.y = array_grid[row + 1, offset]
c.z = offset * terrian_spread
// -------------------------------------------------------
// Increase triangles for new triangle
triangles.length = triangles.length + 1
// Create new triangle
tri.a = a
tri.b = b
tri.c = c
// Add triangle
triangles[triangles.length - 1] = tri
next row
next col
Then with that array of Triangles3D, I do this:
// Colors
c_snow = 0xf7f7f7
c_mountain = 0xbba45d
c_light_grass = 0x88dd8f
c_dark_grass = 0x408746
c_dirt = 0x736336
// Allocate space for data
memblock = CreateMemblock(100000000)
// Set amount of vertices in mesh to be created
SetMemblockInt(memblock, 0, triangles.length * 3)
// All polygons
SetMemblockInt(memblock, 4, 0)
// All vertices have 3 attributes
// -- pos, normal, color
SetMemblockByte(memblock, 8, 3)
// Memory for each vertex
// -- (x,y,z nx,ny,nz color) * 4
SetMemblockByte(memblock, 12, 28)
// Offset of vertex data
SetMemblockInt(memblock, 16, 64)
// Indices offset - none, so 0
SetMemblockInt(memblock, 20, 0)
// Refer to online docs (NOT SURE WHAT THIS DOES)
SetMemBlockInt(memblock,24,0x0C000300)
SetMemblockString(memblock,28,"position")
SetMemblockInt(memblock,40,0x08000300)
SetMemblockString(memblock,44,"normal")
SetMemblockInt(memblock,52,0x08010401)
SetMemblockString(memblock,56,"color")
// Allocate color array
colors as integer[0]
// Color polygon based on height
for i = 0 to triangles.length - 1
// Get triangle points
tri_a as Vector3
tri_a = triangles[i].a
tri_b as Vector3
tri_b = triangles[i].b
tri_c as Vector3
tri_c = triangles[i].c
// Increase colors array by one
colors.length = colors.length + 1
// Set min to max
min = max_height
// Get lowest point on polygon
if tri_a.y < min
min = tri_a.y
endif
if tri_b.y < min
min = tri_b.y
endif
if tri_c.y < min
min = tri_c.y
endif
// Determine color for min polygon height
if min > max_height * 0.85
colors[colors.length - 1] = c_snow
elseif min > max_height * 0.75
colors[colors.length - 1] = c_mountain
elseif min > max_height * 0.35
colors[colors.length - 1] = c_light_grass
elseif min > max_height * 0.15
colors[colors.length - 1] = c_dark_grass
else
colors[colors.length - 1] = c_dirt
endif
next i
// Add all vertices to vertices array
offset = 0
offset_inc = 28 // 28 parts of each vertex
for i = 0 to triangles.length - 1
// Get triangle
tri as Triangle3D
tri = triangles[i]
// Get points on triangle
a as Vector3
a = tri.a
b as Vector3
b = tri.b
c as Vector3
c = tri.c
// Add vertex A
SetMemblockFloat(memblock, 64 + offset, a.x) // x
SetMemblockFloat(memblock, 68 + offset, a.y) // y
SetMemblockFloat(memblock, 72 + offset, a.z) // z
SetMemblockFloat(memblock, 76 + offset, 1) // nx ---- THESE VALUES I don't know how to get
SetMemblockFloat(memblock, 80 + offset, 1) // ny ---- THESE VALUES I don't know how to get
SetMemblockFloat(memblock, 84 + offset, 1) // nz ---- THESE VALUES I don't know how to get
SetMemblockInt(memblock, 88 + offset, colors[i]) // color
// Increase to next vertex position
offset = offset + offset_inc
// Add vertex B
SetMemblockFloat(memblock, 64 + offset, b.x) // x
SetMemblockFloat(memblock, 68 + offset, b.y) // y
SetMemblockFloat(memblock, 72 + offset, b.z) // z
SetMemblockFloat(memblock, 76 + offset, 1) // nx ---- THESE VALUES I don't know how to get
SetMemblockFloat(memblock, 80 + offset, 1) // ny ---- THESE VALUES I don't know how to get
SetMemblockFloat(memblock, 84 + offset, 1) // nz ---- THESE VALUES I don't know how to get
SetMemblockInt(memblock, 88 + offset, colors[i]) // color
// Increase to next vertex position
offset = offset + offset_inc
// Add vertex C
SetMemblockFloat(memblock, 64 + offset, c.x) // x
SetMemblockFloat(memblock, 68 + offset, c.y) // y
SetMemblockFloat(memblock, 72 + offset, c.z) // z
SetMemblockFloat(memblock, 76 + offset, 1) // nx ---- THESE VALUES I don't know how to get
SetMemblockFloat(memblock, 80 + offset, 1) // ny ---- THESE VALUES I don't know how to get
SetMemblockFloat(memblock, 84 + offset, 1) // nz ---- THESE VALUES I don't know how to get
SetMemblockInt(memblock, 88 + offset, colors[i]) // color
// Increase to next vertex position
offset = offset + offset_inc
next i
Any help on how to get those nx,ny,nz values? Or am I doing this all wrong? I just started apk two days ago and haven't been through all the guides and docs.
(Also that shader pack looks bad ass. I'm want to buy it. Does it work with AppGameKit Studio? I don't have "Classic" -- not sure what the difference is.