Guest User

Untitled

a guest
Apr 15th, 2016
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Scala 1.55 KB | None | 0 0
  1.     ... irrelevant code ...
  2.  
  3.     GL11.glPushMatrix()
  4.  
  5.     // Translate away from player
  6.     GL11.glTranslated(x, y, z)
  7.     // Translate into the center of the ship block for rotation
  8.     GL11.glTranslated(0.5, 0.5, 0.5)
  9.  
  10.  
  11.     // Note: Correction matrix is the exact same as the one used for my bounding box
  12.  
  13.     // Convert our correction matrix into a buffer to pass to LWJGL (and then to OpenGL)
  14.     val rotationCorrectionBuffer = matrixToFloatBuffer(entity.correctionMatrix)
  15.  
  16.     // Note: Rotation matrix is the exact same as the one used for my bounding box
  17.  
  18.     // Convert our rotation matrix to a FloatBuffer to pass to LWJGL (and then to OpenGL)
  19.     val rotationBuffer = matrixToFloatBuffer(entity.renderMatrix)
  20.  
  21.     // Multiply our transformation matrix by the rotation correction
  22.     GL11.glMultMatrix(rotationCorrectionBuffer)
  23.     // Then multiply by the actual rotation
  24.     GL11.glMultMatrix(rotationBuffer)
  25.  
  26.     // Translate out of the center for drawing the ship
  27.     GL11.glTranslated(-0.5, -0.5, -0.5)
  28.  
  29.   // Basically takes a 4x4 matrix and converts it to a FloatBuffer
  30.   def matrixToFloatBuffer(m: Matrix4f): FloatBuffer = {
  31.     val fb = BufferUtils.createFloatBuffer(16)
  32.     fb.put(m.m00)
  33.     fb.put(m.m01)
  34.     fb.put(m.m02)
  35.     fb.put(m.m03)
  36.     fb.put(m.m10)
  37.     fb.put(m.m11)
  38.     fb.put(m.m12)
  39.     fb.put(m.m13)
  40.     fb.put(m.m20)
  41.     fb.put(m.m21)
  42.     fb.put(m.m22)
  43.     fb.put(m.m23)
  44.     fb.put(m.m30)
  45.     fb.put(m.m31)
  46.     fb.put(m.m32)
  47.     fb.put(m.m33)
  48.     fb.flip()
  49.     return fb;
  50.   }
  51.  
  52.     ... irrelevant code ...
Advertisement
Add Comment
Please, Sign In to add comment