Only send final matrix result of multiplications to graphics api.

This commit is contained in:
UnknownShadow200 2015-06-30 07:26:09 +10:00
parent b5691061b5
commit 818a42f302
3 changed files with 24 additions and 48 deletions

View File

@ -148,31 +148,6 @@ namespace ClassicalSharp.GraphicsAPI {
public abstract void MultiplyMatrix( ref Matrix4 matrix );
public virtual void Translate( float x, float y, float z ) {
Matrix4 matrix = Matrix4.Translate( x, y, z );
MultiplyMatrix( ref matrix );
}
public virtual void RotateX( float degrees ) {
Matrix4 matrix = Matrix4.RotateX( degrees * 0.01745329251f ); // PI / 180
MultiplyMatrix( ref matrix );
}
public virtual void RotateY( float degrees ) {
Matrix4 matrix = Matrix4.RotateY( degrees * 0.01745329251f );
MultiplyMatrix( ref matrix );
}
public virtual void RotateZ( float degrees ) {
Matrix4 matrix = Matrix4.RotateZ( degrees * 0.01745329251f );
MultiplyMatrix( ref matrix );
}
public virtual void Scale( float x, float y, float z ) {
Matrix4 matrix = Matrix4.Scale( x, y, z );
MultiplyMatrix( ref matrix );
}
public abstract void PushMatrix();
public abstract void PopMatrix();

View File

@ -25,19 +25,19 @@ namespace ClassicalSharp.Model {
protected float leftLegXRot, leftArmXRot, leftArmZRot;
public void RenderModel( Player player, PlayerRenderer renderer ) {
pos = player.Position;
yaw = player.YawDegrees;
pitch = player.PitchDegrees;
yaw = player.YawRadians;
pitch = player.PitchRadians;
leftLegXRot = player.leftLegXRot * 180 / (float)Math.PI;
leftArmXRot = player.leftArmXRot * 180 / (float)Math.PI;
leftArmZRot = player.leftArmZRot * 180 / (float)Math.PI;
rightLegXRot = player.rightLegXRot * 180 / (float)Math.PI;
rightArmXRot = player.rightArmXRot * 180 / (float)Math.PI;
rightArmZRot = player.rightArmZRot * 180 / (float)Math.PI;
leftLegXRot = player.leftLegXRot;
leftArmXRot = player.leftArmXRot;
leftArmZRot = player.leftArmZRot;
rightLegXRot = player.rightLegXRot;
rightArmXRot = player.rightArmXRot;
rightArmZRot = player.rightArmZRot;
graphics.PushMatrix();
graphics.Translate( pos.X, pos.Y, pos.Z );
graphics.RotateY( -yaw );
Matrix4 mat = Matrix4.RotateY( -yaw ) * Matrix4.Translate( pos );
graphics.MultiplyMatrix( ref mat );
DrawPlayerModel( player, renderer );
graphics.PopMatrix();
}
@ -125,19 +125,20 @@ namespace ClassicalSharp.Model {
protected void DrawRotate( float x, float y, float z, float angleX, float angleY, float angleZ, ModelPart part ) {
graphics.PushMatrix();
graphics.Translate( x, y, z );
Matrix4 mat = Matrix4.Translate( x, y, z );
if( angleZ != 0 ) {
graphics.RotateZ( angleZ );
mat = Matrix4.RotateZ( angleZ ) * mat;
}
if( angleY != 0 ) {
graphics.RotateY( angleY );
mat = Matrix4.RotateY( angleY ) * mat;
}
if( angleX != 0 ) {
graphics.RotateX( angleX );
mat = Matrix4.RotateX( angleX ) * mat;
}
graphics.Translate( -x, -y, -z );
mat = Matrix4.Translate( -x, -y, -z ) * mat;
graphics.MultiplyMatrix( ref mat );
part.Render();
graphics.PopMatrix();
}
}
}
}

View File

@ -43,18 +43,18 @@ namespace ClassicalSharp.Renderers {
DrawName();
}
const float nameScale = 50f;
const float nameScale = 1 / 50f;
private void DrawName() {
Graphics.PushMatrix();
Graphics.Translate( pos.X, pos.Y + Player.Model.NameYOffset, pos.Z );
Matrix4 mat = Matrix4.Translate( pos.X, pos.Y + Player.Model.NameYOffset, pos.Z );
// Do this to always have names facing the player
float yaw = Window.LocalPlayer.YawDegrees;
Graphics.RotateY( 0f - yaw );
float yaw = Window.LocalPlayer.YawRadians;
mat = Matrix4.RotateY( 0f - yaw ) * mat;
// NOTE: Do this instead with network player's yaw to have names rotate with them instead.
//Graphics.RotateY( 180f - yaw );
Graphics.Scale( 1 / nameScale, -1 / nameScale, 1 / nameScale ); // -y to flip text
Graphics.Translate( -nameWidth / 2f, -nameHeight, 0f );
mat = Matrix4.Scale( nameScale, -nameScale, nameScale ) * mat; // -y to flip text
mat = Matrix4.Translate( -nameWidth / 2f, -nameHeight, 0f ) * mat;
Graphics.MultiplyMatrix( ref mat );
nameTexture.Render( Graphics );
Graphics.PopMatrix();