%% Coordinate Systems
%
% This example serves as a study of the coordinate systems supported by
% F3D Viewer.
%
% The set of Red, Green and Blue boxes are created along the X, Y, Z axes,
% their rotations gradually increasing.
%
% There are the following coordinate systems options:
%
% - 'matlab' (default)
% - 'unreal'
% - 'vrml'
% - 'lhcs'
% - 'aerospace'
%
% Uncomment the option you want to visualize.

%   Copyright 1998-2021 HUMUSOFT s.r.o.

%% Initialize the 3D Foundation object
FW = F3D.World(mfilename);
initialize(FW, [4 4 4]);

% Set the viewport properties
VP = FW.Viewports.Main;
VP.Title = mfilename;
Path = fileparts(which(mfilename));
setLogo(VP, fullfile(Path, 'data', 'MatlabLogo.png'));

Floor = F3D.Geometry.templateFloor(FW.Root, [10 10 0.1]);
Floor.Location(3) = -5;

% Uncomment the option you want to visualize:

FW.CoordinateSystem = 'matlab';
%FW.CoordinateSystem = 'unreal';
%FW.CoordinateSystem = 'vrml';
%FW.CoordinateSystem = 'lhcs';
%FW.CoordinateSystem = 'aerospace';

FW.AngleUnits = 'deg';

Frame = addChild(FW.Root, 'Frame');

N = 6;
for x = 1:N - 1
    Act = addChild(Frame);
    createShape(Act, 'box', [1 1 - x/N 1 - x/N]*0.5);
    Act.Color = [1 0 0];
    Act.Location = [x*0.5 0 0];
    Act.Rotation = [90*x/N 0 0];
end

for y = 1:N - 1
    Act = addChild(Frame);
    createShape(Act, 'box', [1 - y/N 1 1 - y/N]*0.5);
    Act.Color = [0 1 0];
    Act.Location = [0 y*0.5 0];
    Act.Rotation = [0 90*y/N 0];
end

for z = 1:N - 1
    Act = addChild(Frame);
    createShape(Act, 'box', [1 - z/N 1 - z/N 1]*0.5);
    Act.Color = [0 0 1];
    Act.Location = [0 0 z*0.5];
    Act.Rotation = [0 0 90*z/N];
end

Act = addChild(Frame);
createShape(Act, 'box', [0.6 0.6 0.6]);
Act.Color = [1 1 1];