View Full Version : Matrices - Strange results

2851999

10-29-2014, 05:32 AM

Hello, I have spent a while writing a sort of game engine to learn more about OpenGL. About a month ago I started changing the way the system rendered and performed transformations and ended up making my own matrices class to handle the transformations. I don't want to use any libraries as this will not help me learn about matrices. I posted a question on this with more information here: stackoverflow.com/questions/26313568/opengl-matrices-strange-transformations but haven't got a single answer. I am using Java and LWJGL but the problem is more to do with the matrices themselves. When I try to render a cube, it ends up being completely distorted, I can never go be hind it and it just stretches in weird ways, translation doesn't work, nor does rotation. Thank you.

noahn567

11-03-2014, 08:12 PM

Hey i've recently done the same thing as you but i initially used the built in Matric4f libraries. I changed my mesh rotation to use Quaternions instead of euler rotation because im implementing skeletal animations and it just makes my life easier. Here's a very helpful link that will teach you about Quaternions. www.cprogramming.com/tutorial/3d/quaternions.html. Instead of the matrix libraries doing the work. you manually have to do the math. Youl see what i mean. Good luck!

DragonForce99

11-04-2014, 03:17 AM

if you calculate your matrics very well make sure that you are using this equation

Position = ProjectionMatrix * ViewMatrix * Transform

don't change the organization of equation (ProjectionMatrix * ViewMatrix * Transform)

2851999

11-04-2014, 09:34 AM

Hey i've recently done the same thing as you but i initially used the built in Matric4f libraries. I changed my mesh rotation to use Quaternions instead of euler rotation because im implementing skeletal animations and it just makes my life easier. Here's a very helpful link that will teach you about Quaternions. www.cprogramming.com/tutorial/3d/quaternions.html. Instead of the matrix libraries doing the work. you manually have to do the math. Youl see what i mean. Good luck!

Thank you, I will need to look into it but it looks like it will be very useful and this will fix an issue I the rotation. However I have tried removing the rotation all together using comments and it doesn't seem to cause all of the stretching and strange behavior caused by translating the view any where, I am wondering whether it might be caused by the projection matrix being calculated in the wrong way.

2851999

11-04-2014, 09:37 AM

if you calculate your matrics very well make sure that you are using this equation

Position = ProjectionMatrix * ViewMatrix * Transform

don't change the organization of equation (ProjectionMatrix * ViewMatrix * Transform)

I have looked into it, currently I am using this:

Matrix4D projectionViewMatrix = Matrix.multiplyMatrices(Matrix.projectionMatrix, Matrix.viewMatrix);

Matrix.modelViewProjectionMatrix = (Matrix.multiplyMatrices(projectionViewMatrix, Matrix.modelMatrix));

to calculate the final matrix before passing it to the shader, is it possible this is the wrong way round?

DragonForce99

11-08-2014, 07:49 AM

i dont know about your matrix you may need to transpose it ... what ever you got a problem and you have to makesure that you final resulat is currently

i recomend you to use GLM library its vary good math for opengl

2851999

11-09-2014, 02:56 AM

Thank you for helping, I finally fixed it. Firstly the matrix needed to be transposed, but my own code to do that was slightly wrong, and secondly the znear value of the perspective matrix was set to 0.1 which works when using GLU but not when using these sorts of matrices, thank you so much for your help. :D

DragonForce99

11-09-2014, 03:49 AM

good for you :D

Powered by vBulletin® Version 4.2.3 Copyright © 2018 vBulletin Solutions, Inc. All rights reserved.