mirror of
https://github.com/ClassiCube/ClassiCube.git
synced 2025-09-17 11:35:08 -04:00
Finish arbitary scaled models in CustomModel (Thanks 123DMWM), closes #150.
This commit is contained in:
parent
7271985f13
commit
1ac2e63f13
@ -60,7 +60,7 @@ namespace ClassicalSharp.Entities {
|
|||||||
|
|
||||||
void FindHighestFree( ref Vector3 spawn ) {
|
void FindHighestFree( ref Vector3 spawn ) {
|
||||||
BlockInfo info = game.BlockInfo;
|
BlockInfo info = game.BlockInfo;
|
||||||
Vector3 size = entity.Model.CollisionSize;
|
Vector3 size = entity.CollisionSize;
|
||||||
BoundingBox bb = entity.CollisionBounds;
|
BoundingBox bb = entity.CollisionBounds;
|
||||||
Vector3I P = Vector3I.Floor( spawn );
|
Vector3I P = Vector3I.Floor( spawn );
|
||||||
int bbMax = Utils.Floor( size.Y );
|
int bbMax = Utils.Floor( size.Y );
|
||||||
|
@ -11,7 +11,9 @@ namespace ClassicalSharp.Entities {
|
|||||||
|
|
||||||
/// <summary> Returns the bounding box that contains the model, assuming it is not rotated. </summary>
|
/// <summary> Returns the bounding box that contains the model, assuming it is not rotated. </summary>
|
||||||
public BoundingBox PickingBounds {
|
public BoundingBox PickingBounds {
|
||||||
get { UpdateModel(); return Model.PickingBounds.Offset( Position ); }
|
get { UpdateModel(); BoundingBox bb = Model.PickingBounds;
|
||||||
|
return bb.Scale( ModelScale ).Offset( Position );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Bounding box of the model that collision detection
|
/// <summary> Bounding box of the model that collision detection
|
||||||
|
@ -48,7 +48,7 @@ namespace ClassicalSharp.Entities {
|
|||||||
|
|
||||||
/// <summary> Returns the size of the model that is used for collision detection. </summary>
|
/// <summary> Returns the size of the model that is used for collision detection. </summary>
|
||||||
public Vector3 CollisionSize {
|
public Vector3 CollisionSize {
|
||||||
get { UpdateModel(); return Model.CollisionSize; }
|
get { UpdateModel(); return Model.CollisionSize * ModelScale; }
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateModel() {
|
void UpdateModel() {
|
||||||
@ -72,7 +72,8 @@ namespace ClassicalSharp.Entities {
|
|||||||
|
|
||||||
/// <summary> Gets the position of the player's eye in the world. </summary>
|
/// <summary> Gets the position of the player's eye in the world. </summary>
|
||||||
public Vector3 EyePosition {
|
public Vector3 EyePosition {
|
||||||
get { return new Vector3( Position.X, Position.Y + Model.GetEyeY( this ), Position.Z ); }
|
get { return new Vector3( Position.X,
|
||||||
|
Position.Y + Model.GetEyeY( this ) * ModelScale, Position.Z ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
/// <summary> Gets the block just underneath the player's feet position. </summary>
|
/// <summary> Gets the block just underneath the player's feet position. </summary>
|
||||||
|
@ -47,7 +47,7 @@ namespace ClassicalSharp.Entities {
|
|||||||
if( !float.TryParse( scale, out value ) || float.IsNaN( value ) )
|
if( !float.TryParse( scale, out value ) || float.IsNaN( value ) )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
Utils.Clamp( ref value, 0.1f, Model.MaxScale );
|
Utils.Clamp( ref value, 0.25f, Model.MaxScale );
|
||||||
ModelScale = value;
|
ModelScale = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ namespace ClassicalSharp.Entities {
|
|||||||
|
|
||||||
IGraphicsApi api = game.Graphics;
|
IGraphicsApi api = game.Graphics;
|
||||||
api.BindTexture( nameTex.ID );
|
api.BindTexture( nameTex.ID );
|
||||||
Vector3 pos = Position; pos.Y += Model.NameYOffset;
|
Vector3 pos = Position; pos.Y += Model.NameYOffset * ModelScale;
|
||||||
|
|
||||||
Vector3 p111, p121, p212, p222;
|
Vector3 p111, p121, p212, p222;
|
||||||
FastColour col = FastColour.White;
|
FastColour col = FastColour.White;
|
||||||
|
@ -212,6 +212,7 @@ namespace ClassicalSharp.Model {
|
|||||||
for( int i = 0; i < index; i++ ) {
|
for( int i = 0; i < index; i++ ) {
|
||||||
VertexP3fT2fC4b v = cache.vertices[i];
|
VertexP3fT2fC4b v = cache.vertices[i];
|
||||||
float t = cosYaw * v.X - sinYaw * v.Z; v.Z = sinYaw * v.X + cosYaw * v.Z; v.X = t; // Inlined RotY
|
float t = cosYaw * v.X - sinYaw * v.Z; v.Z = sinYaw * v.X + cosYaw * v.Z; v.X = t; // Inlined RotY
|
||||||
|
v.X *= scale; v.Y *= scale; v.Z *= scale;
|
||||||
v.X += pos.X; v.Y += pos.Y; v.Z += pos.Z;
|
v.X += pos.X; v.Y += pos.Y; v.Z += pos.Z;
|
||||||
cache.vertices[i] = v;
|
cache.vertices[i] = v;
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,8 @@ namespace ClassicalSharp.Model {
|
|||||||
offset = 0.5f * 0.5f;
|
offset = 0.5f * 0.5f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public override float MaxScale { get { return 3; } }
|
||||||
|
|
||||||
public override float NameYOffset { get { return 1.3875f; } }
|
public override float NameYOffset { get { return 1.3875f; } }
|
||||||
|
|
||||||
public override float GetEyeY( Entity entity ) { return 14/16f; }
|
public override float GetEyeY( Entity entity ) { return 14/16f; }
|
||||||
@ -40,28 +42,30 @@ namespace ClassicalSharp.Model {
|
|||||||
|
|
||||||
public class GiantModel : HumanoidModel {
|
public class GiantModel : HumanoidModel {
|
||||||
|
|
||||||
const float scale = 2f;
|
const float size = 2f;
|
||||||
public GiantModel( Game window ) : base( window ) { }
|
public GiantModel( Game window ) : base( window ) { }
|
||||||
|
|
||||||
protected override void MakeDescriptions() {
|
protected override void MakeDescriptions() {
|
||||||
base.MakeDescriptions();
|
base.MakeDescriptions();
|
||||||
head = head.Scale( scale ); torso = torso.Scale( scale );
|
head = head.Scale( size ); torso = torso.Scale( size );
|
||||||
lLeg = lLeg.Scale( scale ); rLeg = rLeg.Scale( scale );
|
lLeg = lLeg.Scale( size ); rLeg = rLeg.Scale( size );
|
||||||
lArm = lArm.Scale( scale ); rArm = rArm.Scale( scale );
|
lArm = lArm.Scale( size ); rArm = rArm.Scale( size );
|
||||||
offset = 0.5f * scale;
|
offset = 0.5f * size;
|
||||||
}
|
}
|
||||||
|
|
||||||
public override float NameYOffset { get { return 2 * scale + 0.1375f; } }
|
|
||||||
|
|
||||||
public override float GetEyeY( Entity entity ) { return base.GetEyeY( entity ) * scale; }
|
public override float MaxScale { get { return 1; } }
|
||||||
|
|
||||||
|
public override float NameYOffset { get { return 2 * size + 0.1375f; } }
|
||||||
|
|
||||||
|
public override float GetEyeY( Entity entity ) { return base.GetEyeY( entity ) * size; }
|
||||||
|
|
||||||
public override Vector3 CollisionSize {
|
public override Vector3 CollisionSize {
|
||||||
get { return new Vector3( 8/16f * scale + 0.6f/16f,
|
get { return new Vector3( 8/16f * size + 0.6f/16f,
|
||||||
28.1f/16f * scale, 8/16f * scale + 0.6f/16f ); }
|
28.1f/16f * size, 8/16f * size + 0.6f/16f ); }
|
||||||
}
|
}
|
||||||
|
|
||||||
public override BoundingBox PickingBounds {
|
public override BoundingBox PickingBounds {
|
||||||
get { return base.PickingBounds.Scale( scale ); }
|
get { return base.PickingBounds.Scale( size ); }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,8 +37,8 @@ namespace ClassicalSharp.Model {
|
|||||||
/// <summary> Vertical offset from the model's feet/base that the model's eye is located. </summary>
|
/// <summary> Vertical offset from the model's feet/base that the model's eye is located. </summary>
|
||||||
public abstract float GetEyeY( Entity entity );
|
public abstract float GetEyeY( Entity entity );
|
||||||
|
|
||||||
/// <sumary> The maximum scale the entity can have (for collisions and rendering). </summary>
|
/// <summary> The maximum scale the entity can have (for collisions and rendering). </summary>
|
||||||
public virtual float MaxScale { get { return 1; } }
|
public virtual float MaxScale { get { return 2; } }
|
||||||
|
|
||||||
/// <summary> The size of the bounding box that is used when
|
/// <summary> The size of the bounding box that is used when
|
||||||
/// performing collision detection for this model. </summary>
|
/// performing collision detection for this model. </summary>
|
||||||
@ -50,7 +50,7 @@ namespace ClassicalSharp.Model {
|
|||||||
|
|
||||||
protected Vector3 pos;
|
protected Vector3 pos;
|
||||||
protected float cosYaw, sinYaw, cosHead, sinHead;
|
protected float cosYaw, sinYaw, cosHead, sinHead;
|
||||||
protected float uScale, vScale;
|
protected float uScale, vScale, scale;
|
||||||
|
|
||||||
/// <summary> Renders the model based on the given entity's position and orientation. </summary>
|
/// <summary> Renders the model based on the given entity's position and orientation. </summary>
|
||||||
public void Render( Player p ) {
|
public void Render( Player p ) {
|
||||||
@ -60,6 +60,7 @@ namespace ClassicalSharp.Model {
|
|||||||
World map = game.World;
|
World map = game.World;
|
||||||
col = game.World.IsLit( Vector3I.Floor( p.EyePosition ) ) ? map.Sunlight : map.Shadowlight;
|
col = game.World.IsLit( Vector3I.Floor( p.EyePosition ) ) ? map.Sunlight : map.Shadowlight;
|
||||||
uScale = 1 / 64f; vScale = 1 / 32f;
|
uScale = 1 / 64f; vScale = 1 / 32f;
|
||||||
|
scale = p.ModelScale;
|
||||||
|
|
||||||
cols[0] = col;
|
cols[0] = col;
|
||||||
cols[1] = FastColour.Scale( col, FastColour.ShadeYBottom );
|
cols[1] = FastColour.Scale( col, FastColour.ShadeYBottom );
|
||||||
@ -105,6 +106,7 @@ namespace ClassicalSharp.Model {
|
|||||||
for( int i = 0; i < part.Count; i++ ) {
|
for( int i = 0; i < part.Count; i++ ) {
|
||||||
ModelVertex v = vertices[part.Offset + i];
|
ModelVertex v = vertices[part.Offset + i];
|
||||||
float t = cosYaw * v.X - sinYaw * v.Z; v.Z = sinYaw * v.X + cosYaw * v.Z; v.X = t; // Inlined RotY
|
float t = cosYaw * v.X - sinYaw * v.Z; v.Z = sinYaw * v.X + cosYaw * v.Z; v.X = t; // Inlined RotY
|
||||||
|
v.X *= scale; v.Y *= scale; v.Z *= scale;
|
||||||
v.X += pos.X; v.Y += pos.Y; v.Z += pos.Z;
|
v.X += pos.X; v.Y += pos.Y; v.Z += pos.Z;
|
||||||
|
|
||||||
FastColour col = part.Count == boxVertices ?
|
FastColour col = part.Count == boxVertices ?
|
||||||
@ -161,6 +163,7 @@ namespace ClassicalSharp.Model {
|
|||||||
t = cosYaw * tX - sinYaw * tZ; tZ = sinYaw * tX + cosYaw * tZ; tX = t; // Inlined RotY
|
t = cosYaw * tX - sinYaw * tZ; tZ = sinYaw * tX + cosYaw * tZ; tX = t; // Inlined RotY
|
||||||
v.X += tX; v.Y += y; v.Z += tZ;
|
v.X += tX; v.Y += y; v.Z += tZ;
|
||||||
}
|
}
|
||||||
|
v.X *= scale; v.Y *= scale; v.Z *= scale;
|
||||||
v.X += pos.X; v.Y += pos.Y; v.Z += pos.Z;
|
v.X += pos.X; v.Y += pos.Y; v.Z += pos.Z;
|
||||||
|
|
||||||
FastColour col = part.Count == boxVertices ?
|
FastColour col = part.Count == boxVertices ?
|
||||||
|
Loading…
x
Reference in New Issue
Block a user