### Author Topic: OpenGL rotations  (Read 336 times)

#### Richard Frost ##### OpenGL rotations
« on: July 07, 2020, 03:22:36 PM »
How does one apply a rotation centered on an object instead of the middle of the screen?
I'd like these 6 objects to stay in one place and spin.

Ashish's plasma cube was the starting point for this experimentation.

Code: QB64: [Select]
1. ' keys xyz to toggle rotations, arrow up/down speed
2.
3. _TITLE "Bonkers"
4.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
5. DIM SHARED glAllow AS _BYTE, glinit, s&(6), s2&(6), d(23, 4), d, n, x, y, z, r
6. SCREEN _NEWIMAGE(500, 500, 32)
7. d = 4: n = 23: sp = 60: x = 1: y = 1: z = 1
8. FOR i = 0 TO n
9.     FOR j = 0 TO 4
10.         t\$ = MID\$("zpnppppppppzpnpzznnpzpnpnppppnpzpnnzznnnzpnpnppppnpzpppzznppzpnnnpppnnpzpnpzznnpzpnpnppnpppznnpzznnnzpppnppppppzpnpzzpnn", i * 5 + j + 1, 1)
11.         d(i, j) = (INSTR("nzp", t\$) - 2) / 4 '          n=-1,z=0,p=1
12.     NEXT j
13. FOR p = 1 TO 6 '                                        generate 6 textures, one for each piece
14.     FOR i = 0 TO 250
15.         j = 255 - i
16.         IF p = 1 THEN c& = _RGB(i / 2, j, j) '          w
17.         IF p = 2 THEN c& = _RGB(j / 2, j, i) '          t
18.         IF p = 3 THEN c& = _RGB(j, i / 2, i) '          u
19.         IF p = 4 THEN c& = _RGB(i / 4, i, j / 2) '      x
20.         IF p = 5 THEN c& = _RGB(j / 2, i / 2, i) '      t+
21.         IF p = 6 THEN c& = _RGB(i, j, i) '              z
22.         LINE (i, i)-(_WIDTH - i, _HEIGHT - i), c&, B
23.     NEXT i
24.     s&(p) = _COPYIMAGE(0)
25. SCREEN _NEWIMAGE(800, 800, 32)
26. glAllow = -1
27.     i\$ = INKEY\$
28.     IF i\$ = "x" THEN x = x XOR 1 '                      x axis on/off
29.     IF i\$ = "y" THEN y = y XOR 1 '                      y
30.     IF i\$ = "z" THEN z = z XOR 1 '                      z
31.     IF LEN(i\$) = 2 THEN '                               maybe arrow key
32.         kk = ASC(RIGHT\$(i\$, 1))
33.         sp = sp + (kk = 80) * 10 - (kk = 72) * 10 '     speed
34.         IF sp < 10 THEN sp = 10 '                       lower speed limit
35.     r = (r + 1) MOD 360 '                               master rotation
36.     _PRINTSTRING (0, 0), STR\$(x) + STR\$(y) + STR\$(z) + STR\$(sp) + " "
37. LOOP UNTIL i\$ = CHR\$(27)
38. SCREEN 0, 0, 0, 0
39.
40. SUB _GL ()
41.     IF NOT glAllow THEN EXIT SUB
42.     IF NOT glinit THEN
43.         glinit = -1
44.         FOR p = 1 TO 6
45.             _GLGENTEXTURES 1, _OFFSET(s2&(p))
46.             m = _MEMIMAGE(s&(p))
47.             _GLBINDTEXTURE _GL_TEXTURE_2D, s2&(p)
48.             _GLTEXIMAGE2D _GL_TEXTURE_2D, 0, _GL_RGB, 500, 500, 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, m.OFFSET
49.             _GLTEXPARAMETERI _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_LINEAR
50.             _GLTEXPARAMETERI _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_NEAREST
51.             _FREEIMAGE s&(p)
52.         NEXT p
53.     FOR p = 1 TO 6 '                                                                          6 pieces
54.         _GLENABLE _GL_TEXTURE_2D
55.         _GLENABLE _GL_DEPTH_TEST
56.         _GLBINDTEXTURE _GL_TEXTURE_2D, s2&(p)
57.         _GLUPERSPECTIVE 45, 1280 / 800, 1, 50
58.         gluLookAt 4, 5, 12, 0, 1, 0, 0, 1, 0
59.         _GLROTATEF r + p * 20, x, y, z
60.         _GLTRANSLATEF p * 2 + (p > 3) * 6 - 3, 4 + (p < 4) * 2, p / 2 '                       2 lines of 3 pieces
62.         IF p = 1 THEN v 2, 0, 1, 0: v 2, .5, 1, .5: v 1, -.25, 1, -.5 '                       w
63.         IF p = 2 THEN v 2, 0, 1, 0: v 1, .25, 1, .5: v 1, .25, 1, -.5 '                       t
64.         IF p = 3 THEN v 3, 0, 1, 0: v 1, .5, 1, .5: v 1, -.5, 1, .5 '                         u
65.         IF p = 4 THEN v 3, 0, 1, 0: v 1, 0, 1, .5: v 1, 0, 1, -.5 '                           x
66.         IF p = 5 THEN v 2, 0, 1, 0: v 1, .25, 1, .5: v 1, .25, 1, -.5: v 1, .75, 1, .5 '      t+
67.         IF p = 6 THEN v 2, 0, 1, 0: v 1, .25, 1, .5: v 1, -.25, 1, -.5 '                      z
68.     NEXT p
69.
70. SUB v (xm, xo, ym, yo) '                                                                      multipliers and offsets
71.     FOR i = 0 TO n '
72.         _GLTEXCOORD2F d(i, 0) * d, d(i, 1) * d '                                              from texture
73.         _GLVERTEX3F d(i, 2) * xm + xo, d(i, 3) * ym + yo, d(i, 4) '                           make a box or rectangle
74.     NEXT i
75.
« Last Edit: July 07, 2020, 04:20:30 PM by Richard Frost »
It works better if you plug it in.

#### bplus ##### Re: OpenGL rotations
« Reply #1 on: July 07, 2020, 04:33:26 PM »
Well I don't know dukey about GL but can you put them in separate destinations spin them in their own self centered world and project the images where you want them back on screen?

#### Richard Frost ##### Re: OpenGL rotations
« Reply #2 on: July 07, 2020, 04:39:15 PM »
Yes, I'd thought of that, but surely there's a better (elegant) way.

I'm suprised you don't know, since you're into cool graphics.  You do your own rotations/projections/etc. without GL?
« Last Edit: July 07, 2020, 04:42:39 PM by Richard Frost »
It works better if you plug it in.

#### bplus ##### Re: OpenGL rotations
« Reply #3 on: July 07, 2020, 04:46:53 PM »
Rotations are easy in 2D with Rotozoom.

B+ gets D- in 3D. ;(

If you thought of that and I thought of that then that's it! :)
« Last Edit: July 07, 2020, 04:48:52 PM by bplus »

#### Richard Frost ##### Re: OpenGL rotations
« Reply #4 on: July 07, 2020, 07:40:20 PM »
Found it, I think - moving the gluLookat above the rotate fixes it.  Not that I understand WHY it works.

It works better if you plug it in.

#### bplus ##### Re: OpenGL rotations
« Reply #5 on: July 07, 2020, 08:04:10 PM »
Is that "gluLookat above the rotate" above each object?

#### Richard Frost ##### Re: OpenGL rotations
« Reply #6 on: July 07, 2020, 10:33:37 PM »
Ack.  I meant to say moving the _glTranslatef.   Switching between the old and new can be see by pressing the q key here.
There is only one instance of each of the translate, lookat, and rotate commands, and they're all executed before each redraw of the objects at new angles.

My replacing the DATA statements that defined the vertexes with one long string saved a few lines.    Ashish should take note
of how I eliminated multiple lines of _glTexCoord2f & _glVertex3f to draw a box.  :)

Code: QB64: [Select]
1. ' keys xyz to toggle rotations, arrow up/down speed
2.
3. _TITLE "Bonkers"
4.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
5. DIM SHARED glAllow AS _BYTE, glinit, s&(6), s2&(6), d(23, 4), d, n, x, y, z, r, q
6. SCREEN _NEWIMAGE(500, 500, 32)
7. d = 4: n = 23: sp = 60: x = 1: y = 1: z = 1
8. FOR i = 0 TO n
9.     FOR j = 0 TO 4
10.         t\$ = MID\$("zpnppppppppzpnpzznnpzpnpnppppnpzpnnzznnnzpnpnppppnpzpppzznppzpnnnpppnnpzpnpzznnpzpnpnppnpppznnpzznnnzpppnppppppzpnpzzpnn", i * 5 + j + 1, 1)
11.         d(i, j) = (INSTR("nzp", t\$) - 2) / 4 '          n=-1,z=0,p=1
12.     NEXT j
13. FOR p = 1 TO 6 '                                        generate 6 textures, one for each piece
14.     FOR i = 0 TO 250
15.         j = 255 - i
16.         IF p = 1 THEN c& = _RGB(i / 2, j, j) '          w
17.         IF p = 2 THEN c& = _RGB(j / 2, j, i) '          t
18.         IF p = 3 THEN c& = _RGB(j, i / 2, i) '          u
19.         IF p = 4 THEN c& = _RGB(i / 4, i, j / 2) '      x
20.         IF p = 5 THEN c& = _RGB(j / 2, i / 2, i) '      t+
21.         IF p = 6 THEN c& = _RGB(i, j, i) '              z
22.         LINE (i, i)-(_WIDTH - i, _HEIGHT - i), c&, B
23.     NEXT i
24.     s&(p) = _COPYIMAGE(0)
25. SCREEN _NEWIMAGE(800, 800, 32)
26. glAllow = -1
27.     i\$ = INKEY\$
28.     IF i\$ = "q" THEN q = q XOR 1
29.     IF i\$ = "x" THEN x = x XOR 1 '                      x axis on/off
30.     IF i\$ = "y" THEN y = y XOR 1 '                      y
31.     IF i\$ = "z" THEN z = z XOR 1 '                      z
32.     IF LEN(i\$) = 2 THEN '                               maybe arrow key
33.         kk = ASC(RIGHT\$(i\$, 1))
34.         sp = sp + (kk = 80) * 10 - (kk = 72) * 10 '     speed
35.         IF sp < 10 THEN sp = 10 '                       lower speed limit
36.     r = (r + 1) MOD 360 '                               master rotation
37.     _PRINTSTRING (0, 0), STR\$(x) + STR\$(y) + STR\$(z) + STR\$(sp) + " "
38. LOOP UNTIL i\$ = CHR\$(27)
39. SCREEN 0, 0, 0, 0
40.
41. SUB _GL ()
42.     IF NOT glAllow THEN EXIT SUB
43.     IF NOT glinit THEN
44.         glinit = -1
45.         FOR p = 1 TO 6
46.             _GLGENTEXTURES 1, _OFFSET(s2&(p))
47.             m = _MEMIMAGE(s&(p))
48.             _GLBINDTEXTURE _GL_TEXTURE_2D, s2&(p)
49.             _GLTEXIMAGE2D _GL_TEXTURE_2D, 0, _GL_RGB, 500, 500, 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, m.OFFSET
50.             _GLTEXPARAMETERI _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_LINEAR
51.             _GLTEXPARAMETERI _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_NEAREST
52.             _FREEIMAGE s&(p)
53.         NEXT p
54.     FOR p = 1 TO 6 '                                                                          6 pieces
55.         _GLENABLE _GL_TEXTURE_2D
56.         _GLENABLE _GL_DEPTH_TEST
57.         _GLBINDTEXTURE _GL_TEXTURE_2D, s2&(p)
58.         _GLUPERSPECTIVE 45, 1280 / 800, 1, 20
59.         IF q = 0 THEN _GLTRANSLATEF p * 2 + (p > 3) * 6 - 4, 4 + (p < 4) * 2 - 2, p / 2 '                   2 lines of 3 pieces
60.         gluLookAt 2, 5, 10, 0, 1, 0, 0, 1, 0
61.         _GLROTATEF r + p * 30, x, y, z
62.         IF q = 1 THEN _GLTRANSLATEF p * 2 + (p > 3) * 6 - 4, 4 + (p < 4) * 2 - 2, p / 2 '                   2 lines of 3 pieces
64.         IF p = 1 THEN v 2, 0, 1, 0: v 2, .5, 1, .5: v 1, -.25, 1, -.5 '                       w
65.         IF p = 2 THEN v 2, 0, 1, 0: v 1, .25, 1, .5: v 1, .25, 1, -.5 '                       t
66.         IF p = 3 THEN v 3, 0, 1, 0: v 1, .5, 1, .5: v 1, -.5, 1, .5 '                         u
67.         IF p = 4 THEN v 3, 0, 1, 0: v 1, 0, 1, .5: v 1, 0, 1, -.5 '                           x
68.         IF p = 5 THEN v 2, 0, 1, 0: v 1, .25, 1, .5: v 1, .25, 1, -.5: v 1, .75, 1, .5 '      t+
69.         IF p = 6 THEN v 2, 0, 1, 0: v 1, .25, 1, .5: v 1, -.25, 1, -.5 '                      z
70.     NEXT p
71.
72. SUB v (xm, xo, ym, yo) '                                                                      multipliers and offsets
73.     FOR i = 0 TO n '
74.         _GLTEXCOORD2F d(i, 0) * d, d(i, 1) * d '                                              from texture
75.         _GLVERTEX3F d(i, 2) * xm + xo, d(i, 3) * ym + yo, d(i, 4) '                           make a box or rectangle
76.     NEXT i
77.
78.
« Last Edit: July 07, 2020, 10:44:04 PM by Richard Frost »
It works better if you plug it in.

#### Ashish ##### Re: OpenGL rotations
« Reply #7 on: July 08, 2020, 12:23:47 AM »
Hi @Richard Frost
You need to translate first and then do rotation in order to make object rotate on its own axis. Just like you did in your last reply.

Nice demo BTW! :D
if (Me.success) {Me.improve()} else {Me.tryAgain()}

My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

#### Richard Frost ##### Re: OpenGL rotations
« Reply #8 on: July 08, 2020, 01:26:42 AM »
Also, why the LookAt goes before the rotate makes no sense to me, but that's the way it works.
It works better if you plug it in.

#### Ashish ##### Re: OpenGL rotations
« Reply #9 on: July 08, 2020, 01:41:10 AM »
Hi Richard, check out this code.
Code: QB64: [Select]
1. ' keys xyz to toggle rotations, arrow up/down speed
2.
3. _TITLE "Bonkers"
4.     SUB gluLookAt (BYVAL eyeX#, BYVAL eyeY#, BYVAL eyeZ#, BYVAL centerX#, BYVAL centerY#, BYVAL centerZ#, BYVAL upX#, BYVAL upY#, BYVAL upZ#)
5. DIM SHARED glAllow AS _BYTE, glinit, s&(6), s2&(6), d(23, 4), d, n, x, y, z, r, q
6. SCREEN _NEWIMAGE(500, 500, 32)
7. d = 4: n = 23: sp = 60: x = 1: y = 1: z = 1
8. FOR i = 0 TO n
9.     FOR j = 0 TO 4
10.         t\$ = MID\$("zpnppppppppzpnpzznnpzpnpnppppnpzpnnzznnnzpnpnppppnpzpppzznppzpnnnpppnnpzpnpzznnpzpnpnppnpppznnpzznnnzpppnppppppzpnpzzpnn", i * 5 + j + 1, 1)
11.         d(i, j) = (INSTR("nzp", t\$) - 2) / 4 '          n=-1,z=0,p=1
12.     NEXT j
13. FOR p = 1 TO 6 '                                        generate 6 textures, one for each piece
14.     FOR i = 0 TO 250
15.         j = 255 - i
16.         IF p = 1 THEN c& = _RGB(i / 2, j, j) '          w
17.         IF p = 2 THEN c& = _RGB(j / 2, j, i) '          t
18.         IF p = 3 THEN c& = _RGB(j, i / 2, i) '          u
19.         IF p = 4 THEN c& = _RGB(i / 4, i, j / 2) '      x
20.         IF p = 5 THEN c& = _RGB(j / 2, i / 2, i) '      t+
21.         IF p = 6 THEN c& = _RGB(i, j, i) '              z
22.         LINE (i, i)-(_WIDTH - i, _HEIGHT - i), c&, B
23.     NEXT i
24.     s&(p) = _COPYIMAGE(0)
25. SCREEN _NEWIMAGE(800, 800, 32)
26. glAllow = -1
27.     i\$ = INKEY\$
28.     IF i\$ = "q" THEN q = q XOR 1
29.     IF i\$ = "x" THEN x = x XOR 1 '                      x axis on/off
30.     IF i\$ = "y" THEN y = y XOR 1 '                      y
31.     IF i\$ = "z" THEN z = z XOR 1 '                      z
32.     IF LEN(i\$) = 2 THEN '                               maybe arrow key
33.         kk = ASC(RIGHT\$(i\$, 1))
34.         sp = sp + (kk = 80) * 10 - (kk = 72) * 10 '     speed
35.         IF sp < 10 THEN sp = 10 '                       lower speed limit
36.     r = (r + 1) MOD 360 '                               master rotation
37.     _PRINTSTRING (0, 0), STR\$(x) + STR\$(y) + STR\$(z) + STR\$(sp) + " "
38. LOOP UNTIL i\$ = CHR\$(27)
39. SCREEN 0, 0, 0, 0
40.
41. SUB _GL ()
42.     IF NOT glAllow THEN EXIT SUB
43.     IF NOT glinit THEN
44.         glinit = -1
45.         FOR p = 1 TO 6
46.             _GLGENTEXTURES 1, _OFFSET(s2&(p))
47.             m = _MEMIMAGE(s&(p))
48.             _GLBINDTEXTURE _GL_TEXTURE_2D, s2&(p)
49.             _GLTEXIMAGE2D _GL_TEXTURE_2D, 0, _GL_RGB, 500, 500, 0, _GL_BGRA_EXT, _GL_UNSIGNED_BYTE, m.OFFSET
50.             _GLTEXPARAMETERI _GL_TEXTURE_2D, _GL_TEXTURE_MAG_FILTER, _GL_LINEAR
51.             _GLTEXPARAMETERI _GL_TEXTURE_2D, _GL_TEXTURE_MIN_FILTER, _GL_NEAREST
52.             _FREEIMAGE s&(p)
53.         NEXT p
54.     _GLMATRIXMODE _GL_PROJECTION
55.     _GLUPERSPECTIVE 45, 1280 / 800, 1, 20 'needs to be called in projection matrix mode
56.
57.     _GLMATRIXMODE _GL_MODELVIEW
58.     gluLookAt 2, 5, 10, 0, 1, 0, 0, 1, 0 'need to be only called once.
59.
60.     FOR p = 1 TO 6 '                                                                          6 pieces
61.         _GLPUSHMATRIX 'save previous state
62.         _GLENABLE _GL_TEXTURE_2D
63.         _GLENABLE _GL_DEPTH_TEST
64.         _GLBINDTEXTURE _GL_TEXTURE_2D, s2&(p)
65.
66.         IF q = 0 THEN _GLTRANSLATEF p * 2 + (p > 3) * 6 - 4, 4 + (p < 4) * 2 - 2, p / 2 '                   2 lines of 3 pieces
67.         _GLROTATEF r + p * 30, x, y, z
68.         IF q = 1 THEN _GLTRANSLATEF p * 2 + (p > 3) * 6 - 4, 4 + (p < 4) * 2 - 2, p / 2 '                   2 lines of 3 pieces
70.         IF p = 1 THEN v 2, 0, 1, 0: v 2, .5, 1, .5: v 1, -.25, 1, -.5 '                       w
71.         IF p = 2 THEN v 2, 0, 1, 0: v 1, .25, 1, .5: v 1, .25, 1, -.5 '                       t
72.         IF p = 3 THEN v 3, 0, 1, 0: v 1, .5, 1, .5: v 1, -.5, 1, .5 '                         u
73.         IF p = 4 THEN v 3, 0, 1, 0: v 1, 0, 1, .5: v 1, 0, 1, -.5 '                           x
74.         IF p = 5 THEN v 2, 0, 1, 0: v 1, .25, 1, .5: v 1, .25, 1, -.5: v 1, .75, 1, .5 '      t+
75.         IF p = 6 THEN v 2, 0, 1, 0: v 1, .25, 1, .5: v 1, -.25, 1, -.5 '                      z
76.         _GLPOPMATRIX 'restore previous state
77.     NEXT p
78.
79. SUB v (xm, xo, ym, yo) '                                                                      multipliers and offsets
80.     FOR i = 0 TO n '
81.         _GLTEXCOORD2F d(i, 0) * d, d(i, 1) * d '                                              from texture
82.         _GLVERTEX3F d(i, 2) * xm + xo, d(i, 3) * ym + yo, d(i, 4) '                           make a box or rectangle
83.     NEXT i
84.
85.
86.
87.
if (Me.success) {Me.improve()} else {Me.tryAgain()}

My Projects - https://github.com/AshishKingdom?tab=repositories
OpenGL tutorials - https://ashishkingdom.github.io/OpenGL-Tutorials

#### Unseen Machine ##### Re: OpenGL rotations
« Reply #10 on: July 08, 2020, 03:19:11 AM »
Hi folks,

So i figured i'd explain. It's all about pushing and poping!

If you want to perform a translation or rotation on an object and not effect the whole scene you need to make sure youre on in the right place on the stack. Once you've performed an action such as _gltranslate or _glrotatef the changes you made in position or rotation will continue, that is unless you push and pop the matrices.

As for the way you've implemented it.

gluLookAt : This is old and outdated and (in my opinion) should'nt be used. I find it best to make your own camera controls!

_GLBEGIN : Again, this is a legacy command and really shouldnt be used either. Use the vertex and texture buffer instead.

https://nehe.gamedev.net/tutorial/lessons_01__05/22004/
It's an old reference (uses _GLBEGIN!) but still one of the best.

Just so you have an idea of how third person camera works
Code: QB64: [Select]
1.  IF KB(0).Q THEN Cam.Rot.X = Cam.Rot.X + 1
2.  IF Cam.Rot.X > 360 THEN Cam.Rot.X = Cam.Rot.X - 360
3.
4.  IF KB(0).Z THEN Cam.Rot.X = Cam.Rot.X + 1
5.  IF Cam.Rot.X < -360 THEN Cam.Rot.X = Cam.Rot.X + 360
6.
7.  IF KB(0).W THEN
8.   yrotrad = (Cam.Rot.Y / 180 * 3.141592654F)
9.   xrotrad = (Cam.Rot.X / 180 * 3.141592654F)
10.   Cam.POS.X = Cam.POS.X + SIN(yrotrad)
11.   Cam.POS.Z = Cam.POS.Z - COS(yrotrad)
12.   Cam.POS.Y = Cam.POS.Y - SIN(xrotrad)
13.
14.  IF KB(0).S THEN
15.   yrotrad = (Cam.Rot.Y / 180 * 3.141592654F)
16.   xrotrad = (Cam.Rot.X / 180 * 3.141592654F)
17.   Cam.POS.X = Cam.POS.X - SIN(yrotrad)
18.   Cam.POS.Z = Cam.POS.Z + COS(yrotrad)
19.   Cam.POS.Y = Cam.POS.Y + SIN(xrotrad)
20.
21.  IF KB(0).D THEN
22.   yrotrad = (Cam.Rot.Y / 180 * 3.141592654F)
23.   Cam.POS.X = Cam.POS.X + COS(yrotrad) * 0.2
24.   Cam.POS.Z = Cam.POS.Z + SIN(yrotrad) * 0.2
25.
26.  IF KB(0).A THEN
27.   yrotrad = (Cam.Rot.Y / 180 * 3.141592654F)
28.   Cam.POS.X = Cam.POS.X - COS(yrotrad) * 0.2
29.   Cam.POS.Z = Cam.POS.Z - SIN(yrotrad) * 0.2
30.
31.  diffx = Mouse(0).X - Mouse(1).X '// check the difference between the current x and the last x position
32.  diffy = Mouse(0).Y - Mouse(1).Y '// check the difference between the current y and the last y position
33.  Cam.Rot.X = Cam.Rot.X + diffy '// set the Cam.Rot.x to Cam.Rot.x with the addition of the difference in the y position
34.  Cam.Rot.Y = Cam.Rot.Y + diffx '// set the Cam.Rot.x to Cam.Rot.y with the addition of the difference in the x position
35.
36.
37.
39.  _GLROTATEF Cam.Rot.X, 1.0, 0.0, 0
40.  '// Thinkthe thing the camera is following gets rendered here....
41.
42.  _GLROTATEF Cam.Rot.Y, 0.0, 1.0, 0.0 '  //rotate our camera on the y-axis (up and down)
43.  _GLTRANSLATED Cam.POS.X, 0.0F, Cam.POS.Z ' //translate the screen to the position of our camera

Unseen

#### Richard Frost ##### Re: OpenGL rotations
« Reply #11 on: July 12, 2020, 12:23:43 AM »
Old and outdated is ok with me, if it works.

Unseen, why is your method better?   You don't say.
It works better if you plug it in.

#### Unseen Machine ##### Re: OpenGL rotations
« Reply #12 on: July 12, 2020, 04:32:40 AM »
Quote
Unseen, why is your method better?   You don't say.

Cause its faster to render this way, hell using the index buffer over the vertex buffer is even faster but that method is to complicated for my liking. Secondly, my way should run on all modern o/s's (i.e android) which doesnt support legacy GL commands such as _GLBegin/_GLEnd

Unseen

#### Richard Frost ##### Re: OpenGL rotations
« Reply #13 on: July 12, 2020, 07:46:32 AM »
#### TempodiBasic 