public Location GetEyePosition() { Location renderrelpos = GetWeldSpot(); Location start = renderrelpos + new Location(0, 0, CBHHeight * (CBody.StanceManager.CurrentStance == Stance.Standing ? 1.8 : 1.5)); if (tAnim != null) { SingleAnimationNode head = tAnim.GetNode("special06.r"); Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>(SavedAdjustments); Matrix rotforw = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, -(float)(Direction.Pitch / 1.75f * Utilities.PI180))); adjs["spine04"] = GetAdjustment("spine04") * rotforw; Matrix m4 = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-Direction.Yaw + 270) * Utilities.PI180) % 360f)) * head.GetBoneTotalMatrix(0, adjs) * (rotforw * Matrix.CreateTranslation(new Vector3(0, 0, 0.2f))); m4.Transpose(); Location end = renderrelpos + new Location(m4.Translation) * 1.5f; start.Z = end.Z; // FUTURE: Maybe handle player rotation? double len = (end - start).Length(); Location normdir = (end - start) / len; RayCastResult rcr; if (TheRegion.SpecialCaseRayTrace(start, normdir, (float)len, MaterialSolidity.FULLSOLID, IgnoreThis, out rcr)) { return(new Location(rcr.HitData.Location + rcr.HitData.Normal * 0.2f)); } return(end); } else { return(start); } }
public void UpdateTransforms(ModelNode pNode, Matrix4 transf) { string nodename = pNode.Name; Matrix4 nodeTransf = Matrix4.Identity; double time; SingleAnimationNode pNodeAnim = FindNodeAnim(nodename, pNode.Mode, out time); if (pNodeAnim != null) { BEPUutilities.Vector3 vec = pNodeAnim.lerpPos(time); BEPUutilities.Quaternion quat = pNodeAnim.lerpRotate(time); OpenTK.Quaternion oquat = new OpenTK.Quaternion(quat.X, quat.Y, quat.Z, quat.W); Matrix4 trans; Matrix4.CreateTranslation(vec.X, vec.Y, vec.Z, out trans); trans.Transpose(); Matrix4 rot; Matrix4.CreateFromQuaternion(ref oquat, out rot); rot.Transpose(); Matrix4.Mult(ref trans, ref rot, out nodeTransf); } Matrix4 global; Matrix4.Mult(ref transf, ref nodeTransf, out global); for (int i = 0; i < pNode.Bones.Count; i++) { //Matrix4 modded; //Matrix4.Mult(ref globalInverse, ref global, out modded); Matrix4.Mult(ref global, ref pNode.Bones[i].Offset, out pNode.Bones[i].Transform); } for (int i = 0; i < pNode.Children.Count; i++) { UpdateTransforms(pNode.Children[i], global); } }
public void UpdateTransforms(ModelNode pNode, Matrix4 transf) { string nodename = pNode.Name; Matrix4 nodeTransf = Matrix4.Identity; double time; SingleAnimationNode pNodeAnim = FindNodeAnim(nodename, pNode.Mode, out time); if (pNodeAnim != null) { BEPUutilities.Vector3 vec = pNodeAnim.lerpPos(time); BEPUutilities.Quaternion quat = pNodeAnim.lerpRotate(time); Quaternion oquat = new Quaternion((float)quat.X, (float)quat.Y, (float)quat.Z, (float)quat.W); Matrix4 trans; Matrix4.CreateTranslation((float)vec.X, (float)vec.Y, (float)vec.Z, out trans); trans.Transpose(); Matrix4 rot; Matrix4.CreateFromQuaternion(ref oquat, out rot); Matrix4 r2; if (CustomAnimationAdjustments.TryGetValue(nodename, out r2)) { rot *= r2; } rot.Transpose(); Matrix4.Mult(ref trans, ref rot, out nodeTransf); } else { Matrix4 temp; if (CustomAnimationAdjustments.TryGetValue(nodename, out temp)) { temp.Transpose(); nodeTransf = temp; } } Matrix4 global; Matrix4.Mult(ref transf, ref nodeTransf, out global); for (int i = 0; i < pNode.Bones.Count; i++) { if (ForceBoneNoOffset) { pNode.Bones[i].Transform = global; } else { Matrix4.Mult(ref global, ref pNode.Bones[i].Offset, out pNode.Bones[i].Transform); } } for (int i = 0; i < pNode.Children.Count; i++) { UpdateTransforms(pNode.Children[i], global); } }
public override Location GetEyePosition() { if (tAnim != null) { SingleAnimationNode head = tAnim.GetNode("special06.r"); Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>(); Matrix rotforw = Matrix.CreateFromQuaternion(BEPUutilities.Quaternion.CreateFromAxisAngle(Vector3.UnitX, -(double)(Direction.Pitch / 1.75f * Utilities.PI180))); adjs["spine05"] = rotforw; Matrix m4 = Matrix.CreateFromQuaternion(BEPUutilities.Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (double)((-Direction.Yaw + 270) * Utilities.PI180) % 360f)) * head.GetBoneTotalMatrix(0, adjs) * (rotforw * Matrix.CreateTranslation(new Vector3(0, 0, 0.2f))); m4.Transpose(); return(GetPosition() + new Location(m4.Translation) * 1.5f); } else { return(GetPosition() + new Location(0, 0, CBHHeight * (CBody.StanceManager.CurrentStance == Stance.Standing ? 1.8 : 1.5))); } }
public Location GetEyePosition() { Location renderrelpos = GetWeldSpot(); Location start = renderrelpos + new Location(0, 0, CBHHeight * (CBody.StanceManager.CurrentStance == Stance.Standing ? 1.8 : 1.5)); if (tAnim != null) { SingleAnimationNode head = tAnim.GetNode("special06.r"); Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>(SavedAdjustments); Matrix rotforw = Matrix.CreateFromQuaternion(BEPUutilities.Quaternion.CreateFromAxisAngle(Vector3.UnitX, -(float)(Direction.Pitch / 1.75f * Utilities.PI180))); adjs["spine04"] = GetAdjustment("spine04") * rotforw; Matrix m4 = Matrix.CreateFromQuaternion(BEPUutilities.Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-Direction.Yaw + 270) * Utilities.PI180) % 360f)) * head.GetBoneTotalMatrix(0, adjs) * (rotforw * Matrix.CreateTranslation(new Vector3(0, 0, 0.2f))); m4.Transpose(); return(renderrelpos + new Location(m4.Translation) * 1.5f); } else { return(start); } }
// TODO: Merge with base.Render() as much as possible! public override void Render() { View3D.CheckError("Render - Player - Pre"); Location renderrelpos = GetWeldSpot(); if (TheClient.IsMainMenu || !TheClient.CVars.r_drawself.ValueB) { return; } TheClient.SetEnts(); if (TheClient.CVars.n_debugmovement.ValueB) { if (ServerLocation.IsInfinite() || ServerLocation.IsNaN() || renderrelpos.IsInfinite() || renderrelpos.IsNaN()) { SysConsole.Output(OutputType.WARNING, "NaN server data"); } else { TheClient.Rendering.RenderLine(ServerLocation, renderrelpos); View3D.CheckError("Render - Player - Line"); TheClient.Rendering.RenderLineBox(ServerLocation + new Location(-0.2), ServerLocation + new Location(0.2)); if (View3D.CheckError("Render - Player - LineBox")) { SysConsole.Output(OutputType.DEBUG, "Caught: " + (ServerLocation + new Location(-0.2)) + "::: " + (ServerLocation + new Location(0.2))); } } } if (TheClient.VR != null) { return; } View3D.CheckError("Render - Player - 0"); OpenTK.Matrix4d mat = OpenTK.Matrix4d.Scale(1.5f) * OpenTK.Matrix4d.CreateRotationZ((Direction.Yaw * Utilities.PI180)) * PlayerAngleMat * OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos)); TheClient.MainWorldView.SetMatrix(2, mat); TheClient.Rendering.SetMinimumLight(0.0f); model.CustomAnimationAdjustments = new Dictionary <string, OpenTK.Matrix4>(SavedAdjustmentsOTK) { // TODO: safe (no-collision) rotation check? { "spine04", GetAdjustmentOTK("spine04") * OpenTK.Matrix4.CreateRotationX(-(float)(Direction.Pitch / 2f * Utilities.PI180)) } }; View3D.CheckError("Render - Player - 1"); if (!TheClient.MainWorldView.RenderingShadows && TheClient.CVars.g_firstperson.ValueB) { model.CustomAnimationAdjustments["neck01"] = GetAdjustmentOTK("neck01") * OpenTK.Matrix4.CreateRotationX(-(float)(160f * Utilities.PI180)); } else { model.CustomAnimationAdjustments["neck01"] = GetAdjustmentOTK("neck01"); } model.Draw(aHTime, hAnim, aTTime, tAnim, aLTime, lAnim); Model mod = TheClient.GetItemForSlot(TheClient.QuickBarPos).Mod; bool hasjp = HasJetpack(); View3D.CheckError("Render - Player - 2"); if (!hasjp && tAnim != null && mod != null) { mat = OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos)); TheClient.MainWorldView.SetMatrix(2, mat); Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>(SavedAdjustments); // TODO: Logic of this rotation math? Matrix rotforw = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, ((float)(Direction.Pitch / 2f * Utilities.PI180) % 360f))); adjs["spine04"] = GetAdjustment("spine04") * rotforw; SingleAnimationNode hand = tAnim.GetNode("metacarpal2.r"); Matrix m4 = Matrix.CreateScale(1.5f, 1.5f, 1.5f) * (Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-Direction.Yaw + 90) * Utilities.PI180) % 360f)) * hand.GetBoneTotalMatrix(aTTime, adjs)) * Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-90) * Utilities.PI180) % 360f)); OpenTK.Matrix4 bonemat = new OpenTK.Matrix4((float)m4.M11, (float)m4.M12, (float)m4.M13, (float)m4.M14, (float)m4.M21, (float)m4.M22, (float)m4.M23, (float)m4.M24, (float)m4.M31, (float)m4.M32, (float)m4.M33, (float)m4.M34, (float)m4.M41, (float)m4.M42, (float)m4.M43, (float)m4.M44); GL.UniformMatrix4(100, false, ref bonemat); mod.LoadSkin(TheClient.Textures); mod.Draw(); bonemat = OpenTK.Matrix4.Identity; GL.UniformMatrix4(100, false, ref bonemat); } View3D.CheckError("Render - Player - 3"); if (hasjp) { // TODO: Abstractify! Model jetp = GetHeldItem().Mod; mat = OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos)); TheClient.MainWorldView.SetMatrix(2, mat); Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>(); Matrix rotforw = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, ((float)(Direction.Pitch / 2f * Utilities.PI180) % 360f))); adjs["spine04"] = GetAdjustment("spine04") * rotforw; SingleAnimationNode spine = tAnim.GetNode("spine04"); Matrix m4 = Matrix.CreateScale(1.5f, 1.5f, 1.5f) * (Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-Direction.Yaw + 90) * Utilities.PI180) % 360f)) * spine.GetBoneTotalMatrix(aTTime, adjs)) * Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, (float)((90) * Utilities.PI180) % 360f)); OpenTK.Matrix4 bonemat = new OpenTK.Matrix4((float)m4.M11, (float)m4.M12, (float)m4.M13, (float)m4.M14, (float)m4.M21, (float)m4.M22, (float)m4.M23, (float)m4.M24, (float)m4.M31, (float)m4.M32, (float)m4.M33, (float)m4.M34, (float)m4.M41, (float)m4.M42, (float)m4.M43, (float)m4.M44); GL.UniformMatrix4(100, false, ref bonemat); jetp.LoadSkin(TheClient.Textures); jetp.Draw(); bonemat = OpenTK.Matrix4.Identity; GL.UniformMatrix4(100, false, ref bonemat); } View3D.CheckError("Render - Player - 4"); if (IsTyping) { TheClient.Textures.GetTexture("ui/game/typing").Bind(); // TODO: store! TheClient.Rendering.RenderBillboard(renderrelpos + new Location(0, 0, 4), new Location(2), TheClient.MainWorldView.CameraPos); } View3D.CheckError("Render - Player - Post"); }
public override void Render() { Location renderrelpos = GetWeldSpot(); TheClient.SetEnts(); // TODO: Merge with base.Render() as much as possible! if (TheClient.CVars.n_debugmovement.ValueB) { TheClient.Rendering.RenderLine(ServerLocation, renderrelpos); TheClient.Rendering.RenderLineBox(ServerLocation + new Location(-0.2), ServerLocation + new Location(0.2)); } OpenTK.Matrix4d mat = OpenTK.Matrix4d.Scale(1.5f) * OpenTK.Matrix4d.CreateRotationZ((Direction.Yaw * Utilities.PI180)) * PlayerAngleMat * OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos)); TheClient.MainWorldView.SetMatrix(2, mat); TheClient.Rendering.SetMinimumLight(0.0f); model.CustomAnimationAdjustments = new Dictionary <string, OpenTK.Matrix4>(SavedAdjustmentsOTK); // TODO: safe (no-collision) rotation check? model.CustomAnimationAdjustments["spine04"] = GetAdjustmentOTK("spine04") * OpenTK.Matrix4.CreateRotationX(-(float)(Direction.Pitch / 2f * Utilities.PI180)); if (!TheClient.MainWorldView.RenderingShadows && TheClient.CVars.g_firstperson.ValueB) { model.CustomAnimationAdjustments["neck01"] = GetAdjustmentOTK("neck01") * OpenTK.Matrix4.CreateRotationX(-(float)(160f * Utilities.PI180)); } else { model.CustomAnimationAdjustments["neck01"] = GetAdjustmentOTK("neck01"); } model.Draw(aHTime, hAnim, aTTime, tAnim, aLTime, lAnim); Model mod = TheClient.GetItemForSlot(TheClient.QuickBarPos).Mod; bool hasjp = HasJetpack(); if (!hasjp && tAnim != null && mod != null) { mat = OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos)); TheClient.MainWorldView.SetMatrix(2, mat); Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>(SavedAdjustments); Matrix rotforw = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, ((float)(Direction.Pitch / 2f * Utilities.PI180) % 360f))); adjs["spine04"] = GetAdjustment("spine04") * rotforw; SingleAnimationNode hand = tAnim.GetNode("metacarpal2.r"); Matrix m4 = Matrix.CreateScale(1.5f, 1.5f, 1.5f) * (Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-Direction.Yaw + 90) * Utilities.PI180) % 360f)) * hand.GetBoneTotalMatrix(aTTime, adjs)) * Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-90) * Utilities.PI180) % 360f)); OpenTK.Matrix4 bonemat = new OpenTK.Matrix4((float)m4.M11, (float)m4.M12, (float)m4.M13, (float)m4.M14, (float)m4.M21, (float)m4.M22, (float)m4.M23, (float)m4.M24, (float)m4.M31, (float)m4.M32, (float)m4.M33, (float)m4.M34, (float)m4.M41, (float)m4.M42, (float)m4.M43, (float)m4.M44); GL.UniformMatrix4(40, false, ref bonemat); mod.LoadSkin(TheClient.Textures); mod.Draw(); bonemat = OpenTK.Matrix4.Identity; GL.UniformMatrix4(40, false, ref bonemat); } if (hasjp) { // TODO: Abstractify! Model jetp = GetHeldItem().Mod; mat = OpenTK.Matrix4d.CreateTranslation(ClientUtilities.ConvertD(renderrelpos)); TheClient.MainWorldView.SetMatrix(2, mat); Dictionary <string, Matrix> adjs = new Dictionary <string, Matrix>(); Matrix rotforw = Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, ((float)(Direction.Pitch / 2f * Utilities.PI180) % 360f))); adjs["spine04"] = GetAdjustment("spine04") * rotforw; SingleAnimationNode spine = tAnim.GetNode("spine04"); Matrix m4 = Matrix.CreateScale(1.5f, 1.5f, 1.5f) * (Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitZ, (float)((-Direction.Yaw + 90) * Utilities.PI180) % 360f)) * spine.GetBoneTotalMatrix(aTTime, adjs)) * Matrix.CreateFromQuaternion(Quaternion.CreateFromAxisAngle(Vector3.UnitX, (float)((90) * Utilities.PI180) % 360f)); OpenTK.Matrix4 bonemat = new OpenTK.Matrix4((float)m4.M11, (float)m4.M12, (float)m4.M13, (float)m4.M14, (float)m4.M21, (float)m4.M22, (float)m4.M23, (float)m4.M24, (float)m4.M31, (float)m4.M32, (float)m4.M33, (float)m4.M34, (float)m4.M41, (float)m4.M42, (float)m4.M43, (float)m4.M44); GL.UniformMatrix4(40, false, ref bonemat); jetp.LoadSkin(TheClient.Textures); jetp.Draw(); bonemat = OpenTK.Matrix4.Identity; GL.UniformMatrix4(40, false, ref bonemat); } if (IsTyping) { TheClient.Textures.GetTexture("ui/game/typing").Bind(); // TODO: store! TheClient.Rendering.RenderBillboard(renderrelpos + new Location(0, 0, 4), new Location(2), TheClient.MainWorldView.CameraPos); } }