About the terrain bump

Typically: "How do I... ", "How can I... " questions
Post Reply
yifanzhou
Posts: 4
Joined: 03 Jun 2020, 06:17

About the terrain bump

Post by yifanzhou »

Hello,

I am using the model ——terrain bump.ttm. Is it possible to get the position information about the edge point of the terrain bump? As I show in the figure below.

Image

coppelia
Site Admin
Posts: 8450
Joined: 14 Dec 2012, 00:25

Re: About the terrain bump

Post by coppelia »

Hello,

the data is generated in a generic manner, so you will have to identify where it is generated. In that attached customization script, near the end, you have the generation of the height field. You can modify the code to something like following, in order to visualize the individual points:

Code: Select all

    local points={}
    local xSize=dxs
    local ySize=yt*dxs/xt
    local dx=xSize/xt
    local dy=ySize/yt
    for y=1,yt,1 do
        for x=1,xt,1 do
            xp=(x-xt/2)/(xt/2)
            yp=(y-yt/2)/(yt/2)
            r=dps*math.sqrt(t1*xp*xp+t2*yp*yp)
            nh=dzs/((r*r)+1)
            if (nh<minw) then minw=nh end
            if (nh>maxw) then maxw=nh end
            table.insert(heights,nh)
            local pos={-xSize*0.5+(x-1)*dx,-ySize*0.5+(y-1)*dy,nh}
            points[#points+1]=pos
        end
    end
    bumpShape=sim.createHeightfieldShape(options,0,xt,yt,dxs,heights)

    local c=sim.addDrawingObject(sim.drawing_spherepoints,0.02,0,-1,4)
    
    sim.setObjectName(bumpShape,objName)
    sim.setObjectProperty(bumpShape,objProperty)
    sim.setObjectSpecialProperty(bumpShape,objSpecialProperty)
    sim.setObjectParent(bumpShape,h,true)
    scaling=(maxw-minw)/(maxv-minv)
    matr[12]=matr[12]*scaling
    local oldM=sim.getObjectMatrix(bumpShape,-1)
    sim.setObjectMatrix(bumpShape,sim.handle_parent,matr)
    local newM=sim.getObjectMatrix(bumpShape,-1)
    if config.textured then
        sim.setShapeTexture(bumpShape,bumpTextureId,sim.texturemap_plane,4+8,{1,1})
        sim.setShapeColor(bumpShape,'',0,{1,1,1})
    else
        sim.setShapeColor(bumpShape,'',sim.colorcomponent_ambient_diffuse,config.color)
    end
    local drawingcontainer=sim.addDrawingObject(sim.drawing_spherepoints,0.002,0,-1,99999)

    sim.invertMatrix(oldM)
    local m=sim.multiplyMatrices(oldM,newM)
    for i=1,#points,1 do
        local p=sim.multiplyVector(m,points[i])
        sim.addDrawingObjectItem(drawingcontainer,p)
    end
In the above loop, the corner points are generated when y==1 or y==yt and x==1 or x==xt.

Cheers

Post Reply