Yesterday I just got so sick of C++ dependency problems that I decided to move my video game to Java. It's actually been a pretty good move. Already the external library situation has gone from 12 to 1 and I have way less files to keep track of. And no more makefile! My problem though is I can't figure out how to do the MVP matrix the way I had it in C++. Apparently, lwjgl was overhauled and rereleased just last month, which is probably why I can't find any tutorials or examples for lwjgl 3.0 out here on the net.
So, I need some help. Below is the C++ code. The facing, eyeXYZ, character(), and other variables I can get already in Java. What I can't do is get the whole matrix situation acting right. I'm using Matrix4f and Vector3f and Matrix4f.mul/flip and FloatBuffers and .... I don't even know. Apparently Linear Algebra is the one area where C++ is actually simpler than Java.
What I need is to input the desired camera positiion ( eyeXYZ ) and the characterXYZ and get them MVP matrix back.
I'll then pass the MVP matrix as a uniform into the vertex shader and then be able to follow my character around, RPG style.
Can anyone help?
//C++ code that does exactly what I need
float facing = getCharacterFacing();
facing = (float) ( ( (int) (facing + 180) ) % 360 ) ;
float eyeX = getCharacterX() + CAMERA_DISTANCE_BEHIND * cos( facing * PI / 180.0);
float eyeY = getCharacterY() + CAMERA_DISTANCE_BEHIND * sin( facing * PI / 180.0 );
float eyeZ = getCharacterZ() + 4.0;
glm::mat4 Projection = glm::perspective(45.0f, (float)640/480, 0.1f, 100.0f);
glm::mat4 View = glm::lookAt(
glm::vec3(eyeX,eyeY,eyeZ), // Camera is at (4,3,3), in World Space
glm::vec3(getCharacterX(),getCharacterY(),getCharacterZ()), // and looks at the character
glm::vec3(0,0,getCharacterZ()+20.0) // Up is positive Z, 20 units above character so it's guaranteed to be above character
glm::mat4 Model = glm::mat4(1.0f);
glm::mat4 MVP = Projection * View * Model;