mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-01-22 09:01:57 -05:00
Make players use map program.
This commit is contained in:
parent
0b0419c007
commit
9deb1e1d39
8 changed files with 55 additions and 44 deletions
|
@ -1,4 +1,5 @@
|
|||
using System;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
using OpenTK;
|
||||
|
||||
namespace ClassicalSharp {
|
||||
|
@ -38,7 +39,7 @@ namespace ClassicalSharp {
|
|||
|
||||
public abstract void Despawn();
|
||||
|
||||
public abstract void Render( double deltaTime, float t );
|
||||
public abstract void Render( double deltaTime, float t, MapShader shader );
|
||||
|
||||
public bool TouchesAnyLava() {
|
||||
return TouchesAny( b => b == (byte)Block.Lava || b == (byte)Block.StillLava );
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
using System;
|
||||
using System.Drawing;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
using ClassicalSharp.Renderers;
|
||||
using OpenTK;
|
||||
using OpenTK.Input;
|
||||
|
@ -324,14 +325,14 @@ namespace ClassicalSharp {
|
|||
}
|
||||
}
|
||||
|
||||
public override void Render( double deltaTime, float t ) {
|
||||
public override void Render( double deltaTime, float t, MapShader shader ) {
|
||||
if( !Window.Camera.IsThirdPerson ) return;
|
||||
if( renderer == null ) {
|
||||
renderer = new PlayerRenderer( this, Window );
|
||||
Window.AsyncDownloader.DownloadSkin( SkinName );
|
||||
}
|
||||
SetCurrentAnimState( t );
|
||||
renderer.Render( deltaTime );
|
||||
renderer.Render( deltaTime, shader );
|
||||
}
|
||||
|
||||
public bool HandleKeyDown( Key key ) {
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Drawing;
|
||||
using ClassicalSharp.GraphicsAPI;
|
||||
using ClassicalSharp.Renderers;
|
||||
using OpenTK;
|
||||
|
||||
|
@ -90,13 +91,13 @@ namespace ClassicalSharp {
|
|||
} while( states.Count >= 10 ); // Drop old states, otherwise we will never be able to catch up.
|
||||
}
|
||||
|
||||
public override void Render( double deltaTime, float t ) {
|
||||
public override void Render( double deltaTime, float t, MapShader shader ) {
|
||||
Position = Vector3.Lerp( oldState.pos, newState.pos, t );
|
||||
YawDegrees = Utils.InterpAngle( oldState.yaw, newState.yaw, t );
|
||||
PitchDegrees = Utils.InterpAngle( oldState.pitch, newState.pitch, t );
|
||||
|
||||
SetCurrentAnimState( t );
|
||||
renderer.Render( deltaTime );
|
||||
renderer.Render( deltaTime, shader );
|
||||
}
|
||||
}
|
||||
}
|
14
Game/Game.cs
14
Game/Game.cs
|
@ -284,13 +284,21 @@ namespace ClassicalSharp {
|
|||
}
|
||||
|
||||
void RenderPlayers( double deltaTime, float t ) {
|
||||
//Graphics.AlphaTest = true;
|
||||
//Graphics.AlphaTest = true;
|
||||
MapShader shader = MapRenderer.shader;
|
||||
// TODO: most of these assignments are redundant
|
||||
Graphics.UseProgram( shader.ProgramId );
|
||||
Graphics.SetUniform( shader.mvpLoc, ref mvp );
|
||||
Graphics.SetUniform( shader.fogColLoc, ref Graphics.FogColour );
|
||||
Graphics.SetUniform( shader.fogDensityLoc, Graphics.FogDensity );
|
||||
Graphics.SetUniform( shader.fogEndLoc, Graphics.FogEnd );
|
||||
Graphics.SetUniform( shader.fogModeLoc, (int)Graphics.FogMode );
|
||||
for( int i = 0; i < NetPlayers.Length; i++ ) {
|
||||
if( NetPlayers[i] != null ) {
|
||||
NetPlayers[i].Render( deltaTime, t );
|
||||
NetPlayers[i].Render( deltaTime, t, shader );
|
||||
}
|
||||
}
|
||||
LocalPlayer.Render( deltaTime, t );
|
||||
LocalPlayer.Render( deltaTime, t, shader );
|
||||
//Graphics.AlphaTest = false;
|
||||
}
|
||||
|
||||
|
|
|
@ -21,26 +21,25 @@ namespace ClassicalSharp.Model {
|
|||
protected float yaw, pitch;
|
||||
protected float rightLegXRot, rightArmXRot, rightArmZRot;
|
||||
protected float leftLegXRot, leftArmXRot, leftArmZRot;
|
||||
public void RenderModel( Player player, PlayerRenderer renderer ) {
|
||||
public void RenderModel( Player player, PlayerRenderer renderer, MapShader shader ) {
|
||||
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 );
|
||||
DrawPlayerModel( player, renderer );
|
||||
graphics.PopMatrix();
|
||||
Matrix4 mvp = Matrix4.CreateRotationY( -yaw ) * Matrix4.CreateTranslation( pos ) * window.mvp;
|
||||
graphics.SetUniform( shader.mvpLoc, ref mvp );
|
||||
DrawPlayerModel( player, renderer, shader, ref mvp );
|
||||
graphics.SetUniform( shader.mvpLoc, ref window.mvp );
|
||||
}
|
||||
|
||||
protected abstract void DrawPlayerModel( Player player, PlayerRenderer renderer );
|
||||
protected abstract void DrawPlayerModel( Player player, PlayerRenderer renderer, MapShader shader, ref Matrix4 mvp );
|
||||
|
||||
public abstract void Dispose();
|
||||
|
||||
|
@ -122,21 +121,22 @@ namespace ClassicalSharp.Model {
|
|||
vertices[index++] = new VertexPos3fTex2fCol4b( x1, y1, z, rec.U1, rec.V2, col );
|
||||
}
|
||||
|
||||
protected void DrawRotate( float x, float y, float z, float angleX, float angleY, float angleZ, ModelPart part ) {
|
||||
graphics.PushMatrix();
|
||||
protected void DrawRotate( float x, float y, float z, float angleX, float angleY, float angleZ, MapShader shader, ref Matrix4 mvp, ModelPart part ) {
|
||||
Matrix4 tempMvp = mvp;
|
||||
tempMvp = Matrix4.CreateTranslation( x, y, z ) * tempMvp;
|
||||
graphics.Translate( x, y, z );
|
||||
if( angleZ != 0 ) {
|
||||
graphics.RotateZ( angleZ );
|
||||
tempMvp = Matrix4.CreateRotationZ( angleZ ) * tempMvp;
|
||||
}
|
||||
if( angleY != 0 ) {
|
||||
graphics.RotateY( angleY );
|
||||
tempMvp = Matrix4.CreateRotationY( angleY ) * tempMvp;
|
||||
}
|
||||
if( angleX != 0 ) {
|
||||
graphics.RotateX( angleX );
|
||||
tempMvp = Matrix4.CreateRotationX( angleX ) * tempMvp;
|
||||
}
|
||||
graphics.Translate( -x, -y, -z );
|
||||
part.Render();
|
||||
graphics.PopMatrix();
|
||||
tempMvp = Matrix4.CreateTranslation( -x, -y, -z ) * tempMvp;
|
||||
graphics.SetUniform( shader.mvpLoc, ref tempMvp );
|
||||
part.Render( shader );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ namespace ClassicalSharp {
|
|||
VbId = Graphics.InitVb( vertices, DrawMode.Triangles, VertexFormat.VertexPos3fTex2fCol4b, count );
|
||||
}
|
||||
|
||||
public void Render() {
|
||||
Graphics.DrawVbPos3fTex2fCol4b( DrawMode.Triangles, VbId, Count );
|
||||
public void Render( MapShader shader ) {
|
||||
shader.DrawVb( Graphics, VbId, Count );
|
||||
}
|
||||
|
||||
public void Dispose() {
|
||||
|
|
|
@ -78,7 +78,7 @@ namespace ClassicalSharp.Model {
|
|||
}
|
||||
|
||||
ModelSet model;
|
||||
protected override void DrawPlayerModel( Player player, PlayerRenderer renderer ) {
|
||||
protected override void DrawPlayerModel( Player player, PlayerRenderer renderer, MapShader shader, ref Matrix4 mvp ) {
|
||||
graphics.Texturing = true;
|
||||
int texId = renderer.TextureId <= 0 ? DefaultSkinTextureId : renderer.TextureId;
|
||||
graphics.Bind2DTexture( texId );
|
||||
|
@ -87,14 +87,14 @@ namespace ClassicalSharp.Model {
|
|||
if( skinType == SkinType.Type64x64 ) model = Set64x64;
|
||||
else if( skinType == SkinType.Type64x64Slim ) model = Set64x64Slim;
|
||||
|
||||
DrawRotate( 0, 1.5f, 0, -pitch, 0, 0, model.Head );
|
||||
model.Torso.Render();
|
||||
DrawRotate( 0, 0.75f, 0, leftLegXRot, 0, 0, model.LeftLeg );
|
||||
DrawRotate( 0, 0.75f, 0, rightLegXRot, 0, 0, model.RightLeg );
|
||||
DrawRotate( 0, 1.5f, 0, leftArmXRot, 0, leftArmZRot, model.LeftArm );
|
||||
DrawRotate( 0, 1.5f, 0, rightArmXRot, 0, rightArmZRot, model.RightArm );
|
||||
graphics.AlphaTest = true;
|
||||
DrawRotate( 0, 1.4375f, 0, -pitch, 0, 0, model.Hat );
|
||||
DrawRotate( 0, 1.5f, 0, -pitch, 0, 0, shader, ref mvp, model.Head );
|
||||
graphics.SetUniform( shader.mvpLoc, ref mvp );
|
||||
model.Torso.Render( shader );
|
||||
DrawRotate( 0, 0.75f, 0, leftLegXRot, 0, 0, shader, ref mvp, model.LeftLeg );
|
||||
DrawRotate( 0, 0.75f, 0, rightLegXRot, 0, 0, shader, ref mvp, model.RightLeg );
|
||||
DrawRotate( 0, 1.5f, 0, leftArmXRot, 0, leftArmZRot, shader, ref mvp, model.LeftArm );
|
||||
DrawRotate( 0, 1.5f, 0, rightArmXRot, 0, rightArmZRot, shader, ref mvp, model.RightArm );
|
||||
DrawRotate( 0, 1.4375f, 0, -pitch, 0, 0, shader, ref mvp, model.Hat );
|
||||
}
|
||||
|
||||
public override void Dispose() {
|
||||
|
|
|
@ -35,9 +35,9 @@ namespace ClassicalSharp.Renderers {
|
|||
Graphics.DeleteTexture( nameTextureId );
|
||||
}
|
||||
|
||||
public void Render( double deltaTime ) {
|
||||
public void Render( double deltaTime, MapShader shader ) {
|
||||
pos = Player.Position;
|
||||
Player.Model.RenderModel( Player, this );
|
||||
Player.Model.RenderModel( Player, this, shader );
|
||||
DrawName();
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue