Reputation: 687
I recently switched from using the deprecated gl_*Matrix
to handling matrices on my own. Everything seems to be working fine, except that rotation is about 80 times what it should be. I can switch to using opengl's matrices without changing any other code, and rotation is fine. The complete source is on Github. The most relevant function is here:
calculateMatricesFromPlayer :: GameObject a -> WorldMatrices
calculateMatricesFromPlayer p@(Player{}) =
let Vec3 px py pz = playerPosition p
Vec3 rx ry _ = playerRotation p
-- Create projection matrix
projMat = gperspectiveMatrix 45 (800/600) 0.1 100
-- Create view matrix
rotatedMatX = grotationMatrix rx [-1, 0, 0]
rotatedMatXY = rotatedMatX * grotationMatrix ry [0, -1, 0]
translatedMat = gtranslationMatrix [-px, -py, -pz]
viewMat = rotatedMatXY * translatedMat
-- Model matrix is identity by default
modelMat = gidentityMatrix
in WorldMatrices modelMat viewMat projMat
Is there anything obvious that I am doing wrong?
Upvotes: 2
Views: 162
Reputation: 672
Since there are 360
degrees and 2*pi
radians in a circle, with pi
being approximately 3, it seems very likely that being out by a factor of approximately 80 is you using degrees as input to sin
, cos
or tan
functions which are taking input as radians, since 360/(2*pi)
is approximately 80.
Upvotes: 8