% File: ExampleRay.m % % Compiler: Matlab 5.3 % % Author: Don Brutzman % % Origin: ExampleRay.java % % Revised: 12 May 99 % % Caveat: Matlab's Java interface may change % % Invocation: clear; cd c:\vrtp\mil\navy\nps\rra; pwd % (in Matlab) ExampleRay java on echo off clear; % ensure all previous java variables are gone ssp = java_object ('mil.navy.nps.rra.SSP', 'traditional'); bottom = java_object ('mil.navy.nps.rra.Bottom','slope', 2000); surface = java_object ('mil.navy.nps.rra.Surface','smooth'); ray = java_object ('mil.navy.nps.rra.Ray'); printVRML = java_object ('mil.navy.nps.rra.PrintVRML'); ray.setPosition( -1000, 50, 0); ray.setElevation(80); ray.setAzimuth(20); ray.setDeltaTime(.006); ray.setDuration(1); ray.setBottom(bottom); ray.setSurface(surface); ray.setSsp(ssp); reset(ray); % must pass an argument to use direct form ray.reset(); OutputVrmlString = strcat( ... java_method ('getSceneHeader', printVRML), ... 'Inline { url ["Header.wrl"] }', ... java_method ('getVRMLBottom', bottom), ... java_method ('getVRMLSurface', surface),... 'Transform {', ... ' rotation 1 0 0 3.14', ... ' children ', ... % trailing blank is dropped ' Shape {', ... % must have leading blank ' appearance Appearance {', ... ' material Material {', ... ' emissiveColor 1.0 0.0 0.0', ... ' diffuseColor 0.0 0.0 0.0', ... ' }', ... ' }', ... ' geometry IndexedLineSet {', ... ' coord Coordinate {', ... ' point [ ', ... '' ); k = 1; java_method ('recordPoint', ray); % Record first point always while (getTime(ray) < 8.0) % Propagate all rays through one time step ray.Propagate(.006); % If any ray has reflected then record all of the % points in the beam if (java_method ('reflected', ray)) java_method ('recordPoint', ray); k=k+1; end % if % If the curvature sum reaches the limit, % record all of the points in the beam if (java_method ('totalCurvature', ray) > .022 ) java_method ('recordPoint', ray); k=k+1; end % if end % while java_method ('recordPoint', ray); % Record last point always % Print the positions stored in each ray numberOfRays= double (java_method ('getCount', ray)) % class numberOfRays for k=1:numberOfRays OutputVrmlString = strcat( OutputVrmlString, ray.position(k)); end % for OutputVrmlString = strcat( OutputVrmlString, ... ' ]', ... ' }', ... ' coordIndex [' ); % Define the segments of the ray for k=1:numberOfRays OutputVrmlString = strcat( OutputVrmlString, int2str (k-1), ', ' ); end % for; OutputVrmlString = strcat( OutputVrmlString, ... '-1 ]', ... ' }', ... '}', ... '}' ); OutputVrmlString = strcat( OutputVrmlString, ... java_method ('getLegendViewpoint', printVRML, ... 'ExampleRay', ... 'This is an example ray.', ... 'It has an initial elevation', ... 'of 80 degrees from', ... 'vertical and 20 degrees', ... 'west of north.', ... -500, -500, 15000) ); % record stop time % Date timecheck2 = new Date(); % System.out.println( '# started ' + timecheck ); % System.out.println( '# finished ' + timecheck2 ); % return result: fileId = fopen ('ExampleRay.matlab.wrl', 'w'); fprintf (fileId, '%s', OutputVrmlString); fclose (fileId); % verify OutputVrmlString was saved to file, display results result = dir ('ExampleRay.Matlab.wrl'); if (isempty (result)) disp ('the file is empty! problem creating ExampleRay.Matlab.wrl'); else disp ('VRML file output results:'); disp (result); end; %echo on; clear; % Java classes from memory echo off;