This file is indexed.

/usr/share/psychtoolbox-3/PsychDemos/OpenGL4MatlabDemos/SpinningMovieCube.m is in psychtoolbox-3-common 3.0.11.20131230.dfsg1-1build1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
function SpinningMovieCube(moviename)
% SpinningMovieCubeDemo - Demonstrate use of MATLAB-OpenGL toolbox
%
% This demo demonstrates use of OpenGL commands in a Matlab script together
% with the movie playback functions of PTB. It shows a randomly
% spinning, three dimensional textured cube. The six sides of the cube
% show a quicktime video, loaded and played from a quicktime movie file.
%
% Stop the demo any time by pressing any key.
%
% Notable implementation details:
%
% The implementation is nearly identical as SpinningCubeDemo, so make sure
% you understand that file first.
%
% This demo uses the Screen('GetOpenGLTexture') function to make a
% Psychtoolbox texture  (loaded from the movie) available to
% OpenGL for 3D texture mapping.
%
% It opens a movie file and then - in a loop - fetches video images frame
% by frame. The images which are stored as Psychtoolbox textures are then
% made available as standard OpenGL textures for drawing onto the sides of
% the spinning cube.
%

% 15-Dec-2005 -- created (RFM)
% 21-Jan-2006 -- Modified for use with OpenGL-Psychtoolbox (MK)
% 16-Feb-2006 -- Modified for use with new MOGL (MK)
% 05-Mar-2006 -- Cleaned up for public consumption (MK)
% 23-Aug-2012 -- Adapt to PTB 3.0.10 file structure, cleanup. (MK)
% 06-Apr-2013 -- Make compatible with OpenGL-ES1.1. (MK)

% Assign default movie file, if none provided:
if nargin < 1
    moviename= [ PsychtoolboxRoot 'PsychDemos/MovieDemos/DualDiscs.mov' ];   
end;
moviename %#ok<NOPRT>

% Is the script running in OpenGL Psychtoolbox?
AssertOpenGL;

% Find the screen to use for display:
screenid=max(Screen('Screens'));

% Setup Psychtoolbox for OpenGL 3D rendering support and initialize the
% mogl OpenGL for Matlab wrapper:
InitializeMatlabOpenGL(1);

% Open a double-buffered full-screen window on the main displays screen.
[win , winRect] = Screen('OpenWindow', screenid);

% Open movie file, get a handle to the movie and start playback:
movie=Screen('OpenMovie', win, moviename);
Screen('PlayMovie', movie, 1, 1, 1);

% Setup the OpenGL rendering context of the onscreen window for use by
% OpenGL wrapper. After this command, all following OpenGL commands will
% draw into the onscreen window 'win':
Screen('BeginOpenGL', win);

% Get the aspect ratio of the screen:
ar=winRect(4)/winRect(3);

% Turn on OpenGL local lighting model: The lighting model supported by
% OpenGL is a local Phong model with Gouraud shading.
glEnable(GL_LIGHTING);

% Enable the first local light source GL_LIGHT_0. Each OpenGL
% implementation is guaranteed to support at least 8 light sources. 
glEnable(GL_LIGHT0);

% Enable two-sided lighting - Back sides of polygons are lit as well.
glLightModelfv(GL_LIGHT_MODEL_TWO_SIDE,GL_TRUE);

% Enable proper occlusion handling via depth tests:
glEnable(GL_DEPTH_TEST);

% Define the cubes light reflection properties by setting up reflection
% coefficients for ambient, diffuse and specular reflection:
glMaterialfv(GL_FRONT_AND_BACK,GL_AMBIENT, [ .33 .22 .03 1 ]);
glMaterialfv(GL_FRONT_AND_BACK,GL_DIFFUSE, [ .78 .57 .11 1 ]);
glMaterialfv(GL_FRONT_AND_BACK,GL_SHININESS,27.8);

% Set projection matrix: This defines a perspective projection,
% corresponding to the model of a pin-hole camera - which is a good
% approximation of the human eye and of standard real world cameras --
% well, the best aproximation one can do with 3 lines of code ;-)
glMatrixMode(GL_PROJECTION);
glLoadIdentity;
% Field of view is 25 degrees from line of sight. Objects close than
% 0.1 distance units or farther away than 100 distance units get clipped
% away, aspect ratio is adapted to the monitors aspect ratio:
gluPerspective(25,1/ar,0.1,100);

% Setup modelview matrix: This defines the position, orientation and
% looking direction of the virtual camera:
glMatrixMode(GL_MODELVIEW);
glLoadIdentity;

% Cam is located at 3D position (3,3,5), points upright (0,1,0) and fixates
% at the origin (0,0,0) of the worlds coordinate system:
gluLookAt(3,3,5,0,0,0,0,1,0);

% Setup position and emission properties of the light source:

% Set background color to 'black':
glClearColor(0,0,0,0);

% Point lightsource at (1,2,3)...
glLightfv(GL_LIGHT0,GL_POSITION,[ 1 2 3 0 ]);
% Emits white (1,1,1,1) diffuse light:
glLightfv(GL_LIGHT0,GL_DIFFUSE, [ 1 1 1 1 ]);

% There's also some white, but weak (R,G,B) = (0.1, 0.1, 0.1)
% ambient light present:
glLightfv(GL_LIGHT0,GL_AMBIENT, [ .1 .1 .1 1 ]);

% initialize amount and direction of rotation
theta=0;
rotatev=[ 0 0 1 ];

% Setup global variables needed for texture mapping:
global target;
global tu
global tv

% Run playback loop until key pressed:
while (1)
    % Fetch next video frame from movie file and return a Psychtoolbox
    % texture handle to it:
    Screen('EndOpenGL', win);
    texid = Screen('GetMovieImage', win, movie);
    Screen('BeginOpenGL', win);
    
    % Valid texture?
    if texid<=0
        % No. Abort.
        break;
    end;
    
    % Retrieve and assign textures for each cube face... Here we assign six
    % times the same image...
    for i=1:6
        % Retrieve size of movie texture image:
        [ imw imh] = Screen('WindowSize', texid);
        % Retrieve an OpenGL texture handle and texture mapping parameters:
        % texname(i) contains the OpenGL texture id, target is the texture
        % type, tu and tv are the texture coodinates of the (imw,imh)
        % position of the texture:
        [ texname(i) target tu tv] = Screen('GetOpenGLTexture', win, texid, imw, imh); %#ok<*AGROW>
    end;
    
    % calculate rotation angle and axis of cube for this frame:
    theta=mod(theta+1,360);
    rotatev=rotatev+0.1*[ sin((pi/180)*theta) sin((pi/180)*2*theta) sin((pi/180)*theta/5) ];
    rotatev=rotatev/sqrt(sum(rotatev.^2));

    % Draw cube:
    glPushMatrix;
    glRotatef(theta,rotatev(1),rotatev(2),rotatev(3));
    glClear;
        
    cubeface([ 4 3 2 1 ],texname(1));
    cubeface([ 5 6 7 8 ],texname(2));
    cubeface([ 1 2 6 5 ],texname(3));
    cubeface([ 3 4 8 7 ],texname(4));
    cubeface([ 2 3 7 6 ],texname(5));
    cubeface([ 4 1 5 8 ],texname(6));

    glPopMatrix;
    
    % End OpenGL rendering and check for OpenGL errors.
    Screen('EndOpenGL', win);

    % Show rendered image on next retrace:
    Screen('Flip', win);
    
    % Close the texture after drawing so we don't use up system memory:
    Screen('Close', texid);

    % Switch to OpenGL rendering again for drawing of next frame:
    Screen('BeginOpenGL', win);
    
    % Abort on keypress:
    if KbCheck
        break;
    end;
end

% End of the show:

% Disable OpenGL drawing:
Screen('EndOpenGL', win);

% Stop movie playback and close movie:
Screen('CloseMovie', movie);

% Close onscreen window and release all ressources:
Screen('CloseAll');

return

% draw one face of a textured cube
function cubeface( i, tx )
v=[ 0 0 0 ; 1 0 0 ; 1 1 0 ; 0 1 0 ; 0 0 1 ; 1 0 1 ; 1 1 1 ; 0 1 1 ]'-0.5;
n=cross(v(:,i(2))-v(:,i(1)),v(:,i(3))-v(:,i(2)));
global GL
global target
global tu
global tv

% Enable and bind proper texture:
glEnable(target);
glBindTexture(target,tx);
glTexEnvfv(GL.TEXTURE_ENV,GL.TEXTURE_ENV_MODE,GL.MODULATE);
% Setup filtering for the textures:
glTexParameterfv(GL.TEXTURE_2D,GL.TEXTURE_MAG_FILTER,GL.NEAREST);
glTexParameterfv(GL.TEXTURE_2D,GL.TEXTURE_MIN_FILTER,GL.NEAREST);

% Begin drawing of a new quad:
glBegin(GL.QUADS);

% Assign n as normal vector for this polygons surface normal:
glNormal3f(n(1), n(2), n(3));

% Define vertex 1 by assigning a texture coordinate and a 3D position:
glTexCoord2f(0, 0);
glVertex3f(v(1,i(1)),v(2,i(1)),v(3,i(1)));
% Define vertex 2 by assigning a texture coordinate and a 3D position:
glTexCoord2f(tu, 0);
glVertex3f(v(1,i(2)),v(2,i(2)),v(3,i(2)));
% Define vertex 3 by assigning a texture coordinate and a 3D position:
glTexCoord2f(tu, tv);
glVertex3f(v(1,i(3)),v(2,i(3)),v(3,i(3)));
% Define vertex 4 by assigning a texture coordinate and a 3D position:
glTexCoord2f(0, tv);
glVertex3f(v(1,i(4)),v(2,i(4)),v(3,i(4)));
glEnd;

return