Tutorial 5
glScale and rotation
This tutorial doesn´t
introduce many new concepts, but expands on instructions previously
studied. The new instruction introduced in this tutorial is glScale
. This instruction 'scales' our reference axis. It is a cumulative
transformation like others we've seen in the sense that all
transformations after it are affected by the scaling, until a new
glLoadIdentity appears to clear transformations. For example
if after scaling the reference axis to twice the size and then
translating 1 unit, what will happen is actually a translation of two
units, since we are translating one unit on a scaled axis. The other
thing that is played around with is colour values (look at the score)
and rotation. See how simple rotations can create nice 3D effects.
<CsoundSynthesizer>
<CsOptions>
-+Y
</CsOptions>
<CsInstruments>
#include "OpenGL.h"
sr=100
kr =100
ksmps=1
nchnls=1
GLfps 30
GLpanel "OpenGL panel",
512, 512
GLpanel_end
FLrun
glMatrixMode $GL_PROJECTION
glLoadIdentity
gluPerspective 60,0.1,100
glMatrixMode $GL_MODELVIEW
GLinsert_i $GL_NOT_VALID
glClear $GL_COLOR_BUFFER_BIT
+ $GL_DEPTH_BUFFER_BIT
GLinsert_i 1.1
gisine ftgen 1,0,1024,10,1
instr 2
ired = p4
igreen = p5
iblue = p6
ix = p7
iy = p8
glLoadIdentity
tsize GLoscil 1,360,1
trot1 GLoscil 1,300,1
glTranslate ix,iy,-6
glRotate (trot1*360),1,0,1
glColor ired,igreen,iblue,1
glScale (tsize*3) , (tsize*3)
,(tsize*3)
glLineWidth 6
glBegin $GL_LINE_LOOP
glVertex3 0,0,0
glVertex3 1,0,0
glVertex3 1,1,0
glVertex3 0,1,0
glEnd
GLinsert 1.5
endin
</CsInstruments>
<CsScore>
i 2 2 38 1 0 0 1 -1
i 2 3 37 0.8 0.2 0 0.8 -0.8
i 2 4 36 0.6 0.4 0 0.6 -0.6
i 2 5 35 0.4 0.6 0 0.4 -0.4
i 2 6 34 0.2 0.8 0 0.2 -0.2
i 2 7 33 0 1 0 0 0
i 2 8 32 0 0.8 0.2 -0.2 0.2
i 2 9 31 0 0.6 0.4 -0.4 0
i 2 10 30 0 0.4 0.6 -0.6 0
i 2 11 29 0 0.2 0.8 -0.8 0
i 2 12 28 0 0 1 -1 0
i 2 13 27 0.2 0 0.8 -1.2 0
i 2 14 26 0.4 0 0.6 -1.4 0
</CsScore>
</CsoundSynthesizer>
As
I said before this tutorial doesn't introduce too many new concepts
but shows other uses of the instructions we've seen in previous
tutorials. It also looks a lot nicer because it moves more
'unexpectedly'. As always experiment a lot changing values and adding
whatever you come up with to see the results.
Back
to OpenGL Tutorials Index