[Gambas-user] gb3: OpenGL Rotate and Translate logic
Kevin Fishburne
kevinfishburne at ...1887...
Sat May 26 07:59:51 CEST 2012
On 05/25/2012 10:58 AM, tommyline at ...2340... wrote:
> Hi Kevin,
>
> I attach simple project that uses glu.lookat and rotates around a point on the floor. Try it and tell if it's what you're looking for.
>
> Tomek
Yes, that's what I'm looking for. I boiled that program down to the up
vector for Glu.LookAt() being computed by using the Sin() and Cos() of
the angle for two of the vector components while leaving the third
static. After finding the right values for the up vector I was able to
make the program render the scene with zoom and rotation, however the
camera is in the upper-left corner of the screen instead of at its
center. The code and video that does that is here:
' Calculate offsets to center of screen.
ScreenOffsetX = sWidth / 2 / 128 / Zoom.Current
ScreenOffsetY = sHeight / 2 / 128 / Zoom.Current
' Increment test rotation.
test += 0.01
' Assign values to up vector.
UpVec1 = Sin(test)
UpVec2 = Cos(test)
UpVec3 = 0
' Scale the matrix.
Gl.Scalef(128 * Zoom.Current, 128 * Zoom.Current, 1)
' Set the camera position and orientation.
'Glu.LookAt(Camera.WorldX + ScreenOffsetX, Camera.WorldY +
ScreenOffsetY, 1, Camera.WorldX + ScreenOffsetX, Camera.WorldY +
ScreenOffsetY, 0, UpVec1, UpVec2, UpVec3)
Glu.LookAt(Camera.WorldX, Camera.WorldY, 1, Camera.WorldX,
Camera.WorldY, 0, UpVec1, UpVec2, UpVec3)
http://eightvirtues.com/sanctimonia/misc/X%20Marks%20the%20Wrong%20Spot.ogv
Notice in the commented out Glu.LookAt() I have the screen offsets which
center the scene on my camera (the X rendered on the map is the camera's
world coordinates). When I include the screen offsets the rotation
provided by Glu.LookAt() is using some other origin and not my camera.
It appears as though the origin is the upper-left corner of the screen,
and looks like this:
http://eightvirtues.com/sanctimonia/misc/Screen%20Offset%20Fail.ogv
I saw several posts stating that using Gl.Ortho() would allow the center
of the screen to be used as the origin, but my implementations of it had
no effect other than rendering nothing when the near and far clipping
values were set to unequal values. Hopefully these details will inspire
some sort of epiphany or insight, as I'm about to go crazy, haha.
--
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271
More information about the User
mailing list