Blackvoxel/Blackvoxel — pull request #1 by d3x0r (2014-11-08 06:57:37+00:00)
Title: Back propagation

Add ZMatrix class
Added a couple cross-platform definition fixups...

Did not implement zmatrix anywhere... usage is

in Render_basic.cpp....
glMatrixMode(GL_MODELVIEW);
#if USING_ZMATRIX_CAMERA
if( Camera->use_matrix )
// returns a reference of a inverted matrix for opengl
glLoadMatrixd( Camera->orientation.glMatrix() );
#else
if( !Camera->use_matrix )
{
glLoadIdentity();
glRotatef(-Camera->Roll , 0.0, 0.0, 1.0);
glRotatef(-Camera->Pitch , 1.0, 0.0, 0.0);
glRotatef(180-Camera->Yaw, 0.0, 1.0, 0.0);

glTranslatef(-(float)Camera->x,-(float)Camera->y,-(float)Camera->z);
}
#endif

but that changes camera contents from an x,y,z,yaw,pitch,roll to ZMatrix orientation; which contains all members...
could be a soft-if... then can change it based on player mode so things depending on yaw/pitch/roll can remain unmodified...

----
ZActor_player.cpp
if ViewDirection is changed to a ZMatrix instead of a ZPolar3d; and Location is removed, instead using .. ViewDirection.origin() which just returns a reference to a row in the matrix cast as a ZVector3d...

becomes this....
ViewDirection.Rotate( -Delta_x/(3*MouseRatio), -Delta_y/(3*MouseRatio), 0 );

/*
ViewDirection.yaw+=Delta_x/(3*MouseRatio);
if (ViewDirection.yaw >= 360.0) ViewDirection.yaw -= 360.0;
if (ViewDirection.yaw <0 ) ViewDirection.yaw += 360.0;

ViewDirection.pitch-=Delta_y/(3*MouseRatio);
if (ViewDirection.pitch >= 360.0) ViewDirection.pitch -= 360.0;
if (ViewDirection.pitch <0 ) ViewDirection.pitch += 360.0;
if (ViewDirection.pitch >= 360.0) ViewDirection.pitch -= 360.0;
if (ViewDirection.pitch <0 ) ViewDirection.pitch += 360.0;
ViewDirection.roll = 0.0;

// Pitch clip
if (ViewDirection.pitch >=90.0 && ViewDirection.pitch < 180.0) ViewDirection.pitch = 90.0;
if (ViewDirection.pitch <270.0 && ViewDirection.pitch >=180.0) ViewDirection.pitch = 270.0;
*/

Camera.orientation = ViewDirection;

.forward() returns a refenence to a row in the matrix cast as a ZVector ... so move can be ( matrix.forward() * MoveSpeed ) using exsiting inlined zvector code.

----------
and the position correction in SetPlayerPositon

ViewDirection.translate( NewLocation );

if( ActorMode == 0 ) // make sure we're standing up.
ViewDirection.RotateRoll( -ViewDirection.roll() );

Camera.orientation = ViewDirection;//.orientation;
//Camera.orientation.translate_rel( EyesPosition.x, EyesPosition.y,EyesPosition.z );
// this would be the same...
Camera.orientation.origin() += EyesPosition;

//Camera.orientation.RotateRoll( -Camera.orientation.roll() );
//Camera.orientation.translate( ViewDirection.origin().x + EyesPosition.x, ViewDirection.origin().y + EyesPosition.y,ViewDirection.origin().z+ EyesPosition.z );
//Camera.x = ViewDirection.origin().x + EyesPosition.x;
//Camera.y = ViewDirection.origin().y + EyesPosition.y;
//Camera.z = ViewDirection.origin().z + EyesPosition.z;
// printf("Camera.y: %lf\n", Camera.y);