I'm sure this is ridiculously simple, but my simple brain can't seem to figure it out.

I have a set of screen coordinates, xPos and yPos. I need to adjust their positions based on a zoom level, CameraZoom. The zoom level is relative to the center of the screen (swidth / 2, sheight / 2), and the zoom level range is from 1 to 2. If the zoom is at 1, the x and y coordinates wouldn't change. If the zoom is at 2, they would be half their previous distance from the center of the screen. This simulates the positions of objects changing as the camera zooms in and out.

There has to be some simple equation to produce this. I've attached the procedure that needs this just for reference. Any clues appreciated, as always.

--
Kevin Fishburne
Eight Virtues
www: http://sales.eightvirtues.com
e-mail: [email protected]
phone: (770) 853-6271

Public Sub Texture(Group As String, Optional ID As Short, Optional SubID As 
Byte, xPos As Short, yPos As Short, Width As Short, Height As Short, 
Orientation As Single)

  ' Draw a textured quad in the render window.

  Dim CameraZoom As Single

  ' Assign initial values to variables
  Orientation = Convert.Wrap_Single(0, 359, Orientation)
  CameraZoom = 1 / Zoom.Current

  ' Modify screen coordinates for zoom level.
  

  ' Select texture using its group, ID and SubID.
  Select Case Group
    Case "players"
      Gl.BindTexture(Gl.TEXTURE_2D, tiPlayer[ID].ID[0])
    Case "objects"
      Gl.BindTexture(Gl.TEXTURE_2D, tiObject[ID].ID[SubID])
    Case "shadows"
      Gl.BindTexture(Gl.TEXTURE_2D, tiShadow[ID].ID[0])
    Case "wisps"
      Gl.BindTexture(Gl.TEXTURE_2D, tiWisp[ID].ID[0])
    Case "landscape"
      Gl.BindTexture(Gl.TEXTURE_2D, tiLandscape[ID].ID[0])
    Case "water"
      Gl.BindTexture(Gl.TEXTURE_2D, tiWater[ID].ID[0])
    Case "elevation"
      Gl.BindTexture(Gl.TEXTURE_2D, tiElevation[ID].ID[0])
  End Select

  ' Translate the texture so it may be rotated around its center.
  Gl.MatrixMode(Gl.TEXTURE)
  Gl.LoadIdentity()
  Gl.Translatef(0.5, 0.5, 0)

  ' Rotate the translated texture.
  Gl.Rotatef(Orientation, 0, 0, 1)

  ' Translate it back to where it was.
  Gl.Translatef(-0.5, -0.5, 0)
  Gl.MatrixMode(Gl.MODELVIEW)

  ' Create the quad the texture is drawn on.
  Gl.Begin(Gl.QUADS)
    ' Bottom-left vertex.
    Gl.TexCoord2i(0, 0)
    Gl.Vertex3i(xPos, yPos, 0)
    ' Bottom-right vertex.
    Gl.TexCoord2i(1, 0)
    Gl.Vertex3i(xPos + Width, yPos, 0)
    ' Top-right vertex.
    Gl.TexCoord2i(1, 1)
    Gl.Vertex3i(xPos + Width, yPos + Height, 0)
    ' Top-left vertex.
    Gl.TexCoord2i(0, 1)
    Gl.Vertex3i(xPos, yPos + Height, 0)
  Gl.End()

  ' Reset matrices so subsequent SDL writes won't get botched.
  Gl.MatrixMode(Gl.TEXTURE)
  Gl.LoadIdentity()
  Gl.MatrixMode(Gl.MODELVIEW)
  Gl.LoadIdentity()

End
------------------------------------------------------------------------------
Get a FREE DOWNLOAD! and learn more about uberSVN rich system, 
user administration capabilities and model configuration. Take 
the hassle out of deploying and managing Subversion and the 
tools developers use with it. http://p.sf.net/sfu/wandisco-d2d-2
_______________________________________________
Gambas-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gambas-user

Reply via email to