mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-13 01:26:50 -04:00
Only send final matrix result of multiplications to graphics api.
This commit is contained in:
parent
b5691061b5
commit
818a42f302
@ -148,31 +148,6 @@ namespace ClassicalSharp.GraphicsAPI {
|
|||||||
|
|
||||||
public abstract void MultiplyMatrix( ref Matrix4 matrix );
|
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 PushMatrix();
|
||||||
|
|
||||||
public abstract void PopMatrix();
|
public abstract void PopMatrix();
|
||||||
|
@ -25,19 +25,19 @@ namespace ClassicalSharp.Model {
|
|||||||
protected float leftLegXRot, leftArmXRot, leftArmZRot;
|
protected float leftLegXRot, leftArmXRot, leftArmZRot;
|
||||||
public void RenderModel( Player player, PlayerRenderer renderer ) {
|
public void RenderModel( Player player, PlayerRenderer renderer ) {
|
||||||
pos = player.Position;
|
pos = player.Position;
|
||||||
yaw = player.YawDegrees;
|
yaw = player.YawRadians;
|
||||||
pitch = player.PitchDegrees;
|
pitch = player.PitchRadians;
|
||||||
|
|
||||||
leftLegXRot = player.leftLegXRot * 180 / (float)Math.PI;
|
leftLegXRot = player.leftLegXRot;
|
||||||
leftArmXRot = player.leftArmXRot * 180 / (float)Math.PI;
|
leftArmXRot = player.leftArmXRot;
|
||||||
leftArmZRot = player.leftArmZRot * 180 / (float)Math.PI;
|
leftArmZRot = player.leftArmZRot;
|
||||||
rightLegXRot = player.rightLegXRot * 180 / (float)Math.PI;
|
rightLegXRot = player.rightLegXRot;
|
||||||
rightArmXRot = player.rightArmXRot * 180 / (float)Math.PI;
|
rightArmXRot = player.rightArmXRot;
|
||||||
rightArmZRot = player.rightArmZRot * 180 / (float)Math.PI;
|
rightArmZRot = player.rightArmZRot;
|
||||||
|
|
||||||
graphics.PushMatrix();
|
graphics.PushMatrix();
|
||||||
graphics.Translate( pos.X, pos.Y, pos.Z );
|
Matrix4 mat = Matrix4.RotateY( -yaw ) * Matrix4.Translate( pos );
|
||||||
graphics.RotateY( -yaw );
|
graphics.MultiplyMatrix( ref mat );
|
||||||
DrawPlayerModel( player, renderer );
|
DrawPlayerModel( player, renderer );
|
||||||
graphics.PopMatrix();
|
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 ) {
|
protected void DrawRotate( float x, float y, float z, float angleX, float angleY, float angleZ, ModelPart part ) {
|
||||||
graphics.PushMatrix();
|
graphics.PushMatrix();
|
||||||
graphics.Translate( x, y, z );
|
Matrix4 mat = Matrix4.Translate( x, y, z );
|
||||||
if( angleZ != 0 ) {
|
if( angleZ != 0 ) {
|
||||||
graphics.RotateZ( angleZ );
|
mat = Matrix4.RotateZ( angleZ ) * mat;
|
||||||
}
|
}
|
||||||
if( angleY != 0 ) {
|
if( angleY != 0 ) {
|
||||||
graphics.RotateY( angleY );
|
mat = Matrix4.RotateY( angleY ) * mat;
|
||||||
}
|
}
|
||||||
if( angleX != 0 ) {
|
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();
|
part.Render();
|
||||||
graphics.PopMatrix();
|
graphics.PopMatrix();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -43,18 +43,18 @@ namespace ClassicalSharp.Renderers {
|
|||||||
DrawName();
|
DrawName();
|
||||||
}
|
}
|
||||||
|
|
||||||
const float nameScale = 50f;
|
const float nameScale = 1 / 50f;
|
||||||
private void DrawName() {
|
private void DrawName() {
|
||||||
Graphics.PushMatrix();
|
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
|
// Do this to always have names facing the player
|
||||||
float yaw = Window.LocalPlayer.YawDegrees;
|
float yaw = Window.LocalPlayer.YawRadians;
|
||||||
Graphics.RotateY( 0f - yaw );
|
mat = Matrix4.RotateY( 0f - yaw ) * mat;
|
||||||
// NOTE: Do this instead with network player's yaw to have names rotate with them instead.
|
// NOTE: Do this instead with network player's yaw to have names rotate with them instead.
|
||||||
//Graphics.RotateY( 180f - yaw );
|
//Graphics.RotateY( 180f - yaw );
|
||||||
Graphics.Scale( 1 / nameScale, -1 / nameScale, 1 / nameScale ); // -y to flip text
|
mat = Matrix4.Scale( nameScale, -nameScale, nameScale ) * mat; // -y to flip text
|
||||||
Graphics.Translate( -nameWidth / 2f, -nameHeight, 0f );
|
mat = Matrix4.Translate( -nameWidth / 2f, -nameHeight, 0f ) * mat;
|
||||||
|
Graphics.MultiplyMatrix( ref mat );
|
||||||
nameTexture.Render( Graphics );
|
nameTexture.Render( Graphics );
|
||||||
|
|
||||||
Graphics.PopMatrix();
|
Graphics.PopMatrix();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user