[Gambas-user] gb3: OpenGL Rotate and Translate logic
tommyline at ...2340...
tommyline at ...2340...
Tue May 22 09:02:44 CEST 2012
Hi Kevin.
There's plenty of issues you post, but first thing I would do would be:
instead of:
Gl.Translatef(Camera.WorldX, Camera.WorldY, 0)
Gl.Rotatef(- Camera.Orientation, 0, 0, 1)
Gl.Translatef(- Camera.WorldX, - Camera.WorldY, 0) '<<-- you come back along different path here because
'the world is turned along z-axis
try this:
Gl.Translatef(Camera.WorldX, Camera.WorldY, 0)
gl.PushMatrix() '<-you save the world's coordinate here
do all the drawing here
gl.PopMatrix() '<-restore camera's original position.
Doing gl.Rotatef() you turn GLOBAL coordinates, so if you do gl.Rotatef(90,0,0,1), your x an y axes are swapped, y becomes x, becomes -y, thus doing gl.Translatef(1,1,0) next in fact moves your object by (-1,1,0...I think:)) ).
That's for the moment, the rest we can discuss if you want.
regards
Tomek
----- Original Message -----
From: "Kevin Fishburne" <kevinfishburne at ...1887...>
To: gambas-user at lists.sourceforge.net
Sent: Tuesday, 22 May, 2012 5:14:02 AM
Subject: [Gambas-user] gb3: OpenGL Rotate and Translate logic
Disclaimer: I've been working on this for days and neither Google nor
trial and error is adequate, apparently.
I'm trying to render an overhead, 2D scene with the "camera" at the
center of the screen and the world objects rotated around it. Here are
my variables:
Camera.WorldX As Single ' World coordinates of camera.
Camera.WorldYAs Single ' World coordinates of camera.
Camera.Orientation As Single ' Angle of camera (2D overhead view,
rotates screen like Contra III for SNES).
Camera.Zoom As Single ' Scale of matrix for zooming in and out.
sWidth As Short ' Width in pixels of screen.
sHeight As Short ' Height in pixels of screen.
I need to rotate the matrix so that rendered objects will appear in the
correct positions with regard to the camera's orientation. I need to
translate the matrix so that the camera coordinates are always at the
center of the rendering window. I need to scale the matrix so that the
camera can zoom in and out (always centered at the middle of the
rendering window).
I suspect that to center the camera on the rendering window after
rotating the matrix, I need to "unrotate" the x and y offsets required
to center it, which I can do if necessary using some functions I created
to rotate an arbitrary point about an arbitrary origin.
I think I can successfully rotate the matrix around the camera with code
like this:
Gl.Translatef(Camera.WorldX, Camera.WorldY, 0)
Gl.Rotatef(- Camera.Orientation, 0, 0, 1)
Gl.Translatef(- Camera.WorldX, - Camera.WorldY, 0)
But then I need to translate the scene so that the camera is in the
center of the rendering window. I also can't figure out how to
arbitrarily scale the matrix to zoom in and out on the camera in this
sequence. I have this:
Gl.Scalef(128 * Zoom.Current, 128 * Zoom.Current, 1)
but its effects vary depending on where I place it. The reason it
multiplies by 128 is because each "tile" is 128 pixels, and each world
coordinate is one tile. I couldn't be more confused if I'd just been
shot in the head, so any help is greatly appreciated.
--
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: sales at ...1887...
phone: (770) 853-6271
------------------------------------------------------------------------------
Live Security Virtual Conference
Exclusive live event will cover all the ways today's security and
threat landscape has changed and how IT managers can respond. Discussions
will include endpoint security, mobile security and the latest in malware
threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/
_______________________________________________
Gambas-user mailing list
Gambas-user at lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/gambas-user
More information about the User
mailing list