image thumbnail

Virtual Reality Terrain Modeling

by

 

09 Jun 2004 (Updated )

Use actual terrain data within Virtual Reality Toolbox.

create_terrain_node.m
% CREATE_TERRAIN_NODE
%

% Read in DEMS data
[lat,lon,map,A,B] = usgs24kdem('./dems/Grand Canyon/GRANDCAN.dem',5);

demdata = map(3:end-5,2:end-1);
[xdim zdim] = size(demdata);
xspace = 10;
zspace = 10;
demdata = demdata(:);

% Make sure all vr worlds are closed and deleted
out=vrwho;
for i=1:length(out)
    while (get(out(i),'opencount')~=0)
        close(out(i));
    end
    delete(out(i));
end

myworld = vrworld('vrterraintemplate.wrl'); % bring up template
open(myworld);
nodes(myworld);
VR_h = vrnode(myworld,'VRcoor');

shapeName = ['landscape'];
appearName = ['ElevApp'];

newShape = vrnode(VR_h, 'children', shapeName, 'Shape');
newAppear = vrnode(newShape, 'appearance', appearName,'Appearance');
newMat = vrnode(newAppear, 'material', 'land_material','Material');
setfield(newMat, 'ambientIntensity', [0.25],...
				'diffuseColor',	[0.9 0.6 0.6],...
				'shininess',	[0.078125],...
				'specularColor', [0.0955906 0.0955906 0.0955906]);
newEGrid = vrnode(newShape, 'geometry', 'dem','ElevationGrid');
setfield(newEGrid, 'creaseAngle',3.14, ...
    'xDimension',xdim,...
    'zDimension',zdim,...
    'xSpacing',xspace,...
    'zSpacing',zspace,...
    'height',demdata);

%
% Save the created world to a new WRL file
%
save (myworld, 'terrain.wrl')

close(myworld)
delete(myworld)

Contact us