Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Draw Mesh

edited March 2016 in Questions Posts: 75

This Code lets you go forward and back through swiping up and down when I go to the top block i want it to create a new path mesh in front of it I do not know how to do this. To Sum up I want it to do another path:draw() but I want it to stay and when I go on top of that another one should draw here is the code.

-- Cube
--Ambient
if localise then localise(1,"Ambient") end
function setup()
    displayMode(FULLSCREEN)
    cube = mesh()
    path = mesh()

    --vertices for the corners of the cube (stolen from 3d lab)
    local vertices = {
    vec3(-0.5, -0.5,  0.5), -- Left  bottom front
    vec3( 0.5, -0.5,  0.5), -- Right bottom front
    vec3( 0.5,  0.5,  0.5), -- Right top    front
    vec3(-0.5,  0.5,  0.5), -- Left  top    front
    vec3(-0.5, -0.5, -0.5), -- Left  bottom back
    vec3( 0.5, -0.5, -0.5), -- Right bottom back
    vec3( 0.5,  0.5, -0.5), -- Right top    back
    vec3(-0.5,  0.5, -0.5), -- Left  top    back
    }

    -- now construct a cube out of the vertices above
    path.vertices = {
    -- Front
    vertices[1], vertices[2], vertices[3],
    vertices[1], vertices[3], vertices[4],
    -- Right
    vertices[2], vertices[6], vertices[7],
    vertices[2], vertices[7], vertices[3],
    -- Back
    vertices[6], vertices[5], vertices[8],
    vertices[6], vertices[8], vertices[7],
    -- Left
    vertices[5], vertices[1], vertices[4],
    vertices[5], vertices[4], vertices[8],
    -- Top
    vertices[4], vertices[3], vertices[7],
    vertices[4], vertices[7], vertices[8],
    -- Bottom
    vertices[5], vertices[6], vertices[2],
    vertices[5], vertices[2], vertices[1],
    }
    cube.vertices = {
    -- Front
    vertices[1], vertices[2], vertices[3],
    vertices[1], vertices[3], vertices[4],
    -- Right
    vertices[2], vertices[6], vertices[7],
    vertices[2], vertices[7], vertices[3],
    -- Back
    vertices[6], vertices[5], vertices[8],
    vertices[6], vertices[8], vertices[7],
    -- Left
    vertices[5], vertices[1], vertices[4],
    vertices[5], vertices[4], vertices[8],
    -- Top
    vertices[4], vertices[3], vertices[7],
    vertices[4], vertices[7], vertices[8],
    -- Bottom
    vertices[5], vertices[6], vertices[2],
    vertices[5], vertices[2], vertices[1],
    }

    --now texture it
    -- all the unique texture positions needed
    local texvertices = { vec2(0,0),
    vec2(1,0),
    vec2(0,1),
    vec2(1,1) }

    -- apply the texture coordinates to each triangle
    cube.texCoords = {
    -- Front
    texvertices[1], texvertices[2], texvertices[4],
    texvertices[1], texvertices[4], texvertices[3],
    -- Right
    texvertices[1], texvertices[2], texvertices[4],
    texvertices[1], texvertices[4], texvertices[3],
    -- Back
    texvertices[1], texvertices[2], texvertices[4],
    texvertices[1], texvertices[4], texvertices[3],
    -- Left
    texvertices[1], texvertices[2], texvertices[4],
    texvertices[1], texvertices[4], texvertices[3],
    -- Top
    texvertices[1], texvertices[2], texvertices[4],
    texvertices[1], texvertices[4], texvertices[3],
    -- Bottom
    texvertices[1], texvertices[2], texvertices[4],
    texvertices[1], texvertices[4], texvertices[3],
    }
    path.texCoords = {
    -- Front
    texvertices[1], texvertices[2], texvertices[4],
    texvertices[1], texvertices[4], texvertices[3],
    -- Right
    texvertices[1], texvertices[2], texvertices[4],
    texvertices[1], texvertices[4], texvertices[3],
    -- Back
    texvertices[1], texvertices[2], texvertices[4],
    texvertices[1], texvertices[4], texvertices[3],
    -- Left
    texvertices[1], texvertices[2], texvertices[4],
    texvertices[1], texvertices[4], texvertices[3],
    -- Top
    texvertices[1], texvertices[2], texvertices[4],
    texvertices[1], texvertices[4], texvertices[3],
    -- Bottom
    texvertices[1], texvertices[2], texvertices[4],
    texvertices[1], texvertices[4], texvertices[3],
    }
    cube.texture = "Planet Cute:Plain Block"
    path.texture = "Documents:Path"
    sprite("Documents:Path")
    currentModelMatrix = modelMatrix()
    cube.shader=shader(ambientShader.vertexShader,ambientShader.fragmentShader)
    path.shader=shader(ambientShader.vertexShader,ambientShader.fragmentShader)
    SurfaceColour = color(255,255,255)
    AmbientColour = color(244, 244, 244, 255)
    AmbientColtwo = color(0, 203, 255, 255)
    parameter.number("Strength",0,1,1)
    parameter.watch("Surface Colour = 255 and Ambient = 255")
    x = 0
    y = 1
    z = 0
    pathx = 0
    pathy = 0
    pathz = 0
    parameter.number("pos",1,100,1)
    newpathX = 0
    newpathZ = pathz + 1
    newpath()
    swipex,swipey = 0
    timeset = 0
    pathztwo = pathz - 1
    direction = nil
end
function newpath()

end
function fall()
    y = y - 0.1
end
function leftright()

end
function draw()
    newpathZ  = pathz + 1
    pathztwo = pathz - 1
    timeset = timeset - 1
    if x == pathx and y == pathy + 1 and z == pathz or z == newpathZ and y == pathy + 1 and x == pathx then
        if z == pathz + 1 and y == pathy + 1 and x == pathx then

        end
    else
        fall()
    end
    spriteBatching(false)
    background(40, 40, 50)
    camera(-1,10,-5,0,0,0)
    perspective()
    modelMatrix(currentModelMatrix)
    smooth()
    --do rotation for touch
    if CurrentTouch.state == MOVING then
        currentModelMatrix = modelMatrix()
        swipex = CurrentTouch.deltaX
        swipey = CurrentTouch.deltaY
    else
        swipex = 0
        swipey = 0
    end
    if timeset <= 0 then
        if swipex > 30 then
            x = x - 1
            timeset = 15
        end
        if swipex < -30 then
            x = x + 1
            timeset = 15
        end
        if swipey > 30 then
            z = z + 1
            timeset = 15
        end
        if swipey < -30 then
            z = z - 1
            timeset = 15
        end
    end
    cube:setColors(SurfaceColour)
    path:setColors(SurfaceColour)
    --now combine the ambient colour and strength to reduce work for the shader
    --I'm setting the ambient colour here, because you can change it with parameters
    --I'll move it up into setup when I take those parameters away and the ambient settings become fixed
    cube.shader.ambientLight = color(AmbientColour.r*Strength,AmbientColour.g*Strength,AmbientColour.b*Strength)
    path.shader.ambientLight = color(AmbientColtwo.r*Strength,AmbientColtwo.g*Strength,AmbientColtwo.b*Strength)
    translate(pathx,pathy,pathz)
    path:draw()
    popMatrix()
    translate(pathx,pathy,pathz - 1)
    path:draw(a)
    popMatrix()
    translate(0,0,0)
    translate(x,y,z)
    scale(0.5)
    cube:draw()
    popMatrix()
end
function touched(t)

end
ambientShader = {

vertexShader = [[                      //-- This is a standard vertex shader, nothing added

uniform mat4 modelViewProjection;

attribute vec4 position;
attribute vec4 color;
attribute vec2 texCoord;

varying lowp vec4 vColor;
varying highp vec2 vTexCoord;

void main()
{
vColor = color;
vTexCoord = texCoord;
gl_Position = modelViewProjection * position;
}

]],

fragmentShader = [[

precision highp float;

uniform vec4 ambientLight; // --ambient light colour

varying lowp vec4 vColor;
varying highp vec2 vTexCoord;

void main()
{
vec4 pixel = vColor;  //--get colour of this pixel
//--note - we are ignoring textures for now
//--but when we do include them, we will set pixel based on texture lookup instead
gl_FragColor= pixel * ambientLight; //--apply ambient light
}

]]
}

The Last Bit is some OpenGL
And there is @Ignatz Ambient Shader

Tagged:

Comments

  • Posts: 75

    The textures can be replaced with any texture as it is over written by the shader

  • Posts: 75

    How do I delete this I figured it out

  • dave1707dave1707 Mod
    Posts: 7,559

    Only a Mod can delete it. We don't normally delete discussions because we don't know if someone else can use something from it.

Sign In or Register to comment.