protected override void OnUpdate(GameTime gameTime) { base.OnUpdate(gameTime); var item = Item; if (item == null || item.Renderer == null) { return; } var bounds = Screen.RenderBounds; if (bounds != _previousBounds) { //var c = bounds.Center; //Camera.RenderPosition = new Vector3(c.X, c.Y, 0.0f); //Camera.UpdateProjectionMatrix(); //Camera.UpdateAspectRatio((float) bounds.Width / (float) bounds.Height); Camera.UpdateAspectRatio(bounds.Width / (float)bounds.Height); _previousBounds = bounds; } // Camera.MoveTo(EntityPosition, Vector3.Zero); // Camera.UpdateProjectionMatrix(); var args = new UpdateArgs() { GameTime = gameTime, Camera = Camera, GraphicsDevice = Alex.Instance.GraphicsDevice }; Camera.Update(args); Camera.UpdateProjectionMatrix(); item.Renderer.Update(args, MCMatrix.CreateTranslation(new Vector3(0, 0, 0))); }
public override void Update(IUpdateArgs args) { if (CanRender) { var knownPos = KnownPosition.ToVector3(); // var bb = base.BoundingBox; // var knownPos = bb.GetCenter(); if (DoRotation) { //var offset = new Vector3((float) Width, (float) Height, (float) Width) / 2f; var offset = new Vector3(0.5f, 0f, 0.5f); ItemRenderer.Update(args, MCMatrix.CreateScale(0.25f) * MCMatrix.CreateTranslation(-offset) * MCMatrix.CreateRotationY(MathHelper.ToRadians(_rotation)) * MCMatrix.CreateTranslation(offset) * MCMatrix.CreateTranslation(knownPos)); } else { ItemRenderer.Update(args, MCMatrix.CreateScale(0.25f) * MCMatrix.CreateRotationY(MathHelper.ToRadians(KnownPosition.Yaw)) * MCMatrix.CreateTranslation(knownPos)); } } if (DoRotation) { _rotation += 45f * (float)args.GameTime.ElapsedGameTime.TotalSeconds; } }
private ModelBone ProcessBone( EntityModel source, EntityModelBone bone, ref List <VertexPositionColorTexture> vertices, Vector2 textureSize, Dictionary <string, ModelBone> modelBones) { ModelBone modelBone; int startIndex = vertices.Count; int elementCount = 0; if (bone.Cubes != null) { foreach (var cube in bone.Cubes) { if (cube == null) { Log.Warn("Cube was null!"); continue; } var inflation = (float)(cube.Inflate ?? bone.Inflate); var mirror = cube.Mirror ?? bone.Mirror; var origin = cube.InflatedOrigin(inflation); MCMatrix matrix = MCMatrix.CreateTranslation(origin); if (cube.Rotation.HasValue) { var rotation = cube.Rotation.Value; Vector3 pivot = origin + (cube.InflatedSize(inflation) / 2f); if (cube.Pivot.HasValue) { pivot = cube.InflatedPivot(inflation); // cube.Pivot.Value; } matrix = MCMatrix.CreateTranslation(origin) * MCMatrix.CreateTranslation((-pivot)) * MCMatrix.CreateRotationDegrees(rotation) * MCMatrix.CreateTranslation(pivot); } Cube built = new Cube(cube, textureSize, mirror, inflation); ModifyCubeIndexes(ref vertices, built.Front, origin, matrix); ModifyCubeIndexes(ref vertices, built.Back, origin, matrix); ModifyCubeIndexes(ref vertices, built.Top, origin, matrix); ModifyCubeIndexes(ref vertices, built.Bottom, origin, matrix); ModifyCubeIndexes(ref vertices, built.Left, origin, matrix); ModifyCubeIndexes(ref vertices, built.Right, origin, matrix); } } elementCount = vertices.Count - startIndex; modelBone = new ModelBone(bone, startIndex, elementCount); if (bone.Rotation.HasValue) { var r = bone.Rotation.Value; modelBone.BindingRotation = new Vector3(r.X, r.Y, r.Z); } if (bone.BindPoseRotation.HasValue) { var r = bone.BindPoseRotation.Value; modelBone.BindingRotation += new Vector3(r.X, r.Y, r.Z); } foreach (var childBone in source.Bones.Where( x => x.Parent != null && string.Equals(x.Parent, bone.Name, StringComparison.OrdinalIgnoreCase))) { if (childBone.Parent != null && childBone.Parent.Equals(childBone.Name)) { continue; } if (string.IsNullOrWhiteSpace(childBone.Name)) { childBone.Name = Guid.NewGuid().ToString(); } var child = ProcessBone(source, childBone, ref vertices, textureSize, modelBones); //child.Parent = modelBone; modelBone.AddChild(child); if (!modelBones.TryAdd(childBone.Name, child)) { Log.Warn($"Failed to add bone! {childBone.Name}"); break; } } return(modelBone); }
public void Update(IUpdateArgs args, MCMatrix characterMatrix) { if (_disposed) { return; } //if (!Monitor.TryEnter(_disposeLock, 0)) // return; try { //var device = args.GraphicsDevice; if (CurrentAnim == null && Animations.TryDequeue(out var animation)) { animation.Setup(); animation.Start(); CurrentAnim = animation; } if (CurrentAnim != null) { CurrentAnim.Update(args.GameTime); if (CurrentAnim.IsFinished()) { CurrentAnim.Reset(); CurrentAnim = null; } } if (Definition.Pivot.HasValue) { var pivot = (Definition.Pivot ?? Vector3.Zero); WorldMatrix = MCMatrix.CreateTranslation(-pivot) * MCMatrix.CreateRotationDegrees(BindingRotation + Rotation) * MCMatrix.CreateTranslation(pivot) * characterMatrix; } else { WorldMatrix = MCMatrix.CreateRotationDegrees(BindingRotation + Rotation) * characterMatrix; } var children = Children.ToArray(); if (children.Length > 0) { foreach (var child in children) { child.Update(args, WorldMatrix); } } } finally { // Monitor.Exit(_disposeLock); } }